Skip to main content

GPU Graph topology

Describe existing relationships with GPUGraphAlgorithmsData​

Question: Which existing GPU columns describe the people, accounts, services, or documents in this network?

GPUGraphAlgorithmsData is the ownership-preserving entry point. Construct it when an application already has aligned GPUVector<'uint32'> source and target identifiers and knows how many vertices exist, including isolated vertices that never appear in an edge.

import {GPUGraphAlgorithmsData} from '@luma.gl/graph/gpu-graph-algorithms';

const graph = new GPUGraphAlgorithmsData({
vertexCount,
sourceVertices,
targetVertices,
edgeWeights,
edgeIds,
nodeAttributes,
directed: true
});

The graph borrows its vectors; it does not allocate a graph buffer, copy or concatenate chunks, submit commands, or take ownership of source allocations. Source and target chunks must have the same ordered lengths. Optional stable edge identifiers and float32 edge weights follow the same source partitions, while optional vertex and edge property tables retain their existing metadata.

Use this lightweight representation when existing GPU tables or render inputs already describe a network. It is a description, not an upload helper: first create or adapt your GPU vectors through the application or the appropriate data adapter.

Build reusable adjacency with GPUGraphAlgorithmsTopology​

Question: Given a particular vertex, which other vertices does it connect to?

An edge list answers “what are all relationships?” but repeatedly scanning every edge to discover one vertex's neighbors is expensive. GPUGraphAlgorithmsTopology builds compressed sparse row (CSR) adjacency once so later operations can find each vertex's neighbor interval from adjacent offsets.

For example, a transaction list might contain millions of transfers while an investigator wants only the accounts directly connected to account 42. Its CSR offset interval identifies that account's neighbors without asking each later analysis to rescan the entire edge list.

import {GPUGraphAlgorithmsTopology} from '@luma.gl/graph/gpu-graph-algorithms';

const topology = new GPUGraphAlgorithmsTopology({
graph,
forward: {
offsets: outgoingOffsets,
neighbors: outgoingNeighbors,
edgeIds: outgoingEdgeIds,
edgeWeights: outgoingEdgeWeights,
count: outgoingCount,
overflow: outgoingOverflow
},
reverse: {
offsets: incomingOffsets,
neighbors: incomingNeighbors,
edgeIds: incomingEdgeIds,
edgeWeights: incomingEdgeWeights,
count: incomingCount,
overflow: incomingOverflow
},
invalidEdgeCount
});

Every shown output is an existing, caller-owned, single-chunk GPUVector<'uint32'>. Offsets have vertexCount + 1 rows; neighbors and edge identifiers have equal explicit capacities; count, overflow, and invalidEdgeCount each have one row. When the source graph supplies edge weights, each configured adjacency also requires a matching float32 edge-weight output.

Build reverse adjacency when a directed graph needs incoming-degree queries, incoming or bidirectional breadth-first search, weak-neighborhood community, core-number, or local-clustering analysis, or PageRank. Directed weak components use forward adjacency alone, as do outgoing weighted shortest paths. Modularity reads original edge columns directly and needs no adjacency. Undirected graphs use one symmetric forward adjacency and must not provide reverse adjacency.

Invalid endpoints are excluded and counted. count reports the complete number of accepted adjacency entries even if neighbor capacity is insufficient; overflow makes truncation explicit. Neighbor order within each vertex is intentionally unspecified.

Count relationships with GPUGraphAlgorithmsDegree​

Question: How many direct relationships does each vertex have?

GPUGraphAlgorithmsDegree answers the simplest structural question: how many outgoing or incoming relationships does each vertex have? Use it to identify network hubs, size junction markers, detect isolated accounts, or find unusually connected infrastructure and dependency nodes.

import {GPUGraphAlgorithmsDegree} from '@luma.gl/graph/gpu-graph-algorithms';

const degree = new GPUGraphAlgorithmsDegree({
topology,
output: outgoingDegrees,
direction: 'outgoing'
});

Its caller-owned output has one packed uint32 row per vertex. Outgoing degree is the default; incoming degree on a directed graph requires reverse adjacency. Duplicate edges count individually, and an undirected self-loop counts once.

Degrees come from complete CSR offsets rather than the capacity-bounded neighbor list, so they remain exact even when the corresponding adjacency reports neighbor overflow. Degree is useful when raw connectivity is the question; it does not account for whether a vertex's neighbors are themselves important.

If the caller's command graph already produces CSR, pass the packed offset and output views directly. The graph schedules degree after the offset producer and before any consumers of the output view.

import {addGPUGraphAlgorithmsDegree} from '@luma.gl/graph/gpu-graph-algorithms';

addGPUGraphAlgorithmsDegree(commandGraph, {offsets: forwardOffsets, output: degrees});

Supply one offset per vertex plus a sentinel and one output row per vertex. Choose forward offsets for outgoing degree or reverse offsets for incoming degree. Every stored slot counts once, including parallel edges and self-loops. With no masks, the pass computes each degree by subtracting consecutive offsets. Add an adjacencyMask with one packed uint32 flag per slot to exclude individual edges. To count degree in an induced subgraph, supply vertexMask and neighbors. A slot counts when both its row vertex and its neighbor have nonzero flags. A masked-out vertex receives zero. The masks combine by intersection and may be produced by earlier graph passes.

Use the same CSR orientation for offsets, neighbors, and slot flags. Slot indices are relative to the start of the supplied views. Supply both slots for each mirrored undirected edge if the filter should preserve symmetry. Masked degree scans the supplied slots, so its work is O(V + E).

Weak components over caller-owned CSR​

Use addGPUGraphAlgorithmsConnectedComponents(commandGraph, {offsets, neighbors, output}) when an upstream graph pass already publishes CSR. Forward CSR is sufficient. A directed slot connects both endpoints for weak connectivity. Optional packed vertexMask and adjacencyMask views use the same nonzero inclusion semantics as masked degree. The pass writes 0xffffffff for excluded vertices. Component labels retain their original vertex IDs. An optional one-row converged view reports whether the final iteration reached a fixed point. If the CSR sentinel exceeds the neighbor view capacity, all labels are invalid and convergence is zero.

How modularity would use these views​

A CSR modularity scorer can reuse offsets, neighbors, and both masks. It also needs optional per-slot weights and one community label per enabled vertex. The scorer should compute total, internal, and endpoint weights over the same filtered slots. Directed CSR can use outgoing rows directly. For undirected CSR, define how mirrored slots, parallel edges, and self-loops contribute before reusing the existing edge-list formula. In particular, a loop contributes twice to undirected volume, while the existing topology stores a single loop slot. Excluded vertices must be skipped before checking community label validity. Keep scoring separate from community optimization.