Skip to content

Commit 208cd7c

Browse files
committed
[SYCL] Update documentation with OpenCL types re-use proposal
Signed-off-by: Alexey Bader <alexey.bader@intel.com>
1 parent da9bdd3 commit 208cd7c

File tree

1 file changed

+25
-39
lines changed

1 file changed

+25
-39
lines changed

sycl/doc/SYCL_compiler_and_runtime_design.md

+25-39
Original file line numberDiff line numberDiff line change
@@ -391,17 +391,28 @@ produced by OpenCL C front-end compiler.
391391
It's a regular function, which can conflict with user code produced from C++
392392
source.
393393

394-
395-
SYCL compiler uses solution developed for OpenCL C++ compiler prototype:
394+
SYCL compiler uses modified solution developed for OpenCL C++ compiler
395+
prototype:
396396

397397
- Compiler: https://github.com/KhronosGroup/SPIR/tree/spirv-1.1
398398
- Headers: https://github.com/KhronosGroup/libclcxx
399399

400-
SPIR-V types and operations that do not have LLVM equivalents are **declared**
400+
Our solution re-uses OpenCL data types like sampler, event, image types, etc,
401+
but we use different spelling to avoid potential conflicts with C++ code.
402+
Spelling convention for the OpenCL types enabled in SYCL mode is:
403+
404+
```
405+
__ocl_<OpenCL_type_name> // e.g. __ocl_sampler_t, __ocl_event_t
406+
```
407+
408+
Operations using OpenCL types use special naming convention described in this
409+
[document](https://github.com/KhronosGroup/SPIRV-LLVM-Translator/blob/master/docs/SPIRVRepresentationInLLVM.rst).
410+
This solution allows us avoid SYCL specialization in SPIR-V translator and
411+
leverage clang infrastructure developed for OpenCL types.
412+
413+
SPIR-V operations that do not have LLVM equivalents are **declared**
401414
(but not defined) in the headers and satisfy following requirements:
402415

403-
- the type must be pre-declared as a C++ class in `cl::__spirv` namespace
404-
- the type must not have actual definition in C++ program
405416
- the operation is expressed in C++ as `extern` function not throwing C++
406417
exceptions
407418
- the operation must not have the actual definition in C++ program
@@ -410,42 +421,17 @@ For example, the following C++ code is successfully recognized and translated
410421
into SPIR-V operation `OpGroupAsyncCopy`:
411422

412423
```C++
413-
namespace cl {
414-
namespace __spirv {
415-
// This class does not have definition, it is only predeclared here.
416-
// The pointers to this class objects can be passed to or returned from
417-
// SPIR-V built-in functions. Only in such cases the class is recognized
418-
// as SPIR-V type OpTypeEvent.
419-
class OpTypeEvent;
420-
421-
template <typename dataT>
422-
extern OpTypeEvent *OpGroupAsyncCopy(int32_t Scope, __local dataT *Dest,
423-
__global dataT *Src, size_t NumElements,
424-
size_t Stride, OpTypeEvent *E) noexcept;
425-
} // namespace __spirv
426-
} // namespace cl
427-
428-
cl::__spirv::OpTypeEvent *e =
429-
cl::__spirv::OpGroupAsyncCopy<dataT>(cl::__spirv::Scope::Workgroup,
430-
dst, src, numElements, 1, 0);
424+
template <typename dataT>
425+
extern __ocl_event_t
426+
__spirv_OpGroupAsyncCopy(int32_t Scope, __local dataT *Dest,
427+
__global dataT *Src, size_t NumElements,
428+
size_t Stride, __ocl_event_t E) noexcept;
429+
430+
__ocl_event_t e =
431+
__spirv_OpGroupAsyncCopy(cl::__spirv::Scope::Workgroup,
432+
dst, src, numElements, 1, E);
431433
```
432434
433-
OpenCL C++ compiler uses a special module pass in clang that transforms the
434-
names of C++ classes, globals and functions from the namespace `cl::__spirv::`
435-
to
436-
["SPIR-V representation in LLVM IR"](https://github.com/KhronosGroup/SPIRV-LLVM-Translator/blob/master/docs/SPIRVRepresentationInLLVM.rst)
437-
which is recognized by the LLVM IR to SPIR-V translator.
438-
439-
In the OpenCL C++ prototype project the pass is located at the directory:
440-
`lib/CodeGen/OclCxxRewrite`. The file with the pass is:
441-
`lib/CodeGen/OclCxxRewrite/BifNameReflower.cpp`. The other files in
442-
`lib/CodeGen/OclCxxRewrite` are utility files implementing Itanium demangler
443-
and other helping functionality.
444-
445-
That LLVM module pass has been ported from OpenCL C++ prototype to the SYCL
446-
compiler as is. It made possible using simple declarations of C++ classes and
447-
external functions as if they were the SPIR-V specific types and operations.
448-
449435
#### Some details and agreements on using SPIR-V special types and operations
450436
451437
The SPIR-V specific C++ enumerators and classes are declared in the file:

0 commit comments

Comments
 (0)