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 / src / omega_gpu_dnn_rows_api.c
| 1 | /* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */ |
| 2 | /* Memory/session shell only; admission, byte layout and computation are Omega. */ |
| 3 | #include "omega_gpu_dnn_rows_api.h" |
| 4 | #include "omega_gpu_om_ir.h" |
| 5 | #include "omega_gpu_session.h" |
| 6 | #include "cudapp_native.h" |
| 7 | #include <stdlib.h> |
| 8 | #include <string.h> |
| 9 | static int plan(const OmegaGpuDnnRowsShape *s,uint64_t words[8],uint64_t p[16]) { |
| 10 | uint32_t bits;uint64_t result=0;memcpy(&bits,&s->epsilon,4); |
| 11 | memset(words,0,8*sizeof *words); |
| 12 | words[0]=s->rows;words[1]=s->length;words[2]=s->dtype;words[3]=s->op;words[4]=bits; |
| 13 | if(omega_dr_plan(&result,words,8,p,16)) return OMEGA_GPU_DNN_ROWS_CODEGEN; |
| 14 | return result?OMEGA_GPU_DNN_ROWS_REFUSED:OMEGA_GPU_DNN_ROWS_OK; |
| 15 | } |
| 16 | int omega_gpu_dnn_rows_codegen(const OmegaGpuDnnRowsShape *s,BlackwellIRProgram *program,uint8_t *code,size_t capacity,OmegaBlackwellKernel *kernel) { |
| 17 | uint64_t words[8],p[16]; |
| 18 | if(!s||!program||!code||!kernel)return OMEGA_GPU_DNN_ROWS_BAD_ARGS; |
| 19 | memset(kernel,0,sizeof *kernel);int rc=plan(s,words,p);if(rc)return rc; |
| 20 | rc=omega_gpu_om_ir_replay(omega_dnn_rows,words[3],words[1],words[2],0,program,NULL); |
| 21 | if(rc||omega_blackwell_kernel_encode_into(program,code,capacity,kernel))return OMEGA_GPU_DNN_ROWS_CODEGEN; |
| 22 | return OMEGA_GPU_DNN_ROWS_OK; |
| 23 | } |
| 24 | static void putptr(uint32_t *a,uint64_t p){a[0]=(uint32_t)p;a[1]=(uint32_t)(p>>32);} |
| 25 | int omega_gpu_dnn_rows(const OmegaGpuDnnRowsShape *s,const void *input,float *output) { |
| 26 | uint64_t words[8],p[16];if(!s||!input||!output)return OMEGA_GPU_DNN_ROWS_BAD_ARGS; |
| 27 | int rc=plan(s,words,p);if(rc)return rc; /* Before all device/session access. */ |
| 28 | BlackwellIRProgram *program=malloc(sizeof *program);uint8_t *code=malloc(65536);OmegaBlackwellKernel kernel={0}; |
| 29 | if(!program||!code){free(program);free(code);return OMEGA_GPU_DNN_ROWS_CODEGEN;} |
| 30 | rc=omega_gpu_dnn_rows_codegen(s,program,code,65536,&kernel);if(rc){free(program);free(code);return rc;} |
| 31 | OmegaGpuMem b[3]={0};omega_gpu_session_lock(); |
| 32 | if(omega_gpu_session_open()==NULL||omega_gpu_session_alloc(p[0],&b[0])||omega_gpu_session_alloc(p[1],&b[1])||omega_gpu_session_alloc_code(kernel.code_size,&b[2])){rc=OMEGA_GPU_DNN_ROWS_CHIP;goto cleanup;} |
| 33 | memcpy(b[0].cpu,input,p[0]);memset(b[1].cpu,0,p[1]);memcpy(b[2].cpu,code,kernel.code_size); |
| 34 | for(unsigned i=0;i<3;++i)if(omega_gpu_session_sync_to_gpu(&b[i])){rc=OMEGA_GPU_DNN_ROWS_CHIP;goto cleanup;} |
| 35 | uint32_t args[5];putptr(args,b[0].va);putptr(args+2,b[1].va);args[4]=(uint32_t)words[4]; |
| 36 | OmegaGpuLaunch launch={.code_va=b[2].va,.gpr_count=omega_bw_gpr_declared(program->regalloc.peak_gpr_usage), |
| 37 | .threads_x=(uint32_t)p[3],.threads_y=1,.grid_x=(uint32_t)p[2],.grid_y=1,.num_elements=p[2],.args=args,.n_args=5,.timeout_ms=30000}; |
| 38 | if(omega_gpu_session_launch(&launch,NULL,NULL)||omega_gpu_session_sync_to_cpu(&b[1])){rc=OMEGA_GPU_DNN_ROWS_CHIP;goto cleanup;} |
| 39 | memcpy(output,b[1].cpu,p[1]); |
| 40 | cleanup: |
| 41 | for(unsigned i=0;i<3;++i)omega_gpu_session_free(&b[i]); |
| 42 | omega_gpu_session_unlock();free(program);free(code);return rc; |
| 43 | } |