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 / native_runtime_controls.h
| 1 | /* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */ |
| 2 | /* Included by the existing session-platform fixture only. These are synthetic |
| 3 | * typed host handles, never GPU execution or qualification evidence. Artifact |
| 4 | * admission is real; independent C wire/hash construction is a test oracle. */ |
| 5 | #include "omega_gpu_q36_native.h" |
| 6 | #include "omega_gpu_fp8_api.h" |
| 7 | #include "omega_gpu_fp8gemm_api.h" |
| 8 | #include "omega_gpu_cmdlist.h" |
| 9 | #include "omega_gpu_cmdlist_native.h" |
| 10 | #include "sha256.h" |
| 11 | #include "omega_blackwell_qmd.h" |
| 12 | |
| 13 | #ifdef CUDAPP_NATIVE_RUNTIME_TEST |
| 14 | int omega_gpu_q36_test_submit_incumbent(OmegaGpuCmdList *); |
| 15 | int omega_gpu_q36_test_record_fp8(OmegaGpuCmdList *, OmegaGpuQ36NativeState *, |
| 16 | const OmegaGpuFp8Tensor *, uint64_t, uint64_t, uint64_t); |
| 17 | #endif |
| 18 | |
| 19 | static OmegaNativeArtifactSnapshot nr_snapshot; |
| 20 | static void nr_u32(uint8_t *p, uint32_t v) { |
| 21 | for (unsigned i=0;i<4;++i) p[i]=(uint8_t)(v>>(8*i)); |
| 22 | } |
| 23 | static void nr_admit(OmegaGpuNativeArtifact *a, uint64_t launch[32]) { |
| 24 | char dir[]="/tmp/cudapp-native-runtime-XXXXXX", prefix[256], path[300], id[65], actual[65], err[256]; |
| 25 | uint8_t abi[136]={0}, qpair[768]; |
| 26 | uint32_t q0[96],q1[96],cb[10]={0,0,0,0,0,0,128,0,512,128}; |
| 27 | OmegaCubinParam params[7]; |
| 28 | OmegaBlackwellQmdConfig cfg={.threads_per_block=256,.grid_width=16, |
| 29 | .threads_x=256,.threads_y=1,.grid_x=16,.grid_y=1,.gpr_count=64,.shared_bytes=1024}; |
| 30 | omega_native_artifact_snapshot_free(&nr_snapshot); |
| 31 | EXPECT(mkdtemp(dir)!=NULL); |
| 32 | snprintf(prefix,sizeof prefix,"%s/artifact",dir); |
| 33 | EXPECT(omega_blackwell_build_qmd0(q0,0,0)==0); |
| 34 | EXPECT(omega_blackwell_build_qmd1(q1,&cfg)==0); |
| 35 | nr_u32(abi,14084u|(4u<<16)); nr_u32(abi+4,130); |
| 36 | for(unsigned i=0;i<7;++i) { |
| 37 | uint32_t off=i<3?8*i:24+4*(i-3); |
| 38 | params[i]=(OmegaCubinParam){896+off,i<3?8:4,i<3}; |
| 39 | nr_u32(abi+8+16*i,5892u|(12u<<16)); |
| 40 | nr_u32(abi+16+16*i,i|(off<<16)); |
| 41 | nr_u32(abi+20+16*i,i<3?2225408:1175552); |
| 42 | } |
| 43 | nr_u32(abi+120,6403u|(40u<<16)); nr_u32(abi+124,2564u|(8u<<16)); |
| 44 | nr_u32(abi+128,3); nr_u32(abi+132,896u|(40u<<16)); |
| 45 | sha256_hash(abi,sizeof abi,(uint8_t *)(launch+15)); |
| 46 | sha256_hash((uint8_t *)cb,sizeof cb,(uint8_t *)(launch+19)); |
| 47 | memcpy(qpair,q0,384); memcpy(qpair+384,q1,384); |
| 48 | sha256_hash(qpair,sizeof qpair,(uint8_t *)(launch+23)); |
| 49 | char hash[65]; memset(hash,'a',64); hash[64]=0; |
| 50 | OmegaNativeArtifact artifact={.op="matmul",.shape="m=1,k=256,n=128", |
| 51 | .bounds="m<=1,k<=256,n<=128",.contract_name="synthetic-host-runtime", |
| 52 | .contract_id_hex=hash,.semantic_spec_id_hex=hash,.kernel_function="native_fixture", |
| 53 | .precision="fp8",.accumulation="fp32",.tolerance="0", |
| 54 | .text=a->code,.text_len=(size_t)a->sizes[1],.params=params,.nparams=7, |
| 55 | .gpr_count=64,.grid_x=16,.grid_y=1,.block_x=256,.block_y=1,.block_z=1, |
| 56 | .shared_bytes=1024,.cbank_offset=896,.cbank_args=cb,.cbank_words=10, |
| 57 | .qmd0=q0,.qmd1=q1,.min_driver="580.173.02",.requires="sm_121", |
| 58 | .source_commit="UNKNOWN",.tool_version="host-runtime-oracle/1", |
| 59 | .qualification="device-load=NOT_RUN"}; |
| 60 | EXPECT(omega_native_artifact_export(&artifact,prefix,id,err,sizeof err)==0); |
| 61 | for(unsigned i=0;i<32;++i) { |
| 62 | unsigned value=0; |
| 63 | EXPECT(sscanf(id+2*i,"%2x",&value)==1); a->manifest[i]=(uint8_t)value; |
| 64 | } |
| 65 | EXPECT(omega_native_artifact_snapshot(prefix,"580.173.02",actual,&nr_snapshot,err,sizeof err)==0); |
| 66 | a->admission=&nr_snapshot; |
| 67 | static const char *const suffix[]={".text.bin",".cubin",".qmd0.bin",".qmd1.bin", |
| 68 | ".cbank_args.bin",".json",".manifest",".sha256"}; |
| 69 | for(unsigned i=0;i<sizeof suffix/sizeof suffix[0];++i) { |
| 70 | snprintf(path,sizeof path,"%s%s",prefix,suffix[i]); EXPECT(unlink(path)==0); |
| 71 | } |
| 72 | EXPECT(rmdir(dir)==0); |
| 73 | } |
| 74 | static void nr_word(uint8_t *p, unsigned i, uint64_t v) { |
| 75 | for (unsigned j = 0; j < 8; ++j) p[i * 8 + j] = (uint8_t)(v >> (j * 8)); |
| 76 | } |
| 77 | static void nr_digest(uint8_t out[32], const void *p, size_t n) { sha256_hash(p, n, out); } |
| 78 | static void nr_fixture(OmegaGpuNativeArtifact *a, uint8_t weights[65536], uint8_t raw_scales[1024]) { |
| 79 | uint64_t d[48] = {0}, status = 0; |
| 80 | uint8_t wire[384] = {0}, src[65536] = {0}, scales[1024] = {0}; |
| 81 | uint64_t cfg[16] = {1,256,8,1,8}, ins[8192] = {0}, metadata[2048] = {0}, phys[288] = {0}, stats[8] = {0}; |
| 82 | d[0]=1; d[1]=2; d[2]=8; d[4]=1; d[5]=128; d[6]=128; |
| 83 | d[11]=1; d[13]=1; d[14]=8; d[15]=1; d[17]=128; d[18]=256; d[19]=2; |
| 84 | d[24]=3; d[25]=256; d[26]=4; d[27]=1; d[30]=32768; d[31]=4; |
| 85 | d[33]=256; d[34]=8; d[35]=4; d[36]=32768; d[37]=8; d[40]=1; d[41]=256; |
| 86 | memset(a, 0, sizeof *a); |
| 87 | EXPECT(omega_native_quant(&status,0,d,48,wire,384)==OMEGA_OK && status==0); |
| 88 | EXPECT(omega_native_repack(&status,d,48,src,65536,raw_scales,1024,weights,65536,scales,1024)==OMEGA_OK && status==0); |
| 89 | EXPECT(memcmp(weights,src,32768)==0); |
| 90 | EXPECT(omega_native_compose(&status,cfg,16,ins,8192,metadata,2048,phys,288,stats,8)==OMEGA_OK && status==0); |
| 91 | EXPECT(stats[0]>0 && stats[1]<=64 && stats[2]<=32 && stats[3]<=1024); |
| 92 | EXPECT(omega_bc_encode(&status,ins,8192,phys,288,stats[0],1,a->code,16384)==OMEGA_OK && status>0 && status<=16384); |
| 93 | a->sizes[0]=1152; a->sizes[1]=status; a->sizes[2]=256; |
| 94 | uint64_t words[38] = {1,1152,121,0,1,128,256,1,3,1,1,1,0,0,1,1,256,8,1,1,7,1024,64,6,1,256,16,1,1,7,1,2,0,4,5,6,7,8}; |
| 95 | for (unsigned i=0;i<38;++i) nr_word(a->canonical,i,words[i]); |
| 96 | memcpy(a->canonical+768,wire,384); |
| 97 | /* Digest each actual test input/output rather than a digest sentinel. The |
| 98 | * first four identities are synthetic fixture provenance, not receipts. */ |
| 99 | nr_digest(a->canonical+512,cfg,sizeof cfg); |
| 100 | nr_digest(a->canonical+544,ins,sizeof ins); |
| 101 | nr_digest(a->canonical+576,phys,sizeof phys); |
| 102 | nr_digest(a->canonical+608,d,sizeof d); |
| 103 | nr_digest(a->canonical+640,metadata,sizeof metadata); |
| 104 | nr_digest(a->canonical+672,a->code,(size_t)a->sizes[1]); |
| 105 | nr_digest(a->canonical+736,stats,sizeof stats); |
| 106 | uint64_t launch[32] = {1,16,1,1,256,1,1,1024,64,6,1,896,10,1,1}; |
| 107 | /* Expected template identities are computed independently before admission. |
| 108 | * The retained actual snapshot must match; manifest text is not qualification. */ |
| 109 | nr_admit(a,launch); |
| 110 | for(unsigned i=0;i<32;++i) nr_word(a->launch,i,launch[i]); |
| 111 | nr_digest(a->canonical+704,a->launch,256); |
| 112 | nr_digest(a->realization,a->canonical,1152); |
| 113 | uint8_t got[32]; |
| 114 | EXPECT(omega_native_payload(a,got)==0 && memcmp(got,a->realization,32)==0); |
| 115 | EXPECT(omega_native_admitted(a,got)==0); |
| 116 | } |
| 117 | /* Regression for the real generated production adapter, not a copied composer. |
| 118 | * The legal staged shape exceeds instruction capacity. Refusal must be a |
| 119 | * semantic result with no published actual statistics, never bridge trap 3. */ |
| 120 | static void c_native_compose_capacity(void) { |
| 121 | uint64_t cfg[16]={3,1536,16,8,16}; |
| 122 | uint64_t ins[8192]={0}, metadata[2048]={0}, phys[288]={0}, actual[8]; |
| 123 | uint64_t status; |
| 124 | for(unsigned pass=0;pass<2;++pass) { |
| 125 | memset(actual,0xff,sizeof actual); |
| 126 | status=UINT64_MAX; |
| 127 | EXPECT(omega_native_compose(&status,cfg,16,ins,8192,metadata,2048, |
| 128 | phys,288,actual,8)==OMEGA_OK); |
| 129 | EXPECT(status==2); |
| 130 | for(unsigned i=0;i<8;++i) EXPECT(actual[i]==0); |
| 131 | } |
| 132 | /* The capacity refusal must not poison the next valid native call. */ |
| 133 | memset(cfg,0,sizeof cfg); |
| 134 | cfg[0]=1; cfg[1]=256; cfg[2]=8; cfg[3]=1; cfg[4]=8; |
| 135 | status=UINT64_MAX; |
| 136 | EXPECT(omega_native_compose(&status,cfg,16,ins,8192,metadata,2048, |
| 137 | phys,288,actual,8)==OMEGA_OK && status==0); |
| 138 | EXPECT(actual[0]>0 && actual[0]<=1024); |
| 139 | } |
| 140 | static void nr_state(OmegaGpuQ36NativeState *s, const OmegaGpuNativeArtifact *a) { |
| 141 | memset(s,0,sizeof *s); s->artifact[0]=*a; |
| 142 | memcpy(s->wanted,a->canonical,4096); memcpy(s->records,a->canonical,4096); |
| 143 | uint64_t *q=s->query,*r=s->rows; |
| 144 | q[0]=1; q[1]=1; q[3]=omega_gpu_session_epoch(); q[4]=121; q[5]=1; q[6]=1; |
| 145 | q[7]=1024; q[8]=256; q[9]=32768; q[10]=1024; q[13]=100; |
| 146 | for(unsigned i=0;i<6;++i) nr_digest((uint8_t *)(q+14+i*4),&i,sizeof i); |
| 147 | memcpy(q+30,a->realization,32); |
| 148 | r[0]=1; r[1]=31; r[2]=63; r[3]=10; r[9]=10; |
| 149 | r[12]=64; r[13]=1024; r[14]=256; r[16]=omega_gpu_code_alloc_bytes((size_t)a->sizes[1]); |
| 150 | memcpy(r+17,q+3,4*sizeof(uint64_t)); |
| 151 | memcpy(r+21,a->realization,32); memcpy(r+25,a->canonical+704,32); |
| 152 | nr_digest((uint8_t *)(r+29),"SYNTHETIC-NOT-QUALIFIED",sizeof("SYNTHETIC-NOT-QUALIFIED")-1); |
| 153 | memcpy(r+33,q+14,24*sizeof(uint64_t)); memcpy(r+57,a->canonical+672,32); |
| 154 | } |
| 155 | static uint64_t nr_code_va(const OmegaGpuNativeArtifact *a) { |
| 156 | for(uint32_t i=0;i<NB;++i) |
| 157 | if(fk.mem[i] && fk.t.live[i] && fk.desc[i].kind==OMEGA_GPU_HANDLE_BUF_CODE && |
| 158 | fk.desc[i].bytes>=a->sizes[1] && memcmp(fk.mem[i],a->code,(size_t)a->sizes[1])==0) |
| 159 | return 0x100000000ull+(uint64_t)i*0x1000000ull; |
| 160 | return 0; |
| 161 | } |
| 162 | static unsigned nr_qmd_binds(uint64_t va) { |
| 163 | unsigned n=0; |
| 164 | for(uint32_t i=0;i<NB;++i) if(fk.mem[i] && fk.t.live[i] && fk.desc[i].kind==OMEGA_GPU_HANDLE_BUF_DATA) { |
| 165 | const uint32_t *p=fk.mem[i]; |
| 166 | for(size_t j=0;j+64<=fk.desc[i].bytes/4;j+=64) |
| 167 | if(omega_blackwell_verify_qmd_invariants(p+j)==0 && p[j+32]==(uint32_t)(va>>4) && (p[j+33]&0x1fffffu)==(uint32_t)(va>>36)) ++n; |
| 168 | } |
| 169 | return n; |
| 170 | } |
| 171 | /* Independent legacy C bank/QMD/SHA oracle. Its labels and typed handles are |
| 172 | * synthetic; no GROUP semantics, executed kernel, or qualification is claimed. */ |
| 173 | typedef struct { |
| 174 | uint8_t expected[2][32]; |
| 175 | uint64_t code_bytes; |
| 176 | const char *label; |
| 177 | unsigned calls, submits, syncs; |
| 178 | int refuse; |
| 179 | } NrObservedIntent; |
| 180 | static void nr_inputs(const OmegaGpuFp8Tensor *t, OmegaGpuMem mem[3], uint32_t args[10]) { |
| 181 | OmegaGpuNativeTensorObservation owner; |
| 182 | EXPECT(omega_gpu_fp8_native_observe(t,&owner)==0); |
| 183 | EXPECT(omega_gpu_session_alloc(16,&mem[0])==0); |
| 184 | EXPECT(omega_gpu_session_alloc(1024,&mem[1])==0); |
| 185 | EXPECT(omega_gpu_session_alloc(512,&mem[2])==0); |
| 186 | uint64_t directory[2]={owner.weights.va,owner.scales.va}; |
| 187 | memcpy(mem[0].cpu,directory,sizeof directory); |
| 188 | uint32_t words[10]={(uint32_t)mem[0].va,(uint32_t)(mem[0].va>>32), |
| 189 | (uint32_t)mem[1].va,(uint32_t)(mem[1].va>>32), |
| 190 | (uint32_t)mem[2].va,(uint32_t)(mem[2].va>>32),128,0,512,128}; |
| 191 | memcpy(args,words,sizeof words); |
| 192 | } |
| 193 | static void nr_freeze_intent(NrObservedIntent *intent, const OmegaGpuCmdList *cl, |
| 194 | const OmegaGpuNativeArtifact *a, uint64_t code_va, const uint32_t args[10], |
| 195 | OmegaGpuCmdListMode mode, const char *label) { |
| 196 | OmegaGpuCmdListOwner owner; |
| 197 | EXPECT(omega_gpu_cmdlist_owner(cl,&owner)==0 && owner.count==0); |
| 198 | memset(intent,0,sizeof *intent); |
| 199 | intent->code_bytes=a->sizes[1]; intent->label=label; |
| 200 | for(unsigned i=0;i<2;++i) { |
| 201 | uint8_t bank[1024]={0},qmd[1024]={0},wire[384+1024+768]={0}; |
| 202 | uint32_t drv[OMEGA_BW_CBANK_DRIVER_WORDS],q0[96],q1[96]; |
| 203 | uint64_t bank_va=owner.banks.va+(uint64_t)i*1024; |
| 204 | uint64_t qmd_va=owner.qmds.va+(uint64_t)i*1024; |
| 205 | omega_blackwell_build_cbank_driver_2d(drv,bank_va,256,1,16,1); |
| 206 | memcpy(bank,drv,sizeof drv); memcpy(bank+896,args,10*sizeof *args); |
| 207 | OmegaBlackwellQmdConfig cfg={.code_va=code_va,.cbank_va=bank_va, |
| 208 | .scratch_va=owner.scratch.va,.sem_va=owner.semaphores.va+(uint64_t)i*16, |
| 209 | .qmd0_va=qmd_va+512,.qmd1_va=qmd_va,.num_elements=128, |
| 210 | .threads_per_block=256,.grid_width=16,.threads_x=256,.threads_y=1, |
| 211 | .grid_x=16,.grid_y=1,.gpr_count=64,.shared_bytes=1024}; |
| 212 | EXPECT(omega_blackwell_build_qmd1(q1,&cfg)==0); |
| 213 | EXPECT(omega_blackwell_build_qmd0(q0,qmd_va+512,qmd_va)==0); |
| 214 | q1[10]=mode==OMEGA_GPU_CMDLIST_INLINE?0x00190000u:0; |
| 215 | q1[12]=mode==OMEGA_GPU_CMDLIST_INLINE?(uint32_t)((qmd_va+512)>>8):0; |
| 216 | memcpy(qmd,q1,sizeof q1); memcpy(qmd+512,q0,sizeof q0); |
| 217 | uint64_t meta[32]={1,159,1,0,10,a->sizes[1],i,owner.record_generation,0,0,code_va}; |
| 218 | uint64_t submit[16]={1,159,4,owner.record_generation,mode,0,1,1,0,0,0,2}; |
| 219 | for(unsigned j=0;j<32;++j) nr_word(wire,j,meta[j]); |
| 220 | for(unsigned j=0;j<16;++j) nr_word(wire,32+j,submit[j]); |
| 221 | size_t off=384; |
| 222 | memcpy(wire+off,bank,896+10*sizeof *args); off+=896+10*sizeof *args; |
| 223 | memcpy(wire+off,qmd,384); off+=384; |
| 224 | memcpy(wire+off,qmd+512,384); off+=384; |
| 225 | nr_digest(intent->expected[i],wire,off); |
| 226 | } |
| 227 | } |
| 228 | static int nr_observe_actual(const OmegaGpuCmdList *cl, const OmegaGpuCmdListConsumed *consumed, void *data) { |
| 229 | NrObservedIntent *intent=data; OmegaGpuCmdListOwner owner; |
| 230 | ++intent->calls; |
| 231 | EXPECT(intent->calls==1 && fk.submits==intent->submits && fk.syncs==intent->syncs); |
| 232 | if(omega_gpu_cmdlist_owner(cl,&owner)!=0 || owner.count!=2) return -1; |
| 233 | for(unsigned i=0;i<owner.count;++i) { |
| 234 | OmegaGpuCmdListEntry entry; |
| 235 | if(omega_gpu_cmdlist_entry(cl,i,&entry)!=0) return -1; |
| 236 | uint64_t meta[32]={1,159,1,0,entry.n_args,intent->code_bytes,entry.ordinal, |
| 237 | entry.record_generation,entry.independent,entry.pending_wait,entry.code_va}; |
| 238 | uint64_t submit[16]={1,159,4,owner.record_generation,consumed->options.mode, |
| 239 | consumed->options.barrier,consumed->timeout_ms,consumed->spin_us, |
| 240 | (uint64_t)consumed->options.first_barrier_none,(uint64_t)consumed->options.skip_launch, |
| 241 | (uint64_t)consumed->options.stamps,owner.count}; |
| 242 | uint8_t got[32]={0}; uint64_t result=0; |
| 243 | if(omega_native_mclaunch(&result,meta,32,entry.bank,1024,entry.qmd_slot,1024, |
| 244 | submit,16,got,32)!=OMEGA_OK || result!=0 || |
| 245 | memcmp(got,intent->expected[i],32)!=0) return -1; |
| 246 | const char *dir=getenv("OMEGA_NATIVE_OBSERVER_DIR"); |
| 247 | if(dir && *dir) { |
| 248 | uint8_t wire[32+256+128+1024+1024]={0}; char path[1024]; |
| 249 | memcpy(wire,intent->expected[i],32); |
| 250 | for(unsigned j=0;j<32;++j) nr_word(wire+32,j,meta[j]); |
| 251 | for(unsigned j=0;j<16;++j) nr_word(wire+32+256,j,submit[j]); |
| 252 | memcpy(wire+32+256+128,entry.bank,1024); |
| 253 | memcpy(wire+32+256+128+1024,entry.qmd_slot,1024); |
| 254 | int n=snprintf(path,sizeof path,"%s/%s-%u.wire",dir,intent->label,i); |
| 255 | EXPECT(n>0 && (size_t)n<sizeof path); |
| 256 | FILE *f=fopen(path,"wb"); EXPECT(f!=NULL); |
| 257 | if(!f) return -1; |
| 258 | EXPECT(fwrite(wire,1,sizeof wire,f)==sizeof wire); |
| 259 | EXPECT(fclose(f)==0); |
| 260 | } |
| 261 | } |
| 262 | return 0; |
| 263 | } |
| 264 | static void nr_submit_observed(OmegaGpuCmdList *cl, NrObservedIntent *intent, OmegaGpuCmdListMode mode) { |
| 265 | OmegaGpuCmdListOpts opts={.mode=mode,.timeout_ms=1,.spin_us=1}; |
| 266 | OmegaGpuCmdListStats stats={0}; |
| 267 | intent->submits=fk.submits; intent->syncs=fk.syncs; |
| 268 | EXPECT(omega_gpu_cmdlist_submit_observed(cl,&opts,&stats,nr_observe_actual,intent)== |
| 269 | (intent->refuse?-1:0)); |
| 270 | EXPECT(intent->calls==1); |
| 271 | if(intent->refuse) EXPECT(fk.submits==intent->submits && fk.syncs==intent->syncs); |
| 272 | else EXPECT(stats.launches==2 && stats.sems_done==2 && fk.submits>intent->submits); |
| 273 | } |
| 274 | static void c_native_observer_modes(void) { |
| 275 | fk_reset(); EXPECT(install()==0); |
| 276 | OmegaGpuNativeArtifact a; uint8_t w[65536]={0},sc[1024]={0}; nr_fixture(&a,w,sc); |
| 277 | OmegaGpuFp8Tensor *t=NULL; OmegaGpuCmdList *cl[3]={NULL,NULL,NULL}; |
| 278 | EXPECT(omega_gpu_fp8_tensor_upload(1,128,256,w,(const uint16_t *)sc,&t)==0); |
| 279 | for(unsigned i=0;i<3;++i) EXPECT(omega_gpu_cmdlist_create(2,&cl[i])==0); |
| 280 | omega_gpu_session_lock(); |
| 281 | OmegaGpuMem mem[3]={0}; uint32_t args[10]; nr_inputs(t,mem,args); |
| 282 | OmegaGpuNativeLease lease={0}; EXPECT(omega_gpu_fp8_prepare_native(&a,&lease)==0); |
| 283 | uint64_t code_va=nr_code_va(&a); EXPECT(code_va!=0); |
| 284 | NrObservedIntent pcas,reuse,fresh,refused; |
| 285 | nr_freeze_intent(&pcas,cl[0],&a,code_va,args,OMEGA_GPU_CMDLIST_PCAS,"fresh-pcas"); |
| 286 | nr_freeze_intent(&reuse,cl[0],&a,code_va,args,OMEGA_GPU_CMDLIST_INLINE,"reuse-inline"); |
| 287 | nr_freeze_intent(&fresh,cl[1],&a,code_va,args,OMEGA_GPU_CMDLIST_INLINE,"fresh-inline"); |
| 288 | nr_freeze_intent(&refused,cl[2],&a,code_va,args,OMEGA_GPU_CMDLIST_PCAS,"refused"); |
| 289 | refused.refuse=1; |
| 290 | for(unsigned i=0;i<3;++i) for(unsigned j=0;j<2;++j) |
| 291 | EXPECT(omega_gpu_fp8_record_native(cl[i],t,&a,&lease,1,mem[0].va,mem[1].va,1,mem[2].va)==(int)j); |
| 292 | OmegaGpuCmdListOwner bad_owner; |
| 293 | EXPECT(omega_gpu_cmdlist_owner(cl[2],&bad_owner)==0); |
| 294 | ((uint8_t *)bad_owner.banks.cpu)[896]^=1; /* actual post-record argument corruption */ |
| 295 | nr_submit_observed(cl[0],&pcas,OMEGA_GPU_CMDLIST_PCAS); |
| 296 | nr_submit_observed(cl[0],&reuse,OMEGA_GPU_CMDLIST_INLINE); |
| 297 | nr_submit_observed(cl[1],&fresh,OMEGA_GPU_CMDLIST_INLINE); |
| 298 | nr_submit_observed(cl[2],&refused,OMEGA_GPU_CMDLIST_PCAS); |
| 299 | for(unsigned i=0;i<3;++i) omega_gpu_cmdlist_reset(cl[i]); |
| 300 | EXPECT(omega_native_lease_op(&lease,5,0)==0); omega_gpu_fp8_cache_clear(); |
| 301 | for(unsigned i=0;i<3;++i) omega_gpu_session_free(&mem[i]); |
| 302 | omega_gpu_session_unlock(); |
| 303 | for(unsigned i=0;i<3;++i) omega_gpu_cmdlist_free(cl[i]); |
| 304 | omega_gpu_fp8_tensor_free(t); omega_gpu_session_close(); |
| 305 | omega_native_artifact_snapshot_free(&nr_snapshot); |
| 306 | printf("HOST_ONLY actual typed-owner mode-final wires; role0=SYNTHETIC_LABEL; kernel/GPU/qualification=NOT_RUN\n"); |
| 307 | } |
| 308 | static void c_native_chain(void) { |
| 309 | fk_reset(); EXPECT(install()==0); |
| 310 | OmegaGpuNativeArtifact a; uint8_t weights[65536]={0}, raw_scales[1024]={0}; |
| 311 | nr_fixture(&a,weights,raw_scales); |
| 312 | printf("HOST_ONLY synthetic encoded_code_bytes=%llu encoded_code_sha256=", (unsigned long long)a.sizes[1]); |
| 313 | for (unsigned i=0;i<32;++i) printf("%02x",a.canonical[672+i]); |
| 314 | printf(" qualification=NOT_RUN\n"); |
| 315 | OmegaGpuFp8Tensor *t=NULL; OmegaGpuCmdList *cl=NULL; |
| 316 | EXPECT(omega_gpu_fp8_tensor_upload(1,128,256,weights,(const uint16_t *)raw_scales,&t)==0); |
| 317 | EXPECT(t!=NULL && omega_gpu_cmdlist_create(4,&cl)==0 && cl!=NULL); |
| 318 | if(!t || !cl) return; |
| 319 | omega_gpu_session_lock(); |
| 320 | OmegaGpuMem inputs[3]={0}; uint32_t input_args[10]; nr_inputs(t,inputs,input_args); |
| 321 | OmegaGpuNativeLease prepared={0}; EXPECT(omega_gpu_fp8_prepare_native(&a,&prepared)==0); |
| 322 | EXPECT(omega_native_bound(&a,&prepared)==0); |
| 323 | uint64_t va=nr_code_va(&a); EXPECT(va!=0); |
| 324 | OmegaGpuQ36NativeState *s=calloc(1,sizeof *s); EXPECT(s!=NULL); |
| 325 | if(!s) { omega_gpu_session_unlock(); return; } |
| 326 | nr_state(s,&a); |
| 327 | const OmegaGpuNativeArtifact *chosen=NULL; OmegaGpuNativeLease selected={0}; |
| 328 | EXPECT(omega_q36_native_begin(NULL,prepared.cache,&chosen,&selected)==1); |
| 329 | s->rows[1]=30; |
| 330 | EXPECT(omega_q36_native_begin(s,prepared.cache,&chosen,&selected)<0); |
| 331 | s->rows[1]=31; s->rows[21]^=1; |
| 332 | EXPECT(omega_q36_native_begin(s,prepared.cache,&chosen,&selected)<0); |
| 333 | s->rows[21]^=1; |
| 334 | EXPECT(omega_q36_native_begin(s,prepared.cache,&chosen,&selected)==0); |
| 335 | EXPECT(chosen==&s->artifact[0] && selected.slot==prepared.slot && selected.revision==prepared.revision); |
| 336 | OmegaGpuNativeArtifact bad=a; bad.code[0]^=1; |
| 337 | unsigned allocs=fk.allocs; OmegaGpuNativeLease refused={0}; |
| 338 | EXPECT(omega_gpu_fp8_prepare_native(&bad,&refused)!=0 && fk.allocs==allocs); |
| 339 | bad=a; bad.admission=NULL; |
| 340 | EXPECT(omega_gpu_fp8_prepare_native(&bad,&refused)!=0 && fk.allocs==allocs); |
| 341 | bad=a; bad.manifest[0]^=1; |
| 342 | EXPECT(omega_gpu_fp8_prepare_native(&bad,&refused)!=0 && fk.allocs==allocs); |
| 343 | const unsigned mutated[]={OMEGA_SNAPSHOT_QMD1,OMEGA_SNAPSHOT_CBANK, |
| 344 | OMEGA_SNAPSHOT_TEXT,OMEGA_SNAPSHOT_CUBIN}; |
| 345 | for(unsigned i=0;i<sizeof mutated/sizeof mutated[0];++i) { |
| 346 | nr_snapshot.bytes[mutated[i]][0]^=1; |
| 347 | EXPECT(omega_gpu_fp8_prepare_native(&a,&refused)!=0 && fk.allocs==allocs); |
| 348 | nr_snapshot.bytes[mutated[i]][0]^=1; |
| 349 | } |
| 350 | OmegaGpuNativeLease wrong=selected; wrong.epoch++; |
| 351 | EXPECT(omega_gpu_fp8_record_native(cl,t,chosen,&wrong,1,inputs[0].va,inputs[1].va,1,inputs[2].va)<0); |
| 352 | EXPECT(omega_gpu_cmdlist_count(cl)==0); |
| 353 | OmegaGpuNativeTensorObservation owner; EXPECT(omega_gpu_fp8_native_observe(t,&owner)==0); |
| 354 | uint64_t actual_call[12] = {1,1,128,256,1,10,0,1, |
| 355 | owner.allocation_epoch,omega_gpu_session_epoch(),owner.owner_generation,0}, actual_launch[32] = {0}; |
| 356 | EXPECT(omega_native_bound(chosen,&selected)==0); |
| 357 | EXPECT(omega_native_launch(chosen,actual_call,actual_launch)==0); |
| 358 | actual_call[3] = 128; |
| 359 | EXPECT(omega_native_launch(chosen,actual_call,actual_launch)!=0); |
| 360 | actual_call[3] = 256; |
| 361 | actual_call[8]^=1; EXPECT(omega_native_launch(chosen,actual_call,actual_launch)!=0); |
| 362 | for(unsigned i=0;i<32;++i) EXPECT(actual_launch[i]==0); |
| 363 | actual_call[8]^=1; actual_call[10]=0; |
| 364 | EXPECT(omega_native_launch(chosen,actual_call,actual_launch)!=0); |
| 365 | actual_call[10]=owner.owner_generation; actual_call[11]=1; |
| 366 | EXPECT(omega_native_launch(chosen,actual_call,actual_launch)!=0); |
| 367 | actual_call[11]=0; |
| 368 | EXPECT(omega_gpu_fp8_record_native(cl,t,chosen,&selected,1,inputs[0].va,inputs[1].va,1,inputs[2].va)==0); |
| 369 | EXPECT(nr_qmd_binds(va)>0); |
| 370 | omega_q36_native_end(&selected); |
| 371 | size_t b=16+prepared.slot*16; |
| 372 | EXPECT(prepared.cache->pool[b+3]==1 && prepared.cache->pool[b+4]==0 && prepared.cache->pool[b+5]==1); |
| 373 | omega_gpu_fp8_cache_clear(); EXPECT(nr_code_va(&a)==va); |
| 374 | OmegaGpuCmdListOpts opts={.timeout_ms=1}; OmegaGpuCmdListStats st={0}; |
| 375 | EXPECT(omega_gpu_cmdlist_submit(cl,&opts,&st)==0); |
| 376 | EXPECT(st.launches==1 && st.sems_done==1 && fk.submits>0); |
| 377 | EXPECT(prepared.cache->pool[b+3]==1 && prepared.cache->pool[b+4]==0); |
| 378 | omega_gpu_cmdlist_reset(cl); EXPECT(omega_gpu_cmdlist_count(cl)==0); |
| 379 | EXPECT(prepared.cache->pool[b+3]==0 && omega_native_lease_op(&prepared,5,0)==0); |
| 380 | #ifdef CUDAPP_NATIVE_RUNTIME_TEST |
| 381 | /* Real selected graph caller must accept ordinal 0 AND later ordinal 1. |
| 382 | * The typed-host fake does not execute either encoded kernel. */ |
| 383 | EXPECT(omega_gpu_q36_test_record_fp8(cl,s,t,inputs[0].va,inputs[1].va,inputs[2].va)==0); |
| 384 | EXPECT(omega_gpu_cmdlist_count(cl)==1); |
| 385 | EXPECT(omega_gpu_q36_test_record_fp8(cl,s,t,inputs[0].va,inputs[1].va,inputs[2].va)==0); |
| 386 | EXPECT(omega_gpu_cmdlist_count(cl)==2); |
| 387 | unsigned graph_submits=fk.submits; |
| 388 | /* g.native/g.moe are NULL in this actual nonempty production submit caller. */ |
| 389 | EXPECT(omega_gpu_q36_test_submit_incumbent(cl)==0); |
| 390 | EXPECT(fk.submits>graph_submits && omega_gpu_cmdlist_count(cl)==0); |
| 391 | EXPECT(prepared.cache->pool[b+3]==0 && prepared.cache->pool[b+4]==0); |
| 392 | #endif |
| 393 | omega_gpu_fp8_cache_clear(); EXPECT(nr_code_va(&a)==0); |
| 394 | for(unsigned i=0;i<3;++i) omega_gpu_session_free(&inputs[i]); |
| 395 | free(s); omega_gpu_session_unlock(); |
| 396 | omega_gpu_cmdlist_free(cl); omega_gpu_fp8_tensor_free(t); omega_gpu_session_close(); |
| 397 | omega_native_artifact_snapshot_free(&nr_snapshot); |
| 398 | } |
| 399 | static void c_native_timeout_refs(void) { |
| 400 | fk_reset(); EXPECT(install()==0); |
| 401 | OmegaGpuNativeArtifact a; uint8_t w[65536]={0}, sc[1024]={0}; nr_fixture(&a,w,sc); |
| 402 | OmegaGpuCmdList *cl=NULL; EXPECT(omega_gpu_cmdlist_create(1,&cl)==0); |
| 403 | omega_gpu_session_lock(); OmegaGpuNativeLease lease={0}; |
| 404 | EXPECT(omega_gpu_fp8_prepare_native(&a,&lease)==0); |
| 405 | uint64_t va=nr_code_va(&a), epoch=omega_gpu_session_epoch(); EXPECT(va!=0); |
| 406 | OmegaGpuLaunch L=launch_desc(1); L.code_va=va; |
| 407 | EXPECT(omega_gpu_cmdlist_add_native(cl,&L,&lease)==0); |
| 408 | EXPECT(omega_native_lease_op(&lease,5,0)==0); |
| 409 | fk.mode=MODE_HANG; OmegaGpuCmdListOpts o={.timeout_ms=1}; OmegaGpuCmdListStats st={0}; |
| 410 | EXPECT(omega_gpu_cmdlist_submit(cl,&o,&st)<0); |
| 411 | size_t b=16+lease.slot*16; |
| 412 | EXPECT(lease.cache->pool[b+3]==1 && lease.cache->pool[b+4]==1); |
| 413 | omega_gpu_cmdlist_reset(cl); EXPECT(omega_gpu_cmdlist_count(cl)==1); |
| 414 | omega_gpu_fp8_cache_clear(); EXPECT(nr_code_va(&a)==va && omega_gpu_session_epoch()==epoch); |
| 415 | omega_gpu_session_unlock(); omega_gpu_cmdlist_free(cl); |
| 416 | EXPECT(nr_code_va(&a)==va && lease.cache->pool[b+4]==1); |
| 417 | EXPECT(omega_gpu_session_recover()==0 && omega_gpu_session_epoch()>epoch); |
| 418 | fk.mode=MODE_COMPLETE; omega_gpu_session_lock(); |
| 419 | EXPECT(omega_native_bound(&a,&lease)!=0); |
| 420 | OmegaGpuNativeLease fresh={0}; EXPECT(omega_gpu_fp8_prepare_native(&a,&fresh)==0); |
| 421 | EXPECT(fresh.epoch!=lease.epoch && fresh.cache->pool[b+4]==0); |
| 422 | EXPECT(omega_native_lease_op(&fresh,5,0)==0); omega_gpu_fp8_cache_clear(); |
| 423 | omega_gpu_session_unlock(); omega_gpu_session_close(); |
| 424 | omega_native_artifact_snapshot_free(&nr_snapshot); |
| 425 | } |
| 426 | static void c_native_close_epoch(void) { |
| 427 | fk_reset(); EXPECT(install()==0); |
| 428 | OmegaGpuNativeArtifact a; uint8_t w[65536]={0},sc[1024]={0}; nr_fixture(&a,w,sc); |
| 429 | omega_gpu_session_lock(); OmegaGpuNativeLease old={0}; |
| 430 | EXPECT(omega_gpu_fp8_prepare_native(&a,&old)==0); uint64_t epoch=old.epoch; |
| 431 | omega_gpu_session_unlock(); omega_gpu_session_close(); |
| 432 | EXPECT(omega_gpu_session_epoch()>epoch); |
| 433 | omega_gpu_session_lock(); EXPECT(omega_native_bound(&a,&old)!=0); |
| 434 | OmegaGpuNativeLease fresh={0}; EXPECT(omega_gpu_fp8_prepare_native(&a,&fresh)==0); |
| 435 | EXPECT(fresh.epoch>epoch && omega_native_bound(&a,&fresh)==0); |
| 436 | EXPECT(omega_native_lease_op(&fresh,5,0)==0); omega_gpu_fp8_cache_clear(); |
| 437 | omega_gpu_session_unlock(); omega_gpu_session_close(); |
| 438 | omega_native_artifact_snapshot_free(&nr_snapshot); |
| 439 | } |