[PROPOSAL] Add support for dynamic code analysis (Sanitizers)#18303
[PROPOSAL] Add support for dynamic code analysis (Sanitizers)#18303luotao1 merged 3 commits intoPaddlePaddle:developfrom
Conversation
|
What's the difference between Sanitizers and gperftools, we use |
|
"Sanitizers" is a family of dynamic testing tools built into C++ compilers (Clang and GCC):
Sanitizers are fast, e.g. Valgrind introduced 20x and more slowdown; *San is ~2x slowdown, 1.5x-3x memory overhead. In paddle/build/third_party there are some projects which use Sanitizers, e.g. |
|
Thanks very much for your detail explanation! |
|
Yes, it is enough to add only one flag to CMake: Important: only one Sanitizer is allowed in compile time.
Hint: export an additional environment variable to limit the number of error messages before you run PaddlePaddle, e.g. for AddressSanitizer |
|
@luotao1 Please don't merge this PR yet, we're still testing Sanitizers in PaddlePaddle. |
CMakeLists.txt
Outdated
There was a problem hiding this comment.
Could you remove the option, and write like CMAKE_BUILD_TYPE
Lines 83 to 87 in 047bba8
There was a problem hiding this comment.
You don't need Sanitizers.cmake file to include Sanitizers support in PaddlePaddle, it is built in gcc compiler.
I moved many options to one option SANITIZER_TYPE.
There was a problem hiding this comment.
it is built in gcc compiler.
Does gcc48 support it?
There was a problem hiding this comment.
Yes, it's a part of GCC starting from version 4.8
a7b79b6 to
9064e57
Compare
|
Now, to use sanitizer we have only one CMake option Notice: |
test=develop
test=develop
dfea473 to
3ac4715
Compare
|
@zhupengyang Could you verify the build command in #18303 (comment)? |
commit id: 3ac4715 Verification conclusion: the build command is workable. |


This PR adds support for Sanitizers:
These Sanitizers are based on compiler instrumentation, therefore a rebuild is required in order to use these tools. Sanitizers are implemented in Clang starting 3.1 and GCC starting 4.8 and supported on Linux x86_64 machines. AddressSanitizer and UndefinedBehaviorSanitizer are also available on macOS.
Usage
You can enable the Sanitizers with SANITIZE_ADDRESS, SANITIZE_LEAK, SANITIZE_MEMORY, SANITIZE_THREAD options in your CMake configuration. You can do this by passing e.g.
-DSANITIZE_ADDRESS=ONon your command line. The Sanitizers check your program, while it's running.Only one Sanitizer is allowed in compile time.
Usefully option is
halt_on_errore.g. for ThreadSanitizerexport TSAN_OPTIONS="halt_on_error=1"to exit after first reported error.IMO: maybe it would be nice to connect PaddlePaddle CI with these Sanitizers in future.
Documentation
Comprehensive documentation is here https://github.com/google/sanitizers