tracel-ai/burn · error

kernel failed (device= , dtype= )

Error message

{0} kernel failed (device={1:?}, dtype={2:?}): {3}

What it means

pool_panic is the shared fatal-error handler for all pooling kernels (max/avg pool, adaptive avg pool, and their backward passes) on the CubeCL backend. When the pool kernel launch returns a PoolError, it panics with the operation label, input device, dtype, and the error. One panic site covers six public pool operations.

Solutions

  1. Read the PoolError and the label to identify which pool op failed
  2. Validate kernel_size/stride/padding: stride > 0 and window not exceeding padded input size
  3. Ensure input is a valid NCHW tensor with the expected dtype on a supported device
  4. For backward errors, confirm the output_grad shape equals the forward output shape

Example fix

// before
let out = max_pool2d(x, [3, 3], [0, 0], [1, 1]); // window larger than 2x2 input
// after: pad or shrink the kernel to fit the input
let out = max_pool2d(x, [2, 2], [0, 0], [1, 1]);
Defensive patterns

Strategy: validation

Validate before calling

assert!(stride.iter().all(|&s| s > 0), "pool stride must be > 0");
let padded = (h + 2 * pad).ge(&kernel[0]);
assert!(padded, "pool kernel larger than (padded) input");

Prevention

When it happens

Trigger: Calling max_pool2d, avg_pool2d, adaptive_avg_pool2d (or their _backward/_with_indices variants) with kernel_size/stride/padding combinations that produce invalid output shapes, unsupported dtypes/devices, or malformed input channel layout.

Common situations: Pool window larger than the input spatial dims, stride 0, channel-first vs NHWC confusion after permute, f16 pooling on hardware lacking support, or backward grads with mismatched shapes.

Related errors


AI-assisted analysis of tracel-ai/burn@d16f7ba2ed (2026-09-05). Data as JSON: /api/errors/2088da43f182b4e9. Report an issue: GitHub.

Appendix: source

Thrown at crates/burn-cubecl/src/kernel/pool/base.rs:385

    );

    let mode = PoolMode::from(AdaptiveAvgPoolOptions::new([out_h, out_w]));

    pool2d_backward(
        &output.client,
        input.clone().binding(),
        out_grad.clone().binding(),
        output.clone().binding(),
        mode,
        dtype_to_storage_type(output.dtype),
    )
    .unwrap_or_else(|e| pool_panic("adaptive_avg_pool2d_backward", &input, e));

    permute_nhwc_to_nchw(output)
}

fn pool_panic(label: &str, input: &CubeTensor, error: PoolError) -> ! {
    panic!(
        "{0} kernel failed (device={1:?}, dtype={2:?}): {3}",
        label, input.device, input.dtype, error
    )
}

View on GitHub (pinned to d16f7ba2ed)