From aba2f912a21487776e540724cf354a6cd8d89829 Mon Sep 17 00:00:00 2001 From: morgolock Date: Tue, 5 May 2020 16:28:19 +0100 Subject: COMPMID-3289: Test improvement CLGEMMMatrixMultiplyReshapedKernel. Change-Id: Ia6c2f115849889baceafaf716477456e41f96037 Signed-off-by: morgolock Reviewed-on: https://review.mlplatform.org/c/ml/ComputeLibrary/+/3186 Comments-Addressed: Arm Jenkins Tested-by: Arm Jenkins Reviewed-by: Sang-Hoon Park --- arm_compute/core/KernelDescriptors.h | 22 +++ arm_compute/core/Types.h | 10 ++ tests/validation/CL/GEMMMatrixMultiplyReshaped.cpp | 166 ++++++++++++++++++++- utils/TypePrinter.h | 90 +++++++++++ 4 files changed, 282 insertions(+), 6 deletions(-) diff --git a/arm_compute/core/KernelDescriptors.h b/arm_compute/core/KernelDescriptors.h index d9d3e1a4d8..6b4691bc83 100644 --- a/arm_compute/core/KernelDescriptors.h +++ b/arm_compute/core/KernelDescriptors.h @@ -54,6 +54,28 @@ struct FFTRadixStageKernelInfo /** Descriptor used by the GEMM kernels */ struct GEMMKernelInfo { + GEMMKernelInfo() = default; + GEMMKernelInfo( + unsigned int im, + unsigned int in, + unsigned int ik, + unsigned int idepth_output_gemm3d, + bool ireinterpret_input_as_3d, + bool ibroadcast_bias, + bool ifp_mixed_precision, + ActivationLayerInfo iactivation_info, + int inmult_transpose1xW_width, + int imult_interleave4x4_height, + GEMMLHSMatrixInfo ilhs_info, + GEMMRHSMatrixInfo irhs_info, + int32_t ina_offset, + int32_t inb_offset) + : m(im), n(in), k(ik), depth_output_gemm3d(idepth_output_gemm3d), reinterpret_input_as_3d(ireinterpret_input_as_3d), broadcast_bias(ibroadcast_bias), fp_mixed_precision(ifp_mixed_precision), + activation_info(iactivation_info), mult_transpose1xW_width(inmult_transpose1xW_width), mult_interleave4x4_height(imult_interleave4x4_height), lhs_info(ilhs_info), rhs_info(irhs_info), + a_offset(ina_offset), b_offset(inb_offset) + { + } + unsigned int m{ 0 }; /**< Number of LHS rows*/ unsigned int n{ 0 }; /**< Number of RHS columns*/ unsigned int k{ 0 }; /**< Number of LHS columns or RHS rows */ diff --git a/arm_compute/core/Types.h b/arm_compute/core/Types.h index 37a9679a21..d59bba6ff4 100644 --- a/arm_compute/core/Types.h +++ b/arm_compute/core/Types.h @@ -1964,6 +1964,11 @@ struct GEMMLowpOutputStageInfo /** GEMM LHS (Left Hand Side) matrix information */ struct GEMMLHSMatrixInfo { + GEMMLHSMatrixInfo() = default; + GEMMLHSMatrixInfo(unsigned int m, unsigned int k, unsigned int v, bool trans, bool inter) + : m0(m), k0(k), v0(v), transpose(trans), interleave(inter) + { + } unsigned int m0{ 1 }; /**< Number of rows processed by the matrix multiplication */ unsigned int k0{ 1 }; /**< Number of partial accumulations performed by the matrix multiplication */ unsigned int v0{ 1 }; /**< Number of vertical blocks of size (m0xk0) stored on the same output row */ @@ -1974,6 +1979,11 @@ struct GEMMLHSMatrixInfo /** GEMM RHS (Right Hand Side) matrix information */ struct GEMMRHSMatrixInfo { + GEMMRHSMatrixInfo() = default; + GEMMRHSMatrixInfo(unsigned int n, unsigned int k, unsigned int h, bool trans, bool inter) + : n0(n), k0(k), h0(h), transpose(trans), interleave(inter) + { + } unsigned int n0{ 1 }; /**< Number of columns processed by the matrix multiplication */ unsigned int k0{ 1 }; /**< Number of partial accumulations performed by the matrix multiplication */ unsigned int h0{ 1 }; /**< Number of horizontal blocks of size (k0xn0) stored on the same output row */ diff --git a/tests/validation/CL/GEMMMatrixMultiplyReshaped.cpp b/tests/validation/CL/GEMMMatrixMultiplyReshaped.cpp index a333d1ca02..833a9240bf 100644 --- a/tests/validation/CL/GEMMMatrixMultiplyReshaped.cpp +++ b/tests/validation/CL/GEMMMatrixMultiplyReshaped.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2019 ARM Limited. + * Copyright (c) 2018-2020 ARM Limited. * * SPDX-License-Identifier: MIT * @@ -88,7 +88,7 @@ RelativeTolerance rel_tolerance_f16(0.001f); constexpr float abs_tolerance_f16(0.01f); /** M values to test */ -const auto m_values = framework::dataset::make("M", 37); +const auto m_values = framework::dataset::make("M", 17); /** M_W values to test */ const auto m_w_values = framework::dataset::make("M_W", 5); @@ -97,18 +97,17 @@ const auto m_w_values = framework::dataset::make("M_W", 5); const auto m_h_values = framework::dataset::make("M_H", 7); /** N values to test */ -const auto n_values = framework::dataset::make("N", 51); +const auto n_values = framework::dataset::make("N", 21); /** K values to test */ -const auto k_values = framework::dataset::make("K", 23); +const auto k_values = framework::dataset::make("K", 13); /** Batch size values to test */ -const auto b_values = framework::dataset::make("batch_size", 1, 3); +const auto b_values = framework::dataset::make("batch_size", 2, 3); /** Activation values to test */ const auto act_values = framework::dataset::make("Activation", { - ActivationLayerInfo(), ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LU_BOUNDED_RELU, 8.f, 2.f), }); @@ -169,6 +168,161 @@ const auto lhs_transpose_values = framework::dataset::make("lhs_transpose", { fa TEST_SUITE(CL) TEST_SUITE(GEMMMatrixMultiplyReshaped) + +// *INDENT-OFF* +// clang-format off +DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(zip(zip(zip(zip( + framework::dataset::make("Input0Info", { TensorInfo(TensorShape(64U, 5U, 2U), 1, DataType::F32), // OK + TensorInfo(TensorShape(64U, 5U, 2U), 1, DataType::F16), // OK + TensorInfo(TensorShape(64U, 5U, 2U), 1, DataType::QASYMM8), // Data type not supported + TensorInfo(TensorShape(10U, 5U, 2U), 1, DataType::F32), // Incorrect dimension bias + TensorInfo(TensorShape(64U, 5U, 2U), 1, DataType::F32), // Mismatching shapes + TensorInfo(TensorShape(64U, 5U, 2U), 1, DataType::F16), // OK, do not broadcast bias + TensorInfo(TensorShape(64U, 5U, 2U), 1, DataType::F16), // OK, wider accummulation + TensorInfo(TensorShape(64U, 5U, 2U), 1, DataType::F16), // OK, RHS 4,4,2 + + }), + framework::dataset::make("Input1Info",{ TensorInfo(TensorShape(64U, 6U, 2U), 1, DataType::F32), + TensorInfo(TensorShape(64U, 6U, 2U), 1, DataType::F16), + TensorInfo(TensorShape(64U, 5U, 2U), 1, DataType::QASYMM8), + TensorInfo(TensorShape(64U, 6U, 2U), 1, DataType::F32), + TensorInfo(TensorShape(48U, 11U, 2U), 1, DataType::F32), + TensorInfo(TensorShape(64U, 6U, 2U), 1, DataType::F16), + TensorInfo(TensorShape(64U, 6U, 2U), 1, DataType::F16), + TensorInfo(TensorShape(128U, 3U, 2U), 1, DataType::F16), + + })), + framework::dataset::make("Input2Info", { TensorInfo(TensorShape(21U), 1, DataType::F32), + TensorInfo(TensorShape(21U), 1, DataType::F16), + TensorInfo(TensorShape(21U), 1, DataType::QASYMM8), + TensorInfo(TensorShape(21U), 1, DataType::F32), + TensorInfo(TensorShape(21U), 1, DataType::F32), + TensorInfo(TensorShape(21U,17U), 1, DataType::F16), + TensorInfo(TensorShape(21U,17U), 1, DataType::F16), + TensorInfo(TensorShape(21U,17U,2U), 1, DataType::F16), + + })), + framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(21U,17U,2U), 1, DataType::F32), + TensorInfo(TensorShape(21U,17U,2U), 1, DataType::F16), + TensorInfo(TensorShape(21U,17U,2U), 1, DataType::QASYMM8), + TensorInfo(TensorShape(21U,17U,2U), 1, DataType::F32), + TensorInfo(TensorShape(21U,17U,2U), 1, DataType::F32), + TensorInfo(TensorShape(21U,17U,2U), 1, DataType::F16), + TensorInfo(TensorShape(21U,17U,2U), 1, DataType::F16), + TensorInfo(TensorShape(21U,17U,2U), 1, DataType::F16), + + })), + framework::dataset::make("LHSMInfo",{ + GEMMLHSMatrixInfo(4,4,1,false,true), + GEMMLHSMatrixInfo(4,4,1,false,true), + GEMMLHSMatrixInfo(4,4,1,false,true), + GEMMLHSMatrixInfo(4,2,4,false,false), + GEMMLHSMatrixInfo(4,2,4,false,false), + GEMMLHSMatrixInfo(4,4,1,false,true), + GEMMLHSMatrixInfo(4,4,1,false,true), + GEMMLHSMatrixInfo(4,4,1,false,true), + + })), + framework::dataset::make("RHSMInfo",{ + GEMMRHSMatrixInfo(4,4,1,true,true), + GEMMRHSMatrixInfo(4,4,1, true,true), + GEMMRHSMatrixInfo(4,4,1,true,true), + GEMMRHSMatrixInfo(2,2,1,true,false), + GEMMRHSMatrixInfo(2,2,1,true,false), + GEMMRHSMatrixInfo(4,4,1,true,true), + GEMMRHSMatrixInfo(4,4,1,true,true), + GEMMRHSMatrixInfo(4,4,2,true,false), + + + })), + + + framework::dataset::make("GEMMInfo",{ + GEMMKernelInfo( 17 /**set_is_resizable(true), + &input1_info.clone()->set_is_resizable(true), + &input2_info.clone()->set_is_resizable(true), + &output_info.clone()->set_is_resizable(true),1.f,1.f, + lhs_info, + rhs_info, + gemm_info)) == expected, framework::LogLevel::ERRORS); +} TEST_SUITE(Float) TEST_SUITE(FP32) diff --git a/utils/TypePrinter.h b/utils/TypePrinter.h index 1f499dec7e..55e34c8541 100644 --- a/utils/TypePrinter.h +++ b/utils/TypePrinter.h @@ -29,6 +29,7 @@ #include "arm_compute/core/Error.h" #include "arm_compute/core/GPUTarget.h" #include "arm_compute/core/HOGInfo.h" +#include "arm_compute/core/KernelDescriptors.h" #include "arm_compute/core/Size2D.h" #include "arm_compute/core/Strides.h" #include "arm_compute/core/TensorInfo.h" @@ -235,6 +236,95 @@ inline std::string to_string(const ROIPoolingLayerInfo &pool_info) return str.str(); } +/** Formatted output of the GEMMKernelInfo type. + * + * @param[out] os Output stream. + * @param[in] gemm_info Type to output. + * + * @return Modified output stream. + */ +inline ::std::ostream &operator<<(::std::ostream &os, const GEMMKernelInfo &gemm_info) +{ + os << "( m= " << gemm_info.m; + os << " n= " << gemm_info.n; + os << " k= " << gemm_info.k; + os << " depth_output_gemm3d= " << gemm_info.depth_output_gemm3d; + os << " reinterpret_input_as_3d= " << gemm_info.reinterpret_input_as_3d; + os << " broadcast_bias= " << gemm_info.broadcast_bias; + os << " fp_mixed_precision= " << gemm_info.fp_mixed_precision; + os << " mult_transpose1xW_width= " << gemm_info.mult_transpose1xW_width; + os << " mult_interleave4x4_height= " << gemm_info.mult_interleave4x4_height; + os << " a_offset = " << gemm_info.a_offset; + os << " b_offset = " << gemm_info.b_offset; + os << ")"; + return os; +} + +/** Formatted output of the GEMMLHSMatrixInfo type. + * + * @param[out] os Output stream. + * @param[in] gemm_info Type to output. + * + * @return Modified output stream. + */ +inline ::std::ostream &operator<<(::std::ostream &os, const GEMMLHSMatrixInfo &gemm_info) +{ + os << "( m0= " << (unsigned int)gemm_info.m0 << " k0= " << gemm_info.k0 << " v0= " << gemm_info.v0 << " trans= " << gemm_info.transpose << " inter= " << gemm_info.interleave << "})"; + return os; +} + +/** Formatted output of the GEMMRHSMatrixInfo type. + * + * @param[out] os Output stream. + * @param[in] gemm_info Type to output. + * + * @return Modified output stream. + */ +inline ::std::ostream &operator<<(::std::ostream &os, const GEMMRHSMatrixInfo &gemm_info) +{ + os << "( n0= " << (unsigned int)gemm_info.n0 << " k0= " << gemm_info.k0 << " h0= " << gemm_info.h0 << " trans= " << gemm_info.transpose << " inter= " << gemm_info.interleave << "})"; + return os; +} + +/** Formatted output of the GEMMRHSMatrixInfo type. + * + * @param[in] gemm_info GEMMRHSMatrixInfo to output. + * + * @return Formatted string. + */ +inline std::string to_string(const GEMMRHSMatrixInfo &gemm_info) +{ + std::stringstream str; + str << gemm_info; + return str.str(); +} + +/** Formatted output of the GEMMLHSMatrixInfo type. + * + * @param[in] gemm_info GEMMLHSMatrixInfo to output. + * + * @return Formatted string. + */ +inline std::string to_string(const GEMMLHSMatrixInfo &gemm_info) +{ + std::stringstream str; + str << gemm_info; + return str.str(); +} + +/** Formatted output of the GEMMKernelInfo type. + * + * @param[in] gemm_info GEMMKernelInfo Type to output. + * + * @return Formatted string. + */ +inline std::string to_string(const GEMMKernelInfo &gemm_info) +{ + std::stringstream str; + str << gemm_info; + return str.str(); +} + /** Formatted output of the BoundingBoxTransformInfo type. * * @param[out] os Output stream. -- cgit v1.2.1