Skip to content
This repository was archived by the owner on Mar 28, 2023. It is now read-only.

Commit 3769374

Browse files
[SYCL][CUDA] Add cuda_dev_kit feature (#1056)
These changes add a cuda_dev_kit feature check for detecting availability of a CUDA SDK. CUDA include path and library path can be controlled through the new CUDA_INCLUDE and CUDA_LIBS_DIR variables. Signed-off-by: Larsen, Steffen <[email protected]>
1 parent 773b61e commit 3769374

File tree

4 files changed

+37
-2
lines changed

4 files changed

+37
-2
lines changed

SYCL/Plugin/interop-cuda-experimental.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
// REQUIRES: cuda
1+
// REQUIRES: cuda && cuda_dev_kit
22

3-
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple -lcuda %s -o %t.out
3+
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %cuda_options %s -o %t.out
44
// RUN: %GPU_RUN_PLACEHOLDER %t.out
55

66
#define SYCL_EXT_ONEAPI_BACKEND_CUDA_EXPERIMENTAL 1

SYCL/README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,10 @@ at the full path specified by this variable.
123123

124124
***LEVEL_ZERO_LIBS_DIR*** - path to Level Zero libraries.
125125

126+
***CUDA_INCLUDE*** - path to CUDA headers.
127+
128+
***CUDA_LIBS_DIR*** - path to CUDA libraries.
129+
126130
***HIP_PLATFORM*** - platform selection for HIP targeted devices.
127131
Defaults to AMD if no value is given. Supported values are:
128132
- **AMD** - for HIP to target AMD GPUs
@@ -163,6 +167,7 @@ unavailable.
163167
* **aot_tool** - Ahead-of-time compilation tools availability;
164168
* **ocloc**, **opencl-aot** - Specific AOT tool availability;
165169
* **level_zero_dev_kit** - Level_Zero headers and libraries availability;
170+
* **cuda_dev_kit** - CUDA SDK headers and libraries availability;
166171
* **gpu-intel-gen9** - Intel GPU Gen9 availability;
167172
* **gpu-intel-gen11** - Intel GPU Gen11 availability;
168173
* **gpu-intel-gen12** - Intel GPU Gen12 availability;
@@ -207,6 +212,10 @@ configure specific single test execution in the command line:
207212
can be also set by CMake variable LEVEL_ZERO_INCLUDE.
208213
* **level_zero_libs_dir** - directory containing Level_Zero native libraries,
209214
can be also set by CMake variable LEVEL_ZERO_LIBS_DIR.
215+
* **cuda_include** - directory containing CUDA SDK headers, can be also set by
216+
CMake variable CUDA_INCLUDE.
217+
* **cuda_libs_dir** - directory containing CUDA SDK libraries, can be also set
218+
by CMake variable CUDA_LIBS_DIR.
210219

211220
Example:
212221

SYCL/lit.cfg.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@
131131
cl_options=True
132132
config.available_features.add('cl_options')
133133

134+
# Check for Level Zero SDK
134135
check_l0_file='l0_include.cpp'
135136
with open(check_l0_file, 'w') as fp:
136137
fp.write('#include<level_zero/ze_api.h>\n')
@@ -152,6 +153,29 @@
152153
else:
153154
config.substitutions.append( ('%level_zero_options', '') )
154155

156+
# Check for CUDA SDK
157+
check_cuda_file='cuda_include.cpp'
158+
with open(check_cuda_file, 'w') as fp:
159+
fp.write('#include <cuda.h>\n')
160+
fp.write('int main() { CUresult r = cuInit(0); return r; }')
161+
162+
config.cuda_libs_dir=lit_config.params.get("cuda_libs_dir", config.cuda_libs_dir)
163+
config.cuda_include=lit_config.params.get("cuda_include", (config.cuda_include if config.cuda_include else config.sycl_include))
164+
165+
cuda_options=cuda_options = (' -L'+config.cuda_libs_dir if config.cuda_libs_dir else '')+' -lcuda '+' -I'+config.cuda_include
166+
if cl_options:
167+
cuda_options = ' '+( config.cuda_libs_dir+'/cuda.lib ' if config.cuda_libs_dir else 'cuda.lib')+' /I'+config.cuda_include
168+
169+
config.substitutions.append( ('%cuda_options', cuda_options) )
170+
171+
sp = subprocess.getstatusoutput(config.dpcpp_compiler+' -fsycl ' + check_cuda_file + cuda_options)
172+
if sp[0] == 0:
173+
config.available_features.add('cuda_dev_kit')
174+
config.substitutions.append( ('%cuda_options', cuda_options) )
175+
else:
176+
config.substitutions.append( ('%cuda_options', '') )
177+
178+
# Check for OpenCL ICD
155179
if config.opencl_libs_dir:
156180
if cl_options:
157181
config.substitutions.append( ('%opencl_lib', ' '+config.opencl_libs_dir+'/OpenCL.lib') )

SYCL/lit.site.cfg.py.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ config.sycl_libs_dir = os.path.join(config.dpcpp_root_dir, ('bin' if platform.s
1818
config.opencl_libs_dir = (os.path.dirname("@OpenCL_LIBRARY@") if "@OpenCL_LIBRARY@" else "")
1919
config.level_zero_libs_dir = "@LEVEL_ZERO_LIBS_DIR@"
2020
config.level_zero_include = "@LEVEL_ZERO_INCLUDE@"
21+
config.cuda_libs_dir = "@CUDA_LIBS_DIR@"
22+
config.cuda_include = "@CUDA_INCLUDE@"
2123

2224
config.opencl_include_dir = os.path.join(config.sycl_include, 'sycl')
2325
config.target_devices = lit_config.params.get("target_devices", "@SYCL_TARGET_DEVICES@")

0 commit comments

Comments
 (0)