code wiki / _hdl_build / nx_gpu_mem.nx

nx_gpu_mem.nx

buildroot/runtime/_hdl_build/nx_gpu_mem.nx

4038 B67 linesdepth 4pulls 4 transitivereach 1 importersview sourcekind librarytopic gpu
docsdependenciesstructsconstsfunctions

about

nx_gpu_mem.nx -- HEAPS AND RESIDENCY over the dxg door (gpu GP6): allocate, place, make resident, EVICT, with the budget READ from the device, never assumed. One heap = one EXISTINGHEAP allocation of a page-aligned size, placed at a GPU virtual address through the paging queue and made resident; eviction is the device's own EVICT, and the proof that it happened is the device's own paging state (a make-resident after an evict answers DXG_MKRES_PENDING instead of 0). SCOPE, stated once: these heaps are SYSTEM-memory backed (the UMD-less EXISTINGHEAP path R4d measured), so they live in the NON-LOCAL segment; a VRAM (local-segment) heap needs the vendor UMD's private allocation data, the same blocker class as the command ring (gpu.plan GP5 lesson). Exhausting the non-local budget would exhaust the host's RAM, so this lib walks a BOUNDED window under the budget and never crosses it; the exhaust-to-evict test on the local segment is named on the board as owed, not claimed. license_tier: ORIGINAL No hw writes (Rule 26): per-process allocations, released with the process.

dependencies 3 imports · 1 importers

nx_syscalls.nx nx_dxg.nx nx_gpu_sync.nx nx_gpu_mem.nx nx_gpu_mem_gate.nx

imports: nx_syscalls.nxnx_dxg.nxnx_gpu_sync.nx

imported by: nx_gpu_mem_gate.nx

structs

none

consts

17const GM_MAX_HEAPS: i64 = 64
18const GM_ERR_BUDGET: i64 = 0 - 21 // the budget query refused
19const GM_ERR_ALLOC: i64 = 0 - 22 // an allocation refused or returned no handle
20const GM_ERR_MAP: i64 = 0 - 23 // the GPU VA map refused (259 = pending is fine)
21const GM_ERR_RES: i64 = 0 - 24 // make-resident refused (259 = pending is fine)
22const GM_ERR_EVICT: i64 = 0 - 25 // evict refused
23const GM_ERR_TOOMANY: i64 = 0 - 26 // more heaps than the table holds

functions

26func gm_table_new() -> *i64 { let t: *i64 = sys_mmap(GM_MAX_HEAPS * 8 * 4) as *i64; return t }
called by 1: main calls 1: sys_mmap
27func gm_handle(t: *i64, i: i64) -> i64 { return t[i] }
28func gm_va(t: *i64, i: i64) -> i64 { return t[GM_MAX_HEAPS + i] }
29func gm_sysmem(t: *i64, i: i64) -> *u8 { return t[GM_MAX_HEAPS * 2 + i] as *u8 }
30func gm_bytes(t: *i64, i: i64) -> i64 { return t[GM_MAX_HEAPS * 3 + i] }
33func gpu_mem_budget(fd: i64, adapter: i64, group: i64, out: *i64) -> i64
called by 1: main calls 1: dxg_query_vidmem
41func gpu_mem_heap(fd: i64, device: i64, pq: i64, t: *i64, i: i64, bytes: i64, mapf: *i64, resf: *i64) -> i64
58func gpu_mem_evict(fd: i64, device: i64, t: *i64, i: i64, outtrim: *i64) -> i64
called by 1: main calls 1: dxg_evict
65func gpu_mem_reresident(fd: i64, pq: i64, t: *i64, i: i64, resf: *i64) -> i64
called by 1: main calls 1: dxg_makeresident