interplane.Get Omega
Read in your language

aienos.com

Source of www.aienos.com, served from my own hardware

Brought by drakestapleton

branch main Branches Tags History

aienos.com / om / alpha-page / main.html

4932 lines · 100280 bytes Raw Blame History
1<article class="alpha"><header class="alpha-hero"><p class="alpha-kicker">SOVEREIGN INTELLIGENCE / BUILT ON AienOS</p><h1>Sovereign<br><span>Intelligence.</span></h1><p class="alpha-lead">Alpha testing is open for the DGX Spark GB10. Read the release scope and receipts below.</p><div class="alpha-install"><code id="alpha-command">git clone --branch alpha-20261026.2 https://interplane.io/drakestapleton/sovereign-intelligence &amp;&amp; cd sovereign-intelligence &amp;&amp; sh installer/install.sh</code><button id="alpha-copy" type="button">Copy command</button></div><p id="alpha-copy-status" class="alpha-copy-status" role="status" aria-live="polite"></p><p class="alpha-small">Linux arm64 + NVIDIA GB10 only. Experimental software, installed beside your existing stack. Everything comes from the public GitHub repo <a href="https://interplane.io/drakestapleton/sovereign-intelligence">aien-dev/sovereign-intelligence</a>, so you can read it before you run it: <a href="https://interplane.io/drakestapleton/sovereign-intelligence/blob/alpha-20261026.2/installer/install.sh">read installer/install.sh first</a>. It downloads only this tag's signed release from GitHub and checks the signature and SHA-256 before it unpacks anything. Nothing is downloaded from this website.</p><p class="alpha-payoff">Meet Aien on your own Spark.</p><p class="alpha-small"><strong>Coming in the next update:</strong> Aien's black hole, glass panes, science tools and Omega, running locally. This release installs the engine and Omega wizard, not the Aien experience yet.</p><a class="alpha-scroll" href="#alpha-next">See what happens next ↓</a></header>
2<figure class="alpha-scene" aria-labelledby="alpha-scene-caption"><div class="alpha-space" aria-hidden="true"><svg class="alpha-orbits" viewBox="0 0 1000 500" fill="none"><ellipse cx="500" cy="250" rx="445" ry="125"/><ellipse cx="500" cy="250" rx="360" ry="95"/><ellipse cx="500" cy="250" rx="270" ry="65"/><path d="M35 110 Q500 480 965 110 M35 390 Q500 20 965 390"/></svg><div class="alpha-disc"></div><div class="alpha-hole"></div><div class="alpha-infall"><span data-stack="0">INFERENCE</span><span data-stack="1">DRIVER CALLS</span><span data-stack="2">MATH KERNELS</span><span data-stack="3">ENCODER</span></div><div class="alpha-kept"><span>YOUR GPU / STAYS</span><span>KERNEL DRIVER / STAYS</span></div></div><figcaption id="alpha-scene-caption"><strong>The event horizon is a metaphor.</strong> This animation represents the inference path I am building for the DGX Spark GB10. The installation keeps the existing system packages and GPU driver.</figcaption><button class="alpha-motion" id="alpha-motion" type="button" aria-pressed="false">Play the event horizon</button></figure>
3<section class="alpha-section" id="alpha-next"><p class="alpha-kicker">01 / THE ARRIVAL</p><h2>One download. Then a walkthrough.</h2><ol class="alpha-steps"><li><span>DOWNLOAD</span><h3>Clone it from GitHub.</h3><p>git fetches the installer's readable source from the public repo. install.sh checks your machine, downloads the signed bundle from GitHub Releases, verifies it, then adds a launcher at user level.</p></li><li><span>DOUBLE-CLICK</span><h3>Open the launcher.</h3><p>Open Sovereign Intelligence from your applications menu. The terminal wizard shows what it will change before asking for consent.</p></li><li><span>WIZARD</span><h3>Make the first run yours.</h3><p>Doctor, plan, consent, install, model download, first chat. The wizard names the download and its size before you agree.</p></li></ol><div class="alpha-capture"><p class="alpha-terminal-bar">SOVEREIGN INTELLIGENCE / OMEGA TERMINAL WIZARD</p><img src="/alpha/wizard-plan.svg" width="900" height="612" loading="lazy" decoding="async" alt="Captured Omega wizard plan screen: a black hole and its accretion disk above the plan, which lists the release and model paths and leaves NVIDIA packages untouched."><details><summary>Read the captured terminal text</summary><pre>▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
4▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
5▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
6▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
7▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
8▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
9▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
10▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
11▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
12▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
13▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
14▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀CUDA toolkit▀▀▀▀▀▀▀cuBLAS▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
15▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
16▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
17▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
18▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
19▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
20▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
21 Sovereign Intelligence alpha step 3 of 8 plan written in Omega (.om)
22 Here is exactly what changes, all inside your home folder:
23
24 ~/.local/share/aienos/releases/alpha-20261026.2 this release, already unpacked and checked
25 ~/.local/share/aienos/models/qwen3.6-35b-a3b-fp8-95a723d0
26 the model: 37.5 GB in 56 files.
27 ~/.local/share/aienos/engine.log the engine's log, when it runs
28 ~/.local/bin/aienos, the menu entry and the desktop icon (already there)
29
30 Not touched: NVIDIA's driver, the CUDA toolkit, libcuda, cuBLAS, /usr, /etc. No sudo.
31 Undo everything at any time: aienos uninstall
32
33
34
35
36 &gt; Press Enter for the last question
37</pre></details></div><p class="alpha-small">Captured from the real Omega wizard in a fake-root host run, built from sovereign-intelligence 38071e3 with the redrawn black hole. That drawing ships in the next alpha; alpha-20261026.2 still draws the older one. This is not a GPU installation receipt.</p></section><section class="alpha-section" id="alpha-hardware"><p class="alpha-kicker">02 / KNOW THE BOUNDARY</p><h2>One machine family first.</h2><div class="alpha-columns"><div><h3>NVIDIA DGX Spark / GB10</h3><p>The install target is Linux arm64 with an NVIDIA GB10 (PCI 10de:2e12) and NVIDIA kernel driver 580.173.02. The doctor refuses machines with less than 64 GiB of memory and warns when the GB10 has less than 61,309 MiB free. I am not offering a Windows, macOS, x86 Linux or other-GPU installer yet. Unsupported machines receive a friendly “not yet” without an installation.</p><p>The model is <strong>Qwen3.6-35B-A3B-FP8</strong>, pinned to revision <code>95a723d0</code>: 37,493,015,668 bytes in 56 files, each hash-checked. The plan asks for that size plus 1 GB of free disk. No other model is offered in this release. I retired this outside model on 2026-11-06, and my Spark no longer serves it, so <code>alpha-20261026.2</code> is now a historical pre-release. The model is meant to be the Omega LLM, my own, and no release carries it yet: its server, <code>ollm serve</code>, has run on my Spark's CPU only and is not deployed (<a href="https://interplane.io/drakestapleton/aien-train/tree/0518c915dea370b3bffbb90d579b1daa5ba8b8f5/evidence/OMEGALLM/serve">receipts</a> <code>aien-train 0518c915dea370b3bffbb90d579b1daa5ba8b8f5</code>).</p><h3>What is coming for other machines?</h3><p><strong>PROPOSED:</strong> more hardware and operating systems, after a working port and device-specific evidence. I will not label a machine supported because the code compiles. Tell me which machine you want to test (<code>omega-projects issues</code>).</p></div><aside class="alpha-evidence"><p class="alpha-kicker">EVIDENCE, NOT A PROMISE</p><h3>Alpha is a testing phase.</h3><p><strong>EXERCISED:</strong> the bundled engine <code>19173f9e</code> is byte for byte the build that served this 35B on my Spark until I retired that model on 2026-11-06, and I rebuilt it byte-identically from Core commit <code>59b05a71</code>. That is a development build, not a Core release tag.</p><p><strong>EXERCISED:</strong> installer, wizard and uninstaller on a fake GB10 tree (33/33), plus a stock Ubuntu 24.04 arm64 container (6/6 with a negative control). The first chat ran only against a fake engine.</p><p><strong>NOT_RUN:</strong> a real GB10 install from this installer, its 37.5 GB download and first token, and three-pass physical qualification. I am not calling this installer hardware-qualified.</p><p><a href="https://interplane.io/drakestapleton/sovereign-intelligence/tree/alpha-20261026.2">Release, exact artifacts and evidence</a> <code>sovereign-intelligence 9335a4be7eb6</code></p></aside></div><p class="alpha-small"><a href="https://interplane.io/drakestapleton/sovereign-intelligence">Sovereign Intelligence is the front door</a>. AienOS is its OS layer; Aien, Omega, aien-math and CUDA++ keep their own identities. Read my project audit (<code>sovereign-intelligence main docs/WHAT-I-AM-BUILDING.md</code>).</p></section>
38<section class="alpha-section" id="alpha-source"><p class="alpha-kicker">03 / NOTHING BEHIND THE CURTAIN</p><h2>Built entirely in Omega.</h2><p class="alpha-lead">The walkthrough wizard is a seeded <code>.om</code> program. This page's structure and small motion client are generated by Omega too. Read the source, keep a copy, change it.</p><p>I mean the wizard, not every dependency in the delivery chain: the download bootstrap is POSIX sh, the website builder is Rust, and the host still supplies Linux, a terminal, signature verification and the NVIDIA kernel driver. Those boundaries are explicit.</p><p>The wizard source below targets seeded Omega compiler revision <code>3364a1dfd</code>. This page generator uses its separately pinned compiler; they are not interchangeable.</p><div class="alpha-links"><a href="https://interplane.io/drakestapleton/sovereign-intelligence/tree/alpha-20261026.2/installer/wizard">Browse the wizard source</a><code>sovereign-intelligence release alpha-20261026.2/aienos.om</code><a href="https://interplane.io/drakestapleton/aienos.com/tree/main/om/alpha-page">Read this page's Omega</a></div><p class="alpha-small">aienos.om is the wizard as one plain-text file, SHA-256 <code>d7459752ee454aab116b60c7e5fa7ad7e7a591c2fc52342ea0483590ea91b120</code>, listed in the release's signed SHA256SUMS.</p><details class="alpha-source"><summary>Read the wizard's .om source</summary><pre><code>note SPDX-License-Identifier: Apache-2.0
39note sha256.om: vendored from aien-dev/omega-mv 3364a1dfd0ca50c1b82bf19ba34932d8bc10a7a9 om/sha256/sha256-om2.om
40note (source sha256 dbf002dd6aa36585632b9d01d98ac3f0bd2fa0f0475082940de53638847994bb). Derived mechanically: every "export fn" became "fn", because a
41note program-mode unit (one with fn main) refuses export (OMEGESE 9.13, error 9). build.sh re-derives
42note this file from the pinned source and refuses any other difference.
43note SPDX-License-Identifier: Apache-2.0
44note sha256-om2.om: FIPS 180-4 SHA-256 in OM-2 (spec/omegese-om2.md, &#35;747/&#35;748, ledger L838).
45note The four entries are the API of src/sha256.h, exported through omega-bridge ABI v2 as
46note omega2_sha256_init/update/final/hash; the bridge's generated omega_api.h maps the C names.
47note
48note Invariants:
49note - All hashing state is the caller's 104-byte context (layout shactx below, equal to sha256_ctx
50note on LP64 AArch64). Nothing else persists between calls, so a byte copy of a live context is an
51note equivalent context (erratum E3).
52note - count is the number of bytes absorbed since init, modulo 2^64. buf[0 .. count mod 64) holds the
53note pending bytes of the current block; the rest of buf is unspecified. state is the chaining value
54note after the count div 64 whole blocks.
55note - final reads the context and writes only the digest, so the context is unchanged by it. The
56note contract promises less (after final the context is unspecified, memory safety only).
57note - Every branch and every loop count depends only on lengths, never on message bytes (section 8).
58note - Indices into the unsized input view are checked at run time (trap 3); indices into sized
59note arrays inside unrolled bodies are constants and checked when compiled.
60note bridge c-type shactx sha256_ctx
61note bridge c-define SHA256_DIGEST_SIZE 32
62note bridge c-define SHA256_BLOCK_SIZE 64
63om2
64
65layout shactx 104
66field state uint 8 at 0 little
67field count ulong at 32 little
68field buf uchar 64 at 40 little
69end
70
71note K[0..63]: the first 32 bits of the fractional parts of the cube roots of the first 64 primes.
72note Copied mechanically from seed/qualification/om2/fixtures/sha256-k.dec (tool-computed, never typed).
73fn kinit k edit uint 64 to void
74put k 0 0x428a2f98
75put k 1 0x71374491
76put k 2 0xb5c0fbcf
77put k 3 0xe9b5dba5
78put k 4 0x3956c25b
79put k 5 0x59f111f1
80put k 6 0x923f82a4
81put k 7 0xab1c5ed5
82put k 8 0xd807aa98
83put k 9 0x12835b01
84put k 10 0x243185be
85put k 11 0x550c7dc3
86put k 12 0x72be5d74
87put k 13 0x80deb1fe
88put k 14 0x9bdc06a7
89put k 15 0xc19bf174
90put k 16 0xe49b69c1
91put k 17 0xefbe4786
92put k 18 0x0fc19dc6
93put k 19 0x240ca1cc
94put k 20 0x2de92c6f
95put k 21 0x4a7484aa
96put k 22 0x5cb0a9dc
97put k 23 0x76f988da
98put k 24 0x983e5152
99put k 25 0xa831c66d
100put k 26 0xb00327c8
101put k 27 0xbf597fc7
102put k 28 0xc6e00bf3
103put k 29 0xd5a79147
104put k 30 0x06ca6351
105put k 31 0x14292967
106put k 32 0x27b70a85
107put k 33 0x2e1b2138
108put k 34 0x4d2c6dfc
109put k 35 0x53380d13
110put k 36 0x650a7354
111put k 37 0x766a0abb
112put k 38 0x81c2c92e
113put k 39 0x92722c85
114put k 40 0xa2bfe8a1
115put k 41 0xa81a664b
116put k 42 0xc24b8b70
117put k 43 0xc76c51a3
118put k 44 0xd192e819
119put k 45 0xd6990624
120put k 46 0xf40e3585
121put k 47 0x106aa070
122put k 48 0x19a4c116
123put k 49 0x1e376c08
124put k 50 0x2748774c
125put k 51 0x34b0bcb5
126put k 52 0x391c0cb3
127put k 53 0x4ed8aa4a
128put k 54 0x5b9cca4f
129put k 55 0x682e6ff3
130put k 56 0x748f82ee
131put k 57 0x78a5636f
132put k 58 0x84c87814
133put k 59 0x8cc70208
134put k 60 0x90befffa
135put k 61 0xa4506ceb
136put k 62 0xbef9a3f7
137put k 63 0xc67178f2
138end
139
140note H(0): the first 32 bits of the fractional parts of the square roots of the first 8 primes
141note (fixtures/sha256-iv.dec).
142fn iv s edit uint 8 to void
143put s 0 0x6a09e667
144put s 1 0xbb67ae85
145put s 2 0x3c6ef372
146put s 3 0xa54ff53a
147put s 4 0x510e527f
148put s 5 0x9b05688c
149put s 6 0x1f83d9ab
150put s 7 0x5be0cd19
151end
152
153note Message schedule of the block m[o .. o+64). w is fresh: its incoming contents are never read.
154note The compiler proves that every get of w reads an element written earlier in this function
155note (error 27 otherwise): w[0..16) are the block's big-endian words, w[16..64) the FIPS recurrence.
156fn sched w edit uint 64 fresh m view uchar * o ulong to void
157q = ulong 0
158x = uint 0
159y = uint 0
160for i ulong 16 unroll
161q = add o mul i 4
162x = uint get m q
163x = or shl x 8 uint get m add q 1
164x = or shl x 8 uint get m add q 2
165put w i or shl x 8 uint get m add q 3
166end
167for i ulong 48 unroll
168x = get w add i 1
169y = get w add i 14
170x = add add get w i get w add i 9 xor xor rotr x 7 rotr x 18 shr x 3
171put w add i 16 add x xor xor rotr y 17 rotr y 19 shr y 10
172end
173end
174
175note The 64 rounds on the chaining value s. One round body, emitted 64 times by unroll; i is a constant
176note in each copy, so get kt i and get w i need no run-time check. uint arithmetic wraps mod 2^32.
177note Ch(e,f,g) = (e and f) xor (not e and g) is written g xor (e and (f xor g)); Maj(a,b,c) =
178note (a and b) xor (a and c) xor (b and c) is written (a and b) or (c and (a or b)). Both are bitwise
179note identities. h first becomes T1, then T1 + T2, which is the next a; the names then shift by one.
180note The sums are built a term per line and each Sigma in two lines through t: 12 names are live, and
181note omc hands out 16 registers with no spilling (error 12 under compiler-s1/s2 for longer lines).
182fn rounds s edit uint 8 w view uint 64 kt view uint 64 to void
183a = get s 0
184b = get s 1
185c = get s 2
186d = get s 3
187e = get s 4
188f = get s 5
189g = get s 6
190h = get s 7
191t = uint 0
192for i ulong 64 unroll
193h = add h get kt i
194h = add h get w i
195t = xor rotr e 6 rotr e 11
196t = xor t rotr e 25
197h = add h t
198h = add h xor g and e xor f g
199d = add d h
200t = xor rotr a 2 rotr a 13
201t = xor t rotr a 22
202h = add h t
203t = and c or a b
204h = add h or and a b t
205t = h
206h = g
207g = f
208f = e
209e = d
210d = c
211c = b
212b = a
213a = t
214end
215put s 0 add get s 0 a
216put s 1 add get s 1 b
217put s 2 add get s 2 c
218put s 3 add get s 3 d
219put s 4 add get s 4 e
220put s 5 add get s 5 f
221put s 6 add get s 6 g
222put s 7 add get s 7 h
223end
224
225note One block m[o .. o+64) into s. sched and rounds stay calls: inlined, their names would share
226note one 16-register frame with this function's parameters (no spilling, error 12).
227fn compress s edit uint 8 w edit uint 64 kt view uint 64 m view uchar * o ulong to void
228sched w m o
229rounds s w kt
230end
231
232note The whole blocks of m (len m is a multiple of 64 and at most 2^25, so under 2^19 passes).
233fn run s edit uint 8 w edit uint 64 kt view uint 64 m view uchar * to void
234for j ulong shr len m 6
235compress s w kt m shl j 6
236end
237end
238
239note The whole blocks of m (len m a multiple of 64). A rolled loop traps 4 after 1000000 passes
240note (OMEGESE.md section 2; omc s_for), so m is cut into runs of 2^25 bytes (2^19 blocks):
241note len m = top * 2^44 + mid * 2^25 + rest, and no loop passes 2^20 times. top reaches 1000000
242note only above 1.7e19 bytes, which no AArch64 address space holds.
243fn blocks s edit uint 8 w edit uint 64 kt view uint 64 m view uchar * to void
244q = ulong 0
245for a ulong shr len m 44
246for b ulong 0x80000
247run s w kt part m q 0x2000000
248q = add q 0x2000000
249end
250end
251for b ulong and shr len m 25 0x7ffff
252run s w kt part m q 0x2000000
253q = add q 0x2000000
254end
255run s w kt part m q sub len m q
256end
257
258note Pad the k pending bytes already in p (k &lt; 64; p was all zero past them): 0x80, zeros, and the
259note 64-bit big-endian bit length of the n-byte message in the last 8 bytes of one or two blocks.
260fn finish s edit uint 8 w edit uint 64 kt view uint 64 p edit uchar 128 k ulong n ulong to void
261put p k 0x80
262e = ulong 64
263if ge k 56
264e = 128
265end
266bits = shl n 3
267for i ulong 8 unroll
268put p sub e add i 1 uchar and shr bits mul i 8 0xff
269end
270compress s w kt view p 0
271if eq e 128
272compress s w kt view p 64
273end
274end
275
276fn sha256_init c edit shactx to void
277s = new uint 8 0
278iv s
279for i ulong 8 unroll
280put c state i get s i
281end
282put c count 0
283end
284
285note k bytes of d from o into the context's buffer at bi (bi + k &lt;= 64). A function of its own: inside
286note absorb the copy loop needs more than the 16 registers (error 12 under compiler-s4).
287fn tobuf c edit shactx bi ulong d view uchar * o ulong k ulong to void
288for i ulong k
289put c buf add bi i get d add o i
290end
291end
292
293note Whole blocks are hashed straight from d; the bytes that complete a pending block go through blk.
294fn absorb c edit shactx d view uchar * bi ulong to void
295n = len d
296s = new uint 8 0
297w = new uint 64 0
298kt = new uint 64 0
299blk = new uchar 64 0
300kinit kt
301for i ulong 8 unroll
302put s i get c state i
303end
304off = ulong 0
305if gt bi 0
306off = sub 64 bi
307for i ulong bi
308put blk i get c buf i
309end
310for i ulong off
311put blk add bi i get d i
312end
313compress s w kt view blk 0
314end
315nb = shr sub n off 6
316blocks s w kt part d off shl nb 6
317off = add off shl nb 6
318tobuf c 0 d off sub n off
319for i ulong 8 unroll
320put c state i get s i
321end
322end
323
324note Any length, including 0 and &gt;= 2^32. lt n sub 64 bi cannot wrap (bi &lt; 64); add bi n could.
325fn sha256_update c edit shactx d view uchar * to void
326n = len d
327cnt = get c count
328bi = and cnt 63
329put c count add cnt n
330if lt n sub 64 bi
331tobuf c bi d 0 n
332ret
333end
334absorb c d bi
335end
336
337fn sha256_final c edit shactx o out uchar 32 to void
338s = new uint 8 0
339w = new uint 64 0
340kt = new uint 64 0
341p = new uchar 128 0
342v = ulong 0
343kinit kt
344for i ulong 8 unroll
345put s i get c state i
346end
347cnt = get c count
348k = and cnt 63
349for i ulong k
350put p i get c buf i
351end
352finish s w kt p k cnt
353for i ulong 8 unroll
354v = ulong get s i
355for j ulong 4 unroll
356put o add mul i 4 j uchar and shr v sub 24 mul j 8 0xff
357end
358end
359end
360
361note Equal to init, update(d), final on a fresh context (section 7), with the state in locals. o may
362note overlap d: the binding copies o out only after the call returns status 0.
363fn sha256_hash d view uchar * o out uchar 32 to void
364s = new uint 8 0
365w = new uint 64 0
366kt = new uint 64 0
367p = new uchar 128 0
368v = ulong 0
369kinit kt
370iv s
371n = len d
372nb = shr n 6
373blocks s w kt part d 0 shl nb 6
374off = shl nb 6
375k = sub n off
376for i ulong k
377put p i get d add off i
378end
379finish s w kt p k n
380for i ulong 8 unroll
381v = ulong get s i
382for j ulong 4 unroll
383put o add mul i 4 j uchar and shr v sub 24 mul j 8 0xff
384end
385end
386end
387note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
388note lib.om: the output buffer, numbers, ANSI escapes, paths, files, environment and child
389note processes shared by every screen of the AienOS wizard. Linux arm64 only; every kernel result is
390note a count or minus the Linux errno and is checked where it is used.
391
392global ob uchar 262144
393global obn ulong 1
394global pb uchar 4096
395global pbn ulong 1
396global rb uchar 524288
397global rbn ulong 1
398global hb uchar 1024
399global hbn ulong 1
400global rt uchar 1024
401global rtn ulong 1
402global pr uchar 512
403global prn ulong 1
404global ib uchar 4096
405global ibn ulong 1
406global eb uchar 4096
407global pk uchar 4096
408global pkn ulong 1
409global sb uchar 128
410global ws uchar 8
411global sn int 64
412text tslash "/"
413text t_yes "yes"
414text tusrbin "/usr/bin/"
415text tbin "/bin/"
416
417note Append t to the output buffer. A frame never comes near the 256 KiB cap; past it the
418note bytes are dropped rather than trapping, and the next flush starts clean.
419fn emit t view uchar * to void
420n = get obn 0
421if gt add n len t len ob
422ret
423end
424for i ulong len t
425put ob add n i get t i
426end
427put obn 0 add n len t
428end
429
430fn putb b uchar to void
431n = get obn 0
432if lt n len ob
433put ob n b
434put obn 0 add n 1
435end
436end
437
438note Decimal digits of v, most significant first.
439fn num v ulong to void
440d = new uchar 20 0
441k = ulong 0
442x = v
443while true bound 21
444put d k uchar add rem x 10 48
445k = add k 1
446x = div x 10
447if eq x 0
448break
449end
450end
451for i ulong k
452putb get d sub sub k 1 i
453end
454end
455
456fn snum v long to void
457if lt v 0
458putb 45
459num ulong neg v
460ret
461end
462num ulong v
463end
464
465fn numw v ulong w ulong to void
466x = v
467k = ulong 1
468while ge x 10 bound 21
469x = div x 10
470k = add k 1
471end
472while lt k w bound 64
473putb 32
474k = add k 1
475end
476num v
477end
478
479note Write the whole buffer to fd 1 with a partial-write loop, then empty it.
480fn flush to long
481n = get obn 0
482o = ulong 0
483while lt o n bound 262145
484w = write 1 ob o sub n o
485if le w 0
486put obn 0 0
487ret w
488end
489o = add o ulong w
490end
491put obn 0 0
492ret long n
493end
494
495fn csi to void
496putb 27
497putb 91
498end
499
500fn mv r ulong c ulong to void
501csi
502num r
503putb 59
504num c
505putb 72
506end
507
508fn fg r ulong g ulong b ulong to void
509csi
510putb 51
511putb 56
512putb 59
513putb 50
514putb 59
515num r
516putb 59
517num g
518putb 59
519num b
520putb 109
521end
522
523fn bg r ulong g ulong b ulong to void
524csi
525putb 52
526putb 56
527putb 59
528putb 50
529putb 59
530num r
531putb 59
532num g
533putb 59
534num b
535putb 109
536end
537
538fn sgr0 to void
539csi
540putb 48
541putb 109
542end
543
544fn bold to void
545csi
546putb 49
547putb 109
548end
549
550note Erase from the cursor to the end of the line.
551fn eol to void
552csi
553putb 75
554end
555
556fn cls to void
557csi
558putb 50
559putb 74
560end
561
562note Cursor home with no parameters: every animation frame starts with it.
563fn home to void
564csi
565putb 72
566end
567
568note Alternate screen and hidden cursor on (true) or the user's screen and cursor back (false).
569fn scrn on bool to void
570csi
571putb 63
572num 1049
573if on
574putb 104
575csi
576putb 63
577num 25
578putb 108
579else
580putb 108
581csi
582putb 63
583num 25
584putb 104
585end
586end
587
588note The 64-entry sine table, sin(2 pi k / 64) scaled by 1000, computed with Wolfram:
589note Table[Round[1000*Sin[2 Pi k/64]], {k, 0, 63}]. Only the first quadrant is stored by hand;
590note the rest follows from sin(pi - x) = sin x and sin(x + pi) = -sin x.
591fn sinit to void
592q = new int 17 0
593put q 1 98
594put q 2 195
595put q 3 290
596put q 4 383
597put q 5 471
598put q 6 556
599put q 7 634
600put q 8 707
601put q 9 773
602put q 10 831
603put q 11 882
604put q 12 924
605put q 13 957
606put q 14 981
607put q 15 995
608put q 16 1000
609for k ulong 17
610put sn k get q k
611put sn sub 32 k get q k
612end
613for k ulong 32
614put sn add k 32 neg get sn k
615end
616end
617
618fn isin k ulong to long
619ret long get sn and k 63
620end
621
622fn icos k ulong to long
623ret long get sn and add k 16 63
624end
625
626note Paths: pb is built piece by piece and handed to the host words with its length pbn.
627fn pclr to void
628put pbn 0 0
629end
630
631fn pstr t view uchar * to void
632n = get pbn 0
633if gt add n len t len pb
634trap 3
635end
636for i ulong len t
637put pb add n i get t i
638end
639put pbn 0 add n len t
640end
641
642fn pbyte b uchar to void
643n = get pbn 0
644put pb n b
645put pbn 0 add n 1
646end
647
648fn pnum v ulong to void
649d = new uchar 20 0
650k = ulong 0
651x = v
652while true bound 21
653put d k uchar add rem x 10 48
654k = add k 1
655x = div x 10
656if eq x 0
657break
658end
659end
660for i ulong k
661pbyte get d sub sub k 1 i
662end
663end
664
665fn phome to void
666for i ulong get hbn 0
667pbyte get hb i
668end
669end
670
671fn proot to void
672for i ulong get rtn 0
673pbyte get rt i
674end
675end
676
677note A probe path: the test-only prefix AIENOS_PROBE_ROOT (empty in normal use) then t.
678fn pprobe t view uchar * to void
679pclr
680for i ulong get prn 0
681pbyte get pr i
682end
683pstr t
684end
685
686note Append rb[o .. o+n) to the path.
687fn prb o ulong n ulong to void
688for i ulong n
689pbyte get rb add o i
690end
691end
692
693fn pdrop k ulong to void
694put pbn 0 sub get pbn 0 k
695end
696
697note Stat pb into sb. Returns 0 or minus errno.
698fn pstat to long
699ret stat pb 0 get pbn 0 sb 0 128
700end
701
702note File type bits of the last stat: 4 directory, 2 character device, 8 regular, 10 link.
703fn stype to ulong
704m = or or uint get sb 16 shl uint get sb 17 8 shl uint get sb 18 16
705ret ulong shr and m 61440 12
706end
707
708fn ssize to ulong
709x = ulong 0
710for i ulong 8
711x = or x shl ulong get sb add 48 i mul i 8
712end
713ret x
714end
715
716fn sino to ulong
717x = ulong 0
718for i ulong 8
719x = or x shl ulong get sb add 8 i mul i 8
720end
721ret x
722end
723
724fn pexist to bool
725ret eq pstat 0
726end
727
728note Read the whole file named by pb into rb (at most len rb bytes). Returns the count or -errno.
729fn slurp to long
730put rbn 0 0
731fd = fopen pb 0 get pbn 0 524288 0
732if lt fd 0
733ret fd
734end
735n = ulong 0
736while lt n len rb bound 524289
737k = read int fd rb n sub len rb n
738if lt k 0
739c = fclose int fd
740ret k
741end
742if eq k 0
743break
744end
745n = add n ulong k
746end
747c = fclose int fd
748put rbn 0 n
749ret long n
750end
751
752note Write rb[0 .. n) to the file named by pb, created or truncated, mode 0644.
753fn spill n ulong to long
754fd = fopen pb 0 get pbn 0 525889 420
755if lt fd 0
756ret fd
757end
758o = ulong 0
759while lt o n bound 524289
760k = write int fd rb o sub n o
761if le k 0
762c = fclose int fd
763ret -5
764end
765o = add o ulong k
766end
767c = fclose int fd
768ret 0
769end
770
771note Does rb start, at offset o, with the bytes of t?
772fn rbat o ulong t view uchar * to bool
773if gt add o len t get rbn 0
774ret false
775end
776for i ulong len t
777if ne get rb add o i get t i
778ret false
779end
780end
781ret true
782end
783
784note First offset at or after o where t occurs in rb, or the length of rb's content when absent.
785fn rbfind o ulong t view uchar * to ulong
786n = get rbn 0
787i = o
788while lt i n bound 524289
789if rbat i t
790ret i
791end
792i = add i 1
793end
794ret n
795end
796
797note Does t occur inside rb[o .. e)?
798fn rbin o ulong e ulong t view uchar * to bool
799if lt e len t
800ret false
801end
802i = o
803while le add i len t e bound 524289
804if rbat i t
805ret true
806end
807i = add i 1
808end
809ret false
810end
811
812note Decimal number in rb at o; stops at the first non-digit.
813fn rbnum o ulong to ulong
814x = ulong 0
815i = o
816while lt i get rbn 0 bound 21
817c = get rb i
818if or lt c 48 gt c 57
819break
820end
821x = add mul x 10 ulong sub c 48
822i = add i 1
823end
824ret x
825end
826
827note Copy the environment entry KEY=value whose key is k into eb; returns the value length, or
828note -1 when the key is absent. The value starts at eb[len k + 1].
829fn envget k view uchar * to long
830c = envcnt
831for i ulong ulong c
832n = envread i eb 0 len eb
833if gt n long len k
834m = true
835for j ulong len k
836if ne get eb j get k j
837m = false
838end
839end
840if and m eq get eb len k 61
841ret sub n add long len k 1
842end
843end
844end
845ret -1
846end
847
848note Read one line from fd 0 into ib (without its newline). Returns its length, or -1 at end of input.
849fn rline to long
850n = ulong 0
851put ibn 0 0
852while lt n sub len ib 1 bound 4096
853k = read 0 ib n 1
854if le k 0
855if eq n 0
856ret -1
857end
858break
859end
860if eq get ib n 10
861break
862end
863n = add n 1
864end
865put ibn 0 n
866ret long n
867end
868
869fn ibis t view uchar * to bool
870if ne get ibn 0 len t
871ret false
872end
873for i ulong len t
874if ne get ib i get t i
875ret false
876end
877end
878ret true
879end
880
881note Packed argument lists for execprog: a little-endian u16 count, then u16 length + bytes records.
882fn pkclr to void
883put pk 0 0
884put pk 1 0
885put pkn 0 2
886end
887
888fn pkrec n ulong to ulong
889c = add or uint get pk 0 shl uint get pk 1 8 1
890put pk 0 uchar and c 255
891put pk 1 uchar shr c 8
892o = get pkn 0
893put pk o uchar and n 255
894put pk add o 1 uchar shr n 8
895put pkn 0 add add o 2 n
896ret add o 2
897end
898
899fn pkstr t view uchar * to void
900o = pkrec len t
901for i ulong len t
902put pk add o i get t i
903end
904end
905
906note The current path pb as one argument.
907fn pkpath to void
908o = pkrec get pbn 0
909for i ulong get pbn 0
910put pk add o i get pb i
911end
912end
913
914fn pknum v ulong to void
915pclr
916pnum v
917pkpath
918end
919
920note Exit status from the 4-byte wait status in ws: the exit code, or 128 + signal.
921fn wcode to long
922s = uint get ws 0
923if ne and s 127 0
924ret long add and s 127 128
925end
926ret long uint get ws 1
927end
928
929note Run the packed program in pk with fd 1 and 2 sent to the file named by pb (appended) or, when
930note pb is empty, inherited. Returns the exit status or a negative errno from fork.
931fn runpk to long
932lfd = long -1
933if gt get pbn 0 0
934lfd = fopen pb 0 get pbn 0 525377 420
935if lt lfd 0
936ret lfd
937end
938end
939pid = fork
940if lt pid 0
941ret pid
942end
943if eq pid 0
944if ge lfd 0
945d = dupfd int lfd 1 0
946d = dupfd int lfd 2 0
947end
948r = execprog pk 0 get pkn 0
949exit 127
950end
951if ge lfd 0
952c = fclose int lfd
953end
954r = waitpid int pid ws 0 4 0
955if ne r pid
956ret -10
957end
958ret wcode
959end
960
961note Run pk with its stdout captured into rb (at most len rb bytes); stdin and stderr are inherited.
962note Returns the exit status; rbn holds the captured length.
963fn runcap to long
964put rbn 0 0
965r = pipefds ws 0 8 524288
966if ne r 0
967ret r
968end
969rd = or or uint get ws 0 shl uint get ws 1 8 shl uint get ws 2 16
970wr = or or uint get ws 4 shl uint get ws 5 8 shl uint get ws 6 16
971pid = fork
972if lt pid 0
973ret pid
974end
975if eq pid 0
976d = dupfd int wr 1 0
977r = execprog pk 0 get pkn 0
978exit 127
979end
980c = fclose int wr
981n = ulong 0
982while lt n len rb bound 524289
983k = read int rd rb n sub len rb n
984if le k 0
985break
986end
987n = add n ulong k
988end
989c = fclose int rd
990put rbn 0 n
991r = waitpid int pid ws 0 4 0
992if ne r pid
993ret -10
994end
995ret wcode
996end
997
998note Find a host helper by name in /usr/bin then /bin; leaves its path in pb. False when absent.
999fn findbin t view uchar * to bool
1000pclr
1001pstr tusrbin
1002pstr t
1003if eq faccess pb 0 get pbn 0 1 0
1004ret true
1005end
1006pclr
1007pstr tbin
1008pstr t
1009ret eq faccess pb 0 get pbn 0 1 0
1010end
1011note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
1012note hole.om: the animated black hole. Each terminal cell shows two square pixels with the upper
1013note half block (U+2580): the foreground colour is the upper pixel, the background the lower one.
1014note No floating point and no trigonometry beyond the 64-entry sine table: the angle around the
1015note hole is the integer "diamond angle" (0..255 for one turn), and every radius is compared squared.
1016
1017global gm long 12
1018global tw ulong 1
1019global th ulong 1
1020global tick ulong 1
1021text lb0 "libcuda.so"
1022text lb1 "cuBLAS"
1023text lb2 "nvcc"
1024text lb3 "CUDA toolkit"
1025text lb4 "libcudart"
1026text lb5 "cuDNN"
1027text lb6 "NCCL"
1028text lb7 "TensorRT"
1029text tblk "▀"
1030
1031note gm: 0 cx, 1 cy (pixels), 2 R, 3 horizon^2, 4 photon ring^2, 5 disk inner^2, 6 disk outer^2,
1032note 7 glow^2, 8 scene rows, 9 horizon radius, 10 lensed arc^2.
1033fn hgeom rows ulong to void
1034cx = long div get tw 0 2
1035cy = long rows
1036r = cx
1037if lt cy r
1038r = cy
1039end
1040r = div mul r 95 100
1041rh = div mul r 44 100
1042put gm 0 cx
1043put gm 1 cy
1044put gm 2 r
1045put gm 3 mul rh rh
1046rp = add rh add div r 16 1
1047put gm 4 mul rp rp
1048di = div mul rh 135 100
1049put gm 5 mul di di
1050ro = div mul r 26 10
1051lim = div mul cx 92 100
1052if gt ro lim
1053ro = lim
1054end
1055put gm 6 mul ro ro
1056gl = div mul rp 160 100
1057put gm 7 mul gl gl
1058put gm 8 long rows
1059put gm 9 rh
1060lz = div mul rh 150 100
1061put gm 10 mul lz lz
1062end
1063
1064note Diamond angle of (x, y): 0..255 for one counter-clockwise turn, monotone in the true angle.
1065fn dang x long y long to ulong
1066ax = x
1067if lt ax 0
1068ax = neg ax
1069end
1070ay = y
1071if lt ay 0
1072ay = neg ay
1073end
1074s = add ax ay
1075if eq s 0
1076ret 0
1077end
1078if ge y 0
1079if ge x 0
1080ret ulong div mul 64 ay s
1081end
1082ret ulong add 64 div mul 64 ax s
1083end
1084if lt x 0
1085ret ulong add 128 div mul 64 ay s
1086end
1087ret ulong add 192 div mul 64 ax s
1088end
1089
1090fn pack r long g long b long to ulong
1091ret or or shl ulong r 16 shl ulong g 8 ulong b
1092end
1093
1094note Scale a packed colour by m/1000 and clamp each channel to 255.
1095fn scale c ulong m long to ulong
1096r = div mul long and shr c 16 255 m 1000
1097g = div mul long and shr c 8 255 m 1000
1098b = div mul long and c 255 m 1000
1099if gt r 255
1100r = 255
1101end
1102if gt g 255
1103g = 255
1104end
1105if gt b 255
1106b = 255
1107end
1108if lt r 0
1109r = 0
1110end
1111if lt g 0
1112g = 0
1113end
1114if lt b 0
1115b = 0
1116end
1117ret pack r g b
1118end
1119
1120note One channel of a mix: (x u + y t) / 256.
1121fn mixc x long y long u long t long to long
1122ret div add mul x u mul y t 256
1123end
1124
1125note Mix two packed colours: t/256 of b over a.
1126fn mix a ulong b ulong t long to ulong
1127u = sub 256 t
1128r = mixc long and shr a 16 255 long and shr b 16 255 u t
1129g = mixc long and shr a 8 255 long and shr b 8 255 u t
1130c = mixc long and a 255 long and b 255 u t
1131ret pack r g c
1132end
1133
1134note Accretion disk at (dx, dyd) with dd2 = dx^2 + dyd^2: hot white at the inner edge through orange
1135note to violet at the rim, three spiral arms that wind tighter inward, the approaching side brighter.
1136fn dcol t long to ulong
1137if ge t 128
1138ret mix pack 255 132 36 pack 110 28 120 mul sub t 128 2
1139end
1140ret mix pack 255 240 210 pack 255 132 36 mul t 2
1141end
1142
1143fn dlum dx long dyd long tw2 long to long
1144p = add div dang dx dyd 4 ulong tw2
1145p = add p mul get tick 0 2
1146ret add 640 div mul 360 isin mul p 3 1000
1147end
1148
1149fn diskc dx long dyd long dd2 long to ulong
1150in2 = get gm 5
1151t = div mul sub dd2 in2 256 add sub get gm 6 in2 1
1152c = dcol t
1153i = dlum dx dyd div mul in2 40 add dd2 1
1154dop = sub 1000 div mul dx 350 add get gm 2 1
1155ret scale c div mul i dop 1000
1156end
1157
1158fn shash x ulong y ulong to ulong
1159h = xor mul x 374761393 mul y 668265263
1160h = mul xor h shr h 13 1274126177
1161ret and shr xor h shr h 16 7 2047
1162end
1163
1164fn star x ulong y ulong to ulong
1165h = shash x y
1166if ge h 12
1167ret pack 3 3 10
1168end
1169v = long add 70 mul h 15
1170if eq and shr add get tick 0 mul h 5 3 1 1
1171v = div mul v 2 3
1172end
1173ret pack v v add v 25
1174end
1175
1176note The far side of the disk, bent over and under the shadow by the hole's gravity.
1177fn lensc dx long dy long d2 long to ulong
1178rp2 = get gm 4
1179t = div mul sub d2 rp2 256 add sub get gm 10 rp2 1
1180c = dcol t
1181ret scale c dlum dx mul dy 4 64
1182end
1183
1184note Faint orange halo just outside the photon ring, fading into the stars.
1185fn glow x ulong y ulong d2 long to ulong
1186g7 = get gm 7
1187t = div mul sub g7 d2 200 sub g7 get gm 4
1188ret mix star x y pack 160 60 20 t
1189end
1190
1191note Colour of pixel (x, y) of the scene.
1192fn px x ulong y ulong to ulong
1193dx = sub long x get gm 0
1194dy = sub long y get gm 1
1195d2 = add mul dx dx mul dy dy
1196dyd = mul dy 4
1197dd2 = add mul dx dx mul dyd dyd
1198indisk = and ge dd2 get gm 5 le dd2 get gm 6
1199if and indisk ge dy 0
1200ret diskc dx dyd dd2
1201end
1202if lt d2 get gm 3
1203ret 0
1204end
1205if lt d2 get gm 4
1206f = add 820 div mul 180 isin add div dang dx dy 4 get tick 0 1000
1207ret scale pack 255 226 170 f
1208end
1209if lt d2 get gm 10
1210ret lensc dx dy d2
1211end
1212if indisk
1213ret diskc dx dyd dd2
1214end
1215if lt d2 get gm 7
1216ret glow x y d2
1217end
1218ret star x y
1219end
1220
1221fn hpix c ulong top bool to void
1222r = and shr c 16 255
1223g = and shr c 8 255
1224b = and c 255
1225if top
1226fg r g b
1227else
1228bg r g b
1229end
1230end
1231
1232note Draw the scene rows 1..rows at full terminal width into the output buffer.
1233fn hdraw rows ulong to void
1234lf = ulong 16777216
1235lb = ulong 16777216
1236for row ulong rows
1237mv add row 1 1
1238lf = 16777216
1239lb = 16777216
1240for x ulong get tw 0
1241a = px x mul row 2
1242b = px x add mul row 2 1
1243if ne a lf
1244hpix a true
1245lf = a
1246end
1247if ne b lb
1248hpix b false
1249lb = b
1250end
1251emit tblk
1252end
1253sgr0
1254end
1255end
1256
1257fn lemit i ulong o ulong k ulong to void
1258if eq i 0
1259emit part lb0 o k
1260end
1261if eq i 1
1262emit part lb1 o k
1263end
1264if eq i 2
1265emit part lb2 o k
1266end
1267if eq i 3
1268emit part lb3 o k
1269end
1270if eq i 4
1271emit part lb4 o k
1272end
1273if eq i 5
1274emit part lb5 o k
1275end
1276if eq i 6
1277emit part lb6 o k
1278end
1279if eq i 7
1280emit part lb7 o k
1281end
1282end
1283
1284fn llen i ulong to ulong
1285if eq i 0
1286ret len lb0
1287end
1288if eq i 1
1289ret len lb1
1290end
1291if eq i 2
1292ret len lb2
1293end
1294if eq i 3
1295ret len lb3
1296end
1297if eq i 4
1298ret len lb4
1299end
1300if eq i 5
1301ret len lb5
1302end
1303if eq i 6
1304ret len lb6
1305end
1306ret len lb7
1307end
1308
1309note Label i of the NVIDIA user-space stack spirals inward along the disk plane. It starts green
1310note at the edge of the picture, turns red as it falls, loses letters at the horizon and is gone.
1311fn lfrm i ulong to ulong
1312ret rem add get tick 0 mul i 15 120
1313end
1314
1315fn lrad i ulong to long
1316f = lfrm i
1317ret div mul mul get gm 2 3 long sub 120 f 240
1318end
1319
1320fn lang i ulong to ulong
1321f = lfrm i
1322ret add add mul i 8 div mul f 3 2 div mul f f 90
1323end
1324
1325fn lpos i ulong to void
1326r = lrad i
1327a = lang i
1328x = add get gm 0 div mul r icos a 1000
1329y = add get gm 1 div mul mul r isin a 2 5000
1330rh = get gm 9
1331if or le r rh lt y 0
1332ret
1333end
1334lshow i r x y
1335end
1336
1337fn lshow i ulong r long x long y long to void
1338rh = get gm 9
1339n = llen i
1340k = n
1341if lt r mul rh 2
1342k = ulong div mul long n sub r rh rh
1343end
1344if eq k 0
1345ret
1346end
1347row = add ulong div y 2 1
1348if gt row ulong get gm 8
1349ret
1350end
1351col = sub x long div k 2
1352if or lt col 1 gt add ulong col k get tw 0
1353ret
1354end
1355lpaint i sub n k k lfade r row ulong col
1356end
1357
1358fn lfade r long to long
1359d = mul sub r get gm 9 256
1360t = div d add mul get gm 2 2 1
1361if gt t 256
1362ret 256
1363end
1364ret t
1365end
1366
1367fn lpaint i ulong d ulong k ulong t long row ulong col ulong to void
1368c = mix pack 255 70 30 pack 118 185 0 t
1369mv row col
1370fg and shr c 16 255 and shr c 8 255 and c 255
1371bg 0 0 0
1372bold
1373lemit i div d 2 k
1374sgr0
1375end
1376
1377fn hlabels to void
1378for i ulong 8
1379lpos i
1380end
1381end
1382
1383note One complete frame of the scene: picture, then labels over it.
1384fn hframe rows ulong to void
1385hgeom rows
1386hdraw rows
1387hlabels
1388put tick 0 add get tick 0 1
1389end
1390note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
1391note doctor.om: what this machine is, read only. Nothing here writes a file or loads a library.
1392note Every absolute path goes through pprobe, so a test can point the doctor at a fake tree with
1393note AIENOS_PROBE_ROOT; in normal use that prefix is empty.
1394
1395const NCHK ulong 8
1396global dk ulong 8
1397global dt uchar 1536
1398global dtn ulong 8
1399global dci ulong 1
1400global db uchar 32768
1401global dv ulong 8
1402text c_arch "/proc/sys/kernel/arch"
1403text c_a64 "aarch64"
1404text c_pci "/sys/bus/pci/devices"
1405text c_vend "/vendor"
1406text c_dev "/device"
1407text c_nvv "0x10de"
1408text c_gb10 "0x2e12"
1409text c_dctl "/dev/nvidiactl"
1410text c_dn0 "/dev/nvidia0"
1411text c_duvm "/dev/nvidia-uvm"
1412text c_pdrv "/proc/driver/nvidia/version"
1413text c_mver "/sys/module/nvidia/version"
1414text c_good "580.173.02"
1415text c_mem "/proc/meminfo"
1416text c_mtot "MemTotal:"
1417text c_mav "MemAvailable:"
1418text c_mmap "Mapped:"
1419text c_lock "/tmp/aien-gb10.lock"
1420text c_plk "/proc/locks"
1421text c_cuda "/usr/local/cuda"
1422text c_lcu "/usr/lib/aarch64-linux-gnu/libcuda.so.1"
1423text c_smi "/usr/bin/nvidia-smi"
1424text t_gb " GB"
1425text t_nl "\n"
1426text n_arch "CPU"
1427text n_gpu "GPU"
1428text n_drv "Driver"
1429text n_mem "Memory"
1430text n_disk "Disk"
1431text n_inst "AienOS"
1432text n_busy "GPU lock"
1433text n_nv "NVIDIA"
1434text d_a1 "arm64 (aarch64), Linux"
1435text d_a2 "not arm64: this alpha needs Linux arm64"
1436text d_g1 "NVIDIA GB10 found (PCI 10de:2e12), device nodes present"
1437text d_g2 "no NVIDIA GB10 found: this alpha runs only on a DGX Spark (GB10)"
1438text d_g3 "GB10 found but /dev/nvidiactl, /dev/nvidia0 or /dev/nvidia-uvm is missing"
1439text d_d1 "kernel driver "
1440text d_d2 " (the version this alpha was built and tested against)"
1441text d_d3 " found; this alpha only knows 580.173.02, so it stops here"
1442text d_d4 "no NVIDIA kernel module loaded (/sys/module/nvidia/version missing)"
1443text d_m1 " GB memory, "
1444text d_m2 " GB free for a model"
1445text d_m3 "; another model is using memory, so the first chat waits until it is free"
1446text d_m4 "; this alpha needs a 128 GB GB10"
1447text h_df "df"
1448text h_b1 "-B1"
1449text h_av "--output=avail"
1450text d_k1 " free in your home"
1451text d_k2 "; the model needs "
1452text d_k3 "unknown free space (df not found); the model needs "
1453text d_i1 "not installed yet"
1454text d_i2 "installed: "
1455text d_i3 ", model verified"
1456text d_i4 ", model not downloaded yet"
1457text t_cur "/.local/share/aienos/current"
1458text d_b1 "the GB10 lock (/tmp/aien-gb10.lock) is not held right now"
1459text d_b2 "busy: process "
1460text d_b3 " holds the GB10 lock, so I start no second model"
1461text d_n1 "found "
1462text d_n2 "libcuda"
1463text d_n3 "the CUDA toolkit"
1464text d_n4 "nvidia-smi"
1465text d_n5 ": they stay installed and untouched, and AienOS never loads them"
1466text d_nc ", "
1467text d_n6 "no NVIDIA user-space libraries found; AienOS does not need them"
1468text k_ok " ok "
1469text k_wn " note "
1470text k_no " no "
1471text k_in " info "
1472
1473note Detail line of check i, built with dstr/dnum/drb.
1474fn dsel i ulong to void
1475put dci 0 i
1476put dtn i 0
1477end
1478
1479fn dstr t view uchar * to void
1480i = get dci 0
1481n = get dtn i
1482for j ulong len t
1483if lt add n j 190
1484put dt add mul i 192 add n j get t j
1485end
1486end
1487m = add n len t
1488if gt m 190
1489m = 190
1490end
1491put dtn i m
1492end
1493
1494fn dbyte b uchar to void
1495i = get dci 0
1496n = get dtn i
1497if lt n 190
1498put dt add mul i 192 n b
1499put dtn i add n 1
1500end
1501end
1502
1503fn dnum v ulong to void
1504d = new uchar 20 0
1505k = ulong 0
1506x = v
1507while true bound 21
1508put d k uchar add rem x 10 48
1509k = add k 1
1510x = div x 10
1511if eq x 0
1512break
1513end
1514end
1515for j ulong k
1516dbyte get d sub sub k 1 j
1517end
1518end
1519
1520note Bytes of rb[o ..) up to the first newline or n bytes.
1521fn drb o ulong n ulong to void
1522for j ulong n
1523if ge add o j get rbn 0
1524ret
1525end
1526c = get rb add o j
1527if eq c 10
1528ret
1529end
1530dbyte c
1531end
1532end
1533
1534note Size in GB, rounded to one decimal, from a byte count (1 GB = 10^9 bytes).
1535fn dgb v ulong to void
1536r = add v 50000000
1537dnum div r 1000000000
1538dbyte 46
1539dnum div rem r 1000000000 100000000
1540dstr t_gb
1541end
1542
1543fn verdict i ulong k ulong to void
1544put dk i k
1545end
1546
1547note 0 CPU architecture. The binary itself is aarch64 and static, so running at all proves the ISA;
1548note the kernel's own word is shown when it has one.
1549fn ckarch to void
1550dsel 0
1551pprobe c_arch
1552n = slurp
1553if lt n 0
1554verdict 0 0
1555dstr d_a1
1556ret
1557end
1558if rbat 0 c_a64
1559verdict 0 0
1560dstr d_a1
1561ret
1562end
1563verdict 0 2
1564dstr d_a2
1565end
1566
1567note Is pci device directory entry rb-name a GB10? Builds devices/NAME/vendor and /device.
1568fn pcidev o ulong n ulong to bool
1569pprobe c_pci
1570pbyte 47
1571for j ulong n
1572pbyte get db add o j
1573end
1574k = get pbn 0
1575pstr c_vend
1576r = slurp
1577if or lt r 0 not rbat 0 c_nvv
1578ret false
1579end
1580put pbn 0 k
1581pstr c_dev
1582r = slurp
1583if lt r 0
1584ret false
1585end
1586ret rbat 0 c_gb10
1587end
1588
1589fn dbu16 o ulong to ulong
1590lo = ulong get db o
1591hi = ulong get db add o 1
1592ret or lo shl hi 8
1593end
1594
1595note Length of the zero-terminated name at db[o].
1596fn dname o ulong to ulong
1597k = ulong 0
1598while lt add o k len db bound 300
1599if eq get db add o k 0
1600ret k
1601end
1602k = add k 1
1603end
1604ret k
1605end
1606
1607note Count GB10 devices (PCI 10de:2e12) under /sys/bus/pci/devices.
1608fn gbcount to ulong
1609pprobe c_pci
1610fd = fopen pb 0 get pbn 0 540672 0
1611if lt fd 0
1612ret 0
1613end
1614found = ulong 0
1615while true bound 4096
1616n = getdnts int fd db 0 len db
1617if le n 0
1618break
1619end
1620o = ulong 0
1621while lt o ulong n bound 32768
1622rl = dbu16 add o 16
1623nl = dname add o 19
1624if and gt nl 0 ne get db add o 19 46
1625if pcidev add o 19 nl
1626found = add found 1
1627end
1628end
1629if eq rl 0
1630break
1631end
1632o = add o rl
1633end
1634end
1635c = fclose int fd
1636ret found
1637end
1638
1639fn chrdev t view uchar * to bool
1640pprobe t
1641if ne pstat 0
1642ret false
1643end
1644ret eq stype 2
1645end
1646
1647fn ckgpu to void
1648dsel 1
1649g = gbcount
1650put dv 1 g
1651if eq g 0
1652verdict 1 2
1653dstr d_g2
1654ret
1655end
1656ok = and and chrdev c_dctl chrdev c_dn0 chrdev c_duvm
1657pprobe c_pdrv
1658if or not ok not pexist
1659verdict 1 2
1660dstr d_g3
1661ret
1662end
1663verdict 1 0
1664dstr d_g1
1665end
1666
1667fn ckdrv to void
1668dsel 2
1669pprobe c_mver
1670n = slurp
1671if lt n 0
1672verdict 2 2
1673dstr d_d4
1674ret
1675end
1676dstr d_d1
1677drb 0 40
1678if rbat 0 c_good
1679verdict 2 0
1680dstr d_d2
1681ret
1682end
1683verdict 2 2
1684dstr d_d3
1685end
1686
1687note The kB value after key k in /proc/meminfo (rb), 0 when absent.
1688fn memkb k view uchar * to ulong
1689o = rbfind 0 k
1690if ge o get rbn 0
1691ret 0
1692end
1693o = add o len k
1694while eq get rb o 32 bound 64
1695o = add o 1
1696end
1697ret rbnum o
1698end
1699
1700fn ckmem to void
1701dsel 3
1702pprobe c_mem
1703n = slurp
1704if lt n 0
1705verdict 3 2
1706ret
1707end
1708tot = memkb c_mtot
1709av = memkb c_mav
1710mp = memkb c_mmap
1711fr = ulong 0
1712if gt av mp
1713fr = sub av mp
1714end
1715put dv 3 fr
1716dgbk tot
1717dstr d_m1
1718dgbk fr
1719dstr d_m2
1720if lt tot 67108864
1721verdict 3 2
1722dstr d_m4
1723ret
1724end
1725note 35B load need (Core qwen36_batch at 59b05a71, live load log): 37254 MiB model + 8 rows x 1982.85 MiB
1726note + 8192 MiB kept free = 61309 MiB = 62780416 kB (Wolfram: Ceiling[37254+8*1982.85+8192]*1024).
1727if lt fr 62780416
1728verdict 3 1
1729dstr d_m3
1730ret
1731end
1732verdict 3 0
1733end
1734
1735fn dgbk kb ulong to void
1736dnum div mul kb 1024 1000000000
1737end
1738
1739note Free bytes where the model will live, read with the host's df (Omega has no statfs word yet).
1740fn dfree to ulong
1741if not findbin h_df
1742ret 0
1743end
1744pkclr
1745pkpath
1746pkstr h_b1
1747pkstr h_av
1748pclr
1749phome
1750pkpath
1751r = runcap
1752if ne r 0
1753ret 0
1754end
1755o = rbfind 0 t_nl
1756ret rbnum add o 1
1757end
1758
1759fn ckdisk need ulong to void
1760dsel 4
1761f = dfree
1762put dv 4 f
1763if eq f 0
1764verdict 4 1
1765dstr d_k3
1766dgb need
1767ret
1768end
1769dgb f
1770dstr d_k1
1771if lt f need
1772verdict 4 2
1773dstr d_k2
1774dgb need
1775ret
1776end
1777verdict 4 0
1778end
1779
1780fn ckinst to void
1781dsel 5
1782verdict 5 3
1783pclr
1784phome
1785pstr t_cur
1786n = readlnk pb 0 get pbn 0 rb 0 256
1787if le n 0
1788dstr d_i1
1789ret
1790end
1791put rbn 0 ulong n
1792dstr d_i2
1793s = ulong 0
1794for j ulong ulong n
1795if eq get rb j 47
1796s = add j 1
1797end
1798end
1799drb s sub ulong n s
1800if mdone
1801dstr d_i3
1802else
1803dstr d_i4
1804end
1805end
1806
1807note Is the GB10 lock file held? Its inode is looked up in /proc/locks. Returns the holder pid or 0.
1808fn lockpid to ulong
1809pprobe c_lock
1810if ne pstat 0
1811ret 0
1812end
1813ino = sino
1814pprobe c_plk
1815n = slurp
1816if lt n 0
1817ret 0
1818end
1819o = ulong 0
1820while lt o get rbn 0 bound 524289
1821e = rbfind o t_nl
1822p = lkline o e ino
1823if gt p 0
1824ret p
1825end
1826o = add e 1
1827end
1828ret 0
1829end
1830
1831note One /proc/locks line in rb[o..e): "1: POSIX ADVISORY WRITE PID MAJ:MIN:INODE START END".
1832note Returns PID when INODE equals ino.
1833fn lkline o ulong e ulong ino ulong to ulong
1834f = ulong 0
1835i = o
1836pid = ulong 0
1837while lt i e bound 4096
1838if eq get rb i 32
1839while and lt i e eq get rb i 32 bound 4096
1840i = add i 1
1841end
1842f = add f 1
1843if eq f 4
1844pid = rbnum i
1845end
1846if eq f 5
1847ret lkino i e ino pid
1848end
1849else
1850i = add i 1
1851end
1852end
1853ret 0
1854end
1855
1856fn lkino i ulong e ulong ino ulong pid ulong to ulong
1857j = i
1858c = ulong 0
1859while and lt j e lt c 2 bound 64
1860if eq get rb j 58
1861c = add c 1
1862end
1863j = add j 1
1864end
1865if eq rbnum j ino
1866ret pid
1867end
1868ret 0
1869end
1870
1871fn ckbusy to void
1872dsel 6
1873p = lockpid
1874put dv 6 p
1875if eq p 0
1876verdict 6 0
1877dstr d_b1
1878ret
1879end
1880verdict 6 1
1881dstr d_b2
1882dnum p
1883dstr d_b3
1884end
1885
1886fn cknv to void
1887dsel 7
1888verdict 7 3
1889k = ulong 0
1890pprobe c_lcu
1891a = pexist
1892pprobe c_cuda
1893b = pexist
1894pprobe c_smi
1895c = pexist
1896if not or or a b c
1897dstr d_n6
1898ret
1899end
1900dstr d_n1
1901if a
1902dstr d_n2
1903end
1904if and a or b c
1905dstr d_nc
1906end
1907if b
1908dstr d_n3
1909end
1910if and b c
1911dstr d_nc
1912end
1913if c
1914dstr d_n4
1915end
1916dstr d_n5
1917end
1918
1919note Run every check. Returns true when the machine can take this alpha (no check failed).
1920fn doctor need ulong to bool
1921ckarch
1922ckgpu
1923ckdrv
1924ckmem
1925ckdisk need
1926ckinst
1927ckbusy
1928cknv
1929ok = true
1930for i ulong NCHK
1931if eq get dk i 2
1932ok = false
1933end
1934end
1935ret ok
1936end
1937
1938fn cname i ulong to void
1939if eq i 0
1940emit n_arch
1941end
1942if eq i 1
1943emit n_gpu
1944end
1945if eq i 2
1946emit n_drv
1947end
1948if eq i 3
1949emit n_mem
1950end
1951if eq i 4
1952emit n_disk
1953end
1954if eq i 5
1955emit n_inst
1956end
1957if eq i 6
1958emit n_busy
1959end
1960if eq i 7
1961emit n_nv
1962end
1963end
1964
1965fn ctag k ulong colour bool to void
1966if colour
1967if eq k 0
1968fg 120 220 120
1969end
1970if eq k 1
1971fg 250 200 80
1972end
1973if eq k 2
1974fg 255 90 80
1975end
1976if eq k 3
1977fg 140 170 255
1978end
1979end
1980if eq k 0
1981emit k_ok
1982end
1983if eq k 1
1984emit k_wn
1985end
1986if eq k 2
1987emit k_no
1988end
1989if eq k 3
1990emit k_in
1991end
1992if colour
1993sgr0
1994end
1995end
1996
1997note One check as one line: [tag] name padded to 8, then the detail.
1998fn cline i ulong colour bool to void
1999putb 91
2000ctag get dk i colour
2001putb 93
2002putb 32
2003cname i
2004n = cnlen i
2005while lt n 9 bound 16
2006putb 32
2007n = add n 1
2008end
2009dline i
2010end
2011
2012fn dline i ulong to void
2013for j ulong get dtn i
2014putb get dt add mul i 192 j
2015end
2016end
2017
2018fn cnlen i ulong to ulong
2019if eq i 0
2020ret len n_arch
2021end
2022if eq i 1
2023ret len n_gpu
2024end
2025if eq i 2
2026ret len n_drv
2027end
2028if eq i 3
2029ret len n_mem
2030end
2031if eq i 4
2032ret len n_disk
2033end
2034if eq i 5
2035ret len n_inst
2036end
2037if eq i 6
2038ret len n_busy
2039end
2040ret len n_nv
2041end
2042note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
2043note net.om: a small HTTP/1.0 client for the engine on 127.0.0.1, written with the native socket
2044note words, and the JSON string escaping it needs. No TLS: it only ever talks to the loopback door.
2045note Chat replies are read as a server-sent event stream and shown token by token.
2046
2047global qb uchar 65536
2048global qbn ulong 1
2049global hs uchar 262144
2050global hsn ulong 1
2051global ab uchar 65536
2052global abn ulong 1
2053global nt ulong 4
2054text j_open "{\"stream\":true,\"max_tokens\":1024,\"messages\":["
2055text j_close "]}"
2056text j_user "{\"role\":\"user\",\"content\":\""
2057text j_asst "{\"role\":\"assistant\",\"content\":\""
2058text j_end "\"}"
2059text j_comma ","
2060text h_post "POST /v1/chat/completions HTTP/1.0"
2061text h_host "Host: 127.0.0.1"
2062text h_ctype "Content-Type: application/json"
2063text h_clen "Content-Length: "
2064text h_get1 "GET "
2065text h_get2 " HTTP/1.0"
2066text h_data "data: "
2067text h_done "[DONE]"
2068text h_cont "\"content\":\""
2069text h_health "/health"
2070
2071fn qstr t view uchar * to void
2072n = get qbn 0
2073if gt add n len t len qb
2074trap 3
2075end
2076for i ulong len t
2077put qb add n i get t i
2078end
2079put qbn 0 add n len t
2080end
2081
2082fn qcrlf to void
2083qbyte 13
2084qbyte 10
2085end
2086
2087fn qline t view uchar * to void
2088qstr t
2089qcrlf
2090end
2091
2092note Offset of the blank line that ends the headers in rb, or the content length when absent.
2093fn hend to ulong
2094e4 = new uchar 4 13
2095put e4 1 10
2096put e4 3 10
2097ret rbfind 0 e4
2098end
2099
2100fn qbyte b uchar to void
2101n = get qbn 0
2102put qb n b
2103put qbn 0 add n 1
2104end
2105
2106fn qnum v ulong to void
2107d = new uchar 20 0
2108k = ulong 0
2109x = v
2110while true bound 21
2111put d k uchar add rem x 10 48
2112k = add k 1
2113x = div x 10
2114if eq x 0
2115break
2116end
2117end
2118for i ulong k
2119qbyte get d sub sub k 1 i
2120end
2121end
2122
2123note Append one byte to the conversation history hs (JSON already escaped).
2124fn hbyte b uchar to void
2125n = get hsn 0
2126if lt n len hs
2127put hs n b
2128put hsn 0 add n 1
2129end
2130end
2131
2132fn hstr t view uchar * to void
2133for i ulong len t
2134hbyte get t i
2135end
2136end
2137
2138fn hexd v ulong to uchar
2139if lt v 10
2140ret uchar add v 48
2141end
2142ret uchar add v 87
2143end
2144
2145note The user's line ib, escaped as a JSON string body, appended to the history.
2146fn hesc to void
2147for i ulong get ibn 0
2148c = get ib i
2149if or eq c 34 eq c 92
2150hbyte 92
2151hbyte c
2152else
2153if lt c 32
2154hbyte 92
2155hbyte 117
2156hbyte 48
2157hbyte 48
2158hbyte hexd ulong shr c 4
2159hbyte hexd ulong and c 15
2160else
2161hbyte c
2162end
2163end
2164end
2165end
2166
2167note A loopback TCP connection to port p. Returns the descriptor or -errno.
2168fn tcp p ulong to long
2169a = new uchar 16 0
2170put a 0 2
2171put a 2 uchar shr p 8
2172put a 3 uchar and p 255
2173put a 4 127
2174put a 7 1
2175fd = socknew 2 524289 0
2176if lt fd 0
2177ret fd
2178end
2179r = connect int fd a 0 16
2180if ne r 0
2181c = fclose int fd
2182ret r
2183end
2184ret fd
2185end
2186
2187fn sendq fd int to long
2188n = get qbn 0
2189o = ulong 0
2190while lt o n bound 65537
2191k = send fd qb o sub n o 0
2192if le k 0
2193ret -5
2194end
2195o = add o ulong k
2196end
2197ret 0
2198end
2199
2200note GET path on 127.0.0.1:p. Returns the HTTP status (200 ..), or a negative error.
2201fn hget p ulong t view uchar * to long
2202fd = tcp p
2203if lt fd 0
2204ret fd
2205end
2206put qbn 0 0
2207qstr h_get1
2208qstr t
2209qline h_get2
2210qline h_host
2211qcrlf
2212r = sendq int fd
2213if ne r 0
2214c = fclose int fd
2215ret r
2216end
2217put rbn 0 0
2218k = waitio int fd 1 5000000000
2219if le k 0
2220c = fclose int fd
2221ret -110
2222end
2223k = recv int fd rb 0 64 0
2224c = fclose int fd
2225if lt k 12
2226ret -71
2227end
2228put rbn 0 ulong k
2229ret long rbnum 9
2230end
2231
2232fn alive p ulong to bool
2233ret eq hget p h_health 200
2234end
2235
2236note Decode one \uXXXX escape's four hex digits at rb[o].
2237fn hex4 o ulong to ulong
2238v = ulong 0
2239for i ulong 4
2240c = ulong get rb add o i
2241d = ulong 0
2242if and ge c 48 le c 57
2243d = sub c 48
2244end
2245if and ge c 97 le c 102
2246d = sub c 87
2247end
2248if and ge c 65 le c 70
2249d = sub c 55
2250end
2251v = or shl v 4 d
2252end
2253ret v
2254end
2255
2256note UTF-8 of code point v to the output buffer.
2257fn utf8 v ulong to void
2258if lt v 128
2259putb uchar v
2260ret
2261end
2262if lt v 2048
2263putb uchar or 192 shr v 6
2264putb uchar or 128 and v 63
2265ret
2266end
2267if lt v 65536
2268putb uchar or 224 shr v 12
2269putb uchar or 128 and shr v 6 63
2270putb uchar or 128 and v 63
2271ret
2272end
2273putb uchar or 240 shr v 18
2274putb uchar or 128 and shr v 12 63
2275putb uchar or 128 and shr v 6 63
2276putb uchar or 128 and v 63
2277end
2278
2279note Print the JSON string body starting at rb[o] up to its closing quote, decoding escapes, and keep
2280note the raw escaped bytes in ab for the history. Returns the offset after the closing quote.
2281fn jshow o ulong e ulong to ulong
2282i = o
2283while lt i e bound 524289
2284c = get rb i
2285if eq c 34
2286ret add i 1
2287end
2288abyte c
2289if ne c 92
2290putb c
2291i = add i 1
2292else
2293i = jesc add i 1 e
2294end
2295end
2296ret i
2297end
2298
2299fn abyte c uchar to void
2300n = get abn 0
2301if lt n len ab
2302put ab n c
2303put abn 0 add n 1
2304end
2305end
2306
2307note One escape after a backslash at rb[i]; returns the offset after it.
2308fn jesc i ulong e ulong to ulong
2309if ge i e
2310ret i
2311end
2312c = get rb i
2313abyte c
2314if eq c 110
2315putb 10
2316ret add i 1
2317end
2318if eq c 116
2319putb 9
2320ret add i 1
2321end
2322if eq c 114
2323ret add i 1
2324end
2325if eq c 117
2326if le add i 5 e
2327for k ulong 4
2328abyte get rb add add i 1 k
2329end
2330v = hex4 add i 1
2331if and ge v 55296 lt v 56320
2332ret jsur i e v
2333end
2334utf8 v
2335ret add i 5
2336end
2337ret e
2338end
2339putb c
2340ret add i 1
2341end
2342
2343note A high surrogate at rb[i-1..i+5) followed by \uDC00..\uDFFF.
2344fn jsur i ulong e ulong v ulong to ulong
2345if and le add i 11 e eq get rb add i 5 92
2346for k ulong 6
2347abyte get rb add add i 5 k
2348end
2349lo = hex4 add i 7
2350utf8 add 65536 add shl sub v 55296 10 sub lo 56320
2351ret add i 11
2352end
2353utf8 65533
2354ret add i 5
2355end
2356
2357note Handle the complete event lines in rb[o .. e): print every content delta. Returns the offset of
2358note the first incomplete line, or the length of rb's content plus one after [DONE].
2359fn events o ulong to ulong
2360i = o
2361while lt i get rbn 0 bound 524289
2362nl = rbfind i t_nl
2363if ge nl get rbn 0
2364ret i
2365end
2366if rbat i h_data
2367if rbat add i len h_data h_done
2368ret add get rbn 0 1
2369end
2370c = rbfind i h_cont
2371if lt c nl
2372if eq get nt 0 0
2373put nt 1 ulong sub monons long get nt 2
2374end
2375put nt 0 add get nt 0 1
2376x = jshow add c len h_cont nl
2377w = flush
2378end
2379end
2380i = add nl 1
2381end
2382ret i
2383end
2384
2385note Send the history as one chat request and stream the answer to the screen. The answer's escaped
2386note text is kept in ab for the history. Returns 0, a negative error, or the HTTP status when not 200.
2387fn chatreq p ulong to long
2388body = add add len j_open get hsn 0 len j_close
2389put qbn 0 0
2390qline h_post
2391qline h_host
2392qline h_ctype
2393qstr h_clen
2394qnum body
2395qcrlf
2396qcrlf
2397if gt add get qbn 0 body len qb
2398ret -7
2399end
2400qstr j_open
2401for i ulong get hsn 0
2402qbyte get hs i
2403end
2404qstr j_close
2405fd = tcp p
2406if lt fd 0
2407ret fd
2408end
2409r = sendq int fd
2410if ne r 0
2411c = fclose int fd
2412ret r
2413end
2414put abn 0 0
2415put nt 0 0
2416put nt 2 ulong monons
2417r = chatrx int fd
2418c = fclose int fd
2419ret r
2420end
2421
2422note Receive the reply: status line, headers, then events until [DONE] or the server closes.
2423fn chatrx fd int to long
2424put rbn 0 0
2425hb2 = ulong 0
2426st = long 0
2427o = ulong 0
2428while lt get rbn 0 len rb bound 524289
2429k = waitio fd 1 600000000000
2430if le k 0
2431ret -110
2432end
2433k = recv fd rb get rbn 0 sub len rb get rbn 0 0
2434if le k 0
2435break
2436end
2437put rbn 0 add get rbn 0 ulong k
2438if eq hb2 0
2439e = hend
2440if lt e get rbn 0
2441hb2 = add e 4
2442st = long rbnum 9
2443o = hb2
2444if ne st 200
2445ret st
2446end
2447end
2448end
2449if gt hb2 0
2450o = events o
2451if gt o get rbn 0
2452ret 0
2453end
2454end
2455end
2456if eq hb2 0
2457ret -71
2458end
2459ret 0
2460end
2461note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
2462note steps.om: the screens of the wizard (welcome, doctor, plan, consent, install, model, first chat,
2463note done), the panel under the black hole, the progress bar, file hashing with the Omega SHA-256 unit,
2464note the model download and the engine's start and stop.
2465note
2466note Panel markup: byte 1 gold, 2 plain, 3 green, 4 red, 5 dim, 6 bright. A line ends at byte 10.
2467
2468global ui ulong 12
2469global pt uchar 8192
2470global ptn ulong 1
2471global pp uchar 256
2472global ppn ulong 1
2473global mf uchar 65536
2474global mfn ulong 1
2475global mnm uchar 128
2476global mnn ulong 1
2477global dg uchar 32
2478global bs uchar 1024
2479global bsn ulong 1
2480global pidb uchar 32
2481global ppt uchar 4096
2482global pptn ulong 1
2483text s_title " Sovereign Intelligence alpha "
2484text s_step " step "
2485text s_of " of 8 "
2486text s_n0 "welcome"
2487text s_n1 "doctor"
2488text s_n2 "plan"
2489text s_n3 "your yes"
2490text s_n4 "install"
2491text s_n5 "model"
2492text s_n6 "first chat"
2493text s_n7 "done"
2494text s_omega " written in Omega (.om)"
2495text t_tbase "~/.local/share/aienos"
2496text t_files " files"
2497text t_slash " / "
2498text m_name "name "
2499text m_url "url "
2500text m_bytes "bytes "
2501text m_files "files "
2502text t_share "/share/aienos/model.manifest"
2503text t_base "/.local/share/aienos"
2504text t_models "/models/"
2505text t_vfy "/.aienos-verified"
2506text t_sums "/SHA256SUMS"
2507text i_l1 "Checking every file of this release with SHA-256."
2508text i_l2 "The hash runs in Omega (the sha256.om unit shipped beside me)."
2509text i_ok " files match SHA256SUMS."
2510text i_bad "A file does not match SHA256SUMS: "
2511text i_bad2 "This copy is damaged or was changed. Install again with the curl command."
2512text i_cut "Meanwhile the user-space stack falls into the hole: libcuda, cuBLAS, nvcc."
2513text i_cut2 "That is the picture only. On disk those stay installed; AienOS just never loads them."
2514text i_md1 "Created "
2515text i_md2 " for the model."
2516text t_mkfail "I could not create the model folder in ~/.local/share/aienos."
2517text t_wait "working, please wait"
2518text t_next "Press Enter to continue"
2519text t_close "Press Enter to close"
2520text h_curl "curl"
2521text c_f "-fL"
2522text c_s "-sS"
2523text c_r "--retry"
2524text c_5 "5"
2525text c_c "-C"
2526text c_dash "-"
2527text c_o "-o"
2528text c_ua "--user-agent"
2529text c_uav "aienos-wizard/alpha"
2530text t_part ".part"
2531text t_curlog "/download.log"
2532text m_have "The model is already here and verified. Nothing to download."
2533text m_l1 "Downloading "
2534text m_l2 "from Hugging Face: "
2535text m_l3 " in "
2536text m_l4 " files."
2537text m_l5 "Every file is checked against its SHA-256 before it is used."
2538text m_l6 "A cut connection resumes where it stopped. q is not read here; Ctrl+C stops."
2539text m_fail "The download or a hash check failed. Nothing broken was kept."
2540text m_fail2 "Run aienos again to resume. The log is ~/.local/share/aienos/download.log."
2541text m_done "Every model file is downloaded and matches its SHA-256."
2542text t_dlocal "/.local"
2543text t_dshare "/share"
2544
2545note ui: 0 animate, 1 scene rows, 2 step, 3 last frame ns, 4 bytes done, 5 bytes total,
2546note 6 bar shown, 7 files done, 8 files total, 9 engine pid, 10 frames since step entry.
2547
2548fn pclear to void
2549put ptn 0 0
2550end
2551
2552fn pl t view uchar * to void
2553n = get ptn 0
2554for i ulong len t
2555if lt add n i len pt
2556put pt add n i get t i
2557end
2558end
2559m = add n len t
2560if gt m len pt
2561m = len pt
2562end
2563put ptn 0 m
2564end
2565
2566fn pc b uchar to void
2567n = get ptn 0
2568if lt n len pt
2569put pt n b
2570put ptn 0 add n 1
2571end
2572end
2573
2574fn pln to void
2575pc 10
2576end
2577
2578fn plnum v ulong to void
2579d = new uchar 20 0
2580k = ulong 0
2581x = v
2582while true bound 21
2583put d k uchar add rem x 10 48
2584k = add k 1
2585x = div x 10
2586if eq x 0
2587break
2588end
2589end
2590for i ulong k
2591pc get d sub sub k 1 i
2592end
2593end
2594
2595note Gigabytes (10^9 bytes) rounded to one decimal.
2596fn plgb v ulong to void
2597r = add v 50000000
2598plnum div r 1000000000
2599pc 46
2600plnum div rem r 1000000000 100000000
2601pl t_gb
2602end
2603
2604note The base folder ~/.local/share/aienos as text in the panel, spelled with a tilde.
2605fn plbase to void
2606pl t_tbase
2607end
2608
2609fn prompt t view uchar * to void
2610put ppn 0 0
2611for i ulong len t
2612if lt i len pp
2613put pp i get t i
2614end
2615end
2616put ppn 0 len t
2617end
2618
2619fn mark b uchar to void
2620if eq b 1
2621fg 255 196 90
2622end
2623if eq b 2
2624sgr0
2625end
2626if eq b 3
2627fg 120 220 120
2628end
2629if eq b 4
2630fg 255 100 90
2631end
2632if eq b 5
2633fg 140 140 165
2634end
2635if eq b 6
2636bold
2637fg 245 245 255
2638end
2639end
2640
2641fn sname i ulong to void
2642if eq i 0
2643emit s_n0
2644end
2645if eq i 1
2646emit s_n1
2647end
2648if eq i 2
2649emit s_n2
2650end
2651if eq i 3
2652emit s_n3
2653end
2654if eq i 4
2655emit s_n4
2656end
2657if eq i 5
2658emit s_n5
2659end
2660if eq i 6
2661emit s_n6
2662end
2663if eq i 7
2664emit s_n7
2665end
2666end
2667
2668fn header row ulong to void
2669mv row 1
2670bg 18 16 28
2671fg 255 196 90
2672bold
2673emit s_title
2674sgr0
2675bg 18 16 28
2676fg 200 200 220
2677emit s_step
2678num add get ui 2 1
2679emit s_of
2680sname get ui 2
2681fg 120 120 150
2682emit s_omega
2683eol
2684sgr0
2685end
2686
2687note Draw the panel lines from row r0 on, at most rows lines, each cleared to the end of the line.
2688note Put one panel byte at column col (counted from 3); bytes past the terminal's width are
2689note dropped so a long line never wraps into the next one. Returns the new column.
2690fn pput b uchar col ulong to ulong
2691if ge col sub get tw 0 1
2692ret col
2693end
2694putb b
2695if eq and b 192 128
2696ret col
2697end
2698ret add col 1
2699end
2700
2701fn pdraw r0 ulong rows ulong colour bool to void
2702row = r0
2703col = ulong 3
2704i = ulong 0
2705n = get ptn 0
2706mv row 3
2707eol
2708while lt i n bound 8193
2709b = get pt i
2710if eq b 10
2711row = add row 1
2712if ge row add r0 rows
2713ret
2714end
2715if colour
2716sgr0
2717end
2718mv row 1
2719eol
2720mv row 3
2721col = 3
2722else
2723if lt b 7
2724if colour
2725mark b
2726end
2727else
2728col = pput b col
2729end
2730end
2731i = add i 1
2732end
2733if colour
2734sgr0
2735end
2736row = add row 1
2737while lt row add r0 rows bound 256
2738mv row 1
2739eol
2740row = add row 1
2741end
2742end
2743
2744note The progress bar: done/total bytes as a gold bar, the percentage and the file count.
2745fn pbar row ulong to void
2746mv row 3
2747eol
2748if eq get ui 6 0
2749ret
2750end
2751w = ulong 40
2752tot = get ui 5
2753if eq tot 0
2754tot = 1
2755end
2756dn = get ui 4
2757if gt dn tot
2758dn = tot
2759end
2760f = div mul dn w tot
2761fg 255 196 90
2762for i ulong w
2763if lt i f
2764bg 255 170 60
2765else
2766bg 50 44 70
2767end
2768putb 32
2769end
2770sgr0
2771putb 32
2772numw div mul dn 100 tot 3
2773putb 37
2774putb 32
2775putb 32
2776num get ui 7
2777emit t_slash
2778num get ui 8
2779emit t_files
2780end
2781
2782fn pprompt row ulong colour bool to void
2783mv row 3
2784eol
2785if colour
2786fg 255 196 90
2787bold
2788end
2789putb 62
2790putb 32
2791for i ulong get ppn 0
2792putb get pp i
2793end
2794if colour
2795sgr0
2796end
2797end
2798
2799note One animation frame: the scene, the header, the panel, the bar and the prompt.
2800fn frame to void
2801if eq get ui 0 0
2802ret
2803end
2804sh = get ui 1
2805t = get th 0
2806home
2807hframe sh
2808header add sh 1
2809pdraw add sh 2 sub sub t sh 4 true
2810pbar sub t 1
2811pprompt t true
2812w = flush
2813put ui 3 ulong monons
2814put ui 10 add get ui 10 1
2815end
2816
2817note Draw a frame only when 80 ms have passed since the last one; used inside long loops.
2818fn tickui to void
2819if eq get ui 0 0
2820ret
2821end
2822if gt sub ulong monons get ui 3 80000000
2823frame
2824end
2825end
2826
2827note Plain mode (no terminal or too small): print the panel once, without colour or animation.
2828fn plainout to void
2829putb 10
2830emit s_title
2831emit s_step
2832num add get ui 2 1
2833emit s_of
2834sname get ui 2
2835putb 10
2836for i ulong get ptn 0
2837b = get pt i
2838if or ge b 7 eq b 10
2839putb b
2840end
2841end
2842putb 10
2843if gt get ui 6 0
2844pbarp
2845end
2846w = flush
2847end
2848
2849fn pbarp to void
2850tot = get ui 5
2851if eq tot 0
2852tot = 1
2853end
2854num div mul get ui 4 100 tot
2855putb 37
2856putb 32
2857num get ui 7
2858emit t_slash
2859num get ui 8
2860emit t_files
2861putb 10
2862end
2863
2864fn enter i ulong to void
2865put ui 2 i
2866put ui 6 0
2867put ui 10 0
2868if eq get ui 0 1
2869cls
2870end
2871end
2872
2873note Show the step: a frame, or in plain mode the panel text.
2874fn show to void
2875if eq get ui 0 1
2876frame
2877else
2878plainout
2879end
2880end
2881
2882note Wait for one line of input while the hole keeps turning. Returns its length or -1 at end of input.
2883fn ask to long
2884if eq get ui 0 1
2885while true bound 999999
2886frame
2887k = waitio 0 1 80000000
2888if ne k 0
2889break
2890end
2891end
2892else
2893for i ulong get ppn 0
2894putb get pp i
2895end
2896putb 58
2897putb 32
2898w = flush
2899end
2900ret rline
2901end
2902
2903note Keep animating for about ms milliseconds (plain mode returns at once).
2904fn hold ms ulong to void
2905if eq get ui 0 0
2906ret
2907end
2908st = ulong monons
2909while lt sub ulong monons st mul ms 1000000 bound 100000
2910frame
2911s = sleepns 60000000
2912end
2913end
2914
2915note ---------- SHA-256 of a file, with the Omega unit in sha256.om ----------
2916
2917note Hash the file named by pb into dg, adding its bytes to ui 4 as it goes. Returns the size or -errno.
2918fn fhash to long
2919c = new uchar 104 0
2920buf = new uchar 1048576 0
2921o = new uchar 32 0
2922fd = fopen pb 0 get pbn 0 524288 0
2923if lt fd 0
2924ret fd
2925end
2926sha256_init c
2927tot = ulong 0
2928while true bound 999999
2929k = read int fd buf 0 len buf
2930if lt k 0
2931x = fclose int fd
2932ret k
2933end
2934if eq k 0
2935break
2936end
2937sha256_update c part buf 0 ulong k
2938tot = add tot ulong k
2939put ui 4 add get ui 4 ulong k
2940tickui
2941end
2942x = fclose int fd
2943sha256_final c o
2944for i ulong 32
2945put dg i get o i
2946end
2947ret long tot
2948end
2949
2950note Does dg equal the 64 lowercase hex digits at mf[o]?
2951fn dgis o ulong to bool
2952for i ulong 32
2953b = get dg i
2954if ne get mf add o mul i 2 hexd ulong shr b 4
2955ret false
2956end
2957if ne get mf add add o mul i 2 1 hexd ulong and b 15
2958ret false
2959end
2960end
2961ret true
2962end
2963
2964note ---------- manifests ----------
2965
2966note Load the file named by pb into mf. Returns its length or -errno.
2967fn mload to long
2968n = slurp
2969if lt n 0
2970ret n
2971end
2972if gt get rbn 0 len mf
2973ret -27
2974end
2975for i ulong get rbn 0
2976put mf i get rb i
2977end
2978put mfn 0 get rbn 0
2979ret n
2980end
2981
2982fn mfat o ulong t view uchar * to bool
2983if gt add o len t get mfn 0
2984ret false
2985end
2986for i ulong len t
2987if ne get mf add o i get t i
2988ret false
2989end
2990end
2991ret true
2992end
2993
2994fn mfnl o ulong to ulong
2995i = o
2996while lt i get mfn 0 bound 65537
2997if eq get mf i 10
2998ret i
2999end
3000i = add i 1
3001end
3002ret get mfn 0
3003end
3004
3005fn mfnum o ulong to ulong
3006x = ulong 0
3007i = o
3008while lt i get mfn 0 bound 21
3009c = get mf i
3010if or lt c 48 gt c 57
3011ret x
3012end
3013x = add mul x 10 ulong sub c 48
3014i = add i 1
3015end
3016ret x
3017end
3018
3019note Model manifest lines: "name N", "url U", "bytes B", "files F", then "SHA256 SIZE PATH" per file.
3020
3021note Offset of the value after key t at the start of a manifest line, or the manifest length.
3022fn mkey t view uchar * to ulong
3023o = ulong 0
3024while lt o get mfn 0 bound 65537
3025if mfat o t
3026ret add o len t
3027end
3028o = add mfnl o 1
3029end
3030ret get mfn 0
3031end
3032
3033fn mopen to bool
3034pclr
3035proot
3036pstr t_share
3037n = mload
3038if lt n 0
3039ret false
3040end
3041o = mkey m_name
3042e = mfnl o
3043if ge o e
3044ret false
3045end
3046put mnn 0 0
3047for i ulong sub e o
3048if lt i len mnm
3049put mnm i get mf add o i
3050put mnn 0 add i 1
3051end
3052end
3053ret true
3054end
3055
3056fn mbytes to ulong
3057ret mfnum mkey m_bytes
3058end
3059
3060fn mfiles to ulong
3061ret mfnum mkey m_files
3062end
3063
3064fn pbase to void
3065pclr
3066phome
3067pstr t_base
3068end
3069
3070note pb = ~/.local/share/aienos/models/NAME
3071fn pmodel to void
3072pbase
3073pstr t_models
3074for i ulong get mnn 0
3075pbyte get mnm i
3076end
3077end
3078
3079fn mdone to bool
3080if not mopen
3081ret false
3082end
3083pmodel
3084pstr t_vfy
3085ret pexist
3086end
3087
3088note ---------- install step: verify this release ----------
3089
3090note Verify root/SHA256SUMS ("HEX PATH" lines). Returns the number of files checked, or the
3091note negative offset+1 of the first bad line.
3092fn sums to long
3093pclr
3094proot
3095pstr t_sums
3096n = mload
3097if lt n 0
3098ret -1
3099end
3100put ui 4 0
3101put ui 5 sumbytes
3102put ui 6 1
3103put ui 7 0
3104put ui 8 sumcount
3105o = ulong 0
3106k = long 0
3107while lt o get mfn 0 bound 65537
3108e = mfnl o
3109if ishex o e
3110r = sumline o e
3111if not r
3112ret neg long add o 1
3113end
3114k = add k 1
3115put ui 7 ulong k
3116end
3117o = add e 1
3118end
3119ret k
3120end
3121
3122fn sumline o ulong e ulong to bool
3123pclr
3124proot
3125pbyte 47
3126for i ulong sub sub e o 66
3127pbyte get mf add add o 66 i
3128end
3129r = fhash
3130if lt r 0
3131ret false
3132end
3133ret dgis o
3134end
3135
3136fn sumcount to ulong
3137k = ulong 0
3138o = ulong 0
3139while lt o get mfn 0 bound 65537
3140e = mfnl o
3141if ishex o e
3142k = add k 1
3143end
3144o = add e 1
3145end
3146ret k
3147end
3148
3149note Total size of the files listed in SHA256SUMS (for the progress bar).
3150fn sumbytes to ulong
3151t = ulong 0
3152o = ulong 0
3153while lt o get mfn 0 bound 65537
3154e = mfnl o
3155if ishex o e
3156pclr
3157proot
3158pbyte 47
3159for i ulong sub sub e o 66
3160pbyte get mf add add o 66 i
3161end
3162if eq pstat 0
3163t = add t ssize
3164end
3165end
3166o = add e 1
3167end
3168ret t
3169end
3170
3171fn mkdirs to bool
3172pclr
3173phome
3174pstr t_dlocal
3175r = makedir pb 0 get pbn 0 493
3176pstr t_dshare
3177r = makedir pb 0 get pbn 0 493
3178pbase
3179r = makedir pb 0 get pbn 0 448
3180pmodel
3181pdrop add get mnn 0 1
3182r = makedir pb 0 get pbn 0 448
3183pmodel
3184r = makedir pb 0 get pbn 0 448
3185ret or eq r 0 eq r -17
3186end
3187
3188fn stinst to bool
3189enter 4
3190pclear
3191pl i_l1
3192pln
3193pl i_l2
3194pln
3195pln
3196pc 5
3197pl i_cut
3198pln
3199pl i_cut2
3200pc 2
3201prompt t_wait
3202show
3203k = sums
3204put ui 6 0
3205pclear
3206if lt k 0
3207pc 4
3208pl i_bad
3209pc 2
3210pln
3211pl i_bad2
3212prompt t_close
3213show
3214r = ask
3215ret false
3216end
3217pc 3
3218plnum ulong k
3219pl i_ok
3220pc 2
3221pln
3222if not mkdirs
3223pc 4
3224pl t_mkfail
3225pc 2
3226prompt t_close
3227show
3228r = ask
3229ret false
3230end
3231pl i_md1
3232plbase
3233pl t_models
3234for i ulong get mnn 0
3235pc get mnm i
3236end
3237pl i_md2
3238pln
3239pln
3240pc 5
3241pl i_cut
3242pln
3243pl i_cut2
3244pc 2
3245prompt t_next
3246hold 1500
3247show
3248r = ask
3249ret ge r 0
3250end
3251
3252note ---------- model download ----------
3253
3254note Per file line at mf[o..e): "SHA SIZE PATH". Puts the path start in ui 11 and returns the size.
3255fn fline o ulong e ulong to ulong
3256s = add o 65
3257sz = mfnum s
3258i = s
3259while and lt i e ne get mf i 32 bound 32
3260i = add i 1
3261end
3262put ui 11 add i 1
3263ret sz
3264end
3265
3266note pb = model folder / PATH (from mf[ui 11 .. e)).
3267fn pmfile e ulong to void
3268pmodel
3269pbyte 47
3270for i ulong sub e get ui 11
3271pbyte get mf add get ui 11 i
3272end
3273end
3274
3275note Run curl for URL base + PATH into pb + ".part", animating while it runs. Returns curl's status.
3276fn fetch e ulong sz ulong to long
3277pkclr
3278if not findbin h_curl
3279ret -2
3280end
3281pkpath
3282pkstr c_f
3283pkstr c_s
3284pkstr c_r
3285pkstr c_5
3286pkstr c_ua
3287pkstr c_uav
3288pkstr c_c
3289pkstr c_dash
3290pkstr c_o
3291pmfile e
3292pstr t_part
3293savep
3294pkpath
3295pkurl e
3296pbase
3297pstr t_curlog
3298ret runbg sz
3299end
3300
3301note The URL: the manifest's url value, then PATH.
3302fn pkurl e ulong to void
3303u = mkey m_url
3304ue = mfnl u
3305pclr
3306for i ulong sub ue u
3307pbyte get mf add u i
3308end
3309for i ulong sub e get ui 11
3310pbyte get mf add get ui 11 i
3311end
3312pkpath
3313end
3314
3315note Like runpk, but animates and follows the .part file's size while the child runs.
3316fn runbg sz ulong to long
3317lfd = fopen pb 0 get pbn 0 525377 384
3318if lt lfd 0
3319ret lfd
3320end
3321pid = fork
3322if lt pid 0
3323ret pid
3324end
3325if eq pid 0
3326d = dupfd int lfd 1 0
3327d = dupfd int lfd 2 0
3328r = execprog pk 0 get pkn 0
3329exit 127
3330end
3331c = fclose int lfd
3332base = get ui 4
3333while true bound 999999
3334r = waitpid int pid ws 0 4 1
3335if eq r pid
3336ret wcode
3337end
3338if lt r 0
3339ret r
3340end
3341put ui 4 add base partsz
3342frame
3343s = sleepns 200000000
3344end
3345ret -4
3346end
3347
3348note Size of the .part file being written (its path was saved in ppt by fetch).
3349fn partsz to ulong
3350r = stat ppt 0 get pptn 0 sb 0 128
3351if ne r 0
3352ret 0
3353end
3354ret ssize
3355end
3356
3357fn savep to void
3358for i ulong get pbn 0
3359put ppt i get pb i
3360end
3361put pptn 0 get pbn 0
3362end
3363
3364fn mstep to bool
3365enter 5
3366if not mopen
3367ret false
3368end
3369if mdone
3370pclear
3371pc 3
3372pl m_have
3373pc 2
3374pln
3375prompt t_next
3376show
3377r = ask
3378ret ge r 0
3379end
3380pclear
3381pl m_l1
3382pc 6
3383for i ulong get mnn 0
3384pc get mnm i
3385end
3386pc 2
3387pln
3388pl m_l2
3389plgb mbytes
3390pl m_l3
3391plnum mfiles
3392pl m_l4
3393pln
3394pl m_l5
3395pln
3396pln
3397pc 5
3398pl m_l6
3399pc 2
3400prompt t_wait
3401put ui 4 0
3402put ui 5 mbytes
3403put ui 6 1
3404put ui 7 0
3405put ui 8 mfiles
3406show
3407r = mall
3408put ui 6 0
3409if not r
3410pclear
3411pc 4
3412pl m_fail
3413pc 2
3414pln
3415pl m_fail2
3416prompt t_close
3417show
3418x = ask
3419ret false
3420end
3421pmodel
3422pstr t_vfy
3423put rb 0 111
3424put rb 1 107
3425put rb 2 10
3426x = spill 3
3427pclear
3428pc 3
3429pl m_done
3430pc 2
3431pln
3432prompt t_next
3433show
3434x = ask
3435ret ge x 0
3436end
3437
3438note Is mf[o..e) a file line: 64 lowercase hex digits, then a space?
3439fn ishex o ulong e ulong to bool
3440if le sub e o 66
3441ret false
3442end
3443for i ulong 64
3444c = get mf add o i
3445if not or and ge c 48 le c 57 and ge c 97 le c 102
3446ret false
3447end
3448end
3449ret eq get mf add o 64 32
3450end
3451
3452note Fetch and verify every file of the model manifest.
3453fn mall to bool
3454o = ulong 0
3455while lt o get mfn 0 bound 65537
3456e = mfnl o
3457if ishex o e
3458if not mfile o e
3459ret false
3460end
3461put ui 7 add get ui 7 1
3462end
3463o = add e 1
3464end
3465ret true
3466end
3467
3468note One model file: keep it if it is there and hashes right, else download to .part, check the
3469note size and hash, then rename it into place. A file that fails its hash is deleted.
3470fn mfile o ulong e ulong to bool
3471sz = fline o e
3472pmfile e
3473if eq pstat 0
3474if eq ssize sz
3475r = fhash
3476if and ge r 0 dgis o
3477ret true
3478end
3479put ui 4 sub get ui 4 sz
3480end
3481r = unlink pb 0 get pbn 0
3482end
3483ret mget o e sz
3484end
3485
3486fn mget o ulong e ulong sz ulong to bool
3487for tries ulong 2
3488pmfile e
3489pstr t_part
3490st = get ui 4
3491if eq pstat 0
3492if gt ssize sz
3493r = unlink pb 0 get pbn 0
3494end
3495end
3496c = fetch e sz
3497put ui 4 st
3498pmfile e
3499pstr t_part
3500if and eq c 0 eq pstat 0
3501if eq ssize sz
3502h = fhash
3503if dgis o
3504ret mplace e
3505end
3506end
3507end
3508pmfile e
3509pstr t_part
3510r = unlink pb 0 get pbn 0
3511end
3512ret false
3513end
3514
3515note Rename model/PATH.part to model/PATH with renameat2 (packed list of the two paths).
3516fn mplace e ulong to bool
3517pkclr
3518pmfile e
3519pstr t_part
3520pkpath
3521pmfile e
3522pkpath
3523r = renames pk 0 get pkn 0 0
3524ret eq r 0
3525end
3526note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3527note engine.om: start, watch and stop the engine (aien-serve-http, Core ship/motor-l387, engine omega) on
3528note 127.0.0.1, check from /proc that it loaded no CUDA library, the first-chat screen, the done
3529note screen, the uninstaller and the rollback.
3530
3531const PORT ulong 18100
3532text e_bin "/bin/aien-serve-http"
3533text e_eng "--engine"
3534text e_omega "omega"
3535text e_mdir "--model-dir"
3536text e_port "--port"
3537text e_ctx "--max-context"
3538text e_ctxv "49152"
3539text e_cap "--max-tokens-cap"
3540text e_capv "16384"
3541text e_thk "--thinking"
3542text e_off "off"
3543text e_slot "--batch-slots"
3544text e_slotv "8"
3545text e_log "/engine.log"
3546text e_pid "/engine.pid"
3547text e_null "/dev/null"
3548text e_proc "/proc/"
3549text e_exe "/exe"
3550text e_maps "/maps"
3551text e_name "aien-serve-http"
3552text e_cu1 "libcuda"
3553text e_cu2 "libcublas"
3554text e_cu3 "libcudart"
3555text e_cu4 "libnvidia-"
3556text f_skip1 "I am not starting the engine now: "
3557text f_mem "another model is using this GB10's memory."
3558text f_lock "another process holds the GB10 lock."
3559text f_skip2 "Your model is installed. When the GPU is free, run: aienos chat"
3560text f_load1 "Starting the engine (Core ship/motor-l387 59b05a71) and loading the 35B onto the GB10."
3561text f_load2 "The first load reads about 37.5 GB, so it can take a few minutes."
3562text f_fail1 "The engine stopped before it was ready. Its log: ~/.local/share/aienos/engine.log"
3563text f_q "Say hello in one short sentence, and tell me what you are."
3564text f_you "you "
3565text f_ai "model "
3566text f_ttf "first token after "
3567text f_ms " ms"
3568text f_cuda "CUDA libraries in the engine's memory map (/proc/"
3569text f_cuda2 "/maps): "
3570text f_run "The engine keeps running on 127.0.0.1:18100. Stop it with: aienos stop"
3571text d_l1 "Your local model is ready."
3572text d_l0 "Your model is installed and verified. Start it with aienos chat when the GPU is free."
3573text d_l2 " aienos chat talk to it in this terminal"
3574text d_l3 " aienos doctor check this machine again"
3575text d_l4 " aienos stop stop the engine"
3576text d_l5 " aienos source where my .om source lives"
3577text d_l6 " aienos uninstall remove everything AienOS put on this machine"
3578text d_l7 "OpenAI-style API: http://127.0.0.1:18100/v1/chat/completions"
3579text u_list "/installed-files"
3580text u_sure "This removes AienOS from this machine. Type yes to remove it"
3581text u_keep "--keep-model"
3582text u_yes "--yes"
3583text u_done "AienOS is removed. NVIDIA's driver and CUDA were never touched."
3584text u_kept "The model was kept in ~/.local/share/aienos/models."
3585text u_no "Nothing was removed."
3586text u_stop "The engine did not stop; nothing was removed."
3587text u_dot ".."
3588text u_mods "models"
3589text r_rel "/releases"
3590text r_cur "/current"
3591text r_new "/current.new"
3592text r_pre "releases/"
3593text r_none "There is no other release to roll back to."
3594text r_ok "current now points to "
3595
3596note The packed argument list of the live 35B server's command (same flags), on PORT.
3597fn eargs to void
3598pkclr
3599pclr
3600proot
3601pstr e_bin
3602pkpath
3603pkstr e_eng
3604pkstr e_omega
3605pkstr e_mdir
3606pmodel
3607pkpath
3608pkstr e_port
3609pknum PORT
3610pkstr e_ctx
3611pkstr e_ctxv
3612pkstr e_cap
3613pkstr e_capv
3614pkstr e_thk
3615pkstr e_off
3616pkstr e_slot
3617pkstr e_slotv
3618end
3619
3620note Start the engine in its own session, output appended to engine.log, pid in engine.pid.
3621fn estart to long
3622eargs
3623pbase
3624pstr e_log
3625lfd = fopen pb 0 get pbn 0 525377 384
3626if lt lfd 0
3627ret lfd
3628end
3629nfd = fopen e_null 0 len e_null 524288 0
3630pid = fork
3631if lt pid 0
3632ret pid
3633end
3634if eq pid 0
3635s = setsid
3636d = dupfd int nfd 0 0
3637d = dupfd int lfd 1 0
3638d = dupfd int lfd 2 0
3639r = execprog pk 0 get pkn 0
3640exit 127
3641end
3642c = fclose int lfd
3643c = fclose int nfd
3644put ui 9 ulong pid
3645put rbn 0 0
3646pclr
3647pnum ulong pid
3648for i ulong get pbn 0
3649put rb i get pb i
3650end
3651put rb get pbn 0 10
3652k = add get pbn 0 1
3653pbase
3654pstr e_pid
3655r = spill k
3656ret pid
3657end
3658
3659note The pid in engine.pid when that process is still aien-serve-http, else 0.
3660fn epid to ulong
3661pbase
3662pstr e_pid
3663n = slurp
3664if le n 0
3665ret 0
3666end
3667p = rbnum 0
3668if eq p 0
3669ret 0
3670end
3671pclr
3672pstr e_proc
3673pnum p
3674pstr e_exe
3675n = readlnk pb 0 get pbn 0 rb 0 4096
3676if le n 0
3677ret 0
3678end
3679put rbn 0 ulong n
3680if lt ulong n len e_name
3681ret 0
3682end
3683if rbat sub ulong n len e_name e_name
3684ret p
3685end
3686ret 0
3687end
3688
3689note Stop the engine: SIGTERM, then wait up to 120 s for it to go. Returns true when it is gone.
3690fn estop to bool
3691p = epid
3692if eq p 0
3693ret true
3694end
3695r = killpid int p 15
3696for i ulong 1200
3697x = waitpid int p ws 0 4 1
3698if eq epid 0
3699pbase
3700pstr e_pid
3701x = unlink pb 0 get pbn 0
3702ret true
3703end
3704s = sleepns 100000000
3705end
3706ret false
3707end
3708
3709note Count the CUDA user-space libraries in /proc/PID/maps (libcuda, libcublas, libcudart,
3710note libnvidia-*). Returns the count, or -1 when the maps could not be read.
3711fn ecuda p ulong to long
3712pclr
3713pstr e_proc
3714pnum p
3715pstr e_maps
3716n = slurp
3717if lt n 0
3718ret -1
3719end
3720k = long 0
3721o = ulong 0
3722while lt o get rbn 0 bound 524289
3723e = rbfind o t_nl
3724if culine o e
3725k = add k 1
3726end
3727o = add e 1
3728end
3729ret k
3730end
3731
3732fn culine o ulong e ulong to bool
3733a = or rbin o e e_cu1 rbin o e e_cu2
3734b = or rbin o e e_cu3 rbin o e e_cu4
3735ret or a b
3736end
3737
3738note Wait for the engine's /health while the hole turns. Gives up after limit seconds or when the
3739note process exits. Returns true when it answers.
3740fn ewait limit ulong to bool
3741st = ulong monons
3742p = get ui 9
3743while lt sub ulong monons st mul limit 1000000000 bound 999999
3744if alive PORT
3745ret true
3746end
3747x = waitpid int p ws 0 4 1
3748if eq x long p
3749ret false
3750end
3751put ui 4 div sub ulong monons st 1000000000
3752for k ulong 20
3753frame
3754s = sleepns 100000000
3755end
3756end
3757ret false
3758end
3759
3760fn ckskip to bool
3761if eq get dk 6 1
3762pl f_skip1
3763pl f_lock
3764ret true
3765end
3766if eq get dk 3 1
3767pl f_skip1
3768pl f_mem
3769ret true
3770end
3771ret false
3772end
3773
3774note The first-chat step. Returns false only when the engine failed to come up.
3775fn stchat to bool
3776enter 6
3777pclear
3778put ui 11 0
3779if ckskip
3780pln
3781pln
3782pl f_skip2
3783prompt t_next
3784show
3785r = ask
3786ret true
3787end
3788if not alive PORT
3789pl f_load1
3790pln
3791pl f_load2
3792prompt t_wait
3793put ui 6 0
3794show
3795p = estart
3796if lt p 0
3797ret false
3798end
3799if not ewait 2400
3800pclear
3801pc 4
3802pl f_fail1
3803pc 2
3804prompt t_close
3805show
3806r = ask
3807ret false
3808end
3809end
3810put ui 11 1
3811firstq
3812ret true
3813end
3814
3815note Ask the first question and stream the answer under the picture, then show the evidence lines.
3816fn firstq to void
3817put hsn 0 0
3818hstr j_user
3819put ibn 0 len f_q
3820for i ulong len f_q
3821put ib i get f_q i
3822end
3823hesc
3824hstr j_end
3825pclear
3826pc 5
3827pl f_you
3828pc 2
3829pl f_q
3830pln
3831pc 1
3832pl f_ai
3833pc 2
3834prompt t_wait
3835show
3836if eq get ui 0 1
3837mv add get ui 1 4 10
3838end
3839r = chatreq PORT
3840w = flush
3841ftail
3842end
3843
3844fn ftail to void
3845pclear
3846pc 3
3847pl f_ttf
3848plnum div get nt 1 1000000
3849pl f_ms
3850pc 2
3851pln
3852p = epid
3853if gt p 0
3854pl f_cuda
3855plnum p
3856pl f_cuda2
3857c = ecuda p
3858if eq c 0
3859pc 3
3860end
3861plnum ulong c
3862pc 2
3863pln
3864end
3865pl f_run
3866prompt t_next
3867if eq get ui 0 1
3868pdraw sub get th 0 4 3 true
3869pprompt get th 0 true
3870x = flush
3871else
3872plainout
3873end
3874r = rline
3875end
3876
3877fn stdone ready bool to void
3878enter 7
3879pclear
3880pc 3
3881if ready
3882pl d_l1
3883else
3884pl d_l0
3885end
3886pc 2
3887pln
3888pln
3889pl d_l2
3890pln
3891pl d_l3
3892pln
3893pl d_l4
3894pln
3895pl d_l5
3896pln
3897pl d_l6
3898pln
3899pln
3900pc 5
3901pl d_l7
3902pc 2
3903prompt t_close
3904show
3905r = ask
3906end
3907
3908note ---------- uninstall ----------
3909
3910note Is pb inside the home folder: HOME + "/" + something, with no ".." component?
3911fn inhome to bool
3912h = get hbn 0
3913if le get pbn 0 add h 1
3914ret false
3915end
3916if le h 1
3917ret false
3918end
3919for i ulong h
3920if ne get pb i get hb i
3921ret false
3922end
3923end
3924if ne get pb h 47
3925ret false
3926end
3927for i ulong sub get pbn 0 1
3928if and eq get pb i 46 eq get pb add i 1 46
3929ret false
3930end
3931end
3932ret true
3933end
3934
3935note Unlink every path in installed-files that lies inside the home folder.
3936fn ulist to void
3937pbase
3938pstr u_list
3939n = mload
3940if lt n 0
3941ret
3942end
3943o = ulong 0
3944while lt o get mfn 0 bound 65537
3945e = mfnl o
3946pclr
3947for i ulong sub e o
3948pbyte get mf add o i
3949end
3950if inhome
3951r = unlink pb 0 get pbn 0
3952end
3953o = add e 1
3954end
3955end
3956
3957note Remove the tree at pb (not following links). depth guards the recursion; keep skips the
3958note models folder at the top level.
3959fn rmt depth ulong keep bool to void
3960d = new uchar 8192 0
3961if gt depth 32
3962ret
3963end
3964for pass ulong 3
3965fd = fopen pb 0 get pbn 0 573440 0
3966if lt fd 0
3967r = unlink pb 0 get pbn 0
3968ret
3969end
3970while true bound 100000
3971n = getdnts int fd d 0 8192
3972if le n 0
3973break
3974end
3975o = ulong 0
3976while lt o ulong n bound 8192
3977o = rment d o depth keep
3978end
3979end
3980c = fclose int fd
3981r = rmdir pb 0 get pbn 0
3982if or eq r 0 eq r -2
3983ret
3984end
3985end
3986end
3987
3988note One directory entry at d[o]: remove it (recursing into directories). Returns the next offset.
3989fn rment d view uchar 8192 o ulong depth ulong keep bool to ulong
3990rl = or ulong get d add o 16 shl ulong get d add o 17 8
3991if eq rl 0
3992ret 8192
3993end
3994k = ulong 0
3995while ne get d add add o 19 k 0 bound 256
3996k = add k 1
3997end
3998if isdot d add o 19 k
3999ret add o rl
4000end
4001if and and keep eq depth 0 isname d add o 19 k
4002ret add o rl
4003end
4004sv = get pbn 0
4005pbyte 47
4006for i ulong k
4007pbyte get d add add o 19 i
4008end
4009if eq get d add o 18 4
4010rmt add depth 1 keep
4011else
4012r = unlink pb 0 get pbn 0
4013end
4014put pbn 0 sv
4015ret add o rl
4016end
4017
4018fn isdot d view uchar 8192 o ulong k ulong to bool
4019if ne get d o 46
4020ret false
4021end
4022if eq k 1
4023ret true
4024end
4025ret and eq k 2 eq get d add o 1 46
4026end
4027
4028fn isname d view uchar 8192 o ulong k ulong to bool
4029if ne k len u_mods
4030ret false
4031end
4032for i ulong k
4033if ne get d add o i get u_mods i
4034ret false
4035end
4036end
4037ret true
4038end
4039
4040note aienos uninstall [--keep-model] [--yes]
4041fn uninst keep bool yes bool to int
4042if not yes
4043emit u_sure
4044putb 58
4045putb 32
4046w = flush
4047n = rline
4048if not ibis t_yes
4049emit u_no
4050putb 10
4051w = flush
4052ret 0
4053end
4054end
4055if not estop
4056emit u_stop
4057putb 10
4058w = flush
4059ret 1
4060end
4061ulist
4062pbase
4063rmt 0 keep
4064emit u_done
4065putb 10
4066if keep
4067emit u_kept
4068putb 10
4069end
4070w = flush
4071ret 0
4072end
4073
4074note ---------- rollback ----------
4075
4076note aienos rollback: point current at the newest other release in releases/.
4077fn rollbk to int
4078best = new uchar 256 0
4079pbase
4080pstr r_cur
4081n = readlnk pb 0 get pbn 0 rb 0 512
4082put rbn 0 0
4083if gt n 0
4084put rbn 0 ulong n
4085end
4086bn = rpick best
4087if eq bn 0
4088emit r_none
4089putb 10
4090w = flush
4091ret 1
4092end
4093ret rswap best bn
4094end
4095
4096note Pick the greatest release name that is not the current target (rb holds the link text).
4097fn rpick best edit uchar 256 to ulong
4098d = new uchar 8192 0
4099bn = ulong 0
4100pbase
4101pstr r_rel
4102fd = fopen pb 0 get pbn 0 540672 0
4103if lt fd 0
4104ret 0
4105end
4106n = getdnts int fd d 0 8192
4107c = fclose int fd
4108if le n 0
4109ret 0
4110end
4111o = ulong 0
4112while lt o ulong n bound 8192
4113rl = or ulong get d add o 16 shl ulong get d add o 17 8
4114if eq rl 0
4115break
4116end
4117bn = rcand d add o 19 best bn
4118o = add o rl
4119end
4120ret bn
4121end
4122
4123note Consider entry name d[o..]: keep it in best when it is greater than best and not current.
4124fn rcand d view uchar 8192 o ulong best edit uchar 256 bn ulong to ulong
4125k = ulong 0
4126while and ne get d add o k 0 lt k 200 bound 256
4127k = add k 1
4128end
4129if eq get d o 46
4130ret bn
4131end
4132if and eq get rbn 0 add len r_pre k rbat len r_pre part d o k
4133ret bn
4134end
4135if not gtname d o k best bn
4136ret bn
4137end
4138for i ulong k
4139put best i get d add o i
4140end
4141ret k
4142end
4143
4144fn gtname d view uchar 8192 o ulong k ulong best view uchar 256 bn ulong to bool
4145for i ulong k
4146if ge i bn
4147ret true
4148end
4149a = get d add o i
4150b = get best i
4151if ne a b
4152ret gt a b
4153end
4154end
4155ret false
4156end
4157
4158fn rswap best view uchar 256 bn ulong to int
4159pkclr
4160pclr
4161pstr r_pre
4162for i ulong bn
4163pbyte get best i
4164end
4165pkpath
4166pbase
4167pstr r_new
4168x = unlink pb 0 get pbn 0
4169pkpath
4170r = symlnk pk 0 get pkn 0
4171if ne r 0
4172ret 1
4173end
4174pkclr
4175pbase
4176pstr r_new
4177pkpath
4178pbase
4179pstr r_cur
4180pkpath
4181r = renames pk 0 get pkn 0 0
4182if ne r 0
4183ret 1
4184end
4185emit r_ok
4186emit r_pre
4187for i ulong bn
4188putb get best i
4189end
4190putb 10
4191w = flush
4192ret 0
4193end
4194note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4195note main.om: the aienos command. With no argument (or "wizard") it runs the full-screen wizard;
4196note "doctor", "chat", "start", "stop", "verify", "source", "about", "uninstall" and "rollback" are the
4197note small commands beside it. Build: concatenate sha256.om lib.om hole.om doctor.om net.om steps.om
4198note engine.om main.om, in that order, and compile the result with the pinned omc (see build.sh).
4199
4200text v_tag "alpha-20261026.2"
4201text a_l1 "Sovereign Intelligence alpha-20261026.2: the installer and the aienos command"
4202text a_l2 "written in Omega (.om), compiled by omc sha256 befb8199db8c4bca188a494dfaac2a6f0ee5c36fcea11188c75666c55fce8a1d"
4203text a_l3 " (aien-dev/omega-mv 3364a1dfd0ca50c1b82bf19ba34932d8bc10a7a9, seed/out/omc)"
4204text a_l4 "engine: aien-serve-http sha256 19173f9ec3b609fe79af644f84741d8808b92ea8eb3ecec4bc945af6f22b3aeb,"
4205text a_l5 " the build that serves the Spark's 35B: aien-dev/aien-sovereign-core-mv branch ship/motor-l387"
4206text a_l6 " commit 59b05a71a33e4a2f1324db2f2b6407ee82b8c2c3 (a development build, not a Core release tag)"
4207text a_l7 " evidence: Core evidence/l387-motor-ship (merge train 20261022T0244Z-bfc41659, timing runs)"
4208text a_l8 "GPU path: the engine's statically linked libomega_gpu.a (omega ship/motor-l387 6de999da) talks to"
4209text a_l9 " /dev/nvidiactl, /dev/nvidia0 and /dev/nvidia-uvm. There is no separate CUDA++ runtime."
4210text a_l10 "model: Qwen/Qwen3.6-35B-A3B-FP8 revision 95a723d08a9490559dae23d0cff1d9466213d989 (37.5 GB)"
4211text a_l11 " This is the only model offered. A 27B is to come; it is not offered in this release."
4212text a_l12 "evidence: this engine binary serving the 35B on a GB10 EXERCISED (it is the live server's build);"
4213text a_l13 " this installer's GB10 install and first token, and the 3x physical qualification: NOT_RUN."
4214text a_l14 "signature: Ed25519 alpha release key ff949504b427680039d53c33c85c448546b57d590eb1ecee3bb2ed6c2eaaf54a"
4215text a_l15 " (an alpha key; it is rotated to a ceremony key before beta)"
4216text s_l1 "My Omega source ships with this release:"
4217text s_l2 "/share/aienos/wizard/"
4218text s_l3 " sha256.om lib.om hole.om doctor.om net.om steps.om engine.om main.om"
4219text s_l4 "/share/aienos/aienos.om"
4220text s_l5 " the same files concatenated in build order: one unit, one compile"
4221text s_l6 "Also online: https://www.aienos.com/alpha/ and https://github.com/aien-dev/sovereign-intelligence"
4222text w_l1 "Welcome. I am Drake, and this is Sovereign Intelligence, the AienOS alpha."
4223text w_l2 "This installer is written in Omega, my own language. It sets up a local model on"
4224text w_l3 "your DGX Spark that runs on my own engine: no CUDA toolkit, no libcuda, no cuBLAS."
4225text w_l4 "NVIDIA's kernel driver stays. Everything else NVIDIA ships stays installed, unused."
4226text w_l5 "Next: doctor, plan, your yes, install, model, first chat. Nothing changes before your yes."
4227text w_l6 "Type about for versions and evidence, source for my .om source, q to quit."
4228text w_go "Press Enter to run the doctor"
4229text x_l1 "This alpha runs on Linux arm64 with an NVIDIA GB10 (DGX Spark) only."
4230text x_l2 "Here is what is coming: https://www.aienos.com/alpha/"
4231text x_l3 "I changed nothing. The files the installer unpacked go away with: aienos uninstall"
4232text p_l1 "Here is exactly what changes, all inside your home folder:"
4233text p_l2 "/releases/"
4234text p_l3 " this release, already unpacked and checked"
4235text p_l4 "/models/"
4236text p_l5 "~/.local/bin/aienos, the menu entry and the desktop icon (already there)"
4237text p_l6 "/engine.log the engine's log, when it runs"
4238text p_l7 "Not touched: NVIDIA's driver, the CUDA toolkit, libcuda, cuBLAS, /usr, /etc. No sudo."
4239text p_l8 "Undo everything at any time: aienos uninstall"
4240text p_l9 " the model: "
4241text p_ok "Press Enter for the last question"
4242text c_l1 "Type yes to begin. Anything else stops here, and nothing changes."
4243text c_q "yes or no"
4244text c_stop "Stopped. Nothing was changed."
4245text c_fail "Stopped. Run aienos again once the problem above is fixed; it picks up where it left off."
4246text t_q "q"
4247text t_about "about"
4248text t_source "source"
4249text t_probe "AIENOS_PROBE_ROOT"
4250text t_home "HOME"
4251text t_plain "--plain"
4252text t_exe "/proc/self/exe"
4253text h_stty "stty"
4254text h_size "size"
4255text k_wiz "wizard"
4256text k_doc "doctor"
4257text k_chat "chat"
4258text k_start "start"
4259text k_stop "stop"
4260text k_vfy "verify"
4261text k_unin "uninstall"
4262text k_roll "rollback"
4263text k_help "usage: aienos [wizard [--plain] | doctor | chat | start | stop | verify | source | about | uninstall [--keep-model] [--yes] | rollback]"
4264text n_nohome "HOME is not set; I cannot tell where to install."
4265text n_badrt "I cannot find my own folder (/proc/self/exe)."
4266text n_vok " files match SHA256SUMS"
4267text n_vbad "a file does not match SHA256SUMS"
4268text n_start "engine started, pid "
4269text n_ready "engine ready on http://127.0.0.1:18100/v1"
4270text n_nostrt "engine did not become ready; see ~/.local/share/aienos/engine.log"
4271text n_stopd "engine stopped"
4272text n_chat1 "aienos chat: type a message and press Enter. /bye leaves."
4273text n_bye "/bye"
4274text n_you "you&gt; "
4275text n_ai "model&gt; "
4276text n_err "request failed: "
4277text t_sp " "
4278
4279note argument i into ib; returns its length or -1.
4280fn arg i ulong to long
4281if ge i ulong argcnt
4282ret -1
4283end
4284n = argread i ib 0 len ib
4285if lt n 0
4286ret -1
4287end
4288put ibn 0 ulong n
4289ret n
4290end
4291
4292note HOME, the probe prefix and this release's folder (the parent of bin/aienos).
4293fn setup to bool
4294sinit
4295n = envget t_home
4296if le n 0
4297ret false
4298end
4299for i ulong ulong n
4300put hb i get eb add len t_home add i 1
4301end
4302put hbn 0 ulong n
4303n = envget t_probe
4304if gt n 0
4305for i ulong ulong n
4306put pr i get eb add len t_probe add i 1
4307end
4308put prn 0 ulong n
4309end
4310ret selfdir
4311end
4312
4313fn selfdir to bool
4314n = readlnk t_exe 0 len t_exe rt 0 len rt
4315if or le n 0 ge n long len rt
4316ret false
4317end
4318k = ulong n
4319s = ulong 0
4320for pass ulong 2
4321while and gt k 0 ne get rt sub k 1 47 bound 1024
4322k = sub k 1
4323end
4324if gt k 0
4325k = sub k 1
4326end
4327end
4328put rtn 0 k
4329ret gt k 0
4330end
4331
4332note Terminal: animate when stdin and stdout are character devices and stty reports at least
4333note 64 columns and 22 rows; the picture takes what the 12-line panel leaves. The size comes from the host's stty (Omega has no window-size word yet).
4334fn term plain bool to void
4335put ui 0 0
4336put tw 0 80
4337put th 0 24
4338if plain
4339ret
4340end
4341r = fstat 0 sb 0 128
4342if or ne r 0 ne stype 2
4343ret
4344end
4345r = fstat 1 sb 0 128
4346if or ne r 0 ne stype 2
4347ret
4348end
4349if not findbin h_stty
4350ret
4351end
4352pkclr
4353pkpath
4354pkstr h_size
4355r = runcap
4356if ne r 0
4357ret
4358end
4359rows = rbnum 0
4360sp = rbfind 0 t_sp
4361cols = rbnum add sp 1
4362if or lt cols 64 lt rows 22
4363ret
4364end
4365if gt cols 400
4366cols = 400
4367end
4368put tw 0 cols
4369put th 0 rows
4370note The panel under the picture keeps 12 lines: the plan and the doctor must fit whole.
4371sh = ulong 6
4372if gt rows 22
4373sh = sub rows 16
4374end
4375if gt sh 30
4376sh = 30
4377end
4378put ui 1 sh
4379put ui 0 1
4380end
4381
4382fn plines to void
4383pl w_l1
4384pln
4385pln
4386pl w_l2
4387pln
4388pl w_l3
4389pln
4390pl w_l4
4391pln
4392pln
4393pl w_l5
4394pln
4395pc 5
4396pl w_l6
4397pc 2
4398end
4399
4400fn about to void
4401pl a_l1
4402pln
4403pl a_l2
4404pln
4405pl a_l3
4406pln
4407pl a_l4
4408pln
4409pl a_l5
4410pln
4411pl a_l6
4412pln
4413pl a_l7
4414pln
4415pl a_l8
4416pln
4417pl a_l9
4418pln
4419pl a_l10
4420pln
4421pl a_l11
4422pln
4423pl a_l12
4424pln
4425pl a_l13
4426pln
4427pl a_l14
4428pln
4429pl a_l15
4430end
4431
4432fn source to void
4433pl s_l1
4434pln
4435pc 6
4436plroot
4437pl s_l2
4438pc 2
4439pln
4440pl s_l3
4441pln
4442pc 6
4443plroot
4444pl s_l4
4445pc 2
4446pln
4447pl s_l5
4448pln
4449pln
4450pl s_l6
4451end
4452
4453fn plroot to void
4454for i ulong get rtn 0
4455pc get rt i
4456end
4457end
4458
4459note Welcome; loops on about and source. Returns false to quit.
4460fn stwel to bool
4461while true bound 1000
4462enter 0
4463pclear
4464plines
4465prompt w_go
4466show
4467r = ask
4468if lt r 0
4469ret false
4470end
4471if ibis t_q
4472ret false
4473end
4474if ibis t_about
4475sub1 true
4476end
4477if ibis t_source
4478sub1 false
4479end
4480if not or ibis t_about ibis t_source
4481ret true
4482end
4483end
4484ret false
4485end
4486
4487fn sub1 isab bool to void
4488pclear
4489if isab
4490about
4491else
4492source
4493end
4494prompt t_next
4495show
4496r = ask
4497end
4498
4499note Doctor screen. Returns true when the machine can take this alpha.
4500fn stdoc to bool
4501enter 1
4502pclear
4503need = mneed
4504ok = doctor need
4505for i ulong NCHK
4506dpanel i
4507end
4508if not ok
4509pln
4510pc 4
4511pl x_l1
4512pc 2
4513pln
4514pl x_l2
4515pln
4516pl x_l3
4517prompt t_close
4518show
4519r = ask
4520ret false
4521end
4522prompt t_next
4523show
4524r = ask
4525ret ge r 0
4526end
4527
4528note Bytes the model still needs on disk: none when verified, else its size plus 1 GB.
4529fn mneed to ulong
4530if not mopen
4531ret 0
4532end
4533if mdone
4534ret 0
4535end
4536ret add mbytes 1000000000
4537end
4538
4539fn dpanel i ulong to void
4540k = get dk i
4541if eq k 0
4542pc 3
4543pl k_ok
4544end
4545if eq k 1
4546pc 1
4547pl k_wn
4548end
4549if eq k 2
4550pc 4
4551pl k_no
4552end
4553if eq k 3
4554pc 5
4555pl k_in
4556end
4557pc 2
4558pc 32
4559n = get ptn 0
4560dnm i
4561while lt sub get ptn 0 n 9 bound 16
4562pc 32
4563end
4564for j ulong get dtn i
4565pc get dt add mul i 192 j
4566end
4567pln
4568end
4569
4570fn dnm i ulong to void
4571if eq i 0
4572pl n_arch
4573end
4574if eq i 1
4575pl n_gpu
4576end
4577if eq i 2
4578pl n_drv
4579end
4580if eq i 3
4581pl n_mem
4582end
4583if eq i 4
4584pl n_disk
4585end
4586if eq i 5
4587pl n_inst
4588end
4589if eq i 6
4590pl n_busy
4591end
4592if eq i 7
4593pl n_nv
4594end
4595end
4596
4597fn stplan to bool
4598enter 2
4599pclear
4600pl p_l1
4601pln
4602pln
4603pc 6
4604plbase
4605pl p_l2
4606pl v_tag
4607pc 2
4608pl p_l3
4609pln
4610pc 6
4611plbase
4612pl p_l4
4613for i ulong get mnn 0
4614pc get mnm i
4615end
4616pc 2
4617pln
4618pl p_l9
4619plgb mbytes
4620pl m_l3
4621plnum mfiles
4622pl m_l4
4623pln
4624pc 6
4625plbase
4626pc 2
4627pl p_l6
4628pln
4629pl p_l5
4630pln
4631pln
4632pl p_l7
4633pln
4634pc 1
4635pl p_l8
4636pc 2
4637prompt p_ok
4638show
4639r = ask
4640ret ge r 0
4641end
4642
4643fn styes to bool
4644enter 3
4645pclear
4646pc 6
4647pl c_l1
4648pc 2
4649prompt c_q
4650show
4651r = ask
4652ret and ge r 0 ibis t_yes
4653end
4654
4655fn bye t view uchar * to void
4656if eq get ui 0 1
4657scrn false
4658end
4659sgr0
4660putb 10
4661emit t
4662putb 10
4663w = flush
4664end
4665
4666note The full wizard. Exit 0 for a finished run and for a friendly refusal; 1 when a step failed.
4667fn wizard plain bool to int
4668term plain
4669if not mopen
4670ret 3
4671end
4672if eq get ui 0 1
4673scrn true
4674w = flush
4675end
4676if not stwel
4677bye c_stop
4678ret 0
4679end
4680if not stdoc
4681bye x_l3
4682ret 0
4683end
4684if not stplan
4685bye c_stop
4686ret 0
4687end
4688if not styes
4689bye c_stop
4690ret 0
4691end
4692if not stinst
4693bye c_fail
4694ret 1
4695end
4696if not mstep
4697bye c_fail
4698ret 1
4699end
4700if not stchat
4701bye c_fail
4702ret 1
4703end
4704stdone eq get ui 11 1
4705if eq get ui 11 1
4706bye d_l1
4707else
4708bye d_l0
4709end
4710ret 0
4711end
4712
4713fn istty fd int to bool
4714r = fstat fd sb 0 128
4715ret and eq r 0 eq stype 2
4716end
4717
4718fn cdoctor to int
4719need = mneed
4720ok = doctor need
4721col = istty 1
4722for i ulong NCHK
4723cline i col
4724putb 10
4725end
4726w = flush
4727if ok
4728ret 0
4729end
4730emit x_l1
4731putb 10
4732emit x_l2
4733putb 10
4734w = flush
4735ret 1
4736end
4737
4738fn cverify to int
4739x = mopen
4740k = sums
4741if lt k 0
4742emit n_vbad
4743putb 10
4744w = flush
4745ret 1
4746end
4747num ulong k
4748emit n_vok
4749putb 10
4750w = flush
4751ret 0
4752end
4753
4754note Start the engine when the doctor allows it and wait until it answers.
4755fn cstart to int
4756x = mopen
4757if alive PORT
4758emit n_ready
4759putb 10
4760w = flush
4761ret 0
4762end
4763ok = doctor 0
4764pclear
4765if ckskip
4766for i ulong get ptn 0
4767putb get pt i
4768end
4769putb 10
4770w = flush
4771ret 2
4772end
4773p = estart
4774if lt p 0
4775ret 1
4776end
4777emit n_start
4778num ulong p
4779putb 10
4780w = flush
4781if not ewait 2400
4782emit n_nostrt
4783putb 10
4784w = flush
4785ret 1
4786end
4787emit n_ready
4788putb 10
4789w = flush
4790ret 0
4791end
4792
4793fn cstop to int
4794if estop
4795emit n_stopd
4796putb 10
4797w = flush
4798ret 0
4799end
4800ret 1
4801end
4802
4803fn cchat to int
4804r = cstart
4805if ne r 0
4806ret r
4807end
4808emit n_chat1
4809putb 10
4810put hsn 0 0
4811while true bound 100000
4812emit n_you
4813w = flush
4814n = rline
4815if or lt n 0 ibis n_bye
4816ret 0
4817end
4818if gt get hsn 0 0
4819hstr j_comma
4820end
4821hstr j_user
4822hesc
4823hstr j_end
4824emit n_ai
4825w = flush
4826q = chatreq PORT
4827putb 10
4828w = flush
4829if ne q 0
4830emit n_err
4831snum q
4832putb 10
4833w = flush
4834else
4835hstr j_comma
4836hstr j_asst
4837for i ulong get abn 0
4838hbyte get ab i
4839end
4840hstr j_end
4841end
4842end
4843ret 0
4844end
4845
4846fn cprint to int
4847for i ulong get ptn 0
4848b = get pt i
4849if or ge b 7 eq b 10
4850putb b
4851end
4852end
4853putb 10
4854w = flush
4855ret 0
4856end
4857
4858fn iskey t view uchar * to bool
4859ret ibis t
4860end
4861
4862fn main to int
4863if not setup
4864emit n_nohome
4865putb 10
4866w = flush
4867ret 2
4868end
4869if lt arg 1 0
4870ret wizard false
4871end
4872if iskey k_wiz
4873plain = false
4874if ge arg 2 0
4875plain = ibis t_plain
4876end
4877ret wizard plain
4878end
4879if iskey k_doc
4880ret cdoctor
4881end
4882if iskey k_chat
4883ret cchat
4884end
4885if iskey k_start
4886ret cstart
4887end
4888if iskey k_stop
4889ret cstop
4890end
4891if iskey k_vfy
4892ret cverify
4893end
4894if iskey t_source
4895pclear
4896source
4897ret cprint
4898end
4899if iskey t_about
4900pclear
4901about
4902ret cprint
4903end
4904if iskey k_unin
4905ret cunin
4906end
4907if iskey k_roll
4908ret rollbk
4909end
4910emit k_help
4911putb 10
4912w = flush
4913ret 2
4914end
4915
4916fn cunin to int
4917keep = false
4918yes = false
4919for i ulong 2
4920if ge arg add i 2 0
4921if ibis u_keep
4922keep = true
4923end
4924if ibis u_yes
4925yes = true
4926end
4927end
4928end
4929x = mopen
4930ret uninst keep yes
4931end
4932</code></pre></details></section><section class="alpha-section" id="alpha-feedback"><p class="alpha-kicker">04 / BUILD IT WITH ME</p><h2>Tell me what happened.</h2><p>Open an issue in omega-projects (<code>omega-projects issues</code>). Include your hardware, operating system, release tag, the step that failed and the exact error. Remove tokens, personal paths, private prompts and model data before sharing a log.</p></section><section class="alpha-section alpha-exit" id="alpha-uninstall"><p class="alpha-kicker">05 / THE WAY BACK</p><h2>No one-way door.</h2><p>The installation lives under <code>~/.local/share/aienos</code>. It does not uninstall or overwrite NVIDIA packages or CUDA. Run <code>aienos uninstall</code> and type <code>yes</code> when asked. It removes the alpha installation, downloaded model, command and launchers. To keep the downloaded model, use <code>aienos uninstall --keep-model</code>. If the command is missing, run <code>~/.local/share/aienos/current/bin/aienos uninstall</code>.</p><p><a href="https://interplane.io/drakestapleton/sovereign-intelligence">Uninstaller source and release instructions</a></p><p class="alpha-small">I would rather hear why you left than make it difficult to leave.</p></section></article>