lumbda/docs/bend-dispatch.dot
russell@unturf.com 661f9a01ec
whitepaper: add bend chapter, fifth scope of feedback, source link
Folds 76 commits of substance since 2026-04-24 into the whitepaper
without losing any of the novel cross-domain glue the language earns
its keep on.

Additions
- §4.3 extended from four scopes to five, with bend as feedback across
  heterogeneous compute (host ↔ GPU). New diagram
  diagrams/five-scopes-feedback.png stacks the boundaries.
- §11.8 Bend: cross-tier GPU dispatch. Wire modes (S-exp text, BSHK
  binary), worker hosting per tier, spawn-process-stdio + flush-port
  cross-tier IPC, worker health heartbeat with VRAM-ranked pick,
  6-row catalog of live forms (cuda-shake-fanout, cuda-secp256k1-mul,
  cuda-bignum-cgbn, cuda-radix-sort, cuda-blake3-tree,
  cuda-sim-ops-bin). New diagram diagrams/bend-dispatch.png.
- §2.1 C-tier bignum: arbitrary-precision integers (Boehm-GC managed),
  which unblocked the secp256k1 widths the GPU forms need on the host
  side.
- §12.1 post-cycle audit: recv-exact O(n²)→O(n), asm scheme_read
  overflow, asm gc_sweep page-fault, C-tier JIT cur_code restore
  across CALL/RETURN.
- §13 GPU Phase 1 moved from future to shipped; Phase 2 trampolining
  and Phase 3 interaction combinators sharpened.
- Source repo link (git.unturf.com/engineering/unturf/lumbda) added
  to the cover page band and the Citation block.

Compressions (no novel glue dropped — audited per fox's constraint)
- §8.2-§8.5 EML derivation prose collapsed into a single §8.2
  derivation chain code block; §8.6 renumbered to §8.3.
- §6.6.3 adaptive-meta-GC narrative compressed; result table kept.
- §7.4.1 GC-build S-expression portal tightened to two paragraphs;
  "language is its own wire format" insight kept.

Preserved in full per audit
- §7.5 portable RNG state across tiers
- §7.5.1 one-side kernel entropy + portable bit-identical continuation
- §11.7 sendfile + adaptive preload (27 KB asm-gc within 2% of Caddy)
- §6.6.1 collaborative arena + mark verifier
- §6.6.5 precise block typing
- §8.1 + §8.3 Lumbda hosts its own EML proof checker, ~16× faster
  than Lean cold

Net RST: 1622 → 1655 lines.
2026-06-07 10:49:48 -04:00

97 lines
4.4 KiB
Text
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// Bend cross-tier GPU dispatch — 2026-06-07
// "A diagram is worth 10,000 words." — russell@unturf.com
//
// One (bend …) form. The dispatcher picks local vs worker per call.
// When it goes remote, the wire frame is either S-expression text
// (small payloads, parser cost dominates) or a 4-byte magic + raw
// bytes (huge payloads). Workers spawn a leaf CUDA binary via each
// tier's native process-spawn primitive. CUDA kernel returns bytes
// back through the same wire frame.
digraph bend_dispatch {
rankdir=LR
splines=true
nodesep=0.45
ranksep=0.7
node [shape=box, style="filled,rounded", fontname="Helvetica", fontsize=11, margin="0.18,0.10"]
edge [fontname="Helvetica", fontsize=9, arrowsize=0.85]
label="Bend — one (bend …) form across host, wire, worker, and GPU"
labelloc=t
fontsize=14
fontname="Helvetica Bold"
// ─── Caller side ────────────────────────────────────────────────
subgraph cluster_caller {
label="Caller tier (any of Python / C / asm)"
labelloc=t
style="rounded,filled"
fillcolor="#e8f4f8"
color="#0984e3"
fontname="Helvetica Bold"
fontsize=11
fontcolor="#0984e3"
call [label="(bend! …) form\nin user code" fillcolor="#b3d9e8"]
cost [label="cost estimator\n(local vs wire)" fillcolor="#d6eaf8"]
local [label="evaluate locally\n(small payloads)" fillcolor="#aed6f1"]
call -> cost
cost -> local [label="cheap" fontcolor="#1f618d"]
}
// ─── Wire ──────────────────────────────────────────────────────
subgraph cluster_wire {
label="Wire — port 8320 (BEND)"
labelloc=t
style="rounded,filled"
fillcolor="#fff8e1"
color="#f57f17"
fontname="Helvetica Bold"
fontsize=11
fontcolor="#f57f17"
sexp [label="S-expression\n(text)\n— small payloads" fillcolor="#ffe082"]
bin [label="binary frame\nmagic + raw bytes\n— huge payloads\n(BSHK, BCGB, BSCP,\n BSRT, BSB3, …)" fillcolor="#ffd54f"]
}
cost -> sexp [label="≤ ~1k inputs" fontcolor="#f57f17"]
cost -> bin [label="≥ ~1k inputs\n(150× over S-exp\n at 1 M)" fontcolor="#f57f17"]
// ─── Worker side ───────────────────────────────────────────────
subgraph cluster_worker {
label="Worker tier (any of Python / C / asm — listens on :8320)"
labelloc=t
style="rounded,filled"
fillcolor="#e8f5e9"
color="#2e7d32"
fontname="Helvetica Bold"
fontsize=11
fontcolor="#2e7d32"
recv [label="gpu-worker\nrecv + dispatch\n+ health" fillcolor="#a5d6a7"]
spawn [label="spawn-process-stdio\n— Py: subprocess.Popen\n— C: fork + execve\n— asm: pipe2+fork+execve\n (raw syscall, no libc)" fillcolor="#c8e6c9"]
recv -> spawn
}
sexp -> recv
bin -> recv
// ─── Leaf CUDA binary + GPU ────────────────────────────────────
subgraph cluster_gpu {
label="Leaf CUDA binary + RTX 3090"
labelloc=t
style="rounded,filled"
fillcolor="#f3e5f5"
color="#7b1fa2"
fontname="Helvetica Bold"
fontsize=11
fontcolor="#7b1fa2"
leaf [label="shake256-fanout /\nsecp256k1-batch-mul /\ncgbn-batch-worker /\nblake3-fanout /\nradix-sort /\ndemo_ops …" fillcolor="#ce93d8"]
kernel [label="CUDA kernel\n(byte-identical\n vs host reference)" fillcolor="#ba68c8"]
leaf -> kernel
}
spawn -> leaf [label="stdin / stdout" fontcolor="#7b1fa2"]
// ─── Return path ───────────────────────────────────────────────
kernel -> leaf [label="bytes back" fontcolor="#7b1fa2" style=dashed]
leaf -> spawn [style=invis]
spawn -> recv [label="result" style=dashed fontcolor="#2e7d32"]
recv -> cost [label="wire frame back" style=dashed fontcolor="#f57f17" constraint=false]
local -> call [label="value" style=dashed fontcolor="#1f618d" constraint=false]
}