Skip to content

Commit 0e155f0

Browse files
authored
[SYCL][CUDA] Fix cupti library dynamic loading (#17272)
This patch fixes loading the cupti library on Linux to rely on the dynamic linker to figure out where the library is. It also disable cupti tracing on Windows, as far as I know this is only used on Linux at the moment since the tracing tools don't support Windows. Additionally there are some potential security issues of loading the library just by name on Windows, so we just leave Windows support out for now. This is following up on the discussions on oneapi-src/unified-runtime#1070, statically linking the cupti library was also ruled out as it makes the adapter library go from around 600KiB to around 32MiB.
1 parent a7774f2 commit 0e155f0

File tree

2 files changed

+8
-10
lines changed

2 files changed

+8
-10
lines changed

unified-runtime/source/adapters/cuda/CMakeLists.txt

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,9 @@ else()
7979
message(WARNING "CUDA adapter USM pools are disabled, set UMF_ENABLE_POOL_TRACKING to enable them")
8080
endif()
8181

82-
if (UR_ENABLE_TRACING)
82+
# Only enable xpti tracing on Linux as tracing tools aren't available on
83+
# Windows yet.
84+
if (UR_ENABLE_TRACING AND UNIX)
8385
include(FindCUDACupti)
8486
# The following two ifs can be removed when FindCUDA -> FindCUDAToolkit.
8587
# CUDA_CUPTI_INCLUDE_DIR -> CUDAToolkit_CUPTI_INCLUDE_DIR
@@ -109,18 +111,12 @@ if (UR_ENABLE_TRACING)
109111
target_sources(${TARGET_NAME} PRIVATE ${XPTI_PROXY_SRC})
110112
endif()
111113

112-
if (CUDA_cupti_LIBRARY)
113-
# cupti is dynamically loaded so the adapter still works if it's not available
114-
target_compile_definitions("ur_adapter_cuda" PRIVATE CUPTI_LIB_PATH="${CUDA_cupti_LIBRARY}")
115-
endif()
116-
117114
target_link_libraries(${TARGET_NAME} PRIVATE
118115
${PROJECT_NAME}::headers
119116
${PROJECT_NAME}::common
120117
${PROJECT_NAME}::umf
121118
Threads::Threads
122119
cudadrv
123-
${EXTRA_LIBS}
124120
)
125121

126122
target_include_directories(${TARGET_NAME} PRIVATE

unified-runtime/source/adapters/cuda/tracing.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,12 +143,14 @@ bool cupti_table_t_::isInitialized() const {
143143
}
144144

145145
bool loadCUDATracingLibrary(cuda_tracing_context_t_ *Ctx) {
146-
#if defined(XPTI_ENABLE_INSTRUMENTATION) && defined(CUPTI_LIB_PATH)
146+
#if defined(XPTI_ENABLE_INSTRUMENTATION) && !defined(_WIN32)
147+
const char *CuptiLibName = "libcupti.so";
148+
147149
if (!Ctx)
148150
return false;
149151
if (Ctx->Library)
150152
return true;
151-
auto Lib{ur_loader::LibLoader::loadAdapterLibrary(CUPTI_LIB_PATH)};
153+
auto Lib{ur_loader::LibLoader::loadAdapterLibrary(CuptiLibName)};
152154
if (!Lib)
153155
return false;
154156
cupti_table_t_ Table;
@@ -165,7 +167,7 @@ bool loadCUDATracingLibrary(cuda_tracing_context_t_ *Ctx) {
165167
#else
166168
(void)Ctx;
167169
return false;
168-
#endif // XPTI_ENABLE_INSTRUMENTATION && CUPTI_LIB_PATH
170+
#endif // defined(XPTI_ENABLE_INSTRUMENTATION) && !defined(_WIN32)
169171
}
170172

171173
void unloadCUDATracingLibrary(cuda_tracing_context_t_ *Ctx) {

0 commit comments

Comments
 (0)