суббота, 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

ELF sections

I think we now know ~80% (except whole set from Mercury), but highly recommend to read comment:
cuobjdump -elf rejects any cubin whose section #4 is not .debug_frame ("cuobjdump fatal : Invalid ELF")

facepalm.jpg

Also note that for sm100+ .note.nv.tkinfo/.note.nv.cuver must be implemented. Highly likely there are tons of similar bugs in tools from nvidia

Relocs

Their types are known and we even can extract reloc_howto_type. The main problem here is that in nvdisasm output they are indistinguishable and often looks like:
MOV R20, 32@lo((vfprintf_internal + .L_x_0@srel))
So it's totally unclear what form (from 115 possible) should be applied in each case

EIATTRs

I estimate that we now know ~50% of them. I wrote perl script to calculate some statistics - it seems that many (like EIATTR_COROUTINE_RESUME_ID_OFFSETS) never take place
 
Also note that for section .nv.compat you need to fill another set of attributes - EICOMPAT_ATTR_
facepalm2.jpg

Kernel parameters

I identified some small sub-set of them, but
  • they are different in each SM
  • I even can't estimate share of currently known parameters
At least our asm should be capable to detect unknown and raise alerts

Instruction scheduler

Real scheduler model is unknown. Each instruction has so called "stall count" and sum of those count from instruction till place where RaW/WaR/WaW happens must fulfill latency constraints, which is known (if I right parsed their latency tables)
 
The real problem here is that this algo can't be stretched on LLVM machine scheduler and looks like NP-complete

Yields

It seems that scheduling is cooperative and from time to time instructions must switch to another group in warp with yield flag (btw cost of switching is unknown too). I made option -Y for my dg2.pl to collect stat about instructions having yields
 
Unfortunately I just can't find pattern - it seems that even not all instructions with req_bit_set cause yields

Mercury

Total terra incognita - even ISA is unknown, and we can't predict what would happens if we fully remove all sections with data for mercury

 

Комментариев нет:

Отправить комментарий