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 / tests / test_omega_gpu_code_alloc.c
| 1 | /* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */ |
| 2 | /* GPU code buffer sizing (src/omega_gpu_code_alloc.h): code + 2 KB instruction prefetch tail, page rounded. |
| 3 | * Host only. The NO_TAIL mutant (the page-rounded size used before omega#323) must fail. */ |
| 4 | #include "omega_gpu_code_alloc.h" |
| 5 | #include <stdint.h> |
| 6 | #include <stdio.h> |
| 7 | |
| 8 | static int fails; |
| 9 | #define CHECK(c, ...) do { if (!(c)) { fails++; printf("FAIL: "); printf(__VA_ARGS__); printf("\n"); } } while (0) |
| 10 | |
| 11 | int main(void) { |
| 12 | /* the two attention kernels of omega#323: 2560 B (head_dim 64) and 2688 B (head_dim 128) */ |
| 13 | CHECK(omega_gpu_code_alloc_bytes(2560) == 8192, "2560 B of code -> 8192 (got %zu)", omega_gpu_code_alloc_bytes(2560)); |
| 14 | CHECK(omega_gpu_code_alloc_bytes(2688) == 8192, "2688 B of code -> 8192 (got %zu)", omega_gpu_code_alloc_bytes(2688)); |
| 15 | CHECK(omega_gpu_code_alloc_bytes(2048) == 4096, "2048 B of code fits one page with the tail (got %zu)", omega_gpu_code_alloc_bytes(2048)); |
| 16 | CHECK(omega_gpu_code_alloc_bytes(2049) == 8192, "2049 B of code needs a second page (got %zu)", omega_gpu_code_alloc_bytes(2049)); |
| 17 | CHECK(omega_gpu_code_alloc_bytes(0) == 4096, "empty code -> one page (got %zu)", omega_gpu_code_alloc_bytes(0)); |
| 18 | CHECK(omega_gpu_code_alloc_bytes(0x4000) == 0x5000, "16 KB capacity -> 20 KB (got %zu)", omega_gpu_code_alloc_bytes(0x4000)); |
| 19 | CHECK(omega_gpu_code_alloc_bytes(SIZE_MAX) == 0, "overflow refused"); |
| 20 | CHECK(omega_gpu_code_alloc_bytes(SIZE_MAX - 2048) == 0, "overflow near the limit refused"); |
| 21 | /* every size: at least 2 KB mapped after the code, page multiple, no more than one extra page */ |
| 22 | for (size_t n = 1; n <= 64 * 1024; n += 16) { |
| 23 | size_t b = omega_gpu_code_alloc_bytes(n); |
| 24 | if (b < n + OMEGA_GPU_CODE_PREFETCH_TAIL || b % OMEGA_GPU_CODE_PAGE != 0 || b > n + OMEGA_GPU_CODE_PREFETCH_TAIL + OMEGA_GPU_CODE_PAGE) { |
| 25 | CHECK(0, "%zu B of code -> %zu B (needs >= code + 2048, page multiple)", n, b); |
| 26 | break; |
| 27 | } |
| 28 | } |
| 29 | if (fails) { printf("OMEGA_GPU_CODE_ALLOC FAIL (%d)\n", fails); return 1; } |
| 30 | printf("OMEGA_GPU_CODE_ALLOC PASS\n"); |
| 31 | return 0; |
| 32 | } |