CUDApp
CUDA++: AIEN’s GPU machine-code toolchain, runtime and driver client for NVIDIA GPUs without the CUDA toolkit. Hardware coverage and driver replacement limits are explicit.
Brought by drakestapleton
CUDApp / omega / slices / sequencer.osc
| 1 | // slice-entry: seq_run seq_store |
| 2 | // CUDA++ sequencer, in Omega. The chip sends this program back during boot and NVIDIA's |
| 3 | // driver used to run it (kgspExecuteSequencerBuffer). Opcodes and sizes are the ones in |
| 4 | // rmgspseq.h from the 580.173.02 open driver: |
| 5 | // 0 write (addr, val), 1 modify (addr, mask, val), 2 poll (addr, mask, val, timeout, error), |
| 6 | // 3 delay (us), 4 store (addr, index), 5..8 core ops. |
| 7 | // Core ops refuse: they restart the chip, and this function has no core to restart. |
| 8 | // mem[0..7] is the register file. mem[8..15] is the save area. An address or a save |
| 9 | // index of 8 or more refuses. end is cmdIndex and must be strictly inside the buffer. |
| 10 | // slice-run: seq_run bytes:0000000001000000bc0a000000000000 3 cells:16 -> 0 cells=0,2748,0,0,0,0,0,0,0,0,0,0,0,0,0,0 |
| 11 | // slice-run: seq_run bytes:01000000020000000f0000000500000000000000 4 cells:16=0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0 -> 0 cells=0,0,245,0,0,0,0,0,0,0,0,0,0,0,0,0 |
| 12 | // slice-run: seq_run bytes:0200000003000000ff000000070000000a0000000100000000000000 6 cells:16=0,0,0,7,0,0,0,0,0,0,0,0,0,0,0,0 -> 0 |
| 13 | // slice-run: seq_run bytes:020000000300000001000000010000000a0000002a00000000000000 6 cells:16 -> 18446744073709551615 |
| 14 | // slice-run: seq_run bytes:030000001900000000000000 2 cells:16 -> 0 |
| 15 | // slice-run: seq_store bytes:04000000040000000000000000000000 3 cells:16=0,0,0,0,17,0,0,0,0,0,0,0,0,0,0,0 -> 17 |
| 16 | // slice-run: seq_run bytes:04000000040000000800000000000000 3 cells:16=0,0,0,0,17,0,0,0,0,0,0,0,0,0,0,0 -> 18446744073709551615 |
| 17 | // slice-run: seq_run bytes:0800000000000000 1 cells:16 -> 18446744073709551615 |
| 18 | // slice-run: seq_run bytes:6300000000000000 1 cells:16 -> 18446744073709551615 |
| 19 | // slice-run: seq_run bytes:000000000100000000000000 2 cells:16 -> 18446744073709551615 |
| 20 | // slice-run: seq_run bytes:0000000001000000bc0a000000000000 4 cells:16 -> 18446744073709551615 |
| 21 | // slice-run: seq_run bytes: 0 cells:16 -> 18446744073709551615 |
| 22 | |
| 23 | fn word_at(b: bytes, i: u64) -> u64 { |
| 24 | let o: u64 = i * 4; |
| 25 | return b[o] | (b[o + 1] << 8) | (b[o + 2] << 16) | (b[o + 3] << 24); |
| 26 | } |
| 27 | |
| 28 | fn payload_n(op: u64) -> u64 { |
| 29 | if op == 0 { |
| 30 | return 2; |
| 31 | } |
| 32 | if op == 1 { |
| 33 | return 3; |
| 34 | } |
| 35 | if op == 2 { |
| 36 | return 5; |
| 37 | } |
| 38 | if op == 3 { |
| 39 | return 1; |
| 40 | } |
| 41 | if op == 4 { |
| 42 | return 2; |
| 43 | } |
| 44 | if op == 5 || op == 6 || op == 7 || op == 8 { |
| 45 | return 0; |
| 46 | } |
| 47 | return 18446744073709551615; |
| 48 | } |
| 49 | |
| 50 | fn seq_run(buf: bytes, end: u64, mem: cells) -> u64 { |
| 51 | if mem.len < 16 { |
| 52 | return 18446744073709551615; |
| 53 | } |
| 54 | if buf.len < 4 { |
| 55 | return 18446744073709551615; |
| 56 | } |
| 57 | if buf.len % 4 != 0 { |
| 58 | return 18446744073709551615; |
| 59 | } |
| 60 | let nwords: u64 = buf.len / 4; |
| 61 | if end >= nwords { |
| 62 | return 18446744073709551615; |
| 63 | } |
| 64 | let mut i: u64 = 0; |
| 65 | while i < end bound 256 { |
| 66 | let op: u64 = word_at(buf, i); |
| 67 | i = i + 1; |
| 68 | let n: u64 = payload_n(op); |
| 69 | if n == 18446744073709551615 { |
| 70 | return 18446744073709551615; |
| 71 | } |
| 72 | if i + n > end { |
| 73 | return 18446744073709551615; |
| 74 | } |
| 75 | if op >= 5 { |
| 76 | return 18446744073709551615; |
| 77 | } |
| 78 | if op == 0 { |
| 79 | let addr: u64 = word_at(buf, i); |
| 80 | if addr >= 8 { |
| 81 | return 18446744073709551615; |
| 82 | } |
| 83 | mem[addr] = word_at(buf, i + 1); |
| 84 | } |
| 85 | if op == 1 { |
| 86 | let addr: u64 = word_at(buf, i); |
| 87 | if addr >= 8 { |
| 88 | return 18446744073709551615; |
| 89 | } |
| 90 | let mask: u64 = word_at(buf, i + 1); |
| 91 | let val: u64 = word_at(buf, i + 2); |
| 92 | mem[addr] = (mem[addr] & (~mask)) | val; |
| 93 | } |
| 94 | if op == 2 { |
| 95 | let addr: u64 = word_at(buf, i); |
| 96 | if addr >= 8 { |
| 97 | return 18446744073709551615; |
| 98 | } |
| 99 | let mask: u64 = word_at(buf, i + 1); |
| 100 | let val: u64 = word_at(buf, i + 2); |
| 101 | if (mem[addr] & mask) != val { |
| 102 | return 18446744073709551615; |
| 103 | } |
| 104 | } |
| 105 | if op == 4 { |
| 106 | let addr: u64 = word_at(buf, i); |
| 107 | let index: u64 = word_at(buf, i + 1); |
| 108 | if addr >= 8 || index >= 8 { |
| 109 | return 18446744073709551615; |
| 110 | } |
| 111 | mem[8 + index] = mem[addr]; |
| 112 | } |
| 113 | i = i + n; |
| 114 | } |
| 115 | return 0; |
| 116 | } |
| 117 | |
| 118 | fn seq_store(buf: bytes, end: u64, mem: cells) -> u64 { |
| 119 | if seq_run(buf, end, mem) != 0 { |
| 120 | return 18446744073709551615; |
| 121 | } |
| 122 | return mem[8]; |
| 123 | } |