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/omega-mv/blob/main/research/m15/spbm/reduce.c # 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 Sign in to star 1 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-mv / research / m15 / spbm / reduce.c` 74 lines ยท 4143 bytes Raw Blame History 1 /* SPDX-License-Identifier: GPL-2.0-only */ 2 /* Deterministic reduction of the calibration sampler's exact JSONL format. 3 * This is not the R15 performance reducer and cannot issue an R15 PASS. 4 */ 5 #include 6 #include 7 #include 8 #include 9 #include 10 #include 11 12 struct sample { unsigned seq; uint64_t begin,end,e[5],p[5],nv_begin,nv_end,nv_e,nv_p; }; 13 static void fail(const char *s) { fprintf(stderr,"calibration: %s\n",s); exit(1); } 14 static int parse(const char *s,struct sample *v) 15 { 16 int n=0,got=sscanf(s,"{\"sample\":%u,\"read_begin_ns\":%"SCNu64",\"read_end_ns\":%"SCNu64",\"energy_uj\":[%"SCNu64",%"SCNu64",%"SCNu64",%"SCNu64",%"SCNu64"],\"power_uw\":[%"SCNu64",%"SCNu64",%"SCNu64",%"SCNu64",%"SCNu64"],\"overflow_raw\":[0,0,0,0,0],\"nvml_begin_ns\":%"SCNu64",\"nvml_end_ns\":%"SCNu64",\"nvml_energy_mj\":%"SCNu64",\"nvml_power_mw\":%"SCNu64"}%n", 17 &v->seq,&v->begin,&v->end,&v->e[0],&v->e[1],&v->e[2],&v->e[3],&v->e[4], 18 &v->p[0],&v->p[1],&v->p[2],&v->p[3],&v->p[4],&v->nv_begin,&v->nv_end,&v->nv_e,&v->nv_p,&n); 19 return got==17 && n>0 && (s[n]=='\n' || s[n]==0); 20 } 21 static double mid(const struct sample *v) { return v->begin+(v->end-v->begin)/2.0; } 22 static double nv_mid(const struct sample *v) { return v->nv_begin+(v->nv_end-v->nv_begin)/2.0; } 23 static void reduce(const char *file,const char *phase,int round,int comma) 24 { 25 FILE *f=fopen(file,"r"); char line[2048]; 26 struct sample a={0},prev={0},cur={0}; 27 double integral[5]={0},nv_integral=0,max_span=0,max_gap=0; 28 unsigned count=0; 29 if(!f) fail(file); 30 while(fgets(line,sizeof(line),f)) { 31 if(!parse(line,&cur) || cur.seq!=count || cur.end`10000000` || cur.nv_beginmax_span) max_span=cur.end-cur.begin; 33 for(int i=0;i<5;i++) if(cur.e[i]>UINT32_MAX*UINT64_C(1000) || cur.e[i]%1000 || cur.p[i]>`600000000`) fail("invalid sensor value"); 34 if(!count) a=cur; 35 else { 36 double dt=(mid(&cur)-mid(&prev))/1e9; 37 if(cur.begin<=prev.end || dt>.3) fail("nonmonotonic or missing sample"); 38 if(dt>max_gap) max_gap=dt; 39 for(int i=0;i<5;i++) { 40 if(cur.e[i]2) { phase=(const char **)(argv+2); np=argc-2; } 67 fputs("{\"schema\":\"AIEN_SPBM_CALIBRATION_OBSERVATIONS_V2\",\"qualified\":false,\"R15_PASS\":false,\"energy_order\":[\"pkg\",\"cpu_e\",\"cpu_p\",\"gpc_unverified\",\"gpm\"],\"power_order\":[\"sys_total\",\"soc_pkg\",\"cpu_e\",\"cpu_p\",\"gpu\"],\"windows\":[\n",stdout); 68 for(int round=1;round<=3;round++) for(int i=0;i=(int)sizeof(path)) fail("path too long"); 70 reduce(path,phase[i],round,n++); 71 } 72 fputs("\n]}\n",stdout); 73 return ferror(stdout)?1:0; 74 }