Gian Marco Iodice | 5d01681 | 2022-11-17 11:03:39 +0000 | [diff] [blame] | 1 | /* |
Matthew Bentham | 945b8da | 2023-07-12 11:54:59 +0000 | [diff] [blame] | 2 | * Copyright (c) 2022-2023 Arm Limited. |
Gian Marco Iodice | 5d01681 | 2022-11-17 11:03:39 +0000 | [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_INDIRECT_CONV2D_ADDRESS_PRECALCULATION_FIXTURE |
| 25 | #define ARM_COMPUTE_TEST_INDIRECT_CONV2D_ADDRESS_PRECALCULATION_FIXTURE |
| 26 | |
| 27 | #include "arm_compute/core/TensorShape.h" |
| 28 | #include "arm_compute/core/Types.h" |
| 29 | #include "arm_compute/core/utils/misc/ShapeCalculator.h" |
| 30 | #include "tests/Globals.h" |
| 31 | #include "tests/framework/Fixture.h" |
| 32 | #include "tests/validation/Helpers.h" |
| 33 | #include "tests/validation/reference/IndirectConv2dAddressPrecalculation.h" |
| 34 | |
| 35 | namespace arm_compute |
| 36 | { |
| 37 | namespace test |
| 38 | { |
| 39 | namespace validation |
| 40 | { |
| 41 | using namespace arm_compute::misc::shape_calculator; |
| 42 | |
| 43 | template <typename TensorType, typename AccessorType, typename OperatorType> |
| 44 | class IndirectConv2dAddressPrecalculationValidationFixture : public framework::Fixture |
| 45 | { |
| 46 | public: |
Gian Marco Iodice | 5d01681 | 2022-11-17 11:03:39 +0000 | [diff] [blame] | 47 | void setup(unsigned int src_w, |
| 48 | unsigned int src_h, |
| 49 | unsigned int src_b, |
| 50 | unsigned int wei_w, |
| 51 | unsigned int wei_h, |
| 52 | unsigned int pad, |
| 53 | unsigned int stride, |
| 54 | unsigned int m0) |
| 55 | { |
| 56 | DirectConvComputeKernelInfo desc; |
| 57 | desc.m0 = m0; |
| 58 | desc.n0 = 1; // Not used by the kernel |
| 59 | desc.k0 = 1; // Not used by the kernel |
| 60 | desc.export_weights_to_cl_image = false; // Not used by the kernel |
| 61 | |
| 62 | const PadStrideInfo conv_info(stride, stride, pad, pad); |
| 63 | |
| 64 | const TensorShape shape_conv_src(23, // The input channels are not used by the kernel |
| 65 | src_w, |
| 66 | src_h, |
| 67 | src_b); |
| 68 | |
| 69 | const TensorShape shape_conv_wei(23, // The input channels are not used by the kernel |
| 70 | wei_w, |
| 71 | wei_h, |
| 72 | 23 // The output channels are not used by the kernel |
| 73 | ); |
| 74 | |
| 75 | // The result of the kernel does not change with the datatype. Hence, we can fix it to Fp16 for validation purposes |
| 76 | const DataType data_type = DataType::F16; |
| 77 | |
| 78 | _target = compute_target(shape_conv_src, shape_conv_wei, data_type, conv_info, desc); |
| 79 | _reference = compute_reference(shape_conv_src, shape_conv_wei, data_type, conv_info, desc); |
| 80 | } |
| 81 | |
| 82 | protected: |
| 83 | TensorType compute_target(TensorShape shape_conv_src, TensorShape shape_conv_wei, DataType data_type, const PadStrideInfo &conv_info, const DirectConvComputeKernelInfo &desc) |
| 84 | { |
| 85 | TensorInfo src_conv_info(shape_conv_src, 1, data_type, DataLayout::NHWC); |
| 86 | TensorInfo wei_conv_info(shape_conv_wei, 1, data_type, DataLayout::NHWC); |
| 87 | TensorType dst; |
| 88 | |
| 89 | // The output tensor will be auto-initialized within the function |
| 90 | |
| 91 | // Create and configure function |
| 92 | OperatorType func; |
| 93 | func.configure(&src_conv_info, &wei_conv_info, dst.info(), conv_info, desc); |
| 94 | |
| 95 | add_padding_x({ &dst }); |
| 96 | |
| 97 | // Allocate tensors |
| 98 | dst.allocator()->allocate(); |
| 99 | |
| 100 | // Compute GEMM LHS matrix reshape function |
| 101 | ITensorPack tensors = { { ACL_DST, &dst } }; |
| 102 | func.run(tensors); |
| 103 | |
| 104 | return dst; |
| 105 | } |
| 106 | |
| 107 | SimpleTensor<int32_t> compute_reference(TensorShape shape_conv_src, TensorShape shape_conv_wei, DataType data_type, const PadStrideInfo &conv_info, const DirectConvComputeKernelInfo &desc) |
| 108 | { |
| 109 | ARM_COMPUTE_UNUSED(data_type); |
| 110 | TensorShape shape_out = compute_indirect_buffer_shape(shape_conv_src, DataLayout::NHWC, shape_conv_wei, conv_info, desc); |
| 111 | TensorShape output_conv_shape = compute_deep_convolution_shape(shape_conv_src, DataLayout::NHWC, shape_conv_wei, conv_info); |
| 112 | |
| 113 | return reference::indirect_conv2d_addr_precalculation(shape_conv_src, shape_conv_wei, output_conv_shape, shape_out, conv_info); |
| 114 | } |
| 115 | |
| 116 | TensorType _target{}; |
| 117 | SimpleTensor<int32_t> _reference{}; |
| 118 | }; |
| 119 | } // namespace validation |
| 120 | } // namespace test |
| 121 | } // namespace arm_compute |
| 122 | #endif /* ARM_COMPUTE_TEST_INDIRECT_CONV2D_ADDRESS_PRECALCULATION_FIXTURE */ |