Skip to content

[mlir][IR] Treat tf32 as 19-bit float #116738

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions mlir/lib/IR/BuiltinTypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,6 @@ IntegerType IntegerType::scaleElementBitwidth(unsigned scale) {
//===----------------------------------------------------------------------===//

unsigned FloatType::getWidth() {
// The actual width of TF32 is 19 bits. However, since it is a truncated
// version of Float32, we treat it as 32 bits in MLIR FloatType::getWidth
// for compatibility.
if (llvm::isa<FloatTF32Type>(*this))
return 32;
return APFloat::semanticsSizeInBits(getFloatSemantics());
}

Expand Down
16 changes: 16 additions & 0 deletions mlir/test/IR/attribute.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,14 @@ func.func @correct_type_pass() {

// -----

func.func @tf32_elements_attr() {
// CHECK: "foo"() {attr = dense<4.000000e+00> : tensor<tf32>} : () -> ()
"foo"() {attr = dense<4.0> : tensor<tf32>} : () -> ()
return
}

// -----

//===----------------------------------------------------------------------===//
// Test StringElementsAttr
//===----------------------------------------------------------------------===//
Expand Down Expand Up @@ -675,6 +683,14 @@ func.func @dense_array_attr() attributes {

// -----

func.func @test_invalid_bitwidth_type() {
// expected-error @below{{element type bitwidth must be a multiple of 8}}
"foo"() {tf32attr = array<tf32: 1024.0>} : () -> ()
return
}

// -----

func.func @testConfinedDenseArrayAttr() {
"test.confined_dense_array_attr"() {
i64attr = array<i64: 0, 2, 3>,
Expand Down
Loading