|
| 1 | +//===---- dppl_sycl_program_interface.h - DPPL-SYCL interface --*--C++ --*--===// |
| 2 | +// |
| 3 | +// Python Data Parallel Processing Library (PyDPPL) |
| 4 | +// |
| 5 | +// Copyright 2020 Intel Corporation |
| 6 | +// |
| 7 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 | +// you may not use this file except in compliance with the License. |
| 9 | +// You may obtain a copy of the License at |
| 10 | +// |
| 11 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | +// |
| 13 | +// Unless required by applicable law or agreed to in writing, software |
| 14 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 15 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | +// See the License for the specific language governing permissions and |
| 17 | +// limitations under the License. |
| 18 | +// |
| 19 | +//===----------------------------------------------------------------------===// |
| 20 | +/// |
| 21 | +/// \file |
| 22 | +/// This header declares a C API to create Sycl program an interoperability |
| 23 | +/// program defined in OpenCL. In future, API to create interoperability |
| 24 | +/// kernels from other languages such as Level-0 driver API may be added here. |
| 25 | +/// |
| 26 | +/// \todo Investigate what we should do when we add support for Level-0 API. |
| 27 | +/// |
| 28 | +//===----------------------------------------------------------------------===// |
| 29 | + |
| 30 | +#pragma once |
| 31 | + |
| 32 | +#include "dppl_data_types.h" |
| 33 | +#include "dppl_sycl_types.h" |
| 34 | +#include "Support/DllExport.h" |
| 35 | +#include "Support/ExternC.h" |
| 36 | +#include "Support/MemOwnershipAttrs.h" |
| 37 | + |
| 38 | +DPPL_C_EXTERN_C_BEGIN |
| 39 | + |
| 40 | +/*! |
| 41 | + * @brief Create a Sycl program from an OpenCL SPIR-V binary file. |
| 42 | + * |
| 43 | + * Sycl 1.2 does not expose any method to create a sycl::program from a SPIR-V |
| 44 | + * IL file. To get around this limitation, we need to use the Sycl feature to |
| 45 | + * create an interoperability kernel from an OpenCL kernel. This function first |
| 46 | + * creates an OpenCL program and kernel from the SPIR-V binary and then using |
| 47 | + * the Sycl-OpenCL interoperability feature creates a Sycl kernel from the |
| 48 | + * OpenCL kernel. |
| 49 | + * |
| 50 | + * The feature to create a Sycl kernel from a SPIR-V IL binary will be available |
| 51 | + * in Sycl 2.0 at which point this function may become deprecated. |
| 52 | + * |
| 53 | + * @param Ctx An opaque pointer to a sycl::context |
| 54 | + * @param IL SPIR-V binary |
| 55 | + * @return A new SyclProgramRef pointer if the program creation succeeded, |
| 56 | + * else returns NULL. |
| 57 | + */ |
| 58 | +DPPL_API |
| 59 | +__dppl_give DPPLSyclProgramRef |
| 60 | +DPPLProgram_CreateFromOCLSpirv (__dppl_keep const DPPLSyclContextRef Ctx, |
| 61 | + __dppl_keep const void *IL, |
| 62 | + size_t Length); |
| 63 | + |
| 64 | +/*! |
| 65 | + * @brief Create a Sycl program from an OpenCL kernel source string. |
| 66 | + * |
| 67 | + * @param Ctx An opaque pointer to a sycl::context |
| 68 | + * @param Source OpenCL source string |
| 69 | + * @param CompileOptions Extra compiler flags (refer Sycl spec.) |
| 70 | + * @return A new SyclProgramRef pointer if the program creation succeeded, |
| 71 | + * else returns NULL. |
| 72 | + */ |
| 73 | +DPPL_API |
| 74 | +__dppl_give DPPLSyclProgramRef |
| 75 | +DPPLProgram_CreateFromOCLSource (__dppl_keep const DPPLSyclContextRef Ctx, |
| 76 | + __dppl_keep const char *Source, |
| 77 | + __dppl_keep const char *CompileOpts = nullptr); |
| 78 | + |
| 79 | +/*! |
| 80 | + * @brief Returns the SyclKernel with given name from the program, if not found |
| 81 | + * then return NULL. |
| 82 | + * |
| 83 | + * @param PRef Opaque pointer to a sycl::program |
| 84 | + * @param KernelName Name of kernel |
| 85 | + * @return A SyclKernel reference if the kernel exists, else NULL |
| 86 | + */ |
| 87 | +DPPL_API |
| 88 | +__dppl_give DPPLSyclKernelRef |
| 89 | +DPPLProgram_GetKernel (__dppl_keep DPPLSyclProgramRef PRef, |
| 90 | + __dppl_keep const char *KernelName); |
| 91 | + |
| 92 | +/*! |
| 93 | + * @brief Return True if a SyclKernel with given name exists in the program, if |
| 94 | + * not found then returns False. |
| 95 | + * |
| 96 | + * @param PRef Opaque pointer to a sycl::program |
| 97 | + * @param KernelName Name of kernel |
| 98 | + * @return True if the kernel exists, else False |
| 99 | + */ |
| 100 | +DPPL_API |
| 101 | +bool |
| 102 | +DPPLProgram_HasKernel (__dppl_keep DPPLSyclProgramRef PRef, |
| 103 | + __dppl_keep const char *KernelName); |
| 104 | + |
| 105 | +/*! |
| 106 | + * @brief Frees the DPPLSyclProgramRef pointer. |
| 107 | + * |
| 108 | + * @param PRef Opaque pointer to a sycl::program |
| 109 | + */ |
| 110 | +DPPL_API |
| 111 | +void |
| 112 | +DPPLProgram_Delete (__dppl_take DPPLSyclProgramRef PRef); |
| 113 | + |
| 114 | +DPPL_C_EXTERN_C_END |
0 commit comments