mirror of
https://github.com/pytorch/pytorch.git
synced 2025-10-20 21:14:14 +08:00
[build] Add LeakSanitizer option to CMake (#158686)
Pull Request resolved: https://github.com/pytorch/pytorch/pull/158686 Approved by: https://github.com/eellison
This commit is contained in:
committed by
PyTorch MergeBot
parent
af60398c3a
commit
bdbe931d58
@ -234,6 +234,7 @@ cmake_dependent_option(INSTALL_TEST "Install test binaries if BUILD_TEST is on"
|
||||
option(USE_CPP_CODE_COVERAGE "Compile C/C++ with code coverage flags" OFF)
|
||||
option(USE_COLORIZE_OUTPUT "Colorize output during compilation" ON)
|
||||
option(USE_ASAN "Use Address+Undefined Sanitizers" OFF)
|
||||
option(USE_LSAN "Use Leak Sanitizer" OFF)
|
||||
option(USE_TSAN "Use Thread Sanitizer" OFF)
|
||||
option(USE_CUDA "Use CUDA" ON)
|
||||
option(USE_XPU "Use XPU" ON)
|
||||
|
@ -1830,6 +1830,12 @@ if(BUILD_TEST)
|
||||
target_link_libraries(${test_name}_${CPU_CAPABILITY} Sanitizer::undefined)
|
||||
endif()
|
||||
endif()
|
||||
if(USE_LSAN AND TARGET Sanitizer::leak)
|
||||
target_link_libraries(${test_name}_${CPU_CAPABILITY} Sanitizer::leak)
|
||||
endif()
|
||||
if(USE_TSAN AND TARGET Sanitizer::thread)
|
||||
target_link_libraries(${test_name}_${CPU_CAPABILITY} Sanitizer::thread)
|
||||
endif()
|
||||
else()
|
||||
add_executable(${test_name}_${CPU_CAPABILITY} "${test_src}")
|
||||
target_link_libraries(${test_name}_${CPU_CAPABILITY} torch_library sleef gtest_main)
|
||||
|
@ -108,24 +108,32 @@ if(CAFFE2_CMAKE_BUILDING_WITH_MAIN_REPO AND NOT INTERN_BUILD_MOBILE)
|
||||
enable_ubsan()
|
||||
endif()
|
||||
|
||||
if(USE_ASAN OR USE_TSAN)
|
||||
if(USE_ASAN OR USE_LSAN OR USE_TSAN)
|
||||
find_package(Sanitizer REQUIRED)
|
||||
if(USE_ASAN)
|
||||
if(TARGET Sanitizer::address)
|
||||
list(APPEND Caffe2_DEPENDENCY_LIBS Sanitizer::address)
|
||||
else()
|
||||
message(WARNING "Not ASAN found. Suppress this warning with -DUSE_ASAN=OFF.")
|
||||
message(WARNING "ASAN not found. Suppress this warning with -DUSE_ASAN=OFF.")
|
||||
caffe2_update_option(USE_ASAN OFF)
|
||||
endif()
|
||||
if(TARGET Sanitizer::undefined)
|
||||
list(APPEND Caffe2_DEPENDENCY_LIBS Sanitizer::undefined)
|
||||
endif()
|
||||
endif()
|
||||
if(USE_LSAN)
|
||||
if(TARGET Sanitizer::leak)
|
||||
list(APPEND Caffe2_DEPENDENCY_LIBS Sanitizer::leak)
|
||||
else()
|
||||
message(WARNING "LSAN not found. Suppress this warning with -DUSE_LSAN=OFF.")
|
||||
caffe2_update_option(USE_LSAN OFF)
|
||||
endif()
|
||||
endif()
|
||||
if(USE_TSAN)
|
||||
if(TARGET Sanitizer::thread)
|
||||
list(APPEND Caffe2_DEPENDENCY_LIBS Sanitizer::thread)
|
||||
else()
|
||||
message(WARNING "Not TSAN found. Suppress this warning with -DUSE_TSAN=OFF.")
|
||||
message(WARNING "TSAN not found. Suppress this warning with -DUSE_TSAN=OFF.")
|
||||
caffe2_update_option(USE_TSAN OFF)
|
||||
endif()
|
||||
endif()
|
||||
|
@ -66,6 +66,7 @@ function(caffe2_print_configuration_summary)
|
||||
message(STATUS " LAPACK : ${LAPACK_INFO}")
|
||||
endif()
|
||||
message(STATUS " USE_ASAN : ${USE_ASAN}")
|
||||
message(STATUS " USE_LSAN : ${USE_LSAN}")
|
||||
message(STATUS " USE_TSAN : ${USE_TSAN}")
|
||||
message(STATUS " USE_CPP_CODE_COVERAGE : ${USE_CPP_CODE_COVERAGE}")
|
||||
message(STATUS " USE_CUDA : ${USE_CUDA}")
|
||||
|
@ -95,6 +95,9 @@ endif()
|
||||
if(USE_ASAN AND TARGET Sanitizer::undefined)
|
||||
list(APPEND TORCH_PYTHON_LINK_LIBRARIES Sanitizer::undefined)
|
||||
endif()
|
||||
if(USE_LSAN AND TARGET Sanitizer::leak)
|
||||
list(APPEND TORCH_PYTHON_LINK_LIBRARIES Sanitizer::leak)
|
||||
endif()
|
||||
if(USE_TSAN AND TARGET Sanitizer::thread)
|
||||
list(APPEND TORCH_PYTHON_LINK_LIBRARIES Sanitizer::thread)
|
||||
endif()
|
||||
|
Reference in New Issue
Block a user