-
Notifications
You must be signed in to change notification settings - Fork 793
[SYCL][SPIR-V] Drop Unnecessary Matrix Use parameter #6923
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
[SYCL][SPIR-V] Drop Unnecessary Matrix Use parameter #6923
Conversation
Last parameter 'Use' is optional in SPIR-V, but is not optional in DPCPP headers. If it has Unnecessary value - skip it Signed-off-by: Sidorov, Dmitry <dmitry.sidorov@intel.com>
edd0de4
to
3a136cb
Compare
clang/lib/CodeGen/CodeGenTypes.cpp
Outdated
@@ -57,11 +57,14 @@ void CodeGenTypes::addRecordTypeName(const RecordDecl *RD, | |||
if (auto TemplateDecl = dyn_cast<ClassTemplateSpecializationDecl>(RD)) { | |||
ArrayRef<TemplateArgument> TemplateArgs = | |||
TemplateDecl->getTemplateArgs().asArray(); | |||
constexpr size_t MaxMatrixParameter = 6; | |||
assert(TemplateArgs.size() <= MaxMatrixParameter && | |||
"Too many template parameters for JointMatrixINTEL type"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a minimum matrix parameter we can also check at the same time?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added, thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Assert message should be updated right? Since you added a minimum requirement as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, actually, after some consideration I realized, that there is no max or min number of template parameters, it's just a fixed number of 6.
Signed-off-by: Sidorov, Dmitry <dmitry.sidorov@intel.com>
e95bf92
to
1405c9d
Compare
clang/lib/CodeGen/CodeGenTypes.cpp
Outdated
@@ -57,11 +57,14 @@ void CodeGenTypes::addRecordTypeName(const RecordDecl *RD, | |||
if (auto TemplateDecl = dyn_cast<ClassTemplateSpecializationDecl>(RD)) { | |||
ArrayRef<TemplateArgument> TemplateArgs = | |||
TemplateDecl->getTemplateArgs().asArray(); | |||
constexpr size_t MaxMatrixParameter = 6; | |||
assert(TemplateArgs.size() <= MaxMatrixParameter && | |||
"Too many template parameters for JointMatrixINTEL type"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Assert message should be updated right? Since you added a minimum requirement as well
const auto IntTemplateParam = TemplateArgs[I].getAsIntegral(); | ||
// Last parameter 'Use' is optional in SPIR-V, but is not optional | ||
// in DPCPP headers. If it has Unnecessary value - skip it | ||
constexpr size_t Unnecessary = 3; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For my understanding can you explain this? What is the significance of '3' here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the significance of '3' here?
comment would be helpful. Thank you
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added the comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm still a little confused. My question was why is "3" = Unecessary. Is this defined by the spec? What are possible legal values for Use parameter?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, there is no Unnecessary
in both SPIR-V and SYCL spec. Legal values on user-visible API level are 0, 1 and 2 (same for SPIR-V). Yet Unnecessary
is defined in intermediate level of SYCL headers to keep compatibility with previous version of the extension, where we didn't have Use
parameter making to be a default Use
value.
While answering your question another idea came up in my mind, which might be cleaner. What if we declare struct __spirv_JointMatrixINTEL
depending on SYCL_EXT_ONEAPI_MATRIX
, WDYT @yubingex007-a11y @dkhaldi ? Like this:
#if SYCL_EXT_ONEAPI_MATRIX == 1
template <typename T, std::size_t R, std::size_t C, MatrixLayout L,
Scope::Flag S = Scope::Flag::Subgroup>
struct __spirv_JointMatrixINTEL {
T(*Value)
[R][C][static_cast<size_t>(L) + 1][static_cast<size_t>(S) + 1];
};
#else
template <typename T, std::size_t R, std::size_t C, MatrixLayout L,
Scope::Flag S = Scope::Flag::Subgroup,
MatrixUse U = MatrixUse::Unnecessary>
struct __spirv_JointMatrixINTEL {
T(*Value)
[R][C][static_cast<size_t>(L) + 1][static_cast<size_t>(S) + 1]
[static_cast<size_t>(U) + 1];
};
#endif // SYCL_EXT_ONEAPI_MATRIX
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this idea as long this does not break current SPIRV (use is still optional).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Eh, there is quite a lot of things to change in the headers with a lot of code duplication to make it working. @elizabethandrews are we good to have the patch in clang or additional code commentary is required?
Basically every code which contains __spirv_JointMatrixINTEL
should be duplicated and it includes all SPIR-V matrix instructions (10 of them) declarations with their appropriate calls in high-level SYCL API. So it does look for me that this clang modification is easier to support then two copies of the matrix-related code in the headers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we do something like:
template <typename T, std::size_t R, std::size_t C, MatrixLayout L,
Scope::Flag S = Scope::Flag::Subgroup
#if SYCL_EXT_ONEAPI_MATRIX == 1
,MatrixUse U = MatrixUse::Unnecessary>
#else
>
#endif
struct __spirv_JointMatrixINTEL {
T(*Value)
[R][C][static_cast<size_t>(L) + 1][static_cast<size_t>(S) + 1]
#if SYCL_EXT_ONEAPI_MATRIX == 1
[static_cast<size_t>(U) + 1];
#else
;
#endif // SYCL_EXT_ONEAPI_MATRIX
};
Also, I see that Unnecessary template parameter is a default value, why can't we just declare it? How it will be incompatible with the previous version of the extension?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM other than the couple of things that @elizabethandrews pointed out already.
Signed-off-by: Sidorov, Dmitry <dmitry.sidorov@intel.com>
Converted to draft. |
Last parameter 'Use' is optional in SPIR-V, but is not optional in DPCPP headers. If it has Unnecessary value - skip it
Signed-off-by: Sidorov, Dmitry dmitry.sidorov@intel.com