30 :
Layer(external_context), _input(nullptr), _kernel(nullptr), _bias(nullptr), _output(nullptr),
31 _padding_type(ir::PaddingType::EXPLICIT), _padding_left(0), _padding_top(0), _padding_right(0),
32 _padding_bottom(0), _stride_width(0), _stride_height(0), _dilation_width_factor(1),
33 _dilation_height_factor(1), _activation(ir::Activation::
NONE)
40 const uint32_t padding_left,
const uint32_t padding_right,
41 const uint32_t padding_top,
const uint32_t padding_bottom,
42 const uint32_t stride_width,
const uint32_t stride_height,
43 const uint32_t dilation_width_factor,
44 const uint32_t dilation_height_factor,
50 _padding_type = padding_type;
51 _padding_left = padding_left;
52 _padding_right = padding_right;
53 _padding_top = padding_top;
54 _padding_bottom = padding_bottom;
55 _stride_width = stride_width;
56 _stride_height = stride_height;
57 _dilation_width_factor = dilation_width_factor;
58 _dilation_height_factor = dilation_height_factor;
59 _activation = activation;
91 float output_activation_min = 0.f, output_activation_max = 0.f;
92 CalculateActivationRange<float>(_activation, &output_activation_min, &output_activation_max);
96 const auto &kernel_shape = _kernel->
getShape();
97 uint32_t kernel_height = kernel_shape.dim(1);
98 uint32_t kernel_width = kernel_shape.dim(2);
99 uint32_t output_channels = kernel_shape.dim(0);
100 uint32_t input_channels = kernel_shape.dim(3);
101 assert(
static_cast<uint32_t
>(_input->
getShape().dim(3)) == input_channels);
102 assert(
static_cast<uint32_t
>(_output->
getShape().dim(3)) == output_channels);
104 enum xnn_status status = xnn_create_convolution2d_nhwc_f32(
105 _padding_top, _padding_right, _padding_bottom, _padding_left, kernel_height, kernel_width,
106 _stride_height, _stride_width, _dilation_height_factor, _dilation_width_factor, 1 ,
107 input_channels , output_channels ,
108 input_channels , output_channels ,
109 reinterpret_cast<const float *
>(_kernel->
buffer()),
110 reinterpret_cast<const float *
>(_bias->
buffer()), output_activation_min, output_activation_max,
112 if (status != xnn_status_success)
114 throw std::runtime_error{
"failed to create FP32 Convolution operator"};
122 if (_input->
buffer() ==
nullptr || _output->
buffer() ==
nullptr)
128 uint32_t input_width = _input->
getShape().dim(2);
129 uint32_t input_height = _input->
getShape().dim(1);
130 uint32_t batch_size = _input->
getShape().dim(0);
131 size_t workspace_size = 0;
132 size_t workspace_alignment = 0;
133 enum xnn_status status = xnn_reshape_convolution2d_nhwc_f32(
134 _kernel_op, batch_size, input_height, input_width, &workspace_size, &workspace_alignment,
136 if (status != xnn_status_success)
138 throw std::runtime_error{
"failed to create FP32 DepthwiseConvolution operator"};
141 std::vector<uint8_t> workspace(workspace_size);
142 status = xnn_setup_convolution2d_nhwc_f32(
_kernel_op, workspace.data(),
143 reinterpret_cast<const float *
>(_input->
buffer()),
144 reinterpret_cast<float *
>(_output->
buffer()));
145 if (status != xnn_status_success)
147 throw std::runtime_error{
"failed to create FP32 Convolution operator"};