[PATCH] D71016: [SYCL] Implement OpenCL kernel function generation

Mariya Podchishchaeva via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Dec 4 07:30:47 PST 2019


Fznamznon created this revision.
Herald added subscribers: cfe-commits, Anastasia, ebevhan, jfb, yaxunl, mgorny.
Herald added a project: clang.
Fznamznon added reviewers: bader, Naghasan, ABataev.

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.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D71016

Files:
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/Parse/ParseAST.cpp
  clang/lib/Sema/CMakeLists.txt
  clang/lib/Sema/SemaSYCL.cpp
  clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
  clang/test/CodeGenSYCL/Inputs/sycl.hpp
  clang/test/CodeGenSYCL/basic-opencl-kernel.cpp
  clang/test/CodeGenSYCL/device-functions.cpp
  clang/test/SemaSYCL/Inputs/sycl.hpp
  clang/test/SemaSYCL/accessors-targets.cpp
  clang/test/SemaSYCL/basic-opencl-kernel.cpp
  clang/test/SemaSYCL/built-in-type-kernel-arg.cpp
  clang/test/SemaSYCL/fake-accessors.cpp
  clang/test/SemaSYCL/mangle-kernel.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D71016.232130.patch
Type: text/x-patch
Size: 44617 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20191204/0f60c37a/attachment-0001.bin>


More information about the cfe-commits mailing list