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/omega-mv/blob/main/seed/tensix/oracle.py # omega-mv Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance. Brought by drakestapleton Sign in to star 1 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-mv / seed / tensix / oracle.py` 137 lines ยท 7092 bytes Raw Blame History 1 #!/usr/bin/env python3 2 # oracle.py -- interop oracle, not Omega-native; never generates kernels. 3 # 4 # Host dependency (oracle only): Python 3 standard library (ctypes, struct). It moves bytes that asm2 made 5 # into two outside checkers and moves the result back out; it never writes, changes or chooses an 6 # instruction word. Omega replacement: an .om host loader once Omega has a dlopen/FFI word (ttsim path) 7 # and a byte-writer for ELF headers (qemu path); both are proposals, not implemented. 8 # 9 # oracle.py ttsim LIB ARCH IMAGE A B N OUT 10 # Tenstorrent ttsim (libttsim_{wh,bh}), the vendor's open simulator, driven through its PCI Express 11 # interface only, the way a host driver drives a card: read BAR0 from config space, point one TLB 12 # window at Tensix tile L1, hold the tile's five RISC-V cores in soft reset, write IMAGE at L1 0x0 13 # (the reset pc of RISCV B), the argument block at 0x1000, A at 0x2000, B at 0x3000, then release 14 # RISCV B only and clock until the stub writes the done mark 0x0600d000 at 0x1010. OUT gets the 4N 15 # bytes at 0x4000. ARCH is wh (Wormhole B0, n150) or bh (Blackhole A0, p150). 16 # oracle.py elf IMAGE A B N OUT 17 # Wraps IMAGE in a 32-bit RISC-V ELF executable for qemu-riscv32 (Linux user mode): one load segment 18 # at 0x10000, IMAGE at 0x10100 (the entry), argument block 0x11000, A 0x12000, B 0x13000, out 0x14000. 19 # Sources (read 2026-10-26): tt-isa-documentation `be833101` WormholeB0/PCIExpressTile/TLBs.md, 20 # BlackholeA0/PCIExpressTile/HostToDeviceTLBs.md, */TensixTile/SoftReset.md, */NoC/Coordinates.md; 21 # ttsim `b3620244` src/libttsim.cpp (API), src/pcie.cpp (config space); ELF: System V gABI, RISC-V psABI. 22 import ctypes, struct, sys 23 24 L1_ARGS, L1_A, L1_B, L1_OUT, DONE = 0x1000, 0x2000, 0x3000, 0x4000, 0x0600D000 25 SOFT_RESET_0 = 0xFFB121B0 # RISCV_DEBUG_REG_SOFT_RESET_0 (BH SoftReset.md; WH tile_regs 0xFFB12000+0x1B0) 26 ALL_CORES, BRISC = 0x47800, 0x800 # bits 11 (B), 12-14 (T0-T2), 18 (NC) 27 TLB_CFG = 0x1FC00000 # TLB configuration array in BAR0 (both architectures) 28 29 30 def die(msg): 31 sys.stderr.write("oracle: " + msg + "\n") 32 sys.exit(1) 33 34 35 def words(path, n): 36 data = open(path, "rb").read() 37 if len(data) != 4 * n: 38 die("%s has %d bytes, want %d" % (path, len(data), 4 * n)) 39 return data 40 41 42 def ttsim(lib_path, arch, image_path, a_path, b_path, n, out_path): 43 lib = ctypes.CDLL(lib_path) 44 u32, u64, vp = ctypes.c_uint32, ctypes.c_uint64, ctypes.c_void_p 45 lib.libttsim_pci_config_rd32.restype = u32 46 lib.libttsim_pci_config_rd32.argtypes = [u32, u32] 47 lib.libttsim_pci_mem_wr_bytes.argtypes = [u64, vp, u32] 48 lib.libttsim_pci_mem_rd_bytes.argtypes = [u64, vp, u32] 49 lib.libttsim_clock.argtypes = [u32] 50 lib.libttsim_init() 51 ident = lib.libttsim_pci_config_rd32(0, 0x0) 52 want = {"wh": 0x401E1E52, "bh": 0xB1401E52}[arch] 53 if ident != want: 54 die("config space id 0x%08x, want 0x%08x for %s" % (ident, want, arch)) 55 if not lib.libttsim_pci_config_rd32(0, 0x4) & 2: 56 die("BAR memory decode (Command.MSE) is off") 57 bar0 = (lib.libttsim_pci_config_rd32(0, 0x10) & ~0xF) | (lib.libttsim_pci_config_rd32(0, 0x14) << 32) 58 59 def wr(addr, data): 60 buf = ctypes.create_string_buffer(data, len(data)) 61 lib.libttsim_pci_mem_wr_bytes(bar0 + addr, buf, len(data)) 62 63 def rd(addr, size): 64 buf = ctypes.create_string_buffer(size) 65 lib.libttsim_pci_mem_rd_bytes(bar0 + addr, buf, size) 66 return buf.raw 67 68 if arch == "wh": 69 # 1 MiB windows: local_offset = top 16 bits of the 36-bit tile address, x_end at bit 16, y_end at 22. 70 x, y, shift = 1, 1, 20 # NoC #0 (1,1) is a Tensix tile (WormholeB0/NoC/Coordinates.md) 71 72 def point(window, tile_addr): 73 cfg = (tile_addr >> shift) | (x << 16) | (y << 22) 74 wr(TLB_CFG + 8 * window, struct.pack("> 21, x_end at bit 43, y_end at 49. 78 x, y, shift = 1, 2, 21 # NoC #0 (1,2) is a Tensix tile (BlackholeA0/NoC/Coordinates.md) 79 80 def point(window, tile_addr): 81 cfg = (tile_addr >> shift) | (x << 43) | (y << 49) 82 for i in range(3): # three 32-bit register writes 83 wr(TLB_CFG + 12 * window + 4 * i, struct.pack("> (32 * i)) & 0xFFFFFFFF)) 84 return window << shift 85 86 l1 = point(0, 0) 87 regs = point(1, SOFT_RESET_0 & ~((1 << shift) - 1)) + (SOFT_RESET_0 & ((1 << shift) - 1)) 88 reset_before = struct.unpack("= limit: 100 die("no done mark after %d clocks" % clocks) 101 lib.libttsim_clock(step) 102 clocks += step 103 open(out_path, "wb").write(rd(l1 + L1_OUT, 4 * n)) 104 wr(regs, struct.pack(" args: 114 die("image too large") 115 body = bytearray(out + 4 * n) 116 body[code:code + len(image)] = image 117 body[args:args + 16] = struct.pack(" vaddr 0x10000, read/write/execute, page aligned. 125 phdr = struct.pack("