Why GPU Layout?
Force-directed layout algorithms like ForceAtlas2 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
Performance
| 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
ForceAtlas2 Algorithm
ForceAtlas2 is a force-directed algorithm designed for network visualization:Forces
- Repulsion: All nodes repel each other (prevents overlap)
- Attraction: Connected nodes attract each other (clusters related nodes)
- Gravity: Pulls nodes toward center (prevents drift)
Parameters
| Parameter | Effect |
|---|---|
gravity | Center pull strength. Higher = tighter clusters |
scalingRatio | Overall layout scale |
edgeWeightInfluence | How much edge weights affect attraction |
strongGravityMode | Prevents nodes from drifting to infinity |
barnesHutTheta | Approximation accuracy (performance vs quality) |
Barnes-Hut Optimization
Instead of computing n² force interactions, Barnes-Hut groups distant nodes:Compute Shaders
The core algorithm runs in WGSL compute shaders:Protocol
GraphPU uses a simple WebSocket JSON protocol:Start Layout
Progress Update
Result
Building GraphPU
Features
| Feature | Description |
|---|---|
server | WebSocket server (default) |
metal | Force Metal backend (macOS) |
vulkan | Force Vulkan backend |
Configuration
Environment variables:| Variable | Default | Description |
|---|---|---|
GRAPHPU_HOST | 0.0.0.0 | Bind address |
GRAPHPU_PORT | 9002 | WebSocket port |
GRAPHPU_LOG | info | Log level |