среда, 2 декабря 2026 г.

yields in SASS instructions

As I claimed here it seems that Yield flags has elusive pattern, but on other hand they inserted strictly deterministically - you can recompile the same cubin and check that Yields always take place for the same instructions

So I added to my dg2.pl option -Y to produce CSV files with 9 params like instruction name, yield flag, stall count, read/write/wait barriers and so on. If you are AI addicted - before further reading you can play with couple of samples to check if your favorite AI for mega$$/month can extract simple pattern

суббота, 21 ноября 2026 г.

why it's so hard to make SASS assembler?

Short answer: bcs paranoid nvidia don't disclose its ABI (and punishes you silently when you get them wrong)

Indeed, their ISA is known but I know only couple of nominally functional assemblers for modern SM (given that their nvasm_internal used for many RT kernels remains private and not available)

CuAssembler

  • last update was 3 years ago
  • new SM90+ are not supported
  • many of listed below problems just not solved (although you can mitigate some)

Unnamed asm from nvidia-sass-document

Chinese comrade invented its own syntax looking like
LDC.64 {R0,R1}, #param(data);[7:7:{{}}:5:1] 
It try to solve couple of problems with nvdisasm output:
  1. ambiguity for wide operands
  2. part after semicolon describes explicit scheduler settings like usched_info, req_bit_set etc (like in good old maxas)

I think that having own syntax is bad idea generally. Currently the only trusted source of SASS asm is official nvdisasm and so we should at least has capability to parse it and then automatically compare to assure that our encoder/decoder works

Let's classify what problems can arise if our generated CUBIN missed or malformed some data

  • CUBIN won't loading. Difficulty: easy, you can always compare with generated by ptxas and find out what is wrong
  • CUBIN loading but some tools (like cupti, nsight, memcheck/synccheck) refused to work with it. Difficulty: easy, see previous point
  • CUBIN loading but fails in some rare edge-cases. Difficulty: medium, but can be hard if we can't use cuda-gdb
  • CUBIN loading and successfully working, but due to some missed data (for example for scheduler) at not optimal performance. As usually nvidia doing this totally silently - no logs/messages from driver. Difficulty: nightmare, such cases extremely hard to detect 

And now lets list what must be generated to get good & wealthy CUBIN - keep in mind that this set is incomplete

пятница, 6 ноября 2026 г.

notes on PTX verification

I recently read article called "Formalizing PTX in Lean to Prove GPU Kernel Correctness". All you need for hype - gpu, ptx, lean for the Navier-Stokes equations

As is customary in such cases, there is no code, however paper contains remarkable phrase:

The interpreter implements 81 instruction forms

Just some numbers: ptxas from sdk 13.1 has has 270 unique instructions in 1420 forms, from sdk 13.4 - 291 instructions in 1669 forms. How do I know this? Well

So they covered in best case 81 / 270 = 30% of all PTX instructions, and now they’ll be shouting loudly all over the internet "software solved", "all your code belongs to us", "your entire career is now a $20/month subscription" and the rest of the obligatory misanthropic repertoire

Ok, let's examine some real projects in this field - I mean you even can check their source code

SentyWard

Parser is just blood from eyes and it is absolutely impossible to figure out which instructions and attributes it can recognize. Executor doesn't look even slightly better but from numerous

if (op == "shl"

if (In(op, {"shr", "div", "rem"})

at least we can estimate that its support of PTX is incomplete

volta

function parse_opcode looks terrible, but at least we can estimate number of supported PTX instructions: ~160 / 270 = 60%. Twice as much, but it's not enough for hype because there's no lean

cuKLEE

Strictly speaking, it can only parse PTX inline asm, and as you can see it also understands very limited number of instructions

Conclusion

There are no verification tools with full support of PTX - mainly bcs evil nvidia refuses to publish formal PTX spec (and instead of fixing bugs in official documentation prefers to release something with name "nsight-perf-sdk-for-ai")

среда, 4 ноября 2026 г.

ebnf & parser of PTX from sdk 13.4

Observing raw data from previous part we can conclude that many (17) new attributes were inserted in middle of indices table thereby shifting the indices. And even worse - they were inserted in many arbitrary places. So instead of patching long-suffering script iptx.pl I made its clone iptx3.pl (DRY, yeah)

After some brute-forcing & RE I was able to identify 130 attributes masks - so still unknown 8. Given that at least 6 of them describe semantics of instruction - actually only 2 indices currently unknown:
  • 13:5 for spdecompress
  • 17:0 for tensormap.replace

EBNF

5246 lines vs 4460 from old version

Intrinsics

I wrote script to compare them. No new instrinsics but 3 were removed:
  • __cuda_sm20_div_rn_ftz_f32
  • __cuda_sm20_div_rn_f32
  • __cuda_sm20_div_rn_noftz_f32_slowpath
See raw data in files ptx_intr.txt & ptx134_intr.txt

Expanded macros

Seems that all newly added PTX instructions actually implemented as macros and expanding to calls of __nv_ptx_builtin_ocg_XXX. Unfortunately I was unable to find those functions inside ptxas, and in RT kernels too. Some (like fabricXXX) described here
 
However we always can generate ptx and examine what it actually compiles into:
__HIR0X1C0.8.U2.2TO4.X4 R0, R8, R8, UR4 ;

It's funny that sample for spdecompress from official doc doesn't even compile. And for trace.marks too. I wonder — has even one of the many morons on Twitter, who keep posting this document as if it were the official nvidia assembler manual, actually tried verifying anything in it?

Parser

New data from iptx3.pl -C

понедельник, 26 октября 2026 г.

machineIR passes & mlir dialects from tileiras & cute dsl

Previous parts: 1, 2 & 3

Let's continue to dissect compilers from nvidia. This time, I decided to examine compilers that are guaranteed to contain their custom MLIR dialects - tileiras and CuTe DSL

tileiras

As usual, their official repository is completely useless - it does not contain code for conversions/lowering so you can't build your own version of this compiler. So I used exactly the same techniques and scripts for its analysis from previous part

Strings from constructors - contain nothing of value

Passes shows 5 custom missed in vanilla llvm:

  1. nvptx-set-global-array-alignment (Find good alignment for statically sized global/shared arrays)
  2. nvptx-set-local-array-alignment (Find good alignment for statically sized alloca arrays)
  3. nvvm-peephole-optimizer (NVVM Peephole Optimizer)
  4. lower-aggr-copies (Lower Aggregate Copies)
  5. mergereturn (Unify function exit nodes)

As you can see this list differs from cicc and prompts some philosophical musings: just how many LLVM forks do they have, and are those dev-teams even aware of each other’s existence?

enumerate registered MLIR dialects

There is very good doc about MLIR capabilities from NPU compiler, however it does not contains answer to our question - how we can extract from LLVM binary all registered MLIR dialects

So I spent several days poking around megabytes of MLIR sources. It seems that perfect solution does not exist (due of heavy using of template black magic), but we can get practically good one - method MLIRContext::getOrLoadDialect:

  • it can be identified by string "a dialect with namespace". Warning: there are another methods using this string like MLIRContext::getOrLoadDynamicDialect but fortunately they usually not linked with custom LLVM forks
  • it's called from BytecodeDialect::load method and so we can catch all dialects allowed in input .bc files

So I wrote yet another dirty IDC script to extract MLIR dialects - total 30 unique


CuTe DSL

Official repository claims that you can build your own compiler with vanilla LLVM (I never verified if that is true). What they didn't said - in their python packages compiler based on their closed-source LLVM fork, in my case I dissected _cutlass_ir.cpython-313-x86_64-linux-gnu.so

First remarkable thing is its size - 144Mb, for example size of cicc is 78Mb and size of tileiras 89Mb. Highly unlikely that python bindings have size of ~60Mb, so lets check  

strings from constructors

We could remark something very familiar - string like AddWaitForCCOrPOffDeck & co. Also section .rodata has huge blobs for "fermi macros", so we can conclude that it was linked with PTXAS

machineIR passes

+ 54 new passes, wow! Also it has 2767 nvvm intrinsics vs 1998 in plain LLVM

MLIR dialects 

As you can see it contains 32, including our beloved cute & cute_nvgpu

 

Conclusion

It appears that CuTe DSL compiler based on the same LLVM fork as cicc and so produces fastest code, also it supports 32 MLIR dialects and scripting from python - just combo

среда, 21 октября 2026 г.

new ptx instructions from cuda sdk 13.4

File with extracted instructions, attributes masks and operands - 1669 items (vs 1420 in version from 13.0). Being lazy person I also wrote script to compare them (in Perl, of course). 21 newly added instructions:

  • applypriority.async.bulk (1 forms)
  • applypriority.async.bulk.tensor (12 forms)
  • clmad.hi (2 forms)
  • clmad.lo (2 forms)
  • fabric.submit (1 forms)
  • fabric.try_atom.async (13 forms)
  • fabric.try_get.async (2 forms)
  • fabric.try_get.async.tensor (10 forms)
  • fabric.try_pullred.async (5 forms)
  • fabric.try_put.async (8 forms)
  • fabric.try_put.async.tensor (20 forms)
  • fabric.try_red.async (16 forms)
  • fabric.try_red.async.tensor (20 forms)
  • fabric.wait (1 forms)
  • mbarrier.check_layout (1 forms)
  • multimem.red.async (1 forms)
  • multimem.st.async (3 forms)
  • spcompress (1 forms)
  • spdecompress (1 forms)
  • tcgen05.ld.red.spcompress (1 forms)
  • tcgen05.ld.spcompress (1 forms)

It seems that attribute mask has the same size 20 bytes:
270 uniq ins
FD FF FF FF F1 FF FF 9F F9 FF E7 CF FF F3 DF FF FF 00 00 00
length of mask 121
291 uniq ins
FD FF FF FF FB FF FF FF E7 FF 9F 3F FF FF 7F FF FF FF 29 00
length of mask 138

As you can see they added 138 - 121 = 17 new attributes. But worst of all, the attribute indices have changed too. Lets compare for example first form for ld instruction:
old:
60 00 00 00 A0 EC 03 00 00 00 00 00 01 00 00 00 00 00 00 00
new
C0 00 00 00 A0 EC 03 00 00 00 00 00 04 00 00 80 00 00 00 00

Also I made option -f to compare new forms - 127 new forms, like
perl ip_cmp.pl -f ptx_ops3.txt
--- 249 lines
add: 11 old forms, 17 new
 line 751: add    ddd    Q32Q32
 line 752: add    dcd    Q32R16
 line 753: add    012    H64H32H64
 line 754: add    012    H64E32H64
 line 755: add    012    H32H64H64
 line 756: add    012    E32H64H64

etc

понедельник, 19 октября 2026 г.

inefficient uniform registers allocation in ptxas

While poking around RT kernels (extracted from libcuda.so) I stumbled upon very remarkable sample - sm159.elf. First let's check what tools were used to compile it - dump section .note.nv.tkinfo (here it has index 5):

readelf -x 5 sm159.elf

Hex dump of section '.note.nv.tkinfo':
  0x00000000 0c000000 9c000000 d0070000 4e564944 ............NVID
  0x00000010 49412043 6f727000 02000000 00000000 IA Corp.........
  0x00000020 01000000 07000000 35000000 54000000 ........5...T...
  0x00000030 00707478 61730043 75646120 636f6d70 .ptxas.Cuda comp
  0x00000040 696c6174 696f6e20 746f6f6c 732c2072 ilation tools, r
  0x00000050 656c6561 73652031 332e312c 20563133 elease 13.1, V13
  0x00000060 2e312e30 00427569 6c642063 7564615f .1.0.Build cuda_
  0x00000070 612e6375 64615f61 2e333630 34343438 a.cuda_a.3604448
  0x00000080 365f3000 2d6d6178 72726567 636f756e 6_0.-maxrregcoun
  0x00000090 74203332 202d6172 63682073 6d5f3132 t 32 -arch sm_12
  0x000000a0 31202d64 6c636d20 6367202d 6d203634 1 -dlcm cg -m 64
  0x000000b0 20000000                             ... 
As you can see it was compiled with regular ptxas from SDK 13.1 (and not with nvasm_internal). This file contains huge function _ZN6RefTMA12TMACommand_tC1ERKNS_19ptx_inst_parametersE - first branch happens at offset 0xc70 and first back-edge at 37c0. Let's take a look at this piece of code:
    /*01b0*/      LDC.64 R28, c[0x0][0x358] ; move base ptr into R28-29
    /*01c0*/      R2UR UR4, R28.reuse ; assign UR4
    /*01d0*/      R2UR UR5, R29.reuse ;
    /*01e0*/      R2UR UR6, R28 ;
    /*01f0*/      R2UR UR7, R29 ;
    /*0200*/      R2UR UR8, R28.reuse ; assign the same value from R28-29
    /*0210*/      R2UR UR9, R29.reuse ;
    /*0220*/      R2UR UR10, R28.reuse ;
    /*0230*/      R2UR UR11, R29.reuse ;
    /*0240*/      ST.E desc[UR4][R16.64+0x18], R3 ; use UR4 for desc operand
    /*0250*/      R2UR UR12, R28.reuse ;
    /*0260*/      R2UR UR13, R29 ;
    /*0270*/      ST.E desc[UR6][R16.64+0x38], R3 ;
    /*0280*/      R2UR UR70, R28 ;
    /*0290*/      R2UR UR71, R29.reuse ;
    /*02a0*/      ST.E desc[UR8][R16.64+0x58], R3 ;
    /*02b0*/      R2UR UR68, R28.reuse ;
    /*02c0*/      R2UR UR69, R29.reuse ;
    /*02d0*/      ST.E desc[UR10][R16.64+0x78], R3 ;
    /*02e0*/      R2UR UR66, R28.reuse ;
    /*02f0*/      R2UR UR67, R29 ;
    /*0300*/      ST.E desc[UR12][R16.64+0x118], R5 ;

What noteworthy things can we examine here?