aboutsummaryrefslogtreecommitdiff
path: root/src/core/CL/cl_kernels/tile_helpers.h
diff options
context:
space:
mode:
authorGunes Bayir <gunes.bayir@arm.com>2023-04-13 18:22:58 +0100
committerGunes Bayir <gunes.bayir@arm.com>2023-04-17 15:54:44 +0000
commit9d0c4deb760efc2ca07e5e0b8218995201ad8a1f (patch)
tree8f64b754d05768e2f69cfae387137140a6bb22b5 /src/core/CL/cl_kernels/tile_helpers.h
parent99145f787e9e99b45522f16d861c8527583f2b4e (diff)
downloadComputeLibrary-9d0c4deb760efc2ca07e5e0b8218995201ad8a1f.tar.gz
Add quantized CL MatMul kernels for Lhs NT/T, Rhs NT
Implement OpenCL kernels for batched Matrix Multiplication for the quantized data types QASYMM8 and QASYMM8_SIGNED. Quantized MatMul is supported with the following MatMul attributes: * adj_x = false, adj_y = false * adj_x = true, adj_y = false We consider native format kernels only. In other words, no reshaping of the operand matrices is done. Resolves: COMPMID-5921, COMPMID-5922 Change-Id: I99e0f68054a2bd635c60ec2641acc2e7ff398473 Signed-off-by: Omar Al Khatib <omar.alkhatib@arm.com> Signed-off-by: Gunes Bayir <gunes.bayir@arm.com> Signed-off-by: Jakub Sujak <jakub.sujak@arm.com> Reviewed-on: https://review.mlplatform.org/c/ml/ComputeLibrary/+/9435 Reviewed-by: SiCong Li <sicong.li@arm.com> Reviewed-by: Viet-Hoa Do <viet-hoa.do@arm.com> Comments-Addressed: Arm Jenkins <bsgcomp@arm.com> Tested-by: Arm Jenkins <bsgcomp@arm.com> Benchmark: Arm Jenkins <bsgcomp@arm.com>
Diffstat (limited to 'src/core/CL/cl_kernels/tile_helpers.h')
-rw-r--r--src/core/CL/cl_kernels/tile_helpers.h99
1 files changed, 99 insertions, 0 deletions
diff --git a/src/core/CL/cl_kernels/tile_helpers.h b/src/core/CL/cl_kernels/tile_helpers.h
index 872f4c0b57..c9b5370dea 100644
--- a/src/core/CL/cl_kernels/tile_helpers.h
+++ b/src/core/CL/cl_kernels/tile_helpers.h
@@ -536,6 +536,100 @@
}) \
})
+/** Store a VECTOR variable (e.g. int4, int8, char2 etc.) to a specified column in the TILE object
+ *
+ * @param[in] VECTOR Vector variable to store
+ * @param[in, out] TILE Tile variable to store to
+ * @param[in] WIDTH Width of the vector variable, also height of the tile (e.g. 2 if char2)
+ * @param[in] COLUMN Column index of the tile
+ */
+#define COPY_VECTOR_TO_TILE_COLUMN(VECTOR, TILE, WIDTH, COLUMN) COPY_VECTOR_TO_TILE_COLUMN_STR(VECTOR, TILE, WIDTH, COLUMN)
+#define COPY_VECTOR_TO_TILE_COLUMN_STR(VECTOR, TILE, WIDTH, COLUMN) COPY_##WIDTH##_VECTOR_TO_TILE_COLUMN(VECTOR, TILE, COLUMN)
+#define COPY_1_VECTOR_TO_TILE_COLUMN(VECTOR, TILE, COLUMN) \
+ ({ \
+ TILE[0].s[COLUMN] = VECTOR; \
+ })
+
+#define COPY_2_VECTOR_TO_TILE_COLUMN(VECTOR, TILE, COLUMN) \
+ ({ \
+ TILE[0].s[COLUMN] = VECTOR.s0; \
+ TILE[1].s[COLUMN] = VECTOR.s1; \
+ })
+
+#define COPY_3_VECTOR_TO_TILE_COLUMN(VECTOR, TILE, COLUMN) \
+ ({ \
+ TILE[0].s[COLUMN] = VECTOR.s0; \
+ TILE[1].s[COLUMN] = VECTOR.s1; \
+ TILE[2].s[COLUMN] = VECTOR.s2; \
+ })
+
+#define COPY_4_VECTOR_TO_TILE_COLUMN(VECTOR, TILE, COLUMN) \
+ ({ \
+ TILE[0].s[COLUMN] = VECTOR.s0; \
+ TILE[1].s[COLUMN] = VECTOR.s1; \
+ TILE[2].s[COLUMN] = VECTOR.s2; \
+ TILE[3].s[COLUMN] = VECTOR.s3; \
+ })
+
+#define COPY_8_VECTOR_TO_TILE_COLUMN(VECTOR, TILE, COLUMN) \
+ ({ \
+ TILE[0].s[COLUMN] = VECTOR.s0; \
+ TILE[1].s[COLUMN] = VECTOR.s1; \
+ TILE[2].s[COLUMN] = VECTOR.s2; \
+ TILE[3].s[COLUMN] = VECTOR.s3; \
+ TILE[4].s[COLUMN] = VECTOR.s4; \
+ TILE[5].s[COLUMN] = VECTOR.s5; \
+ TILE[6].s[COLUMN] = VECTOR.s6; \
+ TILE[7].s[COLUMN] = VECTOR.s7; \
+ })
+
+#define COPY_16_VECTOR_TO_TILE_COLUMN(VECTOR, TILE, COLUMN) \
+ ({ \
+ TILE[0].s[COLUMN] = VECTOR.s0; \
+ TILE[1].s[COLUMN] = VECTOR.s1; \
+ TILE[2].s[COLUMN] = VECTOR.s2; \
+ TILE[3].s[COLUMN] = VECTOR.s3; \
+ TILE[4].s[COLUMN] = VECTOR.s4; \
+ TILE[5].s[COLUMN] = VECTOR.s5; \
+ TILE[6].s[COLUMN] = VECTOR.s6; \
+ TILE[7].s[COLUMN] = VECTOR.s7; \
+ TILE[8].s[COLUMN] = VECTOR.s8; \
+ TILE[9].s[COLUMN] = VECTOR.s9; \
+ TILE[10].s[COLUMN] = VECTOR.sA; \
+ TILE[11].s[COLUMN] = VECTOR.sB; \
+ TILE[12].s[COLUMN] = VECTOR.sC; \
+ TILE[13].s[COLUMN] = VECTOR.sD; \
+ TILE[14].s[COLUMN] = VECTOR.sE; \
+ TILE[15].s[COLUMN] = VECTOR.sF; \
+ })
+
+/** Load SRC_HEIGHT x SRC_WIDTH elements from global memory (tensor), and store them in a SRC_WIDTH x SRC_HEIGHT tile
+ *
+ * @param[in] DATA_TYPE Data type
+ * @param[in] SRC_HEIGHT Number of source rows, or number of columns of the output tile
+ * @param[in] SRC_WIDTH Number of source columns, or number of tile rows
+ * @param[in] TENSOR_TYPE Type of cl_type used to store the tensor in global memory (BUFFER=cl_buffer, IMAGE=cl_image).
+ * In case of cl_image, only WIDTH multiples of 4 are supported (4, 8, 16)
+ * @param[in] TENSOR Tensor basename
+ * @param[in] X Starting X position
+ * @param[in] Y Starting Y position
+ * @param[in] YI_MULTIPLIER Parameter used to multiply the internal row increment (_i).
+ * In common cases should be 1 but it becomes useful when we want to load rows which are multiple of STRIDE_Y.
+ * (e.g. loading the weights of convolution layer).
+ * In this case the address calculation is performed as: (Y + _i * Y_MULTIPLIER) * STRIDE_Y
+ * @param[in] STRIDE_Y Stride Y (in bytes) used to load each row.
+ * @param[out] dst Output tile
+ */
+#define T_LOAD_TRANSPOSED(DATA_TYPE, SRC_HEIGHT, SRC_WIDTH, TENSOR_TYPE, TENSOR, X, Y, YI_MULTIPLIER, STRIDE_Y, dst) \
+ ({ \
+ LOOP_UNROLLING(int, _i, 0, 1, SRC_HEIGHT, \
+ { \
+ VEC_DATA_TYPE(DATA_TYPE, SRC_WIDTH) \
+ tmp = V_LOAD(DATA_TYPE, SRC_WIDTH, TENSOR_TYPE, TENSOR, X, ((Y) + _i * (int)(YI_MULTIPLIER)), STRIDE_Y); \
+ COPY_VECTOR_TO_TILE_COLUMN(tmp, dst, SRC_WIDTH, _i); \
+ }) \
+ })
+
/** Load a tile from global memory (tensor) using an indirect Y index tile
*
* @param[in] DATA_TYPE Data type
@@ -1259,6 +1353,11 @@
* @param[in] lhs LHS tile
* @param[in] rhs RHS tile
* @param[in, out] dst DST tile
+ *
+ * @note For Int8/UInt8 multiplications, we only have T_MMUL_NT_T because we need
+ * the multiply the rows of Lhs and Rhs tensors to utilize dot product extension.
+ * Addition of other versions requires dealing with on the fly transposition of
+ * these tile elements and therefore is not favored.
*/
#define T_MMUL(LHS_DATA_TYPE, RHS_DATA_TYPE, DST_DATA_TYPE, M0, N0, K0, LHS_LAYOUT, RHS_LAYOUT, lhs, rhs, dst) T_MMUL_##LHS_LAYOUT##_##RHS_LAYOUT(LHS_DATA_TYPE, RHS_DATA_TYPE, DST_DATA_TYPE, M0, N0, K0, lhs, rhs, dst)
#define T_MMUL_NT_T(LHS_DATA_TYPE, RHS_DATA_TYPE, DST_DATA_TYPE, M0, N0, K0, lhs, rhs, dst) T_MMUL_NT_T_##LHS_DATA_TYPE##_##RHS_DATA_TYPE##_##DST_DATA_TYPE(LHS_DATA_TYPE, RHS_DATA_TYPE, DST_DATA_TYPE, M0, N0, K0, lhs, rhs, dst)