Skip to content

[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

Merged
merged 14 commits into from
Mar 26, 2021

Conversation

elizabethandrews
Copy link
Contributor

@elizabethandrews elizabethandrews commented Mar 11, 2021

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 a
corresponding entry in the kernel_signatures structure in the integration header. The param
kind 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

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>
Copy link
Contributor

@erichkeane erichkeane left a 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).

@@ -2871,6 +2970,14 @@ class SyclKernelIntHeaderCreator : public SyclKernelFieldHandler {
return true;
}

void handleSyclKernelHandlerType(QualType Ty) {
// Add corresponding entry in integration header.
Copy link
Contributor

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.

Copy link
Contributor Author

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

Copy link
Contributor

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.

Copy link
Contributor Author

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>
Signed-off-by: Elizabeth Andrews <elizabeth.andrews@intel.com>
@elizabethandrews elizabethandrews changed the title [WIP][SYCL] Implement SYCL 2020 specialization constants [SYCL] Implement SYCL 2020 specialization constants in Clang Mar 18, 2021
@elizabethandrews elizabethandrews marked this pull request as ready for review March 18, 2021 21:12
…passed

Signed-off-by: Elizabeth Andrews <elizabeth.andrews@intel.com>
@elizabethandrews
Copy link
Contributor Author

I will add test for latest commit (parallel_for_work_group) ASAP.

@elizabethandrews elizabethandrews changed the title [SYCL] Implement SYCL 2020 specialization constants in Clang [Do not merge][Ready for review][SYCL][Do not merge Implement SYCL 2020 specialization constants in Clang Mar 19, 2021
@elizabethandrews elizabethandrews changed the title [Do not merge][Ready for review][SYCL][Do not merge Implement SYCL 2020 specialization constants in Clang [Do not merge][SYCL] Implement SYCL 2020 specialization constants in Clang Mar 19, 2021
// 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";
Copy link
Contributor

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.

@@ -777,6 +782,23 @@ constructKernelName(Sema &S, FunctionDecl *KernelCallerFunc,
KernelNameType)};
}

static bool hasNativeSycl2020SpecConstantSupport(ASTContext &Context) {
Copy link
Contributor

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".

Copy link
Contributor Author

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

Copy link
Contributor Author

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 :)

Copy link
Contributor

@keryell keryell Mar 23, 2021

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?

Copy link
Contributor Author

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?

Signed-off-by: Elizabeth Andrews <elizabeth.andrews@intel.com>
…er change

Signed-off-by: Elizabeth Andrews <elizabeth.andrews@intel.com>
@elizabethandrews elizabethandrews changed the title [Do not merge][SYCL] Implement SYCL 2020 specialization constants in Clang [SYCL] Implement SYCL 2020 specialization constants in Clang Mar 23, 2021
Signed-off-by: Elizabeth Andrews <elizabeth.andrews@intel.com>
erichkeane
erichkeane previously approved these changes Mar 24, 2021
Copy link
Contributor

@premanandrao premanandrao left a 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>
premanandrao
premanandrao previously approved these changes Mar 24, 2021
…sitive

Signed-off-by: Elizabeth Andrews <elizabeth.andrews@intel.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants