LCOV - code coverage report
Current view: top level - nntrainer/tensor - optimized_v1_planner.h (source / functions) Coverage Total Hit
Test: coverage_filtered.info Lines: 66.7 % 3 2
Test Date: 2025-12-14 20:38:17 Functions: 0.0 % 1 0

            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   optimzied_v1_planner.h
       6              :  * @date   2 September 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 Optimized V1 Memory Planner
      11              :  *
      12              :  * @note This planner has been design to give reduced memory usage for training
      13              :  * and might not perform very well for inference.
      14              :  *
      15              :  * @details The principle for this planner is to give memory to the requests in
      16              :  * the order of the start of their validity.
      17              :  * This takes advantage of the pattern that the outputs of the layer nodes
      18              :  * allocated during forwarding are also used during backwarding as well.
      19              :  *
      20              :  * If two memory requests have the same start time, then the memory request with
      21              :  * higher end is allocated first. This is to minimize the fragmentation once the
      22              :  * memory is being freed.
      23              :  *
      24              :  * The assigned memories are cached, and once their validity is finished, they
      25              :  * are freed and reused for the next allocations.
      26              :  */
      27              : 
      28              : #ifndef __OPTIMIZED_V1_PLANNER_H_
      29              : #define __OPTIMIZED_V1_PLANNER_H_
      30              : 
      31              : #include <vector>
      32              : 
      33              : #include <memory_planner.h>
      34              : 
      35              : namespace nntrainer {
      36              : 
      37              : /**
      38              :  * @class   OptimizedV1Planner
      39              :  * @brief   Optimized V1 Memory Planner provides the optimized plan for memory
      40              :  * layout
      41              :  * @details optimized planner performs sharing of overlapping memory sharing
      42              :  * upto certain extent
      43              :  */
      44          409 : class OptimizedV1Planner : public MemoryPlanner {
      45              : public:
      46              :   /**
      47              :    * @brief OptimizedV1Planner destructor
      48              :    *
      49              :    */
      50          409 :   OptimizedV1Planner() = default;
      51              : 
      52              :   /**
      53              :    * @copydoc MemoryPlanner::planLayout(
      54              :    * const std::vector<size_t> &memory_size,
      55              :    * const std::vector<std::pair<unsigned int, unsigned int>> &memory_validity,
      56              :    * std::vector<size_t> &memory_offset,
      57              :    * std::vector<bool> &memory_is_wgrad);
      58              :    *
      59              :    */
      60              :   size_t planLayout(
      61              :     const std::vector<size_t> &memory_size,
      62              :     const std::vector<std::pair<unsigned int, unsigned int>> &memory_validity,
      63              :     std::vector<size_t> &memory_offset, std::vector<bool> &memory_is_wgrad,
      64              :     size_t n_wgrad = 0) const;
      65              : 
      66              :   /**
      67              :    * @copydoc MemoryPlanner::getType() const
      68              :    *
      69              :    */
      70            0 :   const std::string getType() const { return type; }
      71              : 
      72              :   static constexpr const char *type = "optimized_v1_planner";
      73              : };
      74              : 
      75              : } // namespace nntrainer
      76              : 
      77              : #endif /** __OPTIMIZED_V1_PLANNER_H_ */
        

Generated by: LCOV version 2.0-1