Giorgio Arena | 93a690e | 2017-08-01 16:09:33 +0100 | [diff] [blame] | 1 | /* |
Usama Arif | e73686a | 2019-04-08 17:30:48 +0100 | [diff] [blame] | 2 | * Copyright (c) 2017-2019 ARM Limited. |
Giorgio Arena | 93a690e | 2017-08-01 16:09:33 +0100 | [diff] [blame] | 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_DEPTHWISECONVOLUTIONFIXTURE |
| 25 | #define ARM_COMPUTE_TEST_DEPTHWISECONVOLUTIONFIXTURE |
| 26 | |
| 27 | #include "arm_compute/core/TensorShape.h" |
| 28 | #include "arm_compute/core/Types.h" |
Giorgio Arena | 7657224 | 2018-04-04 17:44:26 +0100 | [diff] [blame] | 29 | #include "arm_compute/core/utils/misc/ShapeCalculator.h" |
Giorgio Arena | 93a690e | 2017-08-01 16:09:33 +0100 | [diff] [blame] | 30 | #include "tests/Globals.h" |
| 31 | #include "tests/Utils.h" |
Moritz Pflanzer | a09de0c | 2017-09-01 20:41:12 +0100 | [diff] [blame] | 32 | #include "tests/framework/Fixture.h" |
Giorgio Arena | 93a690e | 2017-08-01 16:09:33 +0100 | [diff] [blame] | 33 | |
| 34 | namespace arm_compute |
| 35 | { |
| 36 | namespace test |
| 37 | { |
Michalis Spyrou | 724079d | 2017-12-15 11:37:37 +0000 | [diff] [blame] | 38 | namespace benchmark |
| 39 | { |
Giorgio Arena | 7657224 | 2018-04-04 17:44:26 +0100 | [diff] [blame] | 40 | using namespace arm_compute::misc::shape_calculator; |
| 41 | |
Giorgio Arena | 93a690e | 2017-08-01 16:09:33 +0100 | [diff] [blame] | 42 | /** Fixture that can be used for NEON and CL */ |
| 43 | template <typename TensorType, typename Function, typename Accessor> |
Giorgio Arena | 04a8f8c | 2017-11-23 11:45:24 +0000 | [diff] [blame] | 44 | class DepthwiseConvolutionLayerFixture : public framework::Fixture |
Giorgio Arena | 93a690e | 2017-08-01 16:09:33 +0100 | [diff] [blame] | 45 | { |
| 46 | public: |
| 47 | template <typename...> |
Usama Arif | e73686a | 2019-04-08 17:30:48 +0100 | [diff] [blame] | 48 | void setup(TensorShape src_shape, Size2D kernel_size, PadStrideInfo info, Size2D Dilation, DataType data_type, int batches) |
Giorgio Arena | 93a690e | 2017-08-01 16:09:33 +0100 | [diff] [blame] | 49 | { |
Giorgio Arena | 7657224 | 2018-04-04 17:44:26 +0100 | [diff] [blame] | 50 | // Get shapes |
| 51 | TensorShape weights_shape(kernel_size.width, kernel_size.height); |
| 52 | |
| 53 | const TensorInfo in_info(src_shape, 1, data_type); |
| 54 | const TensorInfo we_info(weights_shape, 1, data_type); |
| 55 | TensorShape dst_shape = compute_depthwise_convolution_shape(in_info, we_info, info, 1); |
| 56 | |
| 57 | weights_shape.set(2, dst_shape.z()); |
| 58 | |
Giorgio Arena | 93a690e | 2017-08-01 16:09:33 +0100 | [diff] [blame] | 59 | // Set batched in source and destination shapes |
Vidhya Sudhan Loganathan | 014333d | 2018-07-02 09:13:49 +0100 | [diff] [blame] | 60 | |
Giorgio Arena | 93a690e | 2017-08-01 16:09:33 +0100 | [diff] [blame] | 61 | src_shape.set(3 /* batch */, batches); |
| 62 | dst_shape.set(3 /* batch */, batches); |
| 63 | |
| 64 | // Create tensors |
Vidhya Sudhan Loganathan | 014333d | 2018-07-02 09:13:49 +0100 | [diff] [blame] | 65 | src = create_tensor<TensorType>(src_shape, data_type, 1, QuantizationInfo(0.5f, 10)); |
| 66 | weights = create_tensor<TensorType>(weights_shape, data_type, 1, QuantizationInfo(0.5f, 10)); |
| 67 | biases = create_tensor<TensorType>(TensorShape(weights_shape[2]), is_data_type_quantized_asymmetric(data_type) ? DataType::S32 : data_type, 1); |
| 68 | dst = create_tensor<TensorType>(dst_shape, data_type, 1, QuantizationInfo(0.5f, 10)); |
Giorgio Arena | 93a690e | 2017-08-01 16:09:33 +0100 | [diff] [blame] | 69 | |
| 70 | // Create and configure function |
Giorgio Arena | 82afedf | 2017-11-15 13:36:15 +0000 | [diff] [blame] | 71 | depth_conv.configure(&src, &weights, &biases, &dst, info); |
Giorgio Arena | 93a690e | 2017-08-01 16:09:33 +0100 | [diff] [blame] | 72 | |
| 73 | // Allocate tensors |
| 74 | src.allocator()->allocate(); |
| 75 | weights.allocator()->allocate(); |
Georgios Pinitas | 81a26ad | 2017-10-23 20:29:30 +0100 | [diff] [blame] | 76 | biases.allocator()->allocate(); |
Giorgio Arena | 93a690e | 2017-08-01 16:09:33 +0100 | [diff] [blame] | 77 | dst.allocator()->allocate(); |
Giorgio Arena | 93a690e | 2017-08-01 16:09:33 +0100 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | void run() |
| 81 | { |
| 82 | depth_conv.run(); |
| 83 | } |
| 84 | |
Joel Liang | 1c5ffd6 | 2017-12-28 10:09:51 +0800 | [diff] [blame] | 85 | void sync() |
| 86 | { |
| 87 | sync_if_necessary<TensorType>(); |
| 88 | sync_tensor_if_necessary<TensorType>(dst); |
| 89 | } |
| 90 | |
Giorgio Arena | 93a690e | 2017-08-01 16:09:33 +0100 | [diff] [blame] | 91 | void teardown() |
| 92 | { |
| 93 | src.allocator()->free(); |
| 94 | weights.allocator()->free(); |
Georgios Pinitas | 81a26ad | 2017-10-23 20:29:30 +0100 | [diff] [blame] | 95 | biases.allocator()->free(); |
Giorgio Arena | 93a690e | 2017-08-01 16:09:33 +0100 | [diff] [blame] | 96 | dst.allocator()->free(); |
| 97 | } |
| 98 | |
| 99 | private: |
| 100 | TensorType src{}; |
| 101 | TensorType weights{}; |
Georgios Pinitas | 81a26ad | 2017-10-23 20:29:30 +0100 | [diff] [blame] | 102 | TensorType biases{}; |
Giorgio Arena | 93a690e | 2017-08-01 16:09:33 +0100 | [diff] [blame] | 103 | TensorType dst{}; |
| 104 | Function depth_conv{}; |
| 105 | }; |
Michalis Spyrou | 724079d | 2017-12-15 11:37:37 +0000 | [diff] [blame] | 106 | } // namespace benchmark |
Giorgio Arena | 93a690e | 2017-08-01 16:09:33 +0100 | [diff] [blame] | 107 | } // namespace test |
| 108 | } // namespace arm_compute |
| 109 | #endif /* ARM_COMPUTE_TEST_DEPTHWISECONVOLUTIONFIXTURE */ |