Fix incorrect CPU float16 implementation#2395
Conversation
Remove print statement indicating all tests passed.
ThrudPrimrose
left a comment
There was a problem hiding this comment.
We need subnormal, inf and NaN in roundtrip tests to ensure we handle them correctly.
| 1e-3, | ||
| 6e-5, | ||
| 6e-8, | ||
| -6e-8, |
There was a problem hiding this comment.
Can you add a subnormal number to your tests?
Merges PR #2395 (head e33d5b0) into extended: replaces the buggy CPU half-precision conversion in dace/runtime/include/dace/types.h with the round-to-nearest-even implementation from the PR, and adds tests/half_cpu_test.py. Conflict resolution: extended had clang-format-reformatted types.h, so the PR's surrounding context conflicted. Kept extended's formatting and swapped in only the corrected half struct (the PR's functional change). half_cpu_test.py 2/2 pass. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
@eliasachermann @ThrudPrimrose Quick follow up. On ARMv8.2-A targets built with the FP16 arithmetic extension ( @ThrudPrimrose Not sure if ARM is something you want to support here, but if it is I'm happy to open a |
This would be a nice extension in my opinion. Once this PR is merged, I would propose that you open a new PR on top of what has merged such that we have native fp16 support for corresponding ARM target. I also know that latest avx512 instruction sets also have native fp16, could be nice to also support them. |
Problem
The
dace::halffallback indace/runtime/include/dace/types.his broken in two independent ways:No default constructor.
Generated code that declares an uninitialized
dace::float16fails to compile:Incorrect conversions.
The float↔half conversion is wrong for zero, subnormals, Inf/NaN, and does no rounding.
Fix
Tests
Adds
tests/half_cpu_test.py, to test the conversion against NumPy as the reference.