{"id":"runtime--CPU-GPU-pipeline","name":"CPU-GPU-pipeline","owner":"yeho","package":"runtime","kind":"runtime","signature":"CPU-GPU-pipeline","description":"Prepare data on the CPU, process independent elements on the GPU, wait for completion, and consume the results on the CPU.","context":"CPU and GPU data processing with explicit ownership and completion.","parameters":[],"returns":"","members":[],"tags":["compute","cpu","gpu","hybrid","pipeline","yeho"],"updated":"2026-09-09","source":{"repository":"yeho","path":"docs/runtime/execution-boundaries.md; docs/runtime/metal-compute-v1.md"},"status":"experimental","notes":[],"examples":[{"id":"hybrid","title":"CPU + GPU · one pipeline","description":"The CPU prepares rewards, the GPU doubles them, then the CPU totals the finished buffer. There is no [both] tag. Ordinary host code and a [gpu] kernel cooperate explicitly.","code":"[gpu]\ncompute DoubleRewards(buffer of int rewards)\n{\n    int index = compute.index\n    if index >= rewards.count { return }\n    rewards[index] = rewards[index] * 2\n}\n\n// CPU: prepare a small game reward batch.\nbuffer of int rewards\nfor level from 1 <= 4 { rewards.Add(level * 10) }\n\n// GPU: process independent elements.\ncomputeTask job = dispatch DoubleRewards(rewards)\nwait job\nif job.failed { Console.Error(job.error.message) Process.Exit(1) }\n\n// CPU: consume only after the GPU has finished.\nint total = 0\nfor index from 0 < rewards.count { total = total + rewards[index] }\nConsole.Log(Text.From(total))\n","tags":["hybrid","cpu","gpu","compute","pipeline"],"run":"metal","expected":"200","verifyRun":true,"manifest":"manifestVersion = \"2\"\npackage = \"api.example.runtime__cpu_gpu_pipeline\"\nversion = \"0.1.0\"\nlanguageEdition = \"yeho-core-2026.1\"\n\n[app]\nkind = \"headless\"\n","verification":"executed","sha256":"aeb2499e279de223464612574882f659ef54463f96623a82e1822bef960df225","checked":"2026-09-09","diagnostic":"","observedOutput":"200","checkedBackend":"metal"}],"searchTerms":[],"url":"https://demonhunterlabs.com/academy/api?item=runtime--CPU-GPU-pipeline","json":"https://demonhunterlabs.com/reference/items/runtime--CPU-GPU-pipeline.json","markdown":"https://demonhunterlabs.com/reference/text/runtime--CPU-GPU-pipeline.md"}
