omega-mv
Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.
Brought by drakestapleton
omega-mv / bench / m1 / block2_gpu_submit.c
| 1 | /* M1 block 2 (omega-mv#575): GPU submit/complete round trip through omega_gpu_execute, |
| 2 | * the full lifecycle Omega runs per job (open, upload, submit, wait, readback, free, close). |
| 3 | * Reports wall per job (p50/p95/p99/max) and thread CPU time per job (the polling cost). |
| 4 | * Usage: block2 --chip [N] ; must run under flock /tmp/aien-gb10.lock. */ |
| 5 | #include <stdio.h> |
| 6 | #include <stdlib.h> |
| 7 | #include <string.h> |
| 8 | #include <time.h> |
| 9 | #include <unistd.h> |
| 10 | #include "omega_gpu_engine.h" |
| 11 | #include "omega_blackwell_engine.h" |
| 12 | #include "omega_blackwell_encoder.h" |
| 13 | |
| 14 | static double now(clockid_t c){struct timespec t;clock_gettime(c,&t);return t.tv_sec+t.tv_nsec*1e-9;} |
| 15 | static int cmpd(const void*a,const void*b){double x=*(const double*)a,y=*(const double*)b;return x<y?-1:x>y;} |
| 16 | |
| 17 | static int run_case(const char*label,uint32_t n,int no_store,long N){ |
| 18 | uint8_t code[OMEGA_BW_VECADD_CODE_SIZE];size_t code_bytes=0; |
| 19 | if(omega_blackwell_encode_vecadd(code,sizeof code,&code_bytes)||code_bytes<0x140u){fprintf(stderr,"encode fail\n");return 1;} |
| 20 | if(no_store)memcpy(code+0x120,code+0x130,OMEGA_BW_INSTRUCTION_BYTES); |
| 21 | uint32_t*a=malloc(n*4),*b=malloc(n*4),*out=malloc(n*4),*poison=malloc(n*4); |
| 22 | for(uint32_t i=0;i<n;i++){a[i]=i+1;b[i]=3*i;poison[i]=~(a[i]+b[i]);} |
| 23 | double*wall=malloc(N*sizeof(double));double cpu_tot=0;long bad=0; |
| 24 | for(long k=0;k<N;k++){ |
| 25 | OmegaGpuJob job;OmegaGpuResult res;memset(&job,0,sizeof job);memset(out,0,n*4); |
| 26 | job.program=code;job.program_len=code_bytes;job.layout=OMEGA_GPU_LAYOUT_VECTOR_1D;job.element_count=n; |
| 27 | job.input_a=a;job.input_a_len=n*4;job.input_b=b;job.input_b_len=n*4;job.output=out;job.output_len=n*4; |
| 28 | job.poison=poison;job.poison_count=n; |
| 29 | job.timeouts.marker_ms=5000;job.timeouts.release_semaphore_ms=5000;job.timeouts.marker2_ms=5000;job.timeouts.visibility_ms=5000; |
| 30 | double w0=now(CLOCK_MONOTONIC),c0=now(CLOCK_THREAD_CPUTIME_ID); |
| 31 | int rc=omega_gpu_execute(&job,&res); |
| 32 | double w1=now(CLOCK_MONOTONIC),c1=now(CLOCK_THREAD_CPUTIME_ID); |
| 33 | if(omega_gpu_engine_is_blocked()){fprintf(stderr,"GPU_ENGINE_BLOCKED, parking\n");fflush(stdout);for(;;)pause();} |
| 34 | int ok=no_store?(rc==OMEGA_GPU_ENGINE_OUTPUT_UNCHANGED):(rc==0); |
| 35 | if(ok&&!no_store)for(uint32_t i=0;i<n;i++)if(out[i]!=a[i]+b[i]){ok=0;break;} |
| 36 | if(!ok){bad++;if(bad<4)fprintf(stderr,"%s job %ld rc=%d state=%d step=%d\n",label,k,rc,res.last_state,res.failed_step);} |
| 37 | wall[k]=w1-w0;cpu_tot+=c1-c0; |
| 38 | } |
| 39 | qsort(wall,N,sizeof(double),cmpd);double sum=0;for(long k=0;k<N;k++)sum+=wall[k]; |
| 40 | printf("%s,%u,%ld,%ld,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.3f\n",label,n,N,bad,sum/N*1e6,wall[N/2]*1e6,wall[(long)(N*0.95)]*1e6,wall[(long)(N*0.99)]*1e6,wall[N-1]*1e6,cpu_tot/N*1e6,cpu_tot/sum); |
| 41 | fflush(stdout);free(a);free(b);free(out);free(poison);free(wall);return bad!=0; |
| 42 | } |
| 43 | int main(int argc,char**argv){ |
| 44 | if(argc<2||strcmp(argv[1],"--chip")){puts("NOT_RUN: pass --chip under flock");return 2;} |
| 45 | long N=argc>2?atol(argv[2]):1000; |
| 46 | omega_gpu_engine_set_backend(omega_blackwell_engine_backend()); |
| 47 | printf("case,elements,n_jobs,failed,wall_mean_us,wall_p50_us,wall_p95_us,wall_p99_us,wall_max_us,cpu_mean_us,cpu_over_wall\n"); |
| 48 | int r=0; |
| 49 | r|=run_case("vecadd_no_store",65,1,N); |
| 50 | r|=run_case("vecadd",65,0,N); |
| 51 | r|=run_case("vecadd",4096,0,N); |
| 52 | r|=run_case("vecadd",65537,0,N/4); |
| 53 | return r; |
| 54 | } |