Repository navigation
Conversation
cvt_f32_to_custom handled E4M3 like an IEEE format with an infinity: every value from 248 up became 0x78, which the decoder (and the tensor datapaths) read as 256, and NaN became 0x7c, which decodes as 384. The codes 0x79..0x7e (288..448) could not be produced at all. Exponent 1111 now holds normal values, values beyond 448 and infinities saturate to +-448, and NaN encodes as S.1111.111. This covers rv_ftoe4m3_s and the mxfp8 quantiser rv_ftomxfp8_s. Add tests/unittest/fp8_cvt: round trip of all E4M3 and E5M2 codes plus E4M3 rounding, saturation and NaN cases.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #493.
Summary
cvt_f32_to_customnow has the E4M3 case thatcvt_custom_to_f32already has: exponent 1111 holds normal values up to 448, NaN encodes asS.1111.111, and values whose rounded magnitude would exceed 448, as well as infinities, saturate to ±448 (OCP SAT; finite overflow still raises OF and NX). Other formats are unchanged. This fixesrv_ftoe4m3_sand the mxfp8 quantiserrv_ftomxfp8_s. No RTL produces E4M3, so saturation follows the OCP MX quantisation rule; NaN on overflow (OVF) would be a two-line change.The new
tests/unittest/fp8_cvtchecks that all 256 E4M3 and E5M2 codes survive decode and encode, plus rounding near 448, saturation, NaN and two mxfp8 values. Subnormal results are still rounded twice (to four significant bits, then to the subnormal grid), on master too; this change does not touch that path.Impact and evidence
Impact class: R2
Contracts touched: none
fp8_cvt: 27 failures on master, passes here; the rest ofmake -C tests/unittest runpasses; the 37 CI cases whose data go through this encoder (fp8sgemm_tcu, mxfp8/nvfp4 MX tests) at XLEN 32 and 64: same verdicts and the same instruction and cycle counts as master, though some mxfp8 inputs change (up to 35 of 8192 codes); a host check over all 2^32 fp32 inputs (RNE) gives the nearest code for every input of magnitude 2^-6 or more and every NaNmodel_paritymodel_parity-mxfp8,-mxfp8-lsu-lanes: pass, as on masterperf_gateperf_gate-mxfp8: same counts as master; both miss the baseline with my local toolchain (v3.0.1, not the pinned v3.0.2)logic_gatefpga_gate/asic_gate)known_issue:, wider tolerance, smaller args, removed case) without a root-cause plan.