Skip to main content

@luma.gl/graph/gpu-timeseries

@luma.gl/graph/gpu-timeseries provides WebGPU chart reduction over uniformly sampled, GPU-resident scalar values. It preserves source chunks and produces exact spike envelopes with stable sample identities. See Signal Room for linked telemetry charts with more than three million real resident samples.

GPUTimeSeries​

import {GPUTimeSeries} from '@luma.gl/graph/gpu-timeseries';

const series = new GPUTimeSeries({values, validity, origin: 0, interval: 0.1});

values is a borrowed, packed GPUVector<'float32'>. Optional packed GPUVector<'uint32'> validity must retain the same ordered chunk lengths, including empty chunks. Nonzero accepts a sample; NaN and infinities are always missing. Stable sample IDs are zero-based source row indices across chunks. origin and positive interval are CPU time metadata: sample index occurs at origin + index * interval. They do not pass large epoch timestamps through Float32 shaders. Defaults are zero and one. Irregular timestamps, resampling and streaming append are not supported.

Construction allocates nothing, preserves source references and does not transfer ownership.

Compose an envelope with downstream analysis​

Use gpuTimeSeriesEnvelope in GPUGraph when another GPU operation needs the per-bin results. For example, compute the span of each bin for a chart and keep the original sample IDs for picking. The graph can keep the full envelope private while returning spans, IDs, and counts.

import {GPUGraph, gpuExpression} from '@luma.gl/graph/gpu-graph';
import {gpuTimeSeriesEnvelope} from '@luma.gl/graph/gpu-timeseries';

const graph = new GPUGraph();
graph.addInput('samples', {type: 'vector', format: 'float32'});
graph.addInput('window', {type: 'vector', format: 'uint32x2'});
graph.add(gpuTimeSeriesEnvelope, {
values: 'samples',
range: 'window',
bins: 512,
output: 'envelope',
sourceIds: 'sampleIds',
counts: 'coverage'
}).add(gpuExpression, {output: 'span', expression: 'envelope.y - envelope.x'});

const compiledGraph = graph.compile(device, {outputs: ['span', 'sampleIds', 'coverage']});

Bind a new window at execution to change the visible sample range without recompiling. Use coverage.x, the valid count, to distinguish empty bins from bins with a genuine zero span.

Pass a source-aligned uint32 vector as selection to summarize a filtered subset. It can be the output of gpuTraceTimeWindow, shared with a grouped statistic. The mask must preserve the sample order and chunk boundaries. Bin boundaries and sample IDs still refer to the original row indices. An excluded row contributes to neither count. A selected row contributes to the missing count if its validity flag is zero or its value is nonfinite. Share a time-window selection.

Compose in a command graph​

In a GPUCommandGraph, pass concrete views. Use the returned destinations in a downstream GPU pass before compiling.

import {gpuTimeSeriesEnvelope, type GPUTimeSeriesEnvelopeResult} from '@luma.gl/graph/gpu-timeseries';

workflow.add(gpuTimeSeriesEnvelope, {
id: 'visible-history',
values: workflow.importGPUVector('samples', series.values),
range, // one uint32x2 view with [start, end) source sample indices
bins: 512
});
const {output, sourceIds, counts} =
workflow.getContribution<GPUTimeSeriesEnvelopeResult>('visible-history');

The three views contain packed rows. output is float32x4 with minimum, maximum, first, and last. sourceIds contains the corresponding uint32x4 source indices, and counts contains uint32x2 valid and missing counts. Pass your own views if the results need to outlive the graph or feed a separate renderer. Each supplied output must match the fixed bin count (1–16,384) and use storage separate from the inputs. Optional validity and selection views follow the same chunks as values.

The range is read on every encoding, clamped to the series length and interpreted as half-open. A reversed or out-of-range interval becomes empty. For B bins, bin b covers [start + floor(span * b / B), start + floor(span * (b + 1) / B)). Integer arithmetic partitions every selected sample exactly once, even when bins outnumber samples. Minimum/maximum ties choose the earliest source ID. First/last refer to valid samples in source order, not extrema order. Empty bins contain zero values, sentinel IDs 0xffffffff, and zero valid count. Missing counts distinguish absent observations from bins with no assigned source rows.

Re-encoding clears every output before reducing current source chunks. There is no capacity overflow: fixed bins summarize the entire selected range, with bounded counts for at most 0xfffffffe source samples. Output reduction is exact, not stochastic sampling; it does not imply continuity between observations. A renderer should display missing bins as gaps and mark mixed bins when missingness matters. Connecting min/max values as an ordered polyline would be misleading.

One 64-thread workgroup reduces each bin per source chunk, then merges in source order. Work is O(visible samples + chunks × bins) and output storage is 40 bytes per bin. Workgroup scratch is bounded; there is no source-sized scratch, automatic packing or hidden readback. Each chunk must fit a device storage binding. This implementation rescans visible samples after a range change; it does not build a multiresolution time index or guarantee a frame rate. The caller can reuse outputs while the range is unchanged and bind them directly to rendering.

The module does not import Arrow or depend on GPU tables. Use Arrow adapters outside it, and keep renderer-specific pixel sizing, axes, picking policy and interpolation above the compute API.