[compiler-rt] [llvm] [compiler-rt] Add KCSAN inspired GPU ConcurrencySanitizer runtime (PR #207714)

Joseph Huber via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 14 17:59:34 PDT 2026


================
@@ -0,0 +1,59 @@
+//===-- sanitizer/gpu_sanitizer.h -------------------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// Shared ABI contract for GPU sanitizer reports shipped to the host over RPC.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef SANITIZER_GPU_SANITIZER_H
+#define SANITIZER_GPU_SANITIZER_H
+
+#include <stdint.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define SANITIZER_GPU_OPCODE(n) (('s' << 24) | (n))
+
+#define TSAN_GPU_REPORT_OPCODE SANITIZER_GPU_OPCODE(1)
+
+/// Access classification flags, mirroring the Linux kernel's KCSAN model.
+enum {
+  TSAN_GPU_ACCESS_WRITE = 1 << 0,    ///< Non-atomic write.
+  TSAN_GPU_ACCESS_COMPOUND = 1 << 1, ///< Read-modify-write.
+  TSAN_GPU_ACCESS_ATOMIC = 1 << 2,   ///< Atomic access.
+};
+
+/// Race report kinds.
+enum {
+  TSAN_GPU_DATA_RACE = 0,      ///< Conflicting access.
+  TSAN_GPU_UNKNOWN_ORIGIN = 1, ///< Watched value changed with no finder.
+  TSAN_GPU_INTRA_WAVE = 2,     ///< Conflict between lanes of the same wave.
+};
+
+/// The data associated with a single detected race.
+typedef struct __tsan_gpu_race {
----------------
jhuber6 wrote:

Okay, that goes into my question in the instrumentation pass. I re-used the existing stuff, but I'm thinking we'll want even more AMD specific handling, so it's likely best to change the name entirely. The question then becomes, should we make it a separate pass? It would be a lot of duplicated code, but it would make it a bit more straightforward.

https://github.com/llvm/llvm-project/pull/207714


More information about the llvm-commits mailing list