Repository navigation
Conversation
Leyukaka
left a comment
There was a problem hiding this comment.
Reviewed 325219d2 by diff only (not built or run). The rounding approach is correct; two test gaps.
Accuracy. I wrote a separate exhaustive check over every positive finite binary16 input (70-digit Decimal log2, RNE of both ends of the SM4 window: absolute 2^-21 on [0.5, 2], relative 2^-21 elsewhere):
- 73 inputs can round differently somewhere inside the window. They are exactly the keys of
log_f16_midpoints, and all 73 results equal the correctly rounded half. - With a correctly rounded f32 log2, no input double-rounds to the wrong half (unlike exp
0x11c5in #3220). - The special-value selects give NaN, +inf, negative values including -inf and ±0 the expected results from the modified bits; 1 gives +0 through the table.
1. The IR check does not exercise the table. The interpreter models Log as math.log2 rounded to f32 (tests/native_f16_alu_check.py:643). By reading, not run: my check shows a correctly rounded f32 log2 already rounds all 73 table inputs correctly, so if the for (const auto &entry : log_f16_midpoints) select loop is deleted from gfx1013_direct_compute.inl, model still passes (check_log_cpp_table only reads the array text) and ir should too. Only a GPU whose Log errs near a midpoint would catch it. One fix: for table inputs, move the interpreter's Log result across the midpoint, still inside the window. That is what the Rsqrt -0 model does for rsq.
2. The SDWA refusal control was deleted instead of moved. sdwa(0x57, WORD_0, PAD, WORD_0, unary=True) was the only unary op checked for unimplemented direct SDWA operand profile. Nothing else at this head checks that diagnostic for a unary op. Pointing it at an op that is still refused, such as v_sin_f16 (0x60), would keep it covered. The plain-form fixture already does this at :422.
Minor: the magnitude ugt 31744 select is redundant with the source ugt 31744 select. The source == 31744 select is redundant on a conforming host. By reading, deleting either one leaves every check passing.
CI. On PRs the Linux job runs native_f16_alu_check.py model. The Windows job runs ctest --preset pr, whose filter includes no native_f16_alu_* or native_sdwa_f16_* tests. The ir and _hardware results come only from the Windows receipt in the PR body.
Approving 325219d2; 1 and 2 can be follow-ups.
Fixes #3219
Refs #2935
Direct compute lowers the remaining binary16 VOP1 op from #3219,
v_log_f16(VOP10x57/ VOP30x1d7, plus SDWA), in the direct C++ compute path. PR #3220 loweredv_rcp_f16,v_sqrt_f16,v_exp_f16andv_rsq_f16; this completes the issue.Accuracy
The host Log (DXIL
dx.op.unary.f32, opcode 23) follows the SM4 log contract: absolute error at most 2^-21 on [0.5, 2], relative error at most 2^-21 elsewhere. That error can cross a binary16 rounding midpoint only for inputs whose exact log2 lies within that window of a midpoint, so the emitter selects the correctly rounded half for exactly those inputs. The newtests/f16_log_midpoints.pygenerator screens all 65,536 binary16 inputs with float64 and verifies the near-midpoint candidates against a 90-digit Decimal reference; it finds 73 such inputs and no exact midpoint ties. Every other positive finite input keeps the host Log result rounded by the existing integer nearest-even conversion. The model (tests/f16_packed_model.py) rounds log2 with the same 90-digit reference, and an exhaustive cross-check confirmed the Decimal model agrees with exact-Log-then-round for every positive finite input except the 73 table entries, where the table value is the correctly rounded one.Special cases are selected explicitly from the modified source bits: log2(1) is +0, log2(+-0) is -infinity, log2(+inf) is +infinity, and negative nonzero inputs (including -infinity) and NaNs give the canonical quiet NaN. VOP3
abs/neg, SDWAsrc0_sel/abs/neg/dst_selWORD_0/WORD_1 anddst_unusedUNUSED_PAD/UNUSED_PRESERVE are covered; the existing binary16 MODE contract (clamp/omod/DPP/high-halfop_selstay refused) is unchanged, and non-SDWA writes still preserve D[31:16].Tests
Linux (Python 3.12.3;
compile_dxilis Windows-only, so the IR dumper was built fromsrc/gfx1013_compute_native.cpp,src/gfx1013_isa.cpp,src/guest_shader_container.cpp,src/gfx1013_compute_ir.cppandtests/native_compute_ir_dump.cppwith g++ 13.3.0 and a local stub ofd3d12.handwrl/client.h, not in the tree):native_f16_alu model: 676 results match f32-then-round; a sub/subrev swap and a zeroed upper half are rejectednative_f16_alu IR: 676 results match the model; 43 refusals carry the named diagnosticnative_sdwa_f16 IR: 46 results and 15 refusalsf16_log_midpoints: 73 entries match the C++ tableform coverage checks passed,docs_links_checkpassed (687 links),bidi_controls_checkpassed/tmpcopies failed as required (corrupted table entry, corruptedlog2(1)model, corrupted -0 special case, corrupted table entry via IR, removedv_log_f16admission guard) and were restored;/tmpcleanednative_fma_f16,native_minmax_f16,native_dot2_f32_f16andnative_fract_f16IR checks still pass against the same dumper (STRIDE raised 512 to 1024 for the larger case table)native_f16_alu_hardwareandnative_sdwa_f16_hardwarewere not run on Linux. Windows verification (compile_dxil, native CTest) still pending.Windows Verification (325219d)