пятница, 11 сентября 2026 г.

shrinking holes in SASS allocated registers

In my previous post I discovered that SASS register allocation can have holes - non-contiguous register indices allocated to a function where intermediate registers like R57 remain unused despite R56 and R58 being live/allocated

To estimate size of problem I wrote some code to collect statistics about number (and share) of functions having holes in register allocations:

  • libcublas.so.13.7.0.74.sm_90.cubin
    ; 34 holes in regs (784), 0.043367
    ; 3 holes in uregs (434), 0.006912
    ; 34 functions with holes (0.629630 from total)
  • libcublas.so.13.7.0.608.sm_90.cubin
    ; 41 holes in regs (8546), 0.004798
    ; 15 holes in uregs (2784), 0.005388
    ; 39 functions with holes (0.102632 from total)
  • libcublas.so.13.7.0.935.sm_90.cubin
    ; 19 holes in regs (5016), 0.003788
    ; 17 holes in uregs (2012), 0.008449
    ; 11 functions with holes (0.059783 from total)

As you can see holes occupy up to 4% of total registers (in average 0.3-0.5%) and it's very tempting to try reduce them. It would seem—what could be simpler? If we have something like that
; RHoles max 61: R56 R58

just remap in whole function R61 to R58 and R60 to R56, and then reduce EIATTR_REGCOUNT,right? Well, actually no

To figure out why lets check this innocent-looking instruction:
LDS.128 R16,[R38] &wr=0x4 ?trans2 ;

Actually it writes to 4 sequentially arranged registers R16-R19 and my registers tracker correctly shows this like
; used regs:
;  R18: 80 write
;  R38: 2
;  R17: 80 write
;  R19: 80 write
;  R16: 80 write

It marks R17 as having width index 1, R18 - windex 2 and so on. You can check summary at end of the block:
; R18
;   1310 <- w 2

As you can easily guess, you can remap registers from tail only when they always had zero windex in this function.

So after addition of this logic let's revisit how many holes can be reduced:

  • libcublas.so.13.7.0.74.sm_90.cubin
    ; 34 functions with holes (0.629630 from total), can reduce 4 holes 0.117647 from 34
    ; 4 fully reduced functions 0.117647
  • libcublas.so.13.7.0.608.sm_90.cubin
    ; 39 functions with holes (0.102632 from total), can reduce 1 holes 0.024390 from 41
    ; 1 fully reduced functions 0.025641
  • libcublas.so.13.7.0.935.sm_90.cubin
    ; 11 functions with holes (0.059783 from total), can reduce 3 holes 0.157895 from 19
    ; 1 partially reduced functions 0.090909

Doesn't look all that impressive

Anyway I added to my Ced command R to remap registers/predicates, so for example offset R P1 P2 and
ISETP.GE.AND P1,PT,R07,RZ,PT ?trans1
will become
ISETP.GE.AND P2,PT,R07,RZ,PT ?trans1

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

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