-
Notifications
You must be signed in to change notification settings - Fork 738
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] Implement OpenCL kernel function generation #249
[SYCL] Implement OpenCL kernel function generation #249
Conversation
@bader , do we still need this PR? |
We need similar PR, but I think the right way to generate OpenCL kernels is to emit LLVM IR in CodeGen, rather than build an AST in Sema. If you agree, we should be refactor the patch.... |
If it's doable and will make our code better, then I'm ok with it. I think this PR can be closed then. |
Let's rebase existing approach to https://reviews.llvm.org/D60455, upload to LLVM Phabricator and ask Clang devs for the feedback. Based on the feedback we decide whether it make sense to re-work the current approach. |
@bader , do we need base OpenCL kernel generation on this patch - 194cc3a ? |
I agree that sampler support is probably not a requirement for the first iteration. |
9165e60
to
06c7431
Compare
clang/lib/Sema/SemaSYCL.cpp
Outdated
// All special SYCL objects must have __init method | ||
CXXMethodDecl *InitMethod = getInitMethod(CRD); | ||
assert(InitMethod && | ||
"The accessor/sampler must have the __init method"); |
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.
Remove "sampler" from 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.
Sounds reasonable.
"__init method is expected"
clang/lib/Sema/SemaSYCL.cpp
Outdated
createSpecialSYCLObjParamDesc(Fld, ArgTy); | ||
} else if (!ArgTy->isStandardLayoutType()) { | ||
|
||
// TODO: Do we need diagnostics with the kernel gen patch? |
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.
@bader , what do you think about adding diagnostics with OpenCL kernel generation patch?
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.
Please, remove and proceed with uploading the patch to reviews.llvm.org.
06c7431
to
07554f8
Compare
@bader , could you please take a look? I have a couple of questions here. |
All SYCL memory objects shared between host and device (buffers/images, these objects map to OpenCL buffers and images) must be accessed through special accessor classes. The "device" side implementation of these classes contain pointers to the device memory. As there is no way in OpenCL to pass structures with pointers inside as kernel arguments, all memory objects shared between host and device must be passed to the kernel as raw pointers. SYCL also has a special mechanism for passing kernel arguments from host to the device. In OpenCL kernel arguments are set by calling `clSetKernelArg` function for each kernel argument, meanwhile in SYCL all the kernel arguments are fields of "SYCL kernel function" which can be defined as a lambda function or a named function object and passed as an argument to SYCL function for invoking kernels (such as `parallel_for` or `single_task`). To facilitate the mapping of SYCL kernel data members to OpenCL kernel arguments and overcome OpenCL limitations we added the generation of an OpenCL kernel function inside the compiler. An OpenCL kernel function contains the body of the SYCL kernel function, receives OpenCL-like parameters and additionally does some manipulation to initialize SYCL kernel data members with these parameters. In some pseudo code the OpenCL kernel function can look like this: ``` // SYCL kernel is defined in SYCL headers: template <typename KernelName, typename KernelType/*, ...*/> __attribute__((sycl_kernel)) void sycl_kernel_function(KernelType KernelFuncObj) { // ... KernelFuncObj(); } // Generated OpenCL kernel function __kernel KernelName(global int* a) { KernelType KernelFuncObj; // Actually kernel function object declaration // doesn't have a name in AST. // Let the kernel function object have one captured field - accessor A. // We need to init it with global pointer from arguments: KernelFuncObj.A.__init(a); // Body of the SYCL kernel from SYCL headers: { KernelFuncObj(); } } ``` OpenCL kernel function is generated by the compiler inside the Sema using AST nodes.
07554f8
to
02e8944
Compare
@Fznamznon , is this PR needed? Can we close it? |
The patch is outdated. I rebased it in #3071, but it's quite different from what we have today in the sycl branch. The code has been significantly refactored by @erichkeane and @Fznamznon. |
I don't. |
I don't. |
Enables tests that were marked with UNSUPPORTED: cuda, but are in fact passing. Result of work on intel#249
I'd like to review OpenCL kernel generation part before pushing it to reviews.llvm.org since it's very big and complicated change with it's own issues and limitations.
For example, our detecting of SYCL special objects, e.g. accessors/samplers seems a bit fragile.