Skip to content

Commit cb86bd1

Browse files
committed
Skip UVM-heavy PatternGen seeds test under compute-sanitizer
Add cuda_python_test_helpers.under_compute_sanitizer() and use it to skip the slow patterngen seed test under sanitizer runs. Document the env-var coupling in ci/tools/env-vars.
1 parent e3183ab commit cb86bd1

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed

ci/tools/env-vars

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ elif [[ "${1}" == "test" ]]; then
6868
# We don't test compute-sanitizer on CTK<12 because backporting fixes is too much effort
6969
# We only test compute-sanitizer on python 3.12 arbitrarily; we don't need to use sanitizer on the entire matrix
7070
# Only local ctk installs have compute-sanitizer; there is no wheel for it
71+
# NOTE: If you change sanitizer-related env vars here (e.g., SETUP_SANITIZER,
72+
# SANITIZER_CMD, CUDA_INJECTION64_PATH), update
73+
# cuda_python_test_helpers.under_compute_sanitizer() accordingly.
7174
if [[ "${PY_VER}" == "3.12" && "${CUDA_VER}" != "11.8.0" && "${LOCAL_CTK}" == 1 && "${HOST_PLATFORM}" == linux* ]]; then
7275
echo "LATEST_CUDA_VERSION=$(bash .github/workflows/guess_latest.sh $TEST_CUDA_MAJOR)" >> $GITHUB_ENV
7376
SETUP_SANITIZER=1

cuda_core/tests/test_helpers.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
from helpers.latch import LatchKernel
1212
from helpers.logging import TimestampedLogger
1313

14+
from cuda_python_test_helpers import under_compute_sanitizer
15+
1416
ENABLE_LOGGING = False # Set True for test debugging and development
1517
NBYTES = 64
1618

@@ -66,6 +68,10 @@ def test_01():
6668
pass
6769

6870

71+
@pytest.mark.skipif(
72+
under_compute_sanitizer(),
73+
reason="Too slow under compute-sanitizer (UVM-heavy test).",
74+
)
6975
def test_patterngen_seeds():
7076
"""Test PatternGen with seed argument."""
7177
device = Device()

cuda_python_test_helpers/cuda_python_test_helpers/__init__.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"IS_WSL",
1717
"libc",
1818
"supports_ipc_mempool",
19+
"under_compute_sanitizer",
1920
]
2021

2122

@@ -37,6 +38,38 @@ def _detect_wsl() -> bool:
3738
libc = ctypes.CDLL("libc.so.6")
3839

3940

41+
def under_compute_sanitizer() -> bool:
42+
"""Return True if the current process is likely running under compute-sanitizer.
43+
44+
This is best-effort and primarily intended for CI, where the environment
45+
is configured by wrapper scripts.
46+
"""
47+
# Explicit override (if we ever want to set this directly in CI).
48+
if os.environ.get("CUDA_PYTHON_UNDER_SANITIZER") == "1":
49+
return True
50+
51+
# CI sets these when compute-sanitizer is enabled.
52+
if os.environ.get("SETUP_SANITIZER") == "1":
53+
return True
54+
55+
cmd = os.environ.get("SANITIZER_CMD", "")
56+
if "compute-sanitizer" in cmd or "cuda-memcheck" in cmd:
57+
return True
58+
59+
# Secondary signals: depending on how tests are invoked, the wrapper name may
60+
# appear in argv (e.g. `compute-sanitizer pytest ...`). This is not reliable
61+
# in general (often argv0 is `python`/`pytest`), but it's cheap and harmless.
62+
argv0 = os.path.basename(sys.argv[0]) if sys.argv else ""
63+
if argv0 in ("compute-sanitizer", "cuda-memcheck"):
64+
return True
65+
if any(("compute-sanitizer" in a or "cuda-memcheck" in a) for a in sys.argv):
66+
return True
67+
68+
# Another common indicator: sanitizer injectors are configured via env vars.
69+
inj = os.environ.get("CUDA_INJECTION64_PATH", "")
70+
return "compute-sanitizer" in inj or "cuda-memcheck" in inj
71+
72+
4073
@functools.cache
4174
def supports_ipc_mempool(device_id: Union[int, object]) -> bool:
4275
"""Return True if mempool IPC via POSIX file descriptor is supported.

0 commit comments

Comments
 (0)