interplane.Get Omega
Read in your language

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

branch main Branches Tags History

CUDApp / tests / test_omega_blackwell_arch_guard.c

69 lines · 2536 bytes Raw Blame History
1/* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */
2/* Production backend on a non-AArch64 host: refuse before any driver call.
3 * Compiled without OMEGA_BLACKWELL_HOST_SIMULATOR. The fake driver is linked
4 * so a call that reached m16_native_open would be counted, not sent to a device.
5 */
6#include "fake_m16_native.h"
7#include "omega_blackwell_engine.h"
8#include "omega_blackwell_submit.h"
9
10#include <errno.h>
11#include <stdio.h>
12#include <string.h>
13
14#if !defined(__aarch64__)
15static int refuse_ok(const char *what, int rc)
16{
17 if (rc == 0 || errno != ENOTSUP) {
18 fprintf(stderr, "%s: expected ENOTSUP, rc=%d errno=%d\n", what, rc, errno);
19 return 1;
20 }
21 return 0;
22}
23#endif
24
25int main(void)
26{
27#if defined(__aarch64__)
28 puts("x86-64 production refusal: NOT_RUN (this binary is AArch64; production barriers stay dsb sy; device open is not attempted)");
29 return 0;
30#else
31 const OmegaGpuBackend *b = omega_blackwell_engine_backend();
32 OmegaGpuBackendDiag d;
33 int failed = 0;
34
35 fake_reset();
36 errno = 0;
37 int rc = b->open_device(b->ctx);
38 memset(&d, 0, sizeof d);
39 b->diagnostics(b->ctx, &d);
40 if (rc == 0 || errno != ENOTSUP || d.drv_rc == 0 ||
41 strstr(d.drv_text, "requires AArch64 Linux") == NULL) {
42 fprintf(stderr, "architecture guard failed: rc=%d errno=%d drv_rc=%d text=%s\n",
43 rc, errno, d.drv_rc, d.drv_text);
44 failed = 1;
45 }
46 if (fk.open_calls != 0 || fk.alloc_calls != 0 || fk.submit_calls != 0) {
47 fprintf(stderr, "architecture guard entered the driver: open=%d alloc=%d submit=%d\n",
48 fk.open_calls, fk.alloc_calls, fk.submit_calls);
49 failed = 1;
50 }
51 if (!failed) puts("Blackwell backend refusal: ENOTSUP, requires AArch64 Linux, driver not entered");
52
53 errno = 0;
54 failed |= refuse_ok("direct vector path",
55 omega_blackwell_execute_vector(NULL, NULL, NULL, NULL, NULL, NULL));
56 errno = 0;
57 failed |= refuse_ok("direct matmul path",
58 omega_blackwell_execute_matmul(NULL, NULL, NULL, NULL, NULL, NULL));
59 errno = 0;
60 failed |= refuse_ok("direct tensor matmul path",
61 omega_blackwell_execute_matmul_tensor(NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL));
62 if (fk.open_calls != 0) {
63 fprintf(stderr, "direct paths entered the driver: open=%d\n", fk.open_calls);
64 failed = 1;
65 }
66 if (!failed) puts("direct Blackwell entry points: ENOTSUP");
67 return failed ? 1 : 0;
68#endif
69}