Skip to content

[SYCL][CUDA] Fix cupti library dynamic loading #17272

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 1 commit into from
Mar 4, 2025
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
10 changes: 3 additions & 7 deletions unified-runtime/source/adapters/cuda/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@ else()
message(WARNING "CUDA adapter USM pools are disabled, set UMF_ENABLE_POOL_TRACKING to enable them")
endif()

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

if (CUDA_cupti_LIBRARY)
# cupti is dynamically loaded so the adapter still works if it's not available
target_compile_definitions("ur_adapter_cuda" PRIVATE CUPTI_LIB_PATH="${CUDA_cupti_LIBRARY}")
endif()

target_link_libraries(${TARGET_NAME} PRIVATE
${PROJECT_NAME}::headers
${PROJECT_NAME}::common
${PROJECT_NAME}::umf
Threads::Threads
cudadrv
${EXTRA_LIBS}
)

target_include_directories(${TARGET_NAME} PRIVATE
Expand Down
8 changes: 5 additions & 3 deletions unified-runtime/source/adapters/cuda/tracing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,14 @@ bool cupti_table_t_::isInitialized() const {
}

bool loadCUDATracingLibrary(cuda_tracing_context_t_ *Ctx) {
#if defined(XPTI_ENABLE_INSTRUMENTATION) && defined(CUPTI_LIB_PATH)
#if defined(XPTI_ENABLE_INSTRUMENTATION) && !defined(_WIN32)
const char *CuptiLibName = "libcupti.so";

if (!Ctx)
return false;
if (Ctx->Library)
return true;
auto Lib{ur_loader::LibLoader::loadAdapterLibrary(CUPTI_LIB_PATH)};
auto Lib{ur_loader::LibLoader::loadAdapterLibrary(CuptiLibName)};
if (!Lib)
return false;
cupti_table_t_ Table;
Expand All @@ -165,7 +167,7 @@ bool loadCUDATracingLibrary(cuda_tracing_context_t_ *Ctx) {
#else
(void)Ctx;
return false;
#endif // XPTI_ENABLE_INSTRUMENTATION && CUPTI_LIB_PATH
#endif // defined(XPTI_ENABLE_INSTRUMENTATION) && !defined(_WIN32)
}

void unloadCUDATracingLibrary(cuda_tracing_context_t_ *Ctx) {
Expand Down
Loading