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 / runtime / artifact_fixture_diff.c
| 1 | /* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */ |
| 2 | #include "omega_native_artifact.h" |
| 3 | #include "omega_native_artifact_snapshot.h" |
| 4 | #include <stdio.h> |
| 5 | #include <stdlib.h> |
| 6 | #include <string.h> |
| 7 | #include <unistd.h> |
| 8 | #include <sys/stat.h> |
| 9 | #include <fcntl.h> |
| 10 | int artifact_c_export(const OmegaNativeArtifact *, const char *, char *, char *, size_t); |
| 11 | int artifact_c_admit(const char *, const char *, char *, char *, size_t); |
| 12 | int artifact_c_snapshot(const char *, const char *, char *, OmegaNativeArtifactSnapshot *, char *, size_t); |
| 13 | void artifact_c_snapshot_free(OmegaNativeArtifactSnapshot *); |
| 14 | static const char *const suffix[]={".manifest",".text.bin",".cubin",".qmd0.bin",".qmd1.bin",".cbank_args.bin",".json",".sha256"}; |
| 15 | static void fail(const char *what,int om,int c) { fprintf(stderr,"ARTIFACT differential FAIL %s om=%d c=%d\n",what,om,c); exit(90); } |
| 16 | static unsigned char *load(const char *p,size_t *n) { |
| 17 | FILE *f=fopen(p,"rb"); if(!f)return NULL; |
| 18 | if(fseek(f,0,SEEK_END))exit(91); |
| 19 | long z=ftell(f); |
| 20 | if(z<0 || fseek(f,0,SEEK_SET))exit(91); |
| 21 | unsigned char *b=malloc((size_t)z+1); if(!b)exit(91); |
| 22 | if(fread(b,1,(size_t)z,f)!=(size_t)z || fclose(f))exit(91); |
| 23 | *n=(size_t)z; |
| 24 | return b; |
| 25 | } |
| 26 | int artifact_diff_export(const OmegaNativeArtifact *a,const char *p,char *id,char *err,size_t cap) { |
| 27 | char alt[2048],x[2200],y[2200],cid[65],ce[256]; |
| 28 | const char *cp=p; |
| 29 | if(p && strlen(p)<sizeof alt) { strcpy(alt,p); size_t z=strlen(alt); if(z)alt[z-1]='~'; cp=alt; |
| 30 | for(unsigned i=0;i<8;++i) {snprintf(x,sizeof x,"%s%s",p,suffix[i]);snprintf(y,sizeof y,"%s%s",cp,suffix[i]);unlink(y); |
| 31 | struct stat st; if(lstat(x,&st)==0) {int fd=open(y,O_WRONLY|O_CREAT|O_TRUNC|O_CLOEXEC,0600);if(fd<0)exit(91);close(fd);} |
| 32 | } |
| 33 | } |
| 34 | int c=artifact_c_export(a,cp,id?cid:NULL,ce,sizeof ce); |
| 35 | int om=omega_native_artifact_export(a,p,id,err,cap); |
| 36 | if(c!=om)fail("export rc",om,c); |
| 37 | if(!om) { |
| 38 | if(strcmp(cid,id))fail("id",1,0); |
| 39 | for(unsigned i=0;i<8;++i) {size_t nx=0,ny=0;snprintf(x,sizeof x,"%s%s",p,suffix[i]);snprintf(y,sizeof y,"%s%s",cp,suffix[i]); |
| 40 | unsigned char *bx=load(x,&nx),*by=load(y,&ny); |
| 41 | if(!bx||!by||nx!=ny||memcmp(bx,by,nx))fail(suffix[i],1,0); |
| 42 | free(bx);free(by); |
| 43 | } |
| 44 | } |
| 45 | if(cp==alt)for(unsigned i=0;i<8;++i){snprintf(y,sizeof y,"%s%s",cp,suffix[i]);unlink(y);} |
| 46 | return om; |
| 47 | } |
| 48 | int artifact_diff_admit(const char *p,const char *d,char *id,char *err,size_t cap) { |
| 49 | char cid[65],ce[256];int c=artifact_c_admit(p,d,id?cid:NULL,ce,sizeof ce); |
| 50 | int om=omega_native_artifact_admit(p,d,id,err,cap); |
| 51 | if(c!=om)fail("admit rc",om,c); |
| 52 | if(id&&strcmp(cid,id))fail("admit id",1,0); |
| 53 | return om; |
| 54 | } |
| 55 | int artifact_diff_snapshot(const char *p,const char *d,char *id,OmegaNativeArtifactSnapshot *out,char *err,size_t cap) { |
| 56 | char cid[65],ce[256];OmegaNativeArtifactSnapshot cs={0}; |
| 57 | int c=artifact_c_snapshot(p,d,id?cid:NULL,out?&cs:NULL,ce,sizeof ce); |
| 58 | int om=omega_native_artifact_snapshot(p,d,id,out,err,cap); |
| 59 | if(c!=om)fail("snapshot rc",om,c); |
| 60 | if(id&&strcmp(cid,id))fail("snapshot id",1,0); |
| 61 | if(!om)for(unsigned i=0;i<6;++i)if(cs.sizes[i]!=out->sizes[i]||memcmp(cs.bytes[i],out->bytes[i],cs.sizes[i]))fail("snapshot bytes",1,0); |
| 62 | artifact_c_snapshot_free(&cs);return om; |
| 63 | } |