zhenglin | 0fb6cf5 | 2017-12-12 15:56:09 +0800 | [diff] [blame] | 1 | /* |
zhenglin | 2219dea | 2018-01-30 18:15:52 +0800 | [diff] [blame] | 2 | * Copyright (c) 2017-2018 ARM Limited. |
zhenglin | 0fb6cf5 | 2017-12-12 15:56:09 +0800 | [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_NORMALIZE_PLANAR_YUV_LAYER_FIXTURE |
| 25 | #define ARM_COMPUTE_TEST_NORMALIZE_PLANAR_YUV_LAYER_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" |
| 34 | #include "tests/validation/Helpers.h" |
| 35 | #include "tests/validation/reference/NormalizePlanarYUVLayer.h" |
| 36 | |
| 37 | namespace arm_compute |
| 38 | { |
| 39 | namespace test |
| 40 | { |
| 41 | namespace validation |
| 42 | { |
| 43 | template <typename TensorType, typename AccessorType, typename FunctionType, typename T> |
| 44 | class NormalizePlanarYUVLayerValidationFixedPointFixture : public framework::Fixture |
| 45 | { |
| 46 | public: |
| 47 | template <typename...> |
| 48 | void setup(TensorShape shape0, TensorShape shape1, DataType dt) |
| 49 | { |
| 50 | _data_type = dt; |
| 51 | _target = compute_target(shape0, shape1, dt); |
| 52 | _reference = compute_reference(shape0, shape1, dt); |
| 53 | } |
| 54 | |
| 55 | protected: |
| 56 | template <typename U> |
| 57 | void fill(U &&src_tensor, U &&mean_tensor, U &&sd_tensor) |
| 58 | { |
| 59 | if(is_data_type_float(_data_type)) |
| 60 | { |
| 61 | float min_bound = 0.f; |
| 62 | float max_bound = 0.f; |
| 63 | std::tie(min_bound, max_bound) = get_normalize_planar_yuv_layer_test_bounds<T>(); |
| 64 | std::uniform_real_distribution<> distribution(min_bound, max_bound); |
zhenglin | 2219dea | 2018-01-30 18:15:52 +0800 | [diff] [blame] | 65 | std::uniform_real_distribution<> distribution_sd(0.1, max_bound); |
zhenglin | 0fb6cf5 | 2017-12-12 15:56:09 +0800 | [diff] [blame] | 66 | library->fill(src_tensor, distribution, 0); |
| 67 | library->fill(mean_tensor, distribution, 1); |
| 68 | library->fill(sd_tensor, distribution_sd, 2); |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | TensorType compute_target(const TensorShape &shape0, const TensorShape &shape1, DataType dt) |
| 73 | { |
| 74 | // Create tensors |
| 75 | TensorType src = create_tensor<TensorType>(shape0, dt, 1); |
| 76 | TensorType dst = create_tensor<TensorType>(shape0, dt, 1); |
| 77 | TensorType mean = create_tensor<TensorType>(shape1, dt, 1); |
| 78 | TensorType sd = create_tensor<TensorType>(shape1, dt, 1); |
| 79 | |
| 80 | // Create and configure function |
| 81 | FunctionType norm; |
| 82 | norm.configure(&src, &dst, &mean, &sd); |
| 83 | |
| 84 | ARM_COMPUTE_EXPECT(src.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 85 | ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 86 | ARM_COMPUTE_EXPECT(mean.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 87 | ARM_COMPUTE_EXPECT(sd.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 88 | |
| 89 | // Allocate tensors |
| 90 | src.allocator()->allocate(); |
| 91 | dst.allocator()->allocate(); |
| 92 | mean.allocator()->allocate(); |
| 93 | sd.allocator()->allocate(); |
| 94 | |
| 95 | ARM_COMPUTE_EXPECT(!src.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 96 | ARM_COMPUTE_EXPECT(!dst.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 97 | ARM_COMPUTE_EXPECT(!mean.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 98 | ARM_COMPUTE_EXPECT(!sd.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 99 | |
| 100 | // Fill tensors |
| 101 | fill(AccessorType(src), AccessorType(mean), AccessorType(sd)); |
| 102 | |
| 103 | // Compute function |
| 104 | norm.run(); |
| 105 | |
| 106 | return dst; |
| 107 | } |
| 108 | |
| 109 | SimpleTensor<T> compute_reference(const TensorShape &shape0, const TensorShape &shape1, DataType dt) |
| 110 | { |
| 111 | // Create reference |
| 112 | SimpleTensor<T> ref_src{ shape0, dt, 1 }; |
| 113 | SimpleTensor<T> ref_mean{ shape1, dt, 1 }; |
| 114 | SimpleTensor<T> ref_sd{ shape1, dt, 1 }; |
| 115 | |
| 116 | // Fill reference |
| 117 | fill(ref_src, ref_mean, ref_sd); |
| 118 | |
| 119 | return reference::normalize_planar_yuv_layer(ref_src, ref_mean, ref_sd); |
| 120 | } |
| 121 | |
| 122 | TensorType _target{}; |
| 123 | SimpleTensor<T> _reference{}; |
| 124 | DataType _data_type{}; |
| 125 | }; |
| 126 | |
| 127 | template <typename TensorType, typename AccessorType, typename FunctionType, typename T> |
| 128 | class NormalizePlanarYUVLayerValidationFixture : public NormalizePlanarYUVLayerValidationFixedPointFixture<TensorType, AccessorType, FunctionType, T> |
| 129 | { |
| 130 | public: |
| 131 | template <typename...> |
| 132 | void setup(TensorShape shape0, TensorShape shape1, DataType dt) |
| 133 | { |
| 134 | NormalizePlanarYUVLayerValidationFixedPointFixture<TensorType, AccessorType, FunctionType, T>::setup(shape0, shape1, dt); |
| 135 | } |
| 136 | }; |
| 137 | } // namespace validation |
| 138 | } // namespace test |
| 139 | } // namespace arm_compute |
| 140 | #endif /* ARM_COMPUTE_TEST_NORMALIZE_PLANAR_YUV_LAYER_FIXTURE */ |