std::shared_ptr<backend::operand::IObject> wrapTensor(const model::OperandIndex &ind) override;
void iterate(const IterateFunction &fn) override;
- // TODO Pass MemoryManager to Executor instead of TensorBuilder
- // std::unique_ptr<IMemoryManager> releaseMemoryManager(void) override;
+ std::unique_ptr<IMemoryManager> releaseMemoryManager(void) override;
std::shared_ptr<T_ITensor> at(const ::neurun::model::OperandIndex &ind);
/**
_apply_dim_correction_map[index] = apply_dim_correction;
}
+template <typename T_ITensor, typename T_Tensor, typename T_SubTensor, typename T_Object>
+std::unique_ptr<IMemoryManager>
+TemplTensorBuilder<T_ITensor, T_Tensor, T_SubTensor, T_Object>::releaseMemoryManager(void)
+{
+ return std::move(_mem_mgr);
+}
+
} // namespace acl_common
} // namespace backend
} // namespace neurun
return _mem_mgr->tensors().at(ind);
}
+std::unique_ptr<IMemoryManager> TensorBuilder::releaseMemoryManager(void)
+{
+ return std::move(_mem_mgr);
+}
+
} // namespace cpu
} // namespace backend
} // namespace neurun
void iterate(const IterateFunction &fn) override;
- // TODO Pass MemoryManager to Executor instead of TensorBuilder
- // std::unique_ptr<IMemoryManager> releaseMemoryManager(void) override;
+ std::unique_ptr<IMemoryManager> releaseMemoryManager(void) override;
std::shared_ptr<operand::Tensor> at(const ::neurun::model::OperandIndex &ind);
#include "compiler/SubTensorInfo.h"
#include "operand/ITensor.h"
#include "model/Layout.h"
+#include "IMemoryManager.h"
namespace neurun
{
tensorAt(const model::OperandIndex &ind) = 0;
virtual std::shared_ptr<backend::operand::IObject> wrapTensor(const model::OperandIndex &ind) = 0;
virtual void iterate(const IterateFunction &fn) = 0;
+
+ virtual std::unique_ptr<IMemoryManager> releaseMemoryManager(void) = 0;
};
} // namespace backend
#include "SubTensorAnalyzer.h"
#include "PlanBuilder.h"
#include "ConstantInitializer.h"
+#include "cpp14/memory.h"
namespace neurun
{
ConstantInitializer{graph, *operand_context, *linear->getLowerInfo()}();
+ // Prepare each MemoryManager on each backend
+ auto mem_mgrs = nnfw::cpp14::make_unique<backend::MemoryManagerSet>();
+ for (auto &tensor_builder : tensor_builders)
+ {
+ mem_mgrs->insert(std::move(tensor_builder->releaseMemoryManager()));
+ }
+
auto plan = std::make_shared<Plan>(operation_sequence);
- return new exec::LinearExecutor{graph.shareModel(), linear->releaseSubgraphContext(),
- operand_context, linear->releaseLowerInfo(),
- linear->releaseElements(), plan};
+ return new exec::LinearExecutor{graph.shareModel(),
+ linear->releaseSubgraphContext(),
+ operand_context,
+ linear->releaseLowerInfo(),
+ std::move(mem_mgrs),
+ linear->releaseElements(),
+ plan};
}
exec::IExecutor *ExecutorFactory::createDataflowExecutor(graph::Graph &graph, bool parallel)
ConstantInitializer{graph, *operand_context, *lower_info}();
+ // Prepare each MemoryManager on each backend
+ auto mem_mgrs = nnfw::cpp14::make_unique<backend::MemoryManagerSet>();
+ for (auto &tensor_builder : tensor_builders)
+ {
+ mem_mgrs->insert(std::move(tensor_builder->releaseMemoryManager()));
+ }
+
if (parallel)
{
- return new exec::ParallelExecutor{graph.shareModel(), std::move(graph.releaseSubgraphContext()),
- operand_context, std::move(lower_info),
- std::move(execution_builder.releaseCodeMap())};
+ return new exec::ParallelExecutor{
+ graph.shareModel(), std::move(graph.releaseSubgraphContext()),
+ operand_context, std::move(lower_info),
+ std::move(mem_mgrs), std::move(execution_builder.releaseCodeMap())};
}
else
{
auto exec = new exec::DataflowExecutor{
- graph.shareModel(), std::move(graph.releaseSubgraphContext()), operand_context,
- std::move(lower_info), std::move(execution_builder.releaseCodeMap())};
+ graph.shareModel(), std::move(graph.releaseSubgraphContext()),
+ operand_context, std::move(lower_info),
+ std::move(mem_mgrs), std::move(execution_builder.releaseCodeMap())};
if (config::ConfigManager::instance().get<bool>(config::PROFILING_MODE))
{
auto et = std::make_shared<backend::ExecTime>(graph.backend_resolver()->getAllBackends());
std::unique_ptr<model::SubgraphContext> subg_ctx,
const std::shared_ptr<compiler::OperandContext> &operand_context,
std::unique_ptr<graph::LowerInfoMap> lower_info,
+ std::unique_ptr<backend::MemoryManagerSet> mem_mgrs,
CodeMap &&code_map)
- : ExecutorBase{model, std::move(subg_ctx), operand_context, std::move(lower_info)},
+ : ExecutorBase{model, std::move(subg_ctx), operand_context, std::move(lower_info),
+ std::move(mem_mgrs)},
_code_map{std::move(code_map)}
{
VERBOSE(DataflowExecutor) << "Constructing Dataflow Executor" << std::endl;
DataflowExecutor(const std::shared_ptr<const model::Model> &model,
std::unique_ptr<model::SubgraphContext> subg_ctx,
const std::shared_ptr<compiler::OperandContext> &operand_context,
- std::unique_ptr<graph::LowerInfoMap> lower_info, CodeMap &&code_map);
+ std::unique_ptr<graph::LowerInfoMap> lower_info,
+ std::unique_ptr<backend::MemoryManagerSet> mem_mgrs, CodeMap &&code_map);
void executeImpl() override;
ExecutorBase::ExecutorBase(const std::shared_ptr<const model::Model> &model,
std::unique_ptr<model::SubgraphContext> subg_ctx,
const std::shared_ptr<compiler::OperandContext> &operand_context,
- std::unique_ptr<graph::LowerInfoMap> lower_info)
+ std::unique_ptr<graph::LowerInfoMap> lower_info,
+ std::unique_ptr<backend::MemoryManagerSet> mem_mgrs)
: _observers(), _model{model}, _subg_ctx{std::move(subg_ctx)},
- _operand_context{operand_context}, _lower_info{std::move(lower_info)}
+ _operand_context{operand_context}, _lower_info{std::move(lower_info)},
+ _mem_mgrs{std::move(mem_mgrs)}
{
_sources.resize(_model->inputs.size());
_sinks.resize(_model->outputs.size());
#include "model/Subgraph.h"
#include "backend/ExecTime.h"
#include "exec/IFunction.h"
+#include "backend/IMemoryManager.h"
#include <list>
namespace neurun
ExecutorBase(const std::shared_ptr<const model::Model> &model,
std::unique_ptr<model::SubgraphContext> subg_ctx,
const std::shared_ptr<compiler::OperandContext> &operand_context,
- std::unique_ptr<graph::LowerInfoMap> lower_info);
+ std::unique_ptr<graph::LowerInfoMap> lower_info,
+ std::unique_ptr<backend::MemoryManagerSet> mem_mgrs);
virtual ~ExecutorBase() = default;
std::unique_ptr<model::SubgraphContext> _subg_ctx;
std::shared_ptr<compiler::OperandContext> _operand_context;
std::unique_ptr<graph::LowerInfoMap> _lower_info;
+ std::unique_ptr<backend::MemoryManagerSet> _mem_mgrs;
std::vector<std::unique_ptr<ISource>> _sources;
std::vector<std::unique_ptr<ISink>> _sinks;
};
std::unique_ptr<model::SubgraphContext> subg_ctx,
const std::shared_ptr<compiler::OperandContext> &operand_context,
std::unique_ptr<graph::LowerInfoMap> lower_info,
+ std::unique_ptr<backend::MemoryManagerSet> mem_mgrs,
std::unique_ptr<std::vector<linear::Element>> elements,
const std::shared_ptr<const neurun::compiler::Plan> &plan)
- : ExecutorBase{model, std::move(subg_ctx), operand_context, std::move(lower_info)},
+ : ExecutorBase{model, std::move(subg_ctx), operand_context, std::move(lower_info),
+ std::move(mem_mgrs)},
_plan{plan}, _elements{std::move(elements)}
{
}
std::unique_ptr<model::SubgraphContext> subg_ctx,
const std::shared_ptr<compiler::OperandContext> &operand_context,
std::unique_ptr<graph::LowerInfoMap> lower_info,
+ std::unique_ptr<backend::MemoryManagerSet> mem_mgrs,
CodeMap &&code_map)
- : DataflowExecutor{model, std::move(subg_ctx), operand_context, std::move(lower_info),
+ : DataflowExecutor{model,
+ std::move(subg_ctx),
+ operand_context,
+ std::move(lower_info),
+ std::move(mem_mgrs),
std::move(code_map)}
{
VERBOSE(ParallelExecutor) << "Constructing Parallel Executor" << std::endl;
ParallelExecutor(const std::shared_ptr<const model::Model> &model,
std::unique_ptr<model::SubgraphContext> subg_ctx,
const std::shared_ptr<compiler::OperandContext> &operand_context,
- std::unique_ptr<graph::LowerInfoMap> lower_info, CodeMap &&code_map);
+ std::unique_ptr<graph::LowerInfoMap> lower_info,
+ std::unique_ptr<backend::MemoryManagerSet> mem_mgrs, CodeMap &&code_map);
void executeImpl() override;