Skip to content

Commit

Permalink
Add USE_TSAN option (pytorch#35197)
Browse files Browse the repository at this point in the history
Summary:
Sometimes it is important to run code with thread sanitizer.
Pull Request resolved: pytorch#35197

Test Plan: CI

Differential Revision: D20605005

Pulled By: malfet

fbshipit-source-id: bcd1a5191b5f859e12b6df6737c980099b1edc36
  • Loading branch information
malfet authored and facebook-github-bot committed Mar 23, 2020
1 parent a00e12e commit 93983c7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ cmake_dependent_option(
"BUILD_TEST" OFF)
option(COLORIZE_OUTPUT "Colorize output during compilation" ON)
option(USE_ASAN "Use Address Sanitizer" OFF)
option(USE_TSAN "Use Thread Sanitizer" OFF)
option(USE_CUDA "Use CUDA" ON)
option(USE_ROCM "Use ROCm" ON)
option(CAFFE2_STATIC_LINK_CUDA "Statically link CUDA libraries" OFF)
Expand Down
9 changes: 9 additions & 0 deletions cmake/MiscCheck.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,15 @@ if (USE_ASAN)
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${CAFFE2_ASAN_FLAG}")
endif()

if (USE_TSAN)
set(CAFFE2_TSAN_FLAG "-fsanitize=thread -fPIE -pie")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CAFFE2_TSAN_FLAG}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CAFFE2_TSAN_FLAG}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${CAFFE2_TSAN_FLAG}")
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} ${CAFFE2_TSAN_FLAG}")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${CAFFE2_TSAN_FLAG}")
endif()

# ---[ Create CAFFE2_BUILD_SHARED_LIBS for macros.h.in usage.
set(CAFFE2_BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS})

Expand Down

0 comments on commit 93983c7

Please sign in to comment.