20#include "kernel/PermuteLayer.h"
33 const std::shared_ptr<TensorRegistry> &tensor_reg,
34 const std::shared_ptr<ExternalContext> &external_context)
35 : basic::KernelGeneratorBase{graph}, _dyn_tensor_manager{dyn_tensor_manager},
36 _tensor_reg{tensor_reg}, _tensor_registries{}, _executors{nullptr}, _model_index{},
37 _external_context{external_context}
44 assert(_dyn_tensor_manager);
47 auto ret = std::make_unique<exec::FunctionSequence>();
50 auto dyn_ctx = std::make_shared<exec::FunctionSequence::DynamicTensorCtx>();
53 dyn_ctx->dynamic_shape_inferer = std::make_unique<exec::DynamicShapeInferer>(_tensor_reg);
55 ret->dynamic_tensor_ctx(dyn_ctx);
70 std::vector<backend::IPortableTensor *> input_tensors;
71 for (
const auto &input_index : node.getInputs())
73 auto input_tensor = getPortableTensor(input_index);
74 input_tensors.emplace_back(input_tensor);
77 std::vector<backend::IPortableTensor *> output_tensors;
78 for (
const auto &output_index : node.getOutputs())
80 auto output_tensor = getPortableTensor(output_index);
81 output_tensors.emplace_back(output_tensor);
86 const auto cond_tensor = input_tensors.front();
87 input_tensors.erase(input_tensors.begin());
88 auto fn = std::make_unique<::onert::backend::builtin::kernel::IfLayer>(
89 cond_tensor, input_tensors, output_tensors, then_subg_index, else_subg_index, _executors,
90 _model_index, _external_context);
95void KernelGenerator::visit(
const ir::operation::Permute &node)
97 const auto output_index{node.getOutputs().at(0)};
101 std::vector<ITensor *> output_tensors{getTensor(output_index)};
102 std::vector<ITensor *> input_tensors{getTensor(input_index)};
103 std::vector<ir::PermuteType> permute_types;
106 for (uint32_t i = 0; i < input_tensors.size(); i++)
109 auto fn = std::make_unique<kernel::PermuteLayer>(input_tensors, output_tensors, permute_types,
114void KernelGenerator::visit(
const ir::operation::While &node)
116 const auto cond_subg_index = node.param().cond_subg_index;
117 const auto body_subg_index = node.param().body_subg_index;
121 std::vector<backend::IPortableTensor *> input_tensors;
122 for (
const auto &input_index : node.getInputs())
124 auto input_tensor = getPortableTensor(input_index);
125 input_tensors.emplace_back(input_tensor);
128 std::vector<backend::IPortableTensor *> output_tensors;
129 for (
const auto &output_index : node.getOutputs())
132 output_tensors.emplace_back(output_tensor);
137 auto fn = std::make_unique<::onert::backend::builtin::kernel::WhileLayer>(
138 input_tensors, output_tensors, cond_subg_index, body_subg_index, _executors, _model_index,
147 auto ret = _tensor_registries.
getITensor(index);
148 assert(ret !=
nullptr);
152backend::IPortableTensor *KernelGenerator::getPortableTensor(
const ir::OperandIndex &index)
154 auto ret = _tensor_reg->getPortableTensor(index);
155 assert(ret !=
nullptr);
Class to manage dynamic tensor and its memory.
std::shared_ptr< DynamicMemoryManager > dynamic_mem_mgr()
std::unique_ptr< exec::IFunction > _return_fn
KernelGenerator(const ir::Graph &graph, DynamicTensorManager *dyn_tensor_manager, const std::shared_ptr< TensorRegistry > &tensor_reg, const std::shared_ptr< ExternalContext > &external_context)
std::unique_ptr< exec::FunctionSequence > generate(ir::OperationIndex ind) override
backend::ITensor * getITensor(ir::OperandIndex ind) const
const Operations & operations() const override
const Param & param() const
const Object & at(const Index &index) const
Get the object that is associated with the given index.
::onert::util::Index< uint32_t, OperandIndexTag > OperandIndex
SubgraphIndex then_subg_index
SubgraphIndex else_subg_index