# CPU-GPU-pipeline

Prepare data on the CPU, process independent elements on the GPU, wait for completion, and consume the results on the CPU.

Last updated: 2026-09-09

Package: runtime | Status: experimental

Tags: compute, cpu, gpu, hybrid, pipeline, yeho

CPU and GPU data processing with explicit ownership and completion.

```yh
CPU-GPU-pipeline
```


## CPU + GPU · one pipeline

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.

Verification: executed

```yh
[gpu]
compute DoubleRewards(buffer of int rewards)
{
    int index = compute.index
    if index >= rewards.count { return }
    rewards[index] = rewards[index] * 2
}

// CPU: prepare a small game reward batch.
buffer of int rewards
for level from 1 <= 4 { rewards.Add(level * 10) }

// GPU: process independent elements.
computeTask job = dispatch DoubleRewards(rewards)
wait job
if job.failed { Console.Error(job.error.message) Process.Exit(1) }

// CPU: consume only after the GPU has finished.
int total = 0
for index from 0 < rewards.count { total = total + rewards[index] }
Console.Log(Text.From(total))

```

Save this beside start.yh as project.mech:

```toml
manifestVersion = "2"
package = "api.example.runtime__cpu_gpu_pipeline"
version = "0.1.0"
languageEdition = "yeho-core-2026.1"

[app]
kind = "headless"

```

Expected output:

```text
200
```

Executed backend: metal

Observed output:

```text
200
```

Extract the example archive beside the yeho and dolphin checkouts. This example requires those source dependencies and a current developer compiler.

```sh
./yeho/build/dolphin-metal/yehoc ./api-examples/runtime--CPU-GPU-pipeline/hybrid --backend metal -o /tmp/yeho-example
/tmp/yeho-example
```




Source: yeho/docs/runtime/execution-boundaries.md; docs/runtime/metal-compute-v1.md

AI training permission: https://demonhunterlabs.com/ai-use
