interplane.Get Omega
Read in your language

omega-bridge

Omega-first language interoperability: checked conversion backends and native language bindings

Brought by drakestapleton

branch main Branches Tags History

omega-bridge / docs / OMEGA-TORCH.md

70 lines · 4317 bytes Raw Blame History Rendered
1# Omega under PyTorch: `torch.compile(model, backend="omega")` (milestone 1)
2
3Status: IMPLEMENTED and EXERCISED on CPU only (AArch64, DGX Spark host), oracle = PyTorch eager,
4Omega-native codegen, Python glue. Not qualified, not merged, not a claim that Omega runs PyTorch in
5general: it runs the core-ATen ops listed below, float32, static shapes, inference only.
6
7## What runs where
8
9| Layer | Implementation | Status |
10|---|---|---|
11| Kernels (`pytorch/kernels/*.om`) | seeded Omega, compiled by omega-mv `seed/out/omc` in function mode to AArch64 words | first-party |
12| Binding (`src/native.om`) | Omega program that writes the C trampoline of native call ABI v1 (`docs/NATIVE-ABI.md`) | first-party; the C it writes is compiled by the host `cc` |
13| Backend glue (`pytorch/omega_torch/__init__.py`) | Python: registers the backend, walks the FX graph, allocates outputs, calls units through `ctypes` | interim migration step |
14
15The glue computes no tensor value. Every value in an output was written by Omega machine code;
16the glue only reads shapes, picks a kernel, supplies the shape constants as a `const NAME ulong N`
17header in front of the fixed kernel text, and passes buffer addresses.
18
19## Ops
20
21Covered (core ATen after `core_aten_decompositions()`): `aten.mm`, `aten.addmm` (1-D bias, beta = alpha
22= 1), `aten.permute` (2-D, dims `[1, 0]`), `aten.add.Tensor` (equal shapes, alpha 1), `aten.relu`,
23`aten._softmax` (2-D, last dim, `half_to_float` false). `addmm(b, x, permute(W, [1, 0]))` whose
24permute has no other user is lowered to the `linear` kernel, which reads `W` in place.
25
26Refused at compile time, with every refused node listed and nothing run: any other op, broadcasting,
27non-float32 dtypes, non-CPU devices, symbolic shapes (`dynamic=False` is required), empty tensors,
28tensors above the Omega array limit of 16,777,216 elements (OMEGESE 9.4), softmax rows above the 4 MiB
29local-array limit, non-contiguous inputs (at run time), autograd (run under `torch.no_grad()`), and a
30visible CUDA device. Eager fallback exists only for ops named in `OMEGA_TORCH_FALLBACK` (or
31`omega_torch.set_fallback`), and every such call is counted in `STATS["eager_fallback_calls"]`.
32
33Numerics: each dot product and softmax sum is accumulated in f64 and rounded once to f32. `exp` is
34written in Omega (`expd` in `softmax.om`): range reduction by ln 2, degree-13 Taylor polynomial
35(truncation below 5.9e-18 relative), exponent bits for 2^k.
36
37## Use
38
39```sh
40export CUDA_VISIBLE_DEVICES= # TorchDynamo touches CUDA while tracing; milestone 1 is CPU only
41export OMEGA_OMC=/path/to/omega-mv/seed/out/omc # sha256 2c82480596bbdc50cda9626866209ef662d5834f278f839ff4ce0250c495029f
42python3 -m unittest -v pytorch/tests/test_omega_torch.py
43```
44
45```python
46import sys; sys.path.insert(0, "pytorch")
47import omega_torch # registers backend "omega"
48with torch.no_grad():
49 y = torch.compile(model, backend="omega", fullgraph=True, dynamic=False)(x)
50```
51
52Built units are cached under `build/torch/<sha256 of unit source, compiler pin and native.om>`.
53
54## Host dependencies
55
56| Dependency | Version used | What it does here | Omega successor |
57|---|---|---|---|
58| PyTorch | 2.14.0+cu130 | TorchDynamo capture, AOTAutograd core-ATen decomposition, tensor allocation, the eager oracle | the oracle stays; capture moves behind a PrivateUse1 `omega` device whose dispatch is an Omega unit |
59| CPython | 3.12.3 | runs the glue and `ctypes` | the glue's graph walk and dispatch move into an Omega unit called through the same C ABI |
60| `cc` (GCC) | system | compiles the C trampoline `src/native.om` writes | an Omega-emitted ELF shared object (the trampoline is a fixed instruction sequence) |
61
62## Successor
63
64The Python glue is interim. The successor is a PrivateUse1 out-of-tree device `omega`
65(`torch.utils.rename_privateuse1_backend("omega")`) whose operator registrations are a fixed C ABI
66table generated by the bridge, with lowering, shape specialisation and dispatch done by an Omega unit.
67That keeps the PyTorch-required registration as the only foreign code and lets eager ops and
68`torch.compile` graphs share one Omega dispatcher. Later targets (GB10 SASS, SPIR-V, StableHLO,
69Tenstorrent, NKI) plug in at the kernel layer, unchanged above it. GPU runs are NOT_RUN: they need an
70authorized window.