aboutsummaryrefslogtreecommitdiff
path: root/arm_compute/core
diff options
context:
space:
mode:
authorRamy Elgammal <ramy.elgammal@arm.com>2023-03-09 21:15:37 +0000
committerGunes Bayir <gunes.bayir@arm.com>2023-03-17 11:00:57 +0000
commit2b6ebfe4270b06b09e45f306e8384950aeca7e4e (patch)
tree44a65551aa32352a57090bf550b96cbf5b54222f /arm_compute/core
parent40aab11ff88ed432d5028478e531f8d0fc404d4c (diff)
downloadComputeLibrary-2b6ebfe4270b06b09e45f306e8384950aeca7e4e.tar.gz
Implement OpenCL MatMul for Lhs NT Rhs T/NT FP32/16
- Implement ClNativeMatMulKernel class - Implement opencl kernel for LHS non-transposed and RHS non-transposed - Implement opencl kernel for LHS non-transposed and RHS transposed - Add test fixture and dataset for matmul - Implement transpose_tensor() for reference implementation to transpose high dimensional tensors Resolves: COMPMID-5944, COMPMID-5951 Co-authored-by: Gunes Bayir <gunes.bayir@arm.com> Co-authored-by: Ramy Elgammal <ramy.elgammal@arm.com> Change-Id: I1d5b8978f41be27baddb3153ade880472141573f Signed-off-by: Gunes Bayir <gunes.bayir@arm.com> Signed-off-by: Ramy Elgammal <ramy.elgammal@arm.com> Reviewed-on: https://review.mlplatform.org/c/ml/ComputeLibrary/+/9333 Tested-by: Arm Jenkins <bsgcomp@arm.com> Reviewed-by: Gian Marco Iodice <gianmarco.iodice@arm.com> Benchmark: Arm Jenkins <bsgcomp@arm.com>
Diffstat (limited to 'arm_compute/core')
-rw-r--r--arm_compute/core/KernelDescriptors.h20
-rw-r--r--arm_compute/core/utils/misc/ShapeCalculator.h34
2 files changed, 48 insertions, 6 deletions
diff --git a/arm_compute/core/KernelDescriptors.h b/arm_compute/core/KernelDescriptors.h
index 19ac254c04..016e03d88e 100644
--- a/arm_compute/core/KernelDescriptors.h
+++ b/arm_compute/core/KernelDescriptors.h
@@ -21,8 +21,8 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
-#ifndef ARM_COMPUTE_CORE_KERNEL_DESCRIPTORS_H
-#define ARM_COMPUTE_CORE_KERNEL_DESCRIPTORS_H
+#ifndef ACL_ARM_COMPUTE_CORE_KERNELDESCRIPTORS
+#define ACL_ARM_COMPUTE_CORE_KERNELDESCRIPTORS
#include "arm_compute/core/PixelValue.h"
#include "arm_compute/core/Types.h"
@@ -223,5 +223,19 @@ struct ScaleKernelInfo
bool align_corners; /**< Align corners of input and output */
DataLayout data_layout; /**< Data layout to use */
};
+
+struct MatMulKernelInfo
+{
+ MatMulKernelInfo(bool adj_lhs = false, bool adj_rhs = false, int m0 = 1, int n0 = 1, int k0 = 1, bool export_rhs_to_cl_image = false)
+ : adj_lhs{ adj_lhs }, adj_rhs{ adj_rhs }, m0{ m0 }, n0{ n0 }, k0{ k0 }, export_rhs_to_cl_image{ export_rhs_to_cl_image }
+ {
+ }
+ bool adj_lhs{ false }; /**< Get Adjoint LHS flag value */
+ bool adj_rhs{ false }; /**< Get Adjoint RHS flag value */
+ int m0{ 1 }; /**< Number of output rows processed by each work-item*/
+ int n0{ 1 }; /**< Number of output columns processed by each work-item*/
+ int k0{ 1 }; /**< Number of inner accumulations */
+ bool export_rhs_to_cl_image{ false }; /**< Flag to know whether the RHS tensor should be exported to cl_image*/
+};
} // namespace arm_compute
-#endif /* ARM_COMPUTE_CORE_KERNEL_DESCRIPTORS_H */
+#endif /* ACL_ARM_COMPUTE_CORE_KERNELDESCRIPTORS */
diff --git a/arm_compute/core/utils/misc/ShapeCalculator.h b/arm_compute/core/utils/misc/ShapeCalculator.h
index 6655cc1439..75a063f75c 100644
--- a/arm_compute/core/utils/misc/ShapeCalculator.h
+++ b/arm_compute/core/utils/misc/ShapeCalculator.h
@@ -21,8 +21,8 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
-#ifndef ARM_COMPUTE_MISC_SHAPE_CALCULATOR_H
-#define ARM_COMPUTE_MISC_SHAPE_CALCULATOR_H
+#ifndef ACL_ARM_COMPUTE_CORE_UTILS_MISC_SHAPECALCULATOR
+#define ACL_ARM_COMPUTE_CORE_UTILS_MISC_SHAPECALCULATOR
#include "arm_compute/core/Helpers.h"
#include "arm_compute/core/ITensorInfo.h"
@@ -1008,6 +1008,34 @@ inline TensorShape compute_mm_shape(const ITensorInfo &input0, const ITensorInfo
/** Calculate the matrix multiplication output shape of two tensors
*
+ * @param[in] input0 First input tensor info
+ * @param[in] input1 Second input tensor info
+ * @param[in] matmul_info Batch MatMul Kernel info to know which matrix is transposed
+ *
+ * @return the calculated shape
+ */
+inline TensorShape compute_batchmatmul_shape(const TensorShape &input0, const TensorShape &input1, const MatMulKernelInfo &matmul_info)
+{
+ TensorShape output_shape{ input0 };
+
+ if(matmul_info.adj_lhs)
+ {
+ output_shape.set(1, input0[0]); // The vertical (M) dimension
+ }
+
+ if(matmul_info.adj_rhs)
+ {
+ output_shape.set(0, input1[1]); // The horizontal (N) dimension
+ }
+ else
+ {
+ output_shape.set(0, input1[0]); // The horizontal (N) dimension
+ }
+
+ return output_shape;
+}
+/** Calculate the matrix multiplication output shape of two tensors
+ *
* @param[in] input Input tensor info
* @param[in] gemm_3d_depth (Optional) GEMM 3d depth
* @param[in] batch_size_on_z (Optional) True if batch size is on z axis
@@ -1579,4 +1607,4 @@ inline TensorShape compute_gather_shape(const TensorShape &input_shape, const Te
} // namespace shape_calculator
} // namespace misc
} // namespace arm_compute
-#endif /* ARM_COMPUTE_MISC_SHAPE_CALCULATOR_H */
+#endif /* ACL_ARM_COMPUTE_CORE_UTILS_MISC_SHAPECALCULATOR */