Skip to content

Commit d32da99

Browse files
authored
[SYCL] Introduce the Level Zero plugin (#1718)
Plugin itself consists of the header and the source file plus cmake file to build the plugin. Also the following changes were made to suport the Level Zero plugin in SYCL RT: * New level0 value was added to the backend enum * New PI_LEVEL0 value support was added to the SYCL_BE config. * Docs were updated. Mentioned Level Zero backend and provided the link to the Level Zero runtime for Intel GPU. * Changes in sycl cmake file to build Level Zero plugin by default and to install it with sycl toolchain. LIT testing with PI_LEVEL0 backend will be enabled in the following commits. This commits introduces the plugin and makes it buildable. Signed-off-by: Artur Gainullin [email protected]
1 parent d40e3eb commit d32da99

File tree

17 files changed

+4204
-17
lines changed

17 files changed

+4204
-17
lines changed

buildbot/configure.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,14 @@ def do_configure(args):
8282
"-DOpenCL_INCLUDE_DIR={}".format(ocl_header_dir),
8383
"-DOpenCL_LIBRARY={}".format(icd_loader_lib)])
8484

85+
if args.l0_headers and args.l0_loader:
86+
cmake_cmd.extend([
87+
"-DL0_INCLUDE_DIR={}".format(args.l0_headers),
88+
"-DL0_LIBRARY={}".format(args.l0_loader)])
89+
elif args.l0_headers or args.l0_loader:
90+
sys.exit("Please specify both Level Zero headers and loader or don't specify "
91+
"none of them to let download from github.com")
92+
8593
# Add additional CMake options if provided
8694
if args.cmake_opt:
8795
cmake_cmd += args.cmake_opt
@@ -115,6 +123,8 @@ def main():
115123
# User options
116124
parser.add_argument("-s", "--src-dir", metavar="SRC_DIR", help="source directory (autodetected by default)")
117125
parser.add_argument("-o", "--obj-dir", metavar="OBJ_DIR", help="build directory. (<src>/build by default)")
126+
parser.add_argument("--l0-headers", metavar="L0_HEADER_DIR", help="directory with Level Zero headers")
127+
parser.add_argument("--l0-loader", metavar="L0_LOADER", help="path to the Level Zero loader")
118128
parser.add_argument("-t", "--build-type",
119129
metavar="BUILD_TYPE", default="Release", help="build type: Debug, Release")
120130
parser.add_argument("--cuda", action='store_true', help="switch from OpenCL to CUDA")

buildbot/dependency.conf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
ocl_cpu_rt_ver=2020.10.4.0.15
44
# https://github.com/intel/llvm/releases/download/2020-03/win-oclcpuexp-2020.10.4.0.15_rel.zip
55
ocl_cpu_rt_ver_win=2020.10.4.0.15
6+
# Same GPU driver supports Level Zero and OpenCL:
67
# https://github.com/intel/compute-runtime/releases/tag/20.19.16754
78
ocl_gpu_rt_ver=20.19.16754
9+
# Same GPU driver supports Level Zero and OpenCL:
810
# https://downloadcenter.intel.com/download/29557/Intel-Graphics-Windows-10-DCH-Drivers
911
ocl_gpu_rt_ver_win=ci-neo-015900
1012
intel_sycl_ver=build

sycl/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,7 @@ set( SYCL_TOOLCHAIN_DEPLOY_COMPONENTS
305305
sycl-headers-extras
306306
sycl
307307
pi_opencl
308+
pi_level0
308309
libsycldevice
309310
)
310311
if(OpenCL_INSTALL_KHRONOS_ICD_LOADER AND TARGET ocl-icd)

sycl/doc/EnvironmentVariables.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ subject to change. Do not rely on these variables in production code.
1212
| Environment variable | Values | Description |
1313
| -------------------- | ------ | ----------- |
1414
| SYCL_PI_TRACE | Described [below](#sycl_pi_trace-options) | Enable specified level of tracing for PI. |
15-
| SYCL_BE | PI_OPENCL, PI_CUDA | Force SYCL RT to consider only devices of the specified backend during the device selection. |
15+
| SYCL_BE | PI_OPENCL, PI_LEVEL0, PI_CUDA | Force SYCL RT to consider only devices of the specified backend during the device selection. |
1616
| SYCL_DEVICE_TYPE | One of: CPU, GPU, ACC, HOST | Force SYCL to use the specified device type. If unset, default selection rules are applied. If set to any unlisted value, this control has no effect. If the requested device type is not found, a `cl::sycl::runtime_error` exception is thrown. If a non-default device selector is used, a device must satisfy both the selector and this control to be chosen. This control only has effect on devices created with a selector. |
1717
| SYCL_PROGRAM_COMPILE_OPTIONS | String of valid OpenCL compile options | Override compile options for all programs. |
1818
| SYCL_PROGRAM_LINK_OPTIONS | String of valid OpenCL link options | Override link options for all programs. |

sycl/doc/GetStartedGuide.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,12 @@ which contains all the symbols required.
161161
To run DPC++ applications on OpenCL devices, OpenCL implementation(s) must be
162162
present in the system.
163163

164-
The OpenCL RT for `GPU`, OpenCL RT for `CPU` and TBB runtime which are needed
165-
to run DPC++ application on Intel `GPU` or Intel `CPU` devices can be
164+
To run DPC++ applications on Level Zero devices, Level Zero implementation(s)
165+
must be present in the system. You can find the link to the Level Zero spec in
166+
the following section [Find More](#find-more).
167+
168+
The Level Zero RT for `GPU`, OpenCL RT for `GPU`, OpenCL RT for `CPU` and TBB runtime
169+
which are needed to run DPC++ application on Intel `GPU` or Intel `CPU` devices can be
166170
downloaded using links in
167171
[the dependency configuration file](../../buildbot/dependency.conf)
168172
and installed following the instructions below. The same versions are used in
@@ -551,5 +555,7 @@ class CUDASelector : public cl::sycl::device_selector {
551555
[https://spec.oneapi.com/versions/latest/elements/dpcpp/source/index.html](https://spec.oneapi.com/versions/latest/elements/dpcpp/source/index.html)
552556
* SYCL\* 1.2.1 specification:
553557
[www.khronos.org/registry/SYCL/specs/sycl-1.2.1.pdf](https://www.khronos.org/registry/SYCL/specs/sycl-1.2.1.pdf)
558+
* oneAPI Level Zero specification:
559+
[https://spec.oneapi.com/versions/latest/oneL0/index.html](https://spec.oneapi.com/versions/latest/oneL0/index.html)
554560
555561
\*Other names and brands may be claimed as the property of others.

sycl/include/CL/sycl/backend_types.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
__SYCL_INLINE_NAMESPACE(cl) {
1414
namespace sycl {
1515

16-
enum class backend { host, opencl, cuda };
16+
enum class backend : char { host, opencl, level0, cuda };
1717

1818
template <backend name, typename SYCLObjectT> struct interop;
1919

sycl/include/CL/sycl/detail/pi.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,11 @@ bool trace(TraceLevel level);
5757

5858
#ifdef SYCL_RT_OS_WINDOWS
5959
#define OPENCL_PLUGIN_NAME "pi_opencl.dll"
60+
#define LEVEL0_PLUGIN_NAME "pi_level0.dll"
6061
#define CUDA_PLUGIN_NAME "pi_cuda.dll"
6162
#else
6263
#define OPENCL_PLUGIN_NAME "libpi_opencl.so"
64+
#define LEVEL0_PLUGIN_NAME "libpi_level0.so"
6365
#define CUDA_PLUGIN_NAME "libpi_cuda.so"
6466
#endif
6567

sycl/plugins/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ if(SYCL_BUILD_PI_CUDA)
55
endif()
66

77
add_subdirectory(opencl)
8+
add_subdirectory(level_zero)
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
# PI Level0 plugin library
2+
3+
if (NOT DEFINED L0_LIBRARY OR NOT DEFINED L0_INCLUDE_DIR)
4+
message(STATUS "Download Level Zero loader and headers from github.com")
5+
if(MSVC)
6+
set(L0_LIBRARY
7+
"${LLVM_LIBRARY_OUTPUT_INTDIR}/${CMAKE_STATIC_LIBRARY_PREFIX}ze_loader${CMAKE_STATIC_LIBRARY_SUFFIX}")
8+
else()
9+
set(L0_LIBRARY
10+
"${LLVM_LIBRARY_OUTPUT_INTDIR}/${CMAKE_SHARED_LIBRARY_PREFIX}ze_loader${CMAKE_SHARED_LIBRARY_SUFFIX}")
11+
endif()
12+
if (CMAKE_C_COMPILER)
13+
list(APPEND AUX_CMAKE_FLAGS -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER})
14+
endif()
15+
if (CMAKE_CXX_COMPILER)
16+
list(APPEND AUX_CMAKE_FLAGS -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER})
17+
endif()
18+
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/l0_loader_build)
19+
ExternalProject_Add(l0-loader
20+
GIT_REPOSITORY https://github.com/oneapi-src/level-zero.git
21+
GIT_TAG origin/master
22+
SOURCE_DIR "${CMAKE_CURRENT_BINARY_DIR}/Level0/l0_loader"
23+
BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/l0_loader_build"
24+
INSTALL_DIR "${CMAKE_CURRENT_BINARY_DIR}/l0_loader_install"
25+
CMAKE_ARGS -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
26+
-DCMAKE_MAKE_PROGRAM=${CMAKE_MAKE_PROGRAM}
27+
-DOpenCL_INCLUDE_DIR=${OpenCL_INCLUDE_DIRS}
28+
-DCMAKE_INSTALL_PREFIX=<INSTALL_DIR>
29+
-DCMAKE_INSTALL_LIBDIR:PATH=lib${LLVM_LIBDIR_SUFFIX}
30+
${AUX_CMAKE_FLAGS}
31+
STEP_TARGETS configure,build,install
32+
DEPENDS ocl-headers
33+
BUILD_BYPRODUCTS ${L0_LIBRARY}
34+
)
35+
ExternalProject_Add_Step(l0-loader llvminstall
36+
COMMAND ${CMAKE_COMMAND} -E copy_directory <INSTALL_DIR>/ ${LLVM_BINARY_DIR}
37+
COMMENT "Installing l0-loader into the LLVM binary directory"
38+
DEPENDEES install
39+
)
40+
41+
install(DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/l0_loader_install/"
42+
DESTINATION "."
43+
COMPONENT l0-loader
44+
)
45+
46+
list(APPEND SYCL_TOOLCHAIN_DEPLOY_COMPONENTS l0-loader)
47+
else()
48+
include_directories("${L0_INCLUDE_DIR}")
49+
endif()
50+
51+
include_directories("${sycl_inc_dir}")
52+
include_directories(${OPENCL_INCLUDE})
53+
54+
add_library(pi_level0 SHARED
55+
"${sycl_inc_dir}/CL/sycl/detail/pi.h"
56+
"${CMAKE_CURRENT_SOURCE_DIR}/pi_level0.cpp"
57+
"${CMAKE_CURRENT_SOURCE_DIR}/pi_level0.hpp"
58+
)
59+
60+
if (MSVC)
61+
# by defining __SYCL_BUILD_SYCL_DLL, we can use __declspec(dllexport)
62+
# which are individually tagged for all pi* symbols in pi.h
63+
target_compile_definitions(pi_level0 PRIVATE __SYCL_BUILD_SYCL_DLL)
64+
else()
65+
# we set the visibility of all symbols 'hidden' by default.
66+
# In pi.h file, we set exported symbols with visibility==default individually
67+
target_compile_options(pi_level0 PUBLIC -fvisibility=hidden)
68+
69+
# This script file is used to allow exporting pi* symbols only.
70+
# All other symbols are regarded as local (hidden)
71+
set(linker_script "${CMAKE_CURRENT_SOURCE_DIR}/../ld-version-script.txt")
72+
73+
# Filter symbols based on the scope defined in the script file,
74+
# and export pi* function symbols in the library.
75+
target_link_libraries( pi_level0
76+
PRIVATE "-Wl,--version-script=${linker_script}"
77+
)
78+
endif()
79+
80+
if (TARGET l0-loader)
81+
add_dependencies(pi_level0 l0-loader)
82+
endif()
83+
add_dependencies(sycl-toolchain pi_level0)
84+
85+
target_link_libraries(pi_level0 PRIVATE "${L0_LIBRARY}")
86+
if (UNIX)
87+
target_link_libraries(pi_level0 PRIVATE pthread)
88+
endif()
89+
90+
add_common_options(pi_level0)
91+
92+
install(TARGETS pi_level0
93+
LIBRARY DESTINATION "lib" COMPONENT pi_level0
94+
RUNTIME DESTINATION "bin" COMPONENT pi_level0)

0 commit comments

Comments
 (0)