Page MenuHomePhabricator

[SYCL] Implement OpenCL kernel function generation
Needs ReviewPublic

Authored by Fznamznon on Dec 4 2019, 7:25 AM.



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) {
  // ...

// 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:
  // Body of the SYCL kernel from SYCL headers:

OpenCL kernel function is generated by the compiler inside the Sema
using AST nodes.

Event Timeline

Fznamznon created this revision.Dec 4 2019, 7:25 AM
Herald added a project: Restricted Project. · View Herald TranscriptDec 4 2019, 7:25 AM
Fznamznon updated this revision to Diff 233013.Dec 10 2019, 1:16 AM

Updated tests using address space attributes added by D71005

keryell added inline comments.Dec 10 2019, 6:04 PM

Feel free to add more comments in this area up to line 103.


After more thought, perhaps the solution proposed by Victor Lomüller during the last SYCL upstreaming meeting about marking accessor classes with some attribute instead of detecting concrete type names is a better generic approach.
I am more convinced now by his argument allowing more experimenting with alternative runtimes, since it looks like it is the only place we detect type names. For example the kernels are marked with an attribute in the runtime instead of concretely detecting the parallel_for() functions and so on.


Missing description about the purpose of this test


Missing description about the purpose of this test.
I am struggling about understanding what this test is for...
OK, after coming back later, I think I got it. I was confused by the fact that in the kernels you are using both true accessors (A, B & C) *and* some objects with names similar to SYCL accessor.
Is it possible to have some tests without true accessors?


Missing description about the purpose of this test

Fznamznon marked an inline comment as done.Dec 13 2019, 6:30 AM
Fznamznon added inline comments.

@Naghasan , what do you think about upstreaming the solution which you proposed?

Fznamznon marked an inline comment as not done.Dec 16 2019, 3:14 AM