blob: cbcfe2e8695db757a98b282a940e3d6cd119e633 [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
Giorgio Arena3c520c52018-05-01 11:47:24 +010051
Georgios Pinitasb7f5d172018-05-08 11:26:06 +010052 // Permute shape if NHWC format
53 if(data_layout == DataLayout::NHWC)
54 {
55 permute(src_shape, PermutationVector(2U, 0U, 1U));
56 }
57
Vidhya Sudhan Loganathan014333d2018-07-02 09:13:49 +010058 TensorInfo src_info(src_shape, 1, data_type);
Giorgio Arena3c520c52018-05-01 11:47:24 +010059 src_info.set_data_layout(data_layout);
60
61 TensorShape dst_shape = compute_pool_shape(src_info, info);
62
Moritz Pflanzeree493ae2017-07-05 10:52:21 +010063 src_shape.set(src_shape.num_dimensions(), batches);
64 dst_shape.set(dst_shape.num_dimensions(), batches);
65
66 // Create tensors
Vidhya Sudhan Loganathan014333d2018-07-02 09:13:49 +010067 src = create_tensor<TensorType>(src_shape, data_type, 1, QuantizationInfo(), data_layout);
68 dst = create_tensor<TensorType>(dst_shape, data_type, 1, QuantizationInfo(), data_layout);
Moritz Pflanzeree493ae2017-07-05 10:52:21 +010069
70 // Create and configure function
71 pool_layer.configure(&src, &dst, info);
72
73 // Allocate tensors
74 src.allocator()->allocate();
75 dst.allocator()->allocate();
Moritz Pflanzeree493ae2017-07-05 10:52:21 +010076 }
77
78 void run()
79 {
80 pool_layer.run();
81 }
82
Joel Liang1c5ffd62017-12-28 10:09:51 +080083 void sync()
84 {
85 sync_if_necessary<TensorType>();
86 sync_tensor_if_necessary<TensorType>(dst);
87 }
88
Moritz Pflanzeree493ae2017-07-05 10:52:21 +010089 void teardown()
90 {
91 src.allocator()->free();
92 dst.allocator()->free();
93 }
94
95private:
96 TensorType src{};
97 TensorType dst{};
98 Function pool_layer{};
99};
Michalis Spyrou724079d2017-12-15 11:37:37 +0000100} // namespace benchmark
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100101} // namespace test
102} // namespace arm_compute
103#endif /* ARM_COMPUTE_TEST_POOLINGLAYERFIXTURE */