--- library_name: kernels license: apache-2.0 tags: - kernel - webgpu - wgsl --- # ai.onnx.Col2Im `ai.onnx` · standard ONNX operator · ONNX opset ≥ 18 ## Description Rearranges column blocks back into a batched multidimensional image. Takes a 3-D input of shape `[N, C * product(block_shape), L]` (where `L` is the number of blocks) and accumulates overlapping block contributions into the output image using the specified `block_shape`, `strides`, `pads`, and `dilations`. See the [ONNX `Col2Im` spec](https://onnx.ai/onnx/operators/onnx__Col2Im.html) for the reference semantics. ## Inputs | Name | Bind key | Logical dtype | WebGPU storage | Rank | Shape | Description | Presence | | --- | --- | --- | --- | --- | --- | --- | --- | | `input` | `input` | `T` | same as logical dtype | `3` | — | Column-block data tensor of shape `[N, C * product(block_shape), L]` to be folded back into an image. | required | | `image_shape` | `image_shape` | `I` | `uint32` | `1` | — | Logical int64 metadata tensor specifying the output spatial dimensions (for example, `[H, W]` for 2-D); non-negative values use uint32 WebGPU storage. | required | | `block_shape` | `block_shape` | `I` | `uint32` | `1` | — | Logical int64 metadata tensor specifying the positive block size on each spatial axis (for example, `[H_block, W_block]` for 2-D); values use uint32 WebGPU storage. | required | ## Outputs | Name | Bind key | Logical dtype | Rank | Shape | Description | Presence | | --- | --- | --- | --- | --- | --- | --- | | `output` | `output` | `T` | derived | — | Output image tensor produced by accumulating rearranged column blocks. Its rank is two greater than the length of `image_shape`. | required | ## Attributes Attributes and default values (overridable per request): | Attribute | Default | Description | | --- | --- | --- | | `dilations` | — | Dilation factors for each spatial axis; defaults to one on every axis. | | `pads` | — | Padding at the beginning of every spatial axis followed by padding at the end of every spatial axis; defaults to zeros. | | `strides` | — | Stride factors for each spatial axis; defaults to one on every axis. | ## Type constraints | Variable | Allowed dtypes | | --- | --- | | `T` | `float32` | | `I` | `int64` | ## Files - [`metadata.json`](build/webgpu/metadata.json) — kernel metadata (id, digests, provenance) - [`manifest.json`](build/webgpu/manifest.json) — the op contract (source of truth) - [`test.json`](build/webgpu/test.json) — correctness cases - [`bench.json`](build/webgpu/bench.json) — benchmark + tuning cases - [`col2im-nd.wgsl.jinja`](build/webgpu/col2im-nd.wgsl.jinja) ## Use with `@huggingface/kernels` The loader automatically allocates outputs whose metadata it can derive from the manifest contract and this call. The explicit `outputs` entries provide shape and logical dtype metadata for the results listed below: - `output` Each entry either requests an optional result or supplies metadata that cannot be inferred from the inputs. 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. ```js import { getKernel } from "@huggingface/kernels"; const kernel = await getKernel("webgpu-kernels/ai.onnx.Col2Im", { version: 1 }); // Explicit destinations request optional results or supply metadata that cannot be inferred. const { output } = await kernel({ input: { data: inputData, shape: [1, 9, 1] }, image_shape: { data: image_shapeData, shape: [2] }, block_shape: { data: block_shapeData, shape: [2] }, }, { outputs: { output: { shape: [1, 1, 3, 3], dtype: "float32" } }, }); ```