Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/CUDApp/blob/main/tools/interop/cubin_probe.c # 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 Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `CUDApp / tools / interop / cubin_probe.c` 168 lines · 7616 bytes Raw Blame History 1 /* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */ 2 /* cubin_probe: load an exported sm_121 cubin through the CUDA driver and run it. 3 * 4 * This is an interop qualification tool, not part of libomega_gpu: it links 5 * libcuda only to validate that the artifact produced by Omega's own encoder is 6 * accepted by the vendor loader and computes the contract result. It refuses to 7 * run without SPARK_WINDOW. It never resets the device or changes driver state. 8 * 9 * cubin_probe [--load-only | --expect-reject] CUBIN MATMUL_FN M K N 10 * 11 * The image is loaded with cuModuleLoadDataEx and the driver's error and info 12 * logs are printed on every load, so a rejection carries whatever reason the 13 * loader gives. --load-only stops after cuModuleGetFunction. --expect-reject 14 * is a negative control: it passes only when load or symbol lookup fails. 15 * The output buffer is filled with a sentinel before launch, so a kernel that 16 * writes nothing cannot pass against a zero reference. 17 * 18 * Exit: 0 PASS (or the expected rejection), 2 usage, 3 no window, 19 * 4 CUDA/load failure, 5 numeric failure, 6 rejection expected but the 20 * image was accepted. */ 21 #include 22 #include 23 #include 24 #include 25 #include 26 27 #include "omega_blackwell_matmul.h" 28 #include "../../om/standalone-oracles/oracle.h" 29 30 #define CK(x) do { CUresult r_ = (x); if (r_) { const char *s_ = "?"; cuGetErrorString(r_, &s_); \ 31 fprintf(stderr, "FAIL %s -> %d %s\n", #x, (int)r_, s_); return 4; } } while (0) 32 33 static void reference(const uint16_t *a,const uint16_t *b,float *out, 34 uint32_t m,uint32_t k,uint32_t n) { 35 #if CUDAPP_MIGRATION_PENDING_C_STANDALONE_ORACLES 36 omega_matmul_cpu_oracle_bf16(a,b,out,m,k,n); 37 #else 38 /* The loops only marshal indexed scalar cells; Omega owns multiply/add. */ 39 for(uint32_t i=0;i %d %s\n", (int)r, s); 74 printf("LOAD error_log=\"%s\"\nLOAD info_log=\"%s\"\n", err, info); 75 return r; 76 } 77 78 int main(int argc, char **argv) { 79 int load_only = 0, expect_reject = 0, a = 1; 80 if (argc > 1 && strcmp(argv[1], "--load-only") == 0) { load_only = 1; a++; } 81 else if (argc > 1 && strcmp(argv[1], "--expect-reject") == 0) { expect_reject = 1; a++; } 82 if (argc - a != 5) { 83 fprintf(stderr, "usage: cubin_probe [--load-only | --expect-reject] CUBIN MATMUL_FN M K N\n"); 84 return 2; 85 } 86 const char *path = argv[a], *fname = argv[a + 1]; 87 if (!getenv("SPARK_WINDOW")) { 88 fprintf(stderr, "refused: SPARK_WINDOW is not set; no authorized GPU window\n"); 89 return 3; 90 } 91 const uint32_t M = (uint32_t)strtoul(argv[a + 2], NULL, 0); 92 const uint32_t K = (uint32_t)strtoul(argv[a + 3], NULL, 0); 93 const uint32_t N = (uint32_t)strtoul(argv[a + 4], NULL, 0); 94 if (!so_all(M,K,N)) return 2; 95 size_t cub_n = 0; 96 uint8_t *cub = slurp(path, &cub_n); 97 if (!cub) { fprintf(stderr, "cannot read %s\n", path); return 2; } 98 99 CK(cuInit(0)); 100 CUdevice dev; 101 CK(cuDeviceGet(&dev, 0)); 102 CUcontext ctx; 103 CUctxCreateParams cparams; 104 memset(&cparams, 0, sizeof cparams); 105 CK(cuCtxCreate(&ctx, &cparams, 0, dev)); 106 CUmodule mod; 107 CUresult lr = load_logged(&mod, cub); 108 CUfunction fn; 109 CUresult fr = CUDA_ERROR_NOT_FOUND; 110 if (lr == CUDA_SUCCESS) { 111 fr = cuModuleGetFunction(&fn, mod, fname); 112 const char *s = "?"; 113 cuGetErrorString(fr, &s); 114 printf("LOAD cuModuleGetFunction(%s) -> %d %s\n", fname, (int)fr, s); 115 } 116 if (expect_reject) { 117 if (lr == CUDA_SUCCESS) cuModuleUnload(mod); 118 cuCtxDestroy(ctx); 119 free(cub); 120 if (!so_all(so_eq(lr,CUDA_SUCCESS),so_eq(fr,CUDA_SUCCESS),1)) { 121 printf("REJECT-PASS cubin=%s fn=%s window=%s\n", path, fname, getenv("SPARK_WINDOW")); 122 return 0; 123 } 124 printf("REJECT-FAIL accepted cubin=%s fn=%s window=%s\n", path, fname, getenv("SPARK_WINDOW")); 125 return 6; 126 } 127 if (!so_all(so_eq(lr,CUDA_SUCCESS),so_eq(fr,CUDA_SUCCESS),1)) return 4; 128 if (load_only) { 129 printf("LOAD-PASS cubin=%s fn=%s window=%s\n", path, fname, getenv("SPARK_WINDOW")); 130 cuModuleUnload(mod); cuCtxDestroy(ctx); free(cub); 131 return 0; 132 } 133 134 const size_t asz = so_bytes(M,so_bytes(K,2,0),0), bsz = so_bytes(K,so_bytes(N,2,0),0), csz = so_bytes(M,so_bytes(N,4,0),0); 135 uint16_t *A = malloc(asz), *B = malloc(bsz); 136 float *C = malloc(csz), *ref = malloc(csz); 137 if (!A || !B || !C || !ref) return 4; 138 /* These fixture values are exactly BF16-representable; op42 is a bit narrowing, not a general quantizer. */ 139 for (uint32_t i = 0; i < (uint32_t)so_bytes(M,K,0); i++) A[i] = (uint16_t)so_call(42,so_call(18,i,0,0,0),0,0,0); 140 for (uint32_t i = 0; i < (uint32_t)so_bytes(K,N,0); i++) B[i] = (uint16_t)so_call(42,so_call(19,i,0,0,0),0,0,0); 141 reference(A, B, ref, M, K, N); 142 143 CUdeviceptr dA, dB, dC; 144 CK(cuMemAlloc(&dA, asz)); CK(cuMemAlloc(&dB, bsz)); CK(cuMemAlloc(&dC, csz)); 145 CK(cuMemcpyHtoD(dA, A, asz)); CK(cuMemcpyHtoD(dB, B, bsz)); 146 float sentinel = SENTINEL; 147 uint32_t sbits; 148 memcpy(&sbits, &sentinel, sizeof sbits); 149 CK(cuMemsetD32(dC, sbits, so_bytes(M,N,0))); 150 void *args[] = { &dA, &dB, &dC }; 151 CK(cuLaunchKernel(fn, 1, 1, 1, 32, 1, 1, 0, NULL, args, NULL)); 152 CK(cuCtxSynchronize()); 153 CK(cuMemcpyDtoH(C, dC, csz)); 154 int bad = 0, untouched = 0; 155 double worst = 0; 156 for (uint32_t i = 0; i < (uint32_t)so_bytes(M,N,0); i++) { 157 untouched=(int)so_call(5,untouched,so_eq(so_bits(C[i]),so_bits(sentinel)),0,0); 158 uint64_t error=so_call(20,so_bits(C[i]),so_bits(ref[i]),0,0), old; 159 memcpy(&old,&worst,sizeof old); 160 worst=so_double(so_call(38,error,old,0,0)); 161 bad=(int)so_call(5,bad,so_call(21,error,0,0,0),0,0); 162 } 163 printf("cubin=%s fn=%s M=%u K=%u N=%u worst_abs=%.9g bad=%d untouched=%d window=%s\n", 164 path, fname, M, K, N, worst, bad, untouched, getenv("SPARK_WINDOW")); 165 cuMemFree(dA); cuMemFree(dB); cuMemFree(dC); 166 cuModuleUnload(mod); cuCtxDestroy(ctx); free(A); free(B); free(C); free(ref); free(cub); 167 return bad ? 5 : 0; 168 }