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 / cmdlist_shell_test.c
| 1 | /* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */ |
| 2 | /* Exercise the real shell's record/plan/emit path without opening a device. |
| 3 | * The existing Streams C oracle compares every generated method word. */ |
| 4 | #define CUDAPP_MIGRATION_PENDING_STREAMS_DIFF 1 |
| 5 | #include "../src/omega_gpu_cmdlist.c" |
| 6 | #include <stdio.h> |
| 7 | #include <stdlib.h> |
| 8 | void cudapp_streams_diff_note(int same,const char *line) { if(!same) { fprintf(stderr,"FAIL %s\n",line);abort(); } } |
| 9 | static uint64_t random_state=123456789; |
| 10 | static unsigned random_word(void) { random_state^=random_state<<13;random_state^=random_state>>7;random_state^=random_state<<17;return (unsigned)random_state; } |
| 11 | int main(void) { |
| 12 | OmegaGpuCmdList cl={0};cl.cap=32;cl.words_cap=16384; |
| 13 | cl.gen=omega_gpu_session_recoveries();cl.epoch=omega_gpu_session_epoch();cl.record_generation=1; |
| 14 | cl.banks.cpu=calloc(cl.cap,1024);cl.banks.va=0x10000000; |
| 15 | cl.qmds.cpu=calloc(cl.cap,1024);cl.qmds.va=0x20000000; |
| 16 | cl.sems.cpu=calloc(cl.cap,16);cl.sems.va=0x30000000; |
| 17 | cl.stamps.va=0x40000000;cl.scratch.va=0x50000000; |
| 18 | cl.words=calloc(cl.words_cap,4);cl.native=calloc(cl.cap,sizeof *cl.native); |
| 19 | cl.indep=calloc(cl.cap,1);cl.wait_va=calloc(cl.cap,sizeof *cl.wait_va); |
| 20 | if(!cl.banks.cpu||!cl.qmds.cpu||!cl.sems.cpu||!cl.words||!cl.native||!cl.indep||!cl.wait_va) return 2; |
| 21 | for(unsigned t=0;t<2000;t++) { |
| 22 | omega_gpu_cmdlist_reset(&cl);unsigned n=random_word()%33; |
| 23 | for(unsigned i=0;i<n;i++) { |
| 24 | uint32_t args[32];for(unsigned j=0;j<32;j++) args[j]=random_word(); |
| 25 | OmegaGpuLaunch l={.code_va=0x60000000,.args=args,.n_args=1+random_word()%32, |
| 26 | .threads_x=128,.threads_y=1,.grid_x=1+random_word()%32,.grid_y=1, |
| 27 | .gpr_count=64,.shared_bytes=random_word()%32769}; |
| 28 | OmegaGpuCmdListAccess a[2]={{4096+64*(random_word()%16),64,1},{4096+64*(random_word()%16),64,2}}; |
| 29 | if(t&1) { |
| 30 | if(omega_gpu_cmdlist_add(&cl,&l)!=(int)i) return 1; |
| 31 | uint32_t bank[256],qmd[256]; |
| 32 | memcpy(bank,(uint8_t *)cl.banks.cpu+i*1024,sizeof bank); |
| 33 | memcpy(qmd,(uint8_t *)cl.qmds.cpu+i*1024,sizeof qmd); |
| 34 | if(omega_gpu_cmdlist_set_accesses(&cl,i,a,2)) return 1; |
| 35 | if(memcmp(bank,(uint8_t *)cl.banks.cpu+i*1024,sizeof bank)|| |
| 36 | memcmp(qmd,(uint8_t *)cl.qmds.cpu+i*1024,sizeof qmd)) return 1; |
| 37 | uint64_t saved[CMDLIST_DESCRIPTOR_WORDS]; |
| 38 | memcpy(saved,cl.program+i*CMDLIST_DESCRIPTOR_WORDS,sizeof saved); |
| 39 | OmegaGpuCmdListAccess bad={1,0,1}; |
| 40 | if(omega_gpu_cmdlist_set_accesses(&cl,i,&bad,1)==0|| |
| 41 | memcmp(saved,cl.program+i*CMDLIST_DESCRIPTOR_WORDS,sizeof saved)) return 1; |
| 42 | } else if(omega_gpu_cmdlist_add_accesses(&cl,&l,a,2)!=(int)i) return 1; |
| 43 | } |
| 44 | OmegaGpuCmdListOpts o={.mode=t&1,.stamps=(t>>1)&1};OmegaGpuCmdListProgramPlan p; |
| 45 | if(omega_gpu_cmdlist_plan_program(&cl,&o,&p)) return 1; |
| 46 | if(n) { |
| 47 | prepare_qmd_mode(&cl,&o);cl.program_active=1; |
| 48 | size_t words=emit_chunk(&cl,&o,0,n,0x70000000);cl.program_active=0; |
| 49 | if(words!=p.words) { fprintf(stderr,"FAIL emitted words %zu != plan %u\n",words,p.words);return 1; } |
| 50 | } else { |
| 51 | OmegaGpuCmdListStats stats; |
| 52 | if(p.words||p.waits||p.submissions||omega_gpu_cmdlist_submit_program(&cl,&o,&stats)|| |
| 53 | stats.submits||stats.first_missing!=-1) return 1; |
| 54 | } |
| 55 | o.first_barrier_none=1; |
| 56 | if(omega_gpu_cmdlist_plan_program(&cl,&o,&p)==0) return 1; |
| 57 | } |
| 58 | free(cl.program);free(cl.barriers);free(cl.banks.cpu);free(cl.qmds.cpu);free(cl.sems.cpu); |
| 59 | free(cl.words);free(cl.native);free(cl.indep);free(cl.wait_va); |
| 60 | puts("PASS real command-list shell: 2000 record/plan/emit programs, PCAS/INLINE/stamps, exact C method differential; no device opened"); |
| 61 | return 0; |
| 62 | } |