Skip to main content

conv2d_bias_forward

Function conv2d_bias_forward 

Source
pub fn conv2d_bias_forward<T: Triton, D: Num, const KH: i32, const KW: i32, const STRIDE_H: i32, const STRIDE_W: i32, const PAD_H: i32, const PAD_W: i32, const G: i32, const BLOCK_OW: i32>(
    x_ptr: T::Pointer<D>,
    w_ptr: T::Pointer<D>,
    bias_ptr: T::Pointer<D>,
    y_ptr: T::Pointer<D>,
    _B: i32,
    C_IN: i32,
    C_OUT: i32,
    H: i32,
    W: i32,
    OH: i32,
    OW: i32,
)
where T::I32Tensor: Tensor<i32, 1> + Comparison<i32, BoolTensor = T::BoolTensor>, T::BoolTensor: BitAnd<Output = T::BoolTensor>, T::Pointer<D>: AddOffsets<i32, 1, T::I32Tensor, Output = T::Tensor<T::Pointer<D>>>,
Expand description

2-D convolution forward pass fused with a per-output-channel bias add.

Identical to conv2d_forward (same grid, same masked-load accumulation loop — see its doc comment) with one addition: acc + bias[c_out] before the store. bias broadcasts the same “load as a [1] tensor, then broadcast_to” pattern conv2d_forward already uses for weights, applied once after the loop instead of once per (c_in, kh, kw) tap.

For Conv2d(has_bias=true) with no downstream BatchNorm/SiLU to fuse into (the conv2d_bn_silu family), this replaces what would otherwise lower to two separate kernel launches — conv2d_forward then a standalone NCHW bias-add — with one. See spinorml-ia5.

Inference-only; no backward pass (training still uses the two-kernel path via conv2d_forward + a separate bias-add, whose backward is a plain per-channel sum over the output gradient — fusing that isn’t this kernel’s job).