Skip to content

Commit e8d2622

Browse files
committed
Integrate Clang ThreadSanitizer in tests
1 parent 226c95d commit e8d2622

File tree

2 files changed

+62
-3
lines changed

2 files changed

+62
-3
lines changed

.github/workflows/ci.yml

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,58 @@ jobs:
122122
CT2_USE_MKL: 1
123123
run: |
124124
ASAN_OPTIONS=detect_leaks=1:print_stats=1 tests/ctranslate2_test tests/data
125-
125+
126+
build-and-test-cpp-x86_64-thread_sanitizer:
127+
runs-on: ubuntu-22.04
128+
env:
129+
CT2_VERBOSE: 1
130+
131+
steps:
132+
- uses: actions/checkout@v4
133+
with:
134+
submodules: recursive
135+
136+
- name: Install Intel oneAPI
137+
run: |
138+
wget https://apt.repos.intel.com/intel-gpg-keys/GPG-PUB-KEY-INTEL-SW-PRODUCTS.PUB
139+
sudo apt-key add *.PUB
140+
sudo sh -c 'echo "deb https://apt.repos.intel.com/oneapi all main" > /etc/apt/sources.list.d/oneAPI.list'
141+
sudo apt update
142+
143+
- name: Install MKL
144+
env:
145+
CT2_USE_MKL: 1
146+
MKL_VERSION: 2023.0.0
147+
run: |
148+
sudo apt install -y intel-oneapi-mkl-devel-$MKL_VERSION
149+
150+
- name: Install Clang
151+
run: |
152+
sudo apt install -y clang
153+
154+
- name: Configure with MKL and Clang
155+
env:
156+
CT2_USE_MKL: 1
157+
run: |
158+
cmake -DCMAKE_INSTALL_PREFIX=$PWD/install -DBUILD_TESTS=ON -DCMAKE_C_COMPILER=/usr/bin/clang -DCMAKE_CXX_COMPILER=/usr/bin/clang++ -DENABLE_THREAD_SANITIZER=ON -DCMAKE_BUILD_TYPE=Debug .
159+
160+
- name: Build
161+
run: |
162+
make -j $(nproc) install
163+
164+
- name: Download test data
165+
working-directory: tests/data/models
166+
run: |
167+
wget https://opennmt-models.s3.amazonaws.com/pi_lm_step_5000.pt
168+
wget https://opennmt-models.s3.amazonaws.com/transliteration-aren-all.tar.gz
169+
tar xf transliteration-aren-all.tar.gz
170+
171+
- name: Test ThreadSanitizer
172+
env:
173+
CT2_USE_MKL: 1
174+
run: |
175+
TSAN_OPTIONS="ignore_noninstrumented_modules=1:halt_on_error=1" tests/ctranslate2_test tests/data
176+
126177
build-and-test-cpp-arm64:
127178
runs-on: ${{ matrix.os }}
128179
env:

CMakeLists.txt

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

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

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

0 commit comments

Comments
 (0)