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
CUDApp / tests / dagsim / format_diff.c
| 1 | /* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 2 | * Read-only C formatting oracles retained from the migrated expressions. */ |
| 3 | #include "dagsim.h" |
| 4 | #include "dagsim_format.h" |
| 5 | #include <math.h> |
| 6 | #include <stdio.h> |
| 7 | int oracle_ds_day_from_date(const char *); |
| 8 | const char *oracle_ds_status_name(int); |
| 9 | const char *oracle_ds_prov_name(int); |
| 10 | static int checks, bad; |
| 11 | #define CHECK(x) do { checks++; if (!(x)) { fprintf(stderr,"format check line %d\n",__LINE__); bad++; } } while (0) |
| 12 | static void same(unsigned mode, uint64_t a[16], double expected) { |
| 13 | double got=ds_unbits(ds_decide(mode,a)); |
| 14 | CHECK((isnan(got)&&isnan(expected)) || ds_bits(got)==ds_bits(expected)); |
| 15 | } |
| 16 | int main(void) { |
| 17 | const char *dates[]={"1970-01-01","1969-12-31","2000-02-29","1900-03-01","2026-11-06","2026-0-0","2026-13-32","2026--1-1","2026-11-06junk","-1-1-1","2026-11","2026-11-x","+2026-+11-+6"}; |
| 18 | for (unsigned i=0;i<sizeof dates/sizeof *dates;i++) CHECK(ds_day_from_date(dates[i])==oracle_ds_day_from_date(dates[i])); |
| 19 | const unsigned cuts[]={255,256,257,511,512,513}; |
| 20 | char longdate[2048]; |
| 21 | for (unsigned i=0;i<sizeof cuts/sizeof *cuts;i++) { |
| 22 | const char *prefix[]={"","2026-","2026-11-"}, *tail[]={"2026-11-06","11-06","06"}; |
| 23 | for (unsigned j=0;j<3;j++) { |
| 24 | size_t n=strlen(prefix[j]); |
| 25 | strcpy(longdate,prefix[j]); memset(longdate+n,'0',cuts[i]); strcpy(longdate+n+cuts[i],tail[j]); |
| 26 | CHECK(ds_day_from_date(longdate)==oracle_ds_day_from_date(longdate)); |
| 27 | memset(longdate+n,' ',cuts[i]); strcpy(longdate+n+cuts[i],tail[j]); |
| 28 | CHECK(ds_day_from_date(longdate)==oracle_ds_day_from_date(longdate)); |
| 29 | } |
| 30 | memset(longdate,' ',cuts[i]-1); strcpy(longdate+cuts[i]-1,"+2026-11-06"); |
| 31 | CHECK(ds_day_from_date(longdate)==oracle_ds_day_from_date(longdate)); |
| 32 | memset(longdate,' ',cuts[i]-1); strcpy(longdate+cuts[i]-1,"-1-1-1"); |
| 33 | CHECK(ds_day_from_date(longdate)==oracle_ds_day_from_date(longdate)); |
| 34 | memset(longdate,' ',cuts[i]); strcpy(longdate+cuts[i],"2026-11-+"); |
| 35 | CHECK(ds_day_from_date(longdate)==oracle_ds_day_from_date(longdate)); |
| 36 | strcpy(longdate,"2026-11-06"); memset(longdate+10,'x',cuts[i]); longdate[10+cuts[i]]=0; |
| 37 | CHECK(ds_day_from_date(longdate)==oracle_ds_day_from_date(longdate)); |
| 38 | } |
| 39 | for (int i=-1;i<=10;i++) CHECK(!strcmp(ds_status_name(i),oracle_ds_status_name(i))); |
| 40 | for (int i=-1;i<=5;i++) CHECK(!strcmp(ds_prov_name(i),oracle_ds_prov_name(i))); |
| 41 | double v[]={0.0,-0.0,1.0,-1.0,0.5,0.05,1e-6,1e-9,1e15,1e14,INFINITY,-INFINITY,NAN}; |
| 42 | for (unsigned i=0;i<sizeof v/sizeof *v;i++) { |
| 43 | uint64_t a[16]={ds_bits(v[i])}; |
| 44 | CHECK(ds_decide(7,a)==!(v[i]==floor(v[i])&&fabs(v[i])<1e15)); |
| 45 | same(18,a,v[i]*1e-9); |
| 46 | for (unsigned j=0;j<sizeof v/sizeof *v;j++) { |
| 47 | uint64_t p[16]={ds_bits(v[i]),ds_bits(v[j])}; |
| 48 | CHECK(ds_decide(8,p)==(v[i]>0&&v[j]>0)); |
| 49 | CHECK(ds_decide(9,p)==(v[i]+1e-6>=v[j])); |
| 50 | same(17,p,v[i]-v[j]); same(19,p,v[j]>v[i]?v[j]:v[i]); |
| 51 | for (unsigned k=0;k<sizeof v/sizeof *v;k++) { |
| 52 | uint64_t s[16]={ds_bits(v[i]),ds_bits(v[j]),ds_bits(v[k])}; |
| 53 | same(16,s,v[j]>=0?fabs(v[i]-v[j])*(v[k]>0?v[k]:0.05):0); |
| 54 | } |
| 55 | } |
| 56 | } |
| 57 | for (unsigned kind=1;kind<=4;kind++) for (unsigned prov=0;prov<=4;prov++) { |
| 58 | uint64_t w[16]={kind,ds_bits(10),ds_bits(8),ds_bits(12),prov}; |
| 59 | double width=kind==2?(12.0-8.0)/10.0:0; |
| 60 | if(prov==4) width=1; |
| 61 | same(15,w,width); |
| 62 | char s[256]; ds_fmt(12,w,s); CHECK(strlen(s)>0); |
| 63 | } |
| 64 | for (unsigned kind=1;kind<=6;kind++) for (unsigned has=0;has<=1;has++) { |
| 65 | uint64_t p[16]={kind,has,3}; CHECK(ds_decide(13,p)==(kind==3&&!has?2:3)); |
| 66 | } |
| 67 | for (unsigned m=0;m<=1;m++) for(unsigned syn=0;syn<=1;syn++) { |
| 68 | uint64_t a[16]={m,syn}; char s[256]; ds_fmt(10,a,s); |
| 69 | CHECK(!strcmp(s,m?"MEASURED":syn?"SYNTHETIC_SENSITIVITY_ONLY":"UNMEASURED")); |
| 70 | CHECK(ds_decide(11,a)==m); |
| 71 | } |
| 72 | for (unsigned i=0;i<3;i++) for(unsigned j=0;j<3;j++) for(unsigned e=0;e<2;e++) { |
| 73 | uint64_t a[16]={ds_bits(v[i]),ds_bits(v[j]),ds_bits(1),ds_bits(v[j]),ds_bits(v[i]),ds_bits(0),e}; |
| 74 | int le=v[j]<=v[i]&&v[i]<=v[j]&&(!e||0<=1); |
| 75 | int lt=v[j]<v[i]||v[i]<v[j]||(e&&0<1); |
| 76 | CHECK(ds_decide(14,a)==(le&<)); |
| 77 | } |
| 78 | for(unsigned n=0;n<=32;n++) { |
| 79 | double scores[32]; unsigned ix[32]; char s[256]={0}; |
| 80 | for(unsigned i=0;i<n;i++) { scores[i]=(double)(i%5); ix[i]=i; } |
| 81 | for(unsigned i=1;i<n;i++) { unsigned k=ix[i],j=i; while(j&&scores[ix[j-1]]<scores[k]){ix[j]=ix[j-1];j--;}ix[j]=k; } |
| 82 | memcpy(s,scores,n*sizeof *scores); uint64_t a[16]={n}; CHECK(!ds_fmt(20,a,s)); |
| 83 | for(unsigned i=0;i<n;i++) CHECK((unsigned char)s[i]==ix[i]); |
| 84 | } |
| 85 | uint64_t over[16]={33}; char s[256]; CHECK(ds_fmt(20,over,s)==1); |
| 86 | printf("format differential: %d checks, %d failures\n",checks,bad); return bad?1:0; |
| 87 | } |