mlir-opt crashes with UNREACHABLE in linalg.elementwise when operands have vector types
mlir-opt crashes with an UNREACHABLE when parsing a linalg.elementwise operation whose operands are vector types instead of tensors or memrefs.
The crash happens during parsing / region construction, before any pass pipeline is executed.
module {
func.func @main() {
%0 = spirv.Constant dense<0> : vector<4xi32>
%1 = gpu.grid_dim x
%2:4 = vector.to_elements %0 : vector<4xi32>
%3 = vector.multi_reduction <add>, %0, %2#0 [0] : vector<4xi32> to i32
%4 = vector.reduction <add>, %0, %3 : vector<4xi32> into i32
%5 = linalg.elementwise kind=#linalg.elementwise_kind<add> ins(%0, %0 : vector<4xi32>, vector<4xi32>) outs(%0 : vector<4xi32>) -> tensor<4xi32>
return
}
}
mlir-opt test.mlir
unsupported non numeric type
UNREACHABLE executed at mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp:514!
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace and instructions to reproduce the bug.
Stack dump:
0. Program arguments: mlir-opt test.mlir
1. MLIR Parser: custom op parser 'builtin.module'
2. MLIR Parser: custom op parser 'func.func'
3. MLIR Parser: custom op parser 'linalg.elementwise'
#0 0x0000565bb1f40e32 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (mlir-opt+0x252fe32)
#1 0x0000565bb1f3d5af llvm::sys::RunSignalHandlers() (mlir-opt+0x252c5af)
#2 0x0000565bb1f3d6fc SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0
#3 0x0000796393245330 (/lib/x86_64-linux-gnu/libc.so.6+0x45330)
#4 0x000079639329eb2c __pthread_kill_implementation ./nptl/pthread_kill.c:44:76
#5 0x000079639329eb2c __pthread_kill_internal ./nptl/pthread_kill.c:78:10
#6 0x000079639329eb2c pthread_kill ./nptl/pthread_kill.c:89:10
#7 0x000079639324527e raise ./signal/../sysdeps/posix/raise.c:27:6
#8 0x00007963932288ff abort ./stdlib/abort.c:81:7
#9 0x0000565bb1f2012e (mlir-opt+0x250f12e)
#10 0x0000565bb7ee3e74 (anonymous namespace)::RegionBuilderHelper::buildBinaryFn(mlir::linalg::BinaryFn, mlir::Value, mlir::Value, llvm::function_ref<mlir::InFlightDiagnostic ()>) LinalgOps.cpp:0:0
#11 0x0000565bb7ef6280 mlir::linalg::ElementwiseOp::regionBuilder(mlir::ImplicitLocOpBuilder&, mlir::Block&, llvm::ArrayRef<mlir::NamedAttribute>, llvm::function_ref<mlir::InFlightDiagnostic ()>) (mlir-opt+0x84e5280)
@llvm/issue-subscribers-mlir-linalg
Author: None (compilerStudyer)
The crash happens during parsing / region construction, before any pass pipeline is executed.
module {
func.func @<!-- -->main() {
%0 = spirv.Constant dense<0> : vector<4xi32>
%1 = gpu.grid_dim x
%2:4 = vector.to_elements %0 : vector<4xi32>
%3 = vector.multi_reduction <add>, %0, %2#<!-- -->0 [0] : vector<4xi32> to i32
%4 = vector.reduction <add>, %0, %3 : vector<4xi32> into i32
%5 = linalg.elementwise kind=#linalg.elementwise_kind<add> ins(%0, %0 : vector<4xi32>, vector<4xi32>) outs(%0 : vector<4xi32>) -> tensor<4xi32>
return
}
}
mlir-opt test.mlir
unsupported non numeric type
UNREACHABLE executed at mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp:514!
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace and instructions to reproduce the bug.
Stack dump:
0. Program arguments: mlir-opt test.mlir
1. MLIR Parser: custom op parser 'builtin.module'
2. MLIR Parser: custom op parser 'func.func'
3. MLIR Parser: custom op parser 'linalg.elementwise'
#<!-- -->0 0x0000565bb1f40e32 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (mlir-opt+0x252fe32)
#<!-- -->1 0x0000565bb1f3d5af llvm::sys::RunSignalHandlers() (mlir-opt+0x252c5af)
#<!-- -->2 0x0000565bb1f3d6fc SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0
#<!-- -->3 0x0000796393245330 (/lib/x86_64-linux-gnu/libc.so.6+0x45330)
#<!-- -->4 0x000079639329eb2c __pthread_kill_implementation ./nptl/pthread_kill.c:44:76
#<!-- -->5 0x000079639329eb2c __pthread_kill_internal ./nptl/pthread_kill.c:78:10
#<!-- -->6 0x000079639329eb2c pthread_kill ./nptl/pthread_kill.c:89:10
#<!-- -->7 0x000079639324527e raise ./signal/../sysdeps/posix/raise.c:27:6
#<!-- -->8 0x00007963932288ff abort ./stdlib/abort.c:81:7
#<!-- -->9 0x0000565bb1f2012e (mlir-opt+0x250f12e)
#<!-- -->10 0x0000565bb7ee3e74 (anonymous namespace)::RegionBuilderHelper::buildBinaryFn(mlir::linalg::BinaryFn, mlir::Value, mlir::Value, llvm::function_ref<mlir::InFlightDiagnostic ()>) LinalgOps.cpp:0:0
#<!-- -->11 0x0000565bb7ef6280 mlir::linalg::ElementwiseOp::regionBuilder(mlir::ImplicitLocOpBuilder&, mlir::Block&, llvm::ArrayRef<mlir::NamedAttribute>, llvm::function_ref<mlir::InFlightDiagnostic ()>) (mlir-opt+0x84e5280)
Is this an issue that should be handled by the verifier or by an explicit condition check? It seems that this case should be diagnosed earlier, rather than reaching an llvm_unreachable. I’d like to try fixing this issue.
This happens during parsing. It looks like emitError is not passed when calling RegionBuilderHelper::buildBinaryFn. (See call site in ElementwiseOp::regionBuilder.)
@javedabsar1
This happens during parsing. It looks like
emitErroris not passed when callingRegionBuilderHelper::buildBinaryFn. (See call site inElementwiseOp::regionBuilder.)
Thanks for the pointer! Would you mind assigning the issue to me? I’ll take a look.
This is interesting. I never imagined vectors being passed to linalg.elementwise. The elementwise op must lower to linalg.generic which only accepts memref/tensors. Probably we need a clean 'check memref or tensor' and bail out nicely on 'linalg.elementwise ... vector<4xi32>, vector<4xi32>) '
This is interesting. I never imagined vectors being passed to linalg.elementwise. The elementwise op must lower to linalg.generic which only accepts memref/tensors. Probably we need a clean 'check memref or tensor' and bail out nicely on 'linalg.elementwise ... vector<4xi32>, vector<4xi32>) '
Just to make sure I’m on the right track, is this the expected outcome for the issue I’m working on?
test.mlir:8:64: error: custom op 'linalg.elementwise' Cannot build binary Linalg operation: expects allComplex, allFloatingPoint, or allInteger, got 'vector<4xi32>' and 'vector<4xi32>'
%5 = linalg.elementwise kind=#linalg.elementwise_kind<add> ins(%0, %0 : vector<4xi32>, vector<4xi32>) outs(%0 : vector<4xi32>) -> tensor<4xi32>
^
test.mlir:9:5: error: custom op 'linalg.elementwise' unable to parse elemwise op
return
^
I still don’t fully understand how the elementwise op should be lowered to linalg.generic.
The types must match. tensor -> tensor, memref -> memref and vector -> vector