Files
nvbench/cmake/NVBenchCUPTI.cmake
Marco Franzreb Salgado dd1ffc94e8 Add Windows support
2026-05-07 00:31:36 -07:00

57 lines
1.8 KiB
CMake

# Since this file is installed, we need to make sure that the CUDAToolkit has
# been found by consumers:
if (NOT TARGET CUDA::toolkit)
find_package(CUDAToolkit REQUIRED)
endif()
if (EXISTS "${CUDAToolkit_LIBRARY_ROOT}/extras/CUPTI/lib64")
# NVIDIA installer layout:
set(nvbench_cupti_root "${CUDAToolkit_LIBRARY_ROOT}/extras/CUPTI")
else()
# Ubuntu package layout:
set(nvbench_cupti_root "${CUDAToolkit_LIBRARY_ROOT}")
endif()
# The CUPTI targets in FindCUDAToolkit are broken:
# - The dll locations are not specified
# - Dependent libraries nvperf_* are not linked.
# So we create our own targets:
function(nvbench_add_cupti_dep dep_name)
string(TOLOWER ${dep_name} dep_name_lower)
string(TOUPPER ${dep_name} dep_name_upper)
add_library(nvbench::${dep_name_lower} SHARED IMPORTED)
find_library(NVBench_${dep_name_upper}_LIBRARY ${dep_name_lower} REQUIRED
DOC "The import library for ${dep_name_lower} from the CUDA Toolkit."
HINTS "${nvbench_cupti_root}/lib64"
)
mark_as_advanced(NVBench_${dep_name_upper}_LIBRARY)
if (WIN32)
set_target_properties(nvbench::${dep_name_lower} PROPERTIES
IMPORTED_IMPLIB "${NVBench_${dep_name_upper}_LIBRARY}"
)
else()
set_target_properties(nvbench::${dep_name_lower} PROPERTIES
IMPORTED_LOCATION "${NVBench_${dep_name_upper}_LIBRARY}"
)
endif()
endfunction()
nvbench_add_cupti_dep(cupti)
target_include_directories(nvbench::cupti INTERFACE
"${nvbench_cupti_root}/include"
)
if (NOT EXISTS "${nvbench_cupti_root}/include/cupti_profiler_host.h")
# Profile Host API does not exist yet, need NVPERF libraries
# for NVPW_* API used in nvbench::cupti_profiler
nvbench_add_cupti_dep(nvperf_target)
nvbench_add_cupti_dep(nvperf_host)
target_link_libraries(nvbench::cupti INTERFACE
nvbench::nvperf_target
nvbench::nvperf_host
)
endif()