ai.onnx.Conv

ai.onnx · standard ONNX operator · ONNX opset ≥ 11

Description

Applies an N-dimensional convolution to the input tensor X using filter weights W and an optional bias B. Supports grouped convolution, explicit per-axis padding, dilation, and stride along each spatial dimension.

See the ONNX Conv spec for the reference semantics.

Inputs

Name Upstream name Logical dtype Rank Shape Description Presence
x X T — — Input data tensor of shape (N x C x D1 x ... x Dn), where N is the batch size and C is the number of channels. required
w W T — — Convolution filter weights of shape (M x C/group x k1 x ... x kn), where M is the number of output feature maps. required
b B T 1 — Optional 1D bias of length M added to each output channel. optional

Outputs

Name Upstream name Logical dtype Rank Shape Description Presence
y Y T same as x derived Output tensor whose spatial dimensions are determined by the kernel size, strides, dilations, and padding. required

Attributes

Attributes and default values (overridable per request):

Attribute Default Description
auto_pad "NOTSET" Automatic padding mode. NOTSET uses pads; SAME_UPPER and SAME_LOWER choose padding so each output spatial size is ceil(input / stride); VALID uses no padding.
dilations — Optional dilation factors, one positive integer per spatial axis. Omission means all ones.
group 1 Number of groups that input and output channels are split into; defaults to 1.
kernel_shape — Optional kernel shape, one positive integer per spatial axis. When present, it must match the spatial dimensions of the weight tensor; omission infers the shape from the weights.
pads — Optional explicit padding in ONNX order [begin_axis_0, ..., begin_axis_n, end_axis_0, ..., end_axis_n]. Omission means all zeros; it cannot be combined with an automatic padding mode.
strides — Optional stride factors, one positive integer per spatial axis. Omission means all ones.

Type constraints

Variable Allowed dtypes
T float32, float16

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.

  • native16_packed_pointwise_64x64, native16_packed_pointwise_128x128, native16_packed_pointwise_64x128 — Views an unpadded single-batch pointwise convolution as contiguous half matrix operands, with float32 accumulation and a fused float32 epilogue before half output.
  • im2col_native16_packed_64x64 — Materializes single-batch half convolution columns, then multiplies the weights by them as packed half matrix operands, with float32 accumulation and a fused float32 epilogue before half output.
  • im2col_native16_packed_64x64_exceptional — Materializes single-batch half convolution columns, then multiplies the weights by them as packed half matrix operands, with float32 accumulation and a fused float32 epilogue before half output. Weight rows that contain Inf or NaN are flagged, and a final pass recomputes those rows in float32 from the original operands.
  • im2col_native16_packed_128x128 — Materializes single-batch half convolution columns, then multiplies the weights by them as packed half matrix operands, with float32 accumulation and a fused float32 epilogue before half output.
  • im2col_native16_packed_128x128_exceptional — Materializes single-batch half convolution columns, then multiplies the weights by them as packed half matrix operands, with float32 accumulation and a fused float32 epilogue before half output. Weight rows that contain Inf or NaN are flagged, and a final pass recomputes those rows in float32 from the original operands.
  • im2col_native16_packed_vector4_64x64 — Materializes single-batch half convolution columns, then multiplies the weights by them as packed half matrix operands, with float32 accumulation and a fused float32 epilogue before half output.
  • im2col_native16_packed_vector4_64x64_exceptional — Materializes single-batch half convolution columns, then multiplies the weights by them as packed half matrix operands, with float32 accumulation and a fused float32 epilogue before half output. Weight rows that contain Inf or NaN are flagged, and a final pass recomputes those rows in float32 from the original operands.
  • im2col_native16_packed_vector4_128x128 — Materializes single-batch half convolution columns, then multiplies the weights by them as packed half matrix operands, with float32 accumulation and a fused float32 epilogue before half output.
  • im2col_native16_packed_vector4_128x128_exceptional — Materializes single-batch half convolution columns, then multiplies the weights by them as packed half matrix operands, with float32 accumulation and a fused float32 epilogue before half output. Weight rows that contain Inf or NaN are flagged, and a final pass recomputes those rows in float32 from the original operands.
  • im2col_native16_packed_vector4_64x128 — Materializes single-batch half convolution columns, then multiplies the weights by them as packed half matrix operands, with float32 accumulation and a fused float32 epilogue before half output.
  • im2col_native16_packed_vector4_64x128_exceptional — Materializes single-batch half convolution columns, then multiplies the weights by them as packed half matrix operands, with float32 accumulation and a fused float32 epilogue before half output. Weight rows that contain Inf or NaN are flagged, and a final pass recomputes those rows in float32 from the original operands.
  • winograd_f32 — Uses F(2x2,3x3) transforms, component matrix products and accumulation in float32 for half-precision tensors. Stores all transform components in a temporary buffer of bounded size. Tiles whose transformed values contain Inf or NaN use the direct spatial sum instead.
  • winograd_f32_striped — Uses F(2x2,3x3) transforms, component matrix products and accumulation in float32 for half-precision tensors. Reuses one temporary buffer across four component rows to bound memory. Tiles whose transformed values contain Inf or NaN use the direct spatial sum instead.
  • grouped_large_kernel_w4, grouped_large_kernel_w4_dilated_lanes — Shares each input row window across output channels and columns with f32 accumulation. Multi-channel groups loop over kernel rows to limit generated instructions; depthwise groups retain unrolling. Dilation-aware lanes reuse overlapping taps. Unless the adapter reports a subgroup size fixed at 32, unrolled large kernels are tried only after other variants.
  • pointwise_channel_reduce — Handles pointwise unit-stride convolution with few output channels by assigning one invocation to each spatial position and accumulating every output channel in registers. It needs no temporary im2col buffer.
  • gemm_1x1_subgroup_matrix — Multiplies 1x1 weights directly by NCHW input. Complete output-channel tiles use direct subgroup-matrix loads, eliminating input staging and reduction-loop barriers; partial tiles retain guarded staging. Tile geometry follows the device's workgroup limits.
  • im2col_gemm_subgroup_matrix — Materializes convolution windows as a column matrix, then multiplies it by the weights with subgroup-matrix operations. It applies when reduction and spatial extents are tile-aligned and the temporary column buffer fits.
  • im2col_gemm_subgroup_matrix_f16 — Materializes convolution windows as a column matrix, then multiplies it by the weights with subgroup-matrix operations. It applies when reduction and spatial extents are tile-aligned and the temporary column buffer fits. Weight rows that contain Inf or NaN are flagged, and a final pass recomputes those rows in float32 from the original operands.
  • im2col_direct_subgroup_matrix — Materializes tile-aligned convolution columns and loads weights and columns directly into subgroup matrices, with no operand staging or K-loop barriers. Accumulates in f32.
  • im2col_direct_f16_subgroup_matrix_f16 — Materializes tile-aligned convolution columns and loads weights and columns directly into subgroup matrices, with no operand staging or K-loop barriers. Accumulates in f32. Weight rows that contain Inf or NaN are flagged, and a final pass recomputes those rows in float32 from the original operands.
  • implicit_im2col_subgroup_matrix — Gathers each logical 2-D or 3-D im2col tile directly from X instead of materializing a column matrix, trading extra address arithmetic for the temporary buffer and bandwidth that materialization would cost. It applies when the output has few output-channel tiles, so the gather is not repeated across many tiles.
  • implicit_im2col_subgroup_matrix_splitk — Partitions the implicit-im2col reduction across workgroups when the unsplit output grid is too small, then a second pass sums the partial results from a temporary buffer. This changes the floating-point addition order compared with the unsplit variant.
  • implicit_volume_tiled_reg — Stages four neighboring NCDHW positions per lane directly from the input and reuses them across output channels. A deep reduction and enough spatial tiles amortize coordinate decoding. Full vector groups stay inside an output row, and with padding, outputs touched by Inf or NaN weights are recomputed tap by tap, skipping padded taps.
  • im2col_gemm_subgroup_matrix_padded, im2col_gemm_subgroup_matrix_padded_f16 — Materializes a zero-padded column matrix before a subgroup-matrix multiply, allowing logical reduction and spatial extents that are not tile-aligned. Padded values contribute zero and are excluded from the logical output.
  • im2col_gemm_subgroup_matrix_padded_splitk, im2col_gemm_subgroup_matrix_padded_splitk_f16 — Materializes a zero-padded column matrix, partitions its subgroup-matrix reduction across workgroups, then sums the partial results from a temporary buffer in a second pass. This keeps the padded column-matrix variant usable when its output grid alone is too small to fill the device; summing the partials changes the floating-point addition order.
  • implicit_im2col_tiled_bias_reg_m32, implicit_im2col_tiled_reg, implicit_im2col_tiled_bias_reg — Gathers logical im2col elements directly from X while filling register-blocked GEMM tiles. It needs no temporary column buffer and runs on devices without subgroup-matrix support.
  • implicit_im2col_tiled_reg_splitk — Splits an underfilled register-tiled implicit-im2col reduction across workgroups and combines raw f32 partials. Narrow half tiles use bounded f32 staging and compact partial rows. Strided windows or full channel tiles can reuse f32 columns within the same temporary-buffer budget. The split reduction reassociates additions.
  • im2col_gemm_tiled_reg — Writes the im2col columns to a temporary f32 buffer, then multiplies them in a tiled GEMM with f32 accumulation. A present bias is applied before the final output cast.
  • gemm_1x1_tiled_reg_splitk — Partitions the register-blocked 1x1 GEMM reduction across additional workgroups when the output grid is small, then a second pass sums the partial results. This changes the floating-point addition order compared with the unsplit variant.
  • subgroup_matrix_16x16x16 — Experimental 16x16x16 half-precision subgroup matrices with f32 accumulation. Any bias is added in f32 before the output cast. The matrix path runs only when the workgroup's subgroups are complete and of the expected width and the weights are finite; otherwise the kernel computes every output element without them.
  • implicit_narrow_f32_wide — Widens the output-column tile for deep f32 reductions with narrow channel tiles when the device storage, workgroup and useful output-grid limits permit it.
  • im2col_gemm_tiled_reg_f16_columns_f32_wide — Exact f16 columns feed register-tiled GEMM with f32 accumulation. Used when the output, counted across the batch, is large enough; channel tiles round up to 32, at most 64. The column buffer and workgroup size must fit WebGPU limits. A bias is loaded once per row of each lane's register block and added to its columns before the final output cast.
  • packed_im2col_gemm_tiled_reg_f16_columns_f32_wide — Aligns exact half column rows to vector words and consumes them through the shared register GEMM while storing only the logical output extent.
  • implicit_im2col_tiled_reg_short_grid, implicit_im2col_tiled_bias_reg_short_grid, implicit_im2col_tiled_reg_wide_m, implicit_im2col_tiled_bias_reg_wide_m — Gathers logical im2col elements directly from X while filling register-blocked GEMM tiles. It needs no temporary column buffer and runs on devices without subgroup-matrix support.
  • im2col_gemm_tiled — Writes the im2col columns to a temporary f32 buffer, then multiplies them in a tiled GEMM with f32 accumulation. A present bias is applied before the final output cast.
  • im2col_gemm_tiled_reg_f16_columns — Exact f16 columns feed register-tiled GEMM with f32 accumulation. Used when the output, counted across the batch, is large enough; channel tiles round up to 32, at most 64. The column buffer and workgroup size must fit WebGPU limits. A bias is loaded once per row of each lane's register block and added to its columns before the final output cast.
  • im2col_gemm_tiled_f16_columns — Exact f16 columns feed the smaller tiled GEMM with f32 accumulation. Short batched spatial workloads use the f32 column layout when it fits; this half-sized layout serves constrained buffers. The spatial-work crossover is independent of the gather workgroup size. A present bias is applied before the final output cast.
  • nhwc_native16_64x64, nhwc_native16_128x128, nhwc_native16_128x64 — Transposes half activations to channel-last order and packs half weights, then runs an implicit-GEMM half convolution on 16x16x16 subgroup matrices with float32 accumulation. The weight-packing pass flags weight rows that contain Inf or NaN; a final pass recomputes those rows in float32 from the original operands, skipping padded taps.

Device requirements

Some implementation variants require subgroup-matrix, shader-f16, and subgroups. Other variants run without them; which variant runs also depends on the request's shapes and dtypes.

Files

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.Conv", { version: 1 });

const xData = Float32Array.of(
  -0.21559301, 0.46916878, 0.44267005, -0.45174667, -0.052164197, 0.29067183, 0.25101,
);
const wData = Float32Array.of(0.24472862);

const { y } = await kernel({
  x: { data: xData, shape: [1, 1, 7] },
  w: { data: wData, shape: [1, 1, 1] },
});
console.log({ y });
Downloads last month
-
kernel
webgpu
wgsl
apache-2.0
WebGPU

Requires WebGPU support. See the compatibility table.