|
3 | 3 | # use LLVM_BINARY_DIR to obtain the locations of the .so files used for LD_PRELOAD |
4 | 4 |
|
5 | 5 | if [ "$#" -eq 0 ]; then |
6 | | - echo "Usage: $0 <sanitizer type> python program.py. <sanitizer type> can be \"asan\"" |
| 6 | + echo "Usage: $0 <sanitizer type> python program.py. <sanitizer type> can be \"asan\", \"tsan\"" |
7 | 7 | exit 1 |
8 | 8 | fi |
9 | 9 |
|
10 | 10 | sanitizer_type=$1 |
11 | 11 |
|
12 | | -if [ "$sanitizer_type" != "asan" ]; then |
13 | | - echo "Error: Unsupported <sanitizer type> $sanitizer_type. Usage: $0 <sanitizer type> python program.py. <sanitizer type> can be \"asan\"" |
| 12 | +if [ "$sanitizer_type" != "asan" ] && [ "$sanitizer_type" != "tsan" ]; then |
| 13 | + echo "Error: Unsupported <sanitizer type> $sanitizer_type. Usage: $0 <sanitizer type> python program.py. <sanitizer type> can be \"asan\", \"tsan\"" |
14 | 14 | exit 1 |
15 | 15 | fi |
16 | 16 |
|
@@ -42,6 +42,57 @@ ASAN_OPTIONS=\"detect_leaks=0\"" |
42 | 42 |
|
43 | 43 | # shift command line arguments to the left by 1 to account for "asan" |
44 | 44 | shift 1 |
| 45 | +elif [ "${sanitizer_type}" = "tsan" ]; then |
| 46 | + # find path to tsan shared library |
| 47 | + tsan_dir="$(find "$llvm_install_dir" -type f -name "libclang_rt.tsan.so")" |
| 48 | + |
| 49 | + if [ -z "$tsan_dir" ]; then |
| 50 | + echo "Error: unable to find libclang_rt.tsan.so in $llvm_install_dir" |
| 51 | + exit 1 |
| 52 | + fi |
| 53 | + |
| 54 | + count=$(echo "$tsan_dir" | wc -l) |
| 55 | + |
| 56 | + if [ "$count" -gt 1 ]; then |
| 57 | + echo "Error: multiple libclang_rt.tsan.so found in $llvm_install_dir" |
| 58 | + echo "$tsan_dir" |
| 59 | + exit 1 |
| 60 | + fi |
| 61 | + |
| 62 | + # find path to archer library |
| 63 | + archer_dir="$(find "$llvm_install_dir" -type f -name "libarcher.so")" |
| 64 | + |
| 65 | + if [ -z "$archer_dir" ]; then |
| 66 | + echo "Error: unable to find libarcher.so in $llvm_install_dir" |
| 67 | + exit 1 |
| 68 | + fi |
| 69 | + |
| 70 | + count=$(echo "$archer_dir" | wc -l) |
| 71 | + |
| 72 | + if [ "$count" -gt 1 ]; then |
| 73 | + echo "Error: multiple libarcher.so found in $llvm_install_dir" |
| 74 | + echo "$archer_dir" |
| 75 | + exit 1 |
| 76 | + fi |
| 77 | + |
| 78 | + # make new suppression.txt file if it doesn't exist already |
| 79 | + if [ ! -f "suppression.txt" ]; then |
| 80 | + echo "called_from_lib:libomp.so |
| 81 | +called_from_lib:libtorch_python.so |
| 82 | +called_from_lib:libtorch_cpu.so |
| 83 | +called_from_lib:libtorch_cuda.so" > "./suppression.txt" |
| 84 | + fi |
| 85 | + |
| 86 | + env_args="LD_PRELOAD=\"$tsan_dir\" \ |
| 87 | +TRITON_ALWAYS_COMPILE=1 \ |
| 88 | +TRITON_SHARED_SANITIZER_TYPE=\"tsan\" \ |
| 89 | +TSAN_OPTIONS=\"ignore_noninstrumented_modules=0:suppressions=suppression.txt\" \ |
| 90 | +OMP_NUM_THREADS=16 \ |
| 91 | +OMP_TOOL_LIBRARIES=\"$archer_dir\" \ |
| 92 | +ARCHER_OPTIONS=\"verbose=1\"" |
| 93 | + |
| 94 | + # shift command line arguments to the left by 1 to account for "tsan" |
| 95 | + shift 1 |
45 | 96 | fi |
46 | 97 |
|
47 | 98 | # invoke python function |
|
0 commit comments