Skip to main content
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.

Performance

NodesCPU TimeGPU TimeSpeedup
1000.5s0.3s1.7x
1,0008s1.2s6.7x
5,000120s4s30x
10,000600s+12s50x+

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

ConceptDescription
ForceAtlas2The force-directed layout algorithm
ProtocolWebSocket 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.