ai.onnx.GatherND
ai.onnx · standard ONNX operator · ONNX opset ≥ 13
Description
Gathers slices from data using an N-dimensional index tensor, producing an output of rank q + r - indices_shape[-1] - 1 - b where r is the data rank, q the indices rank, and b the number of batch dimensions. Each index-tuple in indices selects either a scalar or a sub-tensor slice from data; this is the inverse of ScatterND.
See the ONNX GatherND spec for the reference semantics.
Inputs
| Name | Bind key | Logical dtype | WebGPU storage | Rank | Shape | Description | Presence |
|---|---|---|---|---|---|---|---|
data |
data |
T |
runtime-selected; narrow integers and bool use 32-bit slots | — | — | Tensor of rank r >= 1 to gather slices from. |
required |
indices |
indices |
I |
int32 |
— | — | Logical int64 index tensor of rank q >= 1. Its last dimension specifies the indexing depth into data; for an indexed axis of size s, values must be in [-s, s - 1]. Signed indices use int32 WebGPU storage. |
required |
Outputs
| Name | Bind key | Logical dtype | Rank | Shape | Description | Presence |
|---|---|---|---|---|---|---|
output |
output |
T |
derived | derived; see description | Gathered output tensor of rank q + r - indices_shape[-1] - 1 - batch_dims. |
required |
Attributes
Default values (overridable per request):
| Attribute | Default | Description |
|---|---|---|
batch_dims |
0 |
Number of leading batch dimensions shared by data and indices; gathering begins at dimension batch_dims of data. |
Type constraints
| Variable | Allowed dtypes |
|---|---|
T |
float32, float16, uint32, int32, int16, uint8, int8, bool |
I |
int64 |
Files
metadata.json— kernel metadata (id, digests, provenance)manifest.json— the op contract (source of truth)test.json— correctness casesbench.json— benchmark + tuning casesdatamove-gather-row.wgsl.jinjagather-nd.wgsl.jinja
Use with @huggingface/kernels
The loader derives every required output's shape and logical dtype from the manifest contract and this call. It then allocates the result tensors automatically.
The version: 1 option selects the published kernel contract; it is independent of any operator opset, contrib since_version, or model version.
Replace each *Data placeholder with a typed array containing the corresponding input data.
import { getKernel } from "@huggingface/kernels";
const kernel = await getKernel("webgpu-kernels/ai.onnx.GatherND", { version: 1 });
const { output } = await kernel({
data: { data: dataData, shape: [2, 2] },
indices: { data: indicesData, shape: [2, 1, 2] },
});
- Downloads last month
- -
Requires WebGPU support. See the compatibility table.