Skip to content

Commit de83f29

Browse files
Ver 1: Add sm_* offload arch support to DPCTL_TARGET_CUDA
1 parent bae5f3d commit de83f29

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

CMakeLists.txt

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,10 @@ option(DPCTL_GENERATE_COVERAGE_FOR_PYBIND11_EXTENSIONS
2525
"Build dpctl pybind11 offloading extensions with coverage instrumentation"
2626
OFF
2727
)
28-
option(DPCTL_TARGET_CUDA
29-
"Build DPCTL to target CUDA devices"
30-
OFF
28+
set(DPCTL_TARGET_CUDA
29+
""
30+
CACHE STRING
31+
"Build DPCTL to target CUDA devices. Set to ON to use default architecture (sm_50), or to a specific architecture like sm_80."
3132
)
3233
set(DPCTL_TARGET_HIP
3334
""
@@ -51,9 +52,20 @@ set(_dpctl_sycl_target_compile_options)
5152
set(_dpctl_sycl_target_link_options)
5253

5354
set(_dpctl_sycl_targets)
55+
set(_dpctl_cuda_arch)
5456
set(_dpctl_amd_targets)
5557
if ("x${DPCTL_SYCL_TARGETS}" STREQUAL "x")
56-
if (DPCTL_TARGET_CUDA)
58+
if (NOT "x${DPCTL_TARGET_CUDA}" STREQUAL "x")
59+
if (DPCTL_TARGET_CUDA STREQUAL "ON")
60+
set(_dpctl_cuda_arch "sm_50")
61+
elseif(DPCTL_TARGET_CUDA MATCHES "^sm_")
62+
set(_dpctl_cuda_arch ${DPCTL_TARGET_CUDA})
63+
else()
64+
message(FATAL_ERROR
65+
"Invalid value for DPCTL_TARGET_CUDA: \"${DPCTL_TARGET_CUDA}\". "
66+
"Expected 'ON' or an architecture like 'sm_80'."
67+
)
68+
endif()
5769
set(_dpctl_sycl_targets "nvptx64-nvidia-cuda,spir64-unknown-unknown")
5870
endif()
5971
if (NOT "x${DPCTL_TARGET_HIP}" STREQUAL "x")
@@ -88,6 +100,10 @@ if (_dpctl_sycl_targets)
88100
message(STATUS "Compiling for -fsycl-targets=${_dpctl_sycl_targets}")
89101
list(APPEND _dpctl_sycl_target_compile_options -fsycl-targets=${_dpctl_sycl_targets})
90102
list(APPEND _dpctl_sycl_target_link_options -fsycl-targets=${_dpctl_sycl_targets})
103+
if (_dpctl_cuda_arch)
104+
list(APPEND _dpctl_sycl_target_compile_options -Xsycl-target-backend=nvptx64-nvidia-cuda --offload-arch=${_dpctl_cuda_arch})
105+
list(APPEND _dpctl_sycl_target_link_options -Xsycl-target-backend=nvptx64-nvidia-cuda --offload-arch=${_dpctl_cuda_arch})
106+
endif()
91107
if(_dpctl_amd_targets)
92108
list(APPEND _dpctl_sycl_target_compile_options -Xsycl-target-backend=amdgcn-amd-amdhsa --offload-arch=${_dpctl_amd_targets})
93109
list(APPEND _dpctl_sycl_target_link_options -Xsycl-target-backend=amdgcn-amd-amdhsa --offload-arch=${_dpctl_amd_targets})

0 commit comments

Comments
 (0)