Skip to content

Commit 6f7cd95

Browse files
authored
[SYCL][CUDA] Fix LIT testing with CUDA devices (#1300)
Build the `get_device_count_by_type` tool with the required preprocessor definitions to enable CUDA, and link with CUDA. Pass correct backend name to the `get_device_count_by_type` tool that is required to run tests with PI OpenCL instead of PI CUDA. Clean up the `get_device_count_by_type` tool code to make it harder to call it with the wrong backend and get unexpected query results back. Signed-off-by: Bjoern Knafla <[email protected]>
1 parent 2e19873 commit 6f7cd95

File tree

4 files changed

+213
-119
lines changed

4 files changed

+213
-119
lines changed

sycl/plugins/cuda/CMakeLists.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ message(STATUS "Including the PI API CUDA backend.")
66

77
find_package(CUDA 10.1 REQUIRED)
88

9-
add_library(cudadrv SHARED IMPORTED)
9+
# Make imported library global to use it within the project.
10+
add_library(cudadrv SHARED IMPORTED GLOBAL)
1011

1112
set_target_properties(
1213
cudadrv PROPERTIES

sycl/test/lit.cfg.py

+5-7
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
llvm_config.add_tool_substitutions(['llvm-spirv'], [config.sycl_tools_dir])
7070

7171
backend=lit_config.params.get('SYCL_BE', "PI_OPENCL")
72+
lit_config.note("Backend: {BACKEND}".format(BACKEND=backend))
7273

7374
get_device_count_by_type_path = os.path.join(config.llvm_tools_dir, "get_device_count_by_type")
7475

@@ -119,11 +120,11 @@ def getDeviceCount(device_type):
119120
if getDeviceCount("cpu")[0]:
120121
found_at_least_one_device = True
121122
lit_config.note("Found available CPU device")
122-
cpu_run_substitute = "env SYCL_DEVICE_TYPE=CPU "
123+
cpu_run_substitute = "env SYCL_DEVICE_TYPE=CPU SYCL_BE={SYCL_BE} ".format(SYCL_BE=backend)
123124
cpu_check_substitute = "| FileCheck %s"
124125
config.available_features.add('cpu')
125126
if platform.system() == "Linux":
126-
cpu_run_on_linux_substitute = "env SYCL_DEVICE_TYPE=CPU "
127+
cpu_run_on_linux_substitute = "env SYCL_DEVICE_TYPE=CPU SYCL_BE={SYCL_BE} ".format(SYCL_BE=backend)
127128
cpu_check_on_linux_substitute = "| FileCheck %s"
128129
else:
129130
lit_config.warning("CPU device not found")
@@ -144,18 +145,15 @@ def getDeviceCount(device_type):
144145
if gpu_count > 0:
145146
found_at_least_one_device = True
146147
lit_config.note("Found available GPU device")
147-
gpu_run_substitute = " env SYCL_DEVICE_TYPE=GPU "
148+
gpu_run_substitute = " env SYCL_DEVICE_TYPE=GPU SYCL_BE={SYCL_BE} ".format(SYCL_BE=backend)
148149
gpu_check_substitute = "| FileCheck %s"
149150
config.available_features.add('gpu')
150151
if cuda:
151152
config.available_features.add('cuda')
152-
gpu_run_substitute += " SYCL_BE=PI_CUDA "
153153

154154
if platform.system() == "Linux":
155-
gpu_run_on_linux_substitute = "env SYCL_DEVICE_TYPE=GPU "
155+
gpu_run_on_linux_substitute = "env SYCL_DEVICE_TYPE=GPU SYCL_BE={SYCL_BE} ".format(SYCL_BE=backend)
156156
gpu_check_on_linux_substitute = "| FileCheck %s"
157-
if cuda:
158-
gpu_run_on_linux_substitute += " SYCL_BE=PI_CUDA "
159157
else:
160158
lit_config.warning("GPU device not found")
161159

sycl/tools/CMakeLists.txt

+15-31
Original file line numberDiff line numberDiff line change
@@ -5,45 +5,29 @@ set(CMAKE_CXX_EXTENSIONS OFF)
55
add_executable(get_device_count_by_type get_device_count_by_type.cpp)
66
add_dependencies(get_device_count_by_type ocl-headers ocl-icd)
77

8-
if( SYCL_BUILD_PI_CUDA )
9-
find_package(CUDA 10.1 REQUIRED)
10-
11-
add_library(cudadrv SHARED IMPORTED)
12-
13-
set_target_properties(
14-
cudadrv PROPERTIES
15-
IMPORTED_LOCATION ${CUDA_CUDA_LIBRARY}
16-
INTERFACE_INCLUDE_DIRECTORIES ${CUDA_INCLUDE_DIRS}
17-
)
18-
19-
target_compile_definitions(get_device_count_by_type
20-
PUBLIC $<$<BOOL:${SYCL_BUILD_PI_CUDA}>:USE_PI_CUDA>
21-
)
22-
23-
target_include_directories( get_device_count_by_type
24-
PUBLIC
25-
${CUDA_INCLUDE_DIRS}
26-
)
27-
target_link_libraries(get_device_count_by_type
28-
PUBLIC OpenCL-Headers cudadrv
29-
)
30-
endif()
31-
328
target_link_libraries(get_device_count_by_type
33-
PRIVATE OpenCL::Headers
34-
PRIVATE ${OpenCL_LIBRARIES}
9+
PRIVATE
10+
OpenCL::Headers
11+
${OpenCL_LIBRARIES}
12+
$<$<BOOL:${SYCL_BUILD_PI_CUDA}>:cudadrv>
13+
)
14+
target_compile_definitions(get_device_count_by_type
15+
PRIVATE
16+
$<$<BOOL:${SYCL_BUILD_PI_CUDA}>:USE_PI_CUDA>
3517
)
3618

3719
add_executable(sycl-check sycl-check.cpp)
3820
add_dependencies(sycl-check sycl)
3921
target_include_directories(sycl-check PRIVATE "${sycl_inc_dir}")
4022
target_link_libraries(sycl-check
41-
PRIVATE sycl
42-
PRIVATE OpenCL::Headers
43-
PRIVATE ${OpenCL_LIBRARIES})
23+
PRIVATE
24+
sycl
25+
OpenCL::Headers
26+
${OpenCL_LIBRARIES})
4427

4528
#Minimum supported version of Intel's OCL GPU and CPU devices
4629
target_compile_definitions(sycl-check
47-
PRIVATE MIN_INTEL_OCL_GPU_VERSION=\"18.47.11882\"
48-
PRIVATE MIN_INTEL_OCL_CPU_VERSION=\"18.1.0.0901\",\"7.6.0.1202\"
30+
PRIVATE
31+
MIN_INTEL_OCL_GPU_VERSION=\"18.47.11882\"
32+
MIN_INTEL_OCL_CPU_VERSION=\"18.1.0.0901\",\"7.6.0.1202\"
4933
)

0 commit comments

Comments
 (0)