Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/CUDApp/blob/main/omega/slices/nvrm.osc # 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 Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `CUDApp / omega / slices / nvrm.osc` 141 lines · 4778 bytes Raw Blame History 1 // slice-entry: gp_entry gpput_off span_ok enqueue retire channel_plan 2 // CUDA++ NVRM client, in Omega. This is the submit half of nvrm.c: the GP entry, 3 // the ring, the retire rule, and the channel plan. The C client asked the driver 4 // for the work-submit token (command 0xc36f0108). This plan computes it. Channel 5 // in bits 11:0, runlist in bits 22:16, the GB100 form. Slot 15 of the plan is 0, 6 // meaning that command is not issued. 7 // GP entry from clc96f.h: GET is the low 40 bits of a dword-aligned VA, LEVEL_MAIN 8 // is 0 (bit 41 clear), LENGTH is nwords in bits 62:42, SYNC_PROCEED is 0 (bit 63 9 // clear). The C client sets bit 41, which the header defines as LEVEL_SUBROUTINE. 10 // This function does not. Expected values from Wolfram. 11 // slice-run: gp_entry bytes: 4096 4 -> `17592186048512` 12 // slice-run: gp_entry bytes: `305419896` 1 -> `4398351931000` 13 // slice-run: gp_entry bytes: `1095216660496` 8 -> `36279588749328` 14 // slice-run: gp_entry bytes: 4097 4 -> `18446744073709551615` 15 // slice-run: gp_entry bytes: `1099511627776` 4 -> `18446744073709551615` 16 // slice-run: gp_entry bytes: 0 0 -> `18446744073709551615` 17 // slice-run: gp_entry bytes: 0 `2097152` -> `18446744073709551615` 18 // slice-run: gp_entry bytes: 0 `2097151` -> `9223367638808264704` 19 // slice-run: gpput_off bytes: 1024 -> 8332 20 // slice-run: gpput_off bytes: 1 -> `18446744073709551615` 21 // slice-run: span_ok bytes:`00000000000000000000000000000000` 0 4 -> 0 22 // slice-run: span_ok bytes:`00000000000000000000000000000000` 4 4 -> `18446744073709551615` 23 // slice-run: span_ok bytes:`00000000000000000000000000000000` 1 1 -> `18446744073709551615` 24 // slice-run: enqueue cells:4=0,0,0,0 4096 4 cells:8=0,0,4,0,0,0,0,0 -> 1 cells=`17592186048512`,0,0,0 25 // slice-run: enqueue cells:4=0,0,0,0 4096 4 cells:8=3,0,4,0,0,0,0,0 -> `18446744073709551615` 26 // slice-run: retire cells:4=5,0,0,0 3 -> 3 cells=5,3,0,0 27 // slice-run: retire cells:4=5,0,0,0 9 -> 0 cells=5,0,0,0 28 // slice-run: channel_plan cells:16 3 42 -> 196650 cells=41068,1,36967,1,65536,`1048576`,1024,8192,51567,52928,196650,`67108864`,144,50785,140,0 29 // slice-run: channel_plan cells:16 128 0 -> `18446744073709551615` 30 31 fn gp_entry(b: bytes, va: u64, nwords: u64) -> u64 { 32 if b.len > 0 { 33 return `18446744073709551615`; 34 } 35 if va & 3 != 0 { 36 return `18446744073709551615`; 37 } 38 if va >= `1099511627776` { 39 return `18446744073709551615`; 40 } 41 if nwords == 0 || nwords > `2097151` { 42 return `18446744073709551615`; 43 } 44 return va | (nwords << 42); 45 } 46 47 fn gpput_off(b: bytes, entries: u64) -> u64 { 48 if b.len > 0 { 49 return `18446744073709551615`; 50 } 51 if entries < 2 || entries > 65536 { 52 return `18446744073709551615`; 53 } 54 return entries * 8 + 140; 55 } 56 57 fn span_ok(b: bytes, off: u64, nwords: u64) -> u64 { 58 if off & 3 != 0 { 59 return `18446744073709551615`; 60 } 61 if nwords == 0 || nwords > `2097151` { 62 return `18446744073709551615`; 63 } 64 if nwords > `4611686018427387903` { 65 return `18446744073709551615`; 66 } 67 let nbytes: u64 = nwords * 4; 68 if off > `18446744073709551615` - nbytes { 69 return `18446744073709551615`; 70 } 71 if off + nbytes > b.len { 72 return `18446744073709551615`; 73 } 74 return 0; 75 } 76 77 fn enqueue(ring: cells, va: u64, nwords: u64, st: cells) -> u64 { 78 if st.len < 4 || ring.len < 2 { 79 return `18446744073709551615`; 80 } 81 let put: u64 = st[0]; 82 let retired: u64 = st[1]; 83 let entries: u64 = st[2]; 84 if entries != ring.len || entries < 2 { 85 return `18446744073709551615`; 86 } 87 if put < retired { 88 return `18446744073709551615`; 89 } 90 if put - retired >= entries - 1 { 91 return `18446744073709551615`; 92 } 93 if va & 3 != 0 || va >= `1099511627776` || nwords == 0 || nwords > `2097151` { 94 return `18446744073709551615`; 95 } 96 let idx: u64 = put % entries; 97 ring[idx] = va | (nwords << 42); 98 st[0] = put + 1; 99 st[3] = (put + 1) % entries; 100 return put + 1; 101 } 102 103 fn retire(st: cells, upto: u64) -> u64 { 104 if st.len < 2 { 105 return `18446744073709551615`; 106 } 107 let put: u64 = st[0]; 108 let retired: u64 = st[1]; 109 if upto >= retired && upto <= put { 110 st[1] = upto; 111 return upto; 112 } 113 return retired; 114 } 115 116 fn channel_plan(st: cells, runlist: u64, channel: u64) -> u64 { 117 if st.len < 16 { 118 return `18446744073709551615`; 119 } 120 if channel > 4095 || runlist > 127 { 121 return `18446744073709551615`; 122 } 123 let token: u64 = channel | (runlist << 16); 124 st[0] = 41068; 125 st[1] = 1; 126 st[2] = 36967; 127 st[3] = 1; 128 st[4] = 65536; 129 st[5] = `1048576`; 130 st[6] = 1024; 131 st[7] = 8192; 132 st[8] = 51567; 133 st[9] = 52928; 134 st[10] = token; 135 st[11] = `67108864`; 136 st[12] = 144; 137 st[13] = 50785; 138 st[14] = 140; 139 st[15] = 0; 140 return token; 141 }