[Mlir-commits] [mlir] [MLIR][Math] add canonicalize-f32-promotion pass (PR #92482)
Krzysztof Drewniak
llvmlistbot at llvm.org
Thu May 23 08:09:13 PDT 2024
krzysz00 wrote:
Re your most recent comment, I'd want both:
And as to the truncf/extf pairs, the reason I don't want f32 legalization to delete existing ones is that I have exactly one truncf/extf pair I want to keep around for its effect. The code conceptually goes like this)
```mlir
func @test_kernel(%a: tensor<...xbf16>, %b: tensor<...xbf16>) -> tensor<...xbf16>
func @ref_kernel(%a: tensor<...xf32>, %: tensor<...xf32>) -> tensor<...xf32>
func @main() {
%cTest = launch @test_kernel(...) : tensor<... x bf16>
%cRef = launch @ref_kernel(...) : tensor<... x f32>
%cTestF32 = arith.extf %cTest : tensor<... x bf16> to tensor<... x f32>
// This is the truncf/extf pair I want to preserve. Note that, though I write it on tensors, by the time any sort of
// math legalization is running, this is all scalar elementwise code.
// The truncate/extend replicates the fact that @test_kernel accumulates in f32 and rounds down to bf16
%cRefMatchingTestRounding = arith.truncf %cRef : tensor<...xf32> to tensor<...xbf16>
%cRefF32 = arith.extf %cRefMatchingTestRounding : tensor<...xbf16> to tensor<...xf32>
call @verify_nearness(%cTestF32, %cRefF32)
}
```
https://github.com/llvm/llvm-project/pull/92482
More information about the Mlir-commits
mailing list