Skip to content

Commit 29badd8

Browse files
authored
[SYCL][CUDA] Build with cupti only when needed (#7913)
* Fix an issue where libpi_cuda is linked against libcupti even when XPTI is disabled. * Simplify pi_cuda CMake configuration.
1 parent 59dd387 commit 29badd8

File tree

2 files changed

+26
-22
lines changed

2 files changed

+26
-22
lines changed

sycl/plugins/cuda/CMakeLists.txt

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,27 @@ else()
2323
)
2424
endif()
2525

26-
if (SYCL_ENABLE_XPTI_TRACING)
27-
set(XPTI_PROXY_SRC "${CMAKE_SOURCE_DIR}/../xpti/src/xpti_proxy.cpp")
28-
endif()
26+
if (SYCL_ENABLE_XPTI_TRACING)
27+
# The following two if's can be removed when FindCUDA -> FindCUDAToolkit.
28+
# CUDA_CUPTI_INCLUDE_DIR -> CUDAToolkit_CUPTI_INCLUDE_DIR
29+
include(FindCUDACupti)
30+
if(NOT CUDA_CUPTI_INCLUDE_DIR)
31+
find_cuda_cupti_include_dir()
32+
endif()
33+
# CUDA_cupti_LIBRARY -> CUDAToolkit_cupti_LIBRARY
34+
if(NOT CUDA_cupti_LIBRARY)
35+
find_cuda_cupti_library()
36+
endif()
2937

30-
# The following two if's can be removed when FindCUDA -> FindCUDAToolkit.
31-
# CUDA_CUPTI_INCLUDE_DIR -> CUDAToolkit_CUPTI_INCLUDE_DIR
32-
include(FindCUDACupti)
33-
if(NOT CUDA_CUPTI_INCLUDE_DIR)
34-
find_cuda_cupti_include_dir()
35-
endif()
36-
# CUDA_cupti_LIBRARY -> CUDAToolkit_cupti_LIBRARY
37-
if(NOT CUDA_cupti_LIBRARY)
38-
find_cuda_cupti_library()
38+
set(XPTI_PROXY_SRC "${CMAKE_SOURCE_DIR}/../xpti/src/xpti_proxy.cpp")
39+
set(XPTI_INCLUDE
40+
"${CMAKE_SOURCE_DIR}/../xpti/include"
41+
"${CUDA_CUPTI_INCLUDE_DIR}"
42+
)
43+
set(XPTI_LIBS
44+
"${CMAKE_DL_LIBS}"
45+
"${CUDA_cupti_LIBRARY}"
46+
)
3947
endif()
4048

4149
add_sycl_plugin(cuda
@@ -46,26 +54,20 @@ add_sycl_plugin(cuda
4654
"pi_cuda.cpp"
4755
"tracing.cpp"
4856
${XPTI_PROXY_SRC}
57+
INCLUDE_DIRS
58+
${sycl_inc_dir}
59+
${XPTI_INCLUDE}
4960
LIBRARIES
5061
cudadrv
51-
${CUDA_cupti_LIBRARY}
62+
${XPTI_LIBS}
5263
)
5364

5465
if (SYCL_ENABLE_XPTI_TRACING)
5566
target_compile_definitions(pi_cuda PRIVATE
5667
XPTI_ENABLE_INSTRUMENTATION
5768
XPTI_STATIC_LIBRARY
5869
)
59-
target_include_directories(pi_cuda PRIVATE "${CMAKE_SOURCE_DIR}/../xpti/include")
60-
target_link_libraries(pi_cuda PRIVATE ${CMAKE_DL_LIBS})
6170
endif()
6271

63-
64-
target_include_directories(pi_cuda
65-
PRIVATE
66-
${sycl_inc_dir}
67-
${CUDA_CUPTI_INCLUDE_DIR}
68-
)
69-
7072
set_target_properties(pi_cuda PROPERTIES LINKER_LANGUAGE CXX)
7173

sycl/plugins/cuda/tracing.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
#endif
1313

1414
#include <cuda.h>
15+
#ifdef XPTI_ENABLE_INSTRUMENTATION
1516
#include <cupti.h>
17+
#endif // XPTI_ENABLE_INSTRUMENTATION
1618

1719
#include <exception>
1820
#include <iostream>

0 commit comments

Comments
 (0)