John Richardson | 25c5603 | 2018-05-04 12:09:19 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2018 ARM Limited. |
| 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_WARP_AFFINE_FIXTURE |
| 25 | #define ARM_COMPUTE_TEST_WARP_AFFINE_FIXTURE |
| 26 | |
| 27 | #include "arm_compute/core/TensorShape.h" |
| 28 | #include "arm_compute/core/Types.h" |
| 29 | #include "tests/Globals.h" |
| 30 | #include "tests/Utils.h" |
| 31 | #include "tests/framework/Fixture.h" |
| 32 | #include "tests/validation/reference/Utils.h" |
| 33 | |
| 34 | namespace arm_compute |
| 35 | { |
| 36 | namespace test |
| 37 | { |
| 38 | namespace benchmark |
| 39 | { |
| 40 | template <typename TensorType, typename Function, typename Accessor> |
| 41 | class WarpAffineFixture : public framework::Fixture |
| 42 | { |
| 43 | public: |
| 44 | template <typename...> |
| 45 | void setup(const TensorShape &shape, DataType data_type, InterpolationPolicy policy, BorderMode border_mode) |
| 46 | { |
| 47 | // Generate a random constant value if border_mode is constant |
| 48 | std::mt19937 gen(library->seed()); |
| 49 | std::uniform_int_distribution<uint8_t> distribution_u8(0, 255); |
| 50 | uint8_t constant_border_value = distribution_u8(gen); |
| 51 | |
| 52 | // Create tensors |
| 53 | src = create_tensor<TensorType>(shape, data_type); |
| 54 | dst = create_tensor<TensorType>(shape, data_type); |
| 55 | |
| 56 | // Create and configure function |
Pablo Tello | d8b03dd | 2018-08-07 11:23:54 +0100 | [diff] [blame] | 57 | warp_affine_func.configure(&src, &dst, matrix, policy, border_mode, constant_border_value); |
John Richardson | 25c5603 | 2018-05-04 12:09:19 +0100 | [diff] [blame] | 58 | |
| 59 | // Allocate tensors |
| 60 | src.allocator()->allocate(); |
| 61 | dst.allocator()->allocate(); |
| 62 | } |
| 63 | |
| 64 | void run() |
| 65 | { |
| 66 | warp_affine_func.run(); |
| 67 | } |
| 68 | |
| 69 | void sync() |
| 70 | { |
| 71 | sync_if_necessary<TensorType>(); |
| 72 | sync_tensor_if_necessary<TensorType>(dst); |
| 73 | } |
| 74 | |
| 75 | void teardown() |
| 76 | { |
| 77 | src.allocator()->free(); |
| 78 | dst.allocator()->free(); |
| 79 | } |
| 80 | |
| 81 | private: |
Pablo Tello | d8b03dd | 2018-08-07 11:23:54 +0100 | [diff] [blame] | 82 | const std::array<float, 9> matrix{ { -0.9f, -0.6f, -0.3f, 0.3f, 0.6f, 0.9f, /* ignored*/ 1.f, 1.f, 1.f } }; |
John Richardson | 25c5603 | 2018-05-04 12:09:19 +0100 | [diff] [blame] | 83 | TensorType src{}; |
| 84 | TensorType dst{}; |
| 85 | Function warp_affine_func{}; |
| 86 | }; |
| 87 | } // namespace benchmark |
| 88 | } // namespace test |
| 89 | } // namespace arm_compute |
| 90 | #endif /* ARM_COMPUTE_TEST_WARP_AFFINE_FIXTURE */ |