This is an archive of the discontinued LLVM Phabricator instance.

[mlir] Convert 8-bit float types to i8
ClosedPublic

Authored by krzysz00 on Jun 16 2023, 11:45 AM.

Details

Summary

Whereas LLVM currently doesn't have any types for 8-bit floats, and
whereas existing 8-bit float APIs (for instance, the AMDGCN
intrinsics) take such floats as (packed) bytes, translate the MLIR
8-bit float types to i8 during LLVM lowering.

In order to not special-case arith.constant for bitcasting constants
to their integer form, amend the MLIR to LLVM translator to turn 8-bit
float constants into i8 constants with the same value (by use of
APFloat's bitcast method).

This change can be reverted once LLVM has 8-bit float types.

Diff Detail

Event Timeline

krzysz00 created this revision.Jun 16 2023, 11:45 AM
Herald added a reviewer: dcaballe. · View Herald Transcript
Herald added a project: Restricted Project. · View Herald Transcript
krzysz00 requested review of this revision.Jun 16 2023, 11:45 AM
gysit accepted this revision.Jun 26 2023, 3:35 AM

LGTM!

mlir/lib/Conversion/LLVMCommon/TypeConverter.cpp
197–198

nit: Would it make sense to check type.getWidth() == 8?

It seems to handle one more 8-bit float type:

unsigned FloatType::getWidth() {
  if (llvm::isa<Float8E5M2Type, Float8E4M3FNType, Float8E5M2FNUZType,
          Float8E4M3FNUZType, Float8E4M3B11FNUZType>(*this))
    return 8;
  ...
This revision is now accepted and ready to land.Jun 26 2023, 3:35 AM
krzysz00 updated this revision to Diff 534565.Jun 26 2023, 8:08 AM

Add the newest fp8 type

krzysz00 marked an inline comment as done.Jun 26 2023, 8:10 AM
krzysz00 added inline comments.
mlir/lib/Conversion/LLVMCommon/TypeConverter.cpp
197–198

I wanted to not surprise anyone who adds a different 8-bit type

gysit added inline comments.Jun 26 2023, 8:17 AM
mlir/lib/Conversion/LLVMCommon/TypeConverter.cpp
197–198

sounds good since this is a "temporary" workaround anyways.

This revision was automatically updated to reflect the committed changes.
krzysz00 marked an inline comment as done.