Thread Sanitizer 和 Intel OpenMP

huangapple go评论85阅读模式
英文:

Thread Sanitizer and Intel OpenMP

问题

We are using GCC and Intel OpenMP.

我知道GCC和GCC OpenMP的组合需要一个特殊的OpenMP版本(使用pthread接口而不是直接使用futex系统调用)。

能否使用Thread Sanitizer和GCC + Intel OpenMP?显然,我不能简单地重新编译Intel OpenMP库。

我已经开始了一个测试,但出现了如下错误:

  Atomic read of size 1 at 0x7fffec302980 by thread T4:
    #0 pthread_mutex_lock ../../../../libsanitizer/sanitizer_common/sanitizer_common_interceptors.inc:4250 (libtsan.so.0+0x52d1a)
    #1 __kmp_resume_64 <null> (libiomp5.so+0xb7ae3)

  Previous write of size 1 at 0x7fffec302980 by thread T7:
    #0 pthread_mutex_init ../../../../libsanitizer/tsan/tsan_interceptors_posix.cpp:1227 (libtsan.so.0+0x4c343)
    #1 __kmp_suspend_64 <null> (libiomp5.so+0xb587b)

  Thread T4 (tid=15590, running) created by main thread at:
    #0 pthread_create ../../../../libsanitizer/tsan/tsan_interceptors_posix.cpp:969 (libtsan.so.0+0x5ec85)
    #1 __kmp_create_worker <null> (libiomp5.so+0xb1a34)

我有点假设带有__kmp前缀的内容应该是安全的,这个错误是因为Thread Sanitizer没有封装任何__kmp函数。

英文:

We are using GCC and Intel OpenMP.

I know that the combination of GCC and GCC OpenMP needs a special build of OpenMP (to use pthread interfaces rather than directly use the futex system call).

Is it possible to use Thread Sanitizer and GCC + Intel OpenMP? Obviously I can't just simply recompile the Intel OpenMP library.

I've started a test and I'm getting errors like

WARNING: ThreadSanitizer: data race (pid=15551)
  Atomic read of size 1 at 0x7fffec302980 by thread T4:
    #0 pthread_mutex_lock ../../../../libsanitizer/sanitizer_common/sanitizer_common_interceptors.inc:4250 (libtsan.so.0+0x52d1a)
    #1 __kmp_resume_64 <null> (libiomp5.so+0xb7ae3)

  Previous write of size 1 at 0x7fffec302980 by thread T7:
    #0 pthread_mutex_init ../../../../libsanitizer/tsan/tsan_interceptors_posix.cpp:1227 (libtsan.so.0+0x4c343)
    #1 __kmp_suspend_64 <null> (libiomp5.so+0xb587b)

  Thread T4 (tid=15590, running) created by main thread at:
    #0 pthread_create ../../../../libsanitizer/tsan/tsan_interceptors_posix.cpp:969 (libtsan.so.0+0x5ec85)
    #1 __kmp_create_worker <null> (libiomp5.so+0xb1a34)

I kind of assume that anything with the __kmp prefix should be safe, and this error is because Thread Sanitizer does not encapsulate any __kmp functions.

答案1

得分: 1

First, TSan by it's own does not understand OpenMP synchronization like barriers or task dependencies. We developed libarcher as part of LLVM to feed this information into TSan.
如果单独使用TSan,它无法理解OpenMP的同步,比如栅栏或任务依赖。我们在LLVM的一部分中开发了libarcher,以将这些信息传递给TSan。

If you compile a code with clang -fopenmp -fsanitize=thread, libarcher will automatically be loaded and support TSan. (verify successful loading by exporting export ARCHER_OPTIONS=verbose=true).
如果使用clang -fopenmp -fsanitize=thread编译代码,libarcher将自动加载并支持TSan。(通过导出export ARCHER_OPTIONS=verbose=true来验证加载是否成功)。

libarcher needs OMPT support in the OpenMP runtime, which libgomp does not provide yet.
libarcher需要OpenMP运行时中的OMPT支持,而libgomp目前尚不提供。

libarcher also works with newer Intel OpenMP runtimes (2020+), by explicitly loading it as an OMPT tool: export OMP_TOOL_LIBRARIES=<path-to>/libarcher.so
libarcher还与较新的Intel OpenMP运行时(2020+)兼容,通过显式加载它作为OMPT工具:export OMP_TOOL_LIBRARIES=<path-to>/libarcher.so

To get libarcher you can build from source.
要获取libarcher,你可以从源代码构建。

The source code is contained in the LLVM/OpenMP project:
源代码包含在LLVM/OpenMP项目中:
https://github.com/llvm/llvm-project/releases/download/llvmorg-16.0.6/openmp-16.0.6.src.tar.xz

tar xf openmp-16.0.6.src.tar.xz
cd openmp-16.0.6
mkdir build
cd build
cmake .. -DCMAKE_BUILD_TYPE=Release -DOPENMP_ENABLE_LIBOMPTARGET=False -DCMAKE_INSTALL_PREFIX=$PWD/install
make -j install

should install the code to openmp-16.0.6/build/install/, so libarcher should be in openmp-16.0.6/build/install/lib/libarcher.so
应该将代码安装到openmp-16.0.6/build/install/,因此libarcher应该位于openmp-16.0.6/build/install/lib/libarcher.so

Second, for the issue of false reports from OpenMP runtime code, I suggest
其次,对于OpenMP运行时代码的虚假报告问题,我建议:

export TSAN_OPTIONS='ignore_noninstrumented_modules=1'

This will disable the detection of any data race caused from non-instrumented code. So, if you link to other non-instrumented libraries (e.g. BLAS) they will also be ignored. The picture TSan gets for such libraries is limited to intercepted libc functions anyways.
这将禁用对非受仪器监测的代码引起的任何数据竞争的检测。因此,如果你链接到其他非受仪器监测的库(例如BLAS),它们也将被忽略。对于这种类型的库,TSan获取的信息本来就受限于被拦截的libc函数。

英文:

First, TSan by it's own does not understand OpenMP synchronization like barriers or task dependencies. We developed libarcher as part of LLVM to feed this information into TSan.
If you compile a code with clang -fopenmp -fsanitize=thread, libarcher will automatically be loaded and support TSan. (verify successful loading by exporting export ARCHER_OPTIONS=verbose=true).
libarcher needs OMPT support in the OpenMP runtime, which libgomp does not provide yet.

libarcher also works with newer Intel OpenMP runtimes (2020+), by explicitly loading it as an OMPT tool: export OMP_TOOL_LIBRARIES=<path-to>/libarcher.so
To get libarcher you can build from source.
The source code is contained in the LLVM/OpenMP project:
https://github.com/llvm/llvm-project/releases/download/llvmorg-16.0.6/openmp-16.0.6.src.tar.xz

tar xf openmp-16.0.6.src.tar.xz
cd openmp-16.0.6
mkdir build
cd build
cmake .. -DCMAKE_BUILD_TYPE=Release -DOPENMP_ENABLE_LIBOMPTARGET=False -DCMAKE_INSTALL_PREFIX=$PWD/install
make -j install

should install the code to openmp-16.0.6/build/install/, so libarcher should be in openmp-16.0.6/build/install/lib/libarcher.so

Second, for the issue of false reports from OpenMP runtime code, I suggest

export TSAN_OPTIONS='ignore_noninstrumented_modules=1'

This will disable the detection of any data race caused from non-instrumented code. So, if you link to other non-instrumented libraries (e.g. BLAS) they will also be ignored. The picture TSan gets for such libraries is limited to intercepted libc functions anyways.

huangapple
  • 本文由 发表于 2023年6月26日 18:09:19
  • 转载请务必保留本文链接:https://go.coder-hub.com/76555671.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定