lumbda/wasm/app/demos/bend-gpu.lsp
russell@unturf.com 036fab47fa
bend: handler returns formatted string + http-listener ships strings raw
The previous attempt to ship a pretty summary via an (summary "...")
field inside the structured response broke on the asm (WAT) tier
because read-from-string isn't a primitive there — the demo
extraction fell through to the raw fallback and dumped the entire
escaped S-expression.

Two-part fix that works on all three tiers:

  http-listener (gpu-worker.lsp:1103-1116) — POST response builder
  now checks if the handle-request return value is a string and
  ships it as the raw HTTP body in that case. S-expression returns
  still go through write-to-string. One-line guard, no impact on
  ping/health/cuda-shake-fanout/cuda-sim-ops-bin which all keep
  returning structured S-exps.

  handle-cuda-secp256k1-bench — returns the formatted summary
  string directly instead of an (ok ... (summary ...)) wrapping.
  Drops the now-redundant structured fields; every number lives
  inside the human-readable text already. asm / c / python demo
  just calls (display (bend!-call "(cuda-secp256k1-bench N)")) and
  the formatted output panel renders identically on all tiers.

Demo simplified accordingly: three (display (bend!-call …)) calls
with newlines between, no read-from-string / assoc / pair? dance.
2026-06-14 20:15:37 -04:00

33 lines
1.4 KiB
Text

; bend dispatch — ship a workload to a CUDA worker.
;
; This demo refuses to run locally — set a bend URL in the ⚡ bar
; above first. The playground guards the Run button so a customer
; machine never burns minutes on the local tiers.
;
; Headline: 100,000,000 secp256k1 scalar*G operations dispatched in
; a single ~32-byte HTTP POST. The 3.2 GB of random scalars never
; crosses the wire — the worker synthesizes them from /dev/urandom,
; runs cuda-secp256k1-batched-mul, and ships a small formatted
; summary back. On a 3090 the daemon finishes the math in ~13 s;
; on a single CPU core (libsecp256k1 ~50K keys/s) the same workload
; would take more than half an hour.
;
; The bench op returns a pre-formatted multi-line string (the http
; listener detects string responses and ships them raw, no S-exp
; escape soup) so the playground output panel shows clean prose on
; every tier — asm / c / python all use the same demo source.
(display ";; 1. probe round-trip ...") (newline)
(display " (ping) → ") (display (bend!-call "(ping)")) (newline)
(newline)
(display ";; 2. worker telemetry ...") (newline)
(display " (health) → ") (display (bend!-call "(health)")) (newline)
(newline)
(display ";; 3. heavy GPU compute — sit tight, this is real math") (newline)
(newline)
(display (bend!-call "(cuda-secp256k1-bench 100000000)")) (newline)
(newline)
(print "(your laptop never did the math — it just watched it complete)")