Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/CUDApp/blob/main/tests/model_graphs_nested_objects.c # 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 Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `CUDApp / tests / model_graphs_nested_objects.c` 82 lines · 4969 bytes Raw Blame History 1 /* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */ 2 #include "model_graphs_nested_objects.h" 3 /* Compile once per family. Production entry points and kernel caches are linked 4 * directly from these TUs, not reimplemented. Only backing resource observations 5 * are constructed here: record mode neither reads weights nor executes state. */ 6 #if defined(MG_NEST_FP8) 7 #include "../src/omega_gpu_fp8_api.c" 8 void *mg_nested_fp8(unsigned slot,uint32_t experts,uint32_t n,uint32_t k) { 9 static OmegaGpuFp8Tensor tensors[16]; static uint8_t backing[256]; 10 if(slot>=16 || !dev_open_locked()) return NULL; 11 OmegaGpuFp8Tensor *t=&tensors[slot]; 12 t->experts=experts;t->n=n;t->k=k;t->allocation_epoch=omega_gpu_session_epoch();t->owner_generation=slot+1;t->s_mul=0x1p-56; 13 t->w.cpu=backing;t->w.va=UINT64_C(0xb00000000)+(uint64_t)slot*UINT64_C(0x100000000); 14 t->w.size=(size_t)experts*n*k;t->s.cpu=backing;t->s.va=t->w.va+UINT64_C(0x80000000);t->s.size=(size_t)experts*(n/128)*(k/128)*4; 15 return t; 16 } 17 #elif defined(MG_NEST_BF16) 18 #include "../src/omega_gpu_bf16_gemv_api.c" 19 void *mg_nested_bf16(unsigned slot,uint32_t n,uint32_t k) { 20 static OmegaGpuBf16Tensor tensors[16];static uint8_t backing[256]; 21 if(slot>=16 || !dev_open_locked())return NULL; 22 OmegaGpuBf16Tensor *t=&tensors[slot];t->n=n;t->k=k;t->w.cpu=backing; 23 t->w.va=UINT64_C(0x1b00000000)+(uint64_t)slot*UINT64_C(0x100000000);t->w.size=(size_t)n*k*2; 24 return t; 25 } 26 #elif defined(MG_NEST_GDN) 27 #include "../src/omega_gpu_gdn_api.c" 28 void *mg_nested_gdn(unsigned slot,uint32_t ratio,uint32_t layers) { 29 static OmegaGpuGdn objects[8];static uint8_t lb[8][LB_BYTES]; 30 if(slot>=8 || !dev_open_locked())return NULL; 31 OmegaGpuGdn *o=&objects[slot];o->layers=layers;o->ratio=ratio; 32 if(shape_of(ratio,&o->sh))return NULL; 33 uint64_t base=UINT64_C(0x3000000000)+(uint64_t)slot*UINT64_C(0x100000000); 34 o->par.va=base;o->tail.va=base+UINT64_C(0x10000000);o->state.va=base+UINT64_C(0x20000000); 35 o->lb.va=base+UINT64_C(0x80000000);o->lb.cpu=lb[slot];o->lb.size=LB_BYTES; 36 if(omega_gpu_gdn_multi_prepare(o))return NULL; 37 return o; 38 } 39 #elif defined(MG_NEST_ATTN) 40 #include "../src/omega_gpu_decode_attn_api.c" 41 void *mg_nested_attn(unsigned slot,uint32_t layers) { 42 static OmegaGpuDecodeAttnCache objects[8];static uint32_t backing[8192]; 43 if(slot>=8 || !dev_open_locked())return NULL; 44 OmegaGpuDecodeAttnCache *c=&objects[slot];c->layers=layers;c->max_pos=OMEGA_GPU_DATTN_MAX_POS; 45 c->max_splits=c->max_pos/OMEGA_DATTN_CHUNK;c->plane_bytes=(uint64_t)OMEGA_GPU_DATTN_KV_HEADS*c->max_pos*OMEGA_DATTN_ROW_BYTES+OMEGA_DATTN_PLANE_SLACK; 46 uint64_t base=UINT64_C(0x4000000000)+(uint64_t)slot*UINT64_C(0x1000000000); 47 for(unsigned i=0;ikv[i].va=base+(uint64_t)i*2*c->plane_bytes; 48 c->rope.va=base+UINT64_C(0x800000000);c->norms.va=c->rope.va+UINT64_C(0x10000000);c->part.va=c->norms.va+UINT64_C(0x10000000); 49 c->cnt.va=c->part.va+UINT64_C(0x10000000);c->out.cpu=backing;c->cnt.cpu=backing; 50 return c; 51 } 52 #elif defined(MG_NEST_ATTN256) 53 #include "../src/omega_gpu_decode_attn256_api.c" 54 void *mg_nested_attn256(unsigned slot,uint32_t layers,uint32_t qh,uint32_t kvh,uint32_t qpc) { 55 static OmegaGpuDecodeAttn256Cache objects[8];static uint32_t backing[8192]; 56 if(slot>=8 || !dev_open_locked())return NULL; 57 OmegaGpuDecodeAttn256Cache *c=&objects[slot];c->layers=layers;c->max_pos=OMEGA_GPU_DATTN256_MAX_POS;c->rotary_dim=64; 58 c->shape.q_heads=qh;c->shape.kv_heads=kvh;c->shape.q_per_cta=qpc; 59 if(omega_dattn256_shape(&c->shape,&c->sh))return NULL; 60 c->max_splits=c->max_pos/OMEGA_DATTN256_CHUNK;c->plane_bytes=(uint64_t)c->sh.kvh*c->max_pos*RB+OMEGA_DATTN256_PLANE_SLACK; 61 uint64_t base=UINT64_C(0xc000000000)+(uint64_t)slot*UINT64_C(0x1000000000); 62 for(unsigned i=0;ikv[i].va=base+(uint64_t)i*2*c->plane_bytes; 63 c->rope.va=base+UINT64_C(0x800000000);c->norms.va=c->rope.va+UINT64_C(0x10000000);c->part.va=c->norms.va+UINT64_C(0x10000000); 64 c->cnt.va=c->part.va+UINT64_C(0x10000000);c->out.cpu=backing;c->cnt.cpu=backing; 65 if(!(c->sh.vy&(c->sh.vy-1u)) && omega_gpu_decode_attn256_multi_prepare(c))return NULL; 66 return c; 67 } 68 #elif defined(MG_NEST_ROUTER) 69 #include "../src/omega_gpu_router_api.c" 70 void *mg_nested_router(uint32_t layers,uint32_t experts,uint32_t shared) { 71 static OmegaGpuRouter r;static uint8_t backing[LB_BYTES9]; 72 if(!dev_open_locked())return NULL; 73 r.layers=layers;r.experts=experts;r.shared=shared;r.rows=experts+shared;r.slots=8+shared; 74 r.lb_tab_dn=shared?LB_TAB_DN9:LB_TAB_DN;r.lb_bytes=shared?LB_BYTES9:LB_BYTES; 75 r.gate.va=UINT64_C(0x15000000000);r.norm.va=r.gate.va+UINT64_C(0x10000000);r.dir.va=r.norm.va+UINT64_C(0x10000000); 76 r.lb.va=r.dir.va+UINT64_C(0x10000000);r.lb.cpu=backing;r.owner_generation=1; 77 if(omega_gpu_router_prepare_rows(&r,2048*4,32768))return NULL; 78 return &r; 79 } 80 #else 81 #error Select one MG_NEST recorder family 82 #endif