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 / AGENTS.md

111 lines · 14693 bytes Raw Blame History Rendered
1# CUDA++ (GPU machine-code toolchain, runtime and driver client for NVIDIA GPUs without the CUDA toolkit)
2
3> CUDA++ is the GPU half of the Omega runtime. It writes sm_121 machine code (SASS) directly, launches it through its own client for NVIDIA's open kernel module ioctls, and ships matrix multiply, attention, elementwise and mixture-of-experts libraries on top. Its build and runtime use no CUDA toolkit, `nvcc`, PTX, `libcuda` or cuBLAS. Host verification uses NVIDIA's offline `nvdisasm` as an independent instruction oracle, never as an implementation dependency. It builds with `make` and a C compiler; it runs only on the NVIDIA GB10 (DGX Spark, sm_121) with the 580.173.02 open kernel module. The repository on GitHub is `CUDApp`; the project name is written CUDA++.
4
5Shared rules: read https://www.aienos.com/agents/RULES.md first. This file adds what is specific to this repository; where the two differ, this file wins here.
6
7## Scope
8
9- Applies to the whole repository.
10- `src/`: encoder, kernel builder and register allocator (`omega_blackwell_*`), runtime (`omega_gpu_session`, `omega_gpu_cmdlist`, `omega_gpu_engine`, `omega_gpu_platform*`), libraries (`omega_gpu_*_api.*`). The C names keep the `omega_` prefix on purpose (`docs/NAMING.md`); do not rename them.
11- `nvrm/`, `m16/`: the driver client and the completion wait.
12- `third_party/nvidia-open-580.173.02/`: NVIDIA's open kernel module headers, MIT, copied unchanged. Never edit them. A new driver version goes in a new `third_party/nvidia-open-<version>/` folder (`CONTRIBUTING.md`, "Port a driver version").
13- `tests/`: host tests and the chip tests (`tests/gpu_*_test.c`). `mk/*.mk`: build fragments included by the `Makefile`.
14- `evidence/`: dated receipts. They record what ran on a named commit; never edit or regenerate an existing receipt. New receipts go in a new folder.
15- `build/` is generated (`make`, `OUT_DIR`) and ignored by git.
16- Omega is meant to build these sources at a pinned commit (`cudapp.lock` in Omega). That pin does not exist yet: Omega main still builds its own diverged copy and takes `nvrm` from physics-mv (#106, #107). Changes to public headers or the runtime API will affect Omega once it does. Ownership rule: ARCH-0042, Accepted 2026-10-30 in aien-architecture-mv#342 (Omega owns computation, CUDA++ owns GPU execution, Omega Bridge owns compatibility). The cubin writer is this repository's: `docs/CUBIN_WRITERS.md` (#108). New cubin-writer work stays here. Do not import omega-mv `seed/sm80/cubin.om`.
17
18## Installation
19
20```bash
21git clone https://github.com/aien-dev/CUDApp.git
22cd CUDApp
23make -j8 # build/libomega_gpu.a, copied to build/libcudapp.a
24```
25
26Needs Linux, `git`, `make` and `gcc` (the `Makefile` uses `CC ?= gcc` and builds with `-Wall -Wextra -Werror`). Nothing from the CUDA toolkit is needed to build or run. The complete host test suite additionally requires offline `nvdisasm` for independent encoder operand checks and the pinned Omega verification tools; missing required tools are NOT_RUN, not PASS. The host build and host tests need no GPU. Running a kernel on the chip needs a DGX Spark (GB10) with NVIDIA's open kernel module 580.173.02 loaded and `/dev/nvidia0` and `/dev/nvidia-uvm` present.
27
28## Configuration
29
30- Build variables: `CC` (default `gcc`), `OUT_DIR` (default `build`), `PHYSICS_DIR` (default `.`; Omega overrides it).
31- `CUDAPP_MEM_RESERVE_MIB`: memory the runtime keeps free before any allocation reaches the driver (default 4096; `0` turns the check off; both hosted platforms share it through `src/omega_gpu_mem_reserve.c`). Tests point the check at a fake `/proc/meminfo` with `omega_gpu_platform_linux_test_set_meminfo` (no environment variable chooses that file).
32- `CUDAPP_DOCTOR_ROOT` points `make doctor` at a fake machine root; `CUDAPP_DOCTOR_SHOW=1 sh tests/doctor/run.sh build/cudapp-doctor` prints the doctor's output on the nine fake machines.
33- `AIEN_OMEGA_DGRAPH_BARRIER` and `AIEN_OMEGA_DGRAPH_PREFETCH` tune the decode graph (`src/omega_gpu_decode_graph.c`).
34
35## Usage
36
37Host commands (no GPU opened):
38
39```bash
40make test # portable host suite, x86-64 and AArch64: about 7 minutes
41make test-native-artifact # offline native artifact export test
42make zero-cuda-gate # the built programs need no CUDA library (self-test first)
43make doctor # is this machine ready? reads /proc, /sys and /dev only
44build/hello_gpu --sim # the first kernel on the host warp simulator
45make test-omega-slices # eight OSC slices; needs OMEGA_OSC_COMPILER_DIR; not part of make test
46python3 tools/figures/make_figures.py --check # README figures match the code
47python3 tools/figures/test_stack_legend.py -v # rendered legend check; needs Inkscape
48```
49
50- `docs/OMEGA_HOST_TESTS.md` separates portable commands from target-only ones. `make test` needs no NVIDIA tool and no sibling checkout. On x86-64 the production Blackwell open returns `ENOTSUP` and names AArch64, and the seeded AArch64 binding is not assembled: the C encoder and C cubin writer are the portable bodies, and `make test-om-encoder`, `make test-om-cubin`, `make test-gpu-native-runtime`, `make test-om-spec-encoder`, `make test-portable-receipts` and `make test-model-capacity` exit 2. AArch64 keeps `dsb sy` and keeps those rows in `make test`. `make test-omega-arch-guard` prints `NOT_RUN` on AArch64 and does not build the binary.
51
52- Judge `make test` by its exit code and its last line, `CUDA++ HOST TESTS PASS (<count> targets)`, where `<count>` is computed from the current `HOST_TESTS` manifest in `Makefile`. The log contains many `FAIL` and `ERROR` lines by design (mutation tests and negative controls that must fail). Do not grep the log for them.
53- `make test` already runs the host-only `test-gpu-*` targets listed in `HOST_TESTS` in the `Makefile`. Run those through `make test`, not by hand.
54- `make zero-cuda-gate` reads ELF metadata only (`tools/zero-cuda-gate.sh`).
55- `test-portable-receipts` is included in `make test` on AArch64. It needs full Git history plus the pinned `OMEGA_OMC` and `OMEGA_BRIDGE` used by `test-om-units`. On x86-64 it is outside `make test` and exits 2: the pinned compiler is not part of the portable suite. The `.om` checker verifies original and scrubbed-payload SHA-256, exact HOME-substitution reversal, original Git-blob identity, and independent refusal controls. The TSV separately pins each complete derived file. These are portable derivatives, never rewritten original receipts or qualification authority.
56- `python3 tools/figures/make_figures.py --check` must print `figures current: <n>`. Regenerate figures only when you change the data they are drawn from, and commit the regenerated SVGs with that change.
57
58GPU commands (need a GB10; do not run from an agent session unless the maintainer has given you a GPU window on the DGX Spark):
59
60```bash
61make hello-gpu # runs make doctor, then examples/hello_gpu on the GPU
62./build/gpu_<name>_test --out receipt.json # chip gates; each test's comment in the Makefile says how it is run
63```
64
65`make cubin-probe` (`tools/interop/cubin_probe.c`) links NVIDIA's `libcuda` and refuses to run unless `SPARK_WINDOW` is set. It is an interop check, not part of CUDA++; never add it to a host target.
66
67## Conventions
68
69- Nothing counts until it runs and leaves a receipt: the command, the commit, the machine and what it printed, saved under `evidence/<topic>/` (`CONTRIBUTING.md`).
70- Write the test first and watch it fail for the expected reason; include a negative control. A library change also needs a host reference, a simulator run where the simulator covers it, a mutation test and a chip receipt.
71- A failing test means the work is wrong. Never skip, loosen or rerun a test until it passes once.
72- Every instruction encoding has golden words in the tests and a chip run behind it. Do not change an encoder field without both.
73- No NVIDIA binary, cubin, PTX, firmware or listing printed by NVIDIA's tools goes in this repository (`docs/AUDIT.md`). The former trace-emitter regression pin was removed in #93; its history is recorded in `PROVENANCE.md` section 6. The rules for allowed sources are in `PROVENANCE.md`. If you used NVIDIA's compiler or disassembler on your own small kernels to learn an encoding, say so in a code comment.
74- The runtime API is versioned. `docs/runtime/omega_runtime_api.manifest` is checked against the C headers it names and against `docs/runtime/API.md` by `make test` (`test-runtime-api`, with negative controls). Change a public header, the manifest and `API.md` together.
75- Status words in `README.md` and `ROADMAP.md` are PASS (receipt on a named commit), PARTIAL, MISSING, BUILDING. Do not upgrade a status without the receipt.
76- New source files carry `SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception`. Keep third-party notices (`THIRD_PARTY.md`, `NOTICE`).
77- Plain English, short sentences, every number with the command that produced it.
78- Pull request CI runs the host-only `make test` suite, pinned Omega binding regeneration and mutants, and SBOM generation. GitHub CodeQL is repository code scanning default setup (`dynamic/github-code-scanning/codeql`), not a workflow file in `.github/workflows`. The host-test job's disposable arm64 runner installs only the checksum-verified NVIDIA `nvdisasm` 13.0.85 executable and the bridge source pinned by `om/omega-bridge.lock`. The archive URL and SHA-256 are fixed in `.github/workflows/ci.yml`, from NVIDIA's `redistrib_13.0.2.json` manifest. The oracle is verification-only: no CUDA driver, runtime or compiler is installed, no NVIDIA binary is committed, and no GPU is opened. Provisioning errors and missing-oracle checks remain failures. Put local results in the pull request with their exact source revision; all-green host CI is not physical qualification. `.github/workflows/host-gates.yml` runs `make -j4`, `make test-native-artifact`, `make zero-cuda-gate`, `build/hello_gpu --sim`, read-only `make doctor`, and `python3 tools/figures/make_figures.py --check`. `make test` stays in the `host-tests` job. The rules are `docs/CI_ACCEPTANCE.md`.
79
80## Safety and approvals
81
82- Never run a chip test, `make hello-gpu` or anything that opens `/dev/nvidia*` on a shared DGX Spark without an authorized GPU window from the maintainer. A live model may be serving on the same GPU.
83- Never commit secrets, private paths or host addresses. `tools/extract/audit-scan.sh` and its rule files show what the publication audit checks for.
84- Ask before changing the platform contract (`src/omega_gpu_platform.h`), the driver client's ioctl usage, the qualified chip table (`src/omega_gpu_chip.c`) or the licence files.
85- Work on a branch named for what it does. Never force-push `main`; the `main` ruleset blocks force pushes and deletion.
86
87## Further reading
88
89- `README.md`: what CUDA++ is, the driver part by part, how to run the first kernel.
90- `CONTRIBUTING.md`: the receipt rule and how a change gets in.
91- `ROADMAP.md`: every NVIDIA piece on the Spark, its replacement and receipt.
92- `docs/DRIVER.md`, `docs/HOW_I_DID_IT.md`, `docs/runtime/API.md`, `docs/runtime/PORTABILITY.md`.
93- `docs/AUDIT.md`, `docs/LICENSING_TRANSITION.md`, `THIRD_PARTY.md`: provenance and licences.
94- `docs/CUBIN_WRITERS.md`: the two cubin writers, who owns new work, and what was not run (#108).
95- Aienux, the Aien kernel, which holds the C reference for Aien's own GB10 driver and its GB10 simulator (L332, aienux#441). That driver replaces NVIDIA's `nvidia.ko` and `nvidia-uvm.ko`, together with aien-dev/aien-gpu and aien-dev/omega-gpu-driver; none has run on the GB10 yet (`ROADMAP.md`): https://github.com/aien-dev/aienux
96
97## Cursor Cloud specific instructions
98
99Cloud Agent VMs are x86_64. `make` decides the host from `uname -m` (Makefile L24-31): on x86_64 it sets `CC := gcc` unless `CC` came from the command line or the environment, compiles the same checked portable C units emitted by `om/units.sh` (`src/cudapp_om_*.c`, `src/cudapp_freest_*.c`) that AArch64 compiles, and, unless `OMEGA_OMC` is given explicitly, makes the three rows that execute the pinned AArch64 omc (`test-om-spec-encoder`, `test-portable-receipts`, `test-model-capacity`) exit 2. `gcc` is whatever `PATH` finds first; on these VMs `/usr/local/bin/gcc` and `/usr/local/bin/cc` are the aarch64 cross compiler, so the built binaries are aarch64 and run under qemu-user. qemu-user is registered against `/usr/aarch64-linux-gnu` at boot, and again by `/usr/local/bin/make` if that boot hook did not run. If a binary exits with `Exec format error`, run any `make` target once, then retry it. On AArch64 `CC` stays make's built-in `cc` and the seeded binding is linked.
100
101`make test` is the host suite. Judge the exit code and the last line, `CUDA++ HOST TESTS PASS (<count> targets)`. The log contains intentional `FAIL` lines. Under qemu it is slower than the arm64 CI runner. The attention simulator is one slow part. `test-codegen-freestanding` sweeps every 2^32 bf16 input; a 20 million iteration cast loop took 18 seconds here, so that sweep is on the order of an hour. `build/hello_gpu --sim` is the simulator hello world. `python3 tools/figures/make_figures.py --check` checks the README figures.
102
103Pinned tools sit where the Makefile looks, next to the checkout:
104
105- `../omega-mv` is omega-mv `e5b32567`, `seed/out/omc`, sha256 `2c82480596bbdc50cda9626866209ef662d5834f278f839ff4ce0250c495029f`
106- `../omega-bridge` is omega-bridge `758d74aadf465ed5d4b3c80d798615c8ed4e18f8` (`om/omega-bridge.lock`; draft omega-bridge#71 head, typed views, to move to its merge sha). `tools/bootstrap.sh` checks `uname -m` for aarch64; its rung binaries are AArch64 and run through the qemu-user handler. The built converter is `../omega-bridge/build/bridge` (`build/bootstrap/omc` sha256 `191b776ef98821597c3e30655da6d680a9b66edbc9ceaca3c39c61ea6df098e9`)
107- `nvdisasm` 13.0.85 is the x86_64 redistributable from NVIDIA `redistrib_13.0.2.json` (CI uses the linux-sbsa archive of the same version)
108
109`/usr/local/bin/make` exports `CUDAPP_MEM_RESERVE_MIB=0` when the variable is unset. MemAvailable on this VM under-reports because of the hypervisor balloon, and the default 4 GiB reserve then refuses the Qwen-shaped upload in `test-gpu-serving-alloc`. The platform test unsets the variable and still checks the 4096 default against a fake meminfo. Do not copy that `0` onto a Spark.
110
111`make doctor` prints NOT READY here: no NVIDIA module and no `/dev/nvidia*`. That is the expected diagnostic. The doctor binary is aarch64, so its system line says aarch64; `uname -m` in the shell is x86_64. Do not run `make hello-gpu` or open `/dev/nvidia*`.