Skip to content

accept any shader model in .target - #8

Closed
AJ0070 wants to merge 3 commits into
tinygrad:masterfrom
AJ0070:ptx-modern-targets
Closed

accept any shader model in .target#8
AJ0070 wants to merge 3 commits into
tinygrad:masterfrom
AJ0070:ptx-modern-targets

Conversation

@AJ0070

@AJ0070 AJ0070 commented Aug 23, 2026

Copy link
Copy Markdown

lexer stopped at sm_35, anything newer was a lexical error and abort. CUDA 12 dropped sm_35 so nvrtc 12 has no target it can emit.

one text token replaces the eight hardcoded ones, nothing reads the target back.

bfi pos/len are u32 even for .b64, but the parser types immediates from the instruction so they were rejected. operand 4 also tested b.type instead of c.type. eval_Bfi was already right.

TestTargets fails on master, passes here.

tinygrad test/backend: sm_35 unchanged, sm_50 nv was 91 errors, now 0.

built locally with shared boost, CI does the static -fPIC build.

AJ0070 added 2 commits August 23, 2026 12:58
The lexer enumerated sm_10 through sm_35, so every newer .target was a
lexical error and ocelot aborted. That pinned callers to Kepler, which
CUDA 12 no longer supports at all.

Nothing reads the target string back: targetElement pushes it into
statement.targets and ir/Module.cpp hardcodes "sm_21" for internally
built modules. So one text-carrying token replaces the eight hardcoded
ones and never needs updating for a new architecture.
PTX types bfi's pos and len operands .u32 regardless of whether the
instruction is .b32 or .b64, but the parser types immediates from the
instruction type, so `bfi.b64 d, a, b, 32, 32` yielded b64 immediates
and was rejected. Operand 1 already exempts immediates; operands 3 and
4 did not. Operand 4 also tested b.type instead of c.type.

eval_Bfi already reads both as operandAsU32 for .b32 and .b64, so only
the validator disagreed. nvcc emits bfi.b64 from sm_50 on.
This was referenced Aug 23, 2026
regression test for the two fixes: the lexer stopped at sm_35, and bfi
with immediate pos/len was rejected for .b64.
@AJ0070

AJ0070 commented Aug 23, 2026

Copy link
Copy Markdown
Author

@sirhcm review when you get a chance, this is for the CUDA 12 gpuocelot bounty.

tinygrad will need a release tag to point at, setup-tinygrad pins the prebuilt .so to v0.1.0.

@sirhcm

sirhcm commented Aug 24, 2026

Copy link
Copy Markdown

I can't merge either of these without seeing tinygrad CI passing. sm_35 (with cuda 11) and whatever new arch you will have cuda 12 target should both work.

AJ0070 added a commit to AJ0070/tinygrad that referenced this pull request Aug 24, 2026
nvrtc 11.5 could only target sm_35, which CUDA 12 dropped. bumps to
12.9 with matching cudart headers for cuda_fp16.h.

ocelot URL is temporary, points at a build of tinygrad/gpuocelot#8+tinygrad#10
until those merge and get tagged.
@AJ0070

AJ0070 commented Aug 24, 2026

Copy link
Copy Markdown
Author

both configs green on tinygrad CI:

sm_35 with nvrtc 11.5, only the .so swapped: https://github.com/AJ0070/tinygrad/actions/runs/32765677728
sm_53 with nvrtc 12.9: https://github.com/AJ0070/tinygrad/actions/runs/32770170622

Linux (ptx) and Linux (nv) pass on both. the .so is the libgpuocelot-Linux artifact from this branch's own CI run, published on my fork so tinygrad CI can fetch it by URL. that flips to tinygrad/gpuocelot once these merge and get tagged.

CI caught two things my local runs did not. test/mockgpu/nv/nvdriver.py hardcodes SM_VERSION_3_5 separately from the CUDA mock, so nvrtc 12 rejected the -arch it derived. and test_gated_define_acc_with_half_dtype compares a half accumulated matmul to a float one at atol 1e-2 with unseeded randn, 2 failures in 20 runs, it is skipped below sm_53 so it had never run on the emulator. both fixed on the tinygrad branch, which I will open once there is a tag to point at.

@sirhcm

sirhcm commented Aug 24, 2026

Copy link
Copy Markdown

The way you've structured these changes makes it basically impossible for me to review. It's unclear to me if this will break every time we update tinygrad tests.

@AJ0070

AJ0070 commented Aug 24, 2026

Copy link
Copy Markdown
Author

fair, that is on me. #10 showed this PR's three commits as well, because I cannot set a fork branch as a base, so you were reading both at once. I have closed #10 and will reopen it against master once this lands, and can split it into cvt and the ALU ops if that reads better.

this one stands alone: -20 lines in the parser, plus TestTargets which parses sm_10 through sm_120 and bfi with immediate pos/len, and fails on master.

on breaking when tinygrad tests change: the regression tests are in gpuocelot and do not reference tinygrad, ctest is the contract. the tinygrad runs were evidence for you, not the test suite. if you would rather I drop the tinygrad numbers from the description entirely and let ctest speak, say so.

the target change is also not tinygrad shaped. nothing reads the target string back, so accepting sm_50 through sm_120 is not tuned to any particular emitter. same for bfi, eval_Bfi already read pos and len as u32, only the validator disagreed.

happy to restructure further if there is a shape you prefer. splitting this into target and bfi as two PRs is easy if you want them separate.

@sirhcm

sirhcm commented Aug 24, 2026

Copy link
Copy Markdown

If I wanted an LLM to do this, I'd ask one myself.

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.

2 participants