Skip to content

[CPU] Dequantize feeding a strided conv is not fused, whole-tensor temp lands on the stack #24752

Closed

Description

@dimp-pl

What happened?

Disclaimer: issue text was generated by Claude, but it was guided and checked by me.

A ui8 -> f32 dequantize feeding a strided convolution does not fuse: the dequantize materializes its entire f32 result as a function-local stack allocation, and the convolution reads it through a strided tensor.extract_slice. This is the downsample block of every quantized ResNet-family model (dequant → 1×1 stride-2 conv).

Steps to reproduce your issue

repro.mlir:

func.func @main(%arg0: tensor<1x256x56x56xi8>) -> tensor<1x512x28x28xf32> {
  %scale = arith.constant 1.250000e-01 : f32
  %zero = arith.constant 0.000000e+00 : f32
  %weights = arith.constant dense<1.000000e+00> : tensor<512x256x1x1xf32>
  %init = tensor.empty() : tensor<1x256x56x56xf32>
  %dequant = linalg.generic {
    indexing_maps = [affine_map<(d0, d1, d2, d3) -> (d0, d1, d2, d3)>,
                     affine_map<(d0, d1, d2, d3) -> (d0, d1, d2, d3)>],
    iterator_types = ["parallel", "parallel", "parallel", "parallel"]
  } ins(%arg0 : tensor<1x256x56x56xi8>) outs(%init : tensor<1x256x56x56xf32>) {
    ^bb0(%in: i8, %out: f32):
      %0 = arith.uitofp %in : i8 to f32
      %1 = arith.mulf %0, %scale : f32
      linalg.yield %1 : f32
  } -> tensor<1x256x56x56xf32>
  %out_init = tensor.empty() : tensor<1x512x28x28xf32>
  %fill = linalg.fill ins(%zero : f32) outs(%out_init : tensor<1x512x28x28xf32>) -> tensor<1x512x28x28xf32>
  %conv = linalg.conv_2d_nchw_fchw
    {dilations = dense<1> : tensor<2xi64>, strides = dense<2> : tensor<2xi64>}
    ins(%dequant, %weights : tensor<1x256x56x56xf32>, tensor<512x256x1x1xf32>)
    outs(%fill : tensor<1x512x28x28xf32>) -> tensor<1x512x28x28xf32>
  return %conv : tensor<1x512x28x28xf32>
}

$ iree-compile --iree-hal-target-backends=llvm-cpu repro.mlir -o /dev/null

repro.mlir:21:11: error: 'func.func' op exceeded stack allocation limit of 32768 bytes for function. Got 3211264 bytes

What component(s) does this issue relate to?

MLIR

Version information

Reproduced at IREE 9080be2167, clang-22 host, x86_64.

Additional context

This is one of the things that was discovered when enabling quantized resnet models on int8 to benchmark IREE against ExecuTorch on RISC-V targets.

The better error message for LLVMCPU backend and some allocation size checks are provided in PR #24745. The proper fix for the fusion issue will have to go to to upstream MLIR, if i understand it correctly. I also have a prototype of the fix for the upstream, i'll clean it up and share it.

Activity

  1. added
    bug 🐞
    on Jul 23, 2026
  2. changed the title [-][CPU] Dequantize feeding a strided conv is not fused; whole-tensor temp lands on the stack[/-] [+][CPU] Dequantize feeding a strided conv is not fused, whole-tensor temp lands on the stack[/+] on Jul 23, 2026
  3. egebeysel commented on Aug 11, 2026

    @egebeysel
    Contributor

    The proper fix for the fusion issue will have to go to to upstream MLIR, if i understand it correctly. I also have a prototype of the fix for the upstream, i'll clean it up and share it.

    If you have this cleaned up, I'll be curious to see :) Are you implementing the tiling interface for extract_slice ops?

  4. added a commit that references this issue on Oct 6, 2026
    f2aff78
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug 🐞

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions