LCOV - code coverage report
Current view: top level - nntrainer/tensor - basic_planner.cpp (source / functions) Coverage Total Hit
Test: coverage_filtered.info Lines: 100.0 % 6 6
Test Date: 2025-12-14 20:38:17 Functions: 100.0 % 1 1

            Line data    Source code
       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              :  * std::vector<bool> &memory_is_wgrad);
      25              :  *
      26              :  * @details The basic memory planner does not incorporate any memory sharing.
      27              :  * This planner allocates independent memory for all the required memories
      28              :  * without considering their memory validity.
      29              :  *
      30              :  */
      31          903 : size_t BasicPlanner::planLayout(
      32              :   const std::vector<size_t> &memory_size,
      33              :   const std::vector<std::pair<unsigned int, unsigned int>> &memory_validity,
      34              :   std::vector<size_t> &memory_offset, std::vector<bool> &memory_is_wgrad,
      35              :   size_t n_wgrad) const {
      36              : 
      37          903 :   memory_offset.resize(memory_size.size());
      38              :   size_t csum = 0;
      39              : 
      40        17095 :   for (unsigned int idx = 0; idx < memory_size.size(); idx++) {
      41              : 
      42              : #ifdef DEBUG
      43              :     /** skip any memory requirement, if validity is less than 1 */
      44              :     if (memory_validity[idx].second <= memory_validity[idx].first)
      45              :       throw std::runtime_error("Memory requested for non-valid duration.");
      46              : #endif
      47              : 
      48        16192 :     memory_offset[idx] = csum;
      49        16192 :     csum += memory_size[idx];
      50              :   }
      51              : 
      52          903 :   return csum;
      53              : }
      54              : 
      55              : } // namespace nntrainer
        

Generated by: LCOV version 2.0-1