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/src/omega_gpu_gdn_admit.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 / src / omega_gpu_gdn_admit.c` 100 lines · 5421 bytes Raw Blame History 1 /* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */ 2 /* omega_gpu_gdn_admit.c: see the header. */ 3 #include "omega_gpu_gdn_admit.h" 4 #include "omega_gpu_gdn_api.h" 5 #include 6 #include 7 8 #if defined(CUDAPP_MIGRATION_PENDING_C_GDN_ADMIT) 9 int omega_gdn_admit_shape(uint32_t ratio, uint32_t state_bf16, OmegaGdnShape *s) { 10 OmegaGdnSpec sp; memset(&sp, 0, sizeof sp); sp.ratio = ratio; sp.state_bf16 = state_bf16; 11 return omega_gdn_shape(&sp, s); 12 } 13 int omega_gdn_admit_alloc(uint32_t layers, uint32_t ratio, uint32_t state_bf16, OmegaGdnShape *s) { 14 if (layers == 0 || layers > OMEGA_GPU_GDN_MAX_LAYERS) return -1; 15 return omega_gdn_admit_shape(ratio, state_bf16, s); 16 } 17 int omega_gdn_admit_layer(uint32_t layer, uint32_t layers) { return layer >= layers ? -1 : 0; } 18 int omega_gdn_admit_finite(float eps_l2, float eps_norm, float in_scale, float out_scale) { 19 return !isfinite(eps_l2) || !isfinite(eps_norm) || !isfinite(in_scale) || !isfinite(out_scale) ? -1 : 0; 20 } 21 int omega_gdn_admit_multi(uint32_t layer, uint32_t layers, uint32_t tokens, uint64_t qkv_va, uint64_t z_va, uint32_t xstride, 22 uint64_t ab_va, uint32_t abstride, uint64_t out_va, uint32_t ostride) { 23 if (layer >= layers || tokens == 0 || !qkv_va || !z_va || !ab_va || !out_va) return -1; 24 if (((qkv_va | z_va | out_va | xstride | ostride) & 15u) || ((ab_va | abstride) & 7u)) return -1; 25 return 0; 26 } 27 int omega_gdn_admit_tokens(uint32_t tokens) { 28 return tokens < OMEGA_GDN_PF_MIN_T || tokens > OMEGA_GPU_GDN_PF_MAX_T ? -1 : 0; 29 } 30 int omega_gdn_admit_layout(uint32_t ratio, uint32_t T, size_t off[OMEGA_GDN_PF_SECTIONS], size_t *bytes) { 31 OmegaGdnShape S; const OmegaGdnShape *shp = &S; 32 if (T > OMEGA_GPU_GDN_PF_MAX_T || omega_gdn_admit_shape(ratio, 0, &S)) return -1; 33 const uint64_t T8 = ((uint64_t)T + OMEGA_GDN_SCAN_CHUNK - 1u) / OMEGA_GDN_SCAN_CHUNK * OMEGA_GDN_SCAN_CHUNK; 34 const uint64_t sz[OMEGA_GDN_PF_SECTIONS] = { (uint64_t)T * shp->conv * 4u, (uint64_t)T * shp->vdim * 4u, 35 (uint64_t)T * shp->vh * 8u, (uint64_t)T * shp->vdim * 4u, 36 (uint64_t)T * shp->vdim * 4u, T8 * shp->vh * OMEGA_GDN_REC_BYTES }; 37 size_t at = 0; 38 for (unsigned i = 0; i < OMEGA_GDN_PF_SECTIONS; i++) { off[i] = at; at += (size_t)((sz[i] + 255u) & ~(uint64_t)255u); } 39 *bytes = at; 40 return 0; 41 } 42 int omega_gdn_admit_move(unsigned kind, uint64_t dst, size_t bytes, uint32_t *grid) { 43 const size_t per = (size_t)OMEGA_GDN_COPY_WORDS_PER_CTA * 4u; 44 if ((kind != OMEGA_GDN_ADMIT_KIND_COPY && kind != OMEGA_GDN_ADMIT_KIND_ZERO) || !dst || bytes == 0 || bytes % per || 45 bytes / per > 0x7fffffffu) return -1; 46 *grid = (uint32_t)(bytes / per); 47 return 0; 48 } 49 #else 50 #include "cudapp_native.h" 51 /* One call of the unit: 0 admitted, -1 refused or trapped. o carries inputs and outputs (see om/gdn/admit.om). */ 52 static int admit(uint64_t op, uint64_t a, uint64_t b, uint64_t c, uint64_t o[16]) { 53 uint64_t r = 1; 54 if (omega_gdn_admit(&r, op, a, b, c, o, 16) != 0) return -1; 55 return r == 0 ? 0 : -1; 56 } 57 static void shape_out(const uint64_t o[16], OmegaGdnShape *s) { 58 s->r = (uint32_t)o[0]; s->vh = (uint32_t)o[1]; s->conv = (uint32_t)o[2]; s->vdim = (uint32_t)o[3]; 59 s->par_scal = (uint32_t)o[4]; s->par_norm = (uint32_t)o[5]; s->par_bytes = (uint32_t)o[6]; 60 s->tail_bytes = (uint32_t)o[7]; s->state_bytes = (uint32_t)o[8]; s->post_grid_y = (uint32_t)o[9]; 61 } 62 static uint32_t f32_bits(float f) { uint32_t u; memcpy(&u, &f, 4); return u; } 63 int omega_gdn_admit_shape(uint32_t ratio, uint32_t state_bf16, OmegaGdnShape *s) { 64 uint64_t o[16] = {0}; 65 if (admit(1, ratio, state_bf16, 0, o)) return -1; 66 shape_out(o, s); 67 return 0; 68 } 69 int omega_gdn_admit_alloc(uint32_t layers, uint32_t ratio, uint32_t state_bf16, OmegaGdnShape *s) { 70 uint64_t o[16] = {0}; 71 if (admit(2, layers, ratio, state_bf16, o)) return -1; 72 shape_out(o, s); 73 return 0; 74 } 75 int omega_gdn_admit_layer(uint32_t layer, uint32_t layers) { uint64_t o[16] = {0}; return admit(3, layer, layers, 0, o); } 76 int omega_gdn_admit_finite(float eps_l2, float eps_norm, float in_scale, float out_scale) { 77 uint64_t o[16] = {0}; 78 return admit(4, f32_bits(eps_l2) | (uint64_t)f32_bits(eps_norm) << 32, f32_bits(in_scale) | (uint64_t)f32_bits(out_scale) << 32, 79 0, o); 80 } 81 int omega_gdn_admit_multi(uint32_t layer, uint32_t layers, uint32_t tokens, uint64_t qkv_va, uint64_t z_va, uint32_t xstride, 82 uint64_t ab_va, uint32_t abstride, uint64_t out_va, uint32_t ostride) { 83 uint64_t o[16] = {qkv_va, z_va, ab_va, out_va, xstride, abstride, ostride}; 84 return admit(5, layer, layers, tokens, o); 85 } 86 int omega_gdn_admit_tokens(uint32_t tokens) { uint64_t o[16] = {0}; return admit(6, tokens, 0, 0, o); } 87 int omega_gdn_admit_layout(uint32_t ratio, uint32_t tokens, size_t off[OMEGA_GDN_PF_SECTIONS], size_t *bytes) { 88 uint64_t o[16] = {0}; 89 if (admit(7, tokens, ratio, 0, o)) return -1; 90 for (unsigned i = 0; i < OMEGA_GDN_PF_SECTIONS; i++) off[i] = (size_t)o[i]; 91 *bytes = (size_t)o[OMEGA_GDN_PF_SECTIONS]; 92 return 0; 93 } 94 int omega_gdn_admit_move(unsigned kind, uint64_t dst, size_t bytes, uint32_t *grid) { 95 uint64_t o[16] = {0}; 96 if (admit(8, kind, bytes, dst, o)) return -1; 97 *grid = (uint32_t)o[0]; 98 return 0; 99 } 100 #endif