-
Notifications
You must be signed in to change notification settings - Fork 769
[SYCL] Implement SYCL 2020 specialization constants in Clang #3345
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
Conversation
This is a draft patch to get early feedback. Spec is currently under review here - intel#3331 Signed-off-by: Elizabeth Andrews <elizabeth.andrews@intel.com>
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.
Approve of the direction, and don't see anything particularly bad. A couple of comments.
1 thought though.... i wonder if there is value in having multiple kernel_handler parameters (which becomes possible with the loop).
clang/lib/Sema/SemaSYCL.cpp
Outdated
@@ -2871,6 +2970,14 @@ class SyclKernelIntHeaderCreator : public SyclKernelFieldHandler { | |||
return true; | |||
} | |||
|
|||
void handleSyclKernelHandlerType(QualType Ty) { | |||
// Add corresponding entry in integration header. |
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.
Hmm.... I guess the offset is simply nonsensical in this case, right? I wonder if we're better off having some sort of sentinel value to mean that.
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 think the runtime team will need to answer that. I do not really know how the integration header is consumed
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 know the runtime just loops through these values, but it seems that the offset is simply meaningless/won't be used. From a practicality perspective, pushing 0
here is likely fine. That said (assuming I'm right here), I'd vastly prefer it be an obviously 'meaningless' number. I think that it is unsigned, so -1 doesn't work, so unsigned-max is likely our choice. Please talk with @romanovvlad and confirm I'm correct in its meaninglessness.
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 haven't made this change. I thought I would complete a round of testing with 0 and then change it to unsigned-max to see if change causes any break. @romanovvlad mentioned he thinks offset is meaningless based on comment here - https://github.com/intel/llvm/pull/3331/files#r593198110. If that is the case, I think spec should be modified before we change the implementation here
Signed-off-by: Elizabeth Andrews <elizabeth.andrews@intel.com>
Signed-off-by: Elizabeth Andrews <elizabeth.andrews@intel.com>
Signed-off-by: Elizabeth Andrews <elizabeth.andrews@intel.com>
Signed-off-by: Elizabeth Andrews <elizabeth.andrews@intel.com>
Signed-off-by: Elizabeth Andrews <elizabeth.andrews@intel.com>
…passed Signed-off-by: Elizabeth Andrews <elizabeth.andrews@intel.com>
I will add test for latest commit (parallel_for_work_group) ASAP. |
// TODO: There is no name for the base available, but duplicate names are | ||
// seemingly already possible, so we'll give them all the same name for now. | ||
// This only happens with the accessor types. | ||
StringRef Name = "_arg__base"; |
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 anyone who continues along next time and sees this "TODO" and wants to fix it, the type name of FieldTy might be a good addition here. Duplicates don't cause problems, but perhaps it would be nice from a debug-ability perspective.
clang/lib/Sema/SemaSYCL.cpp
Outdated
@@ -777,6 +782,23 @@ constructKernelName(Sema &S, FunctionDecl *KernelCallerFunc, | |||
KernelNameType)}; | |||
} | |||
|
|||
static bool hasNativeSycl2020SpecConstantSupport(ASTContext &Context) { |
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'd probably prefer something more generic here for the name, like "IsNativeSomethingOrOther".
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 do not know what the generic name for targets which satisfy T.isSPIR() && T.getSubArch() == llvm::Triple::NoSubArch
is. @bader could you please suggest something
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 spoke to @mdtoguchi offline and he suggested isDefaultSYCLArch()
or isDefaultSPIRArch()
. I plan to go with isDefaultSPIRArch()
unless someone here objects :)
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 meaning of isDefaultSPIRArch()
for implementations not using SPIR, like CUDA or others, where they could have an equivalent for specialization constant?
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.
It was my understanding that non-SPIR targets do not have specialization constants support and require special processing. isDefaultSPIRArch()
is used to determine when this special processing is required for specialization constants. I do not what the equivalents in CUDA etc are and how/if they are handled in SYCL compiler. @AlexeySachkov @romanovvlad @bader could you please answer?
…er change Signed-off-by: Elizabeth Andrews <elizabeth.andrews@intel.com>
Signed-off-by: Elizabeth Andrews <elizabeth.andrews@intel.com>
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.
Just a couple minor nits.
Signed-off-by: Elizabeth Andrews <elizabeth.andrews@intel.com>
…sitive Signed-off-by: Elizabeth Andrews <elizabeth.andrews@intel.com>
This patch implements SYCL 2020 specialization constants in the frontend.
Specialization constants in SYCL 2020 are not captured by lambda and are accessed
through new optional lambda argument kernel_handler. If this argument is present,
a clone of the kernel_handler object should be constructed in openCL kernel.
If the target has no native support for specialization constants, the compiler generates
an openCL kernel argument specialization_constants_buffer of type char*. Generated
kernel_handler clone should then be initialized using the generated kernel argument through __init_specialization_constants_buffer method.
The generated kernel argument
specialization_constants_buffer
should also have acorresponding entry in the
kernel_signatures
structure in the integration header. The paramkind for this argument should be
kernel_param_kind_t:specialization_constants_buffer
If the target has native support for specialization constants, the additional argument, and
corresponding handling, need not be generated. In this case, kernel_handler local clone is default
constructed.
Instances of kernel_handler in sycl_kernel is then replaced to use the local clone.
Spec is currently under review here -
#3331
Signed-off-by: Elizabeth Andrews elizabeth.andrews@intel.com