Skip to content

Commit

Permalink
[TIR] Implement max/min_value for fp8 data types (apache#16723)
Browse files Browse the repository at this point in the history
  • Loading branch information
vinx13 authored Mar 15, 2024
1 parent 939b8b9 commit 9ec7249
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/tir/op/op.cc
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,12 @@ PrimExpr max_value(const DataType& dtype, Span span) {
}
} else if (dtype.is_bfloat16()) {
return FloatImm(dtype, std::numeric_limits<float>::max(), span);
} else if (dtype.is_float8()) {
if (dtype.code() == DataType::TypeCode::kE5M2Float) {
return FloatImm(dtype, 57344.0, span);
} else if (dtype.code() == DataType::TypeCode::kE4M3Float) {
return FloatImm(dtype, 448.0, span);
}
}
LOG(FATAL) << "Cannot decide max_value for type" << dtype;
}
Expand Down Expand Up @@ -296,6 +302,12 @@ PrimExpr min_value(const DataType& dtype, Span span) {
}
} else if (dtype.is_bfloat16()) {
return FloatImm(dtype, std::numeric_limits<float>::lowest(), span);
} else if (dtype.is_float8()) {
if (dtype.code() == DataType::TypeCode::kE5M2Float) {
return FloatImm(dtype, -57344.0, span);
} else if (dtype.code() == DataType::TypeCode::kE4M3Float) {
return FloatImm(dtype, -448.0, span);
}
}
LOG(FATAL) << "Cannot decide min_value for type" << dtype;
}
Expand Down

0 comments on commit 9ec7249

Please sign in to comment.