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/aien-sovereign-core-mv/blob/main/om/ribbon/chip_probe.c # aien-sovereign-core-mv AienOS host runtime: inference scheduling, paged KV state, the aien CLI and Spark verification tooling. Its inference engine is in alpha testing (DGX Spark GB10); Omega is the implementation destination. 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 `aien-sovereign-core-mv / om / ribbon / chip_probe.c` 194 lines ยท 9405 bytes Raw Blame History 1 /* SPDX-License-Identifier: Apache-2.0 2 * Measurement instrument only. All queue/ownership policy is pipeline.om. 3 * Connects its actions to real O_DIRECT reads, SHA256 verification and the 4 * existing Omega FP8 slot API. It is not a model serving implementation. 5 */ 6 #define _GNU_SOURCE 7 #include "omega_native.h" 8 #include "omega_gpu_fp8_slots.h" 9 #include 10 #include 11 #include 12 #include 13 #include 14 #include 15 #include 16 #include 17 #include 18 #include 19 #include 20 #include 21 #include 22 23 enum { E = 32, N = 2048, K = 768, SCALE_COUNT = (N/128)*(K/128), 24 WEIGHT_BYTES = N*K, PAYLOAD = WEIGHT_BYTES+2*SCALE_COUNT, 25 STRIDE = (PAYLOAD+4095)/4096*4096 }; 26 typedef struct { 27 int fd; 28 uint32_t key; 29 uint64_t ticket, begin, io_end, end; 30 void *buf; 31 unsigned char expected[SHA256_DIGEST_LENGTH]; 32 pthread_t thread; 33 atomic_int done; 34 bool active, owned, corrupt; 35 int ok; 36 } Read; 37 static uint64_t state[4096]; 38 static unsigned char hashes[E][SHA256_DIGEST_LENGTH]; 39 static uint64_t now_ns(void) { 40 struct timespec t; clock_gettime(CLOCK_MONOTONIC, &t); 41 return (uint64_t)t.tv_sec*1000000000ull+(uint64_t)t.tv_nsec; 42 } 43 static int call(uint64_t op, uint64_t key, uint64_t bytes, uint64_t deadline, 44 uint64_t verified, uint64_t out[8]) { 45 uint64_t q[8]={op,key,bytes,deadline,verified,0,now_ns(),0}, result=99; 46 uint32_t trap=omega_pipeline(&result,state,4096,q,8,out,8); 47 if (trap) { fprintf(stderr,"Omega trap %u\n",trap); return -1; } 48 return (int)result; 49 } 50 static void *read_job(void *arg) { 51 Read *r=arg; 52 r->begin=now_ns(); 53 ssize_t n; 54 do { n=pread(r->fd,r->buf,STRIDE,(off_t)r->key*STRIDE); } while(n<0 && errno==EINTR); 55 r->io_end=now_ns(); 56 if(r->corrupt && n==STRIDE) ((unsigned char*)r->buf)[128]^=1; 57 unsigned char got[SHA256_DIGEST_LENGTH]; 58 r->ok=n==STRIDE && SHA256(r->buf,PAYLOAD,got)!=NULL && memcmp(got,r->expected,sizeof got)==0; 59 r->end=now_ns(); 60 atomic_store_explicit(&r->done,1,memory_order_release); 61 return NULL; 62 } 63 static int fixture(const char *path, unsigned char **all_w, uint16_t **all_s) { 64 *all_w=malloc((size_t)E*WEIGHT_BYTES); *all_s=malloc((size_t)E*2*SCALE_COUNT); 65 unsigned char *b=NULL; 66 if(!*all_w || !*all_s || posix_memalign((void**)&b,4096,STRIDE)) return 1; 67 int fd=open(path,O_WRONLY|O_CREAT|O_EXCL|O_CLOEXEC,0600); 68 if(fd<0) { free(b); return 1; } 69 for(unsigned e=0;e>24)%119); /* finite positive E4M3 */ 75 } 76 uint16_t *s=(uint16_t*)(b+WEIGHT_BYTES); 77 for(unsigned j=0;jdeadline) { failed=1;break; } 105 bool progress=false; 106 for(unsigned i=0;ithread,NULL);r->active=false; 108 read_start[r->key]=r->begin;read_end[r->key]=r->end;io_end[r->key]=r->io_end;read_ns+=r->end-r->begin; 109 if(call(4,r->ticket,0,0,r->ok?1:0,out)) { failed=1;break; } 110 if(!r->ok) { 111 if(call(9,r->ticket,0,0,0,out)) failed=1; 112 r->owned=false; 113 rejected++; 114 } 115 progress=true; 116 } 117 for(unsigned i=0;iticket=out[0];r->key=(uint32_t)out[1]; 122 r->corrupt=mutant && r->key==3;memcpy(r->expected,hashes[r->key],sizeof r->expected); 123 atomic_store_explicit(&r->done,0,memory_order_relaxed);r->active=true;r->owned=true; 124 if(pthread_create(&r->thread,NULL,read_job,r)) { r->active=false;failed=1;break; } 125 progress=true; 126 } 127 if(failed) break; 128 int rc=call(5,0,0,0,0,out); 129 if(rc==0) { 130 uint64_t ticket=out[0];uint32_t key=(uint32_t)out[1]; 131 Read *r=NULL; 132 for(unsigned i=0;iactive) { failed=1;break; } 135 uint64_t c0=now_ns();copy_start[key]=c0; 136 rc=omega_gpu_fp8_slots_load(pool,key,key,r->buf,(uint16_t*)((unsigned char*)r->buf+WEIGHT_BYTES),&versions[key]); 137 copy_end[key]=now_ns();copy_ns+=copy_end[key]-c0; 138 if(call(6,ticket,0,0,rc==0?1:0,out) || rc) { failed=1;break; } 139 r->owned=false; 140 if(call(7,ticket,0,0,0,out)) { failed=1;break; } 141 compute_start[key]=now_ns(); 142 rc=omega_gpu_fp8_slots_gemv_grouped_f32(pool,1,&key,&versions[key],x,1,got,NULL); 143 compute_end[key]=now_ns();compute_ns+=compute_end[key]-compute_start[key]; 144 if(rc || memcmp(got,reference+(size_t)key*N,N*sizeof(float))) { failed=1;break; } 145 if(call(8,ticket,0,0,0,out) || call(9,ticket,0,0,0,out)) { failed=1;break; } 146 completed++;progress=true; 147 } else if(rc!=1) { failed=1;break; } 148 if(!progress) { struct timespec pause={0,100000}; nanosleep(&pause,NULL); } 149 } 150 uint64_t wall=now_ns()-start; 151 /* Stop admissions, wait for any actual I/O, acknowledge it, then free storage. */ 152 call(11,0,0,0,0,out); 153 for(unsigned i=0;i<2;i++) { 154 if(reads[i].active) { pthread_join(reads[i].thread,NULL);call(4,reads[i].ticket,0,0,0,out); } 155 free(reads[i].buf); 156 } 157 for(unsigned r=0;rcompute_start[c]?read_start[r]:compute_start[c]; 159 uint64_t hi=read_end[r]lo) overlap_ns+=hi-lo; 161 } 162 free(got); 163 printf("{\"trial\":%u,\"buffers\":%u,\"mutant\":%d,\"completed\":%u,\"rejected\":%u,\"wall_ns\":%"PRIu64",\"read_ns\":%"PRIu64",\"copy_ns\":%"PRIu64",\"compute_ns\":%"PRIu64",\"read_compute_pair_overlap_ns\":%"PRIu64",\"failed\":%d,\"origin_monotonic_ns\":%"PRIu64",\"spans\":[", 164 trial_id,buffers,mutant,completed,rejected,wall,read_ns,copy_ns,compute_ns,overlap_ns,failed,start); 165 for(unsigned e=0;e