Gian Marco Iodice | adc5395 | 2019-02-15 11:10:31 +0000 | [diff] [blame] | 1 | /* |
Michele Di Giorgio | d9eaf61 | 2020-07-08 11:12:57 +0100 | [diff] [blame] | 2 | * Copyright (c) 2019-2020 Arm Limited. |
Gian Marco Iodice | adc5395 | 2019-02-15 11:10:31 +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 | #include "arm_compute/core/CL/kernels/CLGEMMMatrixMultiplyReshapedOnlyRHSKernel.h" |
| 25 | #include "arm_compute/core/CL/kernels/CLGEMMReshapeRHSMatrixKernel.h" |
Gian Marco Iodice | 7026b30 | 2019-06-26 17:18:11 +0100 | [diff] [blame] | 26 | #include "arm_compute/core/KernelDescriptors.h" |
Gian Marco Iodice | adc5395 | 2019-02-15 11:10:31 +0000 | [diff] [blame] | 27 | #include "arm_compute/core/Types.h" |
| 28 | #include "arm_compute/core/utils/misc/ShapeCalculator.h" |
| 29 | #include "arm_compute/runtime/CL/CLTensor.h" |
| 30 | #include "arm_compute/runtime/CL/CLTensorAllocator.h" |
| 31 | #include "tests/CL/CLAccessor.h" |
| 32 | #include "tests/CL/Helper.h" |
| 33 | #include "tests/PaddingCalculator.h" |
| 34 | #include "tests/datasets/ShapeDatasets.h" |
| 35 | #include "tests/framework/Asserts.h" |
| 36 | #include "tests/framework/Macros.h" |
| 37 | #include "tests/framework/datasets/Datasets.h" |
| 38 | #include "tests/validation/Validation.h" |
| 39 | #include "tests/validation/fixtures/GEMMFixture.h" |
| 40 | |
| 41 | namespace arm_compute |
| 42 | { |
| 43 | namespace test |
| 44 | { |
| 45 | namespace validation |
| 46 | { |
| 47 | using namespace arm_compute::misc::shape_calculator; |
| 48 | |
| 49 | // Create function for CLGEMMReshapeRHSMatrixKernel |
| 50 | using CLGEMMReshapeRHSMatrix = CLSynthetizeFunction<CLGEMMReshapeRHSMatrixKernel>; |
| 51 | |
| 52 | // Create function for CLGEMMMatrixMultiplyReshapedOnlyRHSKernel |
| 53 | using CLGEMMMatrixMultiplyReshapedOnlyRHS = CLSynthetizeFunction<CLGEMMMatrixMultiplyReshapedOnlyRHSKernel>; |
| 54 | |
| 55 | // Fixture for CLGEMMMatrixMultiplyReshapedOnlyRHS |
| 56 | template <typename T> |
| 57 | using CLGEMMMatrixMultiplyReshapedOnlyRHSFixture = GEMMMatrixMultiplyReshapedOnlyRHSValidationFixture<CLTensor, CLAccessor, T, CLGEMMReshapeRHSMatrix, CLGEMMMatrixMultiplyReshapedOnlyRHS>; |
| 58 | |
| 59 | // Fixture for CLGEMMMatrixMultiplyReshapedOnlyRHS3D |
| 60 | template <typename T> |
| 61 | using CLGEMMMatrixMultiplyReshapedOnlyRHS3DFixture = GEMMMatrixMultiplyReshapedOnlyRHS3DValidationFixture<CLTensor, CLAccessor, T, CLGEMMReshapeRHSMatrix, CLGEMMMatrixMultiplyReshapedOnlyRHS>; |
| 62 | |
| 63 | namespace |
| 64 | { |
| 65 | // *INDENT-OFF* |
| 66 | // clang-format off |
| 67 | RelativeTolerance<float> rel_tolerance_f32(0.001f); |
| 68 | constexpr float abs_tolerance_f32(0.0001f); |
| 69 | |
Gian Marco Iodice | 781cba7 | 2020-06-19 16:56:57 +0100 | [diff] [blame] | 70 | RelativeTolerance<float> rel_tolerance_f16(0.001f); |
| 71 | constexpr float abs_tolerance_f16(0.01f); |
| 72 | |
Sheri Zhang | 1a37810 | 2020-04-30 12:59:39 +0100 | [diff] [blame] | 73 | /** Alpha values to test */ |
| 74 | const auto a_values = framework::dataset::make("alpha", {-0.75f} ); |
Gian Marco Iodice | adc5395 | 2019-02-15 11:10:31 +0000 | [diff] [blame] | 75 | |
Sheri Zhang | 1a37810 | 2020-04-30 12:59:39 +0100 | [diff] [blame] | 76 | /** Beta values to test */ |
Gian Marco Iodice | d820db6 | 2019-08-05 14:23:23 +0100 | [diff] [blame] | 77 | const auto beta_values = framework::dataset::make("beta", {-0.35f, 0.0f} ); |
Georgios Pinitas | b0f342e | 2019-05-21 13:32:43 +0100 | [diff] [blame] | 78 | |
Gian Marco Iodice | adc5395 | 2019-02-15 11:10:31 +0000 | [diff] [blame] | 79 | /** M values to test */ |
| 80 | const auto m_values = framework::dataset::make("M", 37); |
| 81 | |
| 82 | /** M_W values to test */ |
| 83 | const auto m_w_values = framework::dataset::make("M_W", 5); |
| 84 | |
| 85 | /** M_H values to test */ |
| 86 | const auto m_h_values = framework::dataset::make("M_H", 7); |
| 87 | |
| 88 | /** N values to test */ |
| 89 | const auto n_values = framework::dataset::make("N", 51); |
| 90 | |
| 91 | /** K values to test */ |
| 92 | const auto k_values = framework::dataset::make("K", 23); |
| 93 | |
| 94 | /** Batch size values to test */ |
| 95 | const auto b_values = framework::dataset::make("batch_size", 1, 3); |
| 96 | |
Gian Marco Iodice | ca1f460 | 2019-07-16 15:46:48 +0100 | [diff] [blame] | 97 | /** Activation values to test */ |
| 98 | const auto act_values = framework::dataset::make("Activation", |
| 99 | { |
| 100 | ActivationLayerInfo(), |
| 101 | ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LU_BOUNDED_RELU, 8.f, 2.f), |
| 102 | }); |
| 103 | |
Gian Marco Iodice | 781cba7 | 2020-06-19 16:56:57 +0100 | [diff] [blame] | 104 | /** M0 values to test - precommit */ |
| 105 | const auto m0_values_precommit = framework::dataset::make("M0", { 4 }); |
Gian Marco Iodice | adc5395 | 2019-02-15 11:10:31 +0000 | [diff] [blame] | 106 | |
Gian Marco Iodice | 781cba7 | 2020-06-19 16:56:57 +0100 | [diff] [blame] | 107 | /** N0 values to test - precommit*/ |
| 108 | const auto n0_values_precommit = framework::dataset::make("N0", { 4 }); |
Gian Marco Iodice | adc5395 | 2019-02-15 11:10:31 +0000 | [diff] [blame] | 109 | |
Gian Marco Iodice | 781cba7 | 2020-06-19 16:56:57 +0100 | [diff] [blame] | 110 | /** K0 values to test - precommit*/ |
| 111 | const auto k0_values_precommit = framework::dataset::make("K0", { 4 }); |
| 112 | |
| 113 | /** M0 values to test - nightly */ |
| 114 | const auto m0_values_nightly = framework::dataset::make("M0", { 8 }); |
| 115 | |
| 116 | /** N0 values to test - nightly */ |
| 117 | const auto n0_values_nightly = framework::dataset::make("N0", { 16 }); |
| 118 | |
| 119 | /** K0 values to test - nightly */ |
| 120 | const auto k0_values_nightly = framework::dataset::make("K0", { 16 }); |
Gian Marco Iodice | adc5395 | 2019-02-15 11:10:31 +0000 | [diff] [blame] | 121 | |
Sheri Zhang | 1a37810 | 2020-04-30 12:59:39 +0100 | [diff] [blame] | 122 | /** H0 values to test */ |
| 123 | const auto h0_values = framework::dataset::make("H0", 1, 3); |
Gian Marco Iodice | adc5395 | 2019-02-15 11:10:31 +0000 | [diff] [blame] | 124 | |
| 125 | /** Interleave values to test with RHS matrix */ |
| 126 | const auto i_values_rhs = framework::dataset::make("interleave_rhs", { true, false }); |
| 127 | |
| 128 | /** Transpose values to test with RHS matrix */ |
Gian Marco Iodice | ba5e096 | 2019-03-11 12:17:44 +0000 | [diff] [blame] | 129 | const auto t_values_rhs = framework::dataset::make("transpose_rhs", { true, false }); |
Gian Marco Iodice | adc5395 | 2019-02-15 11:10:31 +0000 | [diff] [blame] | 130 | |
Gian Marco Iodice | e16c890 | 2019-06-14 16:11:10 +0100 | [diff] [blame] | 131 | /** Broadcast bias from vector to matrix */ |
Gian Marco Iodice | d820db6 | 2019-08-05 14:23:23 +0100 | [diff] [blame] | 132 | const auto broadcast_bias_values = framework::dataset::make("broadcast_bias", { false, true } ); |
Georgios Pinitas | b0f342e | 2019-05-21 13:32:43 +0100 | [diff] [blame] | 133 | |
Gian Marco Iodice | adc5395 | 2019-02-15 11:10:31 +0000 | [diff] [blame] | 134 | /** Configuration test */ |
Sheri Zhang | 1a37810 | 2020-04-30 12:59:39 +0100 | [diff] [blame] | 135 | bool validate_configuration(unsigned int m_value, unsigned int n_value, unsigned int k_value, unsigned int b_value, |
| 136 | unsigned int m0_value, unsigned int n0_value, unsigned int k0_value, unsigned int h0_value, |
Gian Marco Iodice | 781cba7 | 2020-06-19 16:56:57 +0100 | [diff] [blame] | 137 | bool i_value_rhs, bool t_value_rhs, bool export_to_cl_image, bool broadcast_bias, bool input_as_3d, unsigned int depth_output_gemm3d, const ActivationLayerInfo &act_info, |
Sheri Zhang | 1a37810 | 2020-04-30 12:59:39 +0100 | [diff] [blame] | 138 | DataType dt_input0, DataType dt_input1, DataType dt_input2, DataType dt_output, float alpha, float beta) |
Gian Marco Iodice | adc5395 | 2019-02-15 11:10:31 +0000 | [diff] [blame] | 139 | { |
| 140 | const unsigned int M = m_value; |
| 141 | const unsigned int N = n_value; |
| 142 | const unsigned int K = k_value; |
| 143 | |
| 144 | GEMMLHSMatrixInfo lhs_info; |
| 145 | lhs_info.m0 = m0_value; |
| 146 | lhs_info.k0 = k0_value; |
| 147 | |
| 148 | GEMMRHSMatrixInfo rhs_info; |
| 149 | rhs_info.n0 = n0_value; |
| 150 | rhs_info.k0 = k0_value; |
| 151 | rhs_info.h0 = h0_value; |
| 152 | rhs_info.interleave = i_value_rhs; |
Gian Marco Iodice | ba5e096 | 2019-03-11 12:17:44 +0000 | [diff] [blame] | 153 | rhs_info.transpose = t_value_rhs; |
Gian Marco Iodice | 781cba7 | 2020-06-19 16:56:57 +0100 | [diff] [blame] | 154 | rhs_info.export_to_cl_image = export_to_cl_image; |
Gian Marco Iodice | adc5395 | 2019-02-15 11:10:31 +0000 | [diff] [blame] | 155 | |
Gian Marco Iodice | 7026b30 | 2019-06-26 17:18:11 +0100 | [diff] [blame] | 156 | GEMMKernelInfo kernel_info; |
| 157 | kernel_info.m = M; |
| 158 | kernel_info.n = N; |
| 159 | kernel_info.k = K; |
Sheri Zhang | 1a37810 | 2020-04-30 12:59:39 +0100 | [diff] [blame] | 160 | kernel_info.depth_output_gemm3d = depth_output_gemm3d; |
| 161 | kernel_info.reinterpret_input_as_3d = input_as_3d; |
Gian Marco Iodice | 7026b30 | 2019-06-26 17:18:11 +0100 | [diff] [blame] | 162 | kernel_info.broadcast_bias = broadcast_bias; |
Gian Marco Iodice | ca1f460 | 2019-07-16 15:46:48 +0100 | [diff] [blame] | 163 | kernel_info.activation_info = act_info; |
Gian Marco Iodice | adc5395 | 2019-02-15 11:10:31 +0000 | [diff] [blame] | 164 | |
| 165 | const TensorShape lhs_shape(K, M, b_value); |
| 166 | const TensorShape rhs_shape(N, K, b_value); |
Sheri Zhang | 1a37810 | 2020-04-30 12:59:39 +0100 | [diff] [blame] | 167 | const TensorShape rhs_shape_reshaped = compute_rhs_reshaped_shape(TensorInfo(rhs_shape, 1, dt_input1), |
Gian Marco Iodice | adc5395 | 2019-02-15 11:10:31 +0000 | [diff] [blame] | 168 | rhs_info); |
| 169 | |
Sheri Zhang | 1a37810 | 2020-04-30 12:59:39 +0100 | [diff] [blame] | 170 | const TensorShape dst_shape = compute_mm_shape(TensorInfo(lhs_shape, 1, dt_input0), |
| 171 | TensorInfo(rhs_shape_reshaped, 1, dt_input1), |
Gian Marco Iodice | 7026b30 | 2019-06-26 17:18:11 +0100 | [diff] [blame] | 172 | kernel_info); |
Gian Marco Iodice | adc5395 | 2019-02-15 11:10:31 +0000 | [diff] [blame] | 173 | |
Gian Marco Iodice | e16c890 | 2019-06-14 16:11:10 +0100 | [diff] [blame] | 174 | const TensorShape bias_shape(N, |
Sheri Zhang | 1a37810 | 2020-04-30 12:59:39 +0100 | [diff] [blame] | 175 | M, // Correct calculation should be: broadcast_bias? 1 : M, it's wrong here on purpose just for validation test |
Gian Marco Iodice | e16c890 | 2019-06-14 16:11:10 +0100 | [diff] [blame] | 176 | broadcast_bias? 1 : b_value); |
| 177 | |
Sheri Zhang | 1a37810 | 2020-04-30 12:59:39 +0100 | [diff] [blame] | 178 | // Create tensor info |
| 179 | TensorInfo lhs = TensorInfo(lhs_shape, 1, dt_input0); |
| 180 | TensorInfo rhs_reshaped = TensorInfo(rhs_shape_reshaped, 1, dt_input1); |
| 181 | TensorInfo bias = TensorInfo(bias_shape, 1, dt_input2); |
| 182 | TensorInfo dst = TensorInfo(dst_shape, 1, dt_output); |
Gian Marco Iodice | adc5395 | 2019-02-15 11:10:31 +0000 | [diff] [blame] | 183 | |
| 184 | // Create and configure function |
| 185 | CLGEMMMatrixMultiplyReshapedOnlyRHS gemm; |
Sheri Zhang | 1a37810 | 2020-04-30 12:59:39 +0100 | [diff] [blame] | 186 | return bool(gemm.validate(&lhs, &rhs_reshaped, &bias, &dst, alpha, beta, lhs_info, rhs_info, kernel_info)); |
Gian Marco Iodice | adc5395 | 2019-02-15 11:10:31 +0000 | [diff] [blame] | 187 | } |
SiCong Li | 3a50166 | 2020-06-26 10:02:06 +0100 | [diff] [blame] | 188 | |
| 189 | /** Zero padding test */ |
| 190 | bool validate_zero_padding(unsigned int m_value, unsigned int n_value, unsigned int k_value, unsigned int b_value, |
| 191 | unsigned int m0_value, unsigned int n0_value, unsigned int k0_value, unsigned int h0_value, |
| 192 | bool i_value_rhs, bool t_value_rhs, bool export_to_cl_image, bool broadcast_bias, bool input_as_3d, unsigned int depth_output_gemm3d, const ActivationLayerInfo &act_info, |
| 193 | DataType dt_input0, DataType dt_input1, DataType dt_input2, DataType dt_output, float alpha, float beta) |
| 194 | { |
| 195 | const unsigned int M = m_value; |
| 196 | const unsigned int N = n_value; |
| 197 | const unsigned int K = k_value; |
| 198 | |
| 199 | GEMMLHSMatrixInfo lhs_info; |
| 200 | lhs_info.m0 = m0_value; |
| 201 | lhs_info.k0 = k0_value; |
| 202 | |
| 203 | GEMMRHSMatrixInfo rhs_info; |
| 204 | rhs_info.n0 = n0_value; |
| 205 | rhs_info.k0 = k0_value; |
| 206 | rhs_info.h0 = h0_value; |
| 207 | rhs_info.interleave = i_value_rhs; |
| 208 | rhs_info.transpose = t_value_rhs; |
| 209 | rhs_info.export_to_cl_image = export_to_cl_image; |
| 210 | |
| 211 | GEMMKernelInfo kernel_info; |
| 212 | kernel_info.m = M; |
| 213 | kernel_info.n = N; |
| 214 | kernel_info.k = K; |
| 215 | kernel_info.depth_output_gemm3d = depth_output_gemm3d; |
| 216 | kernel_info.reinterpret_input_as_3d = input_as_3d; |
| 217 | kernel_info.broadcast_bias = broadcast_bias; |
| 218 | kernel_info.activation_info = act_info; |
| 219 | |
| 220 | const TensorShape lhs_shape(K, M, b_value); |
| 221 | const TensorShape rhs_shape(N, K, b_value); |
| 222 | const TensorShape rhs_shape_reshaped = compute_rhs_reshaped_shape(TensorInfo(rhs_shape, 1, dt_input1), |
| 223 | rhs_info); |
| 224 | |
| 225 | const TensorShape dst_shape = compute_mm_shape(TensorInfo(lhs_shape, 1, dt_input0), |
| 226 | TensorInfo(rhs_shape_reshaped, 1, dt_input1), |
| 227 | kernel_info); |
| 228 | |
| 229 | const TensorShape bias_shape(N, |
| 230 | M, // Correct calculation should be: broadcast_bias? 1 : M, it's wrong here on purpose just for validation test |
| 231 | broadcast_bias? 1 : b_value); |
| 232 | |
| 233 | // Create tensors |
| 234 | CLTensor lhs = create_tensor<CLTensor>(lhs_shape, dt_input0); |
| 235 | CLTensor rhs_reshaped = create_tensor<CLTensor>(rhs_shape_reshaped, dt_input1); |
| 236 | CLTensor bias = create_tensor<CLTensor>(bias_shape, dt_input2); |
| 237 | CLTensor dst = create_tensor<CLTensor>(dst_shape, dt_output); |
| 238 | |
| 239 | ARM_COMPUTE_EXPECT(lhs.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 240 | ARM_COMPUTE_EXPECT(rhs_reshaped.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 241 | ARM_COMPUTE_EXPECT(bias.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 242 | ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 243 | |
| 244 | // Validate zero-padding |
| 245 | CLGEMMMatrixMultiplyReshapedOnlyRHS gemm; |
| 246 | |
| 247 | gemm.configure(&lhs, &rhs_reshaped, &bias, &dst, alpha, beta, lhs_info, rhs_info, kernel_info); |
| 248 | |
SiCong Li | 406a13f | 2020-07-15 12:09:58 +0100 | [diff] [blame] | 249 | // Padding can be added along rhs and bias's X dimension |
| 250 | return dst.info()->padding().empty() && lhs.info()->padding().empty() && bias.info()->padding().bottom == 0 && bias.info()->padding().top == 0; |
SiCong Li | 3a50166 | 2020-06-26 10:02:06 +0100 | [diff] [blame] | 251 | } |
Gian Marco Iodice | adc5395 | 2019-02-15 11:10:31 +0000 | [diff] [blame] | 252 | } // namespace |
| 253 | |
| 254 | TEST_SUITE(CL) |
| 255 | TEST_SUITE(GEMMMatrixMultiplyReshapedOnlyRHS) |
Sheri Zhang | 1a37810 | 2020-04-30 12:59:39 +0100 | [diff] [blame] | 256 | |
| 257 | /** Validate tests |
| 258 | * |
| 259 | * A series of validation tests on configurations which according to the API specification |
| 260 | * the function should fail against. |
| 261 | * |
| 262 | * Checks performed in order: |
| 263 | * - Mismachting data type: input1, input2 and output need to have same data type as input0. Support data type: F32/F16. |
| 264 | * - Unsupported M0: MO can only be 1,2,3,4,5,6,7,8 |
| 265 | * - Unsupported N0: NO can only be 2,3,4,8,16 |
| 266 | * - Unsupported K0: KO can only be 2,3,4,8,16 |
| 267 | * - Unsupported bias addition: bias broadcast mode is 0 if the input or output has to be reinterpreted as 3D |
| 268 | * - Incorrect bias diemension when bias broadcast mode is 1 and beta is not 0.0f, should be (n, 1), not (n, m) |
| 269 | * - Incorrect input0 dimension when input is reinterpreted as 3D: input0->dimension(1) * input0->dimension(2) != m |
Gian Marco Iodice | 781cba7 | 2020-06-19 16:56:57 +0100 | [diff] [blame] | 270 | * - Correct support for creating an OpenCL image object from buffer |
| 271 | * - Incorrect support for creating an OpenCL image object from buffer. N0 is 2 but it can only be 4,8 and 16 |
| 272 | * - Incorrect support for creating an OpenCL image object from buffer. Data type is F16 but it can only be F32 |
Sheri Zhang | 1a37810 | 2020-04-30 12:59:39 +0100 | [diff] [blame] | 273 | */ |
Gian Marco Iodice | 781cba7 | 2020-06-19 16:56:57 +0100 | [diff] [blame] | 274 | DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(zip(zip(zip(zip(zip(zip(zip(zip(zip(zip( |
| 275 | framework::dataset::make("batch_size", { 1, 1, 1, 1, 1, 1, 2, 1, 1, 1 }), |
| 276 | framework::dataset::make("M0", { 4, 9, 4, 4, 4, 4, 4, 4, 4, 4 })), |
| 277 | framework::dataset::make("N0", { 4, 4, 18, 4, 4, 4, 4, 8, 2, 8 })), |
| 278 | framework::dataset::make("K0", { 4, 4, 4, 1, 4, 4, 4, 4, 4, 4 })), |
| 279 | framework::dataset::make("broadcast_bias", { false, false, false, false, false, true, true, false, false, false })), |
| 280 | framework::dataset::make("input_as_3d", { 0, 0, 0, 0, 1, 0, 1, 0, 0, 0 })), |
| 281 | framework::dataset::make("depth_output_gemm3d", { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0 })), |
| 282 | framework::dataset::make("export_to_cl_image", { false, false, false, false, false, false, false, true, true, true })), |
| 283 | framework::dataset::make("data_type_input0", { DataType::F32, DataType::F32, DataType::F32, DataType::F32, DataType::F32, DataType::F32, DataType::F32, DataType::F32, DataType::F32, DataType::F16})), |
| 284 | framework::dataset::make("data_type_input1", { DataType::F32, DataType::F32, DataType::F32, DataType::F32, DataType::F32, DataType::F32, DataType::F32, DataType::F32, DataType::F32, DataType::F16})), |
| 285 | framework::dataset::make("data_type_input2", { DataType::F32, DataType::F32, DataType::F32, DataType::F32, DataType::F32, DataType::F32, DataType::F32, DataType::F32, DataType::F32, DataType::F16})), |
| 286 | framework::dataset::make("data_type_output", { DataType::F16, DataType::F32, DataType::F32, DataType::F32, DataType::F32, DataType::F32, DataType::F32, DataType::F32, DataType::F32, DataType::F16})), |
| 287 | framework::dataset::make("Beta", { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f , 1.0f})), |
| 288 | framework::dataset::make("Expected", { false, false, false, false, false, false, false, true, false, false })), |
| 289 | b_value, m0_value, n0_value, k0_value, broadcast_bias, input_as_3d, depth_output_gemm3d, export_to_cl_image, dt_input0, dt_intpu1, dt_input2, dt_output, beta, expected) |
Sheri Zhang | 1a37810 | 2020-04-30 12:59:39 +0100 | [diff] [blame] | 290 | { |
Gian Marco Iodice | 781cba7 | 2020-06-19 16:56:57 +0100 | [diff] [blame] | 291 | bool expected_value = expected; |
| 292 | |
| 293 | // Change expected to false if the target platform does not support the OpenCL cl_khr_image2d_from_buffer extension |
| 294 | if(!image2d_from_buffer_supported(CLKernelLibrary::get().get_device()) && export_to_cl_image) |
| 295 | { |
| 296 | expected_value = false; |
| 297 | } |
| 298 | |
| 299 | bool status = validate_configuration(37, 51, 23, b_value, m0_value, n0_value, k0_value, 1, false, false, export_to_cl_image, broadcast_bias, input_as_3d, depth_output_gemm3d, ActivationLayerInfo(), dt_input0, dt_intpu1, dt_input2, dt_output, 1.0f, beta); |
| 300 | ARM_COMPUTE_EXPECT(status == expected_value, framework::LogLevel::ERRORS); |
Sheri Zhang | 1a37810 | 2020-04-30 12:59:39 +0100 | [diff] [blame] | 301 | } |
| 302 | |
SiCong Li | 3a50166 | 2020-06-26 10:02:06 +0100 | [diff] [blame] | 303 | /** Validate zero padding tests |
| 304 | * |
| 305 | * A series of validation tests to check that no padding is added as part of configuration for 4 different scenarios. |
| 306 | * |
| 307 | * Checks performed in order: |
| 308 | * - No partial blocks in both x and y dimensions |
| 309 | * - Partial blocks in x dimension |
| 310 | * - Partial blocks in y dimension |
| 311 | * - Partial blocks in both x and y dimensions |
SiCong Li | 3b64e3e | 2020-07-28 09:01:28 +0100 | [diff] [blame^] | 312 | * - Special case: partial_n0 == 9 (vstore1 should be invoked instead of vstore_partial_1) |
SiCong Li | 3a50166 | 2020-06-26 10:02:06 +0100 | [diff] [blame] | 313 | */ |
| 314 | DATA_TEST_CASE(ValidateZeroPadding, framework::DatasetMode::ALL, zip(zip(zip(zip( |
SiCong Li | 3b64e3e | 2020-07-28 09:01:28 +0100 | [diff] [blame^] | 315 | framework::dataset::make("M", { 24, 64, 101, 1, 100 }), |
| 316 | framework::dataset::make("N", { 48, 29, 16, 122, 41 })), |
| 317 | framework::dataset::make("M0", { 4, 8, 7, 2, 1 })), |
| 318 | framework::dataset::make("N0", { 4, 4, 16, 3, 16 })), |
| 319 | framework::dataset::make("export_to_cl_image", { false, true, true, false, false })), |
SiCong Li | 3a50166 | 2020-06-26 10:02:06 +0100 | [diff] [blame] | 320 | m_value, n_value, m0_value, n0_value, export_to_cl_image) |
| 321 | { |
| 322 | constexpr DataType dt = DataType::F32; |
| 323 | // Disable export_to_cl_image if the target platform does not support the OpenCL cl_khr_image2d_from_buffer extension |
| 324 | bool actual_export_to_cl_image = image2d_from_buffer_supported(CLKernelLibrary::get().get_device()) && export_to_cl_image; |
| 325 | |
| 326 | bool status = validate_zero_padding(m_value, n_value, 23, 1, m0_value, n0_value, 4, 1, false, false, actual_export_to_cl_image, false, 0, 0, ActivationLayerInfo(), dt, dt, dt, dt, 1.0f, 1.0f); |
| 327 | ARM_COMPUTE_EXPECT(status, framework::LogLevel::ERRORS); |
| 328 | } |
| 329 | |
Gian Marco Iodice | adc5395 | 2019-02-15 11:10:31 +0000 | [diff] [blame] | 330 | TEST_SUITE(Float) |
| 331 | TEST_SUITE(FP32) |
Gian Marco Iodice | adc5395 | 2019-02-15 11:10:31 +0000 | [diff] [blame] | 332 | |
Gian Marco Iodice | 781cba7 | 2020-06-19 16:56:57 +0100 | [diff] [blame] | 333 | FIXTURE_DATA_TEST_CASE(RunPrecommit, CLGEMMMatrixMultiplyReshapedOnlyRHSFixture<float>, framework::DatasetMode::PRECOMMIT, |
| 334 | combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine( |
Gian Marco Iodice | adc5395 | 2019-02-15 11:10:31 +0000 | [diff] [blame] | 335 | m_values, |
| 336 | n_values), |
| 337 | k_values), |
| 338 | b_values), |
Gian Marco Iodice | 781cba7 | 2020-06-19 16:56:57 +0100 | [diff] [blame] | 339 | m0_values_precommit), |
| 340 | n0_values_precommit), |
| 341 | k0_values_precommit), |
Sheri Zhang | 1a37810 | 2020-04-30 12:59:39 +0100 | [diff] [blame] | 342 | h0_values), |
Gian Marco Iodice | adc5395 | 2019-02-15 11:10:31 +0000 | [diff] [blame] | 343 | i_values_rhs), |
| 344 | t_values_rhs), |
Gian Marco Iodice | 781cba7 | 2020-06-19 16:56:57 +0100 | [diff] [blame] | 345 | framework::dataset::make("export_to_cl_image_rhs", false)), |
Gian Marco Iodice | adc5395 | 2019-02-15 11:10:31 +0000 | [diff] [blame] | 346 | framework::dataset::make("DataType", DataType::F32)), |
Georgios Pinitas | b0f342e | 2019-05-21 13:32:43 +0100 | [diff] [blame] | 347 | a_values), |
| 348 | beta_values), |
Gian Marco Iodice | ca1f460 | 2019-07-16 15:46:48 +0100 | [diff] [blame] | 349 | broadcast_bias_values), |
| 350 | act_values)) |
Gian Marco Iodice | adc5395 | 2019-02-15 11:10:31 +0000 | [diff] [blame] | 351 | { |
| 352 | // Validate output |
| 353 | validate(CLAccessor(_target), _reference, rel_tolerance_f32, 0.f, abs_tolerance_f32); |
| 354 | } |
| 355 | |
Gian Marco Iodice | 781cba7 | 2020-06-19 16:56:57 +0100 | [diff] [blame] | 356 | FIXTURE_DATA_TEST_CASE(RunNightly, CLGEMMMatrixMultiplyReshapedOnlyRHSFixture<float>, framework::DatasetMode::NIGHTLY, |
| 357 | combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine( |
| 358 | m_values, |
| 359 | n_values), |
| 360 | k_values), |
| 361 | b_values), |
| 362 | m0_values_nightly), |
| 363 | n0_values_nightly), |
| 364 | k0_values_nightly), |
| 365 | h0_values), |
| 366 | i_values_rhs), |
| 367 | t_values_rhs), |
| 368 | framework::dataset::make("export_to_cl_image_rhs", false)), |
| 369 | framework::dataset::make("DataType", DataType::F32)), |
| 370 | a_values), |
| 371 | beta_values), |
| 372 | broadcast_bias_values), |
| 373 | act_values)) |
| 374 | { |
| 375 | // Validate output |
| 376 | validate(CLAccessor(_target), _reference, rel_tolerance_f32, 0.f, abs_tolerance_f32); |
| 377 | } |
| 378 | |
| 379 | FIXTURE_DATA_TEST_CASE(RunPrecommit3D, CLGEMMMatrixMultiplyReshapedOnlyRHS3DFixture<float>, framework::DatasetMode::PRECOMMIT, |
| 380 | combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine( |
Gian Marco Iodice | adc5395 | 2019-02-15 11:10:31 +0000 | [diff] [blame] | 381 | m_w_values, |
| 382 | m_h_values), |
| 383 | n_values), |
| 384 | k_values), |
| 385 | b_values), |
Gian Marco Iodice | 781cba7 | 2020-06-19 16:56:57 +0100 | [diff] [blame] | 386 | m0_values_precommit), |
| 387 | n0_values_precommit), |
| 388 | k0_values_precommit), |
Sheri Zhang | 1a37810 | 2020-04-30 12:59:39 +0100 | [diff] [blame] | 389 | h0_values), |
Gian Marco Iodice | adc5395 | 2019-02-15 11:10:31 +0000 | [diff] [blame] | 390 | i_values_rhs), |
| 391 | t_values_rhs), |
Gian Marco Iodice | 781cba7 | 2020-06-19 16:56:57 +0100 | [diff] [blame] | 392 | framework::dataset::make("export_to_cl_image_rhs", false)), |
Gian Marco Iodice | adc5395 | 2019-02-15 11:10:31 +0000 | [diff] [blame] | 393 | framework::dataset::make("DataType", DataType::F32)), |
Georgios Pinitas | b0f342e | 2019-05-21 13:32:43 +0100 | [diff] [blame] | 394 | a_values), |
Gian Marco Iodice | ca1f460 | 2019-07-16 15:46:48 +0100 | [diff] [blame] | 395 | beta_values), |
| 396 | act_values)) |
Gian Marco Iodice | adc5395 | 2019-02-15 11:10:31 +0000 | [diff] [blame] | 397 | { |
| 398 | // Validate output |
| 399 | validate(CLAccessor(_target), _reference, rel_tolerance_f32, 0.f, abs_tolerance_f32); |
| 400 | } |
| 401 | |
Gian Marco Iodice | 781cba7 | 2020-06-19 16:56:57 +0100 | [diff] [blame] | 402 | FIXTURE_DATA_TEST_CASE(RunNightly3D, CLGEMMMatrixMultiplyReshapedOnlyRHS3DFixture<float>, framework::DatasetMode::NIGHTLY, |
| 403 | combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine( |
| 404 | m_w_values, |
| 405 | m_h_values), |
| 406 | n_values), |
| 407 | k_values), |
| 408 | b_values), |
| 409 | m0_values_nightly), |
| 410 | n0_values_nightly), |
| 411 | k0_values_nightly), |
| 412 | h0_values), |
| 413 | i_values_rhs), |
| 414 | t_values_rhs), |
| 415 | framework::dataset::make("export_to_cl_image_rhs", false)), |
| 416 | framework::dataset::make("DataType", DataType::F32)), |
| 417 | a_values), |
| 418 | beta_values), |
| 419 | act_values)) |
| 420 | { |
| 421 | // Validate output |
| 422 | validate(CLAccessor(_target), _reference, rel_tolerance_f32, 0.f, abs_tolerance_f32); |
| 423 | } |
| 424 | |
| 425 | TEST_SUITE(ExportToCLImage) |
| 426 | FIXTURE_DATA_TEST_CASE(RunPrecommit, CLGEMMMatrixMultiplyReshapedOnlyRHSFixture<float>, framework::DatasetMode::PRECOMMIT, |
| 427 | combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine( |
| 428 | m_values, |
| 429 | n_values), |
| 430 | k_values), |
| 431 | b_values), |
| 432 | m0_values_precommit), |
| 433 | n0_values_precommit), |
| 434 | k0_values_precommit), |
| 435 | h0_values), |
| 436 | i_values_rhs), |
| 437 | t_values_rhs), |
| 438 | framework::dataset::make("export_to_cl_image_rhs", true)), |
| 439 | framework::dataset::make("DataType", DataType::F32)), |
| 440 | a_values), |
| 441 | beta_values), |
| 442 | broadcast_bias_values), |
| 443 | act_values)) |
| 444 | { |
| 445 | // Validate output only if the target platform supports the OpenCL cl_khr_image2d_from_buffer extension |
| 446 | if(image2d_from_buffer_supported(CLKernelLibrary::get().get_device())) |
| 447 | { |
| 448 | validate(CLAccessor(_target), _reference, rel_tolerance_f32, 0.f, abs_tolerance_f32); |
| 449 | } |
| 450 | else |
| 451 | { |
| 452 | ARM_COMPUTE_TEST_INFO("cl_khr_image2d_from_buffer not supported. TEST skipped"); |
| 453 | framework::ARM_COMPUTE_PRINT_INFO(); |
| 454 | } |
| 455 | } |
| 456 | |
| 457 | FIXTURE_DATA_TEST_CASE(RunNightly, CLGEMMMatrixMultiplyReshapedOnlyRHSFixture<float>, framework::DatasetMode::NIGHTLY, |
| 458 | combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine( |
| 459 | m_values, |
| 460 | n_values), |
| 461 | k_values), |
| 462 | b_values), |
| 463 | m0_values_nightly), |
| 464 | n0_values_nightly), |
| 465 | k0_values_nightly), |
| 466 | h0_values), |
| 467 | i_values_rhs), |
| 468 | t_values_rhs), |
| 469 | framework::dataset::make("export_to_cl_image_rhs", true)), |
| 470 | framework::dataset::make("DataType", DataType::F32)), |
| 471 | a_values), |
| 472 | beta_values), |
| 473 | broadcast_bias_values), |
| 474 | act_values)) |
| 475 | { |
| 476 | // Validate output only if the target platform supports the OpenCL cl_khr_image2d_from_buffer extension |
| 477 | if(image2d_from_buffer_supported(CLKernelLibrary::get().get_device())) |
| 478 | { |
| 479 | validate(CLAccessor(_target), _reference, rel_tolerance_f32, 0.f, abs_tolerance_f32); |
| 480 | } |
| 481 | else |
| 482 | { |
| 483 | ARM_COMPUTE_TEST_INFO("cl_khr_image2d_from_buffer not supported. TEST skipped"); |
| 484 | framework::ARM_COMPUTE_PRINT_INFO(); |
| 485 | } |
| 486 | } |
| 487 | |
| 488 | FIXTURE_DATA_TEST_CASE(RunPrecommit3D, CLGEMMMatrixMultiplyReshapedOnlyRHS3DFixture<float>, framework::DatasetMode::PRECOMMIT, |
| 489 | combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine( |
| 490 | m_w_values, |
| 491 | m_h_values), |
| 492 | n_values), |
| 493 | k_values), |
| 494 | b_values), |
| 495 | m0_values_precommit), |
| 496 | n0_values_precommit), |
| 497 | k0_values_precommit), |
| 498 | h0_values), |
| 499 | i_values_rhs), |
| 500 | t_values_rhs), |
| 501 | framework::dataset::make("export_to_cl_image_rhs", true)), |
| 502 | framework::dataset::make("DataType", DataType::F32)), |
| 503 | a_values), |
| 504 | beta_values), |
| 505 | act_values)) |
| 506 | { |
| 507 | // Validate output |
| 508 | validate(CLAccessor(_target), _reference, rel_tolerance_f32, 0.f, abs_tolerance_f32); |
| 509 | } |
| 510 | |
| 511 | FIXTURE_DATA_TEST_CASE(RunNightly3D, CLGEMMMatrixMultiplyReshapedOnlyRHS3DFixture<float>, framework::DatasetMode::NIGHTLY, |
| 512 | combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine( |
| 513 | m_w_values, |
| 514 | m_h_values), |
| 515 | n_values), |
| 516 | k_values), |
| 517 | b_values), |
| 518 | m0_values_nightly), |
| 519 | n0_values_nightly), |
| 520 | k0_values_nightly), |
| 521 | h0_values), |
| 522 | i_values_rhs), |
| 523 | t_values_rhs), |
| 524 | framework::dataset::make("export_to_cl_image_rhs", true)), |
| 525 | framework::dataset::make("DataType", DataType::F32)), |
| 526 | a_values), |
| 527 | beta_values), |
| 528 | act_values)) |
| 529 | { |
| 530 | // Validate output |
| 531 | validate(CLAccessor(_target), _reference, rel_tolerance_f32, 0.f, abs_tolerance_f32); |
| 532 | } |
| 533 | TEST_SUITE_END() // ExportToCLImage |
Gian Marco Iodice | adc5395 | 2019-02-15 11:10:31 +0000 | [diff] [blame] | 534 | TEST_SUITE_END() // FP32 |
Gian Marco Iodice | 781cba7 | 2020-06-19 16:56:57 +0100 | [diff] [blame] | 535 | |
| 536 | TEST_SUITE(FP16) |
| 537 | FIXTURE_DATA_TEST_CASE(RunPrecommit, CLGEMMMatrixMultiplyReshapedOnlyRHSFixture<half>, framework::DatasetMode::PRECOMMIT, |
| 538 | combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine( |
| 539 | m_values, |
| 540 | n_values), |
| 541 | k_values), |
| 542 | b_values), |
| 543 | m0_values_precommit), |
| 544 | n0_values_precommit), |
| 545 | k0_values_precommit), |
| 546 | h0_values), |
| 547 | i_values_rhs), |
| 548 | t_values_rhs), |
| 549 | framework::dataset::make("export_to_cl_image_rhs", false)), |
| 550 | framework::dataset::make("DataType", DataType::F16)), |
| 551 | a_values), |
| 552 | beta_values), |
| 553 | broadcast_bias_values), |
| 554 | act_values)) |
| 555 | { |
| 556 | // Validate output |
| 557 | validate(CLAccessor(_target), _reference, rel_tolerance_f16, 0.f, abs_tolerance_f16); |
| 558 | } |
| 559 | |
| 560 | FIXTURE_DATA_TEST_CASE(RunNightly, CLGEMMMatrixMultiplyReshapedOnlyRHSFixture<half>, framework::DatasetMode::NIGHTLY, |
| 561 | combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine( |
| 562 | m_values, |
| 563 | n_values), |
| 564 | k_values), |
| 565 | b_values), |
| 566 | m0_values_nightly), |
| 567 | n0_values_nightly), |
| 568 | k0_values_nightly), |
| 569 | h0_values), |
| 570 | i_values_rhs), |
| 571 | t_values_rhs), |
| 572 | framework::dataset::make("export_to_cl_image_rhs", false)), |
| 573 | framework::dataset::make("DataType", DataType::F16)), |
| 574 | a_values), |
| 575 | beta_values), |
| 576 | broadcast_bias_values), |
| 577 | act_values)) |
| 578 | { |
| 579 | // Validate output |
| 580 | validate(CLAccessor(_target), _reference, rel_tolerance_f16, 0.f, abs_tolerance_f16); |
| 581 | } |
| 582 | |
| 583 | FIXTURE_DATA_TEST_CASE(RunPrecommit3D, CLGEMMMatrixMultiplyReshapedOnlyRHS3DFixture<half>, framework::DatasetMode::PRECOMMIT, |
| 584 | combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine( |
| 585 | m_w_values, |
| 586 | m_h_values), |
| 587 | n_values), |
| 588 | k_values), |
| 589 | b_values), |
| 590 | m0_values_precommit), |
| 591 | n0_values_precommit), |
| 592 | k0_values_precommit), |
| 593 | h0_values), |
| 594 | i_values_rhs), |
| 595 | t_values_rhs), |
| 596 | framework::dataset::make("export_to_cl_image_rhs", false)), |
| 597 | framework::dataset::make("DataType", DataType::F16)), |
| 598 | a_values), |
| 599 | beta_values), |
| 600 | act_values)) |
| 601 | { |
| 602 | // Validate output |
| 603 | validate(CLAccessor(_target), _reference, rel_tolerance_f16, 0.f, abs_tolerance_f16); |
| 604 | } |
| 605 | |
| 606 | FIXTURE_DATA_TEST_CASE(RunNightly3D, CLGEMMMatrixMultiplyReshapedOnlyRHS3DFixture<half>, framework::DatasetMode::NIGHTLY, |
| 607 | combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine( |
| 608 | m_w_values, |
| 609 | m_h_values), |
| 610 | n_values), |
| 611 | k_values), |
| 612 | b_values), |
| 613 | m0_values_nightly), |
| 614 | n0_values_nightly), |
| 615 | k0_values_nightly), |
| 616 | h0_values), |
| 617 | i_values_rhs), |
| 618 | t_values_rhs), |
| 619 | framework::dataset::make("export_to_cl_image_rhs", false)), |
| 620 | framework::dataset::make("DataType", DataType::F16)), |
| 621 | a_values), |
| 622 | beta_values), |
| 623 | act_values)) |
| 624 | { |
| 625 | // Validate output |
| 626 | validate(CLAccessor(_target), _reference, rel_tolerance_f16, 0.f, abs_tolerance_f16); |
| 627 | } |
| 628 | |
| 629 | TEST_SUITE_END() // FP16 |
| 630 | |
Gian Marco Iodice | adc5395 | 2019-02-15 11:10:31 +0000 | [diff] [blame] | 631 | TEST_SUITE_END() // Float |
| 632 | TEST_SUITE_END() // GEMMMatrixMulipltyReshapedOnlyRHS |
| 633 | TEST_SUITE_END() // CL |
| 634 | } // namespace validation |
| 635 | } // namespace test |
Georgios Pinitas | b0f342e | 2019-05-21 13:32:43 +0100 | [diff] [blame] | 636 | } // namespace arm_compute |