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

[SYCL][CUDA] Add cuda_dev_kit feature #1056

Merged
merged 2 commits into from
Jun 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions SYCL/Plugin/interop-cuda-experimental.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// REQUIRES: cuda
// REQUIRES: cuda && cuda_dev_kit

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

#define SYCL_EXT_ONEAPI_BACKEND_CUDA_EXPERIMENTAL 1
Expand Down
9 changes: 9 additions & 0 deletions SYCL/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@ at the full path specified by this variable.

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

***CUDA_INCLUDE*** - path to CUDA headers.

***CUDA_LIBS_DIR*** - path to CUDA libraries.

***HIP_PLATFORM*** - platform selection for HIP targeted devices.
Defaults to AMD if no value is given. Supported values are:
- **AMD** - for HIP to target AMD GPUs
Expand Down Expand Up @@ -163,6 +167,7 @@ unavailable.
* **aot_tool** - Ahead-of-time compilation tools availability;
* **ocloc**, **opencl-aot** - Specific AOT tool availability;
* **level_zero_dev_kit** - Level_Zero headers and libraries availability;
* **cuda_dev_kit** - CUDA SDK headers and libraries availability;
* **gpu-intel-gen9** - Intel GPU Gen9 availability;
* **gpu-intel-gen11** - Intel GPU Gen11 availability;
* **gpu-intel-gen12** - Intel GPU Gen12 availability;
Expand Down Expand Up @@ -207,6 +212,10 @@ configure specific single test execution in the command line:
can be also set by CMake variable LEVEL_ZERO_INCLUDE.
* **level_zero_libs_dir** - directory containing Level_Zero native libraries,
can be also set by CMake variable LEVEL_ZERO_LIBS_DIR.
* **cuda_include** - directory containing CUDA SDK headers, can be also set by
CMake variable CUDA_INCLUDE.
* **cuda_libs_dir** - directory containing CUDA SDK libraries, can be also set
by CMake variable CUDA_LIBS_DIR.

Example:

Expand Down
24 changes: 24 additions & 0 deletions SYCL/lit.cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@
cl_options=True
config.available_features.add('cl_options')

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

# Check for CUDA SDK
check_cuda_file='cuda_include.cpp'
with open(check_cuda_file, 'w') as fp:
fp.write('#include <cuda.h>\n')
fp.write('int main() { CUresult r = cuInit(0); return r; }')

config.cuda_libs_dir=lit_config.params.get("cuda_libs_dir", config.cuda_libs_dir)
config.cuda_include=lit_config.params.get("cuda_include", (config.cuda_include if config.cuda_include else config.sycl_include))

cuda_options=cuda_options = (' -L'+config.cuda_libs_dir if config.cuda_libs_dir else '')+' -lcuda '+' -I'+config.cuda_include
if cl_options:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be cl_options if this is for cuda?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Level zero uses this too. Seems like an obfuscated way of determining if it is on Windows.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, many thanks for clarifying.

cuda_options = ' '+( config.cuda_libs_dir+'/cuda.lib ' if config.cuda_libs_dir else 'cuda.lib')+' /I'+config.cuda_include

config.substitutions.append( ('%cuda_options', cuda_options) )

sp = subprocess.getstatusoutput(config.dpcpp_compiler+' -fsycl ' + check_cuda_file + cuda_options)
if sp[0] == 0:
config.available_features.add('cuda_dev_kit')
config.substitutions.append( ('%cuda_options', cuda_options) )
else:
config.substitutions.append( ('%cuda_options', '') )

# Check for OpenCL ICD
if config.opencl_libs_dir:
if cl_options:
config.substitutions.append( ('%opencl_lib', ' '+config.opencl_libs_dir+'/OpenCL.lib') )
Expand Down
2 changes: 2 additions & 0 deletions SYCL/lit.site.cfg.py.in
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ config.sycl_libs_dir = os.path.join(config.dpcpp_root_dir, ('bin' if platform.s
config.opencl_libs_dir = (os.path.dirname("@OpenCL_LIBRARY@") if "@OpenCL_LIBRARY@" else "")
config.level_zero_libs_dir = "@LEVEL_ZERO_LIBS_DIR@"
config.level_zero_include = "@LEVEL_ZERO_INCLUDE@"
config.cuda_libs_dir = "@CUDA_LIBS_DIR@"
config.cuda_include = "@CUDA_INCLUDE@"

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