[pkg] Enable debug mode for CI
[platform/core/ml/nntrainer.git] / nntrainer / tensor / basic_planner.cpp
1 // SPDX-License-Identifier: Apache-2.0
2 /**
3  * Copyright (C) 2021 Parichay Kapoor <pk.kapoor@samsung.com>
4  *
5  * @file   basic_planner.cpp
6  * @date   11 August 2021
7  * @see    https://github.com/nnstreamer/nntrainer
8  * @author Parichay Kapoor <pk.kapoor@samsung.com>
9  * @bug    No known bugs except for NYI items
10  * @brief  This is Naive Memory Planner
11  *
12  */
13
14 #include <basic_planner.h>
15 #include <nntrainer_error.h>
16
17 namespace nntrainer {
18
19 /**
20  * @copydoc MemoryPlanner::planLayout(
21  * const std::vector<size_t> &memory_size,
22  * const std::vector<std::pair<unsigned int, unsigned int>> &memory_validity,
23  * std::vector<size_t> &memory_offset);
24  *
25  * @details The basic memory planner does not incorporate any memory sharing.
26  * This planner allocates independent memory for all the required memories
27  * without considering their memory validity.
28  *
29  */
30 size_t BasicPlanner::planLayout(
31   const std::vector<size_t> &memory_size,
32   const std::vector<std::pair<unsigned int, unsigned int>> &memory_validity,
33   std::vector<size_t> &memory_offset) const {
34
35   memory_offset.resize(memory_size.size());
36   size_t csum = 0;
37
38   for (unsigned int idx = 0; idx < memory_size.size(); idx++) {
39
40 #ifdef DEBUG
41     /** skip any memory requirement, if validity is less than 1 */
42     if (memory_validity[idx].second <= memory_validity[idx].first)
43       throw std::runtime_error("Memory requested for non-valid duration.");
44 #endif
45
46     memory_offset[idx] = csum;
47     csum += memory_size[idx];
48   }
49
50   return csum;
51 }
52
53 } // namespace nntrainer