blob: 09da816fd4e3da3b5befe0bd27dddcf9047dfd4f [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 {
Michalis Spyrou6bff1952019-10-02 17:22:11 +010050 ARM_COMPUTE_UNUSED(Dilation);
51
Giorgio Arena76572242018-04-04 17:44:26 +010052 // Get shapes
53 TensorShape weights_shape(kernel_size.width, kernel_size.height);
54
55 const TensorInfo in_info(src_shape, 1, data_type);
56 const TensorInfo we_info(weights_shape, 1, data_type);
57 TensorShape dst_shape = compute_depthwise_convolution_shape(in_info, we_info, info, 1);
58
59 weights_shape.set(2, dst_shape.z());
60
Giorgio Arena93a690e2017-08-01 16:09:33 +010061 // Set batched in source and destination shapes
Vidhya Sudhan Loganathan014333d2018-07-02 09:13:49 +010062
Giorgio Arena93a690e2017-08-01 16:09:33 +010063 src_shape.set(3 /* batch */, batches);
64 dst_shape.set(3 /* batch */, batches);
65
66 // Create tensors
Vidhya Sudhan Loganathan014333d2018-07-02 09:13:49 +010067 src = create_tensor<TensorType>(src_shape, data_type, 1, QuantizationInfo(0.5f, 10));
68 weights = create_tensor<TensorType>(weights_shape, data_type, 1, QuantizationInfo(0.5f, 10));
69 biases = create_tensor<TensorType>(TensorShape(weights_shape[2]), is_data_type_quantized_asymmetric(data_type) ? DataType::S32 : data_type, 1);
70 dst = create_tensor<TensorType>(dst_shape, data_type, 1, QuantizationInfo(0.5f, 10));
Giorgio Arena93a690e2017-08-01 16:09:33 +010071
72 // Create and configure function
Giorgio Arena82afedf2017-11-15 13:36:15 +000073 depth_conv.configure(&src, &weights, &biases, &dst, info);
Giorgio Arena93a690e2017-08-01 16:09:33 +010074
75 // Allocate tensors
76 src.allocator()->allocate();
77 weights.allocator()->allocate();
Georgios Pinitas81a26ad2017-10-23 20:29:30 +010078 biases.allocator()->allocate();
Giorgio Arena93a690e2017-08-01 16:09:33 +010079 dst.allocator()->allocate();
Giorgio Arena93a690e2017-08-01 16:09:33 +010080 }
81
82 void run()
83 {
84 depth_conv.run();
85 }
86
Joel Liang1c5ffd62017-12-28 10:09:51 +080087 void sync()
88 {
89 sync_if_necessary<TensorType>();
90 sync_tensor_if_necessary<TensorType>(dst);
91 }
92
Giorgio Arena93a690e2017-08-01 16:09:33 +010093 void teardown()
94 {
95 src.allocator()->free();
96 weights.allocator()->free();
Georgios Pinitas81a26ad2017-10-23 20:29:30 +010097 biases.allocator()->free();
Giorgio Arena93a690e2017-08-01 16:09:33 +010098 dst.allocator()->free();
99 }
100
101private:
102 TensorType src{};
103 TensorType weights{};
Georgios Pinitas81a26ad2017-10-23 20:29:30 +0100104 TensorType biases{};
Giorgio Arena93a690e2017-08-01 16:09:33 +0100105 TensorType dst{};
106 Function depth_conv{};
107};
Michalis Spyrou724079d2017-12-15 11:37:37 +0000108} // namespace benchmark
Giorgio Arena93a690e2017-08-01 16:09:33 +0100109} // namespace test
110} // namespace arm_compute
111#endif /* ARM_COMPUTE_TEST_DEPTHWISECONVOLUTIONFIXTURE */