Repository navigation
rdna2spirv: round f16 typed-buffer stores toward zero and saturate at 65504 (SHADER-395) - #2262
Closed
Youssefrah16 wants to merge 1 commit into
Closed
Youssefrah16 wants to merge 1 commit into
Youssefrah16 wants to merge 1 commit into
Conversation
… 65504 (SHADER-395)
Author
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.
Fix
SHADER-395("f16 typed-buffer stores round toward zero on RDNA2 and gfx1150, and saturate at 65504, where the translator rounds to nearest even and overflows to infinity: switch the f16 store narrowing to the measured rule, keeping d16 loads' rule separate"), claimed in #2078 (#issuecomment-7082017955).Summary
tools/rdna2spirv.py(Gen.encode_format, line 1304): Switchkind == "f16"typed-buffer store format narrowing (16_FLOAT,16_16_FLOAT,16_16_16_16_FLOATused bybuffer_store_format_*andtbuffer_store_format_*) fromself.f16_bits(self.tof(fcomps[c]))(round-to-nearest-even,|x| >= 65520 -> ±inf) toself.f16_bits(self.tof(fcomps[c]), rtz=True)(round toward zero, finite overflow clamped to±65504(0x7bff/0xfbff),±inf -> ±0x7c00, quiet NaNs and f16 subnormals preserved).d16loads kept separate:buffer_load_format_d16_*,tbuffer_load_format_d16_*, andimage_* ... d16continue usingGen.f16_bits(..., rtz=False)/Gen.d16_norm_f16.tests/test_translate.py: Updatetest_encode_format_f16_uses_f16_bits_rtzto cover odd ties (0x3f803000 -> 0x3c01, not RTE0x3c02), finite overflow saturation (+65520.0,-65536.0,±FLT_MAX -> 0x7bff / 0xfbff),+inf -> 0x7c00, and subnormal underflow (0x337fffff -> 0x0000).docs/design.md: Document the hardware-measured16_FLOATtyped-buffer store RTZ +±65504saturation rule in thed16 and f16 format narrowingcontract row.Native RDNA2 Hardware Measurement (
gfx1035)In addition to the
gfx1036(@CLHelper) andgfx1150(@AlxcBTW) measurements reported in #1902, we ran 19f32inputs across both MUBUFbuffer_store_format_xand MTBUFtbuffer_store_format_x(format:[BUF_FMT_16_FLOAT], format13) in bothwave32andwave64(76 native RDNA2 kernels) on an AMD Radeon 680M (gfx1035) viatools/hw_oraclewith the destination dword pre-filled to0xdead0000:f32gfx1035MUBUF & MTBUF (wave32&wave64)Gen.f16_bits(..., rtz=True)rtz=False0x3f8010001 + 2^-11(even tie)0xdead3c000x3c000x3c000x3f8030001 + 3·2^-11(odd tie)0xdead3c010x3c010x3c02(diverged)0x3f803fff0x3c020xdead3c010x3c010x3c02(diverged)0xbf803000-(1 + 3·2^-11)(neg odd tie)0xdeadbc010xbc010xbc02(diverged)0x477fe00065504.0(max f16)0xdead7bff0x7bff0x7bff0x477ff00065520.0(tie above 65504)0xdead7bff0x7bff0x7c00(diverged)0x4780000065536.0(finite overflow)0xdead7bff0x7bff0x7c00(diverged)0xc7800000-65536.0(neg finite overflow)0xdeadfbff0xfbff0xfc00(diverged)0x7f7fffff+FLT_MAX0xdead7bff0x7bff0x7c00(diverged)0xff7fffff-FLT_MAX0xdeadfbff0xfbff0xfc00(diverged)0x7f800000+inf0xdead7c000x7c000x7c000xff800000-inf0xdeadfc000xfc000xfc000x7fc00000+qNaN0xdead7e000x7e000x7e000xffc00000-qNaN0xdeadfe000xfe000xfe000x7f800001+sNaN0xdead7c010x7e00(qNaN)0x7e00(qNaN)0x380000002^-15(f16 subnormal)0xdead02000x02000x02000x338000002^-24(min f16 subnormal)0xdead00010x00010x00010x337fffff2^-240xdead00000x00000x0001(diverged)0x80000000-0.00xdead80000x80000x8000Testing (AI-assisted)
python -m pytest tests/test_translate.py -k "encode_format_f16 or buffer_format_f16" -v(7/7 passed)python -I tests/test_d16_pack.py(3/3 passed)python -I tests/semantic/test_tbuffer_store.py(4/4 passed)python -I tests/semantic/test_buffer_load_format.py(22/22 passed)scripts/run_gpu_tests.py --filter storeon Windows 11:595.71.0)gfx1035, RDNA2) (driver2.0.317/ HIP60443483)