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_code_alloc.h
| 1 | /* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */ |
| 2 | /* Size of a GPU code buffer. Import-free scalar Omega, no device or physics headers. |
| 3 | * |
| 4 | * The SM instruction cache prefetches past the last instruction of a kernel, so the code buffer must |
| 5 | * stay mapped for 2 KB after the code. Source (NVIDIA guidance as recorded by Mesa NVK, |
| 6 | * src/nouveau/vulkan/nvk_device.c, shader heap set-up): "the I-cache pre-fetches and NVIDIA has |
| 7 | * informed us overallocating shaders BOs by 2K is sufficient". A page-rounded buffer alone leaves |
| 8 | * whatever happens to be left in the last page (2560 B of code: 1536 B; 2688 B: 1408 B). |
| 9 | * |
| 10 | * omega#323 (2026-10-07): GB10 Xid 31, GPCCLIENT_GCC FAULT_PTE read on a page boundary while the |
| 11 | * head_dim 128 attention kernel (2688 B) ran; that this tail is the cause is INFERRED until the |
| 12 | * padded build turns the fault off on the chip. Every code upload sizes its buffer here so no site |
| 13 | * can drop the tail (tests/test_omega_gpu_code_alloc.c also scans src/ for page-rounded code sizes). |
| 14 | */ |
| 15 | #ifndef OMEGA_GPU_CODE_ALLOC_H |
| 16 | #define OMEGA_GPU_CODE_ALLOC_H |
| 17 | |
| 18 | #include <stddef.h> |
| 19 | #include <stdint.h> |
| 20 | #include "omega_bw_policy.h" |
| 21 | |
| 22 | #define OMEGA_GPU_CODE_PREFETCH_TAIL 2048u |
| 23 | #define OMEGA_GPU_CODE_PAGE 0x1000u |
| 24 | |
| 25 | /* Bytes to allocate for code_size bytes of code: code + 2 KB, rounded up to a page, at least one page. |
| 26 | * 0 when the sum would overflow (callers refuse the upload). */ |
| 27 | static inline size_t omega_gpu_code_alloc_bytes(size_t code_size) { |
| 28 | #ifdef OMEGA_GPU_CODE_ALLOC_MUTANT_NO_TAIL |
| 29 | const size_t tail = 0; /* mutant: the page-rounded size every site used before omega#323 */ |
| 30 | #else |
| 31 | const size_t tail = OMEGA_GPU_CODE_PREFETCH_TAIL; |
| 32 | #endif |
| 33 | return (size_t)omega_bw_value(4, code_size, tail, 0, 0, 0); |
| 34 | } |
| 35 | |
| 36 | #endif |