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_LAPLACIAN_RECONSTRUCT_FIXTURE 25 #define ARM_COMPUTE_TEST_LAPLACIAN_RECONSTRUCT_FIXTURE 26 27 #include "arm_compute/core/IPyramid.h" 28 #include "arm_compute/core/PyramidInfo.h" 29 #include "arm_compute/core/TensorShape.h" 30 #include "arm_compute/core/Types.h" 31 #include "tests/AssetsLibrary.h" 32 #include "tests/Globals.h" 33 #include "tests/IAccessor.h" 34 #include "tests/framework/Asserts.h" 35 #include "tests/framework/Fixture.h" 36 #include "tests/validation/fixtures/LaplacianPyramidFixture.h" 37 #include "tests/validation/reference/LaplacianPyramid.h" 38 #include "tests/validation/reference/LaplacianReconstruct.h" 39 40 namespace arm_compute 41 { 42 namespace test 43 { 44 namespace validation 45 { 46 template <typename TensorType, typename AccessorType, typename FunctionType, typename LaplacianPyramidType, typename T, typename U, typename PyramidType> 47 class LaplacianReconstructValidationFixture : public LaplacianPyramidValidationFixture<TensorType, AccessorType, LaplacianPyramidType, U, T, PyramidType> 48 { 49 public: 50 template <typename...> setup(TensorShape input_shape,BorderMode border_mode,size_t num_levels,Format format_in,Format format_out)51 void setup(TensorShape input_shape, BorderMode border_mode, size_t num_levels, Format format_in, Format format_out) 52 { 53 std::mt19937 generator(library->seed()); 54 std::uniform_int_distribution<U> distribution_u8(0, 255); 55 const U constant_border_value = distribution_u8(generator); 56 57 using LPF = LaplacianPyramidValidationFixture<TensorType, AccessorType, LaplacianPyramidType, U, T, PyramidType>; 58 LPF::setup(input_shape, border_mode, num_levels, format_out, format_in); 59 60 // Compute target and reference values using the pyramid and lowest 61 // resolution tensor output from Laplacian Pyramid kernel 62 _target = compute_target(input_shape, LPF::_target, LPF::_dst_target, border_mode, constant_border_value); 63 _reference = compute_reference(LPF::_reference, LPF::_dst_reference, border_mode, constant_border_value); 64 } 65 66 protected: 67 template <typename V> fill(V && tensor)68 void fill(V &&tensor) 69 { 70 library->fill_tensor_uniform(tensor, 0); 71 } 72 compute_target(const TensorShape & input_shape,PyramidType & pyramid,TensorType & low_res,BorderMode border_mode,U constant_border_value)73 TensorType compute_target(const TensorShape &input_shape, PyramidType &pyramid, TensorType &low_res, BorderMode border_mode, U constant_border_value) 74 { 75 // Create tensors 76 TensorType dst = create_tensor<TensorType>(input_shape, DataType::U8); 77 78 // Create and configure function 79 FunctionType laplacian_reconstruct; 80 laplacian_reconstruct.configure(&pyramid, &low_res, &dst, border_mode, constant_border_value); 81 82 // Allocate tensors 83 dst.allocator()->allocate(); 84 ARM_COMPUTE_EXPECT(!dst.info()->is_resizable(), framework::LogLevel::ERRORS); 85 86 // Compute function 87 laplacian_reconstruct.run(); 88 89 return dst; 90 } 91 compute_reference(const std::vector<SimpleTensor<T>> & pyramid,const SimpleTensor<T> & low_res,BorderMode border_mode,U constant_border_value)92 SimpleTensor<U> compute_reference(const std::vector<SimpleTensor<T>> &pyramid, 93 const SimpleTensor<T> &low_res, BorderMode border_mode, U constant_border_value) 94 { 95 return reference::laplacian_reconstruct<T, U>(pyramid, low_res, border_mode, constant_border_value); 96 } 97 98 TensorType _target{}; 99 SimpleTensor<U> _reference{}; 100 }; 101 } // namespace validation 102 } // namespace test 103 } // namespace arm_compute 104 #endif /* ARM_COMPUTE_TEST_LAPLACIAN_RECONSTRUCT_FIXTURE */ 105