Commit 8bfc2848 authored by Nagy Mostafa's avatar Nagy Mostafa Committed by Scott Cyphers

[MLIR] Use f64 APFloat (#3453)

* Use f64 APFloat

* PR feedback
parent 2ff6995e
...@@ -100,6 +100,8 @@ namespace ...@@ -100,6 +100,8 @@ namespace
PatternRewriter& rewriter, PatternRewriter& rewriter,
DialectLoweringPass& pass); DialectLoweringPass& pass);
ValueHandle createZeroConstant(mlir::Type type);
/// Conversion from types in the nGraph dialect to the Standard dialect. /// Conversion from types in the nGraph dialect to the Standard dialect.
class NGraphTypeConverter : public TypeConverter class NGraphTypeConverter : public TypeConverter
{ {
...@@ -509,20 +511,8 @@ namespace ...@@ -509,20 +511,8 @@ namespace
LoopNestBuilder(pivs, lbs, ubs, steps)([&] { LoopNestBuilder(pivs, lbs, ubs, steps)([&] {
ValueHandle val = iLHS(ivs); ValueHandle val = iLHS(ivs);
if (auto floatTy = elemTy.dyn_cast<FloatType>()) ValueHandle zero = createZeroConstant(elemTy);
{
ValueHandle zero = intrinsics::constant_float(llvm::APFloat(0.0f), floatTy);
iRes(ivs) = intrinsics::select(val > zero, val, zero);
}
else if (auto intTy = elemTy.dyn_cast<IntegerType>())
{
ValueHandle zero = intrinsics::constant_int(0, intTy.getWidth());
iRes(ivs) = intrinsics::select(val > zero, val, zero); iRes(ivs) = intrinsics::select(val > zero, val, zero);
}
else
{
NGRAPH_CHECK(false, "Unsupported type for Relu");
}
}); });
rewriter.replaceOp(op, {result}); rewriter.replaceOp(op, {result});
...@@ -840,22 +830,10 @@ namespace ...@@ -840,22 +830,10 @@ namespace
ValueHandle val = iLHS(ivs); ValueHandle val = iLHS(ivs);
if (isa<NGNegOp>(op)) if (isa<NGNegOp>(op))
{ {
if (auto floatTy = elemTy.dyn_cast<FloatType>()) ValueHandle zero = createZeroConstant(elemTy);
{
ValueHandle zero = intrinsics::constant_float(llvm::APFloat(0.0f), floatTy);
iRes(ivs) = zero - val;
}
else if (auto intTy = elemTy.dyn_cast<IntegerType>())
{
ValueHandle zero = intrinsics::constant_int(0, intTy.getWidth());
iRes(ivs) = zero - val; iRes(ivs) = zero - val;
} }
else else
{
NGRAPH_CHECK(false, "Unsupported type for Negative");
}
}
else
{ {
NGRAPH_CHECK(false, "Unsupported op"); NGRAPH_CHECK(false, "Unsupported op");
} }
...@@ -1029,6 +1007,30 @@ namespace ...@@ -1029,6 +1007,30 @@ namespace
rewriter.replaceOp(op, result); rewriter.replaceOp(op, result);
} }
ValueHandle createZeroConstant(mlir::Type type)
{
if (auto floatTy = type.dyn_cast<FloatType>())
{
if (floatTy.isF32())
{
return intrinsics::constant_float(llvm::APFloat(0.0f), floatTy);
}
else if (floatTy.isF64())
{
return intrinsics::constant_float(llvm::APFloat(0.0), floatTy);
}
else
{
NGRAPH_UNREACHABLE("Unsupported floating-point precision");
}
}
else if (auto intTy = type.dyn_cast<IntegerType>())
{
return intrinsics::constant_int(0, intTy.getWidth());
}
NGRAPH_UNREACHABLE("Unsupported type");
}
} }
namespace mlir namespace mlir
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment