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 / chip_enum_diff.c
| 1 | /* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */ |
| 2 | #include "omega_chip_enum.h" |
| 3 | #include <stdio.h> |
| 4 | #include <string.h> |
| 5 | uint64_t oracle_enum(uint64_t,uint64_t,uint64_t,uint64_t,uint64_t); |
| 6 | static unsigned cases; |
| 7 | static int plant; |
| 8 | static void check(uint64_t m,uint64_t a,uint64_t b,uint64_t c,uint64_t d) { |
| 9 | uint64_t want=oracle_enum(m,a,b,c,d), got=omega_chip_enum_decide(m,a,b,c,d); |
| 10 | if (plant && !cases) got ^= 1; |
| 11 | if (got != want) { fprintf(stderr,"enum mismatch mode=%lu a=%lu b=%lu\n",m,a,b); exit(1); } |
| 12 | ++cases; |
| 13 | } |
| 14 | int main(int argc,char **argv) { |
| 15 | if (argc > 2 && !strcmp(argv[1],"--scan")) { |
| 16 | OmegaGpuPciDev rows[1024]; |
| 17 | for (int cap=-1;cap<=3;cap++) { |
| 18 | memset(rows,0xa5,sizeof rows); |
| 19 | int n=omega_gpu_chip_scan(argv[2],rows,cap); |
| 20 | printf("cap=%d n=%d\n",cap,n); |
| 21 | for(int i=0;i<n && i<cap;i++) printf("%s %x %x %x\n",rows[i].bdf,rows[i].vendor,rows[i].device,rows[i].class_code); |
| 22 | if(cap<=0 && rows[0].vendor != 0xa5a5) return 3; |
| 23 | } |
| 24 | printf("null=%d\n",omega_gpu_chip_scan(argv[2],NULL,1024)); |
| 25 | int n=omega_gpu_chip_scan(argv[2],rows,1024); |
| 26 | for(int i=0;i<n;i++) printf("%s %x %x %x\n",rows[i].bdf,rows[i].vendor,rows[i].device,rows[i].class_code); |
| 27 | return 0; |
| 28 | } |
| 29 | plant=argc>1; |
| 30 | const uint64_t masks[]={0xffff,0xff,0x1f,7}; |
| 31 | for(uint64_t v=0;v<=0xffff;v++) { |
| 32 | check(0,v,0x2e12,0x10de,0x2e12); |
| 33 | check(0,0x10de,v,0x10de,0x2e12); |
| 34 | check(1,v,0,0,0); |
| 35 | if (!!omega_gpu_chip_find(v,0x2e12) != (v==0x10de)) return 4; |
| 36 | if (!!omega_gpu_chip_find(0x10de,v) != (v==0x2e12)) return 5; |
| 37 | for(unsigned m=0;m<4;m++) check(3,v,masks[m],0,0); |
| 38 | } |
| 39 | const uint64_t edges[]={0,1,6,7,8,30,31,32,254,255,256,65534,65535,65536,UINT32_MAX-1,UINT32_MAX,UINT64_MAX}; |
| 40 | for(unsigned i=0;i<sizeof edges/sizeof edges[0];i++) { |
| 41 | uint64_t a=edges[i]; |
| 42 | check(1,a,0,0,0); check(2,a,0,0,0); |
| 43 | for(unsigned m=0;m<4;m++) check(3,a,masks[m],0,0); |
| 44 | for(unsigned j=0;j<sizeof edges/sizeof edges[0];j++) { |
| 45 | uint64_t b=edges[j]; |
| 46 | check(4,a,b,0,0);check(4,a,b,1,0); |
| 47 | char why[512],bdf[64];uint32_t sm=123; |
| 48 | snprintf(bdf,sizeof bdf,"%04x:%02x:%02x.%x",(unsigned)a&0xffffu,(unsigned)b&0xffu,(unsigned)a&0x1fu,(unsigned)b&7u); |
| 49 | if(omega_gpu_chip_admit_card(a,b,a,b,0,0,&sm,why,sizeof why)!=-1 || sm || !strstr(why,bdf)) return 6; |
| 50 | } |
| 51 | } |
| 52 | for(uint64_t cls=0;cls<256;cls++) { |
| 53 | check(2,cls<<16,0,0,0);check(2,(cls<<16)|1,0,0,0);check(2,(cls<<16)|0xffff,0,0,0); |
| 54 | check(2,(UINT64_C(1)<<32)|(cls<<16),0,0,0); |
| 55 | check(5,cls,0,0,0); |
| 56 | } |
| 57 | uint32_t sm=0;char why[512]={0}; |
| 58 | if(omega_gpu_chip_admit_card(0,0,0,0,0x10de,0x2e12,&sm,why,sizeof why) || sm!=121) return 7; |
| 59 | printf("CHIP ENUM DIFFERENTIAL PASS cases=%u\n",cases);return 0; |
| 60 | } |