Abe Mbise | 3f0ab6e | 2017-09-01 16:43:47 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2017 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_BOX3X3_FIXTURE |
| 25 | #define ARM_COMPUTE_TEST_BOX3X3_FIXTURE |
| 26 | |
| 27 | #include "arm_compute/core/TensorShape.h" |
| 28 | #include "arm_compute/core/Types.h" |
| 29 | #include "tests/AssetsLibrary.h" |
| 30 | #include "tests/Globals.h" |
| 31 | #include "tests/IAccessor.h" |
| 32 | #include "tests/framework/Asserts.h" |
| 33 | #include "tests/framework/Fixture.h" |
Georgios Pinitas | 5a7e776 | 2017-12-01 16:27:29 +0000 | [diff] [blame] | 34 | #include "tests/validation/reference/Box3x3.h" |
Abe Mbise | 3f0ab6e | 2017-09-01 16:43:47 +0100 | [diff] [blame] | 35 | |
| 36 | #include <random> |
| 37 | |
| 38 | namespace arm_compute |
| 39 | { |
| 40 | namespace test |
| 41 | { |
| 42 | namespace validation |
| 43 | { |
| 44 | template <typename TensorType, typename AccessorType, typename FunctionType, typename T> |
| 45 | class Box3x3ValidationFixture : public framework::Fixture |
| 46 | { |
| 47 | public: |
| 48 | template <typename...> |
| 49 | void setup(TensorShape shape, DataType data_type, BorderMode border_mode) |
| 50 | { |
| 51 | std::mt19937 gen(library->seed()); |
| 52 | std::uniform_int_distribution<uint8_t> distribution(0, 255); |
| 53 | const uint8_t constant_border_value = distribution(gen); |
| 54 | |
Gian Marco | 1a39f6d | 2017-11-08 10:19:21 +0000 | [diff] [blame] | 55 | _border_mode = border_mode; |
| 56 | _target = compute_target(shape, data_type, border_mode, constant_border_value); |
| 57 | _reference = compute_reference(shape, data_type, border_mode, constant_border_value); |
Abe Mbise | 3f0ab6e | 2017-09-01 16:43:47 +0100 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | protected: |
| 61 | template <typename U> |
| 62 | void fill(U &&tensor) |
| 63 | { |
| 64 | library->fill_tensor_uniform(tensor, 0); |
| 65 | } |
| 66 | |
| 67 | TensorType compute_target(const TensorShape &shape, DataType data_type, BorderMode border_mode, uint8_t constant_border_value) |
| 68 | { |
| 69 | // Create tensors |
| 70 | TensorType src = create_tensor<TensorType>(shape, data_type); |
| 71 | TensorType dst = create_tensor<TensorType>(shape, data_type); |
| 72 | |
| 73 | // Create and configure function |
| 74 | FunctionType box3x3; |
| 75 | box3x3.configure(&src, &dst, border_mode, constant_border_value); |
| 76 | |
| 77 | ARM_COMPUTE_EXPECT(src.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 78 | ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 79 | |
| 80 | // Allocate tensors |
| 81 | src.allocator()->allocate(); |
| 82 | dst.allocator()->allocate(); |
| 83 | |
| 84 | ARM_COMPUTE_EXPECT(!src.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 85 | ARM_COMPUTE_EXPECT(!dst.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 86 | |
| 87 | // Fill tensors |
| 88 | fill(AccessorType(src)); |
| 89 | |
| 90 | // Compute function |
| 91 | box3x3.run(); |
| 92 | |
| 93 | return dst; |
| 94 | } |
| 95 | |
| 96 | SimpleTensor<T> compute_reference(const TensorShape &shape, DataType data_type, BorderMode border_mode, uint8_t constant_border_value) |
| 97 | { |
| 98 | ARM_COMPUTE_ERROR_ON(data_type != DataType::U8); |
| 99 | |
| 100 | // Create reference |
| 101 | SimpleTensor<T> src{ shape, data_type }; |
| 102 | |
| 103 | // Fill reference |
| 104 | fill(src); |
| 105 | |
| 106 | // Compute reference |
| 107 | return reference::box3x3<T>(src, border_mode, constant_border_value); |
| 108 | } |
| 109 | |
| 110 | BorderMode _border_mode{}; |
| 111 | TensorType _target{}; |
| 112 | SimpleTensor<T> _reference{}; |
| 113 | }; |
| 114 | } // namespace validation |
| 115 | } // namespace test |
| 116 | } // namespace arm_compute |
| 117 | #endif /* ARM_COMPUTE_TEST_BOX3X3_FIXTURE */ |