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 / mk / om-cubin.mk

83 lines · 6715 bytes Raw Blame History
1# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
2# The sm_121 cubin packer in seeded Omega (om/cubin/cubin_elf.om), linked through the omega-bridge native binding
3# portable generated C units $(CUDAPP_BINDING_SRCS) that om/units.sh generates. The C writer in src/omega_cubin.c is migration-pending: the
4# explicit oracle builds only (CUDAPP_MIGRATION_PENDING_C_CORE, CUDAPP_MIGRATION_PENDING_CUBIN_DIFF).
5# make test-om-cubin (in `make test`, no Omega tools needed)
6# 1. the cubin tests (gpu_artifact_export_test, native_artifact_manifest_test) through the .om packer;
7# 2. the same two tests and the sweep tests/om_cubin_sweep_test.c built with CUDAPP_MIGRATION_PENDING_CUBIN_DIFF:
8# every call is packed both ways and aborts on any difference; the log must hold only SAME lines;
9# 3. its red check: the sweep with one flipped image bit must abort.
10# make test-om-cubin-mutants mutant .om packers, each compiled by the pinned omc, must turn the sweep red
11# (needs OMEGA_MV and OMEGA_BRIDGE_DIR as in mk/om-encoder.mk; without them exit 3, NOT_RUN, never PASS).
12# Its prerequisites run the two Omega tests of the Ampere writer outputs, so the CI om-units job runs them:
13# make test-om-amp-qmd tests/amp_qmd_test.om: amp_qmd.om against amp_runtime, the computation the retained
14# C oracle calls (4096 build + 4096 policy states, all 256 bytes, refusal leaves the output unchanged); an
15# injected bad byte must exit 2.
16# make test-om-ampere-elf-admission (mk/ampere-cubin.mk) the ELF admission unit on the test-ampere-cubin image.
17OM_CUBIN_DIR = $(OUT_DIR)/om-cubin
18OM_CUBIN_BUILD = gcc -std=gnu11 -O2 -Wall -Wextra -Werror -pthread -Isrc
19OM_CUBIN_DEPS = src/omega_cubin.c src/omega_cubin.h $(CUDAPP_BINDING_SRCS) src/cudapp_native.h
20OM_CUBIN_DIFF = -DCUDAPP_MIGRATION_PENDING_CUBIN_DIFF
21
22.PHONY: test-om-cubin test-om-cubin-mutants test-om-amp-qmd
23$(OM_CUBIN_DIR)/sweep_diff: tests/om_cubin_sweep_test.c $(OM_CUBIN_DEPS)
24 @mkdir -p $(OM_CUBIN_DIR)
25 $(OM_CUBIN_BUILD) $(OM_CUBIN_DIFF) -o $@ tests/om_cubin_sweep_test.c src/omega_cubin.c $(CUDAPP_BINDING_SRCS)
26$(OM_CUBIN_DIR)/sweep_diff_red: tests/om_cubin_sweep_test.c $(OM_CUBIN_DEPS)
27 @mkdir -p $(OM_CUBIN_DIR)
28 $(OM_CUBIN_BUILD) $(OM_CUBIN_DIFF) -DCUDAPP_CUBIN_DIFF_SELFTEST -o $@ tests/om_cubin_sweep_test.c src/omega_cubin.c \
29 $(CUDAPP_BINDING_SRCS)
30$(OM_CUBIN_DIR)/artifact_diff: tests/gpu_artifact_export_test.c src/omega_native_artifact.c $(OM_CUBIN_DEPS) $(OUT_DIR)/libomega_gpu.a
31 @mkdir -p $(OM_CUBIN_DIR)
32 $(CC) $(CFLAGS) $(OM_CUBIN_DIFF) -o $@ tests/gpu_artifact_export_test.c src/omega_native_artifact.c src/omega_cubin.c \
33 $(OUT_DIR)/libomega_gpu.a -lpthread -lm
34$(OM_CUBIN_DIR)/manifest_diff: tests/native_artifact_manifest_test.c src/omega_native_artifact.c src/omega_blackwell_realize.c \
35 src/sha256.c $(OM_CUBIN_DEPS)
36 @mkdir -p $(OM_CUBIN_DIR)
37 $(CC) $(CFLAGS) $(OM_CUBIN_DIFF) -ffunction-sections -fdata-sections -Wl,--gc-sections -Wl,--wrap=fopen -o $@ \
38 tests/native_artifact_manifest_test.c src/omega_native_artifact.c \
39 src/omega_cubin.c src/omega_blackwell_realize.c src/sha256.c $(CUDAPP_BINDING_SRCS) -lpthread
40
41test-om-cubin: $(OUT_DIR)/gpu_artifact_export_test $(OUT_DIR)/native_artifact_manifest_test $(OM_CUBIN_DIR)/artifact_diff \
42 $(OM_CUBIN_DIR)/manifest_diff $(OM_CUBIN_DIR)/sweep_diff $(OM_CUBIN_DIR)/sweep_diff_red
43 rm -rf $(OM_CUBIN_DIR)/artifact-om $(OM_CUBIN_DIR)/artifact-diff $(OM_CUBIN_DIR)/diff.log
44 ./$(ARTIFACT_TEST) $(OM_CUBIN_DIR)/artifact-om
45 ./$(OUT_DIR)/native_artifact_manifest_test
46 CUDAPP_CUBIN_DIFF_LOG=$(OM_CUBIN_DIR)/diff.log $(OM_CUBIN_DIR)/artifact_diff $(OM_CUBIN_DIR)/artifact-diff
47 CUDAPP_CUBIN_DIFF_LOG=$(OM_CUBIN_DIR)/diff.log $(OM_CUBIN_DIR)/manifest_diff
48 @a=$$(grep -c . $(OM_CUBIN_DIR)/diff.log); \
49 CUDAPP_CUBIN_DIFF_LOG=$(OM_CUBIN_DIR)/diff.log $(OM_CUBIN_DIR)/sweep_diff || exit 1; \
50 same=$$(grep -c ' SAME$$' $(OM_CUBIN_DIR)/diff.log); other=$$(grep -vc ' SAME$$' $(OM_CUBIN_DIR)/diff.log); \
51 if [ "$$a" -eq 0 ] || [ "$$other" -ne 0 ]; then echo "FAIL cubin diff: $$a test calls, $$same SAME, $$other other lines"; exit 1; fi; \
52 echo "cubin diff: .om and C packers identical (code, bytes, message) on $$same calls ($$a from the artifact tests, $$((same - a)) from the sweep; $$(grep -c '^cubin rc=0 ' $(OM_CUBIN_DIR)/diff.log) images)"
53 @if $(OM_CUBIN_DIR)/sweep_diff_red > /dev/null 2>&1; then \
54 echo "RED CHECK BROKEN: a flipped bit passed the cubin diff"; exit 1; \
55 else echo "red check: one flipped image bit aborts the cubin diff, as it must"; fi
56
57# Each mutant is one edit of the .om source, compiled by the pinned omc into its own binding; the sweep linked
58# with it (diff mode) must abort or fail.
59OM_CUBIN_MUTANTS = 's/^f = add f add add 117 mul 16 tkon m mul 3 n$$/f = add f add add 118 mul 16 tkon m mul 3 n/' \
60 's/^const PBASE ulong 896$$/const PBASE ulong 892/' \
61 's/^if gt get m 4 255$$/if gt get m 4 254/' \
62 's/^sh2 o b get l 10 32 mul 11 tkon m 2$$/sh2 o b get l 10 32 mul 0 tkon m 2/'
63test-om-amp-qmd: om/encoder/amp_runtime.om om/encoder/amp_qmd.om tests/amp_qmd_test.om
64 @[ -x $(OMEGA_MV)/seed/out/omc ] || { echo "NOT_RUN: set OMEGA_MV"; exit 3; }
65 @mkdir -p $(OM_CUBIN_DIR)
66 cat om/encoder/amp_runtime.om om/encoder/amp_qmd.om tests/amp_qmd_test.om | $(OMEGA_MV)/seed/out/omc > $(OM_CUBIN_DIR)/amp_qmd_test
67 chmod +x $(OM_CUBIN_DIR)/amp_qmd_test
68 $(OM_CUBIN_DIR)/amp_qmd_test
69 @rc=0; $(OM_CUBIN_DIR)/amp_qmd_test red > /dev/null || rc=$$?; \
70 if [ $$rc != 2 ]; then echo "RED CHECK BROKEN: amp_qmd_test red exited $$rc, not 2"; exit 1; fi; \
71 echo "red check: an injected output byte exits 2, as it must"
72test-om-cubin-mutants: test-om-amp-qmd test-om-ampere-elf-admission
73 @[ -x $(OMEGA_MV)/seed/out/omc ] && [ -f $(OMEGA_BRIDGE_DIR)/src/native.om ] || { echo "NOT_RUN: set OMEGA_MV and OMEGA_BRIDGE_DIR"; exit 3; }
74 @n=0; for m in $(OM_CUBIN_MUTANTS); do n=$$((n+1)); d=$(OM_CUBIN_DIR)/mutant$$n; rm -rf $$d; mkdir -p $$d; \
75 sed "$$m" om/cubin/cubin_elf.om > $$d/cubin_elf.om; \
76 if cmp -s $$d/cubin_elf.om om/cubin/cubin_elf.om; then echo "MUTANT $$n BROKEN: '$$m' changed nothing"; exit 1; fi; \
77 OMEGA_UNITS=$$(pwd)/$$d/cubin_elf.om OMEGA_UNITS_DEST=$$d OMEGA_OMC=$(OMEGA_MV)/seed/out/omc \
78 OMEGA_BRIDGE=$(OMEGA_BRIDGE_DIR) sh om/units.sh > /dev/null || exit 1; \
79 $(OM_CUBIN_BUILD) $(OM_CUBIN_DIFF) -o $$d/sweep tests/om_cubin_sweep_test.c src/omega_cubin.c \
80 $$d/cudapp_om_cubin_elf.c src/cudapp_freest_core_cubinmsg.c src/cudapp_freest_core_cubadmit.c || exit 1; \
81 if $$d/sweep > $$d/sweep.log 2>&1; then echo "MUTANT $$n SURVIVED: '$$m'"; exit 1; fi; \
82 echo "mutant $$n red ('$$m'): $$(grep -m1 -e 'CUBIN DIFF' -e FAIL $$d/sweep.log)"; \
83 done