From ed264e5dc5fcbc352c209f6ab9c5a56d95670b8f Mon Sep 17 00:00:00 2001 From: Drake Stapleton Date: Sat, 31 Oct 2026 01:36:32 -0500 Subject: [PATCH 1/2] max-cpu: hide the GPU; MAX 26.7.0 Graph() opens a CUDA context when one is visible The rerun of run.sh at 6ec6dab7 on 2026-10-31 exited 1: every check and negative control passed, but the last measure child failed in Accelerator() with CUDA_ERROR_OUT_OF_MEMORY. Graph() calls _populate_device_info_mapping, which creates an Accelerator() whenever accelerator_count() > 0, even for a graph built only on DeviceRef.CPU(). The 'nothing here opens the GPU' claim was false. run.sh and mogg-cache-repro.sh export CUDA_VISIBLE_DEVICES=, omega_max.py exits 2 while an accelerator is visible, and the evidence README says what happened. Rerun with the GPU hidden: OMEGA MAX CPU: PASS, exit 0. --- evidence/MAX-CPU/README.md | 13 +++++++++++-- max-cpu/mogg-cache-repro.sh | 1 + max-cpu/omega_max.py | 12 +++++++++++- max-cpu/run.sh | 4 +++- 4 files changed, 26 insertions(+), 4 deletions(-) diff --git a/evidence/MAX-CPU/README.md b/evidence/MAX-CPU/README.md index 6895de9..e3a7f15 100644 --- a/evidence/MAX-CPU/README.md +++ b/evidence/MAX-CPU/README.md @@ -1,8 +1,17 @@ # MAX CPU route: an Omega kernel as a MAX 26.7.0 graph custom op Status: **EXERCISED(host CPU)** on the DGX Spark's Grace aarch64 host, 2026-10-30/31. This is a -host-CPU run, not a hardware qualification and not a GPU result. Nothing here opened the GPU: -every graph is built on `DeviceRef.CPU()` and the session is `InferenceSession(devices=[CPU()])`. +host-CPU run, not a hardware qualification and not a GPU result. Every graph is built on +`DeviceRef.CPU()` and the session is `InferenceSession(devices=[CPU()])`, so no kernel ran on the +GPU. That alone does not keep the GPU closed: MAX 26.7.0 `Graph()` (`_populate_device_info_mapping`) +creates an `Accelerator()`, a CUDA context, whenever `accelerator_count() > 0`. The run of record +did not hide the GPU, so [INFERENCE] each of its graph processes opened a GB10 context. On +2026-10-31 a rerun at `6ec6dab7` exited 1 for that reason: the last `measure` child (matmul +256x256x256 warm) failed in `Accelerator()` with `CUDA_ERROR_OUT_OF_MEMORY` while the GPU was busy; +every check and negative control had passed. `run.sh` and `mogg-cache-repro.sh` now export +`CUDA_VISIBLE_DEVICES=` and `omega_max.py` exits 2 while an accelerator is visible. With the GPU +hidden, the 2026-10-31 rerun exited 0 (`OMEGA MAX CPU: PASS`, 16 of 16 measurements) and the warm +omega 16x16x8 `maxrss_kib` was 495648 against 589472 in the GPU-visible rerun. ## What runs diff --git a/max-cpu/mogg-cache-repro.sh b/max-cpu/mogg-cache-repro.sh index b543280..4a94a86 100755 --- a/max-cpu/mogg-cache-repro.sh +++ b/max-cpu/mogg-cache-repro.sh @@ -5,6 +5,7 @@ # reports what it saw, it does not gate anything. # TMPDIR=/dev/shm taskset -c 10-14 nice -n 19 ionice -c3 max-cpu/mogg-cache-repro.sh set -eu +export CUDA_VISIBLE_DEVICES= # MAX 26.7.0 Graph() opens a visible GPU; see run.sh cd "$(dirname "$0")/.." MAXPY=${MAXPY:-$HOME/workspace/maxinterop/venv/bin/python} BUILD=${BUILD:-/dev/shm/omega-max-cpu} diff --git a/max-cpu/omega_max.py b/max-cpu/omega_max.py index a8d8f69..515d1e8 100644 --- a/max-cpu/omega_max.py +++ b/max-cpu/omega_max.py @@ -7,7 +7,9 @@ Subcommands (run with the MAX venv python, see max-cpu/run.sh): measure one op/shape in this process: cold start, warm latencies, peak RSS measure-all spawns one `measure` child per (op, shape, cache state) -Every graph runs on DeviceRef.CPU() only. Exit 0 = the expected outcome was observed. +Every graph runs on DeviceRef.CPU() only, and main() refuses (exit 2) while an accelerator is +visible, because MAX 26.7.0 Graph() otherwise opens a CUDA context. Exit 0 = the expected +outcome was observed. """ import argparse @@ -306,6 +308,14 @@ def main(): s.add_argument("--cache", default="fresh") s.add_argument("--t0", type=int, required=True) a = p.parse_args() + # MAX 26.7.0 Graph() creates an Accelerator() (a CUDA context) whenever one is visible, even + # for an all-CPU graph. Refuse unless the GPU is hidden: run.sh exports CUDA_VISIBLE_DEVICES=. + from max.driver import accelerator_count + + if accelerator_count() != 0: + print("omega_max.py: an accelerator is visible; export CUDA_VISIBLE_DEVICES= " + "(this harness must not open the GPU)", file=sys.stderr) + sys.exit(2) fn = {"check": cmd_check, "neg-shape": cmd_neg_shape, "neg-load": cmd_neg_load, "measure": cmd_measure, "measure-all": cmd_measure_all}[a.cmd] sys.exit(fn(a)) diff --git a/max-cpu/run.sh b/max-cpu/run.sh index 5e1baa1..55b337c 100755 --- a/max-cpu/run.sh +++ b/max-cpu/run.sh @@ -1,8 +1,10 @@ #!/bin/sh # Reproduce the MAX CPU route for the Omega matmul custom op (evidence/MAX-CPU/README.md). # Run from anywhere, pinned: TMPDIR=/dev/shm taskset -c 10-14 nice -n 19 ionice -c3 max-cpu/run.sh -# CPU only: every graph is built on DeviceRef.CPU(); nothing here opens the GPU. +# CPU only: every graph is built on DeviceRef.CPU(). MAX 26.7.0 Graph() still opens a CUDA +# context when a GPU is visible, so the GPU is hidden here and omega_max.py refuses otherwise. set -eu +export CUDA_VISIBLE_DEVICES= cd "$(dirname "$0")/.." MAXPY=${MAXPY:-$HOME/workspace/maxinterop/venv/bin/python} OMEGA_REPO=${OMEGA_REPO:-$HOME/workspace/omega} From 5f7492fff138a931599e467c6f50eade1e857ade Mon Sep 17 00:00:00 2001 From: Drake Stapleton Date: Sat, 31 Oct 2026 02:14:54 -0500 Subject: [PATCH 2/2] max-cpu: cores 5-9 in run instructions; mogg-cache-repro exits 0 as documented --- evidence/MAX-CPU/README.md | 6 +++--- max-cpu/mogg-cache-repro.sh | 5 +++-- max-cpu/run.sh | 2 +- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/evidence/MAX-CPU/README.md b/evidence/MAX-CPU/README.md index e3a7f15..60edcea 100644 --- a/evidence/MAX-CPU/README.md +++ b/evidence/MAX-CPU/README.md @@ -45,8 +45,8 @@ the same f32 values. ## Reproduce ```sh -TMPDIR=/dev/shm taskset -c 10-14 nice -n 19 ionice -c3 max-cpu/run.sh # ~11 min -TMPDIR=/dev/shm taskset -c 10-14 nice -n 19 ionice -c3 max-cpu/mogg-cache-repro.sh # after run.sh +TMPDIR=/dev/shm taskset -c 5-9 nice -n 19 ionice -c3 max-cpu/run.sh # ~11 min +TMPDIR=/dev/shm taskset -c 5-9 nice -n 19 ionice -c3 max-cpu/mogg-cache-repro.sh # after run.sh ``` `run.sh` extracts both omc stages from git objects and checks their sha256, builds the library and @@ -112,7 +112,7 @@ ExecutionEngine; the MAX kernel JIT does not resolve symbols from the process im `LD_PRELOAD` gave the same error. The Mojo FFI docs at the pin (c-ffi.mdx, Limitations) say `external_call()` cannot load dynamic libraries and point to `OwnedDLHandle`. -## Measurements (EXERCISED(host CPU), `taskset -c 10-14`) +## Measurements (EXERCISED(host CPU), `taskset -c 10-14`; historical run of record. Cores 10-14 are reserved on this host now: rerun on 5-9) `measure-all` starts one child process per series. `cold_ns` runs from process start to the end of the first execute (import, graph build, compile, load, first call); `fresh` = empty diff --git a/max-cpu/mogg-cache-repro.sh b/max-cpu/mogg-cache-repro.sh index 4a94a86..02d599a 100755 --- a/max-cpu/mogg-cache-repro.sh +++ b/max-cpu/mogg-cache-repro.sh @@ -3,7 +3,7 @@ # source changes, when the package path and MODULAR_CACHE_DIR stay the same. Needs max-cpu/run.sh # to have built $BUILD first (lib/ and extcall/kernels). Prints one line per step; exit 0 always # reports what it saw, it does not gate anything. -# TMPDIR=/dev/shm taskset -c 10-14 nice -n 19 ionice -c3 max-cpu/mogg-cache-repro.sh +# TMPDIR=/dev/shm taskset -c 5-9 nice -n 19 ionice -c3 max-cpu/mogg-cache-repro.sh set -eu export CUDA_VISIBLE_DEVICES= # MAX 26.7.0 Graph() opens a visible GPU; see run.sh cd "$(dirname "$0")/.." @@ -28,4 +28,5 @@ step 3-fixed-cacheB-fresh "$R/pkg/kernels" "$R/cacheB" cp max-cpu/kernels/__init__.mojo "$R/other/kernels/" # the fixed glue, another path step 4-fixed-otherpath-cacheA "$R/other/kernels" "$R/cacheA" sha256sum "$R/pkg/kernels/__init__.mojo" "$BUILD/extcall/kernels/__init__.mojo" -diff "$R/cacheA-after-1.txt" "$R/cacheA-after-2.txt" >/dev/null && echo "cacheA: no new files in step 2" +if diff "$R/cacheA-after-1.txt" "$R/cacheA-after-2.txt" >/dev/null; then echo "cacheA: no new files in step 2" +else echo "cacheA: step 2 added $(comm -13 "$R/cacheA-after-1.txt" "$R/cacheA-after-2.txt" | wc -l) files"; fi diff --git a/max-cpu/run.sh b/max-cpu/run.sh index 55b337c..2bf55f8 100755 --- a/max-cpu/run.sh +++ b/max-cpu/run.sh @@ -1,6 +1,6 @@ #!/bin/sh # Reproduce the MAX CPU route for the Omega matmul custom op (evidence/MAX-CPU/README.md). -# Run from anywhere, pinned: TMPDIR=/dev/shm taskset -c 10-14 nice -n 19 ionice -c3 max-cpu/run.sh +# Run from anywhere, pinned: TMPDIR=/dev/shm taskset -c 5-9 nice -n 19 ionice -c3 max-cpu/run.sh # CPU only: every graph is built on DeviceRef.CPU(). MAX 26.7.0 Graph() still opens a CUDA # context when a GPU is visible, so the GPU is hidden here and omega_max.py refuses otherwise. set -eu