1 // SPDX-License-Identifier: Apache-2.0
3 * Copyright (C) 2021 Parichay Kapoor <pk.kapoor@samsung.com>
5 * @file basic_planner.cpp
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
14 #include <basic_planner.h>
15 #include <nntrainer_error.h>
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);
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.
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 {
35 memory_offset.resize(memory_size.size());
38 for (unsigned int idx = 0; idx < memory_size.size(); idx++) {
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.");
46 memory_offset[idx] = csum;
47 csum += memory_size[idx];
53 } // namespace nntrainer