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 / om / prefill-shape / scoped-check.c
| 1 | /* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */ |
| 2 | /* Real call-path isolation test. The device-open and kernel-cache boundaries are |
| 3 | * intercepted; neither a GPU nor fake matrix arithmetic is used. */ |
| 4 | #include "omega_gpu_prefill.h" |
| 5 | #include "omega_blackwell_codegen_qg.h" |
| 6 | #include <stdio.h> |
| 7 | #include <string.h> |
| 8 | #include "../standalone-oracles/oracle.h" |
| 9 | static unsigned opened, keyed, failed; |
| 10 | static OmegaQgSpec want; |
| 11 | int __wrap_omega_gpu_pf_open_locked(void) { opened=(unsigned)so_call(5,opened,1,0,0); return OMEGA_GPU_PF_OK; } |
| 12 | int __wrap_omega_gpu_pf_kernel_locked(const OmegaPfKey *key, OmegaPfGen gen, OmegaPfKernel *out) { |
| 13 | OmegaQgSpec got; (void)gen; (void)out; |
| 14 | memcpy(&got,key->words,sizeof got); keyed=(unsigned)so_call(5,keyed,1,0,0); |
| 15 | if (!so_eq((uint64_t)(int64_t)memcmp(&got,&want,sizeof got),0)) { fprintf(stderr,"wrong per-call kernel key\n"); failed=so_bad(failed,0); } |
| 16 | return OMEGA_GPU_PF_TOO_LARGE; /* stop before allocation/launch */ |
| 17 | } |
| 18 | static void expect(unsigned rt,unsigned warps,unsigned group,unsigned mutant) { |
| 19 | memset(&want,0,sizeof want);want.rt=rt;want.warps=warps;want.group=group;want.mutant=mutant; |
| 20 | want.k=128;want.n=256;want.wait=45;want.direct=1; |
| 21 | opened=keyed=0; |
| 22 | } |
| 23 | static void check(int ok,const char *why) { failed=so_bad(failed,ok); if(!ok) fprintf(stderr,"%s\n",why); } |
| 24 | static int scoped(unsigned rt,unsigned group) { |
| 25 | return omega_gpu_pf_qgemm_scoped(rt,8,45,group,256,128,OMEGA_GPU_PF_PLAIN,16,1,0,32,48,64,NULL); |
| 26 | } |
| 27 | int main(void) { |
| 28 | omega_gpu_pf_qgemm_set_shape(2,4,45);omega_gpu_pf_qgemm_set_group(1);omega_gpu_pf_qgemm_test_set_mutant(1); |
| 29 | check(so_eq(omega_gpu_pf_qgemm_scoped_bm(8,8,45,4),128),"checked128 tile height"); |
| 30 | check(so_eq(omega_gpu_pf_qgemm_scoped_bm(4,8,45,0),64),"checked64 tile height"); |
| 31 | check(so_eq(omega_gpu_pf_qgemm_scoped_bm(0,8,45,4),0),"zero shape refused"); |
| 32 | check(so_eq(omega_gpu_pf_qgemm_scoped_bm(8,8,121,4),0),"unsafe wait refused"); |
| 33 | check(so_eq(omega_gpu_pf_qgemm_scoped_bm(8,8,45,6),0),"group outside bound refused"); |
| 34 | for(unsigned i=0;i<3;i++) { |
| 35 | unsigned rt=(unsigned)so_call(41,so_eq(i,1),8,4,0),group=(unsigned)so_call(41,so_eq(i,1),4,0,0); |
| 36 | expect(rt,8,group,0); |
| 37 | int src=scoped(rt,group); |
| 38 | check(so_all(so_eq((uint64_t)(int64_t)src,(uint64_t)(int64_t)OMEGA_GPU_PF_TOO_LARGE),so_eq(opened,1),so_eq(keyed,1)),"scoped call reached its own kernel key"); |
| 39 | expect(2,4,1,1); |
| 40 | int rc=omega_gpu_pf_qgemm(256,128,OMEGA_GPU_PF_PLAIN,16,1,0,32,48,64,NULL); |
| 41 | check(so_all(so_eq((uint64_t)(int64_t)rc,(uint64_t)(int64_t)OMEGA_GPU_PF_TOO_LARGE),so_eq(opened,1),so_eq(keyed,1)),"legacy settings unchanged after scoped call"); |
| 42 | check(so_eq(omega_gpu_pf_qgemm_bm(),32),"legacy tile height unchanged"); |
| 43 | } |
| 44 | const uint32_t rows[] = {1,30,64,65,128,4096,UINT32_MAX}; |
| 45 | for(unsigned i=0;i<sizeof(rows)/sizeof(rows[0]);i++) { |
| 46 | uint32_t p[4];for(unsigned j=0;j<4;j++)p[j]=omega_gpu_pf_qgemm_reading_option(rows[i],j); |
| 47 | expect((unsigned)so_call(15,rows[i],0,0,0),8,(unsigned)so_call(16,rows[i],0,0,0),0); |
| 48 | int rc=omega_gpu_pf_qgemm_scoped(p[0],p[1],p[2],p[3],256,128,OMEGA_GPU_PF_PLAIN,16,1,0,32,48,64,NULL); |
| 49 | check(so_all(so_eq((uint64_t)(int64_t)rc,(uint64_t)(int64_t)OMEGA_GPU_PF_TOO_LARGE),so_eq(opened,1),so_eq(keyed,1)),"adaptive profile reaches matching cache key"); |
| 50 | check(so_eq(omega_gpu_pf_qgemm_bm(),32),"adaptive query leaves legacy height unchanged"); |
| 51 | } |
| 52 | check(so_eq(omega_gpu_pf_qgemm_reading_option(0,0),UINT32_MAX),"zero reading rows refused"); |
| 53 | check(so_eq(omega_gpu_pf_qgemm_reading_option(64,4),UINT32_MAX),"unknown reading option refused"); |
| 54 | expect(8,8,6,0); |
| 55 | int brc=scoped(8,6); |
| 56 | check(so_all(so_eq((uint64_t)(int64_t)brc,(uint64_t)(int64_t)OMEGA_GPU_PF_BAD_ARGS),so_eq(opened,0),so_eq(keyed,0)),"invalid options refused before device access"); |
| 57 | omega_gpu_pf_qgemm_set_shape(0,0,0);omega_gpu_pf_qgemm_set_group(0);omega_gpu_pf_qgemm_test_set_mutant(0); |
| 58 | printf("scoped qgemm isolation: %s\n",failed?"FAIL":"PASS");return failed?1:0; |
| 59 | } |