Skip to content

fix(runtime): report CUDA probe stage and Driver API error - #1341

Merged
Lorenzobattistela merged 3 commits into
bendlang:mainfrom
oxura:fix/cuda-probe-errors
Oct 5, 2026
Merged

Lorenzobattistela merged 3 commits into
bendlang:mainfrom
oxura:fix/cuda-probe-errors

Conversation

@oxura

@oxura oxura commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #1145.

gpu_probe returns NULL on success or the reason it failed, instead of one bool, so --gpu on no longer blames WSL2 for every failure.

  • CUDA: cuInit, cuDeviceGet, the concurrent-managed-access query and cuDevicePrimaryCtxRetain go through GPU_CHECK, which reports <function> failed: <cuGetErrorName>, e.g. cuInit failed: CUDA_ERROR_UNKNOWN. A failed cuCtxSetCurrent releases the retained primary context and reports the same way. A device without concurrent managed access gets CUDA device lacks concurrent managed access (WSL2 lacks it). The L2 size query stays best-effort.
  • Metal: this binary found no usable Metal GPU.
  • No GPU backend: this binary has no CUDA or Metal GPU support.
  • --gpu on prints the reason and exits 1. Automatic mode still falls back to the CPU silently. --gpu-build uses the new return.
  • main() keeps dev a compile-time false in GPU-less builds (why is "" when the GPU is not requested). The first form, active ? gpu_probe() : NULL, kept clang from folding it, so cube_run and corpus_lay stopped inlining into main and editdist SEQ-CPU went from 1.92 s to 2.39 s (1.24x).

Verification, merged onto main 5169abf:

  • Cluster gates: repo 50/50, test 1569/1569, ping 47/47, perf 122/124 (main alone: 122/124). editdist SEQ-CPU 0.99x, tree-matmul SEQ-CPU 1.04x.
  • comp.ts 63,132 / 64,000 ttok (main 62,940).
  • The probe, taken from this branch's source, run against stub Driver API calls failing one stage at a time: each stage reports its function and error name, and a failed cuCtxSetCurrent releases the context.
  • On an M4 Mac: the Metal build runs bfs with --gpu on and --gpu off; a CPU-only build exits 1 with the no-support message under --gpu on and runs normally without it.

Not tested on a CUDA GPU.

🤖 Generated with Claude Code

@oxura

oxura commented Oct 5, 2026

Copy link
Copy Markdown
Contributor Author

Joint local verification of #1337–#1341 against main 565d7fd, including the constructor-model correction in #1338:

  • Combined repository gate: PASS 50 / 50; original caps/core-language/gates unchanged.
  • Actual Lean 4.34.0 BendTT kernel accepts all six positive new proof fixtures, existing vec_safe_lookup, Base's Type-model control and compact 9000 Nat control. The 4097 regression uses an independent 2^12+1 structural value oracle.
  • User-defined parameterized/def Unit remains explicitly out of elaboration scope (no model for idt~A), not a claimed kernel success.
  • Versioned kernel cache works with no Lean on PATH. The earlier incompatible 4.32/source-only-cache and explicit BENDTT controls were also exercised.
  • Combined emitted HTTP JS retains ABC across fragmented headers and six receives. Individual HTTP smoke additionally used actual TCP under Bun/native C and an exact 65536-character response split into 65536 one-character receives.
  • Combined generated CUDA C reports cuInit(0) failed: CUDA_ERROR_UNKNOWN when forced under fault injection; automatic CPU fallback prints 2147450880 without diagnostics.
  • Code changes merge automatically. Only additive Unreleased CHANGELOG entries needed combining in the local integration checkout.

No physical GPU, macOS/Metal runtime, or mini-cluster gate was exercised. Separate PR source branches remain independent; the integration branch is local verification only.

@Lorenzobattistela Lorenzobattistela left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks — the probe refactor looks correct. I fault-injected each Driver API stage against stubs: the messages are right, and the context is released when cuCtxSetCurrent fails. Merged onto main bf96827, all gates pass on the cluster (repo 50/50, test 1551/1551, perf 121–123/124 against 123/124 on main, ping 47/47).

  1. After #1281, comp.ts is at 62984 on main and 63020 with this PR, so the Dialect/Gpu/Cube comment compression isn't needed anymore. Please restore those comments. The Cube one lost the reason the column grows "no more" than a LINE per thread (the tree-matmul 15 MB -> 68 MB case), and the Dialect one lost "a segment is a case of the device's switch".

Also, in general, do not just trim comments unrelated to your PR to make it fit the cap.

  1. Could the managed-access message keep the WSL2 hint, e.g. "CUDA device lacks concurrent managed access (WSL2 lacks it)"? That's still the common cause of that particular failure.

  2. Nit: GPU_CHECK stringifies the whole call (cuDeviceGetAttribute(&managed, CU_DEVICE_ATTRIBUTE_..., gpu_dev) failed), but the context-set case prints only the function name. Consider printing just the function name everywhere.

  3. Please drop the CHANGELOG entry, they're never added on PRs, just on releases.

@Lorenzobattistela Lorenzobattistela self-assigned this Oct 5, 2026
oxura and others added 2 commits October 5, 2026 21:44
The CPU-only gpu_probe() is a string literal. Writing the probe result
as `active ? gpu_probe() : NULL` kept clang from folding dev to false,
so corpus_setup kept its GPU branches, cube_run and corpus_lay were no
longer inlined into main, and editdist SEQ-CPU took 2.39 s instead of
1.92 s (1.24x). With "" as the inactive value, dev folds again.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@Lorenzobattistela
Lorenzobattistela merged commit 5c885eb into bendlang:main Oct 5, 2026
1 check passed
@oxura

oxura commented Oct 6, 2026

Copy link
Copy Markdown
Contributor Author

Confirmed the merged probe reports only the Driver API function name, retains the WSL2 hint specifically for missing concurrent managed access, and releases the primary context after a context-set failure. Thanks for restoring the unrelated runtime comments and checking this on the cluster. I will not trim unrelated comments to meet a cap in future PRs, and will leave release notes to releases. No physical CUDA/Metal claim from this Linux host.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

--gpu on on native Linux says "WSL2's lack" concurrent managed access when cuInit itself failed

2 participants