1 /* 2 * Copyright (c) 2017-2020 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 all 14 * copies or substantial portions of the Software. 15 * 16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 * SOFTWARE. 23 */ 24 #ifndef ARM_COMPUTE_TEST_DEPTHWISE_CONVOLUTION_FIXTURE 25 #define ARM_COMPUTE_TEST_DEPTHWISE_CONVOLUTION_FIXTURE 26 27 #include "arm_compute/core/TensorShape.h" 28 #include "arm_compute/core/Types.h" 29 #include "arm_compute/core/utils/misc/ShapeCalculator.h" 30 #include "tests/AssetsLibrary.h" 31 #include "tests/Globals.h" 32 #include "tests/IAccessor.h" 33 #include "tests/framework/Asserts.h" 34 #include "tests/framework/Fixture.h" 35 #include "tests/validation/Helpers.h" 36 #include "tests/validation/reference/ActivationLayer.h" 37 #include "tests/validation/reference/DepthwiseConvolutionLayer.h" 38 39 #include "utils/Utils.h" 40 41 #include <random> 42 43 namespace arm_compute 44 { 45 namespace test 46 { 47 namespace validation 48 { 49 using namespace arm_compute::misc::shape_calculator; 50 51 template <typename TensorType, typename AccessorType, typename FunctionType, typename T, typename TW> 52 class DepthwiseConvolutionLayerValidationGenericFixture : public framework::Fixture 53 { 54 public: 55 using TBias = typename std::conditional < std::is_same<T, uint8_t>::value || std::is_same<T, int8_t>::value, int32_t, T >::type; 56 57 public: 58 template <typename...> setup(TensorShape in_shape,Size2D kernel_size,PadStrideInfo pad_stride_info,Size2D dilation,unsigned int depth_multiplier,DataType input_data_type,DataType weights_data_type,QuantizationInfo input_quantization_info,QuantizationInfo weights_quantization_info,QuantizationInfo output_quantization_info,DataLayout data_layout,ActivationLayerInfo act_info)59 void setup(TensorShape in_shape, Size2D kernel_size, PadStrideInfo pad_stride_info, Size2D dilation, 60 unsigned int depth_multiplier, DataType input_data_type, DataType weights_data_type, 61 QuantizationInfo input_quantization_info, QuantizationInfo weights_quantization_info, QuantizationInfo output_quantization_info, 62 DataLayout data_layout, ActivationLayerInfo act_info) 63 { 64 const DataType bias_data_type = is_data_type_quantized(input_data_type) ? DataType::S32 : input_data_type; 65 66 TensorShape weights_shape(kernel_size.width, kernel_size.height); 67 68 const TensorInfo in_info(in_shape, 1, input_data_type); 69 const TensorInfo we_info(weights_shape, 1, weights_data_type); 70 const TensorShape out_shape = compute_depthwise_convolution_shape(in_info, we_info, pad_stride_info, depth_multiplier, dilation); 71 72 weights_shape.set(2, out_shape.z()); 73 const TensorShape biases_shape(weights_shape[2]); 74 75 _target = compute_target(in_shape, weights_shape, biases_shape, out_shape, pad_stride_info, dilation, depth_multiplier, 76 input_data_type, weights_data_type, bias_data_type, input_quantization_info, weights_quantization_info, output_quantization_info, data_layout, act_info); 77 _reference = compute_reference(in_shape, weights_shape, biases_shape, out_shape, pad_stride_info, dilation, depth_multiplier, 78 input_data_type, weights_data_type, bias_data_type, input_quantization_info, weights_quantization_info, output_quantization_info, act_info); 79 } 80 81 protected: 82 template <typename U> fill(U && tensor,int i)83 void fill(U &&tensor, int i) 84 { 85 switch(tensor.data_type()) 86 { 87 case DataType::QASYMM8: 88 { 89 std::uniform_int_distribution<uint8_t> distribution(0, 10); 90 library->fill(tensor, distribution, i); 91 break; 92 } 93 case DataType::QASYMM8_SIGNED: 94 case DataType::QSYMM8_PER_CHANNEL: 95 { 96 std::uniform_int_distribution<int8_t> distribution(-10, 10); 97 library->fill(tensor, distribution, i); 98 break; 99 } 100 case DataType::F32: 101 case DataType::F16: 102 { 103 std::uniform_real_distribution<> distribution(-1.0f, 1.0f); 104 library->fill(tensor, distribution, i); 105 break; 106 } 107 case DataType::S32: 108 { 109 std::uniform_int_distribution<int32_t> distribution(-100, 100); 110 library->fill(tensor, distribution, i); 111 break; 112 } 113 default: 114 library->fill_tensor_uniform(tensor, i); 115 } 116 } 117 compute_target(TensorShape input_shape,TensorShape weights_shape,TensorShape biases_shape,TensorShape output_shape,PadStrideInfo & pad_stride_info,Size2D dilation,unsigned int depth_multiplier,const DataType input_data_type,const DataType weights_data_type,const DataType bias_data_type,const QuantizationInfo & input_quantization_info,const QuantizationInfo & weights_quantization_info,const QuantizationInfo & output_quantization_info,const DataLayout data_layout,const ActivationLayerInfo & act_info)118 TensorType compute_target(TensorShape input_shape, TensorShape weights_shape, TensorShape biases_shape, TensorShape output_shape, PadStrideInfo &pad_stride_info, Size2D dilation, 119 unsigned int depth_multiplier, const DataType input_data_type, const DataType weights_data_type, const DataType bias_data_type, 120 const QuantizationInfo &input_quantization_info, const QuantizationInfo &weights_quantization_info, const QuantizationInfo &output_quantization_info, 121 const DataLayout data_layout, const ActivationLayerInfo &act_info) 122 { 123 if(data_layout == DataLayout::NHWC) 124 { 125 permute(input_shape, PermutationVector(2U, 0U, 1U)); 126 permute(weights_shape, PermutationVector(2U, 0U, 1U)); 127 permute(output_shape, PermutationVector(2U, 0U, 1U)); 128 } 129 130 // Create tensors 131 TensorType src = create_tensor<TensorType>(input_shape, input_data_type, 1, input_quantization_info, data_layout); 132 TensorType weights = create_tensor<TensorType>(weights_shape, weights_data_type, 1, weights_quantization_info, data_layout); 133 TensorType biases = create_tensor<TensorType>(biases_shape, bias_data_type, 1, input_quantization_info, data_layout); 134 TensorType dst = create_tensor<TensorType>(output_shape, input_data_type, 1, output_quantization_info, data_layout); 135 136 // Create Depthwise Convolution configure function 137 FunctionType dwc; 138 dwc.configure(&src, &weights, &biases, &dst, pad_stride_info, depth_multiplier, act_info, dilation); 139 140 ARM_COMPUTE_EXPECT(src.info()->is_resizable(), framework::LogLevel::ERRORS); 141 ARM_COMPUTE_EXPECT(weights.info()->is_resizable(), framework::LogLevel::ERRORS); 142 ARM_COMPUTE_EXPECT(biases.info()->is_resizable(), framework::LogLevel::ERRORS); 143 ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS); 144 145 // Allocate tensors 146 src.allocator()->allocate(); 147 weights.allocator()->allocate(); 148 biases.allocator()->allocate(); 149 dst.allocator()->allocate(); 150 151 ARM_COMPUTE_EXPECT(!src.info()->is_resizable(), framework::LogLevel::ERRORS); 152 ARM_COMPUTE_EXPECT(!weights.info()->is_resizable(), framework::LogLevel::ERRORS); 153 ARM_COMPUTE_EXPECT(!biases.info()->is_resizable(), framework::LogLevel::ERRORS); 154 ARM_COMPUTE_EXPECT(!dst.info()->is_resizable(), framework::LogLevel::ERRORS); 155 156 // Fill tensors 157 fill(AccessorType(src), 0); 158 fill(AccessorType(weights), 1); 159 fill(AccessorType(biases), 2); 160 161 // Compute function 162 dwc.run(); 163 164 return dst; 165 } 166 compute_reference(const TensorShape & in_shape,const TensorShape & weights_shape,const TensorShape & biases_shape,const TensorShape & out_shape,const PadStrideInfo & pad_stride_info,const Size2D & dilation,unsigned int depth_multiplier,const DataType input_data_type,const DataType weights_data_type,const DataType bias_data_type,const QuantizationInfo & input_quantization_info,const QuantizationInfo & weights_quantization_info,const QuantizationInfo & output_quantization_info,const ActivationLayerInfo & act_info)167 SimpleTensor<T> compute_reference(const TensorShape &in_shape, const TensorShape &weights_shape, const TensorShape &biases_shape, const TensorShape &out_shape, 168 const PadStrideInfo &pad_stride_info, const Size2D &dilation, unsigned int depth_multiplier, 169 const DataType input_data_type, const DataType weights_data_type, const DataType bias_data_type, 170 const QuantizationInfo &input_quantization_info, const QuantizationInfo &weights_quantization_info, const QuantizationInfo &output_quantization_info, 171 const ActivationLayerInfo &act_info) 172 { 173 SimpleTensor<T> src{ in_shape, input_data_type, 1, input_quantization_info }; 174 SimpleTensor<TW> weights{ weights_shape, weights_data_type, 1, weights_quantization_info }; 175 SimpleTensor<TBias> biases{ biases_shape, bias_data_type, 1, input_quantization_info }; 176 177 fill(src, 0); 178 fill(weights, 1); 179 fill(biases, 2); 180 181 SimpleTensor<T> depth_out = reference::depthwise_convolution(src, weights, biases, out_shape, pad_stride_info, depth_multiplier, dilation, output_quantization_info); 182 return (act_info.enabled()) ? reference::activation_layer<T>(depth_out, act_info) : depth_out; 183 } 184 185 TensorType _target{}; 186 SimpleTensor<T> _reference{}; 187 }; 188 189 template <typename TensorType, typename AccessorType, typename FunctionType, typename T> 190 class DepthwiseConvolutionLayerValidationFixture : public DepthwiseConvolutionLayerValidationGenericFixture<TensorType, AccessorType, FunctionType, T, T> 191 { 192 public: 193 template <typename...> setup(TensorShape in_shape,Size2D kernel_size,PadStrideInfo pad_stride_info,Size2D dilation,unsigned int depth_multiplier,DataType data_type,DataLayout data_layout,ActivationLayerInfo act_info)194 void setup(TensorShape in_shape, Size2D kernel_size, PadStrideInfo pad_stride_info, Size2D dilation, unsigned int depth_multiplier, DataType data_type, DataLayout data_layout, 195 ActivationLayerInfo act_info) 196 { 197 DepthwiseConvolutionLayerValidationGenericFixture<TensorType, AccessorType, FunctionType, T, T>::setup(in_shape, kernel_size, pad_stride_info, dilation, depth_multiplier, 198 data_type, data_type, QuantizationInfo(), QuantizationInfo(), QuantizationInfo(), 199 data_layout, act_info); 200 } 201 }; 202 203 template <typename TensorType, typename AccessorType, typename FunctionType, typename T> 204 class DepthwiseConvolutionLayerNativeValidationFixture : public DepthwiseConvolutionLayerValidationGenericFixture<TensorType, AccessorType, FunctionType, T, T> 205 { 206 public: 207 template <typename...> setup(size_t width,size_t height,size_t channel,size_t batch,Size2D kernel_size,size_t depth_multiplier,Size2D dilation,Size2D stride,bool padding_valid,DataType data_type,DataLayout data_layout)208 void setup(size_t width, size_t height, size_t channel, size_t batch, Size2D kernel_size, size_t depth_multiplier, Size2D dilation, Size2D stride, bool padding_valid, DataType data_type, 209 DataLayout data_layout) 210 { 211 const TensorShape src_shape(width, height, channel, batch); 212 const TensorShape weights_shape(kernel_size.width, kernel_size.height, channel * depth_multiplier); 213 const TensorShape biases_shape(weights_shape.z()); 214 215 PadStrideInfo conv_info; 216 if(padding_valid) 217 { 218 conv_info = PadStrideInfo(); 219 } 220 else 221 { 222 conv_info = calculate_same_pad(src_shape, weights_shape, PadStrideInfo(stride.width, stride.height), DataLayout::NCHW, dilation); 223 } 224 225 _target = compute_target(src_shape, weights_shape, biases_shape, conv_info, dilation, depth_multiplier, data_type, data_layout); 226 _reference = compute_reference(src_shape, weights_shape, biases_shape, conv_info, dilation, depth_multiplier, data_type); 227 } 228 229 protected: 230 template <typename U> fill(U && tensor,int i)231 void fill(U &&tensor, int i) 232 { 233 switch(tensor.data_type()) 234 { 235 case DataType::F32: 236 { 237 std::uniform_real_distribution<> distribution(-1.0f, 1.0f); 238 library->fill(tensor, distribution, i); 239 break; 240 } 241 default: 242 library->fill_tensor_uniform(tensor, i); 243 } 244 } 245 compute_target(TensorShape input_shape,TensorShape weights_shape,TensorShape biases_shape,PadStrideInfo & conv_info,Size2D dilation,unsigned int depth_multiplier,const DataType data_type,const DataLayout data_layout)246 TensorType compute_target(TensorShape input_shape, TensorShape weights_shape, TensorShape biases_shape, PadStrideInfo &conv_info, Size2D dilation, 247 unsigned int depth_multiplier, const DataType data_type, const DataLayout data_layout) 248 { 249 if(data_layout == DataLayout::NHWC) 250 { 251 permute(input_shape, PermutationVector(2U, 0U, 1U)); 252 permute(weights_shape, PermutationVector(2U, 0U, 1U)); 253 } 254 255 // Create tensors 256 TensorType src = create_tensor<TensorType>(input_shape, data_type, 1, QuantizationInfo(), data_layout); 257 TensorType weights = create_tensor<TensorType>(weights_shape, data_type, 1, QuantizationInfo(), data_layout); 258 TensorType biases = create_tensor<TensorType>(biases_shape, data_type, 1, QuantizationInfo(), data_layout); 259 TensorType dst = create_tensor<TensorType>(TensorShape(), data_type, 1, QuantizationInfo(), data_layout); 260 261 // Create Depthwise Convolution configure function 262 FunctionType dwc; 263 dwc.configure(&src, &weights, &biases, &dst, conv_info, depth_multiplier, dilation); 264 265 ARM_COMPUTE_EXPECT(src.info()->is_resizable(), framework::LogLevel::ERRORS); 266 ARM_COMPUTE_EXPECT(weights.info()->is_resizable(), framework::LogLevel::ERRORS); 267 ARM_COMPUTE_EXPECT(biases.info()->is_resizable(), framework::LogLevel::ERRORS); 268 ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS); 269 270 // Allocate tensors 271 src.allocator()->allocate(); 272 weights.allocator()->allocate(); 273 biases.allocator()->allocate(); 274 dst.allocator()->allocate(); 275 276 ARM_COMPUTE_EXPECT(!src.info()->is_resizable(), framework::LogLevel::ERRORS); 277 ARM_COMPUTE_EXPECT(!weights.info()->is_resizable(), framework::LogLevel::ERRORS); 278 ARM_COMPUTE_EXPECT(!biases.info()->is_resizable(), framework::LogLevel::ERRORS); 279 ARM_COMPUTE_EXPECT(!dst.info()->is_resizable(), framework::LogLevel::ERRORS); 280 281 // Fill tensors 282 fill(AccessorType(src), 0); 283 fill(AccessorType(weights), 1); 284 fill(AccessorType(biases), 2); 285 286 // Compute function 287 dwc.run(); 288 289 return dst; 290 } 291 compute_reference(const TensorShape & input_shape,const TensorShape & weights_shape,const TensorShape & biases_shape,const PadStrideInfo & conv_info,const Size2D & dilation,unsigned int depth_multiplier,const DataType data_type)292 SimpleTensor<T> compute_reference(const TensorShape &input_shape, const TensorShape &weights_shape, const TensorShape &biases_shape, const PadStrideInfo &conv_info, 293 const Size2D &dilation, unsigned int depth_multiplier, const DataType data_type) 294 { 295 SimpleTensor<T> src{ input_shape, data_type }; 296 SimpleTensor<T> weights{ weights_shape, data_type }; 297 SimpleTensor<T> biases{ biases_shape, data_type }; 298 299 fill(src, 0); 300 fill(weights, 1); 301 fill(biases, 2); 302 303 const TensorShape dst_shape = compute_depthwise_convolution_shape(TensorInfo(input_shape, 1, data_type), TensorInfo(weights_shape, 1, data_type), conv_info, 304 depth_multiplier, dilation); 305 return reference::depthwise_convolution(src, weights, biases, dst_shape, conv_info, depth_multiplier, dilation); 306 } 307 308 TensorType _target{}; 309 SimpleTensor<T> _reference{}; 310 }; 311 312 template <typename TensorType, typename AccessorType, typename FunctionType, typename T> 313 class DepthwiseConvolutionLayerNativeConfigurableValidationFixture : public DepthwiseConvolutionLayerValidationGenericFixture<TensorType, AccessorType, FunctionType, T, T> 314 { 315 public: 316 template <typename...> setup(size_t width,size_t height,size_t channel,size_t batch,Size2D kernel_size,size_t depth_multiplier,Size2D dilation,Size2D stride,bool padding_valid,DataType data_type,DataLayout data_layout,const ActivationLayerInfo & act_info,unsigned int n0)317 void setup(size_t width, size_t height, size_t channel, size_t batch, Size2D kernel_size, size_t depth_multiplier, Size2D dilation, Size2D stride, bool padding_valid, DataType data_type, 318 DataLayout data_layout, const ActivationLayerInfo &act_info, unsigned int n0) 319 { 320 const TensorShape src_shape(width, height, channel, batch); 321 const TensorShape weights_shape(kernel_size.width, kernel_size.height, channel * depth_multiplier); 322 const TensorShape biases_shape(weights_shape.z()); 323 324 PadStrideInfo conv_info; 325 if(padding_valid) 326 { 327 conv_info = PadStrideInfo(); 328 } 329 else 330 { 331 conv_info = calculate_same_pad(src_shape, weights_shape, PadStrideInfo(stride.width, stride.height), DataLayout::NCHW, dilation); 332 } 333 334 _target = compute_target(src_shape, weights_shape, biases_shape, conv_info, dilation, depth_multiplier, data_type, data_layout, act_info, n0); 335 _reference = compute_reference(src_shape, weights_shape, biases_shape, conv_info, dilation, depth_multiplier, data_type, act_info); 336 } 337 338 protected: 339 template <typename U> fill(U && tensor,int i)340 void fill(U &&tensor, int i) 341 { 342 switch(tensor.data_type()) 343 { 344 case DataType::F32: 345 { 346 std::uniform_real_distribution<> distribution(-1.0f, 1.0f); 347 library->fill(tensor, distribution, i); 348 break; 349 } 350 case DataType::F16: 351 { 352 std::uniform_real_distribution<> distribution(-1.0f, 1.0f); 353 library->fill(tensor, distribution, i); 354 break; 355 } 356 default: 357 library->fill_tensor_uniform(tensor, i); 358 } 359 } 360 compute_target(TensorShape input_shape,TensorShape weights_shape,TensorShape biases_shape,PadStrideInfo & conv_info,Size2D dilation,unsigned int depth_multiplier,const DataType data_type,const DataLayout data_layout,const ActivationLayerInfo & act_info,unsigned int n0)361 TensorType compute_target(TensorShape input_shape, TensorShape weights_shape, TensorShape biases_shape, PadStrideInfo &conv_info, Size2D dilation, 362 unsigned int depth_multiplier, const DataType data_type, const DataLayout data_layout, const ActivationLayerInfo &act_info, unsigned int n0) 363 { 364 if(data_layout == DataLayout::NHWC) 365 { 366 permute(input_shape, PermutationVector(2U, 0U, 1U)); 367 permute(weights_shape, PermutationVector(2U, 0U, 1U)); 368 } 369 370 // Create tensors 371 TensorType src = create_tensor<TensorType>(input_shape, data_type, 1, QuantizationInfo(), data_layout); 372 TensorType weights = create_tensor<TensorType>(weights_shape, data_type, 1, QuantizationInfo(), data_layout); 373 TensorType biases = create_tensor<TensorType>(biases_shape, data_type, 1, QuantizationInfo(), data_layout); 374 TensorType dst = create_tensor<TensorType>(TensorShape(), data_type, 1, QuantizationInfo(), data_layout); 375 376 DWCWeightsKernelInfo dwc_weights_info; 377 dwc_weights_info.n0 = n0; 378 379 DWCKernelInfo dwc_info; 380 dwc_info.activation_info = act_info; 381 382 // Create Depthwise Convolution configure function 383 FunctionType dwc; 384 dwc.configure(&src, &weights, &biases, &dst, dwc_weights_info, dwc_info, conv_info, depth_multiplier, dilation); 385 386 ARM_COMPUTE_EXPECT(src.info()->is_resizable(), framework::LogLevel::ERRORS); 387 ARM_COMPUTE_EXPECT(weights.info()->is_resizable(), framework::LogLevel::ERRORS); 388 ARM_COMPUTE_EXPECT(biases.info()->is_resizable(), framework::LogLevel::ERRORS); 389 ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS); 390 391 // Allocate tensors 392 src.allocator()->allocate(); 393 weights.allocator()->allocate(); 394 biases.allocator()->allocate(); 395 dst.allocator()->allocate(); 396 397 ARM_COMPUTE_EXPECT(!src.info()->is_resizable(), framework::LogLevel::ERRORS); 398 ARM_COMPUTE_EXPECT(!weights.info()->is_resizable(), framework::LogLevel::ERRORS); 399 ARM_COMPUTE_EXPECT(!biases.info()->is_resizable(), framework::LogLevel::ERRORS); 400 ARM_COMPUTE_EXPECT(!dst.info()->is_resizable(), framework::LogLevel::ERRORS); 401 402 // Fill tensors 403 fill(AccessorType(src), 0); 404 fill(AccessorType(weights), 1); 405 fill(AccessorType(biases), 2); 406 407 // Compute function 408 dwc.run(); 409 410 return dst; 411 } 412 compute_reference(const TensorShape & input_shape,const TensorShape & weights_shape,const TensorShape & biases_shape,const PadStrideInfo & conv_info,const Size2D & dilation,unsigned int depth_multiplier,const DataType data_type,const ActivationLayerInfo & act_info)413 SimpleTensor<T> compute_reference(const TensorShape &input_shape, const TensorShape &weights_shape, const TensorShape &biases_shape, const PadStrideInfo &conv_info, 414 const Size2D &dilation, unsigned int depth_multiplier, const DataType data_type, const ActivationLayerInfo &act_info) 415 { 416 SimpleTensor<T> src{ input_shape, data_type }; 417 SimpleTensor<T> weights{ weights_shape, data_type }; 418 SimpleTensor<T> biases{ biases_shape, data_type }; 419 420 fill(src, 0); 421 fill(weights, 1); 422 fill(biases, 2); 423 424 const TensorShape dst_shape = compute_depthwise_convolution_shape(TensorInfo(input_shape, 1, data_type), TensorInfo(weights_shape, 1, data_type), conv_info, 425 depth_multiplier, dilation); 426 return reference::activation_layer(reference::depthwise_convolution(src, weights, biases, dst_shape, conv_info, depth_multiplier, dilation), act_info); 427 } 428 429 TensorType _target{}; 430 SimpleTensor<T> _reference{}; 431 }; 432 433 template <typename TensorType, typename AccessorType, typename FunctionType, typename T> 434 class DepthwiseConvolutionLayerValidationQuantizedFixture : public DepthwiseConvolutionLayerValidationGenericFixture<TensorType, AccessorType, FunctionType, T, T> 435 { 436 public: 437 template <typename...> setup(TensorShape in_shape,Size2D kernel_size,PadStrideInfo pad_stride_info,Size2D dilation,unsigned int depth_multiplier,DataType data_type,QuantizationInfo input_quantization_info,QuantizationInfo output_quantization_info,DataLayout data_layout,ActivationLayerInfo act_info)438 void setup(TensorShape in_shape, Size2D kernel_size, PadStrideInfo pad_stride_info, Size2D dilation, unsigned int depth_multiplier, DataType data_type, 439 QuantizationInfo input_quantization_info, QuantizationInfo output_quantization_info, DataLayout data_layout, ActivationLayerInfo act_info) 440 { 441 DepthwiseConvolutionLayerValidationGenericFixture<TensorType, AccessorType, FunctionType, T, T>::setup(in_shape, kernel_size, pad_stride_info, dilation, depth_multiplier, data_type, 442 data_type, input_quantization_info, input_quantization_info, output_quantization_info, 443 data_layout, act_info); 444 } 445 }; 446 447 template <typename TensorType, typename AccessorType, typename FunctionType, typename T, typename TW> 448 class DepthwiseConvolutionLayerValidationQuantizedPerChannelFixture : public DepthwiseConvolutionLayerValidationGenericFixture<TensorType, AccessorType, FunctionType, T, TW> 449 { 450 public: 451 template <typename...> setup(TensorShape in_shape,Size2D kernel_size,PadStrideInfo pad_stride_info,Size2D dilation,unsigned int depth_multiplier,DataType input_data_type,DataType weights_data_type,QuantizationInfo input_quantization_info,QuantizationInfo output_quantization_info,DataLayout data_layout,ActivationLayerInfo act_info)452 void setup(TensorShape in_shape, Size2D kernel_size, PadStrideInfo pad_stride_info, Size2D dilation, unsigned int depth_multiplier, DataType input_data_type, DataType weights_data_type, 453 QuantizationInfo input_quantization_info, QuantizationInfo output_quantization_info, DataLayout data_layout, ActivationLayerInfo act_info) 454 { 455 const float out_scale = output_quantization_info.uniform().scale; 456 const float in_scale = input_quantization_info.uniform().scale; 457 458 std::vector<float> weights_scales{}; 459 std::mt19937 gen(library->seed()); 460 std::uniform_real_distribution<> dis(0.01f, out_scale / in_scale); 461 for(size_t i = 0; i < in_shape.z() * depth_multiplier; ++i) 462 { 463 weights_scales.push_back(dis(gen)); 464 } 465 466 DepthwiseConvolutionLayerValidationGenericFixture<TensorType, AccessorType, FunctionType, T, TW>::setup(in_shape, kernel_size, pad_stride_info, dilation, depth_multiplier, 467 input_data_type, weights_data_type, 468 input_quantization_info, QuantizationInfo(weights_scales), output_quantization_info, 469 data_layout, act_info); 470 } 471 }; 472 } // namespace validation 473 } // namespace test 474 } // namespace arm_compute 475 #endif /* ARM_COMPUTE_TEST_DEPTHWISE_CONVOLUTION_FIXTURE */ 476