code wiki / _hdl_build / nx_kfd.nx

nx_kfd.nx

buildroot/runtime/_hdl_build/nx_kfd.nx

2765 B45 linesdepth 3pulls 3 transitivereach 1 importersview sourcekind library
docsdependenciesstructsconstsfunctions

about

nx_kfd.nx -- the native-Linux AMD executor shim (/dev/kfd AM/KFD path), sibling to nx_nv (NVIDIA) + nx_dxg (WSL2). Modeled on tinygrad's ops_amd.py AM driver: PM4 ring buffer + wptr + doorbell, bypassing the MES scheduler firmware = the MOST-sovereign GPU path per deep-research. Composes PM4 packets (nx_pm4_asm) into a compute-queue ring, updates wptr, rings the doorbell. Runs on a native-Linux / rented AMD cloud instance (brick-safe, rule #26). LOCALLY-VERIFIABLE (gated): the PM4 compute-dispatch stream composition (via nx_pm4_asm, already gated). CLOUD-PENDING (structured): the KFD queue creation (AMDKFD_IOC_CREATE_QUEUE on /dev/kfd) + the ring/doorbell BAR map -- completed against the instance's ROCt/KFD ABI on first cloud run. Pure funcs, no main. license_tier: ORIGINAL

dependencies 2 imports · 1 importers

nx_syscalls.nx nx_pm4_asm.nx nx_kfd.nx nx_kfd_gate.nx

imports: nx_syscalls.nxnx_pm4_asm.nx

imported by: nx_kfd_gate.nx

structs

none

consts

14const KFD_IOC_CREATE_QUEUE: i64 = 0x02
15const KFD_IOC_CREATE_EVENT: i64 = 0x05
16const KFD_IOC_ALLOC_MEMORY_OF_GPU: i64 = 0x16

functions

18func kfd_open() -> i64 { return sys_openat_rd("/dev/kfd" as *u8) }
called by 1: main calls 1: sys_openat_rd
19func kfd_open_render() -> i64 { return sys_openat_rd("/dev/dri/renderD128" as *u8) }
calls 1: sys_openat_rd
22func pm4_ring_put(ring: *u8, off: i64, dw: i64) -> i64 { let w: *u8 = (ring as i64 + off) as *u8; w[0]=(dw&0xff) as u8; w[1]=((dw>>8)&0xff) as u8; w[2]=((dw>>16)&0xff) as u8; w[3]=((dw>>24)&0xff) as u8; return 0 }
26func pm4_compose_dispatch(ring: *u8, reg_base: i64, n_regs: i64, dim_x: i64, dim_y: i64, dim_z: i64) -> i64
called by 1: main calls 2: pm4_ring_putpm4_packet3
41func kfd_doorbell_ring(doorbell: i64, wptr_dwords: i64) -> i64