Moritz Pflanzer | ee493ae | 2017-07-05 10:52:21 +0100 | [diff] [blame] | 1 | /* |
Anthony Barbier | 72856ab | 2018-01-11 10:45:24 +0000 | [diff] [blame] | 2 | * Copyright (c) 2017-2018 ARM Limited. |
Moritz Pflanzer | ee493ae | 2017-07-05 10:52:21 +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_POOLINGLAYERFIXTURE |
| 25 | #define ARM_COMPUTE_TEST_POOLINGLAYERFIXTURE |
| 26 | |
| 27 | #include "arm_compute/core/TensorShape.h" |
| 28 | #include "arm_compute/core/Types.h" |
Giorgio Arena | 3c520c5 | 2018-05-01 11:47:24 +0100 | [diff] [blame] | 29 | #include "arm_compute/core/utils/misc/ShapeCalculator.h" |
Moritz Pflanzer | ee493ae | 2017-07-05 10:52:21 +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" |
Moritz Pflanzer | ee493ae | 2017-07-05 10:52:21 +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 | 3c520c5 | 2018-05-01 11:47:24 +0100 | [diff] [blame] | 40 | using namespace arm_compute::misc::shape_calculator; |
| 41 | |
Moritz Pflanzer | ee493ae | 2017-07-05 10:52:21 +0100 | [diff] [blame] | 42 | /** Fixture that can be used for NEON and CL */ |
| 43 | template <typename TensorType, typename Function, typename Accessor> |
| 44 | class PoolingLayerFixture : public framework::Fixture |
| 45 | { |
| 46 | public: |
Moritz Pflanzer | b6c8d24 | 2017-07-18 13:42:54 +0100 | [diff] [blame] | 47 | template <typename...> |
Giorgio Arena | 3c520c5 | 2018-05-01 11:47:24 +0100 | [diff] [blame] | 48 | void setup(TensorShape src_shape, PoolingLayerInfo info, DataType data_type, DataLayout data_layout, int batches) |
Moritz Pflanzer | ee493ae | 2017-07-05 10:52:21 +0100 | [diff] [blame] | 49 | { |
| 50 | // Set batched in source and destination shapes |
Giorgio Arena | 3c520c5 | 2018-05-01 11:47:24 +0100 | [diff] [blame] | 51 | |
Georgios Pinitas | b7f5d17 | 2018-05-08 11:26:06 +0100 | [diff] [blame] | 52 | // Permute shape if NHWC format |
| 53 | if(data_layout == DataLayout::NHWC) |
| 54 | { |
| 55 | permute(src_shape, PermutationVector(2U, 0U, 1U)); |
| 56 | } |
| 57 | |
Vidhya Sudhan Loganathan | 014333d | 2018-07-02 09:13:49 +0100 | [diff] [blame] | 58 | TensorInfo src_info(src_shape, 1, data_type); |
Giorgio Arena | 3c520c5 | 2018-05-01 11:47:24 +0100 | [diff] [blame] | 59 | src_info.set_data_layout(data_layout); |
| 60 | |
| 61 | TensorShape dst_shape = compute_pool_shape(src_info, info); |
| 62 | |
Moritz Pflanzer | ee493ae | 2017-07-05 10:52:21 +0100 | [diff] [blame] | 63 | src_shape.set(src_shape.num_dimensions(), batches); |
| 64 | dst_shape.set(dst_shape.num_dimensions(), batches); |
| 65 | |
| 66 | // Create tensors |
Vidhya Sudhan Loganathan | 014333d | 2018-07-02 09:13:49 +0100 | [diff] [blame] | 67 | 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 Pflanzer | ee493ae | 2017-07-05 10:52:21 +0100 | [diff] [blame] | 69 | |
| 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 Pflanzer | ee493ae | 2017-07-05 10:52:21 +0100 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | void run() |
| 79 | { |
| 80 | pool_layer.run(); |
| 81 | } |
| 82 | |
Joel Liang | 1c5ffd6 | 2017-12-28 10:09:51 +0800 | [diff] [blame] | 83 | void sync() |
| 84 | { |
| 85 | sync_if_necessary<TensorType>(); |
| 86 | sync_tensor_if_necessary<TensorType>(dst); |
| 87 | } |
| 88 | |
Moritz Pflanzer | ee493ae | 2017-07-05 10:52:21 +0100 | [diff] [blame] | 89 | void teardown() |
| 90 | { |
| 91 | src.allocator()->free(); |
| 92 | dst.allocator()->free(); |
| 93 | } |
| 94 | |
| 95 | private: |
| 96 | TensorType src{}; |
| 97 | TensorType dst{}; |
| 98 | Function pool_layer{}; |
| 99 | }; |
Michalis Spyrou | 724079d | 2017-12-15 11:37:37 +0000 | [diff] [blame] | 100 | } // namespace benchmark |
Moritz Pflanzer | ee493ae | 2017-07-05 10:52:21 +0100 | [diff] [blame] | 101 | } // namespace test |
| 102 | } // namespace arm_compute |
| 103 | #endif /* ARM_COMPUTE_TEST_POOLINGLAYERFIXTURE */ |