From 08ddd7b1c6c6c08361115142eb58e43267d5f264 Mon Sep 17 00:00:00 2001 From: Gian Marco Iodice Date: Wed, 19 Dec 2018 10:01:18 +0000 Subject: COMPMID-1834: Add transpose support to CLGEMMReshapeLHSMatrixKernel Change-Id: I913a7297a0c34a05b1d37eab1489b430423700e8 Reviewed-on: https://review.mlplatform.org/417 Tested-by: Arm Jenkins Reviewed-by: Michele Di Giorgio --- .../core/CL/kernels/CLGEMMReshapeLHSMatrixKernel.h | 4 +- src/core/CL/CLKernelLibrary.cpp | 1 + src/core/CL/cl_kernels/gemm.cl | 290 ++++++++++++++++++++- .../CL/kernels/CLGEMMReshapeLHSMatrixKernel.cpp | 1 - tests/validation/CL/GEMMReshapeLHSMatrix.cpp | 188 +++++++------ 5 files changed, 397 insertions(+), 87 deletions(-) diff --git a/arm_compute/core/CL/kernels/CLGEMMReshapeLHSMatrixKernel.h b/arm_compute/core/CL/kernels/CLGEMMReshapeLHSMatrixKernel.h index 77d7494a7f..6c9b2a0d27 100644 --- a/arm_compute/core/CL/kernels/CLGEMMReshapeLHSMatrixKernel.h +++ b/arm_compute/core/CL/kernels/CLGEMMReshapeLHSMatrixKernel.h @@ -56,7 +56,7 @@ public: * lhs_info.m0: 2,3,4,5,6,7,8 * lhs_info.k0: 2,4,8,16 * lhs_info.v0: greater than 0 - * lhs_info.transpose: false + * lhs_info.transpose: true, false * lhs_info.interleave: true, false * @param[in] reinterpret_input_as_3d (Optional) True if the input has to be reinterpreted as 3D tensor */ @@ -70,7 +70,7 @@ public: * lhs_info.m0: 2,3,4,5,6,7,8 * lhs_info.k0: 2,4,8,16 * lhs_info.v0: greater than 0 - * lhs_info.transpose: false + * lhs_info.transpose: true, false * lhs_info.interleave: true, false * @param[in] reinterpret_input_as_3d True if the input has to be reinterpreted as 3D tensor * diff --git a/src/core/CL/CLKernelLibrary.cpp b/src/core/CL/CLKernelLibrary.cpp index ea5342c19d..470a50f76b 100644 --- a/src/core/CL/CLKernelLibrary.cpp +++ b/src/core/CL/CLKernelLibrary.cpp @@ -284,6 +284,7 @@ const std::map CLKernelLibrary::_kernel_program_map = { "gemm_lc_vm_f32", "gemm.cl" }, { "gemm_transpose1xW", "gemm.cl" }, { "gemm_reshape_lhs_matrix_nt", "gemm.cl" }, + { "gemm_reshape_lhs_matrix_t", "gemm.cl" }, { "gemm_reshape_rhs_matrix_nt", "gemm.cl" }, { "gemm_reshape_rhs_matrix_t", "gemm.cl" }, { "gemmlowp_matrix_a_reduction", "gemmlowp.cl" }, diff --git a/src/core/CL/cl_kernels/gemm.cl b/src/core/CL/cl_kernels/gemm.cl index 44b50b3caa..35971f3d7e 100644 --- a/src/core/CL/cl_kernels/gemm.cl +++ b/src/core/CL/cl_kernels/gemm.cl @@ -246,6 +246,294 @@ __kernel void gemm_reshape_lhs_matrix_nt(TENSOR3D_DECLARATION(src), (a7, 0, (__global DATA_TYPE *)(output_ptr + 7 * OUTPUT_STEP_X * sizeof(DATA_TYPE))); #endif // M0 > 7 +#undef BLOCK_SIZE +#undef OUTPUT_OFFSET_X +#undef OUTPUT_STEP_X +} + +#if M0 == 2 +#define TRANSPOSE_COLUMN_AND_STORE(output_ptr, output_step_x, i) \ + ({ \ + VEC_DATA_TYPE(DATA_TYPE, M0) \ + res = (VEC_DATA_TYPE(DATA_TYPE, M0))(a0.s##i, a1.s##i); \ + VSTORE(M0) \ + (res, 0, (__global DATA_TYPE *)(output_ptr + 0x##i * output_step_x * sizeof(DATA_TYPE))); \ + }) +#elif M0 == 3 // M0 == 3 +#define TRANSPOSE_COLUMN_AND_STORE(output_ptr, output_step_x, i) \ + ({ \ + VEC_DATA_TYPE(DATA_TYPE, M0) \ + res = (VEC_DATA_TYPE(DATA_TYPE, M0))(a0.s##i, a1.s##i, a2.s##i); \ + VSTORE(M0) \ + (res, 0, (__global DATA_TYPE *)(output_ptr + 0x##i * output_step_x * sizeof(DATA_TYPE))); \ + }) +#elif M0 == 4 // M0 == 4 +#define TRANSPOSE_COLUMN_AND_STORE(output_ptr, output_step_x, i) \ + ({ \ + VEC_DATA_TYPE(DATA_TYPE, M0) \ + res = (VEC_DATA_TYPE(DATA_TYPE, M0))(a0.s##i, a1.s##i, a2.s##i, a3.s##i); \ + VSTORE(M0) \ + (res, 0, (__global DATA_TYPE *)(output_ptr + 0x##i * output_step_x * sizeof(DATA_TYPE))); \ + }) +#elif M0 == 5 // M0 == 5 +#define TRANSPOSE_COLUMN_AND_STORE(output_ptr, output_step_x, i) \ + ({ \ + VEC_DATA_TYPE(DATA_TYPE, 4) \ + res0 = (VEC_DATA_TYPE(DATA_TYPE, 4))(a0.s##i, a1.s##i, a2.s##i, a3.s##i); \ + DATA_TYPE res1 = a4.s##i; \ + VSTORE(4) \ + (res0, 0, (__global DATA_TYPE *)(output_ptr + 0x##i * output_step_x * sizeof(DATA_TYPE))); \ + *((__global DATA_TYPE *)(output_ptr + 0x##i * output_step_x * sizeof(DATA_TYPE)) + 4) = res1; \ + }) +#elif M0 == 6 // M0 == 6 +#define TRANSPOSE_COLUMN_AND_STORE(output_ptr, output_step_x, i) \ + ({ \ + VEC_DATA_TYPE(DATA_TYPE, 4) \ + res0 = (VEC_DATA_TYPE(DATA_TYPE, 4))(a0.s##i, a1.s##i, a2.s##i, a3.s##i); \ + VEC_DATA_TYPE(DATA_TYPE, 2) \ + res1 = (VEC_DATA_TYPE(DATA_TYPE, 2))(a4.s##i, a5.s##i); \ + VSTORE(4) \ + (res0, 0, (__global DATA_TYPE *)(output_ptr + 0x##i * output_step_x * sizeof(DATA_TYPE))); \ + VSTORE(2) \ + (res1, 0, (__global DATA_TYPE *)(output_ptr + 0x##i * output_step_x * sizeof(DATA_TYPE)) + 4); \ + }) +#elif M0 == 7 // M0 == 7 +#define TRANSPOSE_COLUMN_AND_STORE(output_ptr, output_step_x, i) \ + ({ \ + VEC_DATA_TYPE(DATA_TYPE, 4) \ + res0 = (VEC_DATA_TYPE(DATA_TYPE, 4))(a0.s##i, a1.s##i, a2.s##i, a3.s##i); \ + VEC_DATA_TYPE(DATA_TYPE, 3) \ + res1 = (VEC_DATA_TYPE(DATA_TYPE, 3))(a4.s##i, a5.s##i, a6.s##i); \ + VSTORE(4) \ + (res0, 0, (__global DATA_TYPE *)(output_ptr + 0x##i * output_step_x * sizeof(DATA_TYPE))); \ + VSTORE(3) \ + (res1, 0, (__global DATA_TYPE *)(output_ptr + 0x##i * output_step_x * sizeof(DATA_TYPE)) + 4); \ + }) +#elif M0 == 8 // M0 == 8 +#define TRANSPOSE_COLUMN_AND_STORE(output_ptr, output_step_x, i) \ + ({ \ + VEC_DATA_TYPE(DATA_TYPE, M0) \ + res = (VEC_DATA_TYPE(DATA_TYPE, M0))(a0.s##i, a1.s##i, a2.s##i, a3.s##i, a4.s##i, a5.s##i, a6.s##i, a7.s##i); \ + VSTORE(M0) \ + (res, 0, (__global DATA_TYPE *)(output_ptr + 0x##i * output_step_x * sizeof(DATA_TYPE))); \ + }) +#else // M0 not supported +#error "M0 value not supported" +#endif // N0 conditions + +/** This OpenCL kernel reshapes the lhs input matrix. The kernel splits the input matrix in blocks of size M0xK0 and stores each one (transposed) in + * the output matrix unrolling the values. + * + * @note The data type must be passed at compile time using -DDATA_TYPE (i.e. -DDATA_TYPE=float) + * @note The block's dimensions (M0 and K0) must be passed at compile time using -DM0 and -DK0 (i.e. -DM0=2, -DK0=2). + * @note The number of M0xK0 vertical blocks to store on the same output row must be passed at compile time using -DV0 (i.e. -DV0=2) + * @note Only the following values for M0, K0 and V0 are supported: + * M0: 2,3,4,5,6,7,8 + * K0: 2,4,8,16 + * V0: greater than 0 + * @note In case the input has to be reinterpreted as a 3D tensor (i.e. input of convolution layer 1x1), the following information must be passed at compile time: + * -# REINTERPRET_INPUT_AS_3D: To reinterpret the input as 3D + * -# HEIGHT_GEMM3D: The height of the input in case it has to be reinterpreted as a 3D tensor. + * -# DEPTH_GEMM3D: The depth of the input in case it has to be reinterpreted as a 3D tensor + * (HEIGHT_GEMM3D * DEPTH_GEMM3D) = columns matrix A NOT reshaped + * @note If the M0xK0 blocks have to be interleaved, the option -DINTERLEAVE must passed at compile time. + * + * @param[in] src_ptr Pointer to the source LHS tensor. Supported data types: U8/S8/QASYMM8/U16/S16/F16/U32/S32/F32 + * @param[in] src_stride_x Stride of the source LHS tensor in X dimension (in bytes) + * @param[in] src_step_x src_stride_x * number of elements along X processed per workitem(in bytes) + * @param[in] src_stride_y Stride of the source LHS tensor in Y dimension (in bytes) + * @param[in] src_step_y src_stride_y * number of elements along Y processed per workitem(in bytes) + * @param[in] src_stride_z Stride of the source LHS tensor in Z dimension (in bytes) + * @param[in] src_step_z src_stride_z * number of elements along Z processed per workitem(in bytes) + * @param[in] src_offset_first_element_in_bytes The offset of the first element in the source LHS tensor + * @param[out] dst_ptr Pointer to the destination matrix Supported data types: same as @p src_ptr + * @param[in] dst_stride_x Stride of the destination matrix in X dimension (in bytes) + * @param[in] dst_step_x dst_stride_x * number of elements along X processed per workitem(in bytes) + * @param[in] dst_stride_y Stride of the destination matrix in Y dimension (in bytes) + * @param[in] dst_step_y dst_stride_y * number of elements along Y processed per workitem(in bytes) + * @param[in] dst_stride_z Stride of the destination tensor in Z dimension (in bytes) + * @param[in] dst_step_z dst_stride_z * number of elements along Z processed per workitem(in bytes) + * @param[in] dst_offset_first_element_in_bytes The offset of the first element in the destination matrix + * @param[in] cross_plane_pad (Optional) Bottom paddings in unit of elements (only if defined REINTERPRET_INPUT_AS_3D) + */ +__kernel void gemm_reshape_lhs_matrix_t(TENSOR3D_DECLARATION(src), + TENSOR3D_DECLARATION(dst) +#if defined(REINTERPRET_INPUT_AS_3D) + , + uint cross_plane_pad +#endif // REINTERPRET_INPUT_AS_3D + ) +{ + // Block size +#define BLOCK_SIZE ((M0) * (K0)) + + // Output offset X +#if defined(INTERLEAVE) +#define OUTPUT_OFFSET_X (M0) +#else // defined(INTERLEAVE) +#define OUTPUT_OFFSET_X (BLOCK_SIZE) +#endif // defined(INTERLEAVE) + + // Output step X +#if defined(INTERLEAVE) +#define OUTPUT_STEP_X (M0) * (V0) +#else // Do not interleave +#define OUTPUT_STEP_X (M0) +#endif // defined(INTERLEAVE) + + // Compute source and destination addresses + uint x = get_global_id(0); + uint y = get_global_id(1); + uint z = get_global_id(2); + + // ------------------ Compute input/output addresses --------------------------- + + // Compute the input address + __global uchar *input_ptr = src_ptr + src_offset_first_element_in_bytes + x * (uint)K0 * sizeof(DATA_TYPE) + y * (uint)M0 * src_stride_y; + + // Compute the output address + __global uchar *output_ptr = dst_ptr + dst_offset_first_element_in_bytes + (x * (uint)BLOCK_SIZE * (uint)V0 * sizeof(DATA_TYPE)) + ((y / (uint)V0) * (uint)dst_stride_y) + ((y % V0) * + (uint)OUTPUT_OFFSET_X * sizeof(DATA_TYPE)); + + uint zin0 = 0; + uint zin1 = 0; + uint zin2 = 0; + uint zin3 = 0; + uint zin4 = 0; + uint zin5 = 0; + uint zin6 = 0; + uint zin7 = 0; + +#if defined(REINTERPRET_INPUT_AS_3D) + // Add offset for batched GEMM. The batches will be in the fourth dimension and for this reason we + // multiply src_stride_z by DEPTH_GEMM3D + + // Note for the REINTERPRET_INPUT_AS_3D case + // Since we load a 2D input tile from a 3D tensor, we need to check when the plane changes across the z dimension + // in order to take into account the presence of possible cross plane paddings + // + // | | + // | plane0 | + // | | + // |__________________| + // |******************| + // | cross_plane_pad | + // |******************| + // | | + // | plane1 | + // | | + // |__________________| + + input_ptr += z * (uint)src_stride_z * DEPTH_GEMM3D; + + // The plane (zin) is calculated dividing M (y * M0) by HEIGHT_GEMM3D + zin0 = (0 + (uint)(y * M0)) / (uint)HEIGHT_GEMM3D; + zin0 = min((uint)(DEPTH_GEMM3D - 1), zin0); + zin0 *= (cross_plane_pad * src_stride_y); +#if M0 > 1 + zin1 = (1 + (uint)(y * M0)) / (uint)HEIGHT_GEMM3D; + zin1 = min((uint)(DEPTH_GEMM3D - 1), zin1); + zin1 *= (cross_plane_pad * src_stride_y); +#endif // M0 > 1 +#if M0 > 2 + zin2 = (2 + (uint)(y * M0)) / (uint)HEIGHT_GEMM3D; + zin2 = min((uint)(DEPTH_GEMM3D - 1), zin2); + zin2 *= (cross_plane_pad * src_stride_y); +#endif // M0 > 2 +#if M0 > 3 + zin3 = (3 + (uint)(y * M0)) / (uint)HEIGHT_GEMM3D; + zin3 = min((uint)(DEPTH_GEMM3D - 1), zin3); + zin3 *= (cross_plane_pad * src_stride_y); +#endif // M0 > 3 +#if M0 > 4 + zin4 = (4 + (uint)(y * M0)) / (uint)HEIGHT_GEMM3D; + zin4 = min((uint)(DEPTH_GEMM3D - 1), zin4); + zin4 *= (cross_plane_pad * src_stride_y); +#endif // M0 > 4 +#if M0 > 5 + zin5 = (5 + (uint)(y * M0)) / (uint)HEIGHT_GEMM3D; + zin5 = min((uint)(DEPTH_GEMM3D - 1), zin5); + zin5 *= (cross_plane_pad * src_stride_y); +#endif // M0 > 5 +#if M0 > 6 + zin6 = (6 + (uint)(y * M0)) / (uint)HEIGHT_GEMM3D; + zin6 = min((uint)(DEPTH_GEMM3D - 1), zin6); + zin6 *= (cross_plane_pad * src_stride_y); +#endif // M0 > 6 +#if M0 > 6 + zin7 = (7 + (uint)(y * M0)) / (uint)HEIGHT_GEMM3D; + zin7 = min((uint)(DEPTH_GEMM3D - 1), zin7); + zin7 *= (cross_plane_pad * src_stride_y); +#endif // M0 > 7 + +#else // defined(REINTERPRET_INPUT_AS_3D) + + input_ptr += z * (uint)src_stride_z; + +#endif // defined(REINTERPRET_INPUT_AS_3D) + + // Add offset for batched GEMM + output_ptr += z * (uint)dst_stride_z; + + // ---------------------------Load input values -------------------------------- + + // Load values from the LHS matrix + VEC_DATA_TYPE(DATA_TYPE, K0) + a0 = VLOAD(K0)(0, (__global DATA_TYPE *)(input_ptr + 0 * src_stride_y + zin0)); +#if M0 > 1 + VEC_DATA_TYPE(DATA_TYPE, K0) + a1 = VLOAD(K0)(0, (__global DATA_TYPE *)(input_ptr + 1 * src_stride_y + zin1)); +#endif // M0 > 1 +#if M0 > 2 + VEC_DATA_TYPE(DATA_TYPE, K0) + a2 = VLOAD(K0)(0, (__global DATA_TYPE *)(input_ptr + 2 * src_stride_y + zin2)); +#endif // M0 > 2 +#if M0 > 3 + VEC_DATA_TYPE(DATA_TYPE, K0) + a3 = VLOAD(K0)(0, (__global DATA_TYPE *)(input_ptr + 3 * src_stride_y + zin3)); +#endif // M0 > 3 +#if M0 > 4 + VEC_DATA_TYPE(DATA_TYPE, K0) + a4 = VLOAD(K0)(0, (__global DATA_TYPE *)(input_ptr + 4 * src_stride_y + zin4)); +#endif // M0 > 4 +#if M0 > 5 + VEC_DATA_TYPE(DATA_TYPE, K0) + a5 = VLOAD(K0)(0, (__global DATA_TYPE *)(input_ptr + 5 * src_stride_y + zin5)); +#endif // M0 > 5 +#if M0 > 6 + VEC_DATA_TYPE(DATA_TYPE, K0) + a6 = VLOAD(K0)(0, (__global DATA_TYPE *)(input_ptr + 6 * src_stride_y + zin6)); +#endif // M0 > 6 +#if M0 > 7 + VEC_DATA_TYPE(DATA_TYPE, K0) + a7 = VLOAD(K0)(0, (__global DATA_TYPE *)(input_ptr + 7 * src_stride_y + zin7)); +#endif // M0 > 7 + + // ---------------------------Transpose and store block ----------------------- + + TRANSPOSE_COLUMN_AND_STORE(output_ptr, OUTPUT_STEP_X, 0); + TRANSPOSE_COLUMN_AND_STORE(output_ptr, OUTPUT_STEP_X, 1); +#if K0 > 2 + TRANSPOSE_COLUMN_AND_STORE(output_ptr, OUTPUT_STEP_X, 2); + TRANSPOSE_COLUMN_AND_STORE(output_ptr, OUTPUT_STEP_X, 3); +#endif // K0 > 2 +#if K0 > 4 + TRANSPOSE_COLUMN_AND_STORE(output_ptr, OUTPUT_STEP_X, 4); + TRANSPOSE_COLUMN_AND_STORE(output_ptr, OUTPUT_STEP_X, 5); + TRANSPOSE_COLUMN_AND_STORE(output_ptr, OUTPUT_STEP_X, 6); + TRANSPOSE_COLUMN_AND_STORE(output_ptr, OUTPUT_STEP_X, 7); +#endif // K0 > 4 +#if K0 > 8 + TRANSPOSE_COLUMN_AND_STORE(output_ptr, OUTPUT_STEP_X, 8); + TRANSPOSE_COLUMN_AND_STORE(output_ptr, OUTPUT_STEP_X, 9); + TRANSPOSE_COLUMN_AND_STORE(output_ptr, OUTPUT_STEP_X, A); + TRANSPOSE_COLUMN_AND_STORE(output_ptr, OUTPUT_STEP_X, B); + TRANSPOSE_COLUMN_AND_STORE(output_ptr, OUTPUT_STEP_X, C); + TRANSPOSE_COLUMN_AND_STORE(output_ptr, OUTPUT_STEP_X, D); + TRANSPOSE_COLUMN_AND_STORE(output_ptr, OUTPUT_STEP_X, E); + TRANSPOSE_COLUMN_AND_STORE(output_ptr, OUTPUT_STEP_X, F); +#endif // K0 > 8 + #undef BLOCK_SIZE #undef OUTPUT_OFFSET_X #undef OUTPUT_STEP_X @@ -391,7 +679,7 @@ __kernel void gemm_reshape_rhs_matrix_nt(TENSOR3D_DECLARATION(src), } #endif // K0 > 4 #if K0 > 8 - if(y * (uint)K0 + 9 < SRC_HEIGHT) + if(y * (uint)K0 + 8 < SRC_HEIGHT) { a8 = VLOAD(N0)(0, (__global DATA_TYPE *)(input_ptr + 8 * src_stride_y)); } diff --git a/src/core/CL/kernels/CLGEMMReshapeLHSMatrixKernel.cpp b/src/core/CL/kernels/CLGEMMReshapeLHSMatrixKernel.cpp index e0af5801a8..d667781dd7 100644 --- a/src/core/CL/kernels/CLGEMMReshapeLHSMatrixKernel.cpp +++ b/src/core/CL/kernels/CLGEMMReshapeLHSMatrixKernel.cpp @@ -44,7 +44,6 @@ namespace { Status validate_arguments(const ITensorInfo *input, const ITensorInfo *output, const GEMMLHSMatrixInfo &lhs_info, bool reinterpret_input_as_3d) { - ARM_COMPUTE_RETURN_ERROR_ON(lhs_info.transpose); ARM_COMPUTE_RETURN_ERROR_ON(lhs_info.m0 == 0); ARM_COMPUTE_RETURN_ERROR_ON(lhs_info.k0 == 0); ARM_COMPUTE_RETURN_ERROR_ON(lhs_info.v0 == 0); diff --git a/tests/validation/CL/GEMMReshapeLHSMatrix.cpp b/tests/validation/CL/GEMMReshapeLHSMatrix.cpp index ea6589df22..a2dd9c2a0a 100644 --- a/tests/validation/CL/GEMMReshapeLHSMatrix.cpp +++ b/tests/validation/CL/GEMMReshapeLHSMatrix.cpp @@ -42,21 +42,40 @@ namespace test { namespace validation { -namespace -{ +using namespace arm_compute::misc::shape_calculator; + +// Initialize the output tensor with zero and fill the border with zero +using CLGEMMReshapeLHSMatrix = CLSynthetizeFunctionInitOutputWithZeroAndWithZeroConstantBorder; + +template +using CLGEMMReshapeLHSMatrixFixture = GEMMReshapeLHSMatrixValidationFixture; + +// Fixture to use when the input has to be reinterpreted as 3D +template +using CLGEMMReshapeLHSMatrix3DFixture = GEMMReshapeLHSMatrixValidationFixture; + // *INDENT-OFF* // clang-format off /** Data types */ + +namespace +{ const auto data_types = framework::dataset::make("DataType", { DataType::QASYMM8, DataType::F16, DataType::F32 }); /** Batch size values to test */ const auto b_values = framework::dataset::make("batchsize", 1, 3); -/** M0 values to test */ -const auto m0_values = framework::dataset::make("M0", 2, 9); +/** M0 values to test - Precommit */ +const auto m0_values_precommit = framework::dataset::make("M0", { 2, 4, 5 }); -/** K0 values to test */ -const auto k0_values = framework::dataset::make("K0", { 2, 4, 8, 16 }); +/** K0 values to test - Precommit */ +const auto k0_values_precommit = framework::dataset::make("K0", { 2, 4 }); + +/** M0 values to test - Precommit */ +const auto m0_values_nightly = framework::dataset::make("M0", 2, 9); + +/** K0 values to test - Precommit */ +const auto k0_values_nightly = framework::dataset::make("K0", { 2, 4, 8, 16 }); /** V0 values to test */ const auto v0_values = framework::dataset::make("V0", 1, 4); @@ -65,33 +84,10 @@ const auto v0_values = framework::dataset::make("V0", 1, 4); const auto i_values = framework::dataset::make("interleave", { true, false }); /** Transpose values to test */ -const auto t_values = framework::dataset::make("transpose", { false }); -} // namespace - -using namespace arm_compute::misc::shape_calculator; +const auto t_values = framework::dataset::make("transpose", { true, false }); -// Initialize the output tensor with zero and fill the border with zero -using CLGEMMReshapeLHSMatrix = CLSynthetizeFunctionInitOutputWithZeroAndWithZeroConstantBorder; - -template -using CLGEMMReshapeLHSMatrixFixture = GEMMReshapeLHSMatrixValidationFixture; - -// Fixture to use when the input has to be reinterpreted as 3D -template -using CLGEMMReshapeLHSMatrix3DFixture = GEMMReshapeLHSMatrixValidationFixture; - -TEST_SUITE(CL) -TEST_SUITE(GEMMReshapeLHSMatrix) - -DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(combine(combine(combine(combine(combine(combine(datasets::SmallGEMMReshape2DShapes(), - b_values), - data_types), - m0_values), - k0_values), - v0_values), - i_values), - t_values), -shape_in, b_value, data_type, m0_value, k0_value, v0_value, i_value, t_value) +/** Configuration test */ +void validate_configuration(TensorShape shape_in, unsigned int b_value, DataType data_type, unsigned int m0_value, unsigned int k0_value, unsigned int v0_value, bool i_value, bool t_value, bool reinterpret_input_as_3d) { GEMMLHSMatrixInfo lhs_info; lhs_info.m0 = m0_value; @@ -100,8 +96,10 @@ shape_in, b_value, data_type, m0_value, k0_value, v0_value, i_value, t_value) lhs_info.interleave = i_value; lhs_info.transpose = t_value; - const TensorShape shape_src(shape_in[0], shape_in[1], b_value); - const TensorShape shape_dst = compute_lhs_reshaped_shape(TensorInfo(shape_src, 1, data_type), lhs_info, false); + TensorShape shape_src = shape_in; + shape_src.set(shape_src.num_dimensions(), b_value); + + const TensorShape shape_dst = compute_lhs_reshaped_shape(TensorInfo(shape_src, 1, data_type), lhs_info, reinterpret_input_as_3d); // Create tensors CLTensor src = create_tensor(shape_src, data_type); @@ -112,7 +110,37 @@ shape_in, b_value, data_type, m0_value, k0_value, v0_value, i_value, t_value) // Create and configure function CLGEMMReshapeLHSMatrixKernel reshape_lhs; - reshape_lhs.configure(&src, &dst, lhs_info, false); + reshape_lhs.configure(&src, &dst, lhs_info, reinterpret_input_as_3d); +} +} // namespace + +TEST_SUITE(CL) +TEST_SUITE(GEMMReshapeLHSMatrix) + +DATA_TEST_CASE(ConfigurationSmall, framework::DatasetMode::ALL, combine(combine(combine(combine(combine(combine(combine(datasets::SmallGEMMReshape2DShapes(), + b_values), + data_types), + m0_values_precommit), + k0_values_precommit), + v0_values), + i_values), + t_values), +shape_in, b_value, data_type, m0_value, k0_value, v0_value, i_value, t_value) +{ + validate_configuration(shape_in, b_value, data_type, m0_value, k0_value, v0_value, i_value, t_value, false); +} + +DATA_TEST_CASE(ConfigurationLarge, framework::DatasetMode::NIGHTLY, combine(combine(combine(combine(combine(combine(combine(datasets::LargeGEMMReshape2DShapes(), + b_values), + data_types), + m0_values_nightly), + k0_values_nightly), + v0_values), + i_values), + t_values), +shape_in, b_value, data_type, m0_value, k0_value, v0_value, i_value, t_value) +{ + validate_configuration(shape_in, b_value, data_type, m0_value, k0_value, v0_value, i_value, t_value, false); } TEST_SUITE(S32) @@ -120,8 +148,8 @@ FIXTURE_DATA_TEST_CASE(RunSmall, CLGEMMReshapeLHSMatrixFixture, framework:: combine(combine(combine(combine(combine(combine(combine(datasets::SmallGEMMReshape2DShapes(), b_values), framework::dataset::make("DataType", DataType::S32)), - m0_values), - k0_values), + m0_values_precommit), + k0_values_precommit), v0_values), i_values), t_values)) @@ -134,8 +162,8 @@ FIXTURE_DATA_TEST_CASE(RunLarge, CLGEMMReshapeLHSMatrixFixture, framework:: combine(combine(combine(combine(combine(combine(combine(datasets::LargeGEMMReshape2DShapes(), b_values), framework::dataset::make("DataType", DataType::S32)), - m0_values), - k0_values), + m0_values_nightly), + k0_values_nightly), v0_values), i_values), t_values)) @@ -150,8 +178,8 @@ FIXTURE_DATA_TEST_CASE(RunSmall, CLGEMMReshapeLHSMatrixFixture, framework combine(combine(combine(combine(combine(combine(combine(datasets::SmallGEMMReshape2DShapes(), b_values), framework::dataset::make("DataType", DataType::S16)), - m0_values), - k0_values), + m0_values_precommit), + k0_values_precommit), v0_values), i_values), t_values)) @@ -164,8 +192,8 @@ FIXTURE_DATA_TEST_CASE(RunLarge, CLGEMMReshapeLHSMatrixFixture, framework combine(combine(combine(combine(combine(combine(combine(datasets::LargeGEMMReshape2DShapes(), b_values), framework::dataset::make("DataType", DataType::S16)), - m0_values), - k0_values), + m0_values_nightly), + k0_values_nightly), v0_values), i_values), t_values)) @@ -180,8 +208,8 @@ FIXTURE_DATA_TEST_CASE(RunSmall, CLGEMMReshapeLHSMatrixFixture, framework: combine(combine(combine(combine(combine(combine(combine(datasets::SmallGEMMReshape2DShapes(), b_values), framework::dataset::make("DataType", DataType::S8)), - m0_values), - k0_values), + m0_values_precommit), + k0_values_precommit), v0_values), i_values), t_values)) @@ -194,8 +222,8 @@ FIXTURE_DATA_TEST_CASE(RunLarge, CLGEMMReshapeLHSMatrixFixture, framework: combine(combine(combine(combine(combine(combine(combine(datasets::LargeGEMMReshape2DShapes(), b_values), framework::dataset::make("DataType", DataType::S8)), - m0_values), - k0_values), + m0_values_nightly), + k0_values_nightly), v0_values), i_values), t_values)) @@ -205,37 +233,31 @@ FIXTURE_DATA_TEST_CASE(RunLarge, CLGEMMReshapeLHSMatrixFixture, framework: } TEST_SUITE_END() // S8 -TEST_SUITE(REINTERPRET_INPUT_AS_3D) -DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(combine(combine(combine(combine(combine(combine(datasets::SmallGEMMReshape3DShapes(), +TEST_SUITE(ReinterpretInputAs3D) +DATA_TEST_CASE(ConfigurationSmall, framework::DatasetMode::ALL, combine(combine(combine(combine(combine(combine(combine(datasets::SmallGEMMReshape3DShapes(), b_values), data_types), - m0_values), - k0_values), + m0_values_precommit), + k0_values_precommit), v0_values), i_values), t_values), shape_in, b_value, data_type, m0_value, k0_value, v0_value, i_value, t_value) { - GEMMLHSMatrixInfo lhs_info; - lhs_info.m0 = m0_value; - lhs_info.k0 = k0_value; - lhs_info.v0 = v0_value; - lhs_info.interleave = i_value; - lhs_info.transpose = t_value; - - const TensorShape shape_src(shape_in[0], shape_in[1], shape_in[2], b_value); - const TensorShape shape_dst = compute_lhs_reshaped_shape(TensorInfo(shape_src, 1, data_type), lhs_info, true); - - // Create tensors - CLTensor src = create_tensor(shape_src, data_type); - CLTensor dst = create_tensor(shape_dst, data_type); - - ARM_COMPUTE_EXPECT(src.info()->is_resizable(), framework::LogLevel::ERRORS); - ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS); + validate_configuration(shape_in, b_value, data_type, m0_value, k0_value, v0_value, i_value, t_value, true); +} - // Create and configure function - CLGEMMReshapeLHSMatrixKernel reshape_lhs; - reshape_lhs.configure(&src, &dst, lhs_info, true); +DATA_TEST_CASE(ConfigurationLarge, framework::DatasetMode::NIGHTLY, combine(combine(combine(combine(combine(combine(combine(datasets::LargeGEMMReshape3DShapes(), + b_values), + data_types), + m0_values_nightly), + k0_values_nightly), + v0_values), + i_values), + t_values), +shape_in, b_value, data_type, m0_value, k0_value, v0_value, i_value, t_value) +{ + validate_configuration(shape_in, b_value, data_type, m0_value, k0_value, v0_value, i_value, t_value, true); } TEST_SUITE(S32) @@ -243,8 +265,8 @@ FIXTURE_DATA_TEST_CASE(RunSmall, CLGEMMReshapeLHSMatrix3DFixture, framework combine(combine(combine(combine(combine(combine(combine(datasets::SmallGEMMReshape3DShapes(), b_values), framework::dataset::make("DataType", DataType::S32)), - m0_values), - k0_values), + m0_values_precommit), + k0_values_precommit), v0_values), i_values), t_values)) @@ -257,8 +279,8 @@ FIXTURE_DATA_TEST_CASE(RunLarge, CLGEMMReshapeLHSMatrix3DFixture, framework combine(combine(combine(combine(combine(combine(combine(datasets::LargeGEMMReshape3DShapes(), b_values), framework::dataset::make("DataType", DataType::S32)), - m0_values), - k0_values), + m0_values_nightly), + k0_values_nightly), v0_values), i_values), t_values)) @@ -273,8 +295,8 @@ FIXTURE_DATA_TEST_CASE(RunSmall, CLGEMMReshapeLHSMatrix3DFixture, framewo combine(combine(combine(combine(combine(combine(combine(datasets::SmallGEMMReshape3DShapes(), b_values), framework::dataset::make("DataType", DataType::S16)), - m0_values), - k0_values), + m0_values_precommit), + k0_values_precommit), v0_values), i_values), t_values)) @@ -287,8 +309,8 @@ FIXTURE_DATA_TEST_CASE(RunLarge, CLGEMMReshapeLHSMatrix3DFixture, framewo combine(combine(combine(combine(combine(combine(combine(datasets::LargeGEMMReshape3DShapes(), b_values), framework::dataset::make("DataType", DataType::S16)), - m0_values), - k0_values), + m0_values_nightly), + k0_values_nightly), v0_values), i_values), t_values)) @@ -303,8 +325,8 @@ FIXTURE_DATA_TEST_CASE(RunSmall, CLGEMMReshapeLHSMatrix3DFixture, framewor combine(combine(combine(combine(combine(combine(combine(datasets::SmallGEMMReshape3DShapes(), b_values), framework::dataset::make("DataType", DataType::S8)), - m0_values), - k0_values), + m0_values_precommit), + k0_values_precommit), v0_values), i_values), t_values)) @@ -317,8 +339,8 @@ FIXTURE_DATA_TEST_CASE(RunLarge, CLGEMMReshapeLHSMatrix3DFixture, framewor combine(combine(combine(combine(combine(combine(combine(datasets::LargeGEMMReshape3DShapes(), b_values), framework::dataset::make("DataType", DataType::S8)), - m0_values), - k0_values), + m0_values_nightly), + k0_values_nightly), v0_values), i_values), t_values)) @@ -327,7 +349,7 @@ FIXTURE_DATA_TEST_CASE(RunLarge, CLGEMMReshapeLHSMatrix3DFixture, framewor validate(CLAccessor(_target), _reference); } TEST_SUITE_END() // S8 -TEST_SUITE_END() // REINTERPRET_INPUT_AS_3D +TEST_SUITE_END() // ReinterpretInputAs3D TEST_SUITE_END() // GEMMReshapeLHSMatrix TEST_SUITE_END() // CL } // namespace validation -- cgit v1.2.1