From 95a7873da63883d653a900951e4442059a1a405b Mon Sep 17 00:00:00 2001 From: Dmitry Sidorov Date: Mon, 27 Dec 2021 13:01:23 +0300 Subject: [PATCH 1/4] [SYCL] Change matrix type Previously we relied on the structure type (which represented matrix type) mangling to obtain its layout. Now, when DPCPP magling scheme is aligned with C++, thus the structure lost their usual mangling. Yet we want to preserve the desired information within the matrix type, coming from DPCPP headers. To achive this the 'Matrix structure' was changed form: template struct __spirv_JointMatrixINTEL; to template struct __spirv_JointMatrixINTEL { T (*Value)[R][C][L + 1][S + 1]; }; so it's no longer an opaque structure and now it look like this in LLVM IR: %struct.__spirv_JointMatrixINTEL = type { [42 x [6 x [2 x [1 x i32]]]]* } Here we encode the number of Rows, Cols, Layout and Scope as sizes of an array (which element type is the same as the base matrix's type), which is a bit odd, but it's probably the best way we can preserve the information now without having the matrix type itself in LLVM. Signed-off-by: Dmitry Sidorov --- sycl/include/CL/__spirv/spirv_types.hpp | 18 +++++++++++++++++- sycl/test/matrix/matrix-int8-test.cpp | 9 +++++++-- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/sycl/include/CL/__spirv/spirv_types.hpp b/sycl/include/CL/__spirv/spirv_types.hpp index cae0f38c11748..e160cfeed426e 100644 --- a/sycl/include/CL/__spirv/spirv_types.hpp +++ b/sycl/include/CL/__spirv/spirv_types.hpp @@ -110,9 +110,25 @@ enum class GroupOperation : uint32_t { enum class MatrixLayout { RowMajor, ColumnMajor, PackedA, PackedB }; +// TODO: replace the following W/A with a better solution when we have it. +// The following structure is used to represent the joint matrix type in the +// LLVM IR. The structure has a pointer to a multidimensional array member which +// makes the encoding of the matrix type information within the LLVM IR looks +// like this: +// %struct.__spirv_JointMatrixINTEL = type { [42 x [6 x [2 x [1 x float]]]]* } +// Note that an array cannot be of zero size but MatrixLayout and Scope +// parameters can; hence '+ 1' is added to the 3rd and 4th dimensions. +// In general, representing a matrix type information like this is a bit odd +// (especially for MatrixLayout and Scope parameters). But with the current +// tools we have in Clang, this is the only way to preserve and communicate this +// information to SPIRV translator. +// The long term solution would be to introduce a matrix type in Clang and use +// it instead of this member. template -struct __spirv_JointMatrixINTEL; +struct __spirv_JointMatrixINTEL { + T (*Value)[R][C][static_cast(U) + 1][static_cast(S) + 1]; +}; } // namespace __spv diff --git a/sycl/test/matrix/matrix-int8-test.cpp b/sycl/test/matrix/matrix-int8-test.cpp index a1fce823e12a1..c88bf03e60f67 100644 --- a/sycl/test/matrix/matrix-int8-test.cpp +++ b/sycl/test/matrix/matrix-int8-test.cpp @@ -1,5 +1,10 @@ -// RUN: %clangxx -fsycl -O2 %s -o %t.out -// XFAIL: * +// RUN: %clangxx -fsycl -fsycl-device-only -O2 -S -emit-llvm -o - %s | FileCheck %s +// RUNx: %clangxx -fsycl -O2 %s -o %t.out + +// CHECK-DAG: %"struct.__spv::__spirv_JointMatrixINTEL.16" = type { [12 x [12 x [1 x [4 x i32]]]] addrspace(4)* } +// CHECK-DAG: %"struct.__spv::__spirv_JointMatrixINTEL" = type { [12 x [48 x [1 x [4 x i8]]]] addrspace(4)* } +// CHECK-DAG: %"struct.__spv::__spirv_JointMatrixINTEL.14" = type { [48 x [12 x [4 x [4 x i8]]]] addrspace(4)* } + #include #if (SYCL_EXT_ONEAPI_MATRIX == 2) #include From cb0cb11eb5e9637769516ddc61adac67335ecfdc Mon Sep 17 00:00:00 2001 From: Dmitry Sidorov Date: Mon, 27 Dec 2021 14:32:57 +0300 Subject: [PATCH 2/4] Enum explicit numbering and test changes Signed-off-by: Dmitry Sidorov --- sycl/include/CL/__spirv/spirv_types.hpp | 7 ++++++- sycl/test/matrix/matrix-int8-test.cpp | 5 ++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/sycl/include/CL/__spirv/spirv_types.hpp b/sycl/include/CL/__spirv/spirv_types.hpp index e160cfeed426e..4fb0fa8886796 100644 --- a/sycl/include/CL/__spirv/spirv_types.hpp +++ b/sycl/include/CL/__spirv/spirv_types.hpp @@ -108,7 +108,12 @@ enum class GroupOperation : uint32_t { ExclusiveScan = 2 }; -enum class MatrixLayout { RowMajor, ColumnMajor, PackedA, PackedB }; +enum class MatrixLayout : uint32_t { + RowMajor = 0, + ColumnMajor = 1, + PackedA = 2, + PackedB = 3 +}; // TODO: replace the following W/A with a better solution when we have it. // The following structure is used to represent the joint matrix type in the diff --git a/sycl/test/matrix/matrix-int8-test.cpp b/sycl/test/matrix/matrix-int8-test.cpp index c88bf03e60f67..ba4327a8e6cd5 100644 --- a/sycl/test/matrix/matrix-int8-test.cpp +++ b/sycl/test/matrix/matrix-int8-test.cpp @@ -1,9 +1,8 @@ // RUN: %clangxx -fsycl -fsycl-device-only -O2 -S -emit-llvm -o - %s | FileCheck %s -// RUNx: %clangxx -fsycl -O2 %s -o %t.out -// CHECK-DAG: %"struct.__spv::__spirv_JointMatrixINTEL.16" = type { [12 x [12 x [1 x [4 x i32]]]] addrspace(4)* } // CHECK-DAG: %"struct.__spv::__spirv_JointMatrixINTEL" = type { [12 x [48 x [1 x [4 x i8]]]] addrspace(4)* } -// CHECK-DAG: %"struct.__spv::__spirv_JointMatrixINTEL.14" = type { [48 x [12 x [4 x [4 x i8]]]] addrspace(4)* } +// CHECK-DAG: %"struct.__spv::__spirv_JointMatrixINTEL.[[#]]" = type { [12 x [12 x [1 x [4 x i32]]]] addrspace(4)* } +// CHECK-DAG: %"struct.__spv::__spirv_JointMatrixINTEL.[[#]]" = type { [48 x [12 x [4 x [4 x i8]]]] addrspace(4)* } #include #if (SYCL_EXT_ONEAPI_MATRIX == 2) From 16905080088a1da9af06e918e3bd80ac02cff68b Mon Sep 17 00:00:00 2001 From: Dmitry Sidorov Date: Mon, 27 Dec 2021 17:12:25 +0300 Subject: [PATCH 3/4] Address clang-format concerns Signed-off-by: Dmitry Sidorov --- sycl/test/matrix/matrix-int8-test.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/sycl/test/matrix/matrix-int8-test.cpp b/sycl/test/matrix/matrix-int8-test.cpp index ba4327a8e6cd5..fea605510ea75 100644 --- a/sycl/test/matrix/matrix-int8-test.cpp +++ b/sycl/test/matrix/matrix-int8-test.cpp @@ -1,8 +1,11 @@ // RUN: %clangxx -fsycl -fsycl-device-only -O2 -S -emit-llvm -o - %s | FileCheck %s -// CHECK-DAG: %"struct.__spv::__spirv_JointMatrixINTEL" = type { [12 x [48 x [1 x [4 x i8]]]] addrspace(4)* } -// CHECK-DAG: %"struct.__spv::__spirv_JointMatrixINTEL.[[#]]" = type { [12 x [12 x [1 x [4 x i32]]]] addrspace(4)* } -// CHECK-DAG: %"struct.__spv::__spirv_JointMatrixINTEL.[[#]]" = type { [48 x [12 x [4 x [4 x i8]]]] addrspace(4)* } +// CHECK-DAG: %"struct.__spv::__spirv_JointMatrixINTEL" = +// CHECK-DAG: type { [12 x [48 x [1 x [4 x i8]]]] addrspace(4)* } +// CHECK-DAG: %"struct.__spv::__spirv_JointMatrixINTEL.[[#]]" = +// CHECK-DAG: type { [12 x [12 x [1 x [4 x i32]]]] addrspace(4)* } +// CHECK-DAG: %"struct.__spv::__spirv_JointMatrixINTEL.[[#]]" = +// CHECK-DAG: type { [48 x [12 x [4 x [4 x i8]]]] addrspace(4)* } #include #if (SYCL_EXT_ONEAPI_MATRIX == 2) From 0b7f602de5c8da6e207ccf9e8fbdf42aa8fb8451 Mon Sep 17 00:00:00 2001 From: Dmitry Sidorov Date: Tue, 28 Dec 2021 17:32:19 +0300 Subject: [PATCH 4/4] Revert "Address clang-format concerns" This reverts commit 1764dac76364ad8b93b5b417950e0f81d7763923. --- sycl/test/matrix/matrix-int8-test.cpp | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/sycl/test/matrix/matrix-int8-test.cpp b/sycl/test/matrix/matrix-int8-test.cpp index fea605510ea75..ba4327a8e6cd5 100644 --- a/sycl/test/matrix/matrix-int8-test.cpp +++ b/sycl/test/matrix/matrix-int8-test.cpp @@ -1,11 +1,8 @@ // RUN: %clangxx -fsycl -fsycl-device-only -O2 -S -emit-llvm -o - %s | FileCheck %s -// CHECK-DAG: %"struct.__spv::__spirv_JointMatrixINTEL" = -// CHECK-DAG: type { [12 x [48 x [1 x [4 x i8]]]] addrspace(4)* } -// CHECK-DAG: %"struct.__spv::__spirv_JointMatrixINTEL.[[#]]" = -// CHECK-DAG: type { [12 x [12 x [1 x [4 x i32]]]] addrspace(4)* } -// CHECK-DAG: %"struct.__spv::__spirv_JointMatrixINTEL.[[#]]" = -// CHECK-DAG: type { [48 x [12 x [4 x [4 x i8]]]] addrspace(4)* } +// CHECK-DAG: %"struct.__spv::__spirv_JointMatrixINTEL" = type { [12 x [48 x [1 x [4 x i8]]]] addrspace(4)* } +// CHECK-DAG: %"struct.__spv::__spirv_JointMatrixINTEL.[[#]]" = type { [12 x [12 x [1 x [4 x i32]]]] addrspace(4)* } +// CHECK-DAG: %"struct.__spv::__spirv_JointMatrixINTEL.[[#]]" = type { [48 x [12 x [4 x [4 x i8]]]] addrspace(4)* } #include #if (SYCL_EXT_ONEAPI_MATRIX == 2)