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_ABSOLUTE_DIFFERENCE_FIXTURE 25 #define ARM_COMPUTE_TEST_ABSOLUTE_DIFFERENCE_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/AbsoluteDifference.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 AbsoluteDifferenceValidationFixture : public framework::Fixture 45 { 46 public: 47 template <typename...> setup(TensorShape shape,DataType data_type0,DataType data_type1,DataType output_data_type)48 void setup(TensorShape shape, DataType data_type0, DataType data_type1, DataType output_data_type) 49 { 50 _target = compute_target(shape, data_type0, data_type1, output_data_type); 51 _reference = compute_reference(shape, data_type0, data_type1, output_data_type); 52 } 53 54 protected: 55 template <typename U> fill(U && tensor,int i)56 void fill(U &&tensor, int i) 57 { 58 library->fill_tensor_uniform(tensor, i); 59 } 60 compute_target(const TensorShape & shape,DataType data_type0,DataType data_type1,DataType output_data_type)61 TensorType compute_target(const TensorShape &shape, DataType data_type0, DataType data_type1, DataType output_data_type) 62 { 63 // Create tensors 64 TensorType ref_src1 = create_tensor<TensorType>(shape, data_type0, 1); 65 TensorType ref_src2 = create_tensor<TensorType>(shape, data_type1, 1); 66 TensorType dst = create_tensor<TensorType>(shape, output_data_type, 1); 67 68 // Create and configure function 69 FunctionType abs_diff; 70 abs_diff.configure(&ref_src1, &ref_src2, &dst); 71 72 ARM_COMPUTE_EXPECT(ref_src1.info()->is_resizable(), framework::LogLevel::ERRORS); 73 ARM_COMPUTE_EXPECT(ref_src2.info()->is_resizable(), framework::LogLevel::ERRORS); 74 ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS); 75 76 // Allocate tensors 77 ref_src1.allocator()->allocate(); 78 ref_src2.allocator()->allocate(); 79 dst.allocator()->allocate(); 80 81 ARM_COMPUTE_EXPECT(!ref_src1.info()->is_resizable(), framework::LogLevel::ERRORS); 82 ARM_COMPUTE_EXPECT(!ref_src2.info()->is_resizable(), framework::LogLevel::ERRORS); 83 ARM_COMPUTE_EXPECT(!dst.info()->is_resizable(), framework::LogLevel::ERRORS); 84 85 // Fill tensors 86 fill(AccessorType(ref_src1), 0); 87 fill(AccessorType(ref_src2), 1); 88 89 // Compute function 90 abs_diff.run(); 91 92 return dst; 93 } 94 compute_reference(const TensorShape & shape,DataType data_type0,DataType data_type1,DataType output_data_type)95 SimpleTensor<T> compute_reference(const TensorShape &shape, DataType data_type0, DataType data_type1, DataType output_data_type) 96 { 97 // Create reference 98 SimpleTensor<T> ref_src1{ shape, data_type0, 1 }; 99 SimpleTensor<T> ref_src2{ shape, data_type1, 1 }; 100 101 // Fill reference 102 fill(ref_src1, 0); 103 fill(ref_src2, 1); 104 105 return reference::absolute_difference<T>(ref_src1, ref_src2, output_data_type); 106 } 107 108 TensorType _target{}; 109 SimpleTensor<T> _reference{}; 110 }; 111 } // namespace validation 112 } // namespace test 113 } // namespace arm_compute 114 #endif /* ARM_COMPUTE_TEST_ABSOLUTE_DIFFERENCE_FIXTURE */ 115