physics-mv
FORGE: request-bound machine realization, providers and verification for AienOS. Host, simulated and GB10 hardware paths have separate evidence.
Brought by drakestapleton
physics-mv / m16 / m16_native.h
| 1 | /* |
| 2 | * m16_native.h -- M16 libcuda-free native accelerator interface. |
| 3 | * |
| 4 | * Wraps the generic NVIDIA RM/UVM substrate (nvrm/) for independent |
| 5 | * milestone qualification and testability. |
| 6 | */ |
| 7 | #ifndef M16_NATIVE_H |
| 8 | #define M16_NATIVE_H |
| 9 | |
| 10 | #include "nvrm.h" |
| 11 | #include <stddef.h> |
| 12 | #include <stdint.h> |
| 13 | |
| 14 | typedef struct { |
| 15 | Nvrm rm; |
| 16 | NvrmMem pb_mem; |
| 17 | NvrmMem marker_mem; |
| 18 | NvrmMem legacy_allocs[64]; |
| 19 | } M16NativeContext; |
| 20 | |
| 21 | /* Open RM client, device, VA space, and query card state */ |
| 22 | int m16_native_open(M16NativeContext *ctx); |
| 23 | |
| 24 | /* Allocate coherent unified memory mapped identically in CPU and GPU VA */ |
| 25 | int m16_native_alloc_memory(M16NativeContext *ctx, size_t size, void **cpu_addr, uint64_t *gpu_va); |
| 26 | int m16_native_free_memory(M16NativeContext *ctx, void *cpu_addr); |
| 27 | |
| 28 | /* Uncached sibling of m16_native_alloc_memory: the chip stores straight to memory |
| 29 | * instead of holding the write in its L2. nvos.h, NVOS32_ATTR2_GPU_CACHEABLE_YES: |
| 30 | * "For system memory this will not be coherent with direct CPU mappings." Use this |
| 31 | * for any word the CPU polls. */ |
| 32 | int m16_native_alloc_memory_uncached(M16NativeContext *ctx, size_t size, void **cpu_addr, uint64_t *gpu_va); |
| 33 | |
| 34 | /* Offset and payload of the second marker the hardened release stream writes after |
| 35 | * its L2 flush (the block m16/m16_concurrent.c proved on the chip). */ |
| 36 | #define M16_MARKER2_OFF 0x10u |
| 37 | #define M16_MARKER2_PAYLOAD 0x46464646u |
| 38 | |
| 39 | /* Release stream, then L2_FLUSH_DIRTY, then a second release at marker_va + M16_MARKER2_OFF. */ |
| 40 | int m16_native_build_release_flushed(uint32_t *words, uint64_t marker_va, uint32_t payload, uint32_t compute_class); |
| 41 | |
| 42 | /* Create channel group, context share, GPFIFO ring, and schedule channel */ |
| 43 | int m16_native_create_channel(M16NativeContext *ctx); |
| 44 | |
| 45 | /* Build the standard M16 semaphore-release method stream */ |
| 46 | int m16_native_build_release(uint32_t *words, uint64_t marker_va, uint32_t payload, uint32_t compute_class); |
| 47 | |
| 48 | /* Enqueue method stream to GPFIFO ring (without ringing doorbell) */ |
| 49 | int m16_native_enqueue_methods(M16NativeContext *ctx, const uint32_t *methods, size_t count); |
| 50 | |
| 51 | /* Ring usermode doorbell with work-submit token */ |
| 52 | void m16_native_ring_doorbell(M16NativeContext *ctx); |
| 53 | |
| 54 | /* Enqueue and ring doorbell */ |
| 55 | int m16_native_submit_methods(M16NativeContext *ctx, const uint32_t *methods, size_t count); |
| 56 | |
| 57 | /* Poll coherent marker until it equals expected value or timeout_ms expires */ |
| 58 | int m16_native_wait_marker(volatile uint32_t *marker, uint32_t expected, uint64_t timeout_ms); |
| 59 | |
| 60 | /* Poll coherent marker until (int32_t)(*marker - target) >= 0 (monotonic, |
| 61 | * serial-number compare per RFC 1982: correct across uint32_t wraparound) |
| 62 | * or timeout_ms expires. Returns 0 once satisfied, -1 on timeout. */ |
| 63 | int m16_native_wait_marker_ge(volatile uint32_t *marker, uint32_t target, uint64_t timeout_ms); |
| 64 | |
| 65 | /* Free all RM objects, mappings, and close file descriptors */ |
| 66 | int m16_native_close(M16NativeContext *ctx); |
| 67 | |
| 68 | #endif /* M16_NATIVE_H */ |