|
16 | 16 |
|
17 | 17 | #include "KernelGenerator.h" |
18 | 18 |
|
19 | | -#include "ops/Conv2DLayer.h" |
20 | | -#include "ops/FullyConnectedLayer.h" |
21 | | - |
22 | 19 | #include <backend/Backend.h> |
23 | 20 | #include <backend/IConfig.h> |
24 | 21 | #include <memory> |
@@ -72,79 +69,6 @@ KernelGenerator::KernelGenerator(const ir::Graph &graph, |
72 | 69 | // DO NOTHING |
73 | 70 | } |
74 | 71 |
|
75 | | -void KernelGenerator::visit(const ir::operation::Conv2D &node) |
76 | | -{ |
77 | | - using ir::operation::Conv2D; |
78 | | - |
79 | | - const auto ofm_index{node.getOutputs().at(0)}; |
80 | | - const auto ifm_index{node.getInputs().at(Conv2D::Input::INPUT)}; |
81 | | - const auto ker_index{node.getInputs().at(Conv2D::Input::KERNEL)}; |
82 | | - const auto bias_index{node.getInputs().at(Conv2D::Input::BIAS)}; |
83 | | - |
84 | | - auto ofm_tensor = _tensor_reg->getPortableTensor(ofm_index); |
85 | | - auto ifm_tensor = _tensor_reg->getPortableTensor(ifm_index); |
86 | | - auto ker_tensor = _tensor_reg->getPortableTensor(ker_index); |
87 | | - auto bias_tensor = _tensor_reg->getPortableTensor(bias_index); |
88 | | - |
89 | | - const auto stride = node.param().stride; |
90 | | - const auto activation = node.param().activation; |
91 | | - const auto ¶m_padding = node.param().padding; |
92 | | - const auto dilation = node.param().dilation; |
93 | | - auto fn = std::make_unique<ops::ConvolutionLayer>(); |
94 | | - |
95 | | - if (_ctx.at(ifm_index).info().isDynamic() || _ctx.at(ker_index).info().isDynamic()) |
96 | | - { |
97 | | - fn->configure(ifm_tensor, ker_tensor, bias_tensor, param_padding.type, param_padding.param.left, |
98 | | - param_padding.param.right, param_padding.param.top, param_padding.param.bottom, |
99 | | - stride.horizontal, stride.vertical, dilation.width_factor, dilation.height_factor, |
100 | | - activation, ofm_tensor, _external_context); |
101 | | - |
102 | | - _return_fn = std::move(fn); |
103 | | - return; |
104 | | - } |
105 | | - const auto ifm_shape = _ctx.at(ifm_index).shape().asFeature(); |
106 | | - const auto ofm_shape = _ctx.at(ofm_index).shape().asFeature(); |
107 | | - // Kernel format is [depth_out, kernel_height, kernel_width, depth_in]. |
108 | | - const auto &ker_shape = _ctx.at(ker_index).shape(); |
109 | | - const auto ker_height = ker_shape.dim(1); |
110 | | - const auto ker_width = ker_shape.dim(2); |
111 | | - |
112 | | - const auto padding = |
113 | | - ir::calculatePadding(param_padding, ifm_shape, ofm_shape, stride, ker_width, ker_height, |
114 | | - dilation.width_factor, dilation.height_factor); |
115 | | - |
116 | | - fn->configure(ifm_tensor, ker_tensor, bias_tensor, param_padding.type, padding.left, |
117 | | - padding.right, padding.top, padding.bottom, stride.horizontal, stride.vertical, |
118 | | - dilation.width_factor, dilation.height_factor, activation, ofm_tensor, |
119 | | - _external_context); |
120 | | - |
121 | | - _return_fn = std::move(fn); |
122 | | -} |
123 | | - |
124 | | -void KernelGenerator::visit(const ir::operation::FullyConnected &node) |
125 | | -{ |
126 | | - using ir::operation::FullyConnected; |
127 | | - |
128 | | - const auto output_index{node.getOutputs().at(0)}; |
129 | | - const auto input_index{node.getInputs().at(FullyConnected::Input::INPUT)}; |
130 | | - const auto weight_index{node.getInputs().at(FullyConnected::Input::WEIGHT)}; |
131 | | - const auto bias_index{node.getInputs().at(FullyConnected::Input::BIAS)}; |
132 | | - const auto activation = node.param().activation; |
133 | | - const auto weights_format = node.param().weights_format; |
134 | | - if (weights_format != ir::FullyConnectedWeightsFormat::Default) |
135 | | - throw std::runtime_error("Unsupported FullyConnected Weights Format"); |
136 | | - |
137 | | - auto output_tensor = _tensor_reg->getPortableTensor(output_index); |
138 | | - auto input_tensor = _tensor_reg->getPortableTensor(input_index); |
139 | | - auto weight_tensor = _tensor_reg->getPortableTensor(weight_index); |
140 | | - auto bias_tensor = bias_index.undefined() ? nullptr : _tensor_reg->getPortableTensor(bias_index); |
141 | | - |
142 | | - auto fn = std::make_unique<ops::FullyConnectedLayer>(); |
143 | | - |
144 | | - fn->configure(input_tensor, weight_tensor, bias_tensor, activation, output_tensor, |
145 | | - _external_context); |
146 | | - |
147 | | - _return_fn = std::move(fn); |
148 | | -} |
| 72 | +// Visitors for each operation is in ops/<InternalName>Layer.cc file |
149 | 73 |
|
150 | 74 | } // namespace onert::backend::ruy |
0 commit comments