You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Bug in f32->f16 truncation on CPU: 0.49990 is truncated to 0.25. #20163
➜ iree-build tools/iree-compile --iree-hal-target-device=llvm-cpu --iree-llvmcpu-target-cpu=generic ~/a.mlir -o ~/b.vmfb && tools/iree-check-module --device=local-task --module=$HOME/b.vmfb
[==========] Running 1 test from 1 test suite.
[----------] Global test environment set-up.
[----------] 1 test from module
[ RUN ] module.test_trunc_f32_f16
iree/runtime/src/iree/modules/check/module.cc:568: Failure
Failed
Expected near equality of these values. Contents does not match to tolerance parameters atol=0.01, rtol=0. The first failure occurs at index 0 as the lhs value 0.25 differs from the rhs value 0.5.
lhs:
1xf16=0.25
rhs:
1xf16=0.5
[ FAILED ] module.test_trunc_f32_f16, where GetParam() = 0 (24 ms)
The bug only manifests itself when compiling to a CPU target that lacks a native instruction for f32 to f16 truncation (--iree-llvmcpu-target-cpu=generic). When we enable x86 F16C instructions (--iree-llvmcpu-target-cpu=host on any contemporary CPU) the issue goes away.
changed the title [-]`math.powf` `f16` correctness bug: `powf(2.0, -1.0) = 0.25` instead of `0.5`.[/-][+]LLVM bug in f32->f16 truncation on CPU[/+]on Mar 12, 2025
Activity
E2E tests for math ops. (#20169)
bjacob commentedon Mar 12, 2025
Minimized to a LLVM x86 codegen bug for truncation of f32 to f16.
Minimal MLIR testcase:
bjacob commentedon Mar 12, 2025
The bug only manifests itself when compiling to a CPU target that lacks a native instruction for f32 to f16 truncation (
--iree-llvmcpu-target-cpu=generic). When we enable x86 F16C instructions (--iree-llvmcpu-target-cpu=hoston any contemporary CPU) the issue goes away.[-]`math.powf` `f16` correctness bug: `powf(2.0, -1.0) = 0.25` instead of `0.5`.[/-][+]LLVM bug in f32->f16 truncation on CPU[/+]bjacob commentedon Mar 13, 2025
Actually the truncation from float to half here is implemented in our own libdevice. From the generated
.llfile:So it looks like a bug in
iree_f2h_ieee.[-]LLVM bug in f32->f16 truncation on CPU[/-][+]Bug in f32->f16 truncation on CPU[/+][-]Bug in f32->f16 truncation on CPU[/-][+]Bug in f32->f16 truncation on CPU: 0.49990 is truncated to 0.25.[/+]Fix libdevice `iree_f2h_ieee` conversion (#20248)
Fix libdevice `iree_f2h_ieee` conversion (iree-org#20248)
Fix libdevice `iree_f2h_ieee` conversion (#20248)
E2E tests for math ops. (#20169)
Fix libdevice `iree_f2h_ieee` conversion (#20248)