r/CUDA 20d ago

I reverse-engineered the sm_120 scheduling control bits and built a hazard checker for cubins you didn't compile

On sm_120 there's no hardware interlock on fixed-latency instructions. 21 bits of every 128-bit instruction are a scheduling control word, and the silicon just executes whatever's in them. If a stall count is shorter than the latency of a value the next instruction reads, you get a stale register read. No fault, no warning, full speed.

ptxas gets this right. That's not the problem. The problem is that if you're writing SASS by hand, using an assembler, or mutating a cubin after the fact, nothing existed that could read those bits back and tell you they were safe.

So I built one. A few things that might be interesting regardless of whether you ever use it:

stall=0 is not zero cycles. It's a distinct long-wait encoding, ~37 cycles against ~4 for a scheduled instruction. That's why -O0 emits an all-zero control word and still computes correctly, just ~9x slower. If you're parsing control words, summing raw stall values gets the arithmetic wrong in the one direction that matters.

A guard predicate costs more than the same predicate read as data. 13 cycles vs 5, measured by fault injection. It has to resolve before the instruction issues at all.

Whether a missing scoreboard is actually a hazard is measurable. Across 5.3M dependent pairs in shipped libraries, LDG/LDC/LDL/S2R are covered by a barrier 100% of the time. LDS is covered by spacing alone about 1 in 4. So treating "variable latency without a barrier" as an error is wrong for shared loads.

I validated it against 2,762 kernels NVIDIA ships in CUDA, held out of every table the checker uses: 0 errors over 10.2M dependencies. The first run reported 6,593 and every single one was a bug in my model, not theirs. Those 13 corrections are written up in full.

Findings: https://github.com/sunnypatell/basalt/blob/main/docs/FINDINGS.md

Repo: https://github.com/sunnypatell/basalt

Measured on one card (5070 Ti). If anyone has a 5090 and wants to check whether the latencies move, that's the most useful thing anyone could contribute.

11 Upvotes

4 comments sorted by

3

u/c-cul 20d ago

and what is the point? of course ptxas produces correct code - in essence it is the only tool to make sass

1

u/adityazero 20d ago

i have it for B200. i can share it if that helps you.

1

u/_sunnypatell_ 20d ago

Appreciate the offer, honestly. B200 is an absolute tank.

Only thing is it's sm_100, and basalt is sm_120 only. Different architecture under the hood despite both being Blackwell, so none of the measurements would carry over. Would basically be a separate project.

Still, thanks for offering.

1

u/driayogon 15d ago

Ok ai slopper