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/test_core_algorithms.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 / test_core_algorithms.c` 174 lines · 11903 bytes Raw Blame History 1 /* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */ 2 #include "omega_core.h" 3 #include "omega_canonical.h" 4 #include "omega_vector.h" 5 #include "omega_gpu_hostmath.h" 6 #include "omega_gpu_fmt.h" 7 #include "cudapp_native.h" 8 #include "core_util_refs.h" 9 #include 10 #include 11 #include 12 #include 13 #include 14 static uint64_t state=UINT64_C(0xa13e7b965240c8df); 15 static uint64_t rnd(void){state^=state<<13;state^=state>>7;state^=state<<17;return state;} 16 #define CHECK(c) do{if(!(c)){fprintf(stderr,"CORE-UTIL FAIL line %d iteration %u\n",__LINE__,t);return 1;}}while(0) 17 static int canonical(void){ 18 OmegaObject a,b;uint8_t x[32768],y[32768],data[512];SemanticId id; 19 for(unsigned t=0;t<10000;t++){ 20 memset(&a,0,sizeof a);a.kind=(SemanticKind)(rnd()%256);b=a; 21 unsigned attrs=t==9999?32:(unsigned)(rnd()%9),rels=t==9999?64:(unsigned)(rnd()%9),cons=t==9999?32:(unsigned)(rnd()%9); 22 for(unsigned j=0;j>8))==ref_omega_canonical_check_header((uint8_t)t,(uint8_t)(t>>8))); 47 for(unsigned t=0;t<16384;t++){ 48 char text[65];memset(text,'a',64);text[64]=0;text[0]=(char)(t&127);text[1]=(char)(t>>7); 49 SemanticId a0,b0;memset(&a0,0xa5,sizeof a0);b0=a0; 50 CHECK(omega_parse_hex_semantic_id(text,&a0)==ref_omega_parse_hex_semantic_id(text,&b0));CHECK(!memcmp(&a0,&b0,sizeof a0)); 51 char ax[65],bx[65];omega_hex_semantic_id(&a0,ax);ref_omega_hex_semantic_id(&b0,bx);CHECK(!memcmp(ax,bx,65)); 52 int cmp=omega_compare_semantic_id(&a0,&b0),ref=ref_omega_compare_semantic_id(&a0,&b0);CHECK((cmp>0)==(ref>0)&&(cmp<0)==(ref<0)); 53 } 54 puts("CORE-UTIL canonical PASS: 10000 objects, all header pairs, 16384 parser pairs");return 0; 55 } 56 static int effects_eval(void){ 57 for(unsigned t=0;t<10000;t++){ 58 EffectPayload p,a,b;uint8_t x[178],y[178];for(unsigned j=0;j>2)&3,ci=(t>>4)&3; 85 memset(x,0xa5,sizeof x);memcpy(y,x,sizeof x); 86 omega_vector_generate_deterministic(x+ai,x+bi,x+ci,16); 87 ref_omega_vector_generate_deterministic(y+ai,y+bi,y+ci,16);CHECK(!memcmp(x,y,sizeof x)); 88 omega_vector_oracle_u32(x+ai,x+bi,x+ci,16); 89 ref_omega_vector_oracle_u32(y+ai,y+bi,y+ci,16);CHECK(!memcmp(x,y,sizeof x)); 90 } 91 puts("CORE-UTIL vector PASS: 10000 cases, chunk and refusal boundaries");return 0; 92 } 93 static int formatting(void){ 94 int (*f)(char*,size_t,const char*,...)=omega_gpu_fmt; 95 int (*r)(char*,size_t,const char*,...)=ref_omega_gpu_fmt; 96 for(unsigned t=0;t<10000;t++){ 97 char a[256],b[256];memset(a,0xa5,sizeof a);memset(b,0xa5,sizeof b);size_t cap=t<257?t:(size_t)(rnd()%257); 98 uint64_t u=rnd();int d=(int)rnd();const char *s=t%3?"Omega formatter":NULL; 99 const char *fmt="%s/%c/%d/%u/%x/%ld/%lu/%lld/%llu/%zu/%%/%q/%llx/%zx"; 100 int x=f(a,cap,fmt,s,'A',d,(unsigned)u,(unsigned)(u>>32),(long)u,(unsigned long)u,(long long)u,(unsigned long long)u,(size_t)u,(unsigned long long)u,(size_t)u); 101 int y=r(b,cap,fmt,s,'A',d,(unsigned)u,(unsigned)(u>>32),(long)u,(unsigned long)u,(long long)u,(unsigned long long)u,(size_t)u,(unsigned long long)u,(size_t)u); 102 CHECK(x==y&&!memcmp(a,b,sizeof a)); 103 } 104 const char *tails[]={"%","%l","%ll","%z","%q","%lll","plain", "%%"}; 105 for(unsigned t=0;t>10)&31,m=h&1023; 136 if(exp==31)return sign|UINT32_C(0x7f800000)|(m<<13); 137 if(!exp){if(!m)return sign;exp=113;while(!(m&1024)){m<<=1;exp--;}return sign|(exp<<23)|((m&1023)<<13);} 138 return sign|((exp+112)<<23)|(m<<13); 139 } 140 static int f16(void){ 141 for(unsigned t=0;t<65536;t++){uint64_t out;uint16_t want=(uint16_t)t;if((t&0x7c00)==0x7c00&&(t&1023))want|=0x200; 142 CHECK(omega_native_f16(&out,widen((uint16_t)t))==0);CHECK(out==want);} 143 puts("CORE-UTIL f16 PASS: all 65536 binary16 inputs, NaNs quieted with payload preserved");return 0; 144 } 145 static int builders(void){ 146 OmegaGraph *a=omega_graph_create(),*b=ref_omega_graph_create();if(!a||!b)return 1; 147 for(unsigned t=0;t<256;t++){ 148 SemanticId id;for(unsigned i=0;i<32;i++)id.bytes[i]=(uint8_t)rnd();OmegaObject *x,*y; 149 switch(t%16){ 150 #define PAIR(name,...) do{x=omega_##name(a,##__VA_ARGS__);y=ref_omega_##name(b,##__VA_ARGS__);}while(0) 151 case 0:PAIR(build_type_unit);break;case 1:PAIR(build_type_bool);break; 152 case 2:PAIR(build_type_uint,(uint16_t)t);break;case 3:PAIR(build_type_signed_int,(uint16_t)t);break; 153 case 4:PAIR(build_type_fp32);break;case 5:PAIR(build_type_bitvector,(uint16_t)t);break; 154 case 6:PAIR(build_type_byte);break;case 7:PAIR(build_type_sequence,&id,t);break; 155 case 8:PAIR(build_type_cap_ref);break;case 9:PAIR(build_val_bool,&id,t%2);break; 156 case 10:PAIR(build_val_uint,&id,(uint16_t)(t*3),state);break;case 11:PAIR(build_op_binary,OP_ADD,OVERFLOW_WRAP,&id);break; 157 case 12:PAIR(build_apply,&id,&id,&id);break;case 13:PAIR(build_param,&id,(uint16_t)t);break; 158 case 14:PAIR(build_effect,1,2,3,state);break;default:PAIR(graph_add_object,KIND_INVALID);break; 159 #undef PAIR 160 } 161 CHECK(x&&y&&!memcmp(x,y,sizeof *x)); 162 OmegaObject *px=omega_graph_find_object(a,&x->id),*py=ref_omega_graph_find_object(b,&y->id); 163 CHECK((px==NULL)==(py==NULL));if(px)CHECK(px-a->objects==py-b->objects); 164 } 165 {unsigned t=256;CHECK(omega_graph_add_object(a,KIND_TYPE)==NULL);CHECK(ref_omega_graph_add_object(b,KIND_TYPE)==NULL);} 166 omega_graph_destroy(a);ref_omega_graph_destroy(b); 167 puts("CORE-UTIL builders PASS: graph full boundary, every constructor and aliasing ID lookup");return 0; 168 } 169 int main(int argc,char **argv){ 170 setvbuf(stdout,NULL,_IONBF,0); 171 if(argc>1&&!strcmp(argv[1],"--hostmath"))return hostmath(); 172 if(argc>1&&!strcmp(argv[1],"--quick"))return canonical()||formatting()||f16(); 173 return canonical()||effects_eval()||vectors()||formatting()||hostmath()||f16()||builders(); 174 }