-
Notifications
You must be signed in to change notification settings - Fork 52
Add: opt-in compiler sanitizers (ASAN/UBSan + TSAN) for host targets #915
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| name: Sanitizers | ||
|
|
||
| # Nightly sanitizer sweep of main. Kept in its OWN workflow (not ci.yml) so the | ||
| # schedule trigger fires ONLY these jobs — adding `schedule` to ci.yml would run | ||
| # every unguarded job (pre-commit, ut, packaging, self-hosted hardware) on cron. | ||
| # | ||
| # ASAN and TSAN are separate, mutually-exclusive builds; both instrument only | ||
| # host-compiled code (sim runtime + kernels + orchestration), and sim unifies on | ||
| # g++-15 so the preloaded runtime matches the kernels' ABI. Not a PR gate: too | ||
| # slow (TSAN ~5-15x) and subject to the pre-existing sim-oversubscription flake, | ||
| # so a generous per-session timeout + manual rerun is expected. detect_leaks=0 | ||
| # until LSan suppressions exist for the device custom arenas. | ||
| on: | ||
| schedule: | ||
| - cron: "0 18 * * *" # 02:00 Beijing | ||
|
|
||
| concurrency: | ||
| group: sanitizers-${{ github.ref }} | ||
| cancel-in-progress: true | ||
|
|
||
| env: | ||
| PTO_ISA_COMMIT: ddafa8da9c760ecd13fe9fe2833d6ee55fb20bd8 | ||
|
|
||
| jobs: | ||
| sanitizer-sim: | ||
| runs-on: ubuntu-latest | ||
| timeout-minutes: 90 | ||
| strategy: | ||
| fail-fast: false | ||
| matrix: | ||
| sanitizer: [asan, tsan] | ||
| platform: [a2a3sim, a5sim] | ||
|
|
||
| steps: | ||
| - name: Checkout repository | ||
| uses: actions/checkout@v5 | ||
|
|
||
| - name: Set up C++ compiler | ||
| run: | | ||
| sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test | ||
| sudo apt-get update | ||
| sudo apt-get install -y ninja-build graphviz | ||
| sudo apt-get install -y g++-15 || sudo apt-get install -y g++ | ||
| if ! command -v g++-15; then sudo ln -s "$(which g++)" /usr/local/bin/g++-15; fi | ||
|
|
||
| - name: Set up Python | ||
| uses: actions/setup-python@v6 | ||
| with: | ||
| python-version: '3.10' | ||
|
|
||
| - name: Install with sanitizer | ||
| run: | | ||
| pip install torch --index-url https://download.pytorch.org/whl/cpu | ||
| # --no-cache-dir so pip rebuilds rather than reusing a non-sanitizer wheel. | ||
| pip install --no-cache-dir \ | ||
| --config-settings=cmake.define.SIMPLER_SANITIZER=${{ matrix.sanitizer }} '.[test]' | ||
|
|
||
| - name: Run sanitized scene tests (${{ matrix.sanitizer }}, ${{ matrix.platform }}) | ||
| run: | | ||
| # Sim unifies host compilation on g++-15, so preload g++-15's runtime. | ||
| LIB=$(g++-15 -print-file-name=lib${{ matrix.sanitizer }}.so) | ||
| LD_PRELOAD="$LIB" \ | ||
| ASAN_OPTIONS=detect_leaks=0:abort_on_error=1:halt_on_error=1 \ | ||
| UBSAN_OPTIONS=halt_on_error=1:print_stacktrace=1 \ | ||
| TSAN_OPTIONS=halt_on_error=1 \ | ||
| pytest examples tests/st --platform ${{ matrix.platform }} --device 0-15 \ | ||
| --sanitizer ${{ matrix.sanitizer }} -v --pto-session-timeout 1200 \ | ||
| --pto-isa-commit ${{ env.PTO_ISA_COMMIT }} --clone-protocol https --require-pto-isa |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| # Copyright (c) PyPTO Contributors. | ||
| # This program is free software, you can redistribute it and/or modify it under the terms and conditions of | ||
| # CANN Open Software License Agreement Version 2.0 (the "License"). | ||
| # Please refer to the License for details. You may not use this file except in compliance with the License. | ||
| # THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, | ||
| # INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. | ||
| # See LICENSE in the root of the software repository for the full text of the License. | ||
| # ----------------------------------------------------------------------------------------------------------- | ||
| # | ||
| # Shared compiler-sanitizer helper. | ||
| # | ||
| # `SIMPLER_SANITIZERS` is a comma-separated `-fsanitize` token list (e.g. | ||
| # "address,undefined" or "thread"), passed straight through to the compiler. | ||
| # Empty (the default) makes every call below a no-op, so ordinary builds are | ||
| # byte-for-byte unchanged. | ||
| # | ||
| # Apply ONLY to host-compiled targets — the sim runtime/kernels/orchestration | ||
| # and the onboard *host* runtime. NEVER call it for device toolchains (ccec for | ||
| # AICore, aarch64 cross for the AICPU): they run on the NPU and cannot carry a | ||
| # host sanitizer runtime. | ||
| # | ||
| # `-O1` (the last `-O` wins, overriding an earlier `-O3`) plus frame pointers | ||
| # keep sanitizer stack traces from being inlined away — the standard | ||
| # good-report settings. | ||
|
|
||
| function(simpler_apply_sanitizers tgt) | ||
| if(NOT SIMPLER_SANITIZERS) | ||
| return() | ||
| endif() | ||
| target_compile_options(${tgt} PRIVATE | ||
| -fsanitize=${SIMPLER_SANITIZERS} | ||
| -fno-omit-frame-pointer | ||
| -O1) | ||
| target_link_options(${tgt} PRIVATE -fsanitize=${SIMPLER_SANITIZERS}) | ||
| # TSAN can't model standalone std::atomic_thread_fence and warns about it; | ||
| # the AICPU target compiles with -Werror, which would make that warning | ||
| # fatal. Keep the warning visible but non-fatal — the limitation is known | ||
| # and acceptable (fence-ordered accesses just aren't TSAN-tracked there). | ||
| if(SIMPLER_SANITIZERS MATCHES "thread") | ||
| target_compile_options(${tgt} PRIVATE -Wno-error=tsan) | ||
| endif() | ||
| endfunction() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.