gpu-head-to-head
aien-dev/gpu-head-to-head
Brought by drakestapleton
gpu-head-to-head / q35-9b / tools / weight-numeric-glue.c
| 1 | /* Verification-only I/O glue. Every arithmetic operation calls existing |
| 2 | * seeded-Omega kernels from ggml-omega e0813903. No model or GPU is opened. */ |
| 3 | #include <stdint.h> |
| 4 | #include <stdio.h> |
| 5 | #include <string.h> |
| 6 | #if __BYTE_ORDER__ != __ORDER_LITTLE_ENDIAN__ |
| 7 | #error little-endian verification target required |
| 8 | #endif |
| 9 | uint32_t omega_bin_32(uint64_t *,uint64_t,const void *,uint64_t,const void *,uint64_t,void *,uint64_t); |
| 10 | uint32_t omega_bin_1(uint64_t *,uint64_t,const void *,uint64_t,const void *,uint64_t,void *,uint64_t); |
| 11 | uint32_t omega_sexp_32(uint64_t *,uint64_t,void *,uint64_t,uint64_t); |
| 12 | uint32_t omega_sexp_1(uint64_t *,uint64_t,void *,uint64_t,uint64_t); |
| 13 | int main(int argc,char **argv) { |
| 14 | _Static_assert(sizeof(float)==4,"requires float32"); |
| 15 | if(argc!=2 || (strcmp(argv[1],"plus1") && strcmp(argv[1],"negexp")))return 2; |
| 16 | unsigned char raw[65536]; |
| 17 | size_t bytes=fread(raw,1,sizeof raw,stdin); |
| 18 | if(ferror(stdin)||!feof(stdin)||!bytes||bytes%4)return 2; |
| 19 | float data[16384],out[16384],ones[32];memcpy(data,raw,bytes); |
| 20 | for(size_t j=0;j<32;j++)ones[j]=1.0f; |
| 21 | const size_t n=bytes/4;size_t i=0;uint64_t r=0;uint32_t status; |
| 22 | while(i<n){const size_t lanes=n-i>=32?32:1; |
| 23 | if(!strcmp(argv[1],"plus1")) { |
| 24 | status=lanes==32?omega_bin_32(&r,0,data+i,32,ones,32,out+i,32):omega_bin_1(&r,0,data+i,1,ones,1,out+i,1); |
| 25 | } else { |
| 26 | status=lanes==32?omega_sexp_32(&r,0,data+i,32,0):omega_sexp_1(&r,0,data+i,1,0); |
| 27 | for(size_t j=0;j<lanes;j++){uint32_t u;memcpy(&u,data+i+j,4);u^=UINT32_C(0x80000000);memcpy(out+i+j,&u,4);} |
| 28 | } |
| 29 | if(status)return 3; |
| 30 | i+=lanes; |
| 31 | } |
| 32 | return fwrite(out,1,bytes,stdout)==bytes?0:4; |
| 33 | } |