code wiki / _hdl_build / nx_mmaemit.nx
nx_mmaemit.nx source
↩ module page · 28 lines · 1407 B
1// nx_mmaemit.nx -- emit the EXACT 128-bit SASS our sovereign nx_mma_asm encoder produces for the two HMMA
2// instructions in mma_test.cubin (@0x190 R20,R4,R16,RZ and @0x1a0 R16,R4,R18,RZ), plus a corrupted variant
3// (ra 4->6) as a negative control. The host splices these OUR-bytes into the cubin and runs on the 5080.
4import "nx_syscalls.nx"
5import "nx_mma_asm.nx"
6
7func puts(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 }
8func puth(v: i64) -> i64 {
9 let d: *u8 = "0123456789abcdef" as *u8
10 let b: *u8 = sys_mmap(32)
11 var m: i64 = v
12 var k: i64 = 0
13 if m == 0 { b[0]=48 as u8; k=1 }
14 while m > 0 { b[k] = d[m & 15]; m = (m >> 4) & 0xfffffffffffffff; k = k + 1 }
15 puts("0x" as *u8)
16 let o: *u8 = sys_mmap(32)
17 var i: i64 = 0
18 while i < k { o[i] = b[k-1-i]; i = i + 1 }
19 sys_write(1, o, k)
20 return 0
21}
22func main() -> i64 {
23 // opcode HMMA=0x723c ; rc=RZ=0xff ; typebits=0x18 (16816.F32) ; control from cubin high>>40
24 puts("A_lo=" as *u8); puth(nv_mma_low(0x723c, 20, 4, 16)); puts(" A_hi=" as *u8); puth(nv_mma_high(0xff, 0x18, 0x1ff6)); puts("\n" as *u8)
25 puts("B_lo=" as *u8); puth(nv_mma_low(0x723c, 16, 4, 18)); puts(" B_hi=" as *u8); puth(nv_mma_high(0xff, 0x18, 0x2ff0)); puts("\n" as *u8)
26 puts("X_lo=" as *u8); puth(nv_mma_low(0x723c, 20, 6, 16)); puts(" (neg-control: ra 4->6)\n" as *u8)
27 return 0
28}