interplane.Get Omega
Read in your language

omega-mv

Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.

Brought by drakestapleton

branch main Branches Tags History

omega-mv / bridge / cuda / EXTENSION-PROPOSAL.md

118 lines · 6915 bytes Raw Blame History Source

Extension proposal: omc emits a C-ABI shared library

CUDApp's compat/nvml/libnvidia-ml.c is C generated by the omega-bridge cabi-1 emitter from the Omega unit already in this tree, gpu/nvidia/native/nvml/api.om (with nvml.om, query.om, step.om, errstr.om). The C exists for one reason: seed/out/omc cannot write a shared library that a C program loads with dlopen or links with -lnvidia-ml. This file records what omc emits today, the smallest program that shows the gap, and the extension that closes it. Until that extension exists the generated C stays in CUDApp and is not copied here.

What the in-tree omc emits today

Compiler: seed/out/omc, sha256 26540e6de62402d5784b30b24d7c6faae488137c1f8a4b3e784fd0b5d5528991 (omega-mv 2ee0a70d). Measured 2026-11-14 on an aarch64 Linux host.

Program mode (a unit with fn main): a static AArch64 executable.

$ printf 'fn main to int\nret 0\nend\n' | seed/out/omc > p.bin; readelf -h p.bin | grep -E 'Type|Machine'
  Type:                              EXEC (Executable file)
  Machine:                           AArch64
$ readelf -lW p.bin | grep -E 'LOAD|DYNAMIC|INTERP'
  LOAD  0x000000 0x0000000000400000 0x0000000000400000 0x0000d4 0x0000d4 R E 0x1000
  LOAD  0x000000 0x0000000010000000 0x0000000010000000 0x000000 0x800000 RW  0x1000
$ readelf -SW p.bin
There are no sections in this file.

ET_EXEC, two PT_LOAD, no PT_INTERP, no PT_DYNAMIC, no sections, no symbols.

Function mode (no fn main; export fn in OM-2): raw machine words, no file header. The words start with one branch per export fn, in source order, to that function's body; the host must know the offsets.

$ cat nvml_shutdown.om
om2
note smallest shared-library request: one C-ABI export the NVML subset needs
export fn nvmlShutdown to int
ret 0
end
$ seed/out/omc < nvml_shutdown.om > out.bin; echo rc=$?; wc -c < out.bin; od -An -tx1 out.bin
rc=0
12
 01 00 00 14 00 00 80 d2 c0 03 5f d6
$ readelf -h out.bin
readelf: Error: out.bin: Failed to read file header

(b +4; mov x0, #0; ret. With two exports the output starts 02 00 00 14 03 00 00 14.) sha256: nvml_shutdown.om 3908d946…a84a48a58, out.bin 323a7cc8…a586839.

Calling a C function the unit does not define is refused:

$ printf 'om2\nexport fn nvmlShutdown to int\nret omega2_nvrm_close_file 3\nend\n' | seed/out/omc > imp.bin
omc: line 3: error 3

And the export count is capped: 32 export fn compile, the 33rd is omc: line 98: error 14.

What it cannot emit, against what libnvidia-ml.so.1 needs

Needed by the NVML libraryomc today
ET_DYN file, position independent, loadable by ld.sono: ET_EXEC at fixed addresses, or headerless words
PT_DYNAMIC with DT_SONAME libnvidia-ml.so.1, DT_SYMTAB, DT_STRTAB, DT_HASH/DT_GNU_HASHno dynamic segment at all
The named exports of libnvidia-ml.map (nvmlInit_v2 … nvmlDeviceGetComputeRunningProcesses_v3), and nothing else exported (the .map's local: *;)exports are unnamed branch slots, of a number fixed by omc
AAPCS64 calls in: arguments in x0..x7, pointers into the caller's memory, int32 status returnsthe slot calling convention is omc's own; not checked against AAPCS64
Imports resolved at load: omega2_nvrm_open_file, omega2_nvrm_close_file, omega2_nvrm_ioctl (from the loading process)a name the unit does not define is error 3
Process-wide lock around shared state (note cabi lock NvLock process mutex; the C uses pthread_mutex_*) and per-thread trap recovery (the C uses _Thread_local and setjmp)x = atomic, cas, futex, thread, lock, syscall are each error 3 (unknown name); seed/omc/omc.om:8129: "No raw address or arbitrary syscall is exposed to an Omega program."
Writable process state (the globals NvS, NvB, NvR, NvT, NvO of api.om, sized there) relocated with the libraryprogram mode puts writable data in a PT_LOAD at the fixed address 0x10000000 (above); function mode output carries no data segment or relocations

The extension

A third output mode of omc, selected by a unit-level line (proposed spelling, to be checked against the keyword table before it is added):

library libnvidia-ml.so.1
import fn omega2_nvrm_ioctl fd int nr uint hl view uchar * pl view uchar * to int
export fn nvmlShutdown to int
...
  1. library NAME makes the output an AArch64 ET_DYN ELF with DT_SONAME NAME, one PT_LOAD for code, one for data and PT_DYNAMIC; all code position independent (adrp/add for globals), globals in the library's own writable segment with R_AARCH64_RELATIVE where needed.
  2. Each export fn becomes a .dynsym entry STB_GLOBAL STT_FUNC with its name; every other function is local, which is what the version script did. The export count is sized from the unit (no limit of 32; per the no-hard-caps rule an alarm test replaces it).
  3. Each import fn adds an undefined .dynsym entry, a PLT stub and an R_AARCH64_JUMP_SLOT relocation; import fn … from LIB adds DT_NEEDED LIB. Without from, the symbol is resolved from the loading process, as api.om's transport imports are.
  4. Exports and imports follow AAPCS64: integer and pointer arguments in x0..x7, result in x0, x19..x28 and sp preserved. view T * maps to one pointer argument plus a length argument, as cabi-1's span does.
  5. A lock NAME word in library mode lowers to a futex-based mutex (svc with __NR_futex), so no libc import is needed; trap recovery uses a per-thread slot reached through tpidr_el0.

The dynamic-section layout is not new work: bridge/cuda/fixture.om already writes an ET_DYN library from Omega (the link-only libcuda.so.1 stub: .dynstr, .dynsym, .hash, .dynamic with DT_SONAME, symbols in GNU ld's own order). The bridge-cuda gate's oracle tier (run with BRIDGE_CUDA_CUDAPP and BRIDGE_CUDA_OLDOMC set) shows gcc links against it to the byte-identical executables of the frozen profiles; a default run does not run gcc and does not show this. The compiler change adds code, relocations and imports to that layout.

How it would be accepted

Status: PROPOSED. Nothing above is implemented; the measurements in the first section are EXERCISED with the commands shown.