giuros01 | b3204e7 | 2019-04-01 13:50:22 +0100 | [diff] [blame] | 1 | /* |
Georgios Pinitas | 856f66e | 2021-04-22 21:13:21 +0100 | [diff] [blame] | 2 | * Copyright (c) 2019-2021 Arm Limited. |
giuros01 | b3204e7 | 2019-04-01 13:50:22 +0100 | [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 | */ |
Gian Marco Iodice | 7026b30 | 2019-06-26 17:18:11 +0100 | [diff] [blame] | 24 | #include "arm_compute/core/KernelDescriptors.h" |
giuros01 | b3204e7 | 2019-04-01 13:50:22 +0100 | [diff] [blame] | 25 | #include "arm_compute/core/Types.h" |
| 26 | #include "arm_compute/core/utils/misc/ShapeCalculator.h" |
| 27 | #include "arm_compute/runtime/CL/CLTensor.h" |
| 28 | #include "arm_compute/runtime/CL/CLTensorAllocator.h" |
Georgios Pinitas | 7891a73 | 2021-08-20 21:39:25 +0100 | [diff] [blame] | 29 | #include "src/gpu/cl/kernels/ClGemmMatrixMultiplyNativeKernel.h" |
giuros01 | b3204e7 | 2019-04-01 13:50:22 +0100 | [diff] [blame] | 30 | #include "tests/CL/CLAccessor.h" |
| 31 | #include "tests/CL/Helper.h" |
| 32 | #include "tests/PaddingCalculator.h" |
| 33 | #include "tests/datasets/ShapeDatasets.h" |
| 34 | #include "tests/framework/Asserts.h" |
| 35 | #include "tests/framework/Macros.h" |
| 36 | #include "tests/framework/datasets/Datasets.h" |
| 37 | #include "tests/validation/Validation.h" |
| 38 | #include "tests/validation/fixtures/GEMMFixture.h" |
| 39 | |
| 40 | namespace arm_compute |
| 41 | { |
| 42 | namespace test |
| 43 | { |
| 44 | namespace validation |
| 45 | { |
| 46 | using namespace arm_compute::misc::shape_calculator; |
Georgios Pinitas | 856f66e | 2021-04-22 21:13:21 +0100 | [diff] [blame] | 47 | using namespace arm_compute::opencl::kernels; |
giuros01 | b3204e7 | 2019-04-01 13:50:22 +0100 | [diff] [blame] | 48 | |
Georgios Pinitas | 856f66e | 2021-04-22 21:13:21 +0100 | [diff] [blame] | 49 | // Create function for ClGemmMatrixMultiplyNativeKernel |
| 50 | using CLGEMMMatrixMultiplyNative = CLSynthetizeOperator<ClGemmMatrixMultiplyNativeKernel>; |
giuros01 | b3204e7 | 2019-04-01 13:50:22 +0100 | [diff] [blame] | 51 | |
| 52 | // Fixture for CLGEMMMatrixMultiplyNative |
| 53 | template <typename T> |
| 54 | using CLGEMMMatrixMultiplyNativeFixture = GEMMMatrixMultiplyNativeValidationFixture<CLTensor, CLAccessor, T, CLGEMMMatrixMultiplyNative>; |
| 55 | |
SiCongLi | afa1972 | 2021-10-24 19:12:33 +0100 | [diff] [blame^] | 56 | // Fixture for CLGEMMMatrixMultiplyNative with post ops |
| 57 | template <typename T> |
| 58 | using CLGEMMMatrixMultiplyNativeWithPostOpsFixture = |
| 59 | GEMMMatrixMultiplyNativeWithPostOpsValidationFixture<CLTensor, CLAccessor, T, CLGEMMMatrixMultiplyNative>; |
| 60 | |
giuros01 | b3204e7 | 2019-04-01 13:50:22 +0100 | [diff] [blame] | 61 | // Fixture for CLGEMMMatrixMultiplyNative3D |
| 62 | template <typename T> |
| 63 | using CLGEMMMatrixMultiplyNative3DFixture = GEMMMatrixMultiplyNative3DValidationFixture<CLTensor, CLAccessor, T, CLGEMMMatrixMultiplyNative>; |
| 64 | |
| 65 | namespace |
| 66 | { |
| 67 | // *INDENT-OFF* |
| 68 | // clang-format off |
| 69 | RelativeTolerance<float> rel_tolerance_f32(0.001f); |
| 70 | constexpr float abs_tolerance_f32(0.0001f); |
| 71 | |
giuros01 | b3204e7 | 2019-04-01 13:50:22 +0100 | [diff] [blame] | 72 | /** Alpha values to test - Precommit */ |
| 73 | const auto a_values = framework::dataset::make("alpha", {1.0f, -0.75f} ); |
| 74 | |
Gian Marco Iodice | 944170e | 2019-06-24 14:40:30 +0100 | [diff] [blame] | 75 | /** Beta values to test - Precommit */ |
| 76 | const auto beta_values = framework::dataset::make("beta", {-0.75f, 0.0f} ); |
| 77 | |
giuros01 | b3204e7 | 2019-04-01 13:50:22 +0100 | [diff] [blame] | 78 | /** M values to test */ |
| 79 | const auto m_values = framework::dataset::make("M", 37); |
| 80 | |
| 81 | /** M_W values to test */ |
| 82 | const auto m_w_values = framework::dataset::make("M_W", 5); |
| 83 | |
| 84 | /** M_H values to test */ |
| 85 | const auto m_h_values = framework::dataset::make("M_H", 7); |
| 86 | |
| 87 | /** N values to test */ |
| 88 | const auto n_values = framework::dataset::make("N", 51); |
| 89 | |
| 90 | /** K values to test */ |
| 91 | const auto k_values = framework::dataset::make("K", 23); |
| 92 | |
| 93 | /** Batch size values to test */ |
| 94 | const auto b_values = framework::dataset::make("batch_size", 1, 3); |
| 95 | |
Gian Marco Iodice | ca1f460 | 2019-07-16 15:46:48 +0100 | [diff] [blame] | 96 | /** Activation values to test */ |
| 97 | const auto act_values = framework::dataset::make("Activation", |
| 98 | { |
| 99 | ActivationLayerInfo(), |
| 100 | ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LU_BOUNDED_RELU, 8.f, 2.f), |
| 101 | }); |
| 102 | |
giuros01 | b3204e7 | 2019-04-01 13:50:22 +0100 | [diff] [blame] | 103 | /** M0 values to test - Precommit */ |
Gian Marco Iodice | d820db6 | 2019-08-05 14:23:23 +0100 | [diff] [blame] | 104 | const auto m0_values_precommit = framework::dataset::make("M0", { 4, 6 }); |
giuros01 | b3204e7 | 2019-04-01 13:50:22 +0100 | [diff] [blame] | 105 | |
| 106 | /** N0 values to test - Precommit */ |
Gian Marco Iodice | d820db6 | 2019-08-05 14:23:23 +0100 | [diff] [blame] | 107 | const auto n0_values_precommit = framework::dataset::make("N0", { 4 }); |
giuros01 | b3204e7 | 2019-04-01 13:50:22 +0100 | [diff] [blame] | 108 | |
| 109 | /** K0 values to test - Precommit */ |
| 110 | const auto k0_values_precommit = framework::dataset::make("K0", { 4 }); |
| 111 | |
| 112 | /** H0 values to test - Precommit */ |
| 113 | const auto h0_values_precommit = framework::dataset::make("H0", 1, 3); |
| 114 | |
| 115 | /** M0 values to test - Nightly */ |
| 116 | const auto m0_values_nightly = framework::dataset::make("M0", 1, 8); |
| 117 | |
| 118 | /** N0 values to test - Nightly */ |
| 119 | const auto n0_values_nightly = framework::dataset::make("N0", { 2, 3, 4, 8 }); |
| 120 | |
| 121 | /** K0 values to test - Nightly */ |
| 122 | const auto k0_values_nightly = framework::dataset::make("K0", { 2, 3, 4, 8 }); |
| 123 | |
Gian Marco Iodice | 944170e | 2019-06-24 14:40:30 +0100 | [diff] [blame] | 124 | /** Broadcast bias from vector to matrix */ |
Gian Marco Iodice | d820db6 | 2019-08-05 14:23:23 +0100 | [diff] [blame] | 125 | const auto broadcast_bias_values = framework::dataset::make("broadcast_bias", { false, true } ); |
Gian Marco Iodice | 944170e | 2019-06-24 14:40:30 +0100 | [diff] [blame] | 126 | |
SiCong Li | b972ae6 | 2020-08-03 15:39:45 +0100 | [diff] [blame] | 127 | /** Boundary handling cases for testing partial/non-partial (full) block dimensions, resulting from different combinations |
| 128 | * of M, M0, N and N0 values. |
| 129 | * M0 and N0 are kept constant, while the different test cases need to vary M and N. |
| 130 | * |
| 131 | * Eg. M = 64 and N = 33 result in a block dimension that has no partial blocks (all full blocks) in Y dimension and |
| 132 | * parital blocks in X dimension. |
| 133 | */ |
| 134 | const auto boundary_handling_cases = combine(combine(combine(combine(combine(combine(combine(combine(combine( |
| 135 | // Large k to force potential out-of-bound reads on input0 |
| 136 | framework::dataset::make("K", 315), |
| 137 | // Batch size == 1 to force potential out-of-bound reads on input0 |
| 138 | framework::dataset::make("batch_size", 1)), |
| 139 | framework::dataset::make("M0", 4)), |
| 140 | framework::dataset::make("N0", 4)), |
| 141 | framework::dataset::make("K0", 4)), |
| 142 | // Only need to test F32 as F16 shares identical boundary handling logics |
| 143 | framework::dataset::make("DataType", DataType::F32)), |
| 144 | framework::dataset::make("alpha", -0.75f )), |
| 145 | framework::dataset::make("beta", -0.35f )), |
| 146 | broadcast_bias_values), |
| 147 | framework::dataset::make("Activation", ActivationLayerInfo())); |
| 148 | |
SiCongLi | afa1972 | 2021-10-24 19:12:33 +0100 | [diff] [blame^] | 149 | /** Post Ops */ |
| 150 | using PostOpArgBroadcast = CLGEMMMatrixMultiplyNativeWithPostOpsFixture<float>::PostOpArgBroadcast; |
| 151 | experimental::PostOpList<PostOpArgBroadcast> post_ops_1() |
| 152 | { |
| 153 | experimental::PostOpList<PostOpArgBroadcast> post_ops{}; |
| 154 | post_ops.push_back_op<experimental::PostOpAct<PostOpArgBroadcast>>(ActivationLayerInfo{ActivationLayerInfo::ActivationFunction::LINEAR, 0.5F, 0.0F}); |
| 155 | post_ops.push_back_op<experimental::PostOpEltwiseAdd<PostOpArgBroadcast>>( |
| 156 | std::make_tuple(true, true, false), // If broadcast in dims 0, 1 and 2 |
| 157 | 0, |
| 158 | ConvertPolicy::SATURATE); |
| 159 | post_ops.push_back_op<experimental::PostOpAct<PostOpArgBroadcast>>(ActivationLayerInfo{ActivationLayerInfo::ActivationFunction::RELU, 2.1F, 1.3F}); |
| 160 | return post_ops; |
| 161 | } |
| 162 | experimental::PostOpList<PostOpArgBroadcast> post_ops_2() |
| 163 | { |
| 164 | experimental::PostOpList<PostOpArgBroadcast> post_ops{}; |
| 165 | post_ops.push_back_op<experimental::PostOpEltwiseAdd<PostOpArgBroadcast>>( |
| 166 | std::make_tuple(false, true, true), // If broadcast in dims 0, 1 and 2 |
| 167 | 1, |
| 168 | ConvertPolicy::SATURATE); |
| 169 | post_ops.push_back_op<experimental::PostOpAct<PostOpArgBroadcast>>(ActivationLayerInfo{ActivationLayerInfo::ActivationFunction::RELU, 2.1F, 1.3F}); |
| 170 | return post_ops; |
| 171 | } |
| 172 | experimental::PostOpList<PostOpArgBroadcast> post_ops_3() |
| 173 | { |
| 174 | experimental::PostOpList<PostOpArgBroadcast> post_ops{}; |
| 175 | // post_ops.push_back_op<experimental::PostOpAct<PostOpArgBroadcast>>(ActivationLayerInfo{ActivationLayerInfo::ActivationFunction::RELU, 2.1F, 1.3F}); |
| 176 | post_ops.push_back_op<experimental::PostOpEltwiseAdd<PostOpArgBroadcast>>( |
| 177 | std::make_tuple(false, false, false), // If broadcast in dims 0, 1 and 2 |
| 178 | 1, |
| 179 | ConvertPolicy::SATURATE); |
| 180 | return post_ops; |
| 181 | } |
| 182 | |
| 183 | /** Different Post Op Lists */ |
| 184 | const auto post_op_lists = framework::dataset::make("post_op_lists", { |
| 185 | post_ops_1(), |
| 186 | post_ops_2(), |
| 187 | post_ops_3(), |
| 188 | } ); |
| 189 | |
| 190 | bool is_post_op_list_valid(unsigned int m, unsigned int n, unsigned int k, unsigned int batch, DataType data_type, const experimental::PostOpList<ITensorInfo*>& post_ops) |
| 191 | { |
| 192 | const auto lhs_info = GEMMLHSMatrixInfo(4,4,1,false,true); |
| 193 | const auto rhs_info = GEMMRHSMatrixInfo(4,4,1,true,true,false); |
| 194 | |
| 195 | // Create TensorInfo for post op arguments |
| 196 | TensorInfo input0_info(TensorShape(k, m, batch), 1, data_type); |
| 197 | TensorInfo input1_info(TensorShape(n, k, batch), 1, data_type); |
| 198 | TensorInfo input2_info(TensorShape(n), 1, data_type); |
| 199 | TensorInfo output_info(TensorShape(n, m, batch), 1, data_type); |
| 200 | |
| 201 | GEMMKernelInfo gemm_info(m, n, k, 0 /**< Depth of the output tensor in case is reinterpreted as 3D */, |
| 202 | false /**< reinterpret the input as 3D */, |
| 203 | true /**< Flag used to broadcast the bias addition */, |
| 204 | false /**< wider accumm */, |
| 205 | false /**< has pad y */, |
| 206 | ActivationLayerInfo::ActivationFunction::IDENTITY, |
| 207 | 1 /**< Multiplication factor for the width of the 1xW transposed block */, |
| 208 | 1 /**< Multiplication factor for the height of the 4x4 interleaved block */, |
| 209 | lhs_info, |
| 210 | rhs_info, |
| 211 | 0 /**< Offset to be added to each element of the matrix A */, |
| 212 | 0 /**< Offset to be added to each element of the matrix B */, |
| 213 | post_ops); |
| 214 | return bool(ClGemmMatrixMultiplyNativeKernel::validate(&input0_info.clone()->set_is_resizable(true), |
| 215 | &input1_info.clone()->set_is_resizable(true), |
| 216 | &input2_info.clone()->set_is_resizable(true), |
| 217 | &output_info.clone()->set_is_resizable(true),1.f,1.f, |
| 218 | lhs_info, |
| 219 | rhs_info, |
| 220 | gemm_info)); |
| 221 | } |
| 222 | |
giuros01 | b3204e7 | 2019-04-01 13:50:22 +0100 | [diff] [blame] | 223 | /** Configuration test */ |
Gian Marco Iodice | ca1f460 | 2019-07-16 15:46:48 +0100 | [diff] [blame] | 224 | void validate_configuration(unsigned int m_value, unsigned int n_value, unsigned int k_value, unsigned int b_value, unsigned int m0_value, unsigned int n0_value, unsigned int k0_value, bool broadcast_bias, DataType data_type, const ActivationLayerInfo &act_info) |
giuros01 | b3204e7 | 2019-04-01 13:50:22 +0100 | [diff] [blame] | 225 | { |
| 226 | const unsigned int M = m_value; |
| 227 | const unsigned int N = n_value; |
| 228 | const unsigned int K = k_value; |
| 229 | |
| 230 | GEMMLHSMatrixInfo lhs_info; |
| 231 | lhs_info.m0 = m0_value; |
| 232 | lhs_info.k0 = k0_value; |
| 233 | |
| 234 | GEMMRHSMatrixInfo rhs_info; |
| 235 | rhs_info.n0 = n0_value; |
| 236 | rhs_info.k0 = k0_value; |
| 237 | |
Gian Marco Iodice | 7026b30 | 2019-06-26 17:18:11 +0100 | [diff] [blame] | 238 | GEMMKernelInfo kernel_info; |
Gian Marco Iodice | ca1f460 | 2019-07-16 15:46:48 +0100 | [diff] [blame] | 239 | kernel_info.m = M; |
| 240 | kernel_info.n = N; |
| 241 | kernel_info.k = K; |
| 242 | kernel_info.broadcast_bias = broadcast_bias; |
| 243 | kernel_info.activation_info = act_info; |
giuros01 | b3204e7 | 2019-04-01 13:50:22 +0100 | [diff] [blame] | 244 | |
| 245 | const TensorShape lhs_shape(K, M, b_value); |
| 246 | const TensorShape rhs_shape(N, K, b_value); |
Gian Marco Iodice | 944170e | 2019-06-24 14:40:30 +0100 | [diff] [blame] | 247 | const TensorShape bias_shape(N, |
| 248 | broadcast_bias? 1 : M, |
| 249 | broadcast_bias? 1 : b_value); |
giuros01 | b3204e7 | 2019-04-01 13:50:22 +0100 | [diff] [blame] | 250 | const TensorShape dst_shape = compute_mm_shape(TensorInfo(lhs_shape, 1, data_type), |
| 251 | TensorInfo(rhs_shape, 1, data_type), |
Gian Marco Iodice | 7026b30 | 2019-06-26 17:18:11 +0100 | [diff] [blame] | 252 | kernel_info); |
| 253 | |
giuros01 | b3204e7 | 2019-04-01 13:50:22 +0100 | [diff] [blame] | 254 | // Create tensors |
Gian Marco Iodice | 944170e | 2019-06-24 14:40:30 +0100 | [diff] [blame] | 255 | CLTensor lhs = create_tensor<CLTensor>(lhs_shape, data_type); |
giuros01 | b3204e7 | 2019-04-01 13:50:22 +0100 | [diff] [blame] | 256 | CLTensor rhs = create_tensor<CLTensor>(rhs_shape, data_type); |
Gian Marco Iodice | 944170e | 2019-06-24 14:40:30 +0100 | [diff] [blame] | 257 | CLTensor bias = create_tensor<CLTensor>(bias_shape, data_type); |
| 258 | CLTensor dst = create_tensor<CLTensor>(dst_shape, data_type); |
giuros01 | b3204e7 | 2019-04-01 13:50:22 +0100 | [diff] [blame] | 259 | |
| 260 | ARM_COMPUTE_EXPECT(lhs.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 261 | ARM_COMPUTE_EXPECT(rhs.info()->is_resizable(), framework::LogLevel::ERRORS); |
Gian Marco Iodice | 944170e | 2019-06-24 14:40:30 +0100 | [diff] [blame] | 262 | ARM_COMPUTE_EXPECT(bias.info()->is_resizable(), framework::LogLevel::ERRORS); |
giuros01 | b3204e7 | 2019-04-01 13:50:22 +0100 | [diff] [blame] | 263 | ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 264 | |
| 265 | // Create and configure function |
| 266 | CLGEMMMatrixMultiplyNative gemm; |
Georgios Pinitas | 856f66e | 2021-04-22 21:13:21 +0100 | [diff] [blame] | 267 | gemm.configure(lhs.info(), rhs.info(), bias.info(), dst.info(), 1.0f, 1.0f, lhs_info, rhs_info, kernel_info); |
giuros01 | b3204e7 | 2019-04-01 13:50:22 +0100 | [diff] [blame] | 268 | } |
| 269 | } // namespace |
| 270 | |
| 271 | TEST_SUITE(CL) |
| 272 | TEST_SUITE(GEMMMatrixMultiplyNative) |
SiCongLi | afa1972 | 2021-10-24 19:12:33 +0100 | [diff] [blame^] | 273 | TEST_SUITE(ValidateFusedPostOpsConfigs) |
| 274 | TEST_SUITE(Invalid) |
| 275 | TEST_CASE(UnsupportedPostOpSequence, framework::DatasetMode::ALL) |
| 276 | { |
| 277 | const auto data_type = DataType::F32; |
| 278 | const unsigned int m = 17; |
| 279 | const unsigned int n = 1; |
| 280 | const unsigned int k = 13; |
| 281 | const unsigned int batch = 2; |
| 282 | TensorShape post_op_arg0_shape(n, m, batch); |
| 283 | TensorInfo post_op_arg_info(post_op_arg0_shape, 1, data_type); |
| 284 | auto post_op_arg1_info = post_op_arg_info.clone(); |
| 285 | |
| 286 | // Unsupported sequence of post ops |
| 287 | experimental::PostOpList<ITensorInfo*> post_ops{}; |
| 288 | post_ops.push_back_op<experimental::PostOpEltwiseAdd<ITensorInfo*>>( |
| 289 | &post_op_arg_info, |
| 290 | 1, |
| 291 | ConvertPolicy::SATURATE); |
| 292 | post_ops.push_back_op<experimental::PostOpEltwiseAdd<ITensorInfo*>>( |
| 293 | post_op_arg1_info.get(), |
| 294 | 0, |
| 295 | ConvertPolicy::SATURATE); |
| 296 | |
| 297 | ARM_COMPUTE_EXPECT(is_post_op_list_valid(m, n, k, batch, data_type, post_ops) == false, framework::LogLevel::ERRORS); |
| 298 | } |
| 299 | TEST_CASE(OutputWidened, framework::DatasetMode::ALL) |
| 300 | { |
| 301 | // Invalid broadcast: post op tensors "widen" the output tensor |
| 302 | const auto data_type = DataType::F32; |
| 303 | const unsigned int m = 1; |
| 304 | const unsigned int n = 18; |
| 305 | const unsigned int k = 13; |
| 306 | const unsigned int batch = 2; |
| 307 | TensorShape post_op_arg_shape(n, m + 1, batch); // output's Y dimension (m) is "widened", which is not allowed |
| 308 | TensorInfo post_op_arg_info(post_op_arg_shape, 1, data_type); |
| 309 | experimental::PostOpList<ITensorInfo*> post_ops{}; |
| 310 | post_ops.push_back_op<experimental::PostOpEltwiseAdd<ITensorInfo*>>( &post_op_arg_info, 0, ConvertPolicy::SATURATE); |
| 311 | |
| 312 | ARM_COMPUTE_EXPECT(is_post_op_list_valid(m, n, k, batch, data_type, post_ops) == false, framework::LogLevel::ERRORS); |
| 313 | } |
| 314 | TEST_CASE(BroadcastInXDimOnly, framework::DatasetMode::ALL) |
| 315 | { |
| 316 | // Invalid broadcast: post op tensors broadcast in the first dimension (X) only |
| 317 | const auto data_type = DataType::F32; |
| 318 | const unsigned int m = 22; |
| 319 | const unsigned int n = 16; |
| 320 | const unsigned int k = 15; |
| 321 | const unsigned int batch = 3; |
| 322 | TensorShape post_op_arg_shape(1, m, batch); |
| 323 | TensorInfo post_op_arg_info(post_op_arg_shape, 1, data_type); |
| 324 | experimental::PostOpList<ITensorInfo*> post_ops{}; |
| 325 | post_ops.push_back_op<experimental::PostOpEltwiseAdd<ITensorInfo*>>( &post_op_arg_info, 0, ConvertPolicy::SATURATE); |
| 326 | |
| 327 | ARM_COMPUTE_EXPECT(is_post_op_list_valid(m, n, k, batch, data_type, post_ops) == false, framework::LogLevel::ERRORS); |
| 328 | } |
| 329 | TEST_SUITE_END() // Invalid |
| 330 | TEST_SUITE(Valid) |
| 331 | TEST_CASE(EmptyPostOpList, framework::DatasetMode::ALL) |
| 332 | { |
| 333 | const auto data_type = DataType::F32; |
| 334 | const unsigned int m = 22; |
| 335 | const unsigned int n = 16; |
| 336 | const unsigned int k = 15; |
| 337 | const unsigned int batch = 3; |
| 338 | experimental::PostOpList<ITensorInfo*> post_ops{}; |
| 339 | |
| 340 | ARM_COMPUTE_EXPECT(is_post_op_list_valid(m, n, k, batch, data_type, post_ops) == true, framework::LogLevel::ERRORS); |
| 341 | } |
| 342 | TEST_CASE(BroadcastInYDimOnly, framework::DatasetMode::ALL) |
| 343 | { |
| 344 | const auto data_type = DataType::F32; |
| 345 | const unsigned int m = 22; |
| 346 | const unsigned int n = 16; |
| 347 | const unsigned int k = 15; |
| 348 | const unsigned int batch = 3; |
| 349 | TensorShape post_op_arg_shape(n, 1, batch); |
| 350 | TensorInfo post_op_arg_info(post_op_arg_shape, 1, data_type); |
| 351 | experimental::PostOpList<ITensorInfo*> post_ops{}; |
| 352 | post_ops.push_back_op<experimental::PostOpEltwiseAdd<ITensorInfo*>>( &post_op_arg_info, 0, ConvertPolicy::SATURATE); |
| 353 | |
| 354 | ARM_COMPUTE_EXPECT(is_post_op_list_valid(m, n, k, batch, data_type, post_ops) == true, framework::LogLevel::ERRORS); |
| 355 | } |
| 356 | TEST_CASE(BroadcastInBothXandYDims, framework::DatasetMode::ALL) |
| 357 | { |
| 358 | const auto data_type = DataType::F32; |
| 359 | const unsigned int m = 22; |
| 360 | const unsigned int n = 16; |
| 361 | const unsigned int k = 15; |
| 362 | const unsigned int batch = 3; |
| 363 | TensorShape post_op_arg_shape(1, 1, batch); |
| 364 | TensorInfo post_op_arg_info(post_op_arg_shape, 1, data_type); |
| 365 | experimental::PostOpList<ITensorInfo*> post_ops{}; |
| 366 | post_ops.push_back_op<experimental::PostOpEltwiseAdd<ITensorInfo*>>( &post_op_arg_info, 0, ConvertPolicy::SATURATE); |
| 367 | |
| 368 | ARM_COMPUTE_EXPECT(is_post_op_list_valid(m, n, k, batch, data_type, post_ops) == true, framework::LogLevel::ERRORS); |
| 369 | } |
| 370 | TEST_CASE(BroadcastInAllDims, framework::DatasetMode::ALL) |
| 371 | { |
| 372 | const auto data_type = DataType::F32; |
| 373 | const unsigned int m = 22; |
| 374 | const unsigned int n = 16; |
| 375 | const unsigned int k = 15; |
| 376 | const unsigned int batch = 3; |
| 377 | TensorShape post_op_arg_shape(1, 1, 1); |
| 378 | TensorInfo post_op_arg_info(post_op_arg_shape, 1, data_type); |
| 379 | experimental::PostOpList<ITensorInfo*> post_ops{}; |
| 380 | post_ops.push_back_op<experimental::PostOpEltwiseAdd<ITensorInfo*>>( &post_op_arg_info, 0, ConvertPolicy::SATURATE); |
| 381 | |
| 382 | ARM_COMPUTE_EXPECT(is_post_op_list_valid(m, n, k, batch, data_type, post_ops) == true, framework::LogLevel::ERRORS); |
| 383 | } |
| 384 | TEST_SUITE_END() // Valid |
| 385 | TEST_SUITE_END() // ValidateFusedPostOps |
giuros01 | b3204e7 | 2019-04-01 13:50:22 +0100 | [diff] [blame] | 386 | TEST_SUITE(Float) |
| 387 | TEST_SUITE(FP32) |
Gian Marco Iodice | ca1f460 | 2019-07-16 15:46:48 +0100 | [diff] [blame] | 388 | DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(combine(combine(combine(combine(combine(combine(combine( |
giuros01 | b3204e7 | 2019-04-01 13:50:22 +0100 | [diff] [blame] | 389 | m_values, |
| 390 | n_values), |
| 391 | k_values), |
| 392 | framework::dataset::make("batch_size", 1)), |
| 393 | m0_values_precommit), |
| 394 | n0_values_precommit), |
| 395 | k0_values_precommit), |
Gian Marco Iodice | 944170e | 2019-06-24 14:40:30 +0100 | [diff] [blame] | 396 | broadcast_bias_values), |
Gian Marco Iodice | ca1f460 | 2019-07-16 15:46:48 +0100 | [diff] [blame] | 397 | act_values), |
| 398 | m_value, n_value, k_value, b_value, m0_value, n0_value, k0_value, broadcast_bias, act_value) |
giuros01 | b3204e7 | 2019-04-01 13:50:22 +0100 | [diff] [blame] | 399 | { |
Gian Marco Iodice | ca1f460 | 2019-07-16 15:46:48 +0100 | [diff] [blame] | 400 | validate_configuration(m_value, n_value, k_value, b_value, m0_value, n0_value, k0_value, broadcast_bias, DataType::F32, act_value); |
giuros01 | b3204e7 | 2019-04-01 13:50:22 +0100 | [diff] [blame] | 401 | } |
| 402 | |
SiCong Li | b972ae6 | 2020-08-03 15:39:45 +0100 | [diff] [blame] | 403 | FIXTURE_DATA_TEST_CASE(RunSmallBoundaryHandlingPartialInXPartialInY, CLGEMMMatrixMultiplyNativeFixture<float>, framework::DatasetMode::ALL, |
| 404 | combine(combine( |
| 405 | framework::dataset::make("M", 3), |
| 406 | framework::dataset::make("N", 1)), |
| 407 | boundary_handling_cases)) |
| 408 | { |
| 409 | // Validate output |
| 410 | validate(CLAccessor(_target), _reference, rel_tolerance_f32, 0.f, abs_tolerance_f32); |
| 411 | } |
| 412 | |
| 413 | FIXTURE_DATA_TEST_CASE(RunSmallBoundaryHandlingPartialInXFullInY, CLGEMMMatrixMultiplyNativeFixture<float>, framework::DatasetMode::ALL, |
| 414 | combine(combine( |
| 415 | framework::dataset::make("M", 64), |
| 416 | framework::dataset::make("N", 51)), |
| 417 | boundary_handling_cases)) |
| 418 | { |
| 419 | // Validate output |
| 420 | validate(CLAccessor(_target), _reference, rel_tolerance_f32, 0.f, abs_tolerance_f32); |
| 421 | } |
| 422 | |
| 423 | FIXTURE_DATA_TEST_CASE(RunSmallBoundaryHandlingFullInXFullInY, CLGEMMMatrixMultiplyNativeFixture<float>, framework::DatasetMode::ALL, |
| 424 | combine(combine( |
| 425 | framework::dataset::make("M", 64), |
| 426 | framework::dataset::make("N", 32)), |
| 427 | boundary_handling_cases)) |
| 428 | { |
| 429 | // Validate output |
| 430 | validate(CLAccessor(_target), _reference, rel_tolerance_f32, 0.f, abs_tolerance_f32); |
| 431 | } |
| 432 | |
| 433 | FIXTURE_DATA_TEST_CASE(RunSmallBoundaryHandlingFullInXPartialInY, CLGEMMMatrixMultiplyNativeFixture<float>, framework::DatasetMode::ALL, |
| 434 | combine(combine( |
| 435 | framework::dataset::make("M", 37), |
| 436 | framework::dataset::make("N", 32)), |
| 437 | boundary_handling_cases)) |
| 438 | { |
| 439 | // Validate output |
| 440 | validate(CLAccessor(_target), _reference, rel_tolerance_f32, 0.f, abs_tolerance_f32); |
| 441 | } |
| 442 | |
giuros01 | b3204e7 | 2019-04-01 13:50:22 +0100 | [diff] [blame] | 443 | FIXTURE_DATA_TEST_CASE(RunSmall, CLGEMMMatrixMultiplyNativeFixture<float>, framework::DatasetMode::ALL, |
Gian Marco Iodice | ca1f460 | 2019-07-16 15:46:48 +0100 | [diff] [blame] | 444 | combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine( |
giuros01 | b3204e7 | 2019-04-01 13:50:22 +0100 | [diff] [blame] | 445 | m_values, |
| 446 | n_values), |
| 447 | k_values), |
| 448 | b_values), |
| 449 | m0_values_precommit), |
| 450 | n0_values_precommit), |
| 451 | k0_values_precommit), |
| 452 | framework::dataset::make("DataType", DataType::F32)), |
Gian Marco Iodice | 944170e | 2019-06-24 14:40:30 +0100 | [diff] [blame] | 453 | a_values), |
| 454 | beta_values), |
Gian Marco Iodice | ca1f460 | 2019-07-16 15:46:48 +0100 | [diff] [blame] | 455 | broadcast_bias_values), |
| 456 | act_values)) |
giuros01 | b3204e7 | 2019-04-01 13:50:22 +0100 | [diff] [blame] | 457 | { |
| 458 | // Validate output |
| 459 | validate(CLAccessor(_target), _reference, rel_tolerance_f32, 0.f, abs_tolerance_f32); |
| 460 | } |
| 461 | |
Michalis Spyrou | 1d89777 | 2019-12-09 18:47:29 +0000 | [diff] [blame] | 462 | FIXTURE_DATA_TEST_CASE(RunLarge, CLGEMMMatrixMultiplyNativeFixture<float>, framework::DatasetMode::DISABLED, |
Gian Marco Iodice | ca1f460 | 2019-07-16 15:46:48 +0100 | [diff] [blame] | 463 | combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine( |
giuros01 | b3204e7 | 2019-04-01 13:50:22 +0100 | [diff] [blame] | 464 | m_values, |
| 465 | n_values), |
| 466 | k_values), |
| 467 | b_values), |
| 468 | m0_values_nightly), |
| 469 | n0_values_nightly), |
| 470 | k0_values_nightly), |
| 471 | framework::dataset::make("DataType", DataType::F32)), |
Gian Marco Iodice | 944170e | 2019-06-24 14:40:30 +0100 | [diff] [blame] | 472 | a_values), |
| 473 | beta_values), |
Gian Marco Iodice | ca1f460 | 2019-07-16 15:46:48 +0100 | [diff] [blame] | 474 | broadcast_bias_values), |
| 475 | act_values)) |
giuros01 | b3204e7 | 2019-04-01 13:50:22 +0100 | [diff] [blame] | 476 | { |
| 477 | // Validate output |
| 478 | validate(CLAccessor(_target), _reference, rel_tolerance_f32, 0.f, abs_tolerance_f32); |
| 479 | } |
| 480 | |
| 481 | FIXTURE_DATA_TEST_CASE(RunSmall3D, CLGEMMMatrixMultiplyNative3DFixture<float>, framework::DatasetMode::ALL, |
Gian Marco Iodice | ca1f460 | 2019-07-16 15:46:48 +0100 | [diff] [blame] | 482 | combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine( |
giuros01 | b3204e7 | 2019-04-01 13:50:22 +0100 | [diff] [blame] | 483 | m_w_values, |
| 484 | m_h_values), |
| 485 | n_values), |
| 486 | k_values), |
| 487 | b_values), |
| 488 | m0_values_precommit), |
| 489 | n0_values_precommit), |
| 490 | k0_values_precommit), |
| 491 | framework::dataset::make("DataType", DataType::F32)), |
Gian Marco Iodice | 944170e | 2019-06-24 14:40:30 +0100 | [diff] [blame] | 492 | a_values), |
Gian Marco Iodice | ca1f460 | 2019-07-16 15:46:48 +0100 | [diff] [blame] | 493 | beta_values), |
| 494 | act_values)) |
giuros01 | b3204e7 | 2019-04-01 13:50:22 +0100 | [diff] [blame] | 495 | { |
| 496 | // Validate output |
| 497 | validate(CLAccessor(_target), _reference, rel_tolerance_f32, 0.f, abs_tolerance_f32); |
| 498 | } |
| 499 | |
Michalis Spyrou | 1d89777 | 2019-12-09 18:47:29 +0000 | [diff] [blame] | 500 | FIXTURE_DATA_TEST_CASE(RunLarge3D, CLGEMMMatrixMultiplyNative3DFixture<float>, framework::DatasetMode::DISABLED, |
Gian Marco Iodice | ca1f460 | 2019-07-16 15:46:48 +0100 | [diff] [blame] | 501 | combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine( |
giuros01 | b3204e7 | 2019-04-01 13:50:22 +0100 | [diff] [blame] | 502 | m_w_values, |
| 503 | m_h_values), |
| 504 | n_values), |
| 505 | k_values), |
| 506 | b_values), |
| 507 | m0_values_nightly), |
| 508 | n0_values_nightly), |
| 509 | k0_values_nightly), |
| 510 | framework::dataset::make("DataType", DataType::F32)), |
Gian Marco Iodice | 944170e | 2019-06-24 14:40:30 +0100 | [diff] [blame] | 511 | a_values), |
Gian Marco Iodice | ca1f460 | 2019-07-16 15:46:48 +0100 | [diff] [blame] | 512 | beta_values), |
| 513 | act_values)) |
giuros01 | b3204e7 | 2019-04-01 13:50:22 +0100 | [diff] [blame] | 514 | { |
| 515 | // Validate output |
| 516 | validate(CLAccessor(_target), _reference, rel_tolerance_f32, 0.f, abs_tolerance_f32); |
| 517 | } |
SiCongLi | afa1972 | 2021-10-24 19:12:33 +0100 | [diff] [blame^] | 518 | |
| 519 | TEST_SUITE(FusedPostOps) |
| 520 | |
| 521 | FIXTURE_DATA_TEST_CASE(RunSmall, CLGEMMMatrixMultiplyNativeWithPostOpsFixture<float>, framework::DatasetMode::ALL, |
| 522 | combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine( |
| 523 | m_values, |
| 524 | n_values), |
| 525 | k_values), |
| 526 | b_values), |
| 527 | framework::dataset::make("M0", { 4 })), |
| 528 | n0_values_precommit), |
| 529 | k0_values_precommit), |
| 530 | framework::dataset::make("DataType", DataType::F32)), |
| 531 | framework::dataset::make("alpha", {1.0f} )), |
| 532 | framework::dataset::make("beta", {1.0f} )), |
| 533 | framework::dataset::make("broadcast_bias", { false, true } )), |
| 534 | framework::dataset::make("Activation", { ActivationLayerInfo() })), |
| 535 | post_op_lists) |
| 536 | ) |
| 537 | { |
| 538 | // Validate output |
| 539 | validate(CLAccessor(_target), _reference, rel_tolerance_f32, 0.f, abs_tolerance_f32); |
| 540 | } |
| 541 | |
| 542 | TEST_SUITE_END() // FusedPostOps |
| 543 | |
giuros01 | b3204e7 | 2019-04-01 13:50:22 +0100 | [diff] [blame] | 544 | TEST_SUITE_END() // FP32 |
giuros01 | b3204e7 | 2019-04-01 13:50:22 +0100 | [diff] [blame] | 545 | TEST_SUITE_END() // Float |
| 546 | TEST_SUITE_END() // GEMMMatrixMulipltyNative |
| 547 | TEST_SUITE_END() // CL |
| 548 | } // namespace validation |
| 549 | } // namespace test |
| 550 | } // namespace arm_compute |