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_native_artifact.h

94 lines · 4716 bytes Raw Blame History
1/* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */
2/*
3 * omega_native_artifact: export one already-generated CUDApp/Omega GPU
4 * realization as an offline, digest-bound handoff artifact.
5 *
6 * Identity is the canonical manifest bytes; no live GPU virtual address, no
7 * open device handle and no privileged capability enters the artifact. The
8 * QMD bytes are exported as a relocatable template (all device addresses zero)
9 * so an admitting loader must fill them and bind the result in its own receipt.
10 *
11 * This module does not compile kernels, open a device, load a cubin or launch
12 * work. It packages bytes the existing code generator produced and refuses a
13 * malformed or unsupported descriptor.
14 */
15#ifndef OMEGA_NATIVE_ARTIFACT_H
16#define OMEGA_NATIVE_ARTIFACT_H
17
18#include <stddef.h>
19#include <stdint.h>
20#include "omega_blackwell_matmul.h"
21#include "omega_cubin.h"
22
23#define OMEGA_ARTIFACT_FORMAT "omega-native-artifact/1"
24#define OMEGA_ARTIFACT_ID_MAX 65u
25#define OMEGA_ARTIFACT_QMD_WORDS 96u
26/* Kernel-argument words a constant-bank template may carry: the launch path
27 * accepts at most OMEGA_GPU_SESSION_MAX_ARGS (32) arguments. */
28#define OMEGA_ARTIFACT_MAX_CBANK_WORDS 32u
29
30enum {
31 OMEGA_ARTIFACT_OK = 0,
32 OMEGA_ARTIFACT_E_ARG = 1,
33 OMEGA_ARTIFACT_E_FORMAT = 2,
34 OMEGA_ARTIFACT_E_CONTRACT = 3,
35 OMEGA_ARTIFACT_E_ISA = 4,
36 OMEGA_ARTIFACT_E_DIGEST = 5,
37 OMEGA_ARTIFACT_E_IO = 6,
38 OMEGA_ARTIFACT_E_RELOC = 7,
39 OMEGA_ARTIFACT_E_DRIVER = 8,
40 OMEGA_ARTIFACT_E_UNSUPPORTED = 9,
41 OMEGA_ARTIFACT_E_MEM = 10
42};
43
44typedef struct {
45 const char *op; /* "matmul" or "gqa-causal-attention" */
46 const char *shape; /* e.g. "m=16,k=16,n=8" */
47 const char *bounds; /* contract limits, e.g. "m<=8192,k<=16384,n<=8192" */
48 const char *contract_name; /* e.g. "matmul-bf16-v1" */
49 const char *contract_id_hex; /* 64 lowercase hex */
50 const char *semantic_spec_id_hex; /* 64 lowercase hex */
51 const char *kernel_function; /* cubin entry symbol */
52 const char *precision; /* "bf16" / "f32-kv" */
53 const char *accumulation; /* "fp32" */
54 const char *tolerance; /* frozen numeric text, no spaces */
55 const uint8_t *text; size_t text_len;
56 const OmegaCubinParam *params; size_t nparams;
57 uint32_t gpr_count;
58 uint32_t grid_x, grid_y;
59 uint32_t block_x, block_y, block_z;
60 uint32_t shared_bytes;
61 uint32_t cbank_offset;
62 const uint32_t *cbank_args; size_t cbank_words;
63 const uint32_t *qmd0; /* 96 words, addresses zero */
64 const uint32_t *qmd1; /* 96 words, addresses zero */
65 const char *min_driver; /* e.g. "580.173.02" */
66 const char *requires; /* e.g. "sm_121,nvidia-cubin-abi-v8" */
67 const char *source_commit; /* 40 hex, or "UNKNOWN" */
68 const char *tool_version; /* e.g. "cudapp-artifact-export/1" */
69 const char *qualification; /* e.g. "offline-disassembly=PASS;device-load=NOT_RUN" */
70} OmegaNativeArtifact;
71
72const char *omega_native_artifact_rc_name(int rc);
73
74/* Export <prefix>.{text.bin,cubin,qmd0.bin,qmd1.bin,cbank_args.bin,manifest,json,sha256}.
75 * out_id receives the 64-hex artifact id. Refuses unsupported descriptors.
76 * Artifacts are immutable: every output is created O_EXCL|O_NOFOLLOW, so an existing file or a
77 * symlink at any output path is E_IO. A prefix too long for any of the eight paths is E_ARG
78 * before anything is written. min_driver must be strict A.B.C, text fields single-line (E_ARG);
79 * QMD1 launch words must equal grid/block/shared_bytes/gpr_count (E_CONTRACT); at most
80 * OMEGA_ARTIFACT_MAX_CBANK_WORDS constant-bank words. */
81int omega_native_artifact_export(const OmegaNativeArtifact *a, const char *out_prefix,
82 char out_id[OMEGA_ARTIFACT_ID_MAX], char *err, size_t err_cap);
83
84/* Recompute and check an exported artifact's identity and every file digest, then the
85 * manifest's own claims: strict min_driver (E_FORMAT), cbank_words 1..OMEGA_ARTIFACT_MAX_CBANK_WORDS
86 * (E_FORMAT), QMD1 launch words equal to the manifest's grid/block/shared/gpr (E_CONTRACT).
87 * Every file is read once; digest and semantic checks use the same retained
88 * bytes rather than reopening a path after checking its digest.
89 * current_driver may be NULL to skip the minimum-driver check; an unparsable one is E_ARG,
90 * an older one E_DRIVER. out_id is written only when every check passes, empty otherwise. */
91int omega_native_artifact_admit(const char *out_prefix, const char *current_driver,
92 char out_id[OMEGA_ARTIFACT_ID_MAX], char *err, size_t err_cap);
93
94#endif /* OMEGA_NATIVE_ARTIFACT_H */