Skip to content

Commit cdaa4f5

Browse files
committed
TurboPFor: Benchmark app
1 parent 84e966d commit cdaa4f5

File tree

1 file changed

+48
-32
lines changed

1 file changed

+48
-32
lines changed

lib/icapp.c

100644100755
Lines changed: 48 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1209,20 +1209,23 @@ void fpstat(unsigned char *in, size_t n, unsigned char *out, int s, unsigned cha
12091209
eamin = DBL_MAX, eamax = DBL_MIN, easum = 0, easumsqr = 0, //absolute error : abs(input-output)
12101210
ermin = DBL_MAX, ermax = DBL_MIN, ersum = 0, ersumsqr = 0, //relative error : abs(input-output)/abs(input)
12111211
osum = 0; //transformed lossy data (output) : sum
1212-
long long xtb = 0, xlb = 0, zlb = 0, tb = 0, lb = 0, elb=0, mtb=0, itb = 0;
1212+
long long xtb = 0, xlb = 0, zlb = 0, tb = 0, lb = 0, elb = 0, mtb = 0, itb = 0;
12131213
size_t idn = 0;
12141214
unsigned char *ip, *op;
1215-
unsigned esize = s<0?-s:s,t=0, dup=0,zero=0;
1215+
unsigned esize = s<0?-s:s, t = 0, dup=0,zero=0;
12161216
long long mant = 0;
12171217
int expo = 0,e;
1218-
unsigned char *tmp = _tmp;
1219-
if(!tmp) { tmp = malloc(n*esize); if(!tmp) die("malloc failed\n"); } memcpy(tmp, out, n*esize);
1220-
switch(esize) {
1221-
case 2: { uint16_t *p,*t = tmp; qsort(tmp, n, 2, cmpua16); for(dup=0,p = t; p < t+n-1; p++) { if(p[0] == p[1]) dup++; if(!p[0]) zero++; } } break;
1222-
case 4: { uint32_t *p,*t = tmp; qsort(tmp, n, 4, cmpua32); for(dup=0,p = t; p < t+n-1; p++) { if(p[0] == p[1]) dup++; if(!p[0]) zero++; } } break;
1223-
case 8: { uint64_t *p,*t = tmp; qsort(tmp, n, 8, cmpua64); for(dup=0,p = t; p < t+n-1; p++) { if(p[0] == p[1]) dup++; if(!p[0]) zero++; } } break;
1218+
if(_tmp || verbose > 4) {
1219+
unsigned char *tmp = _tmp;
1220+
if(!tmp) { tmp = malloc(n*esize); if(!tmp) die("malloc failed\n"); } memcpy(tmp, out, n*esize);
1221+
switch(esize) {
1222+
case 2: { uint16_t *p,*t = tmp; qsort(tmp, n, 2, cmpua16); for(dup=0,p = t; p < t+n-1; p++) { if(p[0] != p[1]) dup++; if(!p[0]) zero++; } } break;
1223+
case 4: { uint32_t *p,*t = tmp; qsort(tmp, n, 4, cmpua32); for(dup=0,p = t; p < t+n-1; p++) { if(p[0] != p[1]) dup++; if(!p[0]) zero++; } } break;
1224+
case 8: { uint64_t *p,*t = tmp; qsort(tmp, n, 8, cmpua64); for(dup=0,p = t; p < t+n-1; p++) { if(p[0] != p[1]) dup++; if(!p[0]) zero++; } } break;
1225+
default: die("#fpstat");
1226+
}
1227+
if(!_tmp) free(tmp);
12241228
}
1225-
if(!_tmp) free(tmp);
12261229
for(ip = in, op = out; ip < in+n*esize; ip += esize, op += esize)
12271230
switch(s) {
12281231
#if defined(FLT16_BUILTIN)
@@ -1287,8 +1290,8 @@ void fpstat(unsigned char *in, size_t n, unsigned char *out, int s, unsigned cha
12871290
double mse = easumsqr/n, irange = imax - imin;
12881291
if(verbose >= 2) printf("\n");
12891292
//printf("Leading/Trailing bits [%.2f%%,%.2f%%=%.2f%%]. XOR[%.2f%%,%.2f%%=%.2f%%] Zigzag[%.2f%%]\n", BR(lb), BR(tb), BR(lb+tb), BR(xlb), BR(xtb), BR(xlb+xtb), BR(zlb)/*BR(elb), BR(mtb), BR(elb+mtb)*/ );
1290-
if(verbose >= 2) printf("Range: [min=%g / max=%g] = %g. zeros=%.2f%%, Duplicate=%.4f%% ctz=%.1f%%\n", imin, imax, irange, (double)zero*100.0/(double)n,
1291-
(double)dup*100.0/(double)n, (double)((tb-itb)/8)*100.0/(double)(n*esize));
1293+
if(verbose >= 2) printf("Range: [min=%g / max=%g] = %g. zeros=[%u,%.2f%%], Distinct=[%u=%.4f%%] ctz=%.1f%%\n", imin, imax, irange);
1294+
if(verbose > 3 || _tmp) printf("zeros=[%u,%.2f%%], Distinct=[%u=%.4f%%] ctz=%.1f%%\n", zero,(double)zero*100.0/(double)n, dup, (double)dup*100.0/(double)n, (double)((tb-itb)/8)*100.0/(double)(n*esize));
12921295
//printf("Min error: Absolute = %.12f, Relative = %f, pointwise relative = %f\n", eamin, eamin/irange, eamax/irange, ermax);
12931296
//printf("Avg error: Absolute = %.12f, Relative = %f, pointwise relative = %f\n", easum/idn, (easum/idn)/irange, ersum/idn);
12941297
if(verbose > 2) printf("Max error: Absolute = %g, Relative = %g, pointwise relative = %g\n", eamax, eamax/irange, ermax); else if(verbose==2) printf("e=%g ", ermax);
@@ -2115,7 +2118,7 @@ testrazor() {
21152118
}
21162119
#endif
21172120
int main(int argc, char* argv[]) { //testrazor();
2118-
unsigned b = 1 << 31, lz=0, fno,m=1000000, bsize = (unsigned)-1;
2121+
unsigned b = 1 << 31, lz=0, fno,m=1000000, bsize = (unsigned)-1, quantb = 0;
21192122
int isize=4,dfmt = 0,kid=1,skiph=0,decs=0,divs=1,dim0=0;
21202123
uint64_t be_mindelta=0;
21212124
unsigned char *in = NULL, *out, *cpy;
@@ -2130,10 +2133,11 @@ int main(int argc, char* argv[]) { //testrazor();
21302133
int c, digit_optind = 0, this_option_optind = optind ? optind : 1, option_index = 0;
21312134
static struct option long_options[] = { {"blocsize", 0, 0, 'b'}, {0, 0, 0} };
21322135
for(;;) {
2133-
if((c = getopt_long(argc, argv, "a:B:b:C:d:D:d:e:E:f:F:g:G:I:J:k:K:hH:l:m:M:n:p:R:s:v:V:w:W:yz:", long_options, &option_index)) == -1) break;
2136+
if((c = getopt_long(argc, argv, "a:B:b:C:d:D:d:e:E:f:F:g:G:I:J:k:K:hH:l:m:M:n:p:q:R:s:v:V:w:W:yz:", long_options, &option_index)) == -1) break;
21342137
switch(c) {
21352138
case 0 : printf("Option %s", long_options[option_index].name); if(optarg) printf (" with arg %s", optarg); printf ("\n"); break;
21362139
case 'b': bsize = argtoi(optarg,1); break;
2140+
case 'B': b = argtoi(optarg,1); break;
21372141
case 'C': cmp = atoi(optarg); break;
21382142
case 'e': icmd = optarg; break;
21392143
case 'E': scmd = optarg; break;
@@ -2170,7 +2174,6 @@ int main(int argc, char* argv[]) { //testrazor();
21702174
case 'I': if((tm_Rep = atoi(optarg))<=0) tm_rep=tm_Rep=1; break;
21712175
case 'J': if((tm_Rep2 = atoi(optarg))<=0) tm_rep=tm_Rep2=1; break;
21722176
case 's': isize = argtoi(optarg,1); break;
2173-
case 'B': b = argtoi(optarg,1); break;
21742177
//case 'c': cmp++; break;
21752178
case 'l': codlev = atoi(optarg); break;
21762179
case 'y': mcpy = 0; break;
@@ -2181,6 +2184,7 @@ int main(int argc, char* argv[]) { //testrazor();
21812184
case 'm': rm = argtoi(optarg,1); break;
21822185
case 'M': rx = argtoi(optarg,1); break;
21832186
case 'p': { unsigned m = atoi(optarg); if(m==4 || m==8) tpmodeset(m);else die("transpose mode (option -p) must be 4 or 8\n"); } break;
2187+
case 'q': quantb = atoi(optarg); if(quantb < 8) quantb = 8; break;
21842188
case 'f': isize = -argtoi(optarg,1); break;
21852189
case 'R': { char *p; nx = strtoul(optarg, &p, 10); if(!nx) dim0++;
21862190
if(*p) ny = strtoul(p+1, &p, 10);
@@ -2279,24 +2283,36 @@ int main(int argc, char* argv[]) { //testrazor();
22792283

22802284
//if(fno == optind)
22812285
tm_init(tm_Rep, tm_verbose /* 2 print id */);
2282-
2283-
if(errlim > DBL_EPSILON /*|| nsd >= 0*/) { // convert input for lossy floating point compression
2284-
if(errlim < 0.0000009999) errlim = 0.000001;
2285-
if(isize == -4) { printf("Lossy compression float32\n");
2286-
fprazor32(in,n/4,out,errlim); if(verbose>0) fpstat(in, n/4, out, -4, NULL); //if(nsd >= 0) fprnd32(in,n/4,out,nsd); else //
2287-
fprazor32(in,n/4, in,errlim); /*if(nsd >= 0) fprnd32(in,n/4,in, nsd); else */
2288-
} else if(isize == -8) { printf("Lossy compression float64\n");
2289-
fprazor64(in,n/8,out,errlim); if(verbose>0) fpstat(in, n/8, out, -8, NULL); /*if(nsd>=0) fprnd64(in,n/8,out,nsd); else*/
2290-
fprazor64(in,n/8, in,errlim); /*if(nsd>=0) fprnd64(in,n/8, in,nsd); else*/
2291-
}
2292-
#if defined(FLT16_BUILTIN)
2293-
else if(isize == -2) { printf("Lossy compression float16\n");
2294-
fprazor16(in,n/2,out,errlim); if(verbose>0) fpstat(in, n/2, out, -2, NULL); /*if(nsd>=0) fprnd64(in,n/8,out,nsd); else*/
2295-
fprazor16(in,n/2, in,errlim); /*if(nsd>=0) fprnd64(in,n/8, in,nsd); else*/
2296-
}
2297-
#endif
2298-
}
2299-
be_mindelta = mindelta(in, n/abs(isize), abs(isize));
2286+
2287+
if(errlim > DBL_EPSILON/*|| nsd >= 0*/) { // convert input for lossy floating point compression
2288+
if(errlim > DBL_EPSILON && errlim < 0.0000009999) errlim = 0.000001; if(verbose>0) printf("Lossy compression float\n");
2289+
if(isize == -4) fprazor32(in,n/4,out,errlim);
2290+
else if(isize == -8) fprazor64(in,n/8,out,errlim);
2291+
#if defined(FLT16_BUILTIN)
2292+
else if(isize == -2) fprazor16(in,n/2,out,errlim);
2293+
#endif
2294+
if(verbose>0) fpstat(in, n/abs(isize), out, isize, cpy); memcpy(in,out,n);
2295+
} else if(isize < 0 && quantb > 0) { if(verbose>0) printf("Quantization=%d float\n", quantb);
2296+
if(isize == -4) {
2297+
float fmin,fmax;
2298+
if(quantb > 32) quantb = 32;
2299+
fpquant32e32(in, n/4, out, quantb, &fmin, &fmax); if(verbose>0) fpquant32d32(out, n/4, cpy, quantb, fmin, fmax);
2300+
} else if(isize == -8) {
2301+
double fmin,fmax;
2302+
if(quantb > 32) quantb = 32;
2303+
fpquant64e64(in, n/8, out, quantb, &fmin, &fmax); if(verbose>0) fpquant64d64(out,n/8,cpy, quantb, fmin, fmax);
2304+
}
2305+
#if defined(FLT16_BUILTIN)
2306+
else if(isize == -2) { _Float16 fmin,fmax;
2307+
if(quantb > 16) quantb = 16;
2308+
fpquant16e16(in,n/2,out, quantb, &fmin, &fmax); if(verbose>0) { printf("Range=[%g-%g]=%g ", (double)fmin, (double)fmax, (double)fmax - (double)fmin);
2309+
fpquant16d16(out,n/2,cpy, quantb, fmin, fmax);
2310+
}
2311+
}
2312+
#endif
2313+
if(verbose>0) fpstat(in, n/abs(isize), cpy, isize, NULL); memcpy(in, out, n);
2314+
}
2315+
be_mindelta = mindelta(in, n/abs(isize), abs(isize));
23002316

23012317
if(fi && verbose>1) {
23022318
unsigned l; // Calculate bits distributions

0 commit comments

Comments
 (0)