Skip to content

Commit 1c9f9f8

Browse files
authored
[SYCL] Change matrix type (#5221)
Previously we relied on the structure type (which represented matrix type) mangling to obtain its layout. Now, when DPCPP mangling 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 <typename T, int R, int C, int L, int S> struct __spirv_JointMatrixINTEL; to template <typename T, int R, int C, int L, int S> 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 <[email protected]>
1 parent eb4b529 commit 1c9f9f8

File tree

2 files changed

+29
-4
lines changed

2 files changed

+29
-4
lines changed

sycl/include/CL/__spirv/spirv_types.hpp

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,32 @@ enum class GroupOperation : uint32_t {
108108
ExclusiveScan = 2
109109
};
110110

111-
enum class MatrixLayout { RowMajor, ColumnMajor, PackedA, PackedB };
111+
enum class MatrixLayout : uint32_t {
112+
RowMajor = 0,
113+
ColumnMajor = 1,
114+
PackedA = 2,
115+
PackedB = 3
116+
};
112117

118+
// TODO: replace the following W/A with a better solution when we have it.
119+
// The following structure is used to represent the joint matrix type in the
120+
// LLVM IR. The structure has a pointer to a multidimensional array member which
121+
// makes the encoding of the matrix type information within the LLVM IR looks
122+
// like this:
123+
// %struct.__spirv_JointMatrixINTEL = type { [42 x [6 x [2 x [1 x float]]]]* }
124+
// Note that an array cannot be of zero size but MatrixLayout and Scope
125+
// parameters can; hence '+ 1' is added to the 3rd and 4th dimensions.
126+
// In general, representing a matrix type information like this is a bit odd
127+
// (especially for MatrixLayout and Scope parameters). But with the current
128+
// tools we have in Clang, this is the only way to preserve and communicate this
129+
// information to SPIRV translator.
130+
// The long term solution would be to introduce a matrix type in Clang and use
131+
// it instead of this member.
113132
template <typename T, std::size_t R, std::size_t C, MatrixLayout U,
114133
Scope::Flag S = Scope::Flag::Subgroup>
115-
struct __spirv_JointMatrixINTEL;
134+
struct __spirv_JointMatrixINTEL {
135+
T (*Value)[R][C][static_cast<size_t>(U) + 1][static_cast<size_t>(S) + 1];
136+
};
116137

117138
} // namespace __spv
118139

sycl/test/matrix/matrix-int8-test.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1-
// RUN: %clangxx -fsycl -O2 %s -o %t.out
2-
// XFAIL: *
1+
// RUN: %clangxx -fsycl -fsycl-device-only -O2 -S -emit-llvm -o - %s | FileCheck %s
2+
3+
// CHECK-DAG: %"struct.__spv::__spirv_JointMatrixINTEL" = type { [12 x [48 x [1 x [4 x i8]]]] addrspace(4)* }
4+
// CHECK-DAG: %"struct.__spv::__spirv_JointMatrixINTEL.[[#]]" = type { [12 x [12 x [1 x [4 x i32]]]] addrspace(4)* }
5+
// CHECK-DAG: %"struct.__spv::__spirv_JointMatrixINTEL.[[#]]" = type { [48 x [12 x [4 x [4 x i8]]]] addrspace(4)* }
6+
37
#include <CL/sycl.hpp>
48
#if (SYCL_EXT_ONEAPI_MATRIX == 2)
59
#include <iostream>

0 commit comments

Comments
 (0)