ai.onnx.CumSum
ai.onnx · standard ONNX operator · ONNX opset ≥ 14
Description
Computes the cumulative sum of elements along a specified axis. By default, the sum is inclusive (each output element includes itself); setting exclusive to 1 excludes the current element, and setting reverse to 1 scans in the opposite direction.
See the ONNX CumSum spec for the reference semantics.
Differences from the ONNX spec
- Input
axis: Passed as theaxisruntime argument instead of a tensor input.
Inputs
| Name | Logical dtype | Rank | Shape | Description | Presence |
|---|---|---|---|---|---|
x |
T |
— | — | Input tensor to accumulate. | required |
Outputs
| Name | Logical dtype | Rank | Shape | Description | Presence |
|---|---|---|---|---|---|
y |
T |
same as x |
same as x |
Output tensor of the same shape and type as x, containing cumulative sums along the specified axis. |
required |
Runtime arguments
| Name | Kind | Description | Presence |
|---|---|---|---|
axis |
i32 |
Axis along which to accumulate: ONNX's one-element axis input, passed as a scalar. Negative values count from the back. |
required |
Attributes
Default values (overridable per request):
| Attribute | Default | Description |
|---|---|---|
exclusive |
0 |
If 1, the j-th output element is the sum of the first (j-1) input elements, excluding the j-th element itself; defaults to 0 (inclusive). |
reverse |
0 |
If 1, performs the cumulative sum scanning in the reverse direction along the axis; defaults to 0. |
Type constraints
| Variable | Allowed dtypes |
|---|---|
T |
float32, float16, int32, uint32 |
Implementation variants
One implementation is selected per call from the device capabilities, the request shapes and the dtypes; these notes say what each one covers.
single_segment_row_scan_vec4,single_segment_row_scan— A single computed segment needs no cross-segment carry. Reuses the cooperative scan with an identity seed, with no preparatory passes or temporary buffers.
Files
metadata.json— kernel metadata (id, file digests, manifest spec, provenance)manifest.json— the op contract (source of truth)test.json— correctness casesbench.json— benchmark casescumsum-splitk-carry.wgsl.jinjacumsum-splitk-scan.wgsl.jinjacumsum-splitk-totals.wgsl.jinjascan-row-chunked-vec4.wgsl.jinjascan-row-chunked.wgsl.jinjascan-strided-row.wgsl.jinjascan-thread-row.wgsl.jinja
Use with @huggingface/kernels
npm install --save-exact @huggingface/kernels@0.0.1-preview.4
Paste the example into a browser app that resolves npm imports. Serve the app over HTTPS or localhost with WebGPU available.
Required output shapes and logical data types are inferred from the supplied inputs and attributes; result tensors are allocated automatically.
The version: 1 option selects the published kernel contract; it is independent of any operator opset, contrib since_version, or model version.
It follows the v1 branch as fixes land. To pin exact artifact bytes, pass a 40-character commit revision instead of version.
import { getKernel } from "@huggingface/kernels";
const kernel = await getKernel("webgpu-kernels/ai.onnx.CumSum", { version: 1 });
const xData = Int32Array.of(1, 2, 3, 4, 5);
const { y } = await kernel({ x: { data: xData, shape: [5] }, axis: 0 });
console.log({ y });
- Downloads last month
- -
Requires WebGPU support. See the compatibility table.