Skip to content

Commit 7f3b868

Browse files
Add support for events, programs, and kernel submission to dpctl. (#80)
* Add support for events, programs, and kernel submission to dpctl. * New dpctl C API wrappers for sycl::event, sycl::kernel and sycl::program. * Wrappers to create an OpenCL interoperability program from either string or SPIR-V IL files. * Support for submitting an interoperability kernel to a sycl::queue. We support using either a range or an nd_range to submit the kernel. * Event wait function is now exposed via the C API. * New test cases for the C API. * The dpctl Cython wrapper now supports program creation and kernel submission. * Other refactoring to standardize function names, attribute names, comments. * Fix windows build for dpctl. * Update .gitignore Add new line at end of file. * Minor cosmetic changes * Remove empty doxygen comment blocks * Fix indentation * Fix grammatical typos * Additional information is now printed when dpctl.dump is called. * Fix test cases so that kernels are not submitted to default queue. - The default queue points to a Level-0 device is Level-0 drivers are installed. However, we always compile our program for OpenCL and this causes a crash if the test kernels are submitted to the default queue. Fixing it by selecting the GPU:0 queue that is known to be an OpenCL device. A follow up commit will fix this in a proper way. * Add test files to package * Update dpctl/tests/__init__.py * Update dpctl/tests/test_sycl_kernel_submit.py * Update dpctl/tests/test_sycl_program.py * Fix comment. * Another comment was fixed. Co-authored-by: Sergey Pokhodenko <[email protected]> Co-authored-by: Sergey Pokhodenko <[email protected]>
1 parent 4400bdd commit 7f3b868

32 files changed

+2229
-127
lines changed

MANIFEST.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ include versioneer.py
22
recursive-include dpctl/include *.h *.hpp
33
include dpctl/*.pxd
44
include dpctl/*DPPL*Interface.*
5+
include dpctl/tests/input_files/*
56
global-exclude *.cpp

backends/CMakeLists.txt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,10 @@ add_library(
9898
SHARED
9999
source/dppl_sycl_context_interface.cpp
100100
source/dppl_sycl_device_interface.cpp
101+
source/dppl_sycl_event_interface.cpp
102+
source/dppl_sycl_kernel_interface.cpp
101103
source/dppl_sycl_platform_interface.cpp
104+
source/dppl_sycl_program_interface.cpp
102105
source/dppl_sycl_queue_interface.cpp
103106
source/dppl_sycl_queue_manager.cpp
104107
source/dppl_sycl_usm_interface.cpp
@@ -146,13 +149,12 @@ if(WIN32)
146149
)
147150
target_link_libraries(
148151
DPPLSyclInterface
149-
PRIVATE
150-
${DPCPP_ROOT}/lib/sycl.lib
152+
PRIVATE ${DPCPP_ROOT}/lib/sycl.lib
153+
PRIVATE ${DPCPP_ROOT}/lib/OpenCL.lib
151154
)
152155
target_link_libraries(
153156
DPPLOpenCLInterface
154-
PRIVATE
155-
${DPCPP_ROOT}/lib/OpenCL.lib
157+
PRIVATE ${DPCPP_ROOT}/lib/OpenCL.lib
156158
)
157159
endif()
158160

backends/dbg_build.sh

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ mkdir build
55
pushd build
66

77
INSTALL_PREFIX=`pwd`/../install
8+
rm -rf ${INSTALL_PREFIX}
89
export ONEAPI_ROOT=/opt/intel/oneapi
910
DPCPP_ROOT=${ONEAPI_ROOT}/compiler/latest/linux
1011
PYTHON_INC=`python -c "import distutils.sysconfig; \
@@ -24,9 +25,6 @@ cmake \
2425
-DGTEST_LIB_DIR=${CONDA_PREFIX}/lib \
2526
..
2627

27-
make V=1 -n -j 4
28-
make check
29-
make install
30-
28+
make V=1 -n -j 4 && make check && make install
3129

3230
popd
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
//===--- dppl_sycl_event_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 a sub-set of the sycl::event interface.
23+
///
24+
//===----------------------------------------------------------------------===//
25+
26+
#pragma once
27+
28+
#include "dppl_data_types.h"
29+
#include "dppl_sycl_types.h"
30+
#include "Support/DllExport.h"
31+
#include "Support/ExternC.h"
32+
#include "Support/MemOwnershipAttrs.h"
33+
34+
35+
DPPL_C_EXTERN_C_BEGIN
36+
37+
/*!
38+
* @brief C-API wrapper for sycl::event.wait.
39+
*
40+
* @param ERef An opaque DPPLSyclEventRef pointer on which to wait.
41+
*/
42+
DPPL_API
43+
void DPPLEvent_Wait (__dppl_keep DPPLSyclEventRef ERef);
44+
45+
/*!
46+
* @brief Deletes the DPPLSyclEventRef after casting it to a sycl::event.
47+
*
48+
* @param ERef An opaque DPPLSyclEventRef pointer that would be
49+
* freed.
50+
*/
51+
DPPL_API
52+
void
53+
DPPLEvent_Delete (__dppl_take DPPLSyclEventRef ERef);
54+
55+
DPPL_C_EXTERN_C_END
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
//===---- dppl_sycl_kernel_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 kernels from OpenCL kernels. In
23+
/// future, API to create interoperability kernels from other languages such as
24+
/// 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 Returns a C string for the kernel name.
42+
*
43+
* @param KRef DPPLSyclKernelRef pointer to an OpenCL
44+
* interoperability kernel.
45+
* @return If a kernel name exists then returns it as a C string, else
46+
* returns a nullptr.
47+
*/
48+
DPPL_API
49+
__dppl_give const char*
50+
DPPLKernel_GetFunctionName (__dppl_keep const DPPLSyclKernelRef KRef);
51+
52+
/*!
53+
* @brief Returns the number of arguments for the OpenCL kernel.
54+
*
55+
* @param KRef DPPLSyclKernelRef pointer to an OpenCL
56+
* interoperability kernel.
57+
* @return Returns the number of arguments for the OpenCL interoperability
58+
* kernel.
59+
*/
60+
DPPL_API
61+
size_t
62+
DPPLKernel_GetNumArgs (__dppl_keep const DPPLSyclKernelRef KRef);
63+
64+
/*!
65+
* @brief Deletes the DPPLSyclKernelRef after casting it to a sycl::kernel.
66+
*
67+
* @param KRef DPPLSyclKernelRef pointer to an OpenCL
68+
* interoperability kernel.
69+
*/
70+
DPPL_API
71+
void
72+
DPPLKernel_Delete (__dppl_take DPPLSyclKernelRef KRef);
73+
74+
DPPL_C_EXTERN_C_END
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
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

Comments
 (0)