• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2019 Arm Limited.
3  *
4  * SPDX-License-Identifier: MIT
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to
8  * deal in the Software without restriction, including without limitation the
9  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10  * sell copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in
14  * all
15  * copies or substantial portions of the Software.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23  * SOFTWARE.
24  */
25 
26 #include "depthwise_quantized_dilated.hpp"
27 #include "impl_dilated.hpp"
28 
29 namespace depthwise {
30 
31 template <unsigned int OutputTileRows, unsigned int OutputTileCols,
32           unsigned int KernelRows, unsigned int KernelCols,
33           unsigned int StrideRows, unsigned int StrideCols>
34 QAsymm8DilatedDepthwiseConvolution<OutputTileRows, OutputTileCols, KernelRows,
35                                    KernelCols, StrideRows, StrideCols>::
QAsymm8DilatedDepthwiseConvolution(int n_batches,int n_input_rows,int n_input_cols,int n_channels,int dilation_factor,nck::ActivationFunction activation,const qasymm8::QAsymm8Params & weight_quantisation,const qasymm8::QAsymm8Params & input_quantisation,const qasymm8::QAsymm8Params & output_quantisation,unsigned int padding_top,unsigned int padding_left,unsigned int padding_bottom,unsigned int padding_right)36     QAsymm8DilatedDepthwiseConvolution(
37         int n_batches, int n_input_rows, int n_input_cols, int n_channels,
38         int dilation_factor, nck::ActivationFunction activation,
39         const qasymm8::QAsymm8Params &weight_quantisation,
40         const qasymm8::QAsymm8Params &input_quantisation,
41         const qasymm8::QAsymm8Params &output_quantisation,
42         unsigned int padding_top, unsigned int padding_left,
43         unsigned int padding_bottom, unsigned int padding_right)
44     : QAsymm8DilatedDepthwiseConvolution(
45           n_batches, n_input_rows, n_input_cols, n_channels, dilation_factor,
46           QAsymm8DilatedDepthwiseConvolution::get_output_size(
47               n_input_rows, padding_top, padding_bottom, dilation_factor),
48           QAsymm8DilatedDepthwiseConvolution::get_output_size(
49               n_input_cols, padding_left, padding_right, dilation_factor),
50           activation, weight_quantisation, input_quantisation,
51           output_quantisation, padding_top, padding_left, padding_bottom,
52           padding_right) {}
53 
54 template <unsigned int OutputTileRows, unsigned int OutputTileCols,
55           unsigned int KernelRows, unsigned int KernelCols,
56           unsigned int StrideRows, unsigned int StrideCols>
57 QAsymm8DilatedDepthwiseConvolution<OutputTileRows, OutputTileCols, KernelRows,
58                                    KernelCols, StrideRows, StrideCols>::
QAsymm8DilatedDepthwiseConvolution(int n_batches,int n_input_rows,int n_input_cols,int n_channels,int dilation_factor,int n_output_rows,int n_output_cols,nck::ActivationFunction activation,const qasymm8::QAsymm8Params & weight_quantisation,const qasymm8::QAsymm8Params & input_quantisation,const qasymm8::QAsymm8Params & output_quantisation,unsigned int padding_top,unsigned int padding_left,unsigned int padding_bottom,unsigned int padding_right)59     QAsymm8DilatedDepthwiseConvolution(
60         int n_batches, int n_input_rows, int n_input_cols, int n_channels,
61         int dilation_factor, int n_output_rows, int n_output_cols,
62         nck::ActivationFunction activation,
63         const qasymm8::QAsymm8Params &weight_quantisation,
64         const qasymm8::QAsymm8Params &input_quantisation,
65         const qasymm8::QAsymm8Params &output_quantisation,
66         unsigned int padding_top, unsigned int padding_left,
67         unsigned int padding_bottom, unsigned int padding_right)
68     : QAsymm8DilatedDepthwiseConvolution(
69           n_batches, n_input_rows, n_input_cols, n_channels, dilation_factor,
70           n_output_rows, n_output_cols, activation, weight_quantisation,
71           input_quantisation, output_quantisation,
72           qasymm8::QAsymm8RescaleParams::make_rescale_params(
73               weight_quantisation, input_quantisation, output_quantisation),
74           padding_top, padding_left, padding_bottom, padding_right) {}
75 
76 template <unsigned int OutputTileRows, unsigned int OutputTileCols,
77           unsigned int KernelRows, unsigned int KernelCols,
78           unsigned int StrideRows, unsigned int StrideCols>
79 QAsymm8DilatedDepthwiseConvolution<OutputTileRows, OutputTileCols, KernelRows,
80                                    KernelCols, StrideRows, StrideCols>::
QAsymm8DilatedDepthwiseConvolution(int n_batches,int n_input_rows,int n_input_cols,int n_channels,int dilation_factor,nck::ActivationFunction activation,const qasymm8::QAsymm8Params & weight_quantisation,const qasymm8::QAsymm8Params & input_quantisation,const qasymm8::QAsymm8Params & output_quantisation,const qasymm8::QAsymm8RescaleParams & rescale_parameters,unsigned int padding_top,unsigned int padding_left,unsigned int padding_bottom,unsigned int padding_right)81     QAsymm8DilatedDepthwiseConvolution(
82         int n_batches, int n_input_rows, int n_input_cols, int n_channels,
83         int dilation_factor, nck::ActivationFunction activation,
84         const qasymm8::QAsymm8Params &weight_quantisation,
85         const qasymm8::QAsymm8Params &input_quantisation,
86         const qasymm8::QAsymm8Params &output_quantisation,
87         const qasymm8::QAsymm8RescaleParams &rescale_parameters,
88         unsigned int padding_top, unsigned int padding_left,
89         unsigned int padding_bottom, unsigned int padding_right)
90     : QAsymm8DilatedDepthwiseConvolution(
91           n_batches, n_input_rows, n_input_cols, n_channels, dilation_factor,
92           QAsymm8DilatedDepthwiseConvolution::get_output_size(
93               n_input_rows, padding_top, padding_bottom, dilation_factor),
94           QAsymm8DilatedDepthwiseConvolution::get_output_size(
95               n_input_cols, padding_left, padding_right, dilation_factor),
96           activation, weight_quantisation, input_quantisation,
97           output_quantisation, rescale_parameters, padding_top, padding_left,
98           padding_bottom, padding_right) {}
99 
100 template <unsigned int OutputTileRows, unsigned int OutputTileCols,
101           unsigned int KernelRows, unsigned int KernelCols,
102           unsigned int StrideRows, unsigned int StrideCols>
103 QAsymm8DilatedDepthwiseConvolution<OutputTileRows, OutputTileCols, KernelRows,
104                                    KernelCols, StrideRows, StrideCols>::
QAsymm8DilatedDepthwiseConvolution(int n_batches,int n_input_rows,int n_input_cols,int n_channels,int dilation_factor,int n_output_rows,int n_output_cols,nck::ActivationFunction activation,const qasymm8::QAsymm8Params & weight_quantisation,const qasymm8::QAsymm8Params & input_quantisation,const qasymm8::QAsymm8Params & output_quantisation,const qasymm8::QAsymm8RescaleParams & rescale_parameters,unsigned int padding_top,unsigned int padding_left,unsigned int padding_bottom,unsigned int padding_right)105     QAsymm8DilatedDepthwiseConvolution(
106         int n_batches, int n_input_rows, int n_input_cols, int n_channels,
107         int dilation_factor, int n_output_rows, int n_output_cols,
108         nck::ActivationFunction activation,
109         const qasymm8::QAsymm8Params &weight_quantisation,
110         const qasymm8::QAsymm8Params &input_quantisation,
111         const qasymm8::QAsymm8Params &output_quantisation,
112         const qasymm8::QAsymm8RescaleParams &rescale_parameters,
113         unsigned int padding_top, unsigned int padding_left,
114         unsigned int padding_bottom, unsigned int padding_right)
115     : DilatedDepthwiseConvolution<OutputTileRows, OutputTileCols, KernelRows,
116                                   KernelCols, StrideRows, StrideCols, uint8_t,
117                                   int32_t, uint8_t>(
118           n_batches, n_input_rows, n_input_cols, n_channels, dilation_factor,
119           n_output_rows, n_output_cols, activation, padding_top, padding_left,
120           padding_bottom, padding_right,
121           [weight_quantisation, input_quantisation, output_quantisation,
122            rescale_parameters](
123               const int n_batches, const int n_input_rows,
124               const int n_input_cols, const int n_channels,
125               const int n_output_rows, const int n_output_cols,
126               const nck::ActivationFunction activation,
127               const unsigned int padding_top, const unsigned int padding_left,
128               const unsigned int padding_bottom,
129               const unsigned int padding_right) -> IDepthwiseConvolution * {
130             return new QAsymm8DepthwiseConvolution<
131                 OutputTileRows, OutputTileCols, KernelRows, KernelCols,
132                 StrideRows, StrideCols>(
133                 n_batches, n_input_rows, n_input_cols, n_channels,
134                 n_output_rows, n_output_cols, activation, weight_quantisation,
135                 input_quantisation, output_quantisation, rescale_parameters,
136                 padding_top, padding_left, padding_bottom, padding_right);
137           }) {}
138 
139 } // namespace depthwise
140 
141 template class depthwise::QAsymm8DilatedDepthwiseConvolution<2, 2, 3, 3, 1, 1>;
142 template class depthwise::QAsymm8DilatedDepthwiseConvolution<2, 2, 3, 3, 2, 2>;
143 template class depthwise::QAsymm8DilatedDepthwiseConvolution<2, 2, 5, 5, 1, 1>;
144 template class depthwise::QAsymm8DilatedDepthwiseConvolution<2, 2, 5, 5, 2, 2>;
145