interplane.Get Omega
Read in your language

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

branch main Branches Tags History

CUDApp / src / omega_gpu_serving.c

48 lines · 1811 bytes Raw Blame History
1/* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */
2/* omega_gpu_serving.c: see omega_gpu_serving.h. Thin wrapper over the per-API reserve calls. */
3#include "omega_gpu_serving.h"
4#include "omega_gpu_attention_api.h"
5#include "omega_gpu_matmul_api.h"
6#if defined(CUDAPP_MIGRATION_PENDING_C_SERVING)
7#define ENG_C_PART 1
8#endif
9#include "omega_eng_dec.h"
10
11int omega_gpu_reserve_serving(const OmegaGpuServingBounds *b) {
12 uint32_t seqs, one_row;
13 int rows;
14 if (eng_on()) {
15 uint64_t in[5], w[16];
16 in[0] = b ? 1u : 0u;
17 in[1] = b ? b->max_seqs : 0u;
18 in[2] = b ? b->max_rows : 0u;
19 in[3] = b ? b->max_n : 0u;
20 in[4] = b ? b->max_n_one_row : 0u;
21 if (eng_ask(ENG_OP_SERVE, in, 5, w) != 0 || w[0] != 0) return OMEGA_GPU_MATMUL_BAD_ARGS;
22 seqs = (uint32_t)w[1];
23 rows = (int)w[2];
24 one_row = (uint32_t)w[3];
25 } else {
26 if (!b) return OMEGA_GPU_MATMUL_BAD_ARGS;
27 seqs = b->max_seqs ? b->max_seqs : 1;
28 rows = b->max_rows > 1;
29 one_row = b->max_n_one_row ? b->max_n_one_row : b->max_n;
30 }
31 int rc = omega_gpu_attention_reserve(b->max_context, seqs, b->num_q_heads, b->num_kv_heads, b->head_dim, b->kv_block_size);
32 if (rc != 0) return rc;
33 if (rows) {
34 rc = omega_gpu_attention_reserve_rows(b->max_rows, b->num_q_heads, b->head_dim);
35 if (rc != 0) { omega_gpu_attention_unreserve(); return rc; }
36 }
37 rc = omega_gpu_matmul_reserve(b->max_rows, b->max_k, b->max_n, one_row, b->kernel_slots);
38 if (rc != 0) omega_gpu_attention_unreserve();
39 return rc;
40}
41
42void omega_gpu_serving_seal(void) { omega_gpu_matmul_seal(1); }
43
44void omega_gpu_serving_release(void) {
45 omega_gpu_matmul_seal(0);
46 omega_gpu_attention_unreserve();
47 omega_gpu_matmul_unreserve();
48}