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_profile.c
| 1 | /* M1 block 2 profile (omega-mv#575): time each backend callback of the Blackwell engine |
| 2 | * by wrapping the real backend table. Run under flock /tmp/aien-gb10.lock. */ |
| 3 | #include <stdio.h> |
| 4 | #include <stdlib.h> |
| 5 | #include <string.h> |
| 6 | #include <time.h> |
| 7 | #include <unistd.h> |
| 8 | #include "omega_gpu_engine.h" |
| 9 | #include "omega_blackwell_engine.h" |
| 10 | #include "omega_blackwell_encoder.h" |
| 11 | |
| 12 | static const OmegaGpuBackend *R; |
| 13 | static double T[16]; static long N[16]; |
| 14 | static const char *NAMES[16]={"open_device","create_channel","alloc","copy_in","fill_poison","build","submit","wait_marker","wait_marker2","wait_release_semaphore","barrier","copy_out","diagnostics","free_buf","close"}; |
| 15 | static double now(void){struct timespec t;clock_gettime(CLOCK_MONOTONIC,&t);return t.tv_sec+t.tv_nsec*1e-9;} |
| 16 | #define W0(i,call) static int w_##i(void*c){double t=now();int r=R->call(R->ctx);T[i]+=now()-t;N[i]++;return r;} |
| 17 | #define W1(i,call,A,a) static int w_##i(void*c,A){double t=now();int r=R->call(R->ctx,a);T[i]+=now()-t;N[i]++;return r;} |
| 18 | W0(0,open_device) W0(1,create_channel) |
| 19 | static int w_2(void*c,int role,size_t b){double t=now();int r=R->alloc(R->ctx,role,b);T[2]+=now()-t;N[2]++;return r;} |
| 20 | static int w_3(void*c,int role,const void*s,size_t b){double t=now();int r=R->copy_in(R->ctx,role,s,b);T[3]+=now()-t;N[3]++;return r;} |
| 21 | static int w_4(void*c,const uint32_t*w,size_t n){double t=now();int r=R->fill_poison(R->ctx,w,n);T[4]+=now()-t;N[4]++;return r;} |
| 22 | static int w_5(void*c,const OmegaGpuJob*j){double t=now();int r=R->build(R->ctx,j);T[5]+=now()-t;N[5]++;return r;} |
| 23 | W0(6,submit) |
| 24 | W1(7,wait_marker,uint64_t ms,ms) W1(8,wait_marker2,uint64_t ms,ms) W1(9,wait_release_semaphore,uint64_t ms,ms) W1(10,barrier,uint64_t ms,ms) |
| 25 | static int w_11(void*c,void*d,size_t b){double t=now();int r=R->copy_out(R->ctx,d,b);T[11]+=now()-t;N[11]++;return r;} |
| 26 | static void w_12(void*c,OmegaGpuBackendDiag*d){double t=now();R->diagnostics(R->ctx,d);T[12]+=now()-t;N[12]++;} |
| 27 | static int w_13(void*c,int role){double t=now();int r=R->free_buf(R->ctx,role);T[13]+=now()-t;N[13]++;return r;} |
| 28 | W0(14,close) |
| 29 | |
| 30 | int main(int argc,char**argv){ |
| 31 | if(argc<2||strcmp(argv[1],"--chip")){puts("NOT_RUN");return 2;} |
| 32 | long NJ=argc>2?atol(argv[2]):50; |
| 33 | R=omega_blackwell_engine_backend(); |
| 34 | OmegaGpuBackend B={0};B.ctx=(void*)1;B.open_device=w_0;B.create_channel=w_1;B.alloc=w_2;B.copy_in=w_3;B.fill_poison=w_4;B.build=w_5;B.submit=w_6;B.wait_marker=w_7;B.wait_marker2=w_8;B.wait_release_semaphore=w_9;B.barrier=w_10;B.copy_out=w_11;B.diagnostics=w_12;B.free_buf=w_13;B.close=w_14; |
| 35 | omega_gpu_engine_set_backend(&B); |
| 36 | uint8_t code[OMEGA_BW_VECADD_CODE_SIZE];size_t cb=0;omega_blackwell_encode_vecadd(code,sizeof code,&cb); |
| 37 | uint32_t n=65,a[65],b[65],out[65],poison[65];for(uint32_t i=0;i<n;i++){a[i]=i+1;b[i]=3*i;poison[i]=~(a[i]+b[i]);} |
| 38 | double tot=0;long bad=0; |
| 39 | for(long k=0;k<NJ;k++){OmegaGpuJob j;OmegaGpuResult r;memset(&j,0,sizeof j); |
| 40 | j.program=code;j.program_len=cb;j.layout=OMEGA_GPU_LAYOUT_VECTOR_1D;j.element_count=n;j.input_a=a;j.input_a_len=sizeof a;j.input_b=b;j.input_b_len=sizeof b;j.output=out;j.output_len=sizeof out;j.poison=poison;j.poison_count=n; |
| 41 | j.timeouts.marker_ms=5000;j.timeouts.release_semaphore_ms=5000;j.timeouts.marker2_ms=5000;j.timeouts.visibility_ms=5000; |
| 42 | double t=now();int rc=omega_gpu_execute(&j,&r);tot+=now()-t;if(rc)bad++;if(omega_gpu_engine_is_blocked()){puts("BLOCKED");for(;;)pause();}} |
| 43 | printf("callback,calls_per_job,ms_per_job,share\n"); |
| 44 | for(int i=0;i<15;i++)printf("%s,%.1f,%.3f,%.1f%%\n",NAMES[i],(double)N[i]/NJ,T[i]/NJ*1e3,T[i]/tot*100); |
| 45 | printf("TOTAL,,%.3f,100%% (jobs=%ld failed=%ld)\n",tot/NJ*1e3,NJ,bad);return bad!=0;} |