4
4
# This source code is licensed under the BSD-style license found in the
5
5
# LICENSE file in the root directory of this source tree.
6
6
7
- cmake_minimum_required (VERSION 3.22 FATAL_ERROR)
7
+ cmake_minimum_required (VERSION 3.24 FATAL_ERROR)
8
8
project (kineto VERSION 0.1 LANGUAGES CXX C)
9
9
10
10
#install libraries into correct locations on all platforms
@@ -52,6 +52,7 @@ endif()
52
52
# Set LIBKINETO_NOCUPTI to explicitly disable CUPTI
53
53
# Otherwise, CUPTI is disabled if not found
54
54
option (LIBKINETO_NOCUPTI "Disable CUPTI" OFF )
55
+ option (USE_CUPTI_SO "Use CUPTI as a shared library" ON )
55
56
56
57
find_package (CUDAToolkit)
57
58
if (NOT LIBKINETO_NOCUPTI)
@@ -63,24 +64,65 @@ if(NOT LIBKINETO_NOCUPTI)
63
64
NO_DEFAULT_PATH)
64
65
endif ()
65
66
66
- if (NOT CUDA_cupti_LIBRARY)
67
- find_library (CUDA_cupti_LIBRARY cupti PATHS
68
- "${CUDAToolkit_LIBRARY_ROOT} "
69
- "${CUDAToolkit_LIBRARY_ROOT} /extras/CUPTI/lib64"
70
- "${CUDAToolkit_LIBRARY_ROOT} /lib"
71
- "${CUDAToolkit_LIBRARY_ROOT} /lib64"
72
- NO_DEFAULT_PATH)
67
+ if (USE_CUPTI_SO)
68
+ if (NOT CUDA_cupti_LIBRARY)
69
+ find_library (CUDA_cupti_LIBRARY cupti PATHS
70
+ "${CUDAToolkit_LIBRARY_ROOT} "
71
+ "${CUDAToolkit_LIBRARY_ROOT} /extras/CUPTI/lib64"
72
+ "${CUDAToolkit_LIBRARY_ROOT} /lib"
73
+ "${CUDAToolkit_LIBRARY_ROOT} /lib64"
74
+ NO_DEFAULT_PATH)
75
+ endif ()
76
+ set (cupti_LIBRARY ${CUDA_cupti_LIBRARY} )
77
+ else ()
78
+ if (NOT CUDA_cupti_static_LIBRARY)
79
+ find_library (CUDA_cupti_static_LIBRARY cupti_static PATHS
80
+ "${CUDAToolkit_LIBRARY_ROOT} "
81
+ "${CUDAToolkit_LIBRARY_ROOT} /extras/CUPTI/lib64"
82
+ "${CUDAToolkit_LIBRARY_ROOT} /lib"
83
+ "${CUDAToolkit_LIBRARY_ROOT} /lib64"
84
+ NO_DEFAULT_PATH)
85
+ endif ()
86
+ set (cupti_LIBRARY ${CUDA_cupti_static_LIBRARY} )
73
87
endif ()
74
88
75
- if (CUDA_cupti_LIBRARY AND CUPTI_INCLUDE_DIR)
89
+ if (cupti_LIBRARY AND CUPTI_INCLUDE_DIR)
76
90
message (STATUS " CUPTI_INCLUDE_DIR = ${CUPTI_INCLUDE_DIR} " )
77
91
message (STATUS " CUDA_cupti_LIBRARY = ${CUDA_cupti_LIBRARY} " )
92
+ message (STATUS " CUDA_cupti_static_LIBRARY = ${CUDA_cupti_static_LIBRARY} " )
78
93
message (STATUS "Found CUPTI" )
79
- if (NOT TARGET CUDA::cupti)
80
- add_library (CUDA::cupti INTERFACE IMPORTED )
81
- target_link_libraries (CUDA::cupti INTERFACE "${CUDA_cupti_LIBRARY} " )
94
+ if (USE_CUPTI_SO)
95
+ set (cupti_target CUDA::cupti)
96
+ else ()
97
+ set (cupti_target CUDA::cupti_static)
98
+ endif ()
99
+ if (NOT TARGET ${cupti_target} )
100
+ add_library (${cupti_target} INTERFACE IMPORTED )
101
+ target_link_libraries (${cupti_target} INTERFACE "${cupti_LIBRARY} " )
82
102
endif ()
83
- target_include_directories (CUDA::cupti INTERFACE "${CUPTI_INCLUDE_DIR} " )
103
+ target_include_directories (${cupti_target} INTERFACE "${CUPTI_INCLUDE_DIR} " )
104
+
105
+ if (NOT USE_CUPTI_SO)
106
+ include (CheckCXXSourceRuns)
107
+ set (CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} "dl" "pthread" $<LINK_LIBRARY:WHOLE_ARCHIVE,${cupti_LIBRARY} >)
108
+
109
+ check_cxx_source_runs("#include <stdexcept>
110
+ int main() {
111
+ try {
112
+ throw std::runtime_error(\" error\" );
113
+ } catch (...) {
114
+ return 0;
115
+ }
116
+ return 1;
117
+ }" EXCEPTIONS_WORK)
118
+ set (CMAKE_REQUIRED_LINK_OPTIONS "" )
119
+ if (NOT EXCEPTIONS_WORK)
120
+ message (FATAL_ERROR
121
+ "Detected that statically linking against CUPTI causes exceptions to stop working. "
122
+ "See https://github.com/pytorch/pytorch/issues/57744 for more details. " )
123
+ endif ()
124
+ endif ()
125
+
84
126
else ()
85
127
set (LIBKINETO_NOCUPTI ON CACHE BOOL "" FORCE)
86
128
message (STATUS "Could not find CUPTI library" )
@@ -247,8 +289,8 @@ if(NOT LIBKINETO_NOROCTRACER)
247
289
endif ()
248
290
249
291
if (NOT LIBKINETO_NOCUPTI)
250
- target_link_libraries (kineto PUBLIC CUDA::cupti CUDA::cudart CUDA::cuda_driver)
251
- target_link_libraries (kineto_base PUBLIC CUDA::cupti CUDA::cudart CUDA::cuda_driver)
292
+ target_link_libraries (kineto PUBLIC ${cupti_target} CUDA::cudart CUDA::cuda_driver)
293
+ target_link_libraries (kineto_base PUBLIC ${cupti_target} CUDA::cudart CUDA::cuda_driver)
252
294
endif ()
253
295
if (TARGET CUDA::nvperf_host)
254
296
target_link_libraries (kineto_base PRIVATE CUDA::nvperf_host)
0 commit comments