-
Notifications
You must be signed in to change notification settings - Fork 15.4k
AMDGPU: Add round-to-odd rounding during f64 to bf16 conversion #133995
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
Changes from 1 commit
4bd1058
56edadf
b9bdfea
c74dd30
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -911,8 +911,7 @@ SITargetLowering::SITargetLowering(const TargetMachine &TM, | |
| setOperationAction(ISD::MUL, MVT::i1, Promote); | ||
|
|
||
| if (Subtarget->hasBF16ConversionInsts()) { | ||
| setOperationAction(ISD::FP_ROUND, MVT::v2bf16, Legal); | ||
| setOperationAction(ISD::FP_ROUND, MVT::bf16, Legal); | ||
| setOperationAction(ISD::FP_ROUND, {MVT::bf16, MVT::v2bf16}, Custom); | ||
| setOperationAction(ISD::BUILD_VECTOR, MVT::v2bf16, Legal); | ||
| } | ||
|
|
||
|
|
@@ -6888,23 +6887,33 @@ SDValue SITargetLowering::getFPExtOrFPRound(SelectionDAG &DAG, SDValue Op, | |
| } | ||
|
|
||
| SDValue SITargetLowering::lowerFP_ROUND(SDValue Op, SelectionDAG &DAG) const { | ||
| assert(Op.getValueType() == MVT::f16 && | ||
| "Do not know how to custom lower FP_ROUND for non-f16 type"); | ||
|
|
||
| SDValue Src = Op.getOperand(0); | ||
| EVT SrcVT = Src.getValueType(); | ||
| if (SrcVT != MVT::f64) | ||
| return Op; | ||
|
|
||
| // TODO: Handle strictfp | ||
| if (Op.getOpcode() != ISD::FP_ROUND) | ||
| if (SrcVT.getScalarType() != MVT::f64) | ||
| return Op; | ||
|
|
||
| EVT DstVT = Op.getValueType(); | ||
| SDLoc DL(Op); | ||
| if (DstVT == MVT::f16) { | ||
| // TODO: Handle strictfp | ||
| if (Op.getOpcode() != ISD::FP_ROUND) | ||
| return Op; | ||
|
|
||
| SDValue FpToFp16 = DAG.getNode(ISD::FP_TO_FP16, DL, MVT::i32, Src); | ||
| SDValue Trunc = DAG.getNode(ISD::TRUNCATE, DL, MVT::i16, FpToFp16); | ||
| return DAG.getNode(ISD::BITCAST, DL, MVT::f16, Trunc); | ||
| } | ||
|
|
||
| assert (DstVT.getScalarType() == MVT::bf16 && | ||
| "custom lower FP_ROUND for f16 or bf16"); | ||
| assert (Subtarget->hasBF16ConversionInsts() && "f32 -> bf16 is legal"); | ||
|
|
||
| SDValue FpToFp16 = DAG.getNode(ISD::FP_TO_FP16, DL, MVT::i32, Src); | ||
| SDValue Trunc = DAG.getNode(ISD::TRUNCATE, DL, MVT::i16, FpToFp16); | ||
| return DAG.getNode(ISD::BITCAST, DL, MVT::f16, Trunc); | ||
| // Round-inexact-to-odd f64 to f32, then do the final rounding using the | ||
| // hardware f32 -> bf16 instruction. | ||
| EVT F32VT = SrcVT.isVector() ? SrcVT.changeVectorElementType(MVT::f32) : | ||
| MVT::f32; | ||
| SDValue Rod = expandRoundInexactToOdd(F32VT, Src, DL, DAG); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need to custom lower here at all? This seems like the default action. Can you just return the original node?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No. If we return the original node, it will generate the two conversions and have the double rounding issue.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Then the default expansion is buggy? We shouldn't have unique bf16 legalization needs
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The default expansion for bf16 is not optimal at least. I can take a look in a following patch. |
||
| return getFPExtOrFPRound(DAG, Rod, DL, DstVT); | ||
changpeng marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| SDValue SITargetLowering::lowerFMINNUM_FMAXNUM(SDValue Op, | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.