Skip to content

Commit 290b363

Browse files
committed
Integrate Clang ThreadSanitizer in tests
1 parent ee0a539 commit 290b363

2 files changed

Lines changed: 55 additions & 5 deletions

File tree

.github/workflows/ci.yml

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ jobs:
7272
run: |
7373
tests/ctranslate2_test tests/data
7474
75-
build-and-test-cpp-x86_64-sanitizer:
75+
build-and-test-cpp-x86_64-address_sanitizer:
7676
runs-on: ubuntu-22.04
7777
env:
7878
CT2_VERBOSE: 1
@@ -94,7 +94,7 @@ jobs:
9494
CT2_USE_MKL: 1
9595
MKL_VERSION: 2023.0.0
9696
run: |
97-
sudo apt-get install -y intel-oneapi-mkl-devel-$MKL_VERSION
97+
sudo apt install -y intel-oneapi-mkl-devel-$MKL_VERSION
9898
cmake -DCMAKE_INSTALL_PREFIX=$PWD/install -DBUILD_TESTS=ON -DENABLE_ADDRESS_SANITIZER=ON -DCMAKE_BUILD_TYPE=Debug .
9999
100100
- name: Build
@@ -113,7 +113,49 @@ jobs:
113113
CT2_USE_MKL: 1
114114
run: |
115115
ASAN_OPTIONS=detect_leaks=1:print_stats=1 tests/ctranslate2_test tests/data
116-
116+
117+
build-and-test-cpp-x86_64-thread_sanitizer:
118+
runs-on: ubuntu-22.04
119+
env:
120+
CT2_VERBOSE: 1
121+
122+
steps:
123+
- uses: actions/checkout@v4
124+
with:
125+
submodules: recursive
126+
127+
- name: Install Intel oneAPI
128+
run: |
129+
wget https://apt.repos.intel.com/intel-gpg-keys/GPG-PUB-KEY-INTEL-SW-PRODUCTS.PUB
130+
sudo apt-key add *.PUB
131+
sudo sh -c 'echo "deb https://apt.repos.intel.com/oneapi all main" > /etc/apt/sources.list.d/oneAPI.list'
132+
sudo apt-get update
133+
134+
- name: Configure with MKL
135+
env:
136+
CT2_USE_MKL: 1
137+
MKL_VERSION: 2023.0.0
138+
run: |
139+
sudo apt install -y intel-oneapi-mkl-devel-$MKL_VERSION
140+
cmake -DCMAKE_INSTALL_PREFIX=$PWD/install -DBUILD_TESTS=ON -DENABLE_THREAD_SANITIZER=ON -DCMAKE_BUILD_TYPE=Debug .
141+
142+
- name: Build
143+
run: |
144+
make install
145+
146+
- name: Download test data
147+
working-directory: tests/data/models
148+
run: |
149+
wget https://opennmt-models.s3.amazonaws.com/pi_lm_step_5000.pt
150+
wget https://opennmt-models.s3.amazonaws.com/transliteration-aren-all.tar.gz
151+
tar xf transliteration-aren-all.tar.gz
152+
153+
- name: Test ThreadSanitizer
154+
env:
155+
CT2_USE_MKL: 1
156+
run: |
157+
tests/ctranslate2_test tests/data
158+
117159
build-and-test-cpp-arm64:
118160
runs-on: ${{ matrix.os }}
119161
env:

CMakeLists.txt

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ option(BUILD_SHARED_LIBS "Build shared libraries" ON)
2323
option(WITH_TENSOR_PARALLEL "Compile with NCCL and MPI backend" OFF)
2424
option(WITH_FLASH_ATTN "Compile with Flash Attention 2" OFF)
2525
option(ENABLE_ADDRESS_SANITIZER "ASAN" OFF)
26+
option(ENABLE_THREAD_SANITIZER "TSAN" OFF)
2627

2728
MESSAGE(STATUS "Compiler Id: ${CMAKE_CXX_COMPILER_ID}")
2829
MESSAGE(STATUS "Compiler Version: ${CMAKE_CXX_COMPILER_VERSION}")
@@ -480,13 +481,20 @@ if (WITH_RUY)
480481
list(APPEND LIBRARIES ruy)
481482
endif()
482483

484+
# sanitizers
483485
IF (ENABLE_ADDRESS_SANITIZER AND (CMAKE_BUILD_TYPE STREQUAL "Debug" OR CMAKE_BUILD_TYPE STREQUAL "DEBUG"))
484-
MESSAGE (STATUS "ENABLE_ADDRESS_SANITIZER: ENABLED")
486+
MESSAGE (STATUS "ENABLE_ADDRESS_SANITIZER: TRUE")
485487
set(ASAN_FLAGS " -fsanitize=address -fno-omit-frame-pointer -fno-optimize-sibling-calls -fno-common")
486488
string(APPEND CMAKE_C_FLAGS ${ASAN_FLAGS})
487489
string(APPEND CMAKE_CXX_FLAGS ${ASAN_FLAGS})
488490
add_link_options(-fsanitize=address)
489-
ELSEIF (ENABLE_ADDRESS_SANITIZER)
491+
ELSEIF (ENABLE_THREAD_SANITIZER AND (CMAKE_BUILD_TYPE STREQUAL "Debug" OR CMAKE_BUILD_TYPE STREQUAL "DEBUG"))
492+
MESSAGE (STATUS "ENABLE_THREAD_SANITIZER: TRUE")
493+
set(TSAN_FLAGS " -fsanitize=thread")
494+
string(APPEND CMAKE_C_FLAGS ${TSAN_FLAGS})
495+
string(APPEND CMAKE_CXX_FLAGS ${TSAN_FLAGS})
496+
add_link_options(-fsanitize=thread)
497+
ELSEIF (ENABLE_ADDRESS_SANITIZER OR ENABLE_THREAD_SANITIZER)
490498
MESSAGE(FATAL_ERROR "SANITIZER requires Debug build type")
491499
ENDIF ()
492500

0 commit comments

Comments
 (0)