[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"project-107953":3},{"id":4,"name":5,"fullName":6,"owner":7,"repo":5,"description":8,"homepage":9,"htmlUrl":10,"language":11,"languages":10,"totalLinesOfCode":10,"stars":12,"forks":13,"watchers":14,"openIssues":15,"contributorsCount":15,"subscribersCount":15,"size":15,"stars1d":15,"stars7d":16,"stars30d":17,"stars90d":15,"forks30d":15,"starsTrendScore":18,"compositeScore":19,"rankGlobal":10,"rankLanguage":10,"license":20,"archived":21,"fork":21,"defaultBranch":22,"hasWiki":21,"hasPages":21,"topics":23,"createdAt":10,"pushedAt":24,"updatedAt":25,"readmeContent":26,"aiSummary":27,"trendingCount":15,"starSnapshotCount":15,"syncStatus":28,"lastSyncTime":29,"discoverSource":30},107953,"open-flapping-airplanes","Bobliuuu\u002Fopen-flapping-airplanes","Bobliuuu","reproducing the flapping airplanes megakernel, in collab with magni","https:\u002F\u002Fmagnihq.com",null,"Cuda",143,19,107,0,6,18,1,48.7,"MIT License",false,"main",[],"2026-11-08 03:22:52","2026-11-20 09:16:03","\u003Cdiv align=\"center\">\n\n\u003Cimg src=\"site\u002Fassets\u002Fhero.svg\" alt=\"open-flapping-airplanes: one kernel, three programs\" width=\"100%\">\n\n# open-flapping-airplanes\n\n**One persistent GPU kernel that trains a language model, serves it live, and plays Doom, all at the same time.**\n\n![GPU](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002FGPU-A100%20%C2%B7%20B200%20%C2%B7%20B300-76b900?logo=nvidia&logoColor=white) ![launches](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002Fkernel%20launches%20for%20the%20run-1-27c8e8) ![doom](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002FDoom-35%20fps%20on%20the%20GPU-f2c14e) ![status](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002Fstatus-research%20demo-lightgrey)\n\n[📊 Results](#results) · [🧩 Architecture](#architecture) · [✈️ Compared with Flapping Airplanes](#how-it-compares-to-flapping-airplanes) · [🚀 Quick start](#quick-start) · [Repo map](#repo-map) · [Limitations](#limitations) · [🎬 Videos](#videos)\n\n\u003C\u002Fdiv>\n\n---\n\nFlapping Airplanes showed a demo video of one GPU kernel that trains a model, serves it, and plays Doom at the same time. We rebuilt it from that video, in the open.\nIt is a real persistent megakernel: **one launch, and its blocks never exit.** They pull training, serving and Doom tasks from on-GPU queues\nuntil the run ends. We never saw their code; everything here was written from scratch, and every number comes from a result file in this repo.\n\n**Live demo (94 s):** our run on one B200, in Flapping Airplanes' format, with their demo next to ours at the same moment of each run.\n\nhttps:\u002F\u002Fgithub.com\u002Fuser-attachments\u002Fassets\u002F97e664f5-5b6b-43c1-978b-eb30530e9565\n\n**Explainer (98 s):** the problem, the idea, the Doom port, the method, and the results against Flapping Airplanes' published numbers.\n\nhttps:\u002F\u002Fgithub.com\u002Fuser-attachments\u002Fassets\u002F239f7d26-4d33-4623-b42c-94647baa15bb\n\n## What It Does\n\nBuilt by Jerry Zhu from Shopify and Arnold Xu from [Magni](https:\u002F\u002Fmagnihq.com): Magni uses AI agents to push GPUs closer to their physical limits using near-silicon inference. \n\n| | Program | What happens |\n|---|---|---|\n| Train | **Training** | A GPT learns online: forward, backward and AdamW all run as tasks inside the kernel. |\n| Serve | **Inference** | Text streams out of the live, still-training weights, so the output improves while the loss falls. |\n| Play | **Doom** | The real engine (doomgeneric, shareware E1M1) runs its own game loop on the GPU at 35 fps, played by a scripted player. |\n\n\u003Cdiv align=\"center\">\n\n![Live dashboard: training loss, streaming text, Doom](site\u002Fassets\u002Fdashboard.png)\n\n\u003C\u002Fdiv>\n\n## Results\n\n### Headline: LLM scale on one NVIDIA B200 (Modal `gpu=\"B200\"`, 148 SMs)\n\n162.4M-parameter GPT (\"S\"), 4,000 steps of 4,096 tokens, final loss 2.1575. Split: 116 SMs train, 24 serve, 8 run Doom. Serving uses Flapping\nAirplanes' prompt \"What is a megakernel?\". Baselines run alone on the same SM shares (CUDA MPS). Source: [`b200-run\u002FREADME.md`](b200-run\u002FREADME.md).\n\n| System | 4,000 training steps | Serving | Doom |\n|---|---|---|---|\n| **open-flapping-airplanes, `tcgen05` GEMMs, 3 stages** (`ofa_tc3`) | **48.1 s** | **1,660 tok\u002Fs** | 35 fps |\n| **open-flapping-airplanes, `tcgen05` GEMMs, 2 stages** (`ofa_tc2`) | **52.4 s** | **1,741 tok\u002Fs** | 35 fps |\n| open-flapping-airplanes, `mma.sync` GEMMs (`ofa_s`, first build) | 95.8 s | 1,783 tok\u002Fs | 35 fps |\n| Megatron-core + Transformer Engine, eager, 116 SMs | 62.4 s | - | - |\n| **Megatron-core + Transformer Engine, CUDA graphs, 116 SMs** | **43.1 s** | - | - |\n| PyTorch + flash attention, one CUDA graph per step, 116 SMs | 50.9 s | - | - |\n| vLLM 0.33.0, CUDA graphs, 24 SMs, 16 reserved CPU cores | - | 1,537 tok\u002Fs | - |\n\nMegatron + Transformer Engine with CUDA graphs trains faster than both of our builds on this GPU (43.1 s against 48.1 s and 52.4 s). Eager\nMegatron is slower than us, and vLLM serves slower than us.\n\n\u003Cp align=\"center\">\n\u003Cimg src=\"site\u002Fassets\u002F1_training.png\" alt=\"Training time on 116 SMs, B200\" width=\"49%\">\n\u003Cimg src=\"site\u002Fassets\u002F2_serving.png\" alt=\"Serving tokens per second on 24 SMs, B200\" width=\"49%\">\n\u003C\u002Fp>\n\u003Cp align=\"center\">\n\u003Cimg src=\"site\u002Fassets\u002F3_sharing.png\" alt=\"One kernel vs sequential vs side by side\" width=\"60%\">\n\u003C\u002Fp>\n\nRed bars are numbers read from Flapping Airplanes' video; everything else was measured here. Charts are generated by [`tools\u002Fmake_b200_charts.py`](tools\u002Fmake_b200_charts.py) (run it from `site\u002Fassets\u002F`).\n\n### Same GPT on one NVIDIA A100 (108 SMs, 85 \u002F 17 \u002F 6 split)\n\n| System | 4,000 steps | Throughput | Serving | Doom |\n|---|---|---|---|---|\n| **open-flapping-airplanes, `llm\u002Fofa_fast`** (best A100 build, real Doom on) | **190.7 s** | 85.9k tok\u002Fs | 591 tok\u002Fs | 35 fps |\n| Megatron-core + Transformer Engine, restricted to 84 SMs, alone | 233.2 s | - | - | - |\n| PyTorch eager, 84 SMs, alone | 226.2 s | - | - | - |\n\n`ofa_fast` is 1.22x faster than the Megatron + TE baseline and 1.19x faster than eager PyTorch, with the same loss (2.1490) as the Doom-free\nbuild. It merges Doom's PTX into the kernel's PTX so the Doom build avoids the relocatable-code slowdown (224 s with `-rdc`, 190.7 s merged);\nsee [`llm\u002Fofa_fast\u002FREADME.md`](llm\u002Fofa_fast\u002FREADME.md) and [`llm\u002Fbaseline\u002FREADME.md`](llm\u002Fbaseline\u002FREADME.md).\n\n### Same GPT on an NVIDIA B300 (clearly not a B200)\n\nModal `gpu=\"B300\"` (SXM6, compute capability 10.3, 148 SMs), Doom compiled out, `tcgen05` megakernel: **49.9 s** for 4,000 steps on the 116 \u002F 24 \u002F 8\nsplit (40.1 s training-only on all SMs), serving about 1,080 tok\u002Fs. Baselines there had no Transformer Engine: PyTorch eager on 116 SMs 55.9 s,\nMegatron-core without TE 136.6 s. Data: [`b300-run\u002F`](b300-run\u002FREADME.md), report [`B300_ROUND2.md`](b300-run\u002FB300_ROUND2.md).\n**These are B300 measurements, not B200**; the folder name comes from a Modal `B200+` request that can land on either chip.\n\n### The small demo (115k-parameter char model, A100 and B200)\n\nThe original demo is a tiny model whose step lasts about 56 microseconds. There, the same task code launched as ordinary per-op kernels is faster\nper job (13-25% faster at training); the megakernel's advantage is running all three jobs at once: two processes sharing the GPU are 45-49% slower\non the A100 and 42-58% slower on the B200. Numbers: [`benchmarks\u002Fresults\u002F`](benchmarks\u002Fresults\u002F) and the [stats site](site\u002F).\n\n| Demo, all three at once | Train steps\u002Fs | Infer tok\u002Fs | Doom fps | Launches |\n|---|---|---|---|---|\n| A100-SXM4-40GB | 13,507.6 | 53,211.6 | 35.0 | 1 |\n| B200 | 17,788.6 | 71,349.9 | 35.0 | 1 |\n\n## Architecture\n\nEvery block of the kernel is a long-lived worker. At start each block reads its SM id and takes a role from a static partition (B200: 24 SMs\nserve, 8 run Doom, 116 train). Inside the training and serving jobs, thread 0 of a block claims the next task from one ticket counter with a\nsingle `atomicAdd` (no locks, no CAS retry loop) and the whole block runs it. Each task belongs to a phase, and each phase has a completion\ncounter. When a task finishes, the block does a `__threadfence` and then an `atomicAdd` on its phase's counter. Before it starts a task, thread 0\nreads the counters of the phases it depends on with acquire loads and sleeps (`__nanosleep`) until they reach the target. So a forward pass\nreleases its backward pass and a token releases the next token, with no kernel launch in between. Tickets are handed out in dependency order, so\na block waiting on its inputs can never deadlock: the lowest unfinished ticket always has its dependencies done.\n\n```mermaid\nflowchart TB\n    H[\"host: ONE launch\"] --> K\n    subgraph K[\"persistent megakernel (all SMs)\"]\n        direction TB\n        S[\"each block reads its SM id: static role\u003Cbr\u002F>no preemption, no host in the loop\"]\n        subgraph P[\"SM partition (B200: 116 \u002F 24 \u002F 8)\"]\n            direction LR\n            T[\"116 SMs\u003Cbr\u002F>training tasks\u003Cbr\u002F>fwd, bwd, AdamW\"]\n            I[\"24 SMs\u003Cbr\u002F>decode tasks\u003Cbr\u002F>read live weights\"]\n            D[\"8 SMs\u003Cbr\u002F>Doom engine\u003Cbr\u002F>35 fps\"]\n        end\n        S --> P\n        C[\"one ticket counter per job + one completion counter per phase\u003Cbr\u002F>in global memory\"]\n        P \u003C--> C\n    end\n    K --> W[\"pinned memory + HTTP\"] --> B[\"browser: loss, streaming text, Doom frame\"]\n```\n\n```mermaid\nsequenceDiagram\n    autonumber\n    participant T as thread 0 of a block\n    participant Q as ticket counter\n    participant C as phase counters\n    participant W as all threads of the block\n    loop persistent loop, inside ONE launch\n        T->>Q: atomicAdd(ticket), get the next task\n        T->>C: acquire-load the counters of the phases it depends on\n        C-->>T: counter >= target (else __nanosleep and retry)\n        T->>W: run the task (registers, shared memory, L2)\n        W->>C: __threadfence, then atomicAdd(phase counter)\n    end\n```\n\n(The small demo, `a100-demo\u002F`, uses a different scheduler: sharded ticket queues with a CAS claim and Doom > serve > train priority.)\n\nOn Blackwell the GEMMs use `tcgen05` instructions with TMA loads and TMEM accumulators ([`llm\u002Fb200\u002Fgemm_tcgen05\u002F`](llm\u002Fb200\u002Fgemm_tcgen05\u002FREADME.md)),\n34-73% of cuBLAS speed on the model's 15 GEMM shapes against 13-33% for the earlier `mma.sync` code.\n\n**How Doom runs on a GPU.** doomgeneric is compiled with clang's NVPTX backend against a small hand-written tinylibc. clang 14 cannot select\n`va_start` for NVPTX, so `fix_varargs.py` lowers varargs at the LLVM IR level; `build_doom.sh` patches static initialisers PTX cannot express, and\nsound is disabled. Thread 0 runs the game logic and queues column and span draws; the other 255 threads of the block execute the queue behind a\nnamed barrier, which takes a frame from 24 ms to 6.7 ms with a pixel-identical picture.\n\n```mermaid\nflowchart LR\n    A[doomgeneric C source] -->|clang -target nvptx64| B[LLVM bitcode]\n    T[tinylibc.c] --> B\n    B -->|llvm-link| C[one module]\n    C -->|fix_varargs.py| D[patched IR]\n    D -->|llc| E[PTX]\n    E -->|nvcc, or merged into the kernel PTX| F[device code]\n    G[megakernel .cu] --> H((binary))\n    F --> H\n```\n\n## How it compares to Flapping Airplanes\n\nTheir column is read frame by frame from their demo video ([`benchmarks\u002Ffa_published.json`](benchmarks\u002Ffa_published.json)); we did not measure it.\nOurs is the B200 run above (same chip, same 116 \u002F 24 \u002F 8 split, Megatron + Transformer Engine and vLLM as baselines, a 162M-parameter GPT; their\nmodel size, data and settings are unpublished). \"Slower\" is FA's metric, 1 - baseline rate \u002F megakernel rate.\n\n| | Flapping Airplanes (B200, video) | Ours, `tcgen05` 3 stages (`ofa_tc3`) | Ours, `tcgen05` 2 stages (`ofa_tc2`) |\n|---|---|---|---|\n| 4,000 steps, megakernel | 46.1 s | 48.1 s | 52.4 s |\n| Serving \"What is a megakernel?\" | 1,076 tok\u002Fs | 1,660 tok\u002Fs | 1,741 tok\u002Fs |\n| vs Megatron + TE, eager | 70.1 s: baseline **34% slower** | 62.4 s: baseline **23% slower** | 62.4 s: baseline **16% slower** |\n| vs Megatron + TE, CUDA graphs | not reported | 43.1 s: baseline **11.5% faster** | 43.1 s: baseline **21.5% faster** |\n| vs vLLM serving | 710 tok\u002Fs: baseline **34% slower** | 1,537 tok\u002Fs: baseline **7% slower** | 1,537 tok\u002Fs: baseline **12% slower** |\n| Kernel launches | 1 vs 514,562 | 1 vs 2.2M-4.2M host launch calls (15.2M kernels) | same |\n| Doom | plays throughout | 35 fps throughout | 35 fps throughout |\n\n- **Launches.** For the same work (4,000 steps plus about 91,000 served tokens) the baselines make 2.2M to 15.2M launches depending on how they are\n  counted (host launch calls with CUDA graphs versus every kernel on the GPU). Nsight Systems counts **3** launches for a whole `ofa_tc2` process: two one-off setup kernels\n  and the megakernel, which runs all training, serving and Doom ([`b200-run\u002Fresults\u002Flaunches_ofa_tc2\u002F`](b200-run\u002Fresults\u002Flaunches_ofa_tc2\u002Fnsys_launches.json)).\n- **Training.** We beat Megatron + TE as frameworks run by default (eager), by 16-23% against their 34%. Megatron + TE with CUDA graphs is faster than\n  we are: 43.1 s against 48.1 s and 52.4 s. We do not know whether their baseline used graphs.\n- **Serving.** vLLM at batch 1 is bound by its CPU. With 16 reserved cores it made 1,537 tok\u002Fs; in a container without them 684 tok\u002Fs, close to FA's 710.\n  We compare against the faster figure, which favours the baseline.\n- **Doing all three at once saves time, mostly because the GPU is shared.** Same work, one B200: sequential Megatron (graphs) then vLLM about 102 s;\n  the two side by side on their SM shares about 59 s (estimated from separate runs); one megakernel 52.4 s (measured).\n\nMore rows (PyTorch, no-TE Megatron, the A100 and B300 runs, the toy demo) are in [`docs\u002FFA_COMPARISON.md`](docs\u002FFA_COMPARISON.md).\n\n## Quick start\n\nYou need either an NVIDIA A100 box reachable over SSH, or a [Modal](https:\u002F\u002Fmodal.com) account for a B200. The shareware `doom1.wad` is not in this\nrepo; the setup scripts download it and keep it only if its md5 matches.\n\n**A100 (SSH box):**\n\n```bash\n.\u002Fdoom-gpu\u002Fsetup_box.sh ubuntu@\u003Cip>              # once: clang, doomgeneric, shareware WAD (md5 checked)\n.\u002Fa100-demo\u002Frun_demo.sh ubuntu@\u003Cip>              # the small demo, tunnelled to http:\u002F\u002Flocalhost:8080\nMODEL=S .\u002Fllm\u002Fofa_fast\u002Frun_ofa.sh ubuntu@\u003Cip> 8080   # the 162M GPT: train + serve + Doom, one launch\n.\u002Fbenchmarks\u002Frun_benchmarks.sh ubuntu@\u003Cip> 5 6   # small-demo benchmark, writes benchmarks\u002Fresults\u002F\npython3 -m http.server 8000 --directory site     # the stats site, http:\u002F\u002Flocalhost:8000\n```\n\n**B200 (Modal, no SSH):**\n\n```bash\nuv tool install modal && modal setup             # once\nmodal run b200-run\u002Fmodal_app.py --step \u003Cprep|env|mk|tccmp|train|serve|gemm|report>    # LLM-scale comparison, see b200-run\u002FREADME.md\nmodal run benchmarks\u002Frun_modal.py --mode bench   # the small demo on one B200 (about 7 GPU-minutes)\n```\n\nModal runs cost money (a B200 is billed per second); read `b200-run\u002FREADME.md` before running the full comparison.\n\n## Repo map\n\n| Path | What |\n|---|---|\n| `b200-run\u002F` | The LLM-scale comparison on a real B200 against Megatron + TE and vLLM: `modal_app.py`, `results\u002F` |\n| `llm\u002F` | LLM megakernel work: `ofa_fast\u002F` (best A100 build), `ofa\u002F` (rdc Doom build), `megakernel\u002F` (Doom-free), `gemm\u002F`, `gemm2\u002F`, `attention\u002F`, `decode\u002F`, `baseline\u002F` (Megatron, PyTorch, vLLM on A100), `b200\u002F` (Blackwell kit: `tcgen05` GEMMs, megakernel, Modal drivers) |\n| `b300-run\u002F` | **B300** runs on Modal (`gpu=\"B300\"`): reports, logs, raw results |\n| `a100-demo\u002F` | The small-model demo: `demo.cu` megakernel with an HTTP server, three-panel dashboard |\n| `doom-gpu\u002F` | Compiling Doom for the GPU: tinylibc, `fix_varargs.py`, `build_doom.sh`, `setup_box.sh`; `player\u002F` is the scripted player |\n| `benchmarks\u002F` | Small-demo benchmarks: `run_benchmarks.sh` (SSH), `run_modal.py` (Modal), `compare.py`, `fa_published.json`, `results\u002F` |\n| `site\u002F` | Static stats website (`index.html`, `data\u002F`, `assets\u002F`) |\n| `video\u002F` | Sources of the explainer video and of the B200 demo video |\n| `tools\u002F` | `gen_svgs.py` regenerates the animated SVGs |\n| `docs\u002F` | `FA_COMPARISON.md` (every run next to FA's numbers), `RESEARCH.md` (research log), `REORG_PLAN.md` (a folder regrouping that is not done) |\n\n## Limitations\n\n- **Not their code or model.** Same chip, SM split and baselines as the Flapping Airplanes video, but their model, data and training settings are unpublished. We do not reproduce their 46.1 s (our fastest is 48.1 s) or their trained answers (ours is trained on TinyStories).\n- **Megatron + TE with CUDA graphs still trains faster than us on the B200** (43.1 s against 48.1 s).\n\n## Videos\n\n### Live demo (94 s, plays at the top of this README)\n\nOur run on one B200, in Flapping Airplanes' format: the recorded live dashboard (training loss, streaming text, Doom), the code, the split, the side\nby side with the baselines, the result cards, and Flapping Airplanes' demo next to ours at the same moment of each run, with music. Every number\ncomes from `b200-run\u002Fresults\u002F` and `benchmarks\u002Ffa_published.json` through `video\u002Fb200\u002Fmake_data.py`; their footage is from their demo video.\n\n### Explainer (98 s, plays at the top of this README)\n\nThe problem (launch counts), the idea (one persistent kernel, the 116 \u002F 24 \u002F 8 SM split), the Doom port, the method, a still of the B200 dashboard,\nand the results against Flapping Airplanes' published numbers, all on one B200. It is rendered from [`video\u002Fdata.json`](video\u002Fdata.json), whose\nvalues come from `b200-run\u002Fresults\u002F` and `benchmarks\u002Ffa_published.json`, not typed into the scenes.\n\nSources are in [`video\u002F`](video\u002FREADME.md). Full-quality copies are in `video\u002Frelease\u002F`; GitHub's file view does not play files this large, so\ndownload them to watch.\n\n## Credits and licensing\n\n- Independent rebuild, **not affiliated with, endorsed by, or based on code from Flapping Airplanes**. Their numbers come from their public video.\n- **doomgeneric** by ozkl is GPL-licensed; `setup_box.sh` clones it and it is not stored in this repo. **Doom** is by id Software.\n- The **shareware `doom1.wad` is not included**; the setup script downloads it and checks its md5.\n- The code in this repo is released under the [MIT License](LICENSE) (c) 2026 Jerry Zhu. It does not cover doomgeneric, Doom or the WAD, which keep their own licenses.\n- Background: [`docs\u002FRESEARCH.md`](docs\u002FRESEARCH.md), [`benchmarks\u002FREADME.md`](benchmarks\u002FREADME.md), [`site\u002FREADME.md`](site\u002FREADME.md).\n","这是一个开源的 CUDA 持久化 GPU megakernel 实现，单次内核启动即可并行执行大语言模型训练、实时推理服务与 Doom 游戏渲染三项任务。其核心采用 GPU 内队列调度机制，将训练（GPT 前向\u002F反向\u002FAdamW）、流式文本生成（基于动态更新权重）和原生 Doom 引擎（doomgeneric）统一运行于同一持久化内核中，无需 CPU 干预或内核重启动。技术特点包括 SM 级资源静态划分、GPU 内任务队列、定制 GEMM 内核（tcgen05）及低开销跨任务同步。适用于 AI 系统研究、GPU 架构探索、异构计算调度验证等场景。",2,"2026-11-24 04:33:04","CREATED_QUERY"]