llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
28.97k stars 11.94k forks source link

[mlir] [linalg] Generalize linalg.depthwise_conv_2d_nhwc_hwcm crash #109128

Closed iviarcio closed 4 days ago

iviarcio commented 1 month ago

I'm trying to generalize a linalg convolution (see code below) and the compiler crashed (see the file crash.txt attached).

// RUN: mlir-opt "$1".mlir --pass-pipeline=" \ // RUN: builtin.module(transform-interpreter{ \ // RUN: debug-bind-trailing-args=linalg.depthwise_conv_2d_nhwc_hwcm},canonicalize,cse,symbol-dce)" \ // RUN: -o "$1"_opt.mlir

// Original depthwise_conv_2d_nhwc_hwcm to be converted into generic. func.func @depthwise_conv_2d_nhwc_hwcm(%input: tensor<2x4x5x2xf32>, %filter: tensor<2x2x2x3xf32>, %output: tensor<2x3x4x2x3xf32>) { %depw = linalg.depthwise_conv_2d_nhwc_hwcm { dilations = dense<1> : tensor<2xi64>, strides = dense<1> : tensor<2xi64> } ins(%input, %filter : tensor<2x4x5x2xf32>, tensor<2x2x2x3xf32>) outs(%output : tensor<2x3x4x2x3xf32>) -> tensor<2x3x4x2x3xf32> return %depw : tensor<2x3x4x2x3xf32> }

module attributes {transform.with_named_sequence} {

transform.named_sequence @__transform_main( %arg0: !transform.any_op, %conv: !transform.op<"linalg.depthwise_conv_2d_nhwc_hwcm">) {

transform.debug.emit_remark_at %conv, "Input conv" : !transform.op<"linalg.depthwise_conv_2d_nhwc_hwcm">

%res = transform.structured.generalize %conv
  : !transform.op<"linalg.depthwise_conv_2d_nhwc_hwcm">
  -> !transform.any_op 

transform.debug.emit_remark_at %res, "result" : !transform.any_op

transform.yield

} }

llvmbot commented 1 month ago

@llvm/issue-subscribers-mlir-linalg

Author: Marcio M Pereira (iviarcio)

I'm trying to generalize a linalg convolution (see code below) and the compiler crashed (see the file [crash.txt](https://github.com/user-attachments/files/17043886/crash.txt) attached). // RUN: mlir-opt "$1".mlir --pass-pipeline=" \ // RUN: builtin.module(transform-interpreter{ \ // RUN: debug-bind-trailing-args=linalg.depthwise_conv_2d_nhwc_hwcm},canonicalize,cse,symbol-dce)" \ // RUN: -o "$1"_opt.mlir // Original depthwise_conv_2d_nhwc_hwcm to be converted into generic. func.func @depthwise_conv_2d_nhwc_hwcm(%input: tensor<2x4x5x2xf32>, %filter: tensor<2x2x2x3xf32>, %output: tensor<2x3x4x2x3xf32>) { %depw = linalg.depthwise_conv_2d_nhwc_hwcm { dilations = dense<1> : tensor<2xi64>, strides = dense<1> : tensor<2xi64> } ins(%input, %filter : tensor<2x4x5x2xf32>, tensor<2x2x2x3xf32>) outs(%output : tensor<2x3x4x2x3xf32>) -> tensor<2x3x4x2x3xf32> return %depw : tensor<2x3x4x2x3xf32> } module attributes {transform.with_named_sequence} { transform.named_sequence @__transform_main( %arg0: !transform.any_op, %conv: !transform.op<"linalg.depthwise_conv_2d_nhwc_hwcm">) { transform.debug.emit_remark_at %conv, "Input conv" : !transform.op<"linalg.depthwise_conv_2d_nhwc_hwcm"> %res = transform.structured.generalize %conv : !transform.op<"linalg.depthwise_conv_2d_nhwc_hwcm"> -> !transform.any_op transform.debug.emit_remark_at %res, "result" : !transform.any_op transform.yield } }
ubfx commented 1 month ago

I'm not able to reproduce this. Could you attach the mlir file and tell us which commit this was tested on?

iviarcio commented 1 month ago

Thanks ubfx for addressing this issue. I'm attaching the mlir file in zip format and the commit. It's quite recent because I updated my branch to check if the bug had been fixed:

commit d5dd7d230ecaf8242f4429a5e3653e16bf55bcd6 depthwise.zip

ubfx commented 1 month ago

Thank you, now I could reproduce. The problem in this case is a malformed IR, the transform Op should have the type of the operand in ():

%res = transform.structured.generalize %conv : (!transform.op<"linalg.depthwise_conv_2d_nhwc_hwcm">) -> !transform.any_op 
// instead of
%res = transform.structured.generalize %conv : !transform.op<"linalg.depthwise_conv_2d_nhwc_hwcm"> -> !transform.any_op 

Obviously, the compiler still shouldn't crash on malformed IR and I'll see if this can be fixed.

iviarcio commented 1 month ago

Thank you and I apologize for the delay.