This is an archive of the discontinued LLVM Phabricator instance.

[APFloat] Add APFloat semantic support for TF32
ClosedPublic

Authored by jfurtek on Jun 1 2023, 1:27 PM.

Details

Summary

This diff adds APFloat support for a semantic that matches the TF32 data type
used by some accelerators (most notably GPUs from both NVIDIA and AMD).

For more information on the TF32 data type, see https://blogs.nvidia.com/blog/2020/05/14/tensorfloat-32-precision-format/.
Some intrinsics that support the TF32 data type were added in https://reviews.llvm.org/D122044.

For some discussion on supporting common semantics in APFloat, see similar
efforts for 8-bit formats at https://reviews.llvm.org/D146441, as well as
https://discourse.llvm.org/t/rfc-adding-the-amd-graphcore-maybe-others-float8-formats-to-apfloat/67969.

A subsequent diff will extend MLIR to use this data type. (Those changes are
not part of this diff to simplify the review process.)

Diff Detail

Event Timeline

jfurtek created this revision.Jun 1 2023, 1:27 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 1 2023, 1:27 PM
jfurtek requested review of this revision.Jun 1 2023, 1:27 PM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptJun 1 2023, 1:27 PM

I think this LG, but David had to update clang/lib/AST/MicrosoftMangle.cpp when some other float format was added, you don't need this here?

Also do you have plans for MLIR? (nothing required for this patch, just curious).

Also do you have plans for MLIR? (nothing required for this patch, just curious).

Actually it's the last sentence of the patch description (/facepalm)

I think this LG, but David had to update clang/lib/AST/MicrosoftMangle.cpp when some other float format was added, you don't need this here?

I did update that file - it is part of this diff. (I used that diff as a template - otherwise I probably would have missed that change...)

The associated MLIR changes are done - just haven't submitted the diff yet.

mehdi_amini accepted this revision.Jun 1 2023, 7:29 PM

Ok, sorry I missed the mangle update, seeing how I missed the MLIR mention as well: I need more sleep!! :)

This revision is now accepted and ready to land.Jun 1 2023, 7:29 PM
majnemer added inline comments.
llvm/include/llvm/ADT/APFloat.h
190

Hmm, this says improved precision than half but the semantics you gave say 11 digits? Does NVIDIA document how many bits we should expect?

llvm/lib/Support/APFloat.cpp
141

NVIDIA's docs say:

This data format is a special 32-bit floating point format supported by the matrix multiply-and-accumulate instructions, with the same range as .f32 and reduced precision (>=10 bits). The internal layout of tf32 format is implementation defined. PTX facilitates conversion from single precision .f32 type to tf32 format. A register variable containing tf32 data must be declared with .b32 type.

As written, it's at least 11 bits but it can change over time. Will we need corresponding flavors of this for future architectures over time?

jfurtek updated this revision to Diff 527968.Jun 2 2023, 2:02 PM
  • Fix comment and clang-formatting
jfurtek added inline comments.Jun 2 2023, 2:12 PM
llvm/include/llvm/ADT/APFloat.h
190

This was a mistake on my part - the range is better than FP16, not the precision. Updated the comment to reflect this.

The blog post linked in the description provides details on the current format only - I agree that the PTX description seems intentionally vague.

llvm/lib/Support/APFloat.cpp
141

If it changes, we would need to create a different float semantic to represent the new format (i.e. perhaps TF32v2 or something like that).

jfurtek updated this revision to Diff 528567.Jun 5 2023, 1:51 PM
  • Another clang-format fix
jfurtek updated this revision to Diff 533726.Jun 22 2023, 12:25 PM
  • Fix comment and clang-formatting
  • Another clang-format fix
  • Rebase, clang-format...
This revision was automatically updated to reflect the committed changes.