omega-bridge
Omega-first language interoperability: checked conversion backends and native language bindings
Brought by drakestapleton
omega-bridge / docs / max / MAX-26.7-PROBE-PLAN.md
| 1 | <!-- Copied from the MAX 26.7.0 analysis checkout on 2026-10-23. The raw |
| 2 | command outputs and verbatim main-branch reference extracts cited as evidence/ |
| 3 | stay in that analysis checkout; their SHA-256 values are in MAX-SHA256SUMS.txt. |
| 4 | No MAX source is copied into Omega/CUDApp/Bridge production paths. --> |
| 5 | # MAX 26.7.0 Interoperability Probe Plan |
| 6 | |
| 7 | Companion to `FEASIBILITY-REPORT.md` (pin `527d069ee11a41ac5320af1f9402db0a66b2b868`). |
| 8 | This plan separates **non-GPU feature detection** from **GPU-window experiments**. |
| 9 | |
| 10 | Hard rules: |
| 11 | |
| 12 | - The GPU on this workstation belongs to a live serving process. **No GPU step may be run without an authorized window and exclusive access.** Every GPU step below is `NOT_RUN` in this report. |
| 13 | - Do not modify MAX source, do not contact Modular, do not submit upstream changes. All probes are local, read-only with respect to MAX except for temporary directories. |
| 14 | - Do not copy MAX code into Omega/CUDApp/Bridge. Probe scripts live under `probe/` (temporary) and evidence under `evidence/probes/`. |
| 15 | - Do not run destructive commands (`nvidia-smi -r`, driver reload, `rm` of MAX installs). Stop on any unexpected GPU process. |
| 16 | - Every probe captures: command, environment, exit status, stdout/stderr, and (where relevant) output files. Save under `evidence/probes/<probe-id>/`. |
| 17 | |
| 18 | Definitions: |
| 19 | |
| 20 | - `$MAXPY` — Python interpreter with MAX installed (detected in P1). Do not assume the system Python. |
| 21 | - `$MAXPKG` — directory containing the installed `max` package (`python -c "import max,os;print(os.path.dirname(max.__file__))"`). |
| 22 | - `$CORE` — the installed native extension, e.g. `$MAXPKG/_core*.so` or `$MAXPKG/_core/…so`; locate in P2. |
| 23 | - `$WINDOW` — a temporary directory under `/tmp/max-probe-*`, never inside a repo. |
| 24 | |
| 25 | --- |
| 26 | |
| 27 | ## 0. Preconditions and stop conditions |
| 28 | |
| 29 | Before any GPU probe: |
| 30 | |
| 31 | 1. Confirm the pin of the checkout used for comparison: |
| 32 | `git -C ~/workspace/maxinterop/max-source rev-parse HEAD` → must be `527d069...`. |
| 33 | 2. Confirm the installed MAX version and build: |
| 34 | `$MAXPY -c "import max; print(max.__file__, getattr(max,'__version__','NO_VERSION'))"` |
| 35 | 3. Record `nvidia-smi -q` and `nvidia-smi --query-compute-apps=pid,process_name,used_memory --format=csv` **without killing anything**. |
| 36 | 4. Abort the window if any other compute process is active or if the serving process is still up. Do not share the GPU. |
| 37 | |
| 38 | Non-GPU probes are safe to run at any time, but must not import CUDA contexts. Importing `max.driver` and constructing `CPU()` is safe; constructing `Accelerator()` is a GPU step because it creates a context/stream. |
| 39 | |
| 40 | --- |
| 41 | |
| 42 | ## 1. Non-GPU feature detection |
| 43 | |
| 44 | These are static/import/compile-only probes. They require no device and no GPU context. None were executed for this report; only git/source inspection was performed. |
| 45 | |
| 46 | ### P1 — Locate interpreter and package |
| 47 | |
| 48 | ```bash |
| 49 | $MAXPY - <<'PY' |
| 50 | import json, os, sys |
| 51 | import max |
| 52 | print(json.dumps({ |
| 53 | "python": sys.version, |
| 54 | "executable": sys.executable, |
| 55 | "max_file": max.__file__, |
| 56 | "max_dir": os.path.dirname(max.__file__), |
| 57 | "version": getattr(max, "__version__", None), |
| 58 | }, indent=2)) |
| 59 | PY |
| 60 | ``` |
| 61 | |
| 62 | Record: path, version string, wheel/source install. If `max` is absent, stop; the remaining probes need an installed build. |
| 63 | |
| 64 | ### P2 — Import surface and native extension inventory |
| 65 | |
| 66 | ```bash |
| 67 | $MAXPY - <<'PY' |
| 68 | import importlib, os, json |
| 69 | mods = ["max.driver", "max.engine", "max.graph", "max._core.driver", |
| 70 | "max._core.engine", "max._core.dlpack", "max._core.mlrt"] |
| 71 | out = {} |
| 72 | for m in mods: |
| 73 | try: |
| 74 | mod = importlib.import_module(m) |
| 75 | out[m] = {"file": getattr(mod, "__file__", None), |
| 76 | "has": [n for n in ("Buffer","Device","Accelerator","DeviceQueue", |
| 77 | "DeviceEvent","CompletionFlag","make_dlpack_capsule", |
| 78 | "import_dlpack","InferenceSession","Model") |
| 79 | if hasattr(mod, n)]} |
| 80 | except Exception as e: |
| 81 | out[m] = {"error": repr(e)} |
| 82 | print(json.dumps(out, indent=2)) |
| 83 | PY |
| 84 | find "$MAXPKG" -maxdepth 3 -name '*.so' -o -name '*.pyd' | sort |
| 85 | ``` |
| 86 | |
| 87 | Pass criteria / interpretation: |
| 88 | - `max._core.dlpack.make_dlpack_capsule` present → raw-pointer DLPack bridge exists. |
| 89 | - `max.driver.DeviceQueue.native_stream_handle` present as a property → stream co-scheduling possible. |
| 90 | - Absence of any launch/load symbol in `max.driver`/`max._core.driver` confirms the report's Python-launch-absence claim. |
| 91 | |
| 92 | ### P3 — Symbol and dependency inspection of the native extension |
| 93 | |
| 94 | Read-only; this is exactly the analysis permitted by the license. |
| 95 | |
| 96 | ```bash |
| 97 | for so in $(find "$MAXPKG" -name '*.so'); do |
| 98 | echo "=== $so" |
| 99 | readelf -d "$so" 2>/dev/null | grep -E 'NEEDED|RPATH|RUNPATH' |
| 100 | nm -D --defined-only "$so" 2>/dev/null | grep -E \ |
| 101 | 'AsyncRT_DeviceContext_(loadFunction|enqueueFunction|create|synchronize)|M_driver_(bundle_load|function_load|queue_execute)|cuModuleLoadDataEx|cuLaunchKernelEx' || true |
| 102 | strings -a "$so" | grep -aE 'cubin|PTX|SASS|telemetry\.modular\.com|MODULAR_DRIVER_PLUGINS|M_driver_bundle_load' | sort -u | head -50 |
| 103 | done |
| 104 | ``` |
| 105 | |
| 106 | Record: |
| 107 | - `NEEDED libcuda.so.1` (or absence) — proves/refutes CUDA linkage at the installed package level. |
| 108 | - Presence of `AsyncRT_DeviceContext_loadFunction` / `M_driver_bundle_load` — tells which runtime generation the installed pin actually ships (pinned source is silent). |
| 109 | - Presence of `MODULAR_DRIVER_PLUGINS` strings — plugin env support in the installed binary. |
| 110 | - `telemetry.modular.com` strings — native egress surface. |
| 111 | |
| 112 | Caveat: symbol visibility/static linking may hide functions; absence of a symbol is weaker evidence than presence. |
| 113 | |
| 114 | ### P4 — Debug/compile IR dump without a device |
| 115 | |
| 116 | Compile a trivial CPU graph and stop before JIT: |
| 117 | |
| 118 | ```bash |
| 119 | WINDOW=$(mktemp -d /tmp/max-probe-ir.XXXX) |
| 120 | MODULAR_DEBUG=pre-jit,ir-output-dir="$WINDOW" $MAXPY - <<'PY' |
| 121 | from max.driver import CPU |
| 122 | from max.dtype import DType |
| 123 | from max.engine import InferenceSession |
| 124 | from max.graph import DeviceRef, Graph, TensorType |
| 125 | try: |
| 126 | with Graph("probe", input_types=[TensorType(DType.float32, [4], device=DeviceRef.CPU())]) as g: |
| 127 | g.output(g.inputs[0].tensor + g.inputs[0].tensor) |
| 128 | s = InferenceSession(devices=[CPU()]) |
| 129 | s.compile(g) |
| 130 | except Exception as e: |
| 131 | print(type(e).__name__, e) |
| 132 | PY |
| 133 | find "$WINDOW" -type f -maxdepth 3 | sort |
| 134 | ``` |
| 135 | |
| 136 | Pass criteria: |
| 137 | - `CompilationStopped` appears (documented: `max/python/max/_core/engine.pyi:488-496`). |
| 138 | - The IR dir contains MLIR/Mojo for the graph, letting me see `mo.custom`, `mo.graph`, and lowering form without a GPU. |
| 139 | - Repeat with `MODULAR_DEBUG=ir-output-dir=$WINDOW` (no pre-jit) only if CPU JIT is acceptable; otherwise stop at pre-jit. |
| 140 | |
| 141 | Also probe the `sensible` alias and `device-sync-mode` parsing (CPU-only, no execution): |
| 142 | |
| 143 | ```bash |
| 144 | MODULAR_DEBUG=sensible $MAXPY -c "from max._core.engine import DebugConfig; d=DebugConfig(); print(d.nan_check, d.assert_level, d.device_sync_mode)" |
| 145 | ``` |
| 146 | |
| 147 | ### P5 — Virtual-device compile and MEF export (no GPU) |
| 148 | |
| 149 | This tests whether compilation and MEF export can happen with no attached accelerator. The APIs are documented at `max/python/max/_core/driver.pyi:895-1006` and `max/python/max/engine/api.py:450-455,1070-1076`. |
| 150 | |
| 151 | ```bash |
| 152 | WINDOW=$(mktemp -d /tmp/max-probe-mef.XXXX) |
| 153 | $MAXPY - <<'PY' |
| 154 | from max.driver import CPU, set_virtual_device_api, set_virtual_device_target_arch, set_virtual_device_count |
| 155 | from max.dtype import DType |
| 156 | from max.engine import InferenceSession |
| 157 | from max.graph import DeviceRef, Graph, TensorType |
| 158 | set_virtual_device_api("cuda") |
| 159 | set_virtual_device_target_arch("sm_121") |
| 160 | set_virtual_device_count(1) |
| 161 | dev = DeviceRef.GPU(0) |
| 162 | with Graph("probe", input_types=[TensorType(DType.float32, [4], device=dev)]) as g: |
| 163 | g.output(g.inputs[0].tensor + g.inputs[0].tensor) |
| 164 | s = InferenceSession(devices=[CPU()]) |
| 165 | c = s.compile(g) |
| 166 | c.export_mef("$WINDOW/probe.mef") |
| 167 | print("exported") |
| 168 | PY |
| 169 | xxd -l 64 "$WINDOW/probe.mef" |
| 170 | grep -abo $'\x7fELF' "$WINDOW/probe.mef" | head |
| 171 | ``` |
| 172 | |
| 173 | Pass criteria: |
| 174 | - Compile succeeds under a virtual CUDA device targeting sm_121 with no accelerator present. |
| 175 | - MEF starts with magic `0xBEF0` (`MAIN MLRT/docs/GraphRT/ModularExecutorFormat.md:136-159`). |
| 176 | - Embedded ELF magic offsets show code objects. Do not attempt to parse them further yet. |
| 177 | |
| 178 | If virtual-device compile fails on this build, record the exact error; it is itself a finding. |
| 179 | |
| 180 | ### P6 — MEF read-back and metadata |
| 181 | |
| 182 | ```bash |
| 183 | $MAXPY - <<'PY' |
| 184 | from max._core import engine |
| 185 | b = open("$WINDOW/probe.mef","rb").read() |
| 186 | c = engine.read(b) |
| 187 | print(len(c), c.names) |
| 188 | for m in c: print(m.name, [(t.name, t.dtype, t.shape) for t in m.input_metadata], |
| 189 | [(t.name, t.dtype, t.shape) for t in m.output_metadata]) |
| 190 | PY |
| 191 | ``` |
| 192 | |
| 193 | Pass criteria: `engine.read` accepts the exported bytes; names/metadata survive. Failure indicates the artifact is build-specific. |
| 194 | |
| 195 | ### P7 — `.mojoc` and custom-op packaging (no GPU) |
| 196 | |
| 197 | Build a trivial custom-op package with the MAX/Mojo toolchain, if available: |
| 198 | |
| 199 | ```bash |
| 200 | mojo package path/to/probe_kernel -o "$WINDOW/probe.mojoc" |
| 201 | file "$WINDOW/probe.mojoc" |
| 202 | xxd -l 64 "$WINDOW/probe.mojoc" |
| 203 | grep -abo $'\x7fELF' "$WINDOW/probe.mojoc" | head |
| 204 | ``` |
| 205 | |
| 206 | Purpose: determine whether `.mojoc` is itself an ELF/container with embedded object code, and whether it could carry a cubin. Do not modify MAX; this is a local package. |
| 207 | |
| 208 | ### P8 — Environment and config surface |
| 209 | |
| 210 | ```bash |
| 211 | env | grep -E '^(MODULAR_|MAX_|OTEL_|CUDA_)' | sort |
| 212 | $MAXPY - <<'PY' |
| 213 | from max._core import engine |
| 214 | for k in ("debug", "max-debug.ir-output-dir", "max-debug.pre-jit", |
| 215 | "telemetry", "nvptx-compiler-path"): |
| 216 | try: print(k, "=", engine.get_config_value(k)) |
| 217 | except Exception as e: print(k, "->", type(e).__name__, e) |
| 218 | PY |
| 219 | ``` |
| 220 | |
| 221 | Record the precedence documented at `max/python/max/_core/engine.pyi:85-114`: global override → `MODULAR_<KEY>` env → `modular.cfg`. |
| 222 | |
| 223 | Relevant variables found in source: |
| 224 | |
| 225 | | Variable | Purpose | Evidence | |
| 226 | |---|---|---| |
| 227 | | `MODULAR_DEBUG` | comma-separated debug properties | `max/python/max/_core/engine.pyi:418-423` | |
| 228 | | `MODULAR_NVPTX_COMPILER_PATH` | override bundled ptxas | `max/docs/site/gpu/hardware-compatibility.mdx:30-36` | |
| 229 | | `MAX_SERVE_DISABLE_TELEMETRY` | disable serve telemetry | `max/python/max/serve/config.py:311-315` | |
| 230 | | `OTEL_SDK_DISABLED` | disable OTel exporters | `max/python/max/serve/telemetry/common.py:115-124` | |
| 231 | | `MODULAR_DRIVER_PLUGINS` | main-only plugin auto-load | `MAIN Target/lib/DriverPlugin/DriverPlugin.cpp:286-321` | |
| 232 | | `MAX_CUSTOM_OP_BINDING_CACHE_SIZE` | custom-op binding cache bound | `max/python/max/_interpreter_ops/custom_gc.py:155-158` | |
| 233 | | `MODULAR_MAX_DEBUG_PROFILING_OUTPUT_PATH` | profiler output | `max/python/max/_core/profiler.pyi:126` | |
| 234 | | `MODULAR_DEVICE_CONTEXT_DISABLE_HEALTHCHECK` | driver health check toggle (name found in source grep) | `evidence/commands/16-telemetry-offline.txt` | |
| 235 | |
| 236 | ### P9 — Offline/egress check (non-GPU) |
| 237 | |
| 238 | Run the P4/P5 compile-only path under a network-isolated namespace, if permitted: |
| 239 | |
| 240 | ```bash |
| 241 | unshare -n -- $MAXPY - <<'PY' |
| 242 | # same CPU/virtual-device compile as P5 |
| 243 | PY |
| 244 | ``` |
| 245 | |
| 246 | If `unshare` is unavailable, use `strace -f -e trace=network -o "$WINDOW/net.log"` and inspect for `connect()` to non-local addresses. Pass criteria: compile/export completes with no egress, or the exact failing connect is identified. This probes the Python path only; native threads may be spawned but still traced with `-f`. |
| 247 | |
| 248 | ### P10 — Static license and provenance check |
| 249 | |
| 250 | ```bash |
| 251 | git -C "$HOME/workspace/maxinterop/max-source" rev-parse HEAD |
| 252 | sha256sum -c SHA256SUMS |
| 253 | ``` |
| 254 | |
| 255 | Confirm the pin and that no file under `omega/`, `cudapp/`, or `bridge/` contains copied MAX code. This is a policy check, not a runtime probe. |
| 256 | |
| 257 | --- |
| 258 | |
| 259 | ## 2. GPU-window probes (all NOT_RUN) |
| 260 | |
| 261 | Run only in an authorized window, with the serving process stopped and the GPU exclusively owned. Each probe must start from a clean process; a device fault leaves the CUDA context unusable (`max/docs/site/gpu/hardware-compatibility.mdx:129-131`). |
| 262 | |
| 263 | General setup: |
| 264 | |
| 265 | ```bash |
| 266 | nvidia-smi --query-gpu=name,driver_version,compute_cap --format=csv |
| 267 | nvidia-smi --query-compute-apps=pid,process_name,used_memory --format=csv |
| 268 | # Expect: compute_cap 12.1, driver >= 580, no compute apps. |
| 269 | ``` |
| 270 | |
| 271 | ### G1 — Context identity and stream ownership |
| 272 | |
| 273 | Goal: prove MAX and an external CUDA caller share the same `CUcontext` and that `native_stream_handle` is the stream MAX uses. |
| 274 | |
| 275 | Sketch (Python + cuda-python, or C++): |
| 276 | 1. `dev = max.driver.Accelerator()`; `q = dev.default_queue`. |
| 277 | 2. `h = q.native_stream_handle`; assert `h != 0`. |
| 278 | 3. `cuda.cuStreamGetCtx(h)` → context handle; compare with the context current in the external caller (`cuCtxGetCurrent` after a MAX operation). |
| 279 | 4. Create an external stream or use `h` directly; call `cuStreamQuery(h)` and confirm no error. |
| 280 | |
| 281 | Pass: same context handle, nonzero stream, query succeeds. Fail: distinct contexts → pointer sharing via UVA is not safe; stop and reassess. |
| 282 | |
| 283 | Evidence: handles (hex), `cuCtxGetCurrent`, `cuStreamGetCtx`, `cuStreamQuery` results. |
| 284 | |
| 285 | ### G2 — Ordering: MAX work → external kernel → MAX work on one stream |
| 286 | |
| 287 | Goal: validate the Rank-1 co-scheduling boundary without loading the cubin into MAX. |
| 288 | |
| 289 | Sketch: |
| 290 | 1. MAX: allocate `dst`, enqueue a fill/copy on `q`. |
| 291 | 2. External: launch a CUDApp sm_121 kernel on `h` that reads `dst` and writes `out`. |
| 292 | 3. MAX: `q.record_event()`; `event.synchronize()`; read `out` with `to_numpy()`. |
| 293 | 4. Repeat with `q.wait_for(other_queue)` and a second stream to confirm event ordering. |
| 294 | |
| 295 | Pass: deterministic output across ≥100 iterations; no implicit sync required. Fail: race/ordering violation. |
| 296 | |
| 297 | ### G3 — DLPack import of a CUDApp allocation into MAX |
| 298 | |
| 299 | Goal: prove MAX can consume externally allocated memory zero-copy. |
| 300 | |
| 301 | Sketch: |
| 302 | 1. CUDApp allocates `ptr` (same context) and fills it. |
| 303 | 2. Build an exporter capsule: |
| 304 | `cap = max._core.dlpack.make_dlpack_capsule(owner, ptr, device_type, device_id, dtype, shape, strides, None)` |
| 305 | (signature at `max/python/max/_core/dlpack.pyi:20-29`). |
| 306 | 3. `b = max.driver.Buffer.from_dlpack(cap)`; assert `b._data_ptr() == ptr`; run a MAX graph that reads `b`; compare. |
| 307 | 4. Drop `b`, then free `ptr` only after MAX is done (producer-owned contract). |
| 308 | |
| 309 | Pass: no copy (pointer equality), correct values, no use-after-free. Fail: pointer mismatch means a copy; use-after-free indicates ownership mishandling. |
| 310 | |
| 311 | ### G4 — Reverse: MAX buffer into CUDApp |
| 312 | |
| 313 | 1. MAX allocates `b`, fills it. |
| 314 | 2. `cap = b.__dlpack__(stream=q.native_stream_handle)`; CUDApp imports; reads values. |
| 315 | 3. Free order: keep `b` alive until CUDApp is done; then release. |
| 316 | |
| 317 | Pass: values match; MAX's `__dlpack__` synchronized pending work per the contract (`max/tests/tests/driver/test_buffer_sync_contracts.py:13-29`). |
| 318 | |
| 319 | ### G5 — Load a CUDApp cubin via a Mojo custom op (Rank 2) |
| 320 | |
| 321 | Goal: determine whether the pinned `DeviceContext.load_function` accepts a raw cubin in practice and whether MAX can own the launch. |
| 322 | |
| 323 | Precondition: a sm_121(a) cubin from CUDApp with a known entry point and a simple pointer/int signature. |
| 324 | |
| 325 | Steps: |
| 326 | 1. Write a minimal Mojo custom-op package: |
| 327 | - `@extensibility.register("probe_cubin", type="gpu", api="cuda", arch="sm_121a")` struct; |
| 328 | - `execute` takes tensors + `ctx: DeviceContext`; |
| 329 | - constructs `asm` from the cubin bytes (this is the risky step; try `String(unsafe_from_utf8=...)` and, as a control, a PTX version); |
| 330 | - `var f = ctx.load_function[probe_sig](function_name="<symbol>", asm=asm)`; |
| 331 | - `ctx.enqueue_function(f, out, in, n, grid_dim=..., block_dim=...)`; |
| 332 | - `ctx.synchronize()` (or rely on MAX's graph sync). |
| 333 | 2. Build `.mojoc` for sm_121a; compile a graph with `custom_extensions=[...]`; execute. |
| 334 | 3. Controls: |
| 335 | - same wrapper with PTX text (should pass); |
| 336 | - wrong entry-point name (should raise at load); |
| 337 | - a cubin with an embedded NUL / invalid UTF-8 (tests the `String` transport); |
| 338 | - a cubin for the wrong arch (should fail at `cuModuleLoadDataEx` or launch). |
| 339 | 4. Capture: `load_function` exception type/message, `enqueue_function` result, numeric output, and whether `DeviceQueue.synchronize()` observes the external launch. |
| 340 | |
| 341 | Pass: cubin accepted, output correct, MAX sync covers it. Fail modes to distinguish: |
| 342 | - `String` construction rejects bytes → blocked at transport (expected risk). |
| 343 | - `cuModuleLoadDataEx` rejects → cubin invalid/arch mismatch. |
| 344 | - `cuModuleGetFunction` fails → symbol name wrong/mangled. |
| 345 | - launch succeeds but output wrong → ABI mismatch. |
| 346 | - launch succeeds but sync doesn't cover it → ordering defect. |
| 347 | |
| 348 | Do not proceed to G6 unless G5-PTX control passes (establishes the wrapper mechanics). |
| 349 | |
| 350 | ### G6 — HAL bundle path on a main-branch build (Rank 3) |
| 351 | |
| 352 | Precondition: a MAX build from `origin/main` (not the pin), with `CUDAPlugin.so` and HAL headers. This probe cannot be run against v26.7.0 because the headers/plugin are absent. |
| 353 | |
| 354 | Sketch (C++ or Mojo): |
| 355 | 1. `M_driver_create` → `M_driver_device_get` → `M_driver_context_create`. |
| 356 | 2. `M_driver_static_bundle{ mapped_data = cubin_bytes(size), file_type="cubin" }`. |
| 357 | 3. `M_driver_bundle_load(ctx, &bundle, opts, &rt)`. |
| 358 | 4. `M_driver_function_load(ctx, rt, "symbol", len, &fn)`. |
| 359 | 5. `M_driver_memory_alloc_sync(ctx, n, &mem)`; `M_driver_queue_create`; `M_driver_queue_copy_to_device`; `M_driver_queue_execute(q, fn, &cfg, args, sizes, nargs)`; `M_driver_queue_copy_from_device`; `M_driver_queue_synchronize`. |
| 360 | 6. Controls: `file_type="ptx"` with PTX bytes; wrong `file_type`; wrong symbol; zero-size `wrapSync`. |
| 361 | |
| 362 | Pass: numeric correctness, sync semantics, status codes. Also record whether `file_type` is enforced (source says CUDA ignores it — `MAIN Target/lib/CUDA/Function.cpp:68-90`). |
| 363 | |
| 364 | ### G7 — Memory alignment and views |
| 365 | |
| 366 | 1. Allocate many MAX buffers; print `_data_ptr() % 256`, `% 128`, `% 64`. |
| 367 | 2. Run a kernel using 16-byte vector loads on the base pointer and on a `Buffer` slice; check `_aligned(16)`. |
| 368 | 3. Test DLPack-imported CUDApp pointers at unaligned offsets; record driver/kernel behavior. |
| 369 | |
| 370 | Pass: documented floor (64 B on main; unknown at pin) holds; slices honor `_aligned`. Fail: record actual distribution; do not assume 256 B. |
| 371 | |
| 372 | ### G8 — Error propagation across the boundary |
| 373 | |
| 374 | 1. Launch an out-of-bounds kernel externally on MAX's stream; call `DeviceQueue.synchronize()`; record whether it raises and what message. |
| 375 | 2. Repeat with a kernel that traps; check whether MAX marks the context unusable (`hardware-compatibility.mdx:129-131`). |
| 376 | 3. Check that MAX's next operation fails rather than silently continuing. |
| 377 | |
| 378 | Pass: MAX surfaces the error (sticky CUDA error) or clearly documents otherwise. Fail: silent corruption risk. |
| 379 | |
| 380 | ### G9 — Graph capture with external work |
| 381 | |
| 382 | 1. `Model.capture(...)` while an external kernel is enqueued on the same stream. |
| 383 | 2. Determine whether capture records the external `cuLaunchKernelEx` (it should, if on the captured stream) or fails. |
| 384 | 3. Replay and verify. |
| 385 | |
| 386 | Pass: either capture includes the external launch and replay is correct, or capture rejects it explicitly. Silent omission is a finding. |
| 387 | |
| 388 | ### G10 — sm_121 vs sm_121a compatibility |
| 389 | |
| 390 | 1. Produce two cubins from the same kernel: `-arch=sm_121` and `-arch=sm_121a`. |
| 391 | 2. Load/run each on the DGX Spark (`sm_121` device) via G5 or G6. |
| 392 | 3. Record `CUDA_ERROR_NO_BINARY_FOR_GPU`, `CUDA_ERROR_INVALID_PTX`, or success. |
| 393 | |
| 394 | Pass: at least one form loads; document which. This is the only way to resolve the sm_121/sm_121a question; source cannot. |
| 395 | |
| 396 | ### G11 — MEF injection (only after G6) |
| 397 | |
| 398 | Attempt only if G6 passes and legal review approves. Build a MEF with `MLIRToMEF` from a main build, or mutate a non-code section of an exported MEF and re-read it. Do not parse/rewrite code sections without a format owner. This is expected to fail or be version-fragile; record it as negative evidence. |
| 399 | |
| 400 | ### G12 — Plugin env targeting (only on main build) |
| 401 | |
| 402 | 1. Set `MODULAR_DRIVER_PLUGINS="CUDA@/path/to/CUDAPlugin.so"` and run a MAX compile/execute; confirm the plugin is loaded (logs/`strace` open/`dlopen`). |
| 403 | 2. Set a bogus path; confirm the documented "Failed to load driver plugin" path (`MAIN Target/lib/DriverPlugin/DriverPlugin.cpp:286-321`). |
| 404 | 3. Do **not** point it at a custom `.so` unless Rank 4 is being seriously pursued; that is a backend port, not a minimal probe. |
| 405 | |
| 406 | --- |
| 407 | |
| 408 | ## 3. Decision matrix |
| 409 | |
| 410 | | Probe result | Consequence | |
| 411 | |---|---| |
| 412 | | G1 same context, G2 ordering stable, G3/G4 zero-copy | Rank 1 is viable immediately; Omega can co-schedule without MAX changes. | |
| 413 | | G5 PTX passes, cubin fails on `String` | Rank 2 needs an upstream byte-safe `load_function` overload or an unsafe workaround; report as `REQUIRES_MODULAR_CHANGE` for a supported path. | |
| 414 | | G5 cubin passes | Rank 2 becomes the preferred MAX-owned boundary at the pin. | |
| 415 | | G6 passes | Rank 3 is the clean architectural path on main; wait for/upgrade to a build containing HAL. | |
| 416 | | G8 error not surfaced | Rank 1 is unsafe for production; require explicit external synchronization/error handling. | |
| 417 | | G9 capture silently omits external launch | Do not combine graph capture with Rank 1 without disabling capture. | |
| 418 | | G10 only sm_121a loads | Require CUDApp to emit sm_121a (or PTX) for DGX Spark. | |
| 419 | | P3 shows no `M_driver_bundle_load` / `loadFunction` symbols | Installed pin differs from source assumptions; rerun the report's pin analysis against the wheel. | |
| 420 | | P5 fails | MEF export/cross-compile claims are false for this build; restrict to attached-device compile. | |
| 421 | |
| 422 | --- |
| 423 | |
| 424 | ## 4. Evidence capture template |
| 425 | |
| 426 | For every probe: |
| 427 | |
| 428 | ```bash |
| 429 | ID=G2-ordering |
| 430 | OUT=evidence/probes/$ID |
| 431 | mkdir -p "$OUT" |
| 432 | { echo "date: $(date -Is)"; echo "host: $(uname -a)"; |
| 433 | echo "pin: $(git -C "$HOME/workspace/maxinterop/max-source" rev-parse HEAD)"; |
| 434 | echo "max: $($MAXPY -c 'import max;print(max.__file__,getattr(max,"__version__",None))')"; |
| 435 | echo "gpu: $(nvidia-smi --query-gpu=name,driver_version,compute_cap --format=csv,noheader)"; |
| 436 | } > "$OUT/meta.txt" |
| 437 | { set -x; <command>; } > "$OUT/run.log" 2>&1 |
| 438 | echo "exit=$?" >> "$OUT/run.log" |
| 439 | sha256sum "$OUT"/* >> "$OUT/SHA256SUMS" |
| 440 | ``` |
| 441 | |
| 442 | After the window, append the probe outputs to the top-level `SHA256SUMS` manifest and update `FEASIBILITY-REPORT.md` §8 (what is not proven) with what was actually established. |