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_blackwell_matmul_bounds.c
| 1 | /* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */ |
| 2 | /* test_omega_blackwell_matmul_bounds: the refusals at the top of omega_blackwell_execute_matmul and |
| 3 | * omega_blackwell_execute_matmul_tensor (src/omega_blackwell_submit.c), on the simulated driver |
| 4 | * (tests/fake_m16_native.c). Host program, opens no device. |
| 5 | * |
| 6 | * CudaAuditFable REPORT.md RtMem F3: both wrappers take a spec the caller may fill without omega_matmul_spec_init. |
| 7 | * m = k = n = 2^31 made (size_t)m * k * 4 wrap to 0, so a 4 KiB buffer was allocated and then written as if it held |
| 8 | * the whole matrix. Dimensions past OMEGA_BW_MATMUL_MAX_M/K/N are refused before the driver is opened. A code size |
| 9 | * whose allocation size overflows is refused before the open too; it used to return with the device left open. |
| 10 | * Every call runs in a child process: before the fix the oversize spec corrupts the heap. |
| 11 | */ |
| 12 | #include "fake_m16_native.h" |
| 13 | #include "omega_blackwell_matmul.h" |
| 14 | #include "omega_blackwell_submit.h" |
| 15 | |
| 16 | #include <stdint.h> |
| 17 | #include <stdio.h> |
| 18 | #include <string.h> |
| 19 | #include <sys/wait.h> |
| 20 | #include <unistd.h> |
| 21 | |
| 22 | static int n_pass, n_fail; |
| 23 | static void check(const char *id, int ok) { |
| 24 | printf("[%s] %s\n", ok ? "PASS" : "FAIL", id); |
| 25 | if (ok) n_pass++; else n_fail++; |
| 26 | } |
| 27 | |
| 28 | enum { I32_OVERSIZE, TENSOR_OVERSIZE, I32_CODE_OVERFLOW, TENSOR_CODE_OVERFLOW, I32_M_ONE_PAST, TENSOR_N_ONE_PAST }; |
| 29 | |
| 30 | static int refused_before_open(int which) { |
| 31 | static uint32_t in_a[16], in_b[16], out_c[16]; |
| 32 | static uint32_t code[4]; |
| 33 | OmegaBlackwellKernel kern; |
| 34 | OmegaMatMulSpec spec; |
| 35 | OmegaBlackwellMatMulExecution info; |
| 36 | memset(&kern, 0, sizeof kern); |
| 37 | memset(&spec, 0, sizeof spec); |
| 38 | kern.code = (uint8_t *)code; |
| 39 | kern.code_size = sizeof code; |
| 40 | spec.m = spec.k = spec.n = 4; |
| 41 | const int tensor = which == TENSOR_OVERSIZE || which == TENSOR_CODE_OVERFLOW || which == TENSOR_N_ONE_PAST; |
| 42 | spec.precision = tensor ? OMEGA_MATMUL_PRECISION_FP16 : OMEGA_MATMUL_PRECISION_INT32; |
| 43 | if (which == I32_OVERSIZE || which == TENSOR_OVERSIZE) spec.m = spec.k = spec.n = 1u << 31; |
| 44 | if (which == I32_CODE_OVERFLOW || which == TENSOR_CODE_OVERFLOW) kern.code_size = SIZE_MAX; |
| 45 | if (which == I32_M_ONE_PAST) spec.m = OMEGA_BW_MATMUL_MAX_M + 1u; |
| 46 | if (which == TENSOR_N_ONE_PAST) spec.n = OMEGA_BW_MATMUL_MAX_N + 1u; |
| 47 | fake_reset(); |
| 48 | fflush(stdout); |
| 49 | pid_t pid = fork(); |
| 50 | if (pid == 0) { |
| 51 | int rc = tensor ? omega_blackwell_execute_matmul_tensor(&spec, &kern, in_a, in_b, (float *)out_c, &info, NULL, NULL) |
| 52 | : omega_blackwell_execute_matmul(&spec, &kern, in_a, in_b, out_c, &info); |
| 53 | if (rc == 0 || fk.open_calls != 0 || fk.alloc_calls != 0) |
| 54 | printf(" case %d: rc %d, driver opens %d, allocs %d\n", which, rc, fk.open_calls, fk.alloc_calls); |
| 55 | fflush(stdout); |
| 56 | _exit(rc != 0 && fk.open_calls == 0 && fk.alloc_calls == 0 ? 0 : 1); |
| 57 | } |
| 58 | int st = 0; |
| 59 | if (pid < 0 || waitpid(pid, &st, 0) != pid) return 0; |
| 60 | if (WIFSIGNALED(st)) printf(" case %d: child killed by signal %d\n", which, WTERMSIG(st)); |
| 61 | return WIFEXITED(st) && WEXITSTATUS(st) == 0; |
| 62 | } |
| 63 | |
| 64 | int main(void) { |
| 65 | check("matmul_i32_2p31_dims_refused_before_open", refused_before_open(I32_OVERSIZE)); |
| 66 | check("matmul_tensor_2p31_dims_refused_before_open", refused_before_open(TENSOR_OVERSIZE)); |
| 67 | check("matmul_i32_m_one_past_max_refused_before_open", refused_before_open(I32_M_ONE_PAST)); |
| 68 | check("matmul_tensor_n_one_past_max_refused_before_open", refused_before_open(TENSOR_N_ONE_PAST)); |
| 69 | check("matmul_i32_code_size_overflow_refused_before_open", refused_before_open(I32_CODE_OVERFLOW)); |
| 70 | check("matmul_tensor_code_size_overflow_refused_before_open", refused_before_open(TENSOR_CODE_OVERFLOW)); |
| 71 | printf("SUMMARY passed=%d failed=%d\n", n_pass, n_fail); |
| 72 | return n_fail ? 1 : 0; |
| 73 | } |