@@ -391,17 +391,28 @@ produced by OpenCL C front-end compiler.
391
391
It's a regular function, which can conflict with user code produced from C++
392
392
source.
393
393
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:
396
396
397
397
- Compiler: https://github.com/KhronosGroup/SPIR/tree/spirv-1.1
398
398
- Headers: https://github.com/KhronosGroup/libclcxx
399
399
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**
401
414
(but not defined) in the headers and satisfy following requirements:
402
415
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
405
416
- the operation is expressed in C++ as ` extern ` function not throwing C++
406
417
exceptions
407
418
- 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
410
421
into SPIR-V operation ` OpGroupAsyncCopy ` :
411
422
412
423
``` 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);
431
433
```
432
434
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
-
449
435
#### Some details and agreements on using SPIR-V special types and operations
450
436
451
437
The SPIR-V specific C++ enumerators and classes are declared in the file:
0 commit comments