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 / om / standalone-oracles / host-cuda.c
| 1 | /* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */ |
| 2 | /* Verification-only CPU transport, never a replacement libcuda or runtime. |
| 3 | * Its independent C arithmetic is intentional: it supplies corruptible results |
| 4 | * to the actual fixture checkers without loading any driver or opening devices. */ |
| 5 | #include <cuda.h> |
| 6 | #include <stdint.h> |
| 7 | #include <stdlib.h> |
| 8 | #include <string.h> |
| 9 | #include "omega_blackwell_matmul.h" |
| 10 | static int vadd; |
| 11 | CUresult CUDAAPI cuInit(unsigned x) {(void)x;return CUDA_SUCCESS;} |
| 12 | CUresult CUDAAPI cuDeviceGet(CUdevice *d,int x) {*d=x;return CUDA_SUCCESS;} |
| 13 | CUresult CUDAAPI cuCtxCreate(CUcontext *p,CUctxCreateParams *params,unsigned flags,CUdevice d) {(void)params;(void)flags;(void)d;*p=(CUcontext)(uintptr_t)1;return CUDA_SUCCESS;} |
| 14 | CUresult CUDAAPI cuCtxDestroy(CUcontext p) {(void)p;return CUDA_SUCCESS;} |
| 15 | CUresult CUDAAPI cuCtxSynchronize(void) {return CUDA_SUCCESS;} |
| 16 | CUresult CUDAAPI cuModuleLoadData(CUmodule *p,const void *b) {(void)b;*p=(CUmodule)(uintptr_t)1;return CUDA_SUCCESS;} |
| 17 | CUresult CUDAAPI cuModuleLoadDataEx(CUmodule *p,const void *b,unsigned n,CUjit_option *o,void **v) {(void)n;(void)o;(void)v;return cuModuleLoadData(p,b);} |
| 18 | CUresult CUDAAPI cuModuleGetFunction(CUfunction *p,CUmodule m,const char *s) {(void)m;vadd=!strcmp(s,"vadd_u32");*p=(CUfunction)(uintptr_t)1;return CUDA_SUCCESS;} |
| 19 | CUresult CUDAAPI cuModuleUnload(CUmodule p) {(void)p;return CUDA_SUCCESS;} |
| 20 | CUresult CUDAAPI cuMemAlloc(CUdeviceptr *p,size_t n) {*p=(CUdeviceptr)(uintptr_t)malloc(n);return *p?CUDA_SUCCESS:CUDA_ERROR_OUT_OF_MEMORY;} |
| 21 | CUresult CUDAAPI cuMemFree(CUdeviceptr p) {free((void *)(uintptr_t)p);return CUDA_SUCCESS;} |
| 22 | CUresult CUDAAPI cuMemcpyHtoD(CUdeviceptr p,const void *b,size_t n) {memcpy((void *)(uintptr_t)p,b,n);return CUDA_SUCCESS;} |
| 23 | CUresult CUDAAPI cuMemcpyDtoH(void *b,CUdeviceptr p,size_t n) {memcpy(b,(void *)(uintptr_t)p,n);return CUDA_SUCCESS;} |
| 24 | CUresult CUDAAPI cuMemsetD32(CUdeviceptr p,unsigned value,size_t n) {uint32_t *b=(void *)(uintptr_t)p;for(size_t i=0;i<n;i++)b[i]=value;return CUDA_SUCCESS;} |
| 25 | CUresult CUDAAPI cuGetErrorString(CUresult r,const char **s) {(void)r;*s="host CPU transport";return CUDA_SUCCESS;} |
| 26 | CUresult CUDAAPI cuLaunchKernel(CUfunction f,unsigned gx,unsigned gy,unsigned gz,unsigned tx,unsigned ty,unsigned tz,unsigned shared,CUstream stream,void **a,void **extra) { |
| 27 | (void)f;(void)gx;(void)gy;(void)gz;(void)tx;(void)ty;(void)tz;(void)shared;(void)stream;(void)extra; |
| 28 | const void *left=(void *)(uintptr_t)*(CUdeviceptr *)a[0],*right=(void *)(uintptr_t)*(CUdeviceptr *)a[1]; |
| 29 | void *out=(void *)(uintptr_t)*(CUdeviceptr *)a[2]; |
| 30 | if(vadd) { |
| 31 | const uint32_t *x=left,*y=right;uint32_t *z=out,n=*(uint32_t *)a[3]; |
| 32 | for(uint32_t i=0;i<n;i++)z[i]=x[i]+y[i]; |
| 33 | if(getenv("SO_HOST_RED"))z[0]^=1; |
| 34 | } else { |
| 35 | unsigned m=(unsigned)strtoul(getenv("SO_HOST_M"),NULL,0),k=(unsigned)strtoul(getenv("SO_HOST_K"),NULL,0),n=(unsigned)strtoul(getenv("SO_HOST_N"),NULL,0); |
| 36 | omega_matmul_cpu_oracle_bf16(left,right,out,m,k,n); |
| 37 | if(getenv("SO_HOST_RED"))((float *)out)[0]+=1.0f; |
| 38 | } |
| 39 | return CUDA_SUCCESS; |
| 40 | } |