#include "compiler/ExecutionBuilder.h"
#include "exec/ExecTime.h"
#include "compiler/Linear.h"
+#include "compiler/TensorBuilders.h"
#include "backend/IConstantInitializer.h"
#include "backend/IKernelGenerator.h"
#include "backend/IOptimizer.h"
std::shared_ptr<backend::IConfig> _config;
};
+// TODO Think of a better way to manage TensorManagers
+backend::TensorManagerSet createTensorManagerSet(const compiler::TensorBuilders &tensor_builders)
+{
+ backend::TensorManagerSet tensor_mgrs;
+ for (auto &tensor_builder : tensor_builders)
+ {
+ auto s_tensor_manager = tensor_builder->releaseStaticTensorManager();
+ if (s_tensor_manager != nullptr)
+ tensor_mgrs.insert(std::move(s_tensor_manager));
+
+ auto d_tensor_manager = tensor_builder->releaseDynamicTensorManager();
+ if (d_tensor_manager != nullptr)
+ tensor_mgrs.insert(std::move(d_tensor_manager));
+ }
+ return tensor_mgrs;
+}
+
} // namespace
} // namespace onert
});
}
- auto exec =
- new exec::LinearExecutor{std::move(lowered_graph), input_tensors, output_tensors,
- tensor_builders, std::move(code_map), order};
+ TensorRegistries tensor_regs{lowered_graph->backend_contexts(), true};
+ backend::TensorManagerSet tensor_mgrs = createTensorManagerSet(tensor_builders);
+ auto exec = new exec::LinearExecutor{
+ std::move(lowered_graph), input_tensors, output_tensors, tensor_regs,
+ std::move(tensor_mgrs), std::move(code_map), order};
if (!options.trace_filepath.empty())
{
});
}
+ TensorRegistries tensor_regs{lowered_graph->backend_contexts(), true};
+ backend::TensorManagerSet tensor_mgrs = createTensorManagerSet(tensor_builders);
+
exec::ExecutorBase *exec = nullptr;
if (parallel)
{
- exec = new exec::ParallelExecutor{std::move(lowered_graph), input_tensors, output_tensors,
- tensor_builders, std::move(code_map)};
+ exec = new exec::ParallelExecutor{std::move(lowered_graph), input_tensors,
+ output_tensors, tensor_regs,
+ std::move(tensor_mgrs), std::move(code_map)};
}
else
{
- auto dataflow_exec =
- new exec::DataflowExecutor{std::move(lowered_graph), input_tensors, output_tensors,
- tensor_builders, std::move(code_map)};
+ auto dataflow_exec = new exec::DataflowExecutor{std::move(lowered_graph), input_tensors,
+ output_tensors, tensor_regs,
+ std::move(tensor_mgrs), std::move(code_map)};
if (options.he_profiling_mode)
{
std::vector<const backend::Backend *> backends;
#include "backend/ITensor.h"
#include "exec/IExecutor.h"
#include "compiler/LoweredGraph.h"
-#include "TensorBuilders.h"
#include "TensorRegistries.h"
namespace onert
return _cf_tensor_reg;
}
- std::shared_ptr<backend::ITensor> getITensor(ir::OperandIndex ind)
+ std::shared_ptr<backend::ITensor> getITensor(ir::OperandIndex ind) const
{
for (auto &tensor_reg : _tensor_regs)
{
std::unique_ptr<compiler::LoweredGraph> lowered_graph,
const std::vector<std::shared_ptr<backend::ITensor>> &input_tensors,
const std::vector<std::shared_ptr<backend::ITensor>> &output_tensors,
- const compiler::TensorBuilders &tensor_builders, compiler::CodeMap &&code_map)
- : ExecutorBase{std::move(lowered_graph), input_tensors, output_tensors, tensor_builders},
+ const compiler::TensorRegistries &tensor_regs, backend::TensorManagerSet &&tensor_mgrs,
+ compiler::CodeMap &&code_map)
+ : ExecutorBase{std::move(lowered_graph), input_tensors, output_tensors, tensor_regs,
+ std::move(tensor_mgrs)},
_code_map{std::move(code_map)}
{
VERBOSE(DataflowExecutor) << "Constructing Dataflow Executor" << std::endl;
DataflowExecutor(std::unique_ptr<compiler::LoweredGraph> lowered_graph,
const std::vector<std::shared_ptr<backend::ITensor>> &input_tensors,
const std::vector<std::shared_ptr<backend::ITensor>> &output_tensors,
- const compiler::TensorBuilders &tensor_builders, compiler::CodeMap &&code_map);
+ const compiler::TensorRegistries &tensor_regs,
+ backend::TensorManagerSet &&tensor_mgrs, compiler::CodeMap &&code_map);
void executeImpl() override;
ExecutorBase::ExecutorBase(std::unique_ptr<compiler::LoweredGraph> &&lowered_graph,
const std::vector<std::shared_ptr<backend::ITensor>> &input_tensors,
const std::vector<std::shared_ptr<backend::ITensor>> &output_tensors,
- const compiler::TensorBuilders &tensor_builders)
+ const compiler::TensorRegistries &tensor_regs,
+ backend::TensorManagerSet &&tensor_mgrs)
: _lowered_graph{std::move(lowered_graph)}, _graph{_lowered_graph->graph()},
- _input_tensors{input_tensors}, _output_tensors{output_tensors}, _mutex()
+ _input_tensors{input_tensors}, _output_tensors{output_tensors},
+ _tensor_mgrs{std::move(tensor_mgrs)}, _mutex()
{
// TODO Fix the way of knowing whether it is primary or not
bool primary_executor = !(_input_tensors.empty() && _output_tensors.empty());
std::vector<std::shared_ptr<backend::ITensor>> list;
for (auto ind : ind_seq)
{
- std::shared_ptr<backend::ITensor> tensor;
- for (auto &tensor_builder : tensor_builders)
- {
- auto tensor_registry = tensor_builder->tensorRegistry();
- assert(tensor_registry);
- tensor = tensor_registry->getNativeITensor(ind);
- if (tensor != nullptr)
- {
- DynAllocInfo dyn_alloc_info{ind};
- _input_to_dyn_alloc_info.emplace(tensor, dyn_alloc_info);
- break;
- }
- }
+ std::shared_ptr<backend::ITensor> tensor = tensor_regs.getITensor(ind);
assert(tensor != nullptr);
+ DynAllocInfo dyn_alloc_info{ind};
+ _input_to_dyn_alloc_info.emplace(tensor, dyn_alloc_info);
list.push_back(tensor);
}
return list;
std::vector<std::shared_ptr<backend::ITensor>> list;
for (auto ind : ind_seq)
{
- std::shared_ptr<backend::ITensor> tensor;
- for (auto &tensor_builder : tensor_builders)
- {
- auto tensor_registry = tensor_builder->tensorRegistry();
- assert(tensor_registry);
- tensor = tensor_registry->getNativeITensor(ind);
- if (tensor != nullptr)
- {
- DynAllocInfo dyn_alloc_info{ind};
- _output_to_dyn_alloc_info.emplace(tensor, dyn_alloc_info);
- break;
- }
- }
+ std::shared_ptr<backend::ITensor> tensor = tensor_regs.getITensor(ind);
assert(tensor != nullptr);
+ DynAllocInfo dyn_alloc_info{ind};
+ _output_to_dyn_alloc_info.emplace(tensor, dyn_alloc_info);
list.push_back(tensor);
}
return list;
}
else
{
- // If primary graph, all the inputs and outputs belong to controlflow backend
- auto cf_dyn_tensor_builder = tensor_builders.getControlflowTensorBuilder();
- assert(cf_dyn_tensor_builder);
-
assert(input_tensors.size() == _graph.getInputs().size());
assert(output_tensors.size() == _graph.getOutputs().size());
for (uint32_t i = 0; i < input_tensors.size(); i++)
_output_to_dyn_alloc_info.emplace(tensor, dyn_alloc_info);
}
}
-
- // Prepare each TensorManager on each backend
- for (auto &tensor_builder : tensor_builders)
- {
- auto s_tensor_manager = tensor_builder->releaseStaticTensorManager();
- if (s_tensor_manager != nullptr)
- _tensor_mgrs.insert(std::move(s_tensor_manager));
-
- auto d_tensor_manager = tensor_builder->releaseDynamicTensorManager();
- if (d_tensor_manager != nullptr)
- _tensor_mgrs.insert(std::move(d_tensor_manager));
- }
}
void ExecutorBase::execute(const std::vector<std::shared_ptr<backend::ITensor>> &src_tensors,
#include "exec/IFunction.h"
#include "backend/IDynamicTensorManager.h"
#include "backend/ITensorManager.h"
-#include "backend/ITensorBuilder.h"
#include "exec/ExecutionObservee.h"
-#include "compiler/TensorBuilders.h"
+#include "compiler/TensorRegistries.h"
#include <list>
namespace onert
ExecutorBase(std::unique_ptr<compiler::LoweredGraph> &&lowered_graph,
const std::vector<std::shared_ptr<backend::ITensor>> &input_tensors,
const std::vector<std::shared_ptr<backend::ITensor>> &output_tensors,
- const compiler::TensorBuilders &tensor_builders);
+ const compiler::TensorRegistries &tensor_regs,
+ backend::TensorManagerSet &&tensor_mgrs);
virtual ~ExecutorBase() = default;
LinearExecutor(std::unique_ptr<compiler::LoweredGraph> lowered_graph,
const std::vector<std::shared_ptr<backend::ITensor>> &input_tensors,
const std::vector<std::shared_ptr<backend::ITensor>> &output_tensors,
- const compiler::TensorBuilders &tensor_builders, compiler::CodeMap &&code_map,
+ const compiler::TensorRegistries &tensor_regs,
+ backend::TensorManagerSet &&tensor_mgrs, compiler::CodeMap &&code_map,
const std::vector<ir::OpSequenceIndex> &order)
- : ExecutorBase{std::move(lowered_graph), input_tensors, output_tensors, tensor_builders}
+ : ExecutorBase{std::move(lowered_graph), input_tensors, output_tensors, tensor_regs,
+ std::move(tensor_mgrs)}
{
for (auto index : order)
{
std::unique_ptr<compiler::LoweredGraph> lowered_graph,
const std::vector<std::shared_ptr<backend::ITensor>> &input_tensors,
const std::vector<std::shared_ptr<backend::ITensor>> &output_tensors,
- const compiler::TensorBuilders &tensor_builders, compiler::CodeMap &&code_map)
- : DataflowExecutor{std::move(lowered_graph), input_tensors, output_tensors, tensor_builders,
- std::move(code_map)}
+ const compiler::TensorRegistries &tensor_regs, backend::TensorManagerSet &&tensor_mgrs,
+ compiler::CodeMap &&code_map)
+ : DataflowExecutor{std::move(lowered_graph), input_tensors, output_tensors, tensor_regs,
+ std::move(tensor_mgrs), std::move(code_map)}
{
VERBOSE(ParallelExecutor) << "Constructing Parallel Executor" << std::endl;
}
ParallelExecutor(std::unique_ptr<compiler::LoweredGraph> lowered_graph,
const std::vector<std::shared_ptr<backend::ITensor>> &input_tensors,
const std::vector<std::shared_ptr<backend::ITensor>> &output_tensors,
- const compiler::TensorBuilders &tensor_builders, compiler::CodeMap &&code_map);
+ const compiler::TensorRegistries &tensor_regs,
+ backend::TensorManagerSet &&tensor_mgrs, compiler::CodeMap &&code_map);
void executeImpl() override;