19#include "ops/ConvolutionLayer.h"
20#include "ops/FullyConnectedLayer.h"
40 auto ret = std::make_unique<exec::FunctionSequence>();
42 assert(_tensor_builder->dynamicTensorManager());
46 auto dyn_ctx = std::make_shared<exec::FunctionSequence::DynamicTensorCtx>();
48 dyn_ctx->op = &_operations_ctx.
at(ind);
49 dyn_ctx->dynamic_shape_inferer = std::make_shared<exec::DynamicShapeInferer>(_tensor_reg);
51 ret->dynamic_tensor_ctx(dyn_ctx);
60 auto tensor = _tensor_reg->getNativeTensor(ind);
63 tensor->increase_ref();
70 const ir::Graph &graph,
const std::shared_ptr<TensorBuilder> &tensor_builder,
71 const std::shared_ptr<basic::TensorRegistry> &tensor_reg,
72 const std::shared_ptr<backend::custom::IKernelBuilder> &kernel_builder,
73 const std::shared_ptr<ExternalContext> &external_context)
74 : basic::KernelGeneratorBase{graph}, _ctx(graph.operands()), _operations_ctx{graph.operations()},
75 _tensor_builder(tensor_builder), _tensor_reg{tensor_reg}, _kernel_builder(kernel_builder),
76 _external_context(external_context)
86 const auto ifm_index{node.
getInputs().
at(Conv2D::Input::INPUT)};
87 const auto ker_index{node.
getInputs().
at(Conv2D::Input::KERNEL)};
88 const auto bias_index{node.
getInputs().
at(Conv2D::Input::BIAS)};
90 auto ofm_tensor = _tensor_reg->getPortableTensor(ofm_index);
91 auto ifm_tensor = _tensor_reg->getPortableTensor(ifm_index);
92 auto ker_tensor = _tensor_reg->getPortableTensor(ker_index);
93 auto bias_tensor = _tensor_reg->getPortableTensor(bias_index);
99 auto fn = std::make_unique<ops::ConvolutionLayer>();
101 if (_ctx.
at(ifm_index).info().isDynamic() || _ctx.
at(ker_index).info().isDynamic())
103 fn->configure(ifm_tensor, ker_tensor, bias_tensor, param_padding.type, param_padding.param.left,
104 param_padding.param.right, param_padding.param.top, param_padding.param.bottom,
105 stride.horizontal, stride.vertical, dilation.width_factor, dilation.height_factor,
106 activation, ofm_tensor, _external_context);
111 const auto ifm_shape = _ctx.
at(ifm_index).shape().asFeature();
112 const auto ofm_shape = _ctx.
at(ofm_index).shape().asFeature();
114 const auto &ker_shape = _ctx.
at(ker_index).shape();
115 const auto ker_height = ker_shape.dim(1);
116 const auto ker_width = ker_shape.dim(2);
120 dilation.width_factor, dilation.height_factor);
122 fn->configure(ifm_tensor, ker_tensor, bias_tensor, param_padding.type, padding.left,
123 padding.right, padding.top, padding.bottom, stride.horizontal, stride.vertical,
124 dilation.width_factor, dilation.height_factor, activation, ofm_tensor,
130void KernelGenerator::visit(
const ir::operation::FullyConnected &node)
132 using ir::operation::FullyConnected;
134 const auto output_index{node.getOutputs().at(0)};
135 const auto input_index{node.getInputs().at(FullyConnected::Input::INPUT)};
136 const auto weight_index{node.getInputs().at(FullyConnected::Input::WEIGHT)};
137 const auto bias_index{node.getInputs().at(FullyConnected::Input::BIAS)};
138 const auto activation = node.param().activation;
139 const auto weights_format = node.param().weights_format;
141 throw std::runtime_error(
"Unsupported FullyConnected Weights Format");
143 auto output_tensor = _tensor_reg->getPortableTensor(output_index);
144 auto input_tensor = _tensor_reg->getPortableTensor(input_index);
145 auto weight_tensor = _tensor_reg->getPortableTensor(weight_index);
146 auto bias_tensor = bias_index.undefined() ? nullptr : _tensor_reg->getPortableTensor(bias_index);
148 auto fn = std::make_unique<ops::FullyConnectedLayer>();
150 fn->configure(input_tensor, weight_tensor, bias_tensor, activation, output_tensor,
std::unique_ptr< exec::IFunction > _return_fn
std::unique_ptr< exec::FunctionSequence > generate(ir::OperationIndex ind) override
KernelGenerator(const ir::Graph &graph, const std::shared_ptr< TensorBuilder > &tensor_builder, const std::shared_ptr< basic::TensorRegistry > &tensor_reg, const std::shared_ptr< custom::IKernelBuilder > &kernel_builder, const std::shared_ptr< ExternalContext > &external_context)
const Operations & operations() const override
const OperandIndex & at(IOIndex set_index) const
const OperandIndexSequence & getOutputs() const override
OperandIndexSequence & getInputs()
const Param & param() const
const Object & at(const Index &index) const
Get the object that is associated with the given index.
const ExplicitPadding calculatePadding(const Padding &padding, const FeatureShape &ifm_shape, const FeatureShape &ofm_shape, const Stride &stride, uint32_t kw, uint32_t kh, uint32_t dwf=1, uint32_t dhf=1)
This file contains utility macro.