Repository navigation
Metal's refusal of an asked --gpu span names the device's limit - #1047
Merged
Merged
Conversation
nicolas-abril
requested changes
Sep 25, 2026
nicolas-abril
left a comment
Collaborator
There was a problem hiding this comment.
Thanks for splitting this out. You extracted exactly what I asked for on #1012, so this is a change of mind on my side, not something you missed. After looking at it more closely, I don't think an explicit --gpu size should be clamped with a note. It should fail loudly, as it did before.
Why
- It doesn't change #942's run. On Apple Silicon both Metal limits are well above 8 GB. On an M4 with 16 GB,
recommendedMaxWorkingSetSizeis 12124 MB andmaxBufferLengthis 9093 MB, and a 32 GB Mac is higher still. So--gpu 8GBis still wired whole with this PR. The #942 crash was the command buffer that never completed. The limit on each process doesn't touch that, and it can't stop several processes adding up either. - On Metal, it turns a clear error into a silent-ish clamp. Above
maxBufferLength,mainalready stops withbend: the GPU span is more than the device has. I checked--gpu 10GB,20GBand100GBon that M4. On Apple SiliconmaxBufferLengthis the lower of the two limits, so the cap here is effectively that same threshold. The only change is that the error becomes a smaller span plus a stderr line. - It clashes with the out-of-memory hint. The GPU out-of-memory error says "run again with a bigger span, as in --gpu 8GB". A user who follows that advice past the cap gets a note and then the same out-of-memory error, which is confusing.
- It caps CUDA, which was deliberately left uncapped. The CUDA span is one
cuMemAllocManagedrange whose pages fault in on demand. An explicit span larger than the card works today (slowly), and this PR cuts it tocuDeviceTotalMem. When the single span was introduced (fde5e24), the defaults were chosen per backend by what memory costs there: 2 GB on Metal, the whole card on CUDA. Capping the lanes where memory is cheap "would only turn working programs into failures and buy nothing". That commit also set an explicit span the device can't hold to be refused, not clamped.
What I'd like instead
- Keep
gpu_span, the defaults andcorpus_setupas they are onmain. - On Metal, make the existing refusal name the limit, so the user knows what to ask for. For example:
bend: --gpu 20GB is over the device's 9093MB(frommaxBufferLength). That is a few lines aroundnewBufferWithBytesNoCopyingpu_load. - Leave the CUDA lane alone.
- Drop the GUIDE change, since
--gpu 4GBwould mean exactly what it says again. - Please update the title and description so they don't claim to fix part of #942. The runs that crash in #942 are unaffected, and the real fixes there are still the launch deadline and the warning for a
!with no parallelism.
This review was written with AI assistance (Claude Code) and checked by me.
…lang#942) bendlang#942 found an explicit --gpu 8GB wired whole: only the default went through gpu_span. gpu_span now answers the device's limit (Metal's recommended working set under its largest buffer, CUDA's total memory). Both the asked span and the default stop there, and an asked span over it says so on stderr. Metal's default stays 2GB. The cores' span is unchanged. This bounds one process. Several GPU programs running at once can still sum past the machine's memory. Co-Authored-By: Claude Opus 5.5 <[email protected]>
MattCozendey
force-pushed
the
bugfix/gpu-cap
branch
from
September 25, 2026 14:20
3c8e6c1 to
b859a96
Compare
The span is no longer clamped: gpu_span, the defaults, corpus_setup and the CUDA lane are as on main, and GUIDE's --gpu 4GB means what it says. An asked span over maxBufferLength still stops, now with "bend: --gpu 20480MB is over the device's 9093MB", so the user knows what to ask for. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Contributor
Author
|
Updated as requested. |
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
nicolas-abril
approved these changes
Sep 25, 2026
nicolas-abril
left a comment
Collaborator
There was a problem hiding this comment.
Thanks, this is exactly it. I built it on an M4 (16 GB, maxBufferLength 9093 MB):
--gpu on,2GB,4GB,8GBand8.8GBrun and print the right answer.9GB,10GB,20GBand100GBstop withbend: --gpu <N>MB is over the device's 9093MBand exit 1.bun gates/repo.tspasses 46 / 46.
I pushed one small commit that removes the comment on the refusal, and I'm squash-merging.
This review was written with AI assistance (Claude Code) and checked by me.
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
On Metal, an explicit
--gpuspan overmaxBufferLengthalready stops atnewBufferWithBytesNoCopy. With this change the error names the device's limit, so the user knows what to ask for:Any other buffer failure keeps the old message,
the GPU span is more than the device has.gpu_span, the defaults andcorpus_setupare as onmain: no span is clamped.cuMemAllocManagedpages fault in on demand.--gpu 4GBmeans exactly what it says.This does not fix #942. Its crashing runs are unaffected; the real fixes there are still the launch deadline and the warning for a
!with no parallelism.What I verified
bun gates/repo.ts: PASS 46 / 46.snprintf+err_failpattern as the rest ofcomp.ts.🤖 Generated with Claude Code