llvm / llvm-project

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

Downstream `builtin.unrealized_conversion_cast` error following PR #99890, `[MLIR][GPUToNVVM] support fastMath and other non-supported mathOp` #101030

Open bjacob opened 3 months ago

bjacob commented 3 months ago

https://github.com/iree-org/iree is a downstream with a third_party/llvm-project submodule tracking upstream with daily syncs.

The last sync, https://github.com/iree-org/iree/pull/18019, had to locally revert #99890 to temporarily fix compilation failures.

Details in https://github.com/iree-org/iree/pull/18010#issuecomment-2253215720 and more details in this Discord chat.

<unknown>:0: error: LLVM Translation failed for operation: builtin.unrealized_conversion_cast
<unknown>:0: note: see current operation: %71 = "builtin.unrealized_conversion_cast"(%70) : (!llvm.array<1 x vector<1xf32>>) -> vector<1x1xf32>
model.mlir:7:10: error: failed to translate the MLIR LLVM dialect to the native llvm::Module

@ScottTodd @runseny @joker-eph

joker-eph commented 3 months ago

Thanks for the report! Unfortunately as-is it isn’t immediately actionable upstream: any chance you can extract the IR before the conversion pass and attach it here to make it reproducible?

ScottTodd commented 3 months ago

Here is the IR I started debugging with: https://gist.github.com/ScottTodd/667be2ac5e23bb0efbebb319bc3cb5b9

I suspect this is an issue with our downstream usage, but I'm not sure. Quoting from my comment downtream:

Removing LLVM::FMAOp from the target.addIllegalOp<...> block in mlir/lib/Conversion/GPUToNVVM/LowerGpuOpsToNVVMOps.cpp fixes compilation. I suggest debugging around https://github.com/iree-org/iree/blob/1ee68bdd0d8d3c8f3f51d13845b4c8eb3fc24990/compiler/src/iree/compiler/Codegen/LLVMGPU/ConvertToNVVM.cpp#L133-L151

bjacob commented 3 months ago

Still not a self-contained mlir-opt repro as this still relies on iree-opt, but at least it's down to a pass application, no longer a full iree-compile:

https://gist.github.com/bjacob/ff3c0425d063c3938a750ff09cadd448

bjacob commented 3 months ago

Minimized testcase (still iree-opt) showing that the issue is specific to math.fma ops on vector types that have rank >= 2. The issue is that in that case, there is a missing type conversion between !llvm.array<4 x vector<1xf32>> and vector<4x1xf32>.

Note: it doesn't matter that the additional dimension is a unit dim. The result is the same with 4x2xf32.

https://gist.github.com/bjacob/5b2fe816ac992119f4bd17d4d5f4d08a