Skip to content

Support for various BF16 and FP8 extensions - #81

Open
zanderdenning wants to merge 5 commits into
ucb-bar:masterfrom
Rakanic:bf16_fp8
Open

Support for various BF16 and FP8 extensions#81
zanderdenning wants to merge 5 commits into
ucb-bar:masterfrom
Rakanic:bf16_fp8

Conversation

@zanderdenning

Copy link
Copy Markdown
Contributor

Depends on chipsalliance/rocket-chip#3782

This PR adds support for vectorized BF16 and OFP8 to Saturn. These features are disabled by default and enabled with the useMxFPFMA and useMxConversion parameters. Below is a full description of which features from each extension are supported.

  • Zvfbfmin:
    • vfwcvtbf16.f.f.w and vfncvtbf16.f.f.w to convert between BF16 and FP32 (however, this is redundant with instructions in Zvfbfa)
    • I believe this is the entire extension
  • Zvfofp8min:
    • vfwcvtbf16.f.f.w and vfncvtbf16.f.f.w to convert between OFP8 and BF16
    • vfncvtbf16.sat.f.f.w for saturating narrowing from BF16 to OFP8
    • Missing the instructions to convert directly between FP32 and OFP8
  • Zvfbfwma:
    • Missing vfwmaccbf16.vv for BF16 to FP32 MACC (however, this is redundant with instructions in Zvfbfa)
  • Zvfbfa:
    • All FMA operations are supported for BF16 by using altfmt=1 and SEW=16
    • Missing BF16 comparison operations
  • Not technically part of any extension but we support it:
    • All FMA operations are supported for both OFP8 formats by using SEW=8
  • Nominally a lot of these vector extensions depend on their scalar equivalents. However, in practice, this dependency doesn't actually matter. Rocket's FPU doesn't currently support any of these.

@jerryz123 jerryz123 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! Just a few comments

Comment thread src/main/scala/exu/fp/FPFMAPipe.scala Outdated
FWMSAC.VV, FWMSAC.VF, FWNMSAC.VV, FWNMSAC.VF,
FREDOSUM.VV, FREDUSUM.VV, FWREDOSUM.VV, FWREDUSUM.VV
).map(_.pipelined(depth)).map(_.restrictSEW(1,2,3)).flatten
).map(_.pipelined(depth)).map(_.restrictSEW(0,1,2,3)).flatten

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think technically, this should be controlled by a flag

Comment thread src/main/scala/common/Parameters.scala Outdated

def vExts =
(if (useMxConversion) Seq("zvfofp8min", "zfbfmin", "zvfbfmin", "zvfbfa") else Seq()) ++
(if (useMxFPFMA) Seq() else Seq())

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this right?

Comment thread src/main/scala/insns/Instructions.scala Outdated
object FCVT_SGL extends VectorInstruction { val props = Seq(F6(OPFFunct6.funary0), F3(VectorConsts.OPFVV), RS1(BitPat("b00???")), FPAdd.N, FPMul.N) }
object FCVT_WID extends VectorInstruction { val props = Seq(F6(OPFFunct6.funary0), F3(VectorConsts.OPFVV), RS1(BitPat("b01???")), Wide2VD.Y, FPAdd.N, FPMul.N) }
object FCVT_NRW extends VectorInstruction { val props = Seq(F6(OPFFunct6.funary0), F3(VectorConsts.OPFVV), RS1(BitPat("b10???")), Wide2VD.N, Wide2VS2.Y, FPAdd.N, FPMul.N) }
object FCVT_NRW extends VectorInstruction { val props = Seq(F6(OPFFunct6.funary0), F3(VectorConsts.OPFVV), RS1(BitPat("b1????")), Wide2VD.N, Wide2VS2.Y, FPAdd.N, FPMul.N) }

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should create 2 variants of this instruction, b11??? and b10???, and add the form based on extension support

@zanderdenning

Copy link
Copy Markdown
Contributor Author

Good catches, these slipped through the change from experimentation to production. This commit should address those.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants