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

Commit fbe6eb2

Browse files
committed
[SYCL][CUDA] Add cuda_dev_kit feature
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 1ca16ca commit fbe6eb2

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-dg1** - Intel GPU DG1 availability;
167172
* **gpu-intel-dg2** - Intel GPU DG2 availability;
168173
* **gpu-intel-pvc** - Intel GPU PVC availability;
@@ -204,6 +209,10 @@ configure specific single test execution in the command line:
204209
can be also set by CMake variable LEVEL_ZERO_INCLUDE.
205210
* **level_zero_libs_dir** - directory containing Level_Zero native libraries,
206211
can be also set by CMake variable LEVEL_ZERO_LIBS_DIR.
212+
* **cuda_include** - directory containing CUDA SDK headers, can be also set by
213+
CMake variable CUDA_INCLUDE.
214+
* **cuda_libs_dir** - directory containing CUDA SDK libraries, can be also set
215+
by CMake variable CUDA_LIBS_DIR.
207216

208217
Example:
209218

SYCL/lit.cfg.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@
124124
cl_options=True
125125
config.available_features.add('cl_options')
126126

127+
# Check for Level Zero SDK
127128
check_l0_file='l0_include.cpp'
128129
with open(check_l0_file, 'w') as fp:
129130
fp.write('#include<level_zero/ze_api.h>\n')
@@ -145,6 +146,29 @@
145146
else:
146147
config.substitutions.append( ('%level_zero_options', '') )
147148

149+
# Check for CUDA SDK
150+
check_cuda_file='cuda_include.cpp'
151+
with open(check_cuda_file, 'w') as fp:
152+
fp.write('#include <cuda.h>\n')
153+
fp.write('int main() { CUresult r = cuInit(0); return r; }')
154+
155+
config.cuda_libs_dir=lit_config.params.get("cuda_libs_dir", config.cuda_libs_dir)
156+
config.cuda_include=lit_config.params.get("cuda_include", (config.cuda_include if config.cuda_include else config.sycl_include))
157+
158+
cuda_options=cuda_options = (' -L'+config.cuda_libs_dir if config.cuda_libs_dir else '')+' -lcuda '+' -I'+config.cuda_include
159+
if cl_options:
160+
cuda_options = ' '+( config.cuda_libs_dir+'/cuda.lib ' if config.cuda_libs_dir else 'cuda.lib')+' /I'+config.cuda_include
161+
162+
config.substitutions.append( ('%cuda_options', cuda_options) )
163+
164+
sp = subprocess.getstatusoutput(config.dpcpp_compiler+' -fsycl ' + check_cuda_file + cuda_options)
165+
if sp[0] == 0:
166+
config.available_features.add('cuda_dev_kit')
167+
config.substitutions.append( ('%cuda_options', cuda_options) )
168+
else:
169+
config.substitutions.append( ('%cuda_options', '') )
170+
171+
# Check for OpenCL ICD
148172
if config.opencl_libs_dir:
149173
if cl_options:
150174
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)