tools: record the approximate float instructions on an RDNA 2 card #469
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/469"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from brcly/TuxBox. Originally posted by JeffreyBytes on 2026-11-29T12:20:52Z.
Summary
Third piece of T5 (#412): what
v_rcp_f32,v_rcp_iflag_f32,v_rsq_f32,v_sqrt_f32,v_log_f32,v_exp_f32,v_sin_f32,v_cos_f32, their f16 forms andv_ldexp_f32return on an RDNA 2 card. The ISA document only gives these a precision bound, so the card is the only source for the exact bits, and they're everywhere in the recorded shaders (v_rcp_f32in 31,124,v_rsq_f32in 29,630,v_sqrt_f32in 26,727).Same route as #420 and #437: hand-written kernels through ROCm,
MODE[9:0]set withs_setreg_b32, all 1,024 MODE values, on an RX 6700 XT. Inputs are 9,280 fixed f32 words, every one of the 65,536 halves, 12,224 ldexp lanes, and dense sweeps of one or two binades per f32 instruction (8.4M or 16.8M values each).This time there's a second witness too.
vulkan_approx.pyruns the same inputs through RADV as GLSL compute shaders and only records when the driver's disassembly shows the instruction.What the card does
v_rcp_f32,v_rcp_iflag_f32,v_rsq_f32,v_sqrt_f32,v_log_f32,v_exp_f32,v_cos_f320x200v_sin_f320x230v_ldexp_f320x233v_mul_f32, exact0x200plus one or both of0x40/0x80, per instructionThe f16 forms are correctly rounded for every half, except 14 sine and 4 cosine halves that sit almost exactly on a midpoint.
The f32 forms are not correctly rounded and I couldn't find a model that reproduces them:
v_rcp_f32v_rsq_f32v_sqrt_f32v_log_f32v_exp_f32v_sin_f32,v_cos_f32Every rcp/rsq/sqrt/log/exp result is one of the two floats either side of the exact value, never further. rsq isn't rcp of sqrt, sqrt isn't x times rsq, and a per-piece quadratic doesn't fit rcp. So
rdna2_float.approx()gives the card's word only where it's fixed (special cases, exact results, f16) andwithin()holds the rest to the bound. Both hold for every recorded word. The receipt keeps a hash of each sweep rather than the words.Other things worth knowing:
v_rcp_iflag_f32gavev_rcp_f32's word on every input, sweeps included.0xffc00000. Full table in the doc.The Vulkan witness
For rcp, rsq, sqrt, log, exp (f32 and f16) and ldexp the driver emits the instruction alone, and the Vulkan words equal the ROCm words on every input and sweep, under the MODE each SPIR-V float mode maps to (
0xc0default,0xf0denorm-preserve,0x00denorm-flush).Sine and cosine can't be compared directly. RADV multiplies the angle by 1/(2π) first, so the shader runs
v_mul_f32thenv_sin_f32. The test feeds the model the correctly rounded product; every f16 word is reproduced and every f32 word is inside the bound.Under denorm-preserve RADV wraps rcp, rsq, sqrt and log in a scale-by-2^24 sequence for denormal sources. The test models that sequence. One of them looks like a driver bug, not a hardware one: for
log2the undo step multiplies by -24 where it should subtract 24, solog2(2^-149)comes back as 3000.0. I haven't looked for a Mesa report yet.I also ran
vulkan_approx.pyon a Radeon 890M (RDNA 3.5) out of curiosity about a newer generation. Every word matched the RX 6700 XT, sweeps included. That receipt isn't in this PR since the card isn't RDNA 2; I can add it if it's wanted.Against the translator and the ALU check
Nothing in the translator or the check changes here. The doc has a table of what
vector.rsemits for each instruction and where an exact IEEE host has to differ from the card. That part is from reading the code, not from running the translator. The ones that aren't just "one unit":sin((x - round(x)) * 6.28318530718)gives sin(-0) = +0 where the card gives -0, a tiny nonzero value at half and quarter turns where the card gives exactly +0, and a slope six units above the card's for tiny angles.v_exp_f16isexp2in f32 then rounded to f16, which rounds twice: exp(0x11c5) gives0x3c00, the card0x3c01.ray/alu.rs) still writessin(x * 6.283185307179586f)without dropping whole turns, which the main translator fixed in2a22586.For
check_basic_alu_gpu.py: its 1-unit bounds for rcp, rsq and sqrt are as tight as they can be. The 4-unit bounds for log and exp and the 2^-20 trig bound are looser than the card needs, which the comment there says is for the hosts' own functions. Its inputs have no denormals, so it never meets the cases where its models and the card disagree.What's still open
v_rcp_legacy_f32,v_rsq_clamp_f32and so on), so those aren't measured.v_rcp_iflag_f32has no GLSL route, so it has no Vulkan witness.Layout
tools/native_rdna2/approx.hip,approx_inputs.py,check_approx.py;rdna2_float.approx()andwithin()tools/native_rdna2/vulkan_approx.py;vulkan_float.pygets aCard.run_rawsplit so both share the runnerevidence/native-rdna2-approx.json(197 KB),evidence/native-rdna2-vulkan-approx.json(697 KB)tests/test_native_rdna2_approx.pyandtests/test_native_rdna2_vulkan_approx.py, no GPU. The first reproduces the f16 tables under the console's MODE by default;--exhaustivedoes every MODE value in about a minutedocs/CONSOLE_REFERENCE.md, the T5 row indocs/ROADMAP.md, the README intools/native_rdna2Tested
No Lanes scenario and no NVIDIA run, for the same reasons as #420 and #437: this runs native instructions outside TuxBox's providers, only on an RDNA 2 card, and changes no provider, translator or shared check code.
GPU, driver and backend: AMD Radeon RX 6700 XT (
1002:73df, gfx1031), Linux 7.3.6, ROCm under/opt/rocmwithHSA_OVERRIDE_GFX_VERSION=10.3.0(set by the script); RADV, Mesa 26.3.1 for the Vulkan route. No Proton involved.Commands run and their results:
Checks
docs/RESULTS.mdanddocs/progress.svgdon't change; the new receipts aren't a type those views count.