tensorflow / mlir

"Multi-Level Intermediate Representation" Compiler Infrastructure
1.74k stars 259 forks source link

Assertion failed: (packedType && "type conversion failed, such operation should not " "have been matched"), function matchAndRewrite #230

Closed aaronsm closed 5 years ago

aaronsm commented 5 years ago

I'm playing around with mlir-opt lowering to LLVM IR and hit this assertion failure. I'm pretty sure lowering this example is not supposed to work (returning a tensor is not supported?) but I wasn't expecting it to crash.

Here's what I did. I coped the first test case into it's own file and tried to lower to LLVM IR. htps://github.com/tensorflow/mlir/blob/master/test/Quantizer/matmul.mlir

func @matmul(%arg0: tensor<300x3xf32>) -> tensor<300x5xf32> { %0 = "quant.stats"(%arg0) {layerStats = dense<[-6.123e+00, 3.45e+00]> : tensor<2xf32>} : (tensor<300x3xf32>) -> tensor<300x3xf32> %cst = constant {name = "constant.35"} dense<[[-1.060230e-01, 1.215050e-01, 8.002390e-01, -7.688850e-01, 0.0966112986], [6.890140e-01, -4.070560e-01, -0.797852993, 3.789250e-03, -2.088810e-01], [-6.085290e-01, 2.766170e-02, 2.685570e-01, 5.774010e-01, -4.284370e-01]]> : tensor<3x5xf32> %1 = "fxpmath.real_matmul"(%0, %cst) : (tensor<300x3xf32>, tensor<3x5xf32>) -> tensor<300x5xf32> %2 = "quant.stats"(%1) {layerStats = dense<[-8.000000e+00, 8.000000e+00]> : tensor<2xf32>} : (tensor<300x5xf32>) -> tensor<300x5xf32> return %2 : tensor<300x5xf32> }

$ ./mlir-opt test.mlir -lower-to-llvm

Assertion failed: (packedType && "type conversion failed, such operation should not " "have been matched"), function matchAndRewrite, file /llvm-project/llvm/projects/mlir/lib/Conversion/StandardToLLVM/ConvertStandardToLLVM.cpp, line 470.

ftynse commented 5 years ago

Thanks for the report. This is due to code motion in the standard-to-llvm conversion that dropped the check before the assertion. I have a fix coming.

Please note that you cannot lower just anything to the LLVM dialect using "-lower-to-llvm", it only works with a subset of the standard dialect (scalar and vector operations).