CUPTI support

This commit is contained in:
Georgy Evtushenko
2021-09-01 19:43:12 +03:00
parent 3d6c16f8ba
commit 1bc715267c
26 changed files with 1705 additions and 4 deletions

71
cmake/NVBenchCUPTI.cmake Normal file
View File

@@ -0,0 +1,71 @@
# 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()
set(nvbench_cupti_root "${CUDAToolkit_LIBRARY_ROOT}/extras/CUPTI")
# 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)
if (WIN32)
# Attempt to locate the dll in the expected location. This is necessary
# because the CUPTI dll has a versioned suffix, so we can't directly search
# for it with find_file.
file(GLOB dep_dll_path "${nvbench_cupti_root}/lib64/${dep_name_lower}*dll")
cmake_path(GET dep_dll_path FILENAME dep_dll_filename)
# If the dll was not found in the expected location, use a default filename as a user hint.
if (NOT dep_dll_filename)
set(dep_dll_filename ${dep_name_lower}.dll)
endif()
# Use find_file to create a cache variable and mark the file as REQUIRED.
find_file(NVBench_${dep_name_upper}_DLL ${dep_dll_filename} REQUIRED
DOC "The full path to ${dep_name_lower}.dll from the CUDA Toolkit."
HINTS "${nvbench_cupti_root}/lib64/"
)
mark_as_advanced(NVBench_${dep_name_upper}_DLL)
# The .libs don't have suffixes, so we can just directly search for them.
find_library(NVBench_${dep_name_upper}_LIBRARY ${dep_name_lower}.lib REQUIRED
DOC "The full path to ${dep_name_lower}.lib from the CUDA Toolkit."
HINTS "${nvbench_cupti_root}/lib64/"
)
mark_as_advanced(NVBench_${dep_name_upper}_LIBRARY)
set_target_properties(nvbench::${dep_name_lower} PROPERTIES
IMPORTED_LOCATION "${NVBench_${dep_name_upper}_DLL}"
IMPORTED_IMPLIB "${NVBench_${dep_name_upper}_LIBRARY}"
)
else()
find_library(NVBench_${dep_name_upper}_LIBRARY ${dep_name_lower} REQUIRED
DOC "The full path to lib${dep_name_lower}.so from the CUDA Toolkit."
HINTS "${nvbench_cupti_root}/lib64"
)
mark_as_advanced(NVBench_${dep_name_upper}_LIBRARY)
set_target_properties(nvbench::${dep_name_lower} PROPERTIES
IMPORTED_LOCATION "${NVBench_${dep_name_upper}_LIBRARY}"
)
endif()
endfunction()
nvbench_add_cupti_dep(nvperf_target)
nvbench_add_cupti_dep(nvperf_host)
nvbench_add_cupti_dep(cupti)
target_link_libraries(nvbench::cupti INTERFACE
nvbench::nvperf_target
nvbench::nvperf_host
)
target_include_directories(nvbench::cupti INTERFACE
"${nvbench_cupti_root}/include"
)

View File

@@ -64,3 +64,10 @@ if (NVBench_ENABLE_NVML)
include("${CMAKE_CURRENT_LIST_DIR}/NVBenchNVML.cmake")
list(APPEND ctk_libraries nvbench::nvml)
endif()
################################################################################
# CUDAToolkit -> CUPTI
if (NVBench_ENABLE_CUPTI)
include("${CMAKE_CURRENT_LIST_DIR}/NVBenchCUPTI.cmake")
list(APPEND ctk_libraries CUDA::cuda_driver nvbench::cupti)
endif()

View File

@@ -23,7 +23,9 @@ endif()
function(nvbench_setup_dep_dlls target_name)
# The custom command below fails when there aren't any runtime DLLs to copy,
# so only enable it when a relevant dependency is enabled:
if (NVBench_ADD_DEPENDENT_DLLS_TO_BUILD AND NVBench_ENABLE_NVML)
if (NVBench_ADD_DEPENDENT_DLLS_TO_BUILD AND
(NVBench_ENABLE_NVML OR
NVBench_ENABLE_CUPTI))
add_custom_command(TARGET ${target_name}
POST_BUILD
COMMAND

View File

@@ -11,6 +11,15 @@ macro(nvbench_generate_exports)
)
endif()
if (NVBench_ENABLE_CUPTI)
string(APPEND nvbench_build_export_code_block
"include(\"${NVBench_SOURCE_DIR}/cmake/NVBenchCUPTI.cmake\")\n"
)
string(APPEND nvbench_install_export_code_block
"include(\"\${CMAKE_CURRENT_LIST_DIR}/NVBenchCUPTI.cmake\")\n"
)
endif()
rapids_export(BUILD NVBench
EXPORT_SET nvbench-targets
NAMESPACE "nvbench::"

View File

@@ -39,6 +39,14 @@ if (NVBench_ENABLE_NVML)
)
endif()
if (NVBench_ENABLE_CUPTI)
install(
FILES
"${NVBench_SOURCE_DIR}/cmake/NVBenchCUPTI.cmake"
DESTINATION "${config_install_location}"
)
endif()
# Call with a list of library targets to generate install rules:
function(nvbench_install_libraries)
install(TARGETS ${ARGN}

View File

@@ -3,5 +3,9 @@ function(nvbench_write_config_header filepath)
set(NVBENCH_HAS_NVML 1)
endif()
if (NVBench_ENABLE_CUPTI)
set(NVBENCH_HAS_CUPTI 1)
endif()
configure_file("${NVBench_SOURCE_DIR}/cmake/config.cuh.in" "${filepath}")
endfunction()

View File

@@ -20,3 +20,6 @@
// Defined if NVBench has been built with NVML support.
#cmakedefine NVBENCH_HAS_NVML
// Defined if NVBench has been built with CUPTI support.
#cmakedefine NVBENCH_HAS_CUPTI