Skip to content

Commit

Permalink
[onert] Change memory planners to class template (Samsung#12874)
Browse files Browse the repository at this point in the history
This commit changes memory planners to class template to allow memory planning for variable indexes.
  - Change `IMemoryPlanner` to template
  - Change memory planners to class template
  - Change the factory method of memory planners to template

ONE-DCO-1.0-Signed-off-by: ragmani <[email protected]>
  • Loading branch information
ragmani authored Apr 18, 2024
1 parent 263bfea commit 23183fa
Show file tree
Hide file tree
Showing 8 changed files with 258 additions and 279 deletions.
20 changes: 11 additions & 9 deletions runtime/onert/core/include/backend/basic/IMemoryPlanner.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
#ifndef __ONERT_BACKEND_IMEMORY_PLANNER_H__
#define __ONERT_BACKEND_IMEMORY_PLANNER_H__

#include "ir/OperandIndexMap.h"
#include <cstddef>
#include <cstdint>
#include <unordered_map>

namespace onert
{
Expand All @@ -38,21 +40,21 @@ struct Block
/**
* @brief Interface to plan memory
*/
struct IMemoryPlanner
template <typename Index> struct IMemoryPlanner
{
using MemoryPlans = ir::OperandIndexMap<Block>;
using MemoryPlans = std::unordered_map<Index, Block>;

/**
* @brief Claim memory for operand
* @param[in] index The operand index
* @brief Claim memory for tensor
* @param[in] index The tensor index
* @param[in] size The size of the memory
*/
virtual void claim(const ir::OperandIndex &, size_t) = 0;
virtual void claim(const Index &, size_t) = 0;
/**
* @brief Release memory for operand
* @param[in] index The operand index
* @brief Release memory for tensor
* @param[in] index The tensor index
*/
virtual void release(const ir::OperandIndex &) = 0;
virtual void release(const Index &) = 0;
/**
* @brief Get capacity for memory planning
* @return The value of capacity
Expand Down
9 changes: 5 additions & 4 deletions runtime/onert/core/include/backend/basic/MemoryManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#define __ONERT_BACKEND_CPU_MEMORY_MANAGER_H__

#include "Allocator.h"
#include "ir/Index.h"
#include "IMemoryPlanner.h"

namespace onert
Expand Down Expand Up @@ -45,12 +46,12 @@ class MemoryManager
void releasePlan(const ir::OperandIndex &ind);

private:
IMemoryPlanner *createMemoryPlanner();
IMemoryPlanner *createMemoryPlanner(const std::string);
IMemoryPlanner<ir::OperandIndex> *createMemoryPlanner();
IMemoryPlanner<ir::OperandIndex> *createMemoryPlanner(const std::string);

private:
ir::OperandIndexMap<Block> _tensor_mem_map;
std::shared_ptr<IMemoryPlanner> _mem_planner;
std::unordered_map<ir::OperandIndex, Block> _tensor_mem_map;
std::shared_ptr<IMemoryPlanner<ir::OperandIndex>> _mem_planner;
std::shared_ptr<Allocator> _mem_alloc;
};

Expand Down
9 changes: 5 additions & 4 deletions runtime/onert/core/src/backend/basic/MemoryManager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,16 @@ MemoryManager::MemoryManager(const std::string planner_id)
// DO NOTHING
}

basic::IMemoryPlanner *MemoryManager::createMemoryPlanner()
basic::IMemoryPlanner<ir::OperandIndex> *MemoryManager::createMemoryPlanner()
{
auto planner_id = util::getConfigString(util::config::CPU_MEMORY_PLANNER);
return basic::MemoryPlannerFactory::get().create(planner_id);
return basic::MemoryPlannerFactory::get().create<ir::OperandIndex>(planner_id);
}

basic::IMemoryPlanner *MemoryManager::createMemoryPlanner(const std::string planner_id)
basic::IMemoryPlanner<ir::OperandIndex> *
MemoryManager::createMemoryPlanner(const std::string planner_id)
{
return basic::MemoryPlannerFactory::get().create(planner_id);
return basic::MemoryPlannerFactory::get().create<ir::OperandIndex>(planner_id);
}

void MemoryManager::claimPlan(const ir::OperandIndex &ind, uint32_t size)
Expand Down
208 changes: 0 additions & 208 deletions runtime/onert/core/src/backend/basic/MemoryPlanner.cc

This file was deleted.

Loading

0 comments on commit 23183fa

Please sign in to comment.