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 / regalloc_om / checkers.c
| 1 | /* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */ |
| 2 | /* Compile twice: default Omega wrappers and C_EM/C_RECONV reference. The append |
| 3 | * double injects success/failure after the pure state change, with no device. */ |
| 4 | #include "omega_bw_em.h" |
| 5 | #include "omega_bw_em_q.h" |
| 6 | #include "omega_bw_reconv.h" |
| 7 | #include <limits.h> |
| 8 | #include <stdio.h> |
| 9 | #include <stdlib.h> |
| 10 | static BlackwellIRProgram p; |
| 11 | static int fail_append; |
| 12 | #define ins (p.insns) |
| 13 | int omega_bw_ir_append(BlackwellIRProgram *prog, const BlackwellIRInsn *in) { |
| 14 | if (fail_append) return -1; |
| 15 | if (prog->count >= 64) abort(); |
| 16 | ins[prog->count++] = *in; |
| 17 | return 0; |
| 18 | } |
| 19 | int omega_bw_ir_alloc_vreg(BlackwellIRProgram *q) { (void)q; return fail_append ? -1 : 0; } |
| 20 | int omega_bw_ir_alloc_vreg64(BlackwellIRProgram *q) { (void)q; return fail_append ? -1 : 0; } |
| 21 | int omega_bw_ir_alloc_vreg128(BlackwellIRProgram *q) { (void)q; return fail_append ? -1 : 0; } |
| 22 | int omega_bw_ir_alloc_uvreg64(BlackwellIRProgram *q) { (void)q; return fail_append ? -1 : 0; } |
| 23 | static void reset(void) { memset(&p, 0, sizeof p); } |
| 24 | static void emout(const Em *e) { |
| 25 | printf("e %u %u %d %d %zu", e->pending, e->held, e->err, e->depth, p.count); |
| 26 | for (int d=0;d<MAX_LOOPS;d++) printf(" %d",e->open_start[d]); |
| 27 | for (size_t j=0;j<p.count;j++) printf(" %u:%u:%u", ins[j].control, ins[j].imm, ins[j].op); |
| 28 | puts(""); |
| 29 | } |
| 30 | static void rout(int rc, const BwRegions *r) { |
| 31 | printf("r %d %d %d %d",rc,r->depth,r->peak,r->opened); |
| 32 | for(int d=0;d<BW_RECONV_MAX_DEPTH;d++) { |
| 33 | printf(" %d:%d",r->bssy_at[d],r->n_exits[d]); |
| 34 | for(int j=0;j<BW_RECONV_MAX_EXITS;j++) printf(":%d",r->exits[d][j]); |
| 35 | } |
| 36 | for(int j=0;j<8;j++) printf(" %u",ins[j].imm); |
| 37 | puts(""); |
| 38 | } |
| 39 | static void emcases(void) { |
| 40 | const uint32_t bits[]={0,1,2,3,4,63,64,UINT32_MAX}; |
| 41 | for(unsigned j=0;j<sizeof bits/sizeof bits[0];j++) |
| 42 | for(int k=-1;k<=11;k++) for(int pred=0;pred<2;pred++) for(int fail=0;fail<2;fail++) { |
| 43 | reset(); Em e={.p=&p,.pending=bits[j],.held=bits[j]}; fail_append=fail; |
| 44 | BlackwellIRInsn in=I0(BW_IR_NOP); in.predicate_p0=pred; emit(&e,in,k); emout(&e); |
| 45 | } |
| 46 | for(unsigned j=0;j<sizeof bits/sizeof bits[0];j++) for(unsigned sb=0;sb<32;sb++) for(int fail=0;fail<2;fail++) { |
| 47 | reset(); Em e={.p=&p,.pending=bits[j],.held=~bits[j]}; fail_append=fail; |
| 48 | ldw_pf(&e,BW_IR_LDG_E,1,2,3,4,sb); emout(&e); consume(&e,sb); emout(&e); |
| 49 | } |
| 50 | for(unsigned j=0;j<sizeof bits/sizeof bits[0];j++) for(int fail=0;fail<2;fail++) { |
| 51 | reset(); Em e={.p=&p,.pending=bits[j]}; fail_append=fail; |
| 52 | hmma(&e,1,2,3,4,bits[j]); nop(&e,bits[j]); qmma_s(&e,1,2,3,1,4,bits[j]); |
| 53 | qmma(&e,1,2,3,4,bits[j]); f2e4(&e,1,2,1,3,0); emout(&e); |
| 54 | } |
| 55 | for (int fail=0;fail<2;fail++) { |
| 56 | reset(); Em e={.p=&p}; fail_append=fail; |
| 57 | printf("alloc %d %d %d %d\n",V(&e),V64(&e),V128(&e),UV64(&e)); |
| 58 | ldcu64(&e,1,2); ldc64(&e,1,2); ldc32(&e,1,2); s2r(&e,1,2); |
| 59 | movi(&e,1,2); movrz(&e,1); imadi(&e,1,2,0,3,4); imadr(&e,1,2,3,4); |
| 60 | imadw(&e,1,2,3,4); shr(&e,1,2,0,3); andi(&e,1,2,0,3); |
| 61 | ldg_wide(&e,BW_IR_LDG_E,1,2,3,4,0); ldg_wide(&e,BW_IR_LDG_E,1,2,3,4,1); |
| 62 | ldg32(&e,1,2,3,0); ldg32(&e,1,2,3,1); stg(&e,1,2,3,4); |
| 63 | lds128(&e,1,2,3,0); lds128(&e,1,2,3,1); sts32(&e,1,2); bar_sync(&e); |
| 64 | fadd(&e,1,2,3); ffma(&e,1,2,3,0,4); shfl_down(&e,1,2,3); isetp_ge_u32(&e,1,2); |
| 65 | lop3(&e,1,2,3,4,255); iadd(&e,1,2,3); shfl_bfly(&e,1,2,63); f2fp_pack(&e,1,2,3); |
| 66 | bra_if_p0(&e,1); bra(&e,1); (void)bra_if_p0_fwd(&e); |
| 67 | patch_bra(&e,0,3); (void)bssy_fwd(&e); bsync(&e); tail(&e); emout(&e); |
| 68 | } |
| 69 | fail_append=0; |
| 70 | for(int d=0;d<=5;d++) { reset(); Em e={.p=&p,.depth=d}; loop_begin(&e); emout(&e); } |
| 71 | for(int d=-1;d<=4;d++) for(int first=-1;first<=4;first++) for(int last=-1;last<=4;last++) { |
| 72 | reset(); p.count=4; p.regalloc.num_vregs=1; |
| 73 | p.regalloc.intervals[0].first_def=first; p.regalloc.intervals[0].last_use=last; |
| 74 | Em e={.p=&p,.depth=d,.open_start={1,1,1,1}}; loop_end(&e); emout(&e); |
| 75 | printf("iv %d\n",p.regalloc.intervals[0].last_use); |
| 76 | } |
| 77 | /* Include the full uint32 domain above the last representable power of two. */ |
| 78 | const uint32_t logs[]={0,1,2,3,4,7,8,9,0x7fffffff,0x80000000,0x80000001,UINT32_MAX}; |
| 79 | for(unsigned j=0;j<sizeof logs/sizeof logs[0];j++) printf("l %d\n",log2u(logs[j])); |
| 80 | } |
| 81 | static void rcases(void) { |
| 82 | const int ix[]={-1,0,1,INT_MAX}; |
| 83 | for(int d=0;d<=17;d++) for(unsigned j=0;j<sizeof ix/sizeof ix[0];j++) { |
| 84 | BwRegions r={.depth=d,.peak=j%2 ? 16 : (d?d-1:0),.opened=2}; reset(); |
| 85 | printf("n %d\n",bw_regions_next_bar(&r)); |
| 86 | rout(bw_regions_begin(&r,ix[j]),&r); |
| 87 | } |
| 88 | for(int d=-1;d<=1;d++) for(int n=0;n<=9;n++) for(unsigned j=0;j<sizeof ix/sizeof ix[0];j++) { |
| 89 | BwRegions r={.depth=d}; r.n_exits[0]=n; reset(); rout(bw_regions_exit(&r,ix[j]),&r); |
| 90 | } |
| 91 | for(int mode=0;mode<22;mode++) { |
| 92 | reset(); p.count=8; BwRegions r={.depth=1,.n_exits={2},.bssy_at={1},.exits={{2,3}}}; |
| 93 | ins[1].op=BW_IR_BSSY; ins[4].op=BW_IR_BSYNC; ins[2].op=ins[3].op=BW_IR_BRA; |
| 94 | for(int j=0;j<8;j++) ins[j].imm=0xfeed; |
| 95 | int bs=4; BlackwellIRProgram *q=&p; |
| 96 | switch(mode) { |
| 97 | case 0:r.depth=0;break; case 1:q=NULL;break; case 2:bs=-1;break; case 3:bs=8;break; |
| 98 | case 4:r.bssy_at[0]=-1;break; case 5:r.bssy_at[0]=4;break; case 6:ins[1].op=BW_IR_BRA;break; |
| 99 | case 7:ins[4].op=BW_IR_BRA;break; case 8:ins[1].bar_reg=1;break; case 9:ins[4].bar_reg=1;break; |
| 100 | case 10:r.exits[0][0]=1;break; case 11:r.exits[0][0]=4;break; case 12:ins[2].op=BW_IR_NOP;break; |
| 101 | case 13:r.exits[0][1]=1;break; case 14:r.exits[0][1]=4;break; case 15:ins[3].op=BW_IR_NOP;break; |
| 102 | case 16:r.n_exits[0]=0;break; case 17:p.count=SIZE_MAX;break; |
| 103 | case 18:r.depth=-1;break; case 19:bs=INT_MAX;break; case 20:r.bssy_at[0]=INT_MAX;break; |
| 104 | default:break; |
| 105 | } |
| 106 | rout(bw_regions_join(&r,q,bs),&r); |
| 107 | } |
| 108 | BwRegions r={.depth=INT_MIN}; printf("n %d\n",bw_regions_next_bar(&r)); |
| 109 | r.depth=INT_MAX; printf("n %d\n",bw_regions_next_bar(&r)); |
| 110 | } |
| 111 | int main(int argc,char **argv) { |
| 112 | if(argc>1 && strcmp(argv[1],"--log-overflow")==0) { |
| 113 | printf("log-overflow %d\n", log2u(UINT32_MAX)); return 0; |
| 114 | } |
| 115 | (void)argv; emcases(); rcases(); |
| 116 | if(argc>1) puts("red-control"); |
| 117 | puts("CHECKERS source partition complete"); return 0; |
| 118 | } |