This is an archive of the discontinued LLVM Phabricator instance.

[APFloat] Add E4M3B11FNUZ
ClosedPublic

Authored by majnemer on Mar 20 2023, 10:23 AM.

Details

Summary

X. Sun et al. (https://dl.acm.org/doi/10.5555/3454287.3454728) published
a paper showing that an FP format with 4 bits of exponent, 3 bits of
significand and an exponent bias of 11 would work quite well for ML
applications.

Google hardware supports a variant of this format where 0x80 is used to
represent NaN, as in the Float8E4M3FNUZ format. Just like the
Float8E4M3FNUZ format, this format does not support -0 and values which
would map to it will become +0.

This format is proposed for inclusion in OpenXLA's StableHLO dialect: https://github.com/openxla/stablehlo/pull/1308

As part of inclusion in that dialect, APFloat needs to know how to
handle this format.

Diff Detail

Event Timeline

majnemer created this revision.Mar 20 2023, 10:23 AM
majnemer requested review of this revision.Mar 20 2023, 10:23 AM
Herald added projects: Restricted Project, Restricted Project, Restricted Project. · View Herald TranscriptMar 20 2023, 10:23 AM
majnemer updated this revision to Diff 506694.Mar 20 2023, 1:29 PM

Fix a small typo in PyFloat8E4M3B11FNUZType

reedwm accepted this revision.Mar 24 2023, 12:07 PM
This revision is now accepted and ready to land.Mar 24 2023, 12:07 PM
This revision was landed with ongoing or failed builds.Mar 24 2023, 1:07 PM
This revision was automatically updated to reflect the committed changes.
aaron.ballman added inline comments.
clang/lib/AST/MicrosoftMangle.cpp
848

Why are there no changes needed for the Itanium mangler? And when did we start adding a bunch of esoteric float formats? Was there an RFC for this that I missed? (If I did miss something, then sorry for the noise.)

majnemer added inline comments.Mar 25 2023, 7:21 AM
clang/lib/AST/MicrosoftMangle.cpp
848

Hi Aaron,

The Itanium mangler doesn't depend on the APFloat's semantics, it just depends on:

  • The Clang AST type of the float.
  • The bit pattern of the APFloat.

The code to handle the bit pattern is written generically, regardless of APFloat semantics.
Because of this and the lack of a new Clang built-in floating type results in no necessary changes to the Itanium mangler.

This just comes down to a quirk in how the MSVC and Itanium manglers are written: new APFloat semantics necessarily result in the MSVC mangler "noticing" while they don't for the Itanium mangler.

As to your question about an RFC, one was posted for some similar but different formats that people are interested in here

The general consensus on that RFC was that APFloat should support formats that people use in practice. This format is incorporated as part of real hardware in the real world as well as an open source compiler framework.

aaron.ballman added inline comments.Mar 25 2023, 7:56 AM
clang/lib/AST/MicrosoftMangle.cpp
848

Thank you for the explanation (and IRC discussion)! This all seems reasonable to me. I was mostly worried that there were more Clang parts that needed attention and discussion, but this is more used for backend work and isn't really exposed to the frontend except in these sort of fully covered switch cases.