Skip to main content

@luma.gl/graph/gpu-graph-algorithms

Overview​

@luma.gl/graph/gpu-graph-algorithms provides graph-data structures and algorithms that compose inside a caller-owned GPUCommandGraph. It keeps adjacency, traversal frontiers, scores, partitions, and layouts GPU-resident so analysis can feed another analysis or a renderer without downloading the graph through JavaScript.

When to use it​

Use GPU Graph Algorithms for repeated analytics over a graph already stored on the GPU, especially when results will drive filtering, styling, layout, or later graph operations. For a single small graph or an algorithm whose result is immediately needed on the CPU, a CPU graph library may be simpler.

Quick start​

import {GPUCommandGraph} from '@luma.gl/graph/gpu-graph';
import {
GPUGraphAlgorithmsData,
gpuGraphTopology,
gpuLabelPropagation,
gpuPageRank,
type GPUGraphAlgorithmsTopology,
type GPULabelPropagationResult,
type GPUPageRankResult
} from '@luma.gl/graph/gpu-graph-algorithms';

const edgeData = new GPUGraphAlgorithmsData({vertexCount, sourceVertices, targetVertices});
using graph = new GPUCommandGraph(device, {id: 'graph-analysis'});
graph.add(gpuGraphTopology, {id: 'csr', graph: edgeData, reverse: edgeData.directed});
const topology = graph.getContribution<GPUGraphAlgorithmsTopology>('csr');
graph.add(gpuPageRank, {id: 'importance', topology});
const {output: scores} = graph.getContribution<GPUPageRankResult>('importance');
graph.add(gpuLabelPropagation, {id: 'communities', topology, converged: true});
const {output: labels} = graph.getContribution<GPULabelPropagationResult>('communities');

// Add consumers of scores and labels before compiling.
using compiledGraph = graph.compile();
compiledGraph.encode(commandEncoder, {parameters: undefined});
device.submit(commandEncoder.finish());

The graph owns the CSR buffers, scores, and community labels. The application supplies the edge columns and decides when to encode, submit, or read back a result. The same topology also drives gpuVertexDegree, gpuConnectedComponents, and breadth-first search.

Graph Explorer uses a single graph for small datasets. At larger scales it schedules components, communities, and PageRank separately after building CSR once. Keep the compiled topology owner alive for as long as any stage or renderer borrows its buffers. If a traversal graph is rebuilt on resize, pass the existing distances, predecessors, and mask destinations to keep their buffer identities.

Core concepts and data model​

  • GPUGraphAlgorithmsData describes canonical vertex and edge identity.
  • GPUGraphAlgorithmsTopology builds reusable adjacency views for algorithms that need neighbors.
  • Algorithms publish ordinary graph buffers and bounded status so their outputs compose.
  • Iterative operations expose capacity, convergence, and incomplete-result behavior explicitly.
  • Weighted, directed, and undirected semantics are operation-specific and documented in the operations reference.

Explore a live graph​

Loading interactive example…

Operations and API index​

FamilyOperations
Graph and topologyGPUGraphAlgorithmsData, GPUGraphAlgorithmsTopology, GPUGraphAlgorithmsDegree
Traversal and pathsGPUGraphAlgorithmsBreadthFirstSearch, GPUGraphAlgorithmsSingleSourceShortestPath
Connectivity and communitiesGPUGraphAlgorithmsConnectedComponents, gpuCoreNumber, GPUGraphAlgorithmsLabelPropagation, gpuOptimizeModularity
Metrics and rankinggpuLocalClusteringCoefficient, gpuModularity, GPUGraphAlgorithmsPageRank
LayoutGPUGraphAlgorithmsForceLayout, GPUGraphAlgorithmsSpatialForceLayout

The operations reference documents usage, buffers, execution, capacity, validation, and performance for each family.

Limits and compatibility​

  • GPU Graph is experimental and WebGPU-only.
  • Algorithms use fixed compiled capacities and report convergence or incomplete work explicitly.
  • The caller owns source buffers, submission, readback, and cancellation.
  • Algorithm support for weights, directionality, self-edges, and parallel edges is documented per operation.
  • GPU Core provides scheduling and generic GPU operations.
  • GPU Dataframe analyzes columnar records rather than graph topology.
  • GPU Trace adds trace-specific dependency and hierarchy semantics.

Reuse a topology for structural metrics and partition scoring​

Build the topology once. Core numbers and local clustering both project the edges onto distinct weak neighbors. The optimizer also needs reverse adjacency on directed graphs. To score its labels independently, pass them to gpuModularity with the original edge data.

import {GPUCommandGraph} from '@luma.gl/graph/gpu-graph';
import {
gpuGraphTopology, gpuCoreNumber, gpuLocalClusteringCoefficient,
gpuOptimizeModularity, gpuModularity
} from '@luma.gl/graph/gpu-graph-algorithms';

// graph is a GPUGraphAlgorithmsData containing source and target vertex columns.
using commands = new GPUCommandGraph(device);
commands.add(gpuGraphTopology, {id: 'csr', graph, reverse: graph.directed});
const topology = commands.getContribution('csr', gpuGraphTopology);
commands.add(gpuCoreNumber, {id: 'cores', topology, degeneracy: true});
commands.add(gpuLocalClusteringCoefficient, {id: 'clustering', topology, triangles: true});
commands.add(gpuOptimizeModularity, {id: 'partition', topology, converged: true});
const partition = commands.getContribution('partition', gpuOptimizeModularity);
commands.add(gpuModularity, {
id: 'quality', graph, communities: partition.output, communityContributions: true, valid: true
});
const quality = commands.getContribution('quality', gpuModularity);

using execution = commands.compile();
const encoder = device.createCommandEncoder();
execution.encode(encoder, {parameters: undefined});
device.submit(encoder.finish());
encoder.destroy();
// quality.output is a one-row float32 vector available to downstream GPU work.
OperationInputsRequired resultsOptional results
gpuCoreNumberShared topologyCore number per vertexScalar convergence and degeneracy
gpuLocalClusteringCoefficientShared topologyCoefficient per vertexIncident triangles per vertex
gpuOptimizeModularityShared topology, optional initial labelsLabel per vertex and scalar modularityScalar convergence and validity
gpuModularityOriginal edge data and labelsScalar modularityContribution per community label and scalar validity

Existing callers can continue to construct GPUGraphAlgorithmsCoreNumber, GPUGraphAlgorithmsLocalClusteringCoefficient, GPUGraphAlgorithmsModularityOptimization, and GPUGraphAlgorithmsModularity with caller-owned destinations. The declarative operations reuse these implementations and their validation.

For these command contributions, omitted required destinations are allocated by the graph. Set an optional destination to true to allocate it, or supply a packed vector to borrow its storage. Omitting an optional destination leaves it absent from the result. Graph-owned vectors live until the compiled execution is destroyed (or the uncompiled builder is destroyed). Caller-supplied inputs and result vectors remain caller-owned.

Score named CSR values in a GPUGraph​

Use the same gpuModularity operation with packed logical vector ports when the application already has CSR rows. Each accepted adjacency slot represents one original edge. For undirected data stored in symmetric CSR, use an adjacency mask selecting one representative slot per original edge, including one slot per self-loop. Parallel source edges each contribute independently.

graph.add(gpuModularity, {
offsets: 'rowStarts', neighbors: 'columnIndices', communities: 'labels',
weights: 'edgeWeights', adjacencyMask: 'acceptedSlots', directed: false,
output: 'quality', valid: 'validQuality'
});

Each port resolves to a single packed vector chunk. The score is a one-row float32 vector and validity is a one-row uint32 vector. Include either logical name in the compile outputs to retain it. Core numbers, clustering and optimization use the command form because they also consume topology overflow counters and the reverse adjacency of directed graphs.