Skip to content

Commit 4dadba6

Browse files
committed
Move cupti exception check from PyTorch to kineto
Signed-off-by: cyy <[email protected]>
1 parent 7716cbc commit 4dadba6

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

libkineto/CMakeLists.txt

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# This source code is licensed under the BSD-style license found in the
55
# LICENSE file in the root directory of this source tree.
66

7-
cmake_minimum_required(VERSION 3.22 FATAL_ERROR)
7+
cmake_minimum_required(VERSION 3.24 FATAL_ERROR)
88
project(kineto VERSION 0.1 LANGUAGES CXX C)
99

1010
#install libraries into correct locations on all platforms
@@ -79,8 +79,32 @@ if(NOT LIBKINETO_NOCUPTI)
7979
if(NOT TARGET CUDA::cupti)
8080
add_library(CUDA::cupti INTERFACE IMPORTED)
8181
target_link_libraries(CUDA::cupti INTERFACE "${CUDA_cupti_LIBRARY}")
82+
else()
83+
set(CUDA_cupti_LIBRARY "$<TARGET_FILE:CUDA::cupti>")
8284
endif()
8385
target_include_directories(CUDA::cupti INTERFACE "${CUPTI_INCLUDE_DIR}")
86+
87+
if("${CUDA_cupti_LIBRARY}" MATCHES "[.]a")
88+
include(CheckCXXSourceRuns)
89+
set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} "dl" "pthread" $<LINK_LIBRARY:WHOLE_ARCHIVE,"${CUDA_cupti_LIBRARY}">)
90+
91+
check_cxx_source_runs("#include <stdexcept>
92+
int main() {
93+
try {
94+
throw std::runtime_error(\"error\");
95+
} catch (...) {
96+
return 0;
97+
}
98+
return 1;
99+
}" EXCEPTIONS_WORK)
100+
set(CMAKE_REQUIRED_LINK_OPTIONS "")
101+
if(NOT EXCEPTIONS_WORK)
102+
message(FATAL_ERROR
103+
"Detected that statically linking against CUPTI causes exceptions to stop working. "
104+
"See https://github.com/pytorch/pytorch/issues/57744 for more details. ")
105+
endif()
106+
endif()
107+
84108
else()
85109
set(LIBKINETO_NOCUPTI ON CACHE BOOL "" FORCE)
86110
message(STATUS "Could not find CUPTI library")

0 commit comments

Comments
 (0)