[all-commits] [llvm/llvm-project] 030725: [compiler-rt] Add AMDGPU Device UndefinedBehaviorS...

Joseph Huber via All-commits all-commits at lists.llvm.org
Tue Sep 8 19:53:39 PDT 2026


  Branch: refs/heads/users/jhuber6/ubsan-runtime
  Home:   https://github.com/llvm/llvm-project
  Commit: 030725bd157d39384ef00eb8be6dc69a2d8a92e8
      https://github.com/llvm/llvm-project/commit/030725bd157d39384ef00eb8be6dc69a2d8a92e8
  Author: Joseph Huber <huberjn at outlook.com>
  Date:   2026-09-08 (Tue, 08 Sep 2026)

  Changed paths:
    M compiler-rt/cmake/config-ix.cmake
    M compiler-rt/lib/CMakeLists.txt
    M compiler-rt/lib/sanitizer_common/sanitizer_symbolizer.h
    M compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_libcdep.cpp
    M compiler-rt/lib/ubsan/CMakeLists.txt
    A compiler-rt/lib/ubsan/device/CMakeLists.txt
    A compiler-rt/lib/ubsan/device/hsa.h
    A compiler-rt/lib/ubsan/device/ubsan_device.h
    A compiler-rt/lib/ubsan/device/ubsan_device_hsa.cpp
    A compiler-rt/lib/ubsan/device/ubsan_device_hsa.h
    A compiler-rt/lib/ubsan/device/ubsan_device_hsa_interceptors.cpp
    A compiler-rt/lib/ubsan/device/ubsan_device_report.cpp
    A compiler-rt/lib/ubsan/device/ubsan_device_rpc.cpp
    A compiler-rt/lib/ubsan/device/ubsan_device_rpc.h
    A compiler-rt/lib/ubsan/device/ubsan_device_symbolize.cpp
    A compiler-rt/lib/ubsan/device/ubsan_device_symbolize.h
    A compiler-rt/lib/ubsan/ubsan_device.cpp
    A compiler-rt/lib/ubsan/ubsan_device_checks.inc
    A compiler-rt/lib/ubsan/ubsan_device_packet.h
    M compiler-rt/lib/ubsan/ubsan_diag.cpp
    M compiler-rt/lib/ubsan/ubsan_diag.h
    M compiler-rt/lib/ubsan/ubsan_handlers.cpp
    A compiler-rt/lib/ubsan/ubsan_handlers_internal.h
    M compiler-rt/lib/ubsan/ubsan_interface.inc
    M compiler-rt/lib/ubsan/ubsan_value.h
    M compiler-rt/test/CMakeLists.txt
    A compiler-rt/test/ubsan/AMDGPU/abort.hip
    A compiler-rt/test/ubsan/AMDGPU/dedup.hip
    A compiler-rt/test/ubsan/AMDGPU/host-and-device.hip
    A compiler-rt/test/ubsan/AMDGPU/lit.local.cfg.py
    A compiler-rt/test/ubsan/AMDGPU/openmp-overflow.cpp
    A compiler-rt/test/ubsan/AMDGPU/overflow.hip
    A compiler-rt/test/ubsan/AMDGPU/shift.hip
    M compiler-rt/test/ubsan/CMakeLists.txt
    A compiler-rt/test/ubsan/Inputs/hip.h
    M compiler-rt/test/ubsan/lit.common.cfg.py
    M compiler-rt/test/ubsan/lit.site.cfg.py.in
    M llvm/utils/gn/secondary/compiler-rt/lib/ubsan/BUILD.gn

  Log Message:
  -----------
  [compiler-rt] Add AMDGPU Device UndefinedBehaviorSanitizer runtime

Summary:
This adds support for full UBSan on the AMDGPU target. The GPU build of
`compiler-rt` will now build `libclang_rt.ubsan_standalone.a` and the
host build will now provide `libclang_rt.ubsan_device.a` for the
host-side formatting.

The **core** approach is to simply gather arguments from the device and
replay them on the host. The RPC interface acts as the narrow shim to
pass data between the CPU and GPU.

The changes to the core runtime are kept minimal, only exposing a few
needed hooks to re-run and symbolize reports coming from an external
caller. The device archive is a side-library which will only be present
for GPU offloading builds.

Putting this in `compiler-rt` via interceptors avoids an ABI edge
between many consumers, (OpenMP, HIP, Pytorch, etc). The runtime code is
specifically built around HSA, but as more features grow this could be
refactored into a shim layer for SPIR-V / CUDA and factored out to a
common sanitizer utility. Leaving that as future work.

```console
clang -xhip -fsanitize=undefined --offload-arch=native app.hip
clang -fopenmp -fsanitize=undefined --offload-arch=native app.cpp
```

---

Tested using the HIP suite in https://github.com/ORNL/HeCBench. Ran
against 162 programs on my gfx1030 vs an unsanitized `-O3` baseline:

| Metric            | Geomean |
| ----------------- | ------: |
| Kernel time       |   2.12x |
| Wall time         |   1.58x |
| Device image size |   3.22x |
| Host binary size  |  20.43x |
| Compile time      |   1.19x |

| Resource               | Change |
| ---------------------- | -----: |
| VGPR                   |    +19 |
| SGPR                   |    +32 |
| Scratch (B/lane)       | 52/140 |
| Occupancy (waves/SIMD) | 11/140 |

The tool identified three instances of UB on the HIP device with zero
false positives.

```
atomicAggregate (6 reports)
Device: main.cu:29 signed overflow -2147483648 - 1 (int)

background-subtract (6 reports)
Device: main.cu:75 259.48 does not fit in unsigned char

particlefilter (39 reports)
Device: kernel_likelihood.h:37 signed overflow in the LCG (1103515245 * …)
```


  Commit: b311408af229d2cbd1ddf32f0f40e3d9d71d7f9f
      https://github.com/llvm/llvm-project/commit/b311408af229d2cbd1ddf32f0f40e3d9d71d7f9f
  Author: Joseph Huber <huberjn at outlook.com>
  Date:   2026-09-08 (Tue, 08 Sep 2026)

  Changed paths:
    M compiler-rt/cmake/caches/AMDGPU.cmake
    M compiler-rt/lib/CMakeLists.txt
    M compiler-rt/lib/ubsan/device/ubsan_device_hsa.cpp
    M compiler-rt/lib/ubsan/device/ubsan_device_report.cpp
    M compiler-rt/lib/ubsan/device/ubsan_device_rpc.cpp
    A compiler-rt/test/ubsan/AMDGPU/overflow-i128.hip

  Log Message:
  -----------
  Comments, fix cache, fix failure with Die(), properly ignore i128 for now


  Commit: cc53b26eee88985bf11683377215662d2cab4848
      https://github.com/llvm/llvm-project/commit/cc53b26eee88985bf11683377215662d2cab4848
  Author: Joseph Huber <huberjn at outlook.com>
  Date:   2026-09-08 (Tue, 08 Sep 2026)

  Changed paths:
    M compiler-rt/lib/ubsan/CMakeLists.txt
    R compiler-rt/lib/ubsan/device/CMakeLists.txt
    R compiler-rt/lib/ubsan/device/hsa.h
    R compiler-rt/lib/ubsan/device/ubsan_device.h
    R compiler-rt/lib/ubsan/device/ubsan_device_hsa.cpp
    R compiler-rt/lib/ubsan/device/ubsan_device_hsa.h
    R compiler-rt/lib/ubsan/device/ubsan_device_hsa_interceptors.cpp
    R compiler-rt/lib/ubsan/device/ubsan_device_report.cpp
    R compiler-rt/lib/ubsan/device/ubsan_device_rpc.cpp
    R compiler-rt/lib/ubsan/device/ubsan_device_rpc.h
    R compiler-rt/lib/ubsan/device/ubsan_device_symbolize.cpp
    R compiler-rt/lib/ubsan/device/ubsan_device_symbolize.h
    A compiler-rt/lib/ubsan/offload/CMakeLists.txt
    A compiler-rt/lib/ubsan/offload/hsa.h
    A compiler-rt/lib/ubsan/offload/ubsan_offload.h
    A compiler-rt/lib/ubsan/offload/ubsan_offload_hsa.cpp
    A compiler-rt/lib/ubsan/offload/ubsan_offload_hsa.h
    A compiler-rt/lib/ubsan/offload/ubsan_offload_hsa_interceptors.cpp
    A compiler-rt/lib/ubsan/offload/ubsan_offload_report.cpp
    A compiler-rt/lib/ubsan/offload/ubsan_offload_rpc.cpp
    A compiler-rt/lib/ubsan/offload/ubsan_offload_rpc.h
    A compiler-rt/lib/ubsan/offload/ubsan_offload_symbolize.cpp
    A compiler-rt/lib/ubsan/offload/ubsan_offload_symbolize.h
    R compiler-rt/lib/ubsan/ubsan_device.cpp
    R compiler-rt/lib/ubsan/ubsan_device_checks.inc
    R compiler-rt/lib/ubsan/ubsan_device_packet.h
    M compiler-rt/lib/ubsan/ubsan_diag.cpp
    M compiler-rt/lib/ubsan/ubsan_diag.h
    M compiler-rt/lib/ubsan/ubsan_handlers.cpp
    M compiler-rt/lib/ubsan/ubsan_interface.inc
    A compiler-rt/lib/ubsan/ubsan_offload.cpp
    A compiler-rt/lib/ubsan/ubsan_offload_checks.inc
    A compiler-rt/lib/ubsan/ubsan_offload_packet.h

  Log Message:
  -----------
  [compiler-rt] Rename ubsan_device to ubsan_offload

The host interceptor and GPU handler library serve offload, not a
generic device sanitizer. Keep the Apple add_ubsan_device_testsuite name.


  Commit: 1285fea73629eb29018efb2fde9437e4601f33bf
      https://github.com/llvm/llvm-project/commit/1285fea73629eb29018efb2fde9437e4601f33bf
  Author: Joseph Huber <huberjn at outlook.com>
  Date:   2026-09-08 (Tue, 08 Sep 2026)

  Changed paths:
    M compiler-rt/test/ubsan/CMakeLists.txt

  Log Message:
  -----------
  Remove CMake omp dep


Compare: https://github.com/llvm/llvm-project/compare/891e2843f336...1285fea73629

To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list