blob: 5a1a29612c2c0615bebad0ba12300a1b20faa944 [file] [log] [blame]
Moritz Pflanzeree493ae2017-07-05 10:52:21 +01001/*
Anthony Barbier72856ab2018-01-11 10:45:24 +00002 * Copyright (c) 2017-2018 ARM Limited.
Moritz Pflanzeree493ae2017-07-05 10:52:21 +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_POOLINGLAYERFIXTURE
25#define ARM_COMPUTE_TEST_POOLINGLAYERFIXTURE
26
27#include "arm_compute/core/TensorShape.h"
28#include "arm_compute/core/Types.h"
Giorgio Arena3c520c52018-05-01 11:47:24 +010029#include "arm_compute/core/utils/misc/ShapeCalculator.h"
Moritz Pflanzeree493ae2017-07-05 10:52:21 +010030#include "tests/Globals.h"
31#include "tests/Utils.h"
Moritz Pflanzera09de0c2017-09-01 20:41:12 +010032#include "tests/framework/Fixture.h"
Moritz Pflanzeree493ae2017-07-05 10:52:21 +010033
34namespace arm_compute
35{
36namespace test
37{
Michalis Spyrou724079d2017-12-15 11:37:37 +000038namespace benchmark
39{
Giorgio Arena3c520c52018-05-01 11:47:24 +010040using namespace arm_compute::misc::shape_calculator;
41
Moritz Pflanzeree493ae2017-07-05 10:52:21 +010042/** Fixture that can be used for NEON and CL */
43template <typename TensorType, typename Function, typename Accessor>
44class PoolingLayerFixture : public framework::Fixture
45{
46public:
Moritz Pflanzerb6c8d242017-07-18 13:42:54 +010047 template <typename...>
Giorgio Arena3c520c52018-05-01 11:47:24 +010048 void setup(TensorShape src_shape, PoolingLayerInfo info, DataType data_type, DataLayout data_layout, int batches)
Moritz Pflanzeree493ae2017-07-05 10:52:21 +010049 {
50 // Set batched in source and destination shapes
51 const unsigned int fixed_point_position = 4;
Giorgio Arena3c520c52018-05-01 11:47:24 +010052
Georgios Pinitasb7f5d172018-05-08 11:26:06 +010053 // Permute shape if NHWC format
54 if(data_layout == DataLayout::NHWC)
55 {
56 permute(src_shape, PermutationVector(2U, 0U, 1U));
57 }
58
Giorgio Arena3c520c52018-05-01 11:47:24 +010059 TensorInfo src_info(src_shape, 1, data_type, fixed_point_position);
60 src_info.set_data_layout(data_layout);
61
62 TensorShape dst_shape = compute_pool_shape(src_info, info);
63
Moritz Pflanzeree493ae2017-07-05 10:52:21 +010064 src_shape.set(src_shape.num_dimensions(), batches);
65 dst_shape.set(dst_shape.num_dimensions(), batches);
66
67 // Create tensors
Michalis Spyrou57dac842018-03-01 16:03:50 +000068 src = create_tensor<TensorType>(src_shape, data_type, 1, fixed_point_position, QuantizationInfo(), data_layout);
69 dst = create_tensor<TensorType>(dst_shape, data_type, 1, fixed_point_position, QuantizationInfo(), data_layout);
Moritz Pflanzeree493ae2017-07-05 10:52:21 +010070
71 // Create and configure function
72 pool_layer.configure(&src, &dst, info);
73
74 // Allocate tensors
75 src.allocator()->allocate();
76 dst.allocator()->allocate();
Moritz Pflanzeree493ae2017-07-05 10:52:21 +010077 }
78
79 void run()
80 {
81 pool_layer.run();
82 }
83
Joel Liang1c5ffd62017-12-28 10:09:51 +080084 void sync()
85 {
86 sync_if_necessary<TensorType>();
87 sync_tensor_if_necessary<TensorType>(dst);
88 }
89
Moritz Pflanzeree493ae2017-07-05 10:52:21 +010090 void teardown()
91 {
92 src.allocator()->free();
93 dst.allocator()->free();
94 }
95
96private:
97 TensorType src{};
98 TensorType dst{};
99 Function pool_layer{};
100};
Michalis Spyrou724079d2017-12-15 11:37:37 +0000101} // namespace benchmark
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100102} // namespace test
103} // namespace arm_compute
104#endif /* ARM_COMPUTE_TEST_POOLINGLAYERFIXTURE */