The GPU Layout Engine runs natively on the host (not in Docker) because Docker cannot access Metal GPU on macOS. It computes ForceAtlas2 graph layouts using Metal (macOS) or Vulkan (Linux/Windows).
Why GPU Layout?
Force-directed layout algorithms are computationally expensive:
- Each iteration computes forces between all node pairs: O(n²)
- Large graphs need thousands of iterations
- CPU computation becomes impractical for 1000+ nodes
GPUs excel at parallel computation, making them ideal for force calculations.
| Nodes | CPU Time | GPU Time | Speedup |
|---|
| 100 | 0.5s | 0.3s | 1.7x |
| 1,000 | 8s | 1.2s | 6.7x |
| 5,000 | 120s | 4s | 30x |
| 10,000 | 600s+ | 12s | 50x+ |
Architecture
.NET API Server
RustGpuLayoutAdapter implements ILayoutCompute port
WebSocket
Internal connection on ws://localhost:9002
Layout Server (Rust)
wgpu for GPU abstraction, ForceAtlas2 with Barnes-Hut
GPU Compute
Metal (macOS) or Vulkan (Linux/Windows)
The browser never connects directly to the GPU server. All communication goes through the .NET API.
Key Concepts
| Concept | Description |
|---|
| ForceAtlas2 | The force-directed layout algorithm |
| Protocol | WebSocket message format |
Building
cd lib/gpulayout
cargo build --features server --bin layout-server --release
Running
./lib/gpulayout/target/release/layout-server
# Listening on ws://0.0.0.0:9002
Fallback
When GPU is unavailable, CodeGraph falls back to CPU layout automatically.