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
CUDApp / src / omega_gpu_platform_aien.h
| 1 | /* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */ |
| 2 | /* omega_gpu_platform_aien.h -- OmegaGpuPlatform (ABI 1.2) over AIEN's own GB10 driver, aien-gpu.ko (/dev/aien-gpu). |
| 3 | * |
| 4 | * The second implementation of the platform contract (src/omega_gpu_platform.h). The first, |
| 5 | * src/omega_gpu_platform_linux.c, drives NVIDIA's open kernel module through nvrm/ and m16/; this one drives the |
| 6 | * aien-gpu compute ABI 1 (third_party/aien-gpu-abi1/aien_gpu_uapi.h) and includes nothing from nvrm/, m16/ or |
| 7 | * NVIDIA's headers. Everything above the contract (session, command list, libraries) runs unchanged on either. |
| 8 | * |
| 9 | * Same caps and the same refusals as the Linux reference, except max_queues (1 here; the reference can open extra |
| 10 | * channels): TIME, WAIT, LOCK, DMA, SYNC, COMPLETION (polling), DEVICE, |
| 11 | * QUEUE, CLOCK_NS, HOST_MEM; no MMIO, no IRQ; one device (ordinal 0), one queue; GPU-cached buffers only for |
| 12 | * device-private DATA buffers, with the omega #457 L2 invalidate prefix after a host sync into one. The bus address |
| 13 | * is reported as 0 (the module owns the IOMMU mapping). |
| 14 | * |
| 15 | * device_open = open(/dev/aien-gpu) + AGPU_INFO; refused unless abi 1 and state AGPU_STATE_RM_READY |
| 16 | * dma_alloc = reserve a CPU VA range in [64 GiB, 1 TiB) (mmap PROT_NONE, MAP_FIXED_NOREPLACE; a GPFIFO entry carries |
| 17 | * 40 address bits), AGPU_MEM_ALLOC at that VA (GPU VA == CPU VA), mmap the object |
| 18 | * MAP_FIXED|MAP_SHARED over the reservation |
| 19 | * dma_free = AGPU_MEM_FREE, munmap |
| 20 | * queue_open = one GPU-uncached buffer holding the GPFIFO ring (1024 entries) and USERD right after it, one |
| 21 | * error-notifier buffer, AGPU_CHAN_CREATE, mmap of the 64 KiB usermode (doorbell) page |
| 22 | * queue_submit = methods into the BUF_QUEUE ring, dsb, GP entry, dsb, USERD GPPut, dsb, token store at +0x90 |
| 23 | * queue_retire = every submitted entry consumed (caller observed completion) |
| 24 | * poll_word = (int32_t)(word - expected) >= 0, 50 us sleep-poll |
| 25 | * |
| 26 | * Evidence: IMPLEMENTED and host-tested on a simulated device (tests/test_omega_gpu_platform_aien.c). Hardware |
| 27 | * NOT_RUN: it has never opened a real /dev/aien-gpu. |
| 28 | * |
| 29 | * Selection: a program installs it with omega_gpu_session_set_platform(omega_gpu_platform_aien(&caps), &caps) |
| 30 | * before the first session open. The hosted session still installs the Linux reference by default. |
| 31 | * CUDAPP_AIEN_GPU_DEV names another device node (default /dev/aien-gpu). |
| 32 | * |
| 33 | * Migration-pending C: the definition exists only when built with CUDAPP_MIGRATION_PENDING_AIEN_GPU=1 (OFF in |
| 34 | * libomega_gpu.a; ON for the host test and its mutants). Its decisions and request bytes (and |
| 35 | * omega_gpu_aien_gp_entry) come from native/aiengpu/context.om, aien-dev/CUDApp#128; the C rules they replaced stay |
| 36 | * behind CUDAPP_MIGRATION_PENDING_C_PLATFORM_AIEN (OFF) as the differential oracle. The effects (open, ioctl, mmap, |
| 37 | * stores, diagnostics, the function table) wait on the bridge extension aien-dev/omega-bridge#29. |
| 38 | */ |
| 39 | #ifndef OMEGA_GPU_PLATFORM_AIEN_H |
| 40 | #define OMEGA_GPU_PLATFORM_AIEN_H |
| 41 | |
| 42 | #include "omega_gpu_platform.h" |
| 43 | |
| 44 | #ifdef __cplusplus |
| 45 | extern "C" { |
| 46 | #endif |
| 47 | |
| 48 | #define OMEGA_GPU_PLATFORM_AIEN_LOCKS 4u /* lock ids 0..3, as the Linux reference */ |
| 49 | #define OMEGA_GPU_AIEN_DEFAULT_DEV "/dev/aien-gpu" |
| 50 | #define OMEGA_GPU_AIEN_GP_ENTRIES 1024u /* GPFIFO entries, as nvrm_channel */ |
| 51 | #define OMEGA_GPU_AIEN_USERD_OFF (OMEGA_GPU_AIEN_GP_ENTRIES * 8u) /* USERD follows the ring in the same buffer */ |
| 52 | #define OMEGA_GPU_AIEN_FIFO_BYTES 0x10000u /* ring + USERD, GPU-uncached */ |
| 53 | #define OMEGA_GPU_AIEN_NOTIFIER_BYTES 0x10000u /* channel error notifier */ |
| 54 | #define OMEGA_GPU_AIEN_USERD_GPPUT 0x8cu /* Nvc96fControl.GPPut (clc96f.h: 008c-008f) */ |
| 55 | #define OMEGA_GPU_AIEN_DOORBELL_BYTES 0x10000u /* the usermode page */ |
| 56 | #define OMEGA_GPU_AIEN_DOORBELL_WORD 0x90u /* NVC361_NOTIFY_CHANNEL_PENDING */ |
| 57 | |
| 58 | /* The process-wide aien-gpu platform and its caps (written to *caps when caps is not NULL). */ |
| 59 | const OmegaGpuPlatform *omega_gpu_platform_aien(OmegaGpuPlatformCaps *caps); |
| 60 | |
| 61 | /* One GPFIFO entry: pushbuffer VA (dword aligned), LEVEL MAIN, LENGTH 30:10 in dwords, SYNC PROCEED. Bit for bit the |
| 62 | * entry nvrm_gp_entry writes (tests/test_omega_gpu_platform_aien.c compares them). */ |
| 63 | uint64_t omega_gpu_aien_gp_entry(uint64_t va, uint32_t nwords); |
| 64 | |
| 65 | /* The system calls the platform makes, replaceable for host tests (a simulated device). NULL restores the real |
| 66 | * open/close/ioctl/mmap/munmap. Install only while no device is open. */ |
| 67 | typedef struct { |
| 68 | int (*open_dev)(const char *path, int flags); |
| 69 | int (*close_dev)(int fd); |
| 70 | int (*ioctl_dev)(int fd, unsigned long request, void *arg); |
| 71 | void *(*map)(void *addr, size_t len, int prot, int flags, int fd, uint64_t off); |
| 72 | int (*unmap)(void *addr, size_t len); |
| 73 | } OmegaGpuAienSys; |
| 74 | int omega_gpu_platform_aien_set_sys(const OmegaGpuAienSys *sys); /* REFUSED_BUSY while a device is open */ |
| 75 | |
| 76 | #ifdef __cplusplus |
| 77 | } |
| 78 | #endif |
| 79 | #endif |