Skip to content

[SYCL] Change matrix type #5221

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jan 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions sycl/include/CL/__spirv/spirv_types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,32 @@ 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
// 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 <typename T, std::size_t R, std::size_t C, MatrixLayout U,
Scope::Flag S = Scope::Flag::Subgroup>
struct __spirv_JointMatrixINTEL;
struct __spirv_JointMatrixINTEL {
T (*Value)[R][C][static_cast<size_t>(U) + 1][static_cast<size_t>(S) + 1];
};

} // namespace __spv

Expand Down
8 changes: 6 additions & 2 deletions sycl/test/matrix/matrix-int8-test.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
// RUN: %clangxx -fsycl -O2 %s -o %t.out
// XFAIL: *
// 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)* }

#include <CL/sycl.hpp>
#if (SYCL_EXT_ONEAPI_MATRIX == 2)
#include <iostream>
Expand Down