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/evidence/MAX-INTEROP/G2/tools/cubin_variants.py # 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 / evidence / MAX-INTEROP / G2 / tools / cubin_variants.py` 335 lines · 16008 bytes Raw Blame History 1 #!/usr/bin/env python3 2 """Gate-2 load-matrix fixtures (diagnostic, host only). 3 4 Builds cubin variants that separate the candidate causes of CUDApp#68's 5 cuModuleLoadData error 200: missing program headers, missing capmerc/merc 6 sections, missing .note.nv.tkinfo, .nv.callgraph, symtab sh_info, the 7 remaining ptxas-only metadata (E5), and container versus machine code (F, G: 8 each kernel's SASS inside the other writer's container). 9 Writes variants/.cubin and variants/MATRIX.tsv (name, fn, mode, 10 expectation, sha256, what it isolates). 11 """ 12 import hashlib 13 import struct 14 import sys 15 from pathlib import Path 16 17 HERE = Path(__file__).resolve().parent 18 CTL = HERE / "ctl.cubin" 19 STALE = Path("/dev/shm/cudapp-max/evidence/MAX-INTEROP/68/matmul-16x16x8.cubin") 20 MAIN = HERE / "omega-main-artifact/matmul-16x16x8.cubin" 21 SM80 = Path.home() / "workspace/maxinterop/max-source/max/kernels/test/gpu/device_context/data/vec_add.sm80.cubin" 22 OUT = HERE / "variants" 23 FN = "omega_matmul_bf16" 24 25 SH = struct.Struct(" 200 on other GPUs). 208 e = Elf(main_raw) 209 ti = e.add_section(".note.nv.tkinfo", tkh[1], tkh[2], tkh[8], tk) 210 e.set_sh(e.index(".note.nv.cuinfo"), 6, ti) 211 emit("E2-omega-tkinfo-ptxas", bytes(e.b), FN, "run", "UNKNOWN", ".note.nv.tkinfo (ptxas bytes)") 212 e = Elf(main_raw) 213 ti = e.add_section(".note.nv.tkinfo", tkh[1], tkh[2], tkh[8], own_tkinfo(tk)) 214 e.set_sh(e.index(".note.nv.cuinfo"), 6, ti) 215 emit("E3-omega-tkinfo-own", bytes(e.b), FN, "run", "UNKNOWN", ".note.nv.tkinfo (own strings)") 216 e = Elf(main_raw) 217 ti = e.add_section(".note.nv.tkinfo", tkh[1], tkh[2], tkh[8], tk) 218 e.set_sh(e.index(".note.nv.cuinfo"), 6, ti) 219 e.add_section(".nv.callgraph", cgh[1], cgh[2], cgh[8], callgraph, link=e.index(".symtab"), entsize=cgh[9]) 220 st = e.index(".symtab") 221 e.set_sh(st, 7, e.shdrs()[st][5] // 24) 222 emit("E4-omega-tkinfo-cg-symfix", bytes(e.b), FN, "run", "UNKNOWN", "all three metadata gaps") 223 # E5: E4 plus every remaining ptxas-only item except merc and .debug_frame: 224 # EXIT_INSTR_OFFSETS + CRS_STACK_SIZE, the two reserved-smem symbols, and 225 # .nv.constant0 sh_link/align as ptxas writes them. 226 ctl_text = ctl.data(ctl.index(".text." + FN)) 227 assert exit_offsets(ctl_text) == [0x30, 0x780], "EXIT scan disagrees with cuobjdump on the control" 228 main_e = Elf(main_raw) 229 omega_text = main_e.data(main_e.index(".text." + FN)) 230 omega_exits = exit_offsets(omega_text) 231 assert omega_exits == [0x400], omega_exits # nvdisasm 13.0: /*0400*/ EXIT 232 ki = e.index(".nv.info." + FN) 233 ents = nvinfo(e.data(ki)) 234 at = next(n for n, x in enumerate(ents) if x[1] == 0x4A) + 1 235 ents[at:at] = [[4, EXIT_OFFS, struct.pack(f"<{len(omega_exits)}I", *omega_exits)], [4, CRS_STACK, b"\0" * 4]] 236 e.replace(ki, nvinfo_pack(ents), 4) 237 sti, sx = e.index(".symtab"), e.index(".strtab") 238 strtab = e.data(sx) 239 names = [len(strtab), len(strtab) + len(".nv.reservedSmem.offset0") + 1] 240 e.replace(sx, strtab + b".nv.reservedSmem.offset0\0__nv_reservedSMEM_offset_0_alias\0", 1) 241 syms = e.data(sti) + SYM.pack(names[0], 0x21, 0, 0, 0x40, 4) + SYM.pack(names[1], 0x20, 0xA0, e.index(".nv.shared.reserved.0"), 0x40, 0) 242 e.replace(sti, syms, 8) 243 e.set_sh(sti, 7, len(syms) // 24) 244 c0 = e.index(".nv.constant0." + FN) 245 e.set_sh(c0, 6, 0) 246 e.set_sh(c0, 8, 4) 247 emit("E5-omega-allmeta", bytes(e.b), FN, "run", "UNKNOWN", "E4 + exit offsets, crs, smem syms, cbank0 link/align") 248 e5 = bytes(e.b) 249 # F: the control's container without merc (B) carrying Omega's machine code. 250 # The text shrinks in place (0x880 -> 0x480); its segment, symbol size and 251 # EXIT offsets follow. REGCOUNT stays the control's 40: Omega's code writes R0..R31 252 # (peak 32), ptxas declares max register + 3 (control R37 -> 40, mma R15 -> 18). cbank0 is all zero in both. 253 f = Elf(bytes(nomerc.b)) 254 ti = f.index(".text." + FN) 255 th = f.shdrs()[ti] 256 f.b[th[4] : th[4] + th[5]] = omega_text + b"\0" * (th[5] - len(omega_text)) 257 f.set_sh(ti, 5, len(omega_text)) 258 j = f.text_phdr(th[4]) 259 ph = f.phdr(j) 260 ph[5] = ph[6] = len(omega_text) 261 f.set_phdr(j, ph) 262 k = th[7] # .text sh_info = the function symbol 263 s = f.sym(k) 264 s[5] = len(omega_text) 265 f.set_sym(k, s) 266 ki = f.index(".nv.info." + FN) 267 f.replace(ki, nvinfo_pack(set_attr(nvinfo(f.data(ki)), EXIT_OFFS, struct.pack(f"<{len(omega_exits)}I", *omega_exits))), 4) 268 emit("F-ctlcontainer-omega-sass", bytes(f.b), FN, "run", "UNKNOWN: load => Omega SASS accepted", "machine code vs container (ptxas container)") 269 # G: the current CUDApp container (D) carrying the control's machine code. 270 # The text moves to EOF (0x480 -> 0x880) with its segment; symbol size, 271 # REGCOUNT 40 and MAXREG 0xff follow the control's code. The old Omega 272 # bytes are zeroed, so each of F and G holds exactly one kernel's code. 273 g = Elf(main_raw) 274 ti = g.index(".text." + FN) 275 th = g.shdrs()[ti] 276 j = g.text_phdr(th[4]) 277 g.replace(ti, ctl_text, 128) 278 g.b[th[4] : th[4] + th[5]] = b"\0" * th[5] 279 ph = g.phdr(j) 280 ph[2], ph[5], ph[6] = g.shdrs()[ti][4], len(ctl_text), len(ctl_text) 281 g.set_phdr(j, ph) 282 k = th[7] 283 s = g.sym(k) 284 s[5] = len(ctl_text) 285 g.set_sym(k, s) 286 mi = g.index(".nv.info") 287 g.replace(mi, nvinfo_pack(set_attr(nvinfo(g.data(mi)), REGCOUNT, struct.pack(" CUDApp container accepted", "machine code vs container (CUDApp container)") 291 # H: register count and ISA class, the only E5-vs-F metadata differences left 292 # (static diff 2026-10-31: same text, tkinfo, cuinfo, cbank0, e_flags). 293 def with_meta(base, regs=None, maxreg=None, isa=None): 294 v = Elf(base) 295 def put(name, ents): 296 i = v.index(name) 297 h = v.shdrs()[i] 298 new = nvinfo_pack(ents) 299 assert len(new) == h[5] 300 v.b[h[4] : h[4] + h[5]] = new 301 if regs is not None: 302 ents = nvinfo(v.data(v.index(".nv.info"))) 303 sym = struct.unpack_from("