Skip to content

[SYCL][CUDA] Fix LIT testing with CUDA devices #1300

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
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
3 changes: 2 additions & 1 deletion sycl/plugins/cuda/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ message(STATUS "Including the PI API CUDA backend.")

find_package(CUDA 10.1 REQUIRED)

add_library(cudadrv SHARED IMPORTED)
# Make imported library global to use it within the project.
add_library(cudadrv SHARED IMPORTED GLOBAL)

set_target_properties(
cudadrv PROPERTIES
Expand Down
12 changes: 5 additions & 7 deletions sycl/test/lit.cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
llvm_config.add_tool_substitutions(['llvm-spirv'], [config.sycl_tools_dir])

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

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

Expand Down Expand Up @@ -119,11 +120,11 @@ def getDeviceCount(device_type):
if getDeviceCount("cpu")[0]:
found_at_least_one_device = True
lit_config.note("Found available CPU device")
cpu_run_substitute = "env SYCL_DEVICE_TYPE=CPU "
cpu_run_substitute = "env SYCL_DEVICE_TYPE=CPU SYCL_BE={SYCL_BE} ".format(SYCL_BE=backend)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

On a fail LIT prints out this information and eases running the test by hand. Though the user still needs to add the LD_LIBRARY_PATH to find the SYCL library, but that is not part of this change.

cpu_check_substitute = "| FileCheck %s"
config.available_features.add('cpu')
if platform.system() == "Linux":
cpu_run_on_linux_substitute = "env SYCL_DEVICE_TYPE=CPU "
cpu_run_on_linux_substitute = "env SYCL_DEVICE_TYPE=CPU SYCL_BE={SYCL_BE} ".format(SYCL_BE=backend)
cpu_check_on_linux_substitute = "| FileCheck %s"
else:
lit_config.warning("CPU device not found")
Expand All @@ -144,18 +145,15 @@ def getDeviceCount(device_type):
if gpu_count > 0:
found_at_least_one_device = True
lit_config.note("Found available GPU device")
gpu_run_substitute = " env SYCL_DEVICE_TYPE=GPU "
gpu_run_substitute = " env SYCL_DEVICE_TYPE=GPU SYCL_BE={SYCL_BE} ".format(SYCL_BE=backend)
gpu_check_substitute = "| FileCheck %s"
config.available_features.add('gpu')
if cuda:
config.available_features.add('cuda')
gpu_run_substitute += " SYCL_BE=PI_CUDA "

if platform.system() == "Linux":
gpu_run_on_linux_substitute = "env SYCL_DEVICE_TYPE=GPU "
gpu_run_on_linux_substitute = "env SYCL_DEVICE_TYPE=GPU SYCL_BE={SYCL_BE} ".format(SYCL_BE=backend)
gpu_check_on_linux_substitute = "| FileCheck %s"
if cuda:
gpu_run_on_linux_substitute += " SYCL_BE=PI_CUDA "
else:
lit_config.warning("GPU device not found")

Expand Down
46 changes: 15 additions & 31 deletions sycl/tools/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,45 +5,29 @@ set(CMAKE_CXX_EXTENSIONS OFF)
add_executable(get_device_count_by_type get_device_count_by_type.cpp)
add_dependencies(get_device_count_by_type ocl-headers ocl-icd)

if( SYCL_BUILD_PI_CUDA )
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I removed this to avoid duplication and instead use the cudadrv target set up in the sycl/plugin/cuda/CMakeLists.txt CMake file.

find_package(CUDA 10.1 REQUIRED)

add_library(cudadrv SHARED IMPORTED)

set_target_properties(
cudadrv PROPERTIES
IMPORTED_LOCATION ${CUDA_CUDA_LIBRARY}
INTERFACE_INCLUDE_DIRECTORIES ${CUDA_INCLUDE_DIRS}
)

target_compile_definitions(get_device_count_by_type
PUBLIC $<$<BOOL:${SYCL_BUILD_PI_CUDA}>:USE_PI_CUDA>
)

target_include_directories( get_device_count_by_type
PUBLIC
${CUDA_INCLUDE_DIRS}
)
target_link_libraries(get_device_count_by_type
PUBLIC OpenCL-Headers cudadrv
)
endif()

target_link_libraries(get_device_count_by_type
PRIVATE OpenCL::Headers
PRIVATE ${OpenCL_LIBRARIES}
PRIVATE
OpenCL::Headers
${OpenCL_LIBRARIES}
$<$<BOOL:${SYCL_BUILD_PI_CUDA}>:cudadrv>
)
target_compile_definitions(get_device_count_by_type
PRIVATE
$<$<BOOL:${SYCL_BUILD_PI_CUDA}>:USE_PI_CUDA>
)

add_executable(sycl-check sycl-check.cpp)
add_dependencies(sycl-check sycl)
target_include_directories(sycl-check PRIVATE "${sycl_inc_dir}")
target_link_libraries(sycl-check
PRIVATE sycl
PRIVATE OpenCL::Headers
PRIVATE ${OpenCL_LIBRARIES})
PRIVATE
sycl
OpenCL::Headers
${OpenCL_LIBRARIES})

#Minimum supported version of Intel's OCL GPU and CPU devices
target_compile_definitions(sycl-check
PRIVATE MIN_INTEL_OCL_GPU_VERSION=\"18.47.11882\"
PRIVATE MIN_INTEL_OCL_CPU_VERSION=\"18.1.0.0901\",\"7.6.0.1202\"
PRIVATE
MIN_INTEL_OCL_GPU_VERSION=\"18.47.11882\"
MIN_INTEL_OCL_CPU_VERSION=\"18.1.0.0901\",\"7.6.0.1202\"
)
Loading