COMPMID-3289: Test improvement CLGEMMMatrixMultiplyReshapedKernel.
authormorgolock <pablo.tello@arm.com>
Tue, 5 May 2020 15:28:19 +0000 (16:28 +0100)
committerGeorgios Pinitas <georgios.pinitas@arm.com>
Fri, 15 May 2020 13:18:28 +0000 (13:18 +0000)
Change-Id: Ia6c2f115849889baceafaf716477456e41f96037
Signed-off-by: morgolock <pablo.tello@arm.com>
Reviewed-on: https://review.mlplatform.org/c/ml/ComputeLibrary/+/3186
Comments-Addressed: Arm Jenkins <bsgcomp@arm.com>
Tested-by: Arm Jenkins <bsgcomp@arm.com>
Reviewed-by: Sang-Hoon Park <sang-hoon.park@arm.com>
arm_compute/core/KernelDescriptors.h
arm_compute/core/Types.h
tests/validation/CL/GEMMMatrixMultiplyReshaped.cpp
utils/TypePrinter.h

index d9d3e1a4d83f068f77b943a94a5a0fb7e0cad616..6b4691bc83a36fc9d67cef2051da7bbe1a91dc5a 100644 (file)
@@ -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 */
index 37a9679a2191372d4cb223fbffc2f327c63e2102..d59bba6ff4785ec465a32748b7bba74179fc6172 100644 (file)
@@ -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 */
index a333d1ca020cee570d681f8127ff127046a914d0..833a9240bf105a7af95ff7d8c125711e6e983137 100644 (file)
@@ -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<float> 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 /**<M Number of LHS rows*/,
+                                                                            21 /**<N Number of RHS columns*/,
+                                                                            13 /**<K Number of LHS columns or RHS rows */, 0 /**< Depth of the output tensor in case is reinterpreted as 3D */,
+                                                                     false /**< reinterpret the input as 3D */,
+                                                                     true  /**< Flag used to broadcast the bias addition */,
+                                                                     false /**< wider accumm */,
+                                                                   ActivationLayerInfo::ActivationFunction::LU_BOUNDED_RELU,
+                                                                     1   /**< Multiplication factor for the width of the 1xW transposed block */,
+                                                                     1   /**< Multiplication factor for the height of the 4x4 interleaved block */,
+                                                                     GEMMLHSMatrixInfo(4,4,1,false,true),
+                                                                     GEMMRHSMatrixInfo(4,4,1,true,true),
+                                                                     0  /**< Offset to be added to each element of the matrix A */,
+                                                                     0 /**< Offset to be added to each element of the matrix B */),
+
+                                                            GEMMKernelInfo( 17 /**<M Number of LHS rows*/,
+                                                                            21 /**<N Number of RHS columns*/,
+                                                                            13 /**<K Number of LHS columns or RHS rows */, 0 /**< Depth of the output tensor in case is reinterpreted as 3D */,
+                                                                     false /**< reinterpret the input as 3D */,
+                                                                     true  /**< Flag used to broadcast the bias addition */,
+                                                                     false /**< wider accumm */,
+                                                                   ActivationLayerInfo::ActivationFunction::LU_BOUNDED_RELU,
+                                                                     1   /**< Multiplication factor for the width of the 1xW transposed block */,
+                                                                     1   /**< Multiplication factor for the height of the 4x4 interleaved block */,
+                                                                     GEMMLHSMatrixInfo(4,4,1,false,true),
+                                                                     GEMMRHSMatrixInfo(4,4,1,true,true),
+                                                                     0  /**< Offset to be added to each element of the matrix A */,
+                                                                     0 /**< Offset to be added to each element of the matrix B */),
+                                                            GEMMKernelInfo(),
+                                                            GEMMKernelInfo(),
+                                                            GEMMKernelInfo(),
+
+                                                            GEMMKernelInfo( 17 /**<M Number of LHS rows*/,
+                                                                            21 /**<N Number of RHS columns*/,
+                                                                            13 /**<K Number of LHS columns or RHS rows */, 0 /**< Depth of the output tensor in case is reinterpreted as 3D */,
+                                                                     false /**< reinterpret the input as 3D */,
+                                                                     false  /**< Flag used to broadcast the bias addition */,
+                                                                     false /**< wider accumm */,
+                                                                   ActivationLayerInfo::ActivationFunction::LU_BOUNDED_RELU,
+                                                                     1   /**< Multiplication factor for the width of the 1xW transposed block */,
+                                                                     1   /**< Multiplication factor for the height of the 4x4 interleaved block */,
+                                                                     GEMMLHSMatrixInfo(4,4,1,false,true),
+                                                                     GEMMRHSMatrixInfo(4,4,1,true,true),
+                                                                     0  /**< Offset to be added to each element of the matrix A */,
+                                                                     0 /**< Offset to be added to each element of the matrix B */),
+
+
+                                                            GEMMKernelInfo( 17 /**<M Number of LHS rows*/,
+                                                                            21 /**<N Number of RHS columns*/,
+                                                                            13 /**<K Number of LHS columns or RHS rows */, 0 /**< Depth of the output tensor in case is reinterpreted as 3D */,
+                                                                     false /**< reinterpret the input as 3D */,
+                                                                     false  /**< Flag used to broadcast the bias addition */,
+                                                                     true /**< wider accumm */,
+                                                                   ActivationLayerInfo::ActivationFunction::LU_BOUNDED_RELU,
+                                                                     1   /**< Multiplication factor for the width of the 1xW transposed block */,
+                                                                     1   /**< Multiplication factor for the height of the 4x4 interleaved block */,
+                                                                     GEMMLHSMatrixInfo(4,4,1,false,true),
+                                                                     GEMMRHSMatrixInfo(4,4,1,true,true),
+                                                                     0  /**< Offset to be added to each element of the matrix A */,
+                                                                     0 /**< Offset to be added to each element of the matrix B */),
+
+                                                            GEMMKernelInfo( 17 /**<M Number of LHS rows*/,
+                                                                            21 /**<N Number of RHS columns*/,
+                                                                            13 /**<K Number of LHS columns or RHS rows */, 0 /**< Depth of the output tensor in case is reinterpreted as 3D */,
+                                                                     false /**< reinterpret the input as 3D */,
+                                                                     false  /**< Flag used to broadcast the bias addition */,
+                                                                     false /**< wider accumm */,
+                                                                   ActivationLayerInfo::ActivationFunction::LU_BOUNDED_RELU,
+                                                                     1   /**< Multiplication factor for the width of the 1xW transposed block */,
+                                                                     1   /**< Multiplication factor for the height of the 4x4 interleaved block */,
+                                                                     GEMMLHSMatrixInfo(4,4,1,false,true),
+                                                                     GEMMRHSMatrixInfo(4,4,2,true,false),
+                                                                     0  /**< Offset to be added to each element of the matrix A */,
+                                                                     0 /**< Offset to be added to each element of the matrix B */),
+                                                    })),
+               framework::dataset::make("Expected", { true, true, false, false, false, true, true,true})),
+                    input0_info ,input1_info, input2_info, output_info, lhs_info, rhs_info, gemm_info, expected)
+{
+   ARM_COMPUTE_EXPECT(bool(CLGEMMMatrixMultiplyReshapedKernel::validate(&input0_info.clone()->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)
 
index 1f499dec7eb4f0ab5efe2ba48144cbfc1851068a..55e34c8541bc0de8cd6be236b99dd66daec8649e 100644 (file)
@@ -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.