blob: 33753bcd07707b75d8956d22bc245fb9448ac25c [file] [log] [blame]
Giorgio Arena93a690e2017-08-01 16:09:33 +01001/*
Usama Arife73686a2019-04-08 17:30:48 +01002 * Copyright (c) 2017-2019 ARM Limited.
Giorgio Arena93a690e2017-08-01 16:09:33 +01003 *
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 Arena76572242018-04-04 17:44:26 +010029#include "arm_compute/core/utils/misc/ShapeCalculator.h"
Giorgio Arena93a690e2017-08-01 16:09:33 +010030#include "tests/Globals.h"
31#include "tests/Utils.h"
Moritz Pflanzera09de0c2017-09-01 20:41:12 +010032#include "tests/framework/Fixture.h"
Giorgio Arena93a690e2017-08-01 16:09:33 +010033
34namespace arm_compute
35{
36namespace test
37{
Michalis Spyrou724079d2017-12-15 11:37:37 +000038namespace benchmark
39{
Giorgio Arena76572242018-04-04 17:44:26 +010040using namespace arm_compute::misc::shape_calculator;
41
Giorgio Arena93a690e2017-08-01 16:09:33 +010042/** Fixture that can be used for NEON and CL */
43template <typename TensorType, typename Function, typename Accessor>
Giorgio Arena04a8f8c2017-11-23 11:45:24 +000044class DepthwiseConvolutionLayerFixture : public framework::Fixture
Giorgio Arena93a690e2017-08-01 16:09:33 +010045{
46public:
47 template <typename...>
Usama Arife73686a2019-04-08 17:30:48 +010048 void setup(TensorShape src_shape, Size2D kernel_size, PadStrideInfo info, Size2D Dilation, DataType data_type, int batches)
Giorgio Arena93a690e2017-08-01 16:09:33 +010049 {
Giorgio Arena76572242018-04-04 17:44:26 +010050 // 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 Arena93a690e2017-08-01 16:09:33 +010059 // Set batched in source and destination shapes
Vidhya Sudhan Loganathan014333d2018-07-02 09:13:49 +010060
Giorgio Arena93a690e2017-08-01 16:09:33 +010061 src_shape.set(3 /* batch */, batches);
62 dst_shape.set(3 /* batch */, batches);
63
64 // Create tensors
Vidhya Sudhan Loganathan014333d2018-07-02 09:13:49 +010065 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 Arena93a690e2017-08-01 16:09:33 +010069
70 // Create and configure function
Giorgio Arena82afedf2017-11-15 13:36:15 +000071 depth_conv.configure(&src, &weights, &biases, &dst, info);
Giorgio Arena93a690e2017-08-01 16:09:33 +010072
73 // Allocate tensors
74 src.allocator()->allocate();
75 weights.allocator()->allocate();
Georgios Pinitas81a26ad2017-10-23 20:29:30 +010076 biases.allocator()->allocate();
Giorgio Arena93a690e2017-08-01 16:09:33 +010077 dst.allocator()->allocate();
Giorgio Arena93a690e2017-08-01 16:09:33 +010078 }
79
80 void run()
81 {
82 depth_conv.run();
83 }
84
Joel Liang1c5ffd62017-12-28 10:09:51 +080085 void sync()
86 {
87 sync_if_necessary<TensorType>();
88 sync_tensor_if_necessary<TensorType>(dst);
89 }
90
Giorgio Arena93a690e2017-08-01 16:09:33 +010091 void teardown()
92 {
93 src.allocator()->free();
94 weights.allocator()->free();
Georgios Pinitas81a26ad2017-10-23 20:29:30 +010095 biases.allocator()->free();
Giorgio Arena93a690e2017-08-01 16:09:33 +010096 dst.allocator()->free();
97 }
98
99private:
100 TensorType src{};
101 TensorType weights{};
Georgios Pinitas81a26ad2017-10-23 20:29:30 +0100102 TensorType biases{};
Giorgio Arena93a690e2017-08-01 16:09:33 +0100103 TensorType dst{};
104 Function depth_conv{};
105};
Michalis Spyrou724079d2017-12-15 11:37:37 +0000106} // namespace benchmark
Giorgio Arena93a690e2017-08-01 16:09:33 +0100107} // namespace test
108} // namespace arm_compute
109#endif /* ARM_COMPUTE_TEST_DEPTHWISECONVOLUTIONFIXTURE */