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 / gpu_attn_any_predicate.c
| 1 | /* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */ |
| 2 | #include "omega_blackwell_codegen.h" |
| 3 | #include "bw_warp_sim_k.h" |
| 4 | #include <stdio.h> |
| 5 | #include <stdlib.h> |
| 6 | #include <string.h> |
| 7 | static void put64(uint32_t *p,uint64_t n) { memcpy(p,&n,sizeof n); } |
| 8 | static void add(BlackwellIRProgram *p, BlackwellIROpcode op, int d, int a, int b, int c, uint32_t imm, int guard) { |
| 9 | BlackwellIRInsn in={.op=op,.dst_vreg=d,.src1_vreg=a,.src2_vreg=b,.src3_vreg=c,.ureg=-1,.imm=imm, |
| 10 | .predicate_p0=guard!=0,.predicate_not=guard==2}; |
| 11 | if(omega_bw_ir_append(p,&in)<0) abort(); |
| 12 | } |
| 13 | static void setup(BlackwellIRProgram *p) { |
| 14 | omega_bw_ir_init(p); |
| 15 | for(int i=0;i<6;i++) if((i==1||i==2?omega_bw_ir_alloc_vreg64(p):omega_bw_ir_alloc_vreg(p))!=i) abort(); |
| 16 | add(p,BW_IR_S2R,0,-1,-1,-1,BW_SR_TID_X,0); |
| 17 | add(p,BW_IR_LDC64,1,-1,-1,-1,896,0); |
| 18 | add(p,BW_IR_IMAD_WIDE,2,0,-1,1,4,0); |
| 19 | add(p,BW_IR_MOV_IMM,3,-1,-1,-1,1,0); |
| 20 | add(p,BW_IR_ISETP_GE_U32,-1,0,3,-1,0,0); |
| 21 | } |
| 22 | static int memory_case(int store,int guard) { |
| 23 | BlackwellIRProgram *p=malloc(sizeof *p); if(!p) abort(); setup(p); |
| 24 | add(p,BW_IR_MOV_IMM,4,-1,-1,-1,123,0); |
| 25 | add(p,store?BW_IR_STG_E:BW_IR_LDG_E,store?-1:4,2,store?4:-1,-1,0,guard); |
| 26 | add(p,BW_IR_EXIT,-1,-1,-1,-1,0,0); |
| 27 | if(omega_bw_regalloc_solve(p)) abort(); |
| 28 | uint32_t word=7; WsSim s={0};s.p=p;s.threads=32;s.nranges=1; |
| 29 | s.ranges[0]=(WsRange){(uintptr_t)&word,(uintptr_t)&word+4};put64(&s.cbank[896/4],(uintptr_t)&word); |
| 30 | int rc=ws_run(&s,1,1); |
| 31 | int okay=guard?(rc==0 && word==(store?123u:7u)):(rc!=0 && s.err==WS_E_MEM); |
| 32 | free(p);return okay; |
| 33 | } |
| 34 | static int shuffle_case(int guard) { |
| 35 | BlackwellIRProgram *p=malloc(sizeof *p);if(!p)abort();setup(p); |
| 36 | add(p,BW_IR_MOV_IMM,4,-1,-1,-1,0xa5,0); |
| 37 | add(p,BW_IR_SHFL_BFLY,4,0,-1,-1,1,guard); |
| 38 | add(p,BW_IR_STG_E,-1,2,4,-1,0,0); |
| 39 | add(p,BW_IR_EXIT,-1,-1,-1,-1,0,0); |
| 40 | if(omega_bw_regalloc_solve(p))abort(); |
| 41 | uint32_t out[32]={0};WsSim s={0};s.p=p;s.threads=32;s.nranges=1; |
| 42 | s.ranges[0]=(WsRange){(uintptr_t)out,(uintptr_t)(out+32)};put64(&s.cbank[896/4],(uintptr_t)out); |
| 43 | int okay=ws_run(&s,1,1)==0; |
| 44 | for(unsigned i=0;i<32;i++) { |
| 45 | int executes=guard==2?i==0:i!=0; |
| 46 | if(out[i]!=(executes?(i^1u):0xa5u))okay=0; |
| 47 | } |
| 48 | free(p);return okay; |
| 49 | } |
| 50 | int main(void) { |
| 51 | int okay=memory_case(0,2)&memory_case(1,2)&memory_case(0,0)&memory_case(1,0)&shuffle_case(1)&shuffle_case(2); |
| 52 | puts(okay?"warp-sim predicates: PASS (masked LDG/ST, unmasked negatives, guarded SHFL)":"warp-sim predicates: FAIL"); |
| 53 | return !okay; |
| 54 | } |