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/CUDApp/blob/main/tests/dagsim/resolve_diff.c # 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 Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `CUDApp / tests / dagsim / resolve_diff.c` 218 lines · 11875 bytes Raw Blame History 1 /* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */ 2 #include "dagsim.h" 3 #include "runtime/rx_costmodel.h" 4 #include 5 #include 6 #include 7 #include 8 #ifndef CUDAPP_MIGRATION_PENDING_C_DAGSIM_RESOLVE 9 #error resolve migration guard is not implemented 10 #endif 11 extern int ds_resolved_pack(const ds_model *, const ds_opts *, uint64_t *, ds_result *); 12 extern int oracle_ds_resolved_pack(const ds_model *, const ds_opts *, uint64_t *, ds_result *); 13 extern int oracle_ds_diff_models(const ds_model *, const ds_model *, const ds_opts *, ds_diff *); 14 extern double oracle_ds_counterfactual(const ds_model *, const ds_opts *, int); 15 extern int oracle_ds_find_op(const ds_model *, const char *); 16 extern int oracle_ds_find_res(const ds_model *, const char *); 17 static unsigned checks, failed; 18 static int fault; 19 static int fail_alloc; 20 void *__real_malloc(size_t n); 21 void *__wrap_malloc(size_t n) { return fail_alloc ? NULL : __real_malloc(n); } 22 static RxCmFeatures feature; 23 static const char *label; 24 #define CK(c, msg) do { checks++; if (!(c)) { failed++; fprintf(stderr,"FAIL %s: %s\n",label,msg); } } while (0) 25 int __wrap_rx_cm_predict(const RxCostModel *m, const RxCmFeatures *f, uint32_t arm, RxCmPrediction *p) { 26 (void)m; (void)arm; feature=*f; memset(p,0,sizeof *p); 27 p->known=1; p->n=32; p->mean_log2_ps=20.0; p->sd_log2=0.25; p->dof=12.0; 28 if (fault==1) return RX_CM_ERR_UNSUPPORTED; 29 if (fault==2) p->refused=1; 30 if (fault==3) p->known=0; 31 if (fault==4) p->n=0; 32 return fault==5 ? RX_CM_ERR_ARG : RX_CM_OK; 33 } 34 static void init(ds_model *m) { 35 memset(m,0,sizeof *m); m->n_res=4; m->n_ops=2; 36 m->has_calibration=1; m->cal_taken_day=100; m->cal_valid_days=20; 37 strcpy(m->cal_id,"cal"); strcpy(m->instrument,"none"); 38 for(int i=0;i<4;i++) { 39 ds_resource *r=&m->res[i]; snprintf(r->id,sizeof r->id,"r%d",i); 40 r->kind=i+1; r->slots=1; r->cap=`1000000000`.0; r->lo=`500000000`.0; r->hi=`2000000000`.0; r->prov=DS_PROV_SPECIFIED; 41 } 42 for(int i=0;i<2;i++) { 43 ds_op *p=&m->ops[i]; snprintf(p->id,sizeof p->id,"op%d",i); 44 p->kind=DS_OP_COMPUTE; p->engine=0; p->t_ns=16.0; p->lo=8.0; p->hi=32.0; 45 p->t_prov=DS_PROV_SPECIFIED; p->has_t=1; p->bytes=8.0; p->bw=1; 46 p->launch_ns=4.0; p->launcher=3; p->M=64; p->N=16; strcpy(p->src,"source"); 47 } 48 } 49 static void packcheck(ds_model *m, ds_opts *o) { 50 uint64_t a[8192],b[8192]; ds_result x,y; memset(a,0xa5,sizeof a); memset(b,0xa5,sizeof b); 51 memset(&x,0,sizeof x); memset(&y,0,sizeof y); 52 memset(&feature,0,sizeof feature); 53 int sy=oracle_ds_resolved_pack(m,o,b,&y); RxCmFeatures expected=feature; 54 int sx=ds_resolved_pack(m,o,a,&x); 55 if(getenv("DS_RESOLVE_RED")) a[0]^=1; 56 CK(sx==sy,"pack status"); CK(!memcmp(&x,&y,sizeof x),"refusal bytes/state"); 57 if(!sx) CK(!memcmp(a,b,sizeof a),"packed model bytes"); 58 CK(!memcmp(&feature,&expected,sizeof feature),"costmodel features"); 59 } 60 static void diffcheck(ds_model *b, ds_model *t, ds_opts *o) { 61 ds_diff x,y; int sy=oracle_ds_diff_models(b,t,o,&y); int sx=ds_diff_models(b,t,o,&x); 62 if(getenv("DS_RESOLVE_RED")) x.n_added^=1; 63 CK(sx==sy,"diff status"); CK(!memcmp(&x,&y,sizeof x),"diff fields/reason/accounting"); 64 } 65 static void resolve_cases(void) { 66 ds_model m; ds_opts o={.asof_day=120,.interval_q=0.9}; 67 label="resolve modes/provenance"; 68 for(int mode=-1;mode<=1;mode++) for(int prov=0;prov<=4;prov++) for(int where=0;where<3;where++) { 69 init(&m); o.mode=mode; 70 if(where==0) m.res[1].prov=prov; 71 if(where==1) m.ops[0].t_prov=prov; 72 if(where==2) { m.ops[0].t_prov=prov; m.ops[0].src[0]=0; } 73 packcheck(&m,&o); 74 } 75 label="resolve calibration boundary"; 76 for(int has=0;has<=1;has++) for(int day=119;day<=121;day++) for(int via=0;via<2;via++) { 77 init(&m); m.has_calibration=has; o.asof_day=day; 78 if(via) m.ops[0].t_prov=DS_PROV_MEASURED; else m.res[2].prov=DS_PROV_FITTED; 79 packcheck(&m,&o); 80 } 81 label="resolve host clock"; init(&m); m.ops[0].t_prov=DS_PROV_MEASURED; 82 for(int day=-1;day<=0;day++) { o.asof_day=day; packcheck(&m,&o); } 83 o.asof_day=120; 84 label="resolve engine refusals"; 85 for(int kind=1;kind<=6;kind++) for(int launcher=-1;launcher<=0;launcher++) { 86 init(&m); m.ops[0].kind=kind; m.ops[0].engine=-1; m.ops[0].launcher=launcher; packcheck(&m,&o); 87 } 88 label="resolve prediction branches"; 89 double qs[]={-1.0,0.0,0.5,0.9,1.0,2.0,NAN}; 90 for(int mode=-1;mode<=1;mode++) for(int f=0;f<=5;f++) for(unsigned q=0;q