|
| 1 | +# Builtin kernels |
| 2 | + |
| 3 | +| Proposal ID | CP018 | |
| 4 | +|-------------|--------| |
| 5 | +| Name | Builtin kernel support in SYCL | |
| 6 | +| Date of Creation | 12 October 2018 | |
| 7 | +| Target | SYCL 1.2.1 vendor extension | |
| 8 | +| Current Status | _Work In Progress_ | |
| 9 | +| Implemented in | _N/A_ | |
| 10 | +| Reply-to | Ruyman Reyes <ruyman@codeplay.com> | |
| 11 | +| Original author | Ruyman Reyes <ruyman@codeplay.com> | |
| 12 | + |
| 13 | +## Overview |
| 14 | + |
| 15 | +Some OpenCL implementations expose already pre-built and embedded _built-in kernels_ to the users. |
| 16 | +This functionality is used in some cases to expose optimal implementation of some operations, or to |
| 17 | +access some fixed-function hardware available on the platform as a non-programmable OpenCL kernel. |
| 18 | + |
| 19 | +Nowadays SYCL developers can use the OpenCL interoperability functionality to use built-in kernels whenever required. |
| 20 | +However this can be cumbersome and error prone as it forces switching back and forward from OpenCL and SYCL/C++. |
| 21 | + |
| 22 | +This vendor extension to the SYCL 1.2.1 specification exposes an interface to work directly from SYCL with |
| 23 | +OpenCL built-in kernels. |
| 24 | + |
| 25 | +Builtin-kernels can be created explicitly via a new method in the program class, `create_from_built_in_kernel` and then |
| 26 | +used later on from the kernel object, or can be used implicitly with a explicit dispatch function. |
| 27 | + |
| 28 | +In addition, this vendor extension enables further vendor extensions to create SYCL headers that expose a C++ interface |
| 29 | +to the built-in kernels, enabling compile-time checking of parameters. |
| 30 | + |
| 31 | +## Outside of the scope of this extension |
| 32 | + |
| 33 | +* Host emulation of built-in kernels |
| 34 | +* Methods to check whether if the program class has builtin kernels or not |
| 35 | + |
| 36 | +## Revisions |
| 37 | + |
| 38 | +This is the first revision of this extension. |
| 39 | + |
| 40 | +## Interface changes |
| 41 | + |
| 42 | +### Program class |
| 43 | + |
| 44 | +The program class is extended with a new method, `create_from_built_in_kernel`, |
| 45 | +which internally uses the relevant low-level API call(s) to create a valid program object for the devices associated with the instance of the program. |
| 46 | +Built-in kernels do not require a building stage, so the program state is immediately set to executable. |
| 47 | + |
| 48 | +Built-in kernels are not available on the host-device, and will raise `cl::sycl::invalid_context` exception when calling the method on a host context. |
| 49 | + |
| 50 | +A program that contains other kernels cannot be mixed with built in kernels, this would raise a `cl::sycl::compile_program_error` exception. |
| 51 | +Similarly, building, compiling or linking a program created from built-in kernels raises `cl::sycl::invalid_object` exception. |
| 52 | + |
| 53 | + |
| 54 | +## Example |
| 55 | + |
| 56 | +The complete example can be found in the ComputeCPP SDK, the relevant parts are highlighted below: |
| 57 | + |
| 58 | +```cpp |
| 59 | + { |
| 60 | + buffer<float, 1> buf(&input, range<1>(1)); |
| 61 | + buffer<float, 1> bufOut(range<1>(1)); |
| 62 | + bufOut.set_final_data(&output); |
| 63 | + |
| 64 | + program syclProgram(testContext); |
| 65 | + |
| 66 | + syclProgram.create_from_built_in_kernel(kBuiltinKernelName); |
| 67 | + |
| 68 | + auto kernelC = syclProgram.get_kernel(kBuiltinKernelName); |
| 69 | + |
| 70 | + testQueue.submit([&](handler& cgh) { |
| 71 | + auto accIn = buf.get_access<access::mode::read>(cgh); |
| 72 | + auto accOut = bufOut.get_access<access::mode::write>(cgh); |
| 73 | + |
| 74 | + cgh.set_arg(0, accIn); |
| 75 | + cgh.set_arg(1, accOut); |
| 76 | + |
| 77 | + auto myRange = range<1>{1}; |
| 78 | + cgh.parallel_for(myRange, kernelC); |
| 79 | + }); |
| 80 | + } |
| 81 | +``` |
| 82 | +
|
| 83 | +## References |
| 84 | +
|
| 85 | +* SYCL 1.2.1 specification |
| 86 | +* OpenCL 1.2 specification |
0 commit comments