DSP tensor core: fp16 subnormal inputs are used at four times their value

Open
#510 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

@youzi27 is already working on this.

Since Nov 27, 2026.

  • #512 by @youzi27 — open

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
1/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Stale

Research direction

Read hw/rtl/tcu/dsp/VX_tcu_fedp_dsp.sv at fp16_to_fp32, where the issue identifies the exponent calculation for subnormal inputs. Reproduce with the provided sgemm_tcu input change in tests/regression/sgemm_tcu/main.cpp and the ci/blackbox.sh rtlsim command; completion is shown when all 2046 subnormal codes convert correctly and the run passes. Pull request #512 is already open for this issue.

Written by the indexing model from the issue text.

Description

Hi there,

With VX_CFG_TCU_TYPE_DSP, every fp16 subnormal operand of the tensor core is multiplied as if it were four times larger.

On master 2221ee286, give sgemm_tcu subnormals in row 0 of A, for example with this change to tests/regression/sgemm_tcu/main.cpp (after the loops that fill h_A and h_B):

  for (uint32_t k = 0; k < K; ++k)
    h_A[k] = uint16_t(1 + (k * 97) % 0x3ff);  // fp16 subnormals, ITYPE=fp16 only

and run

CONFIGS="-DVX_CFG_NUM_THREADS=8 -DVX_CFG_EXT_TCU_ENABLE -DVX_CFG_TCU_TYPE_DSP -DITYPE=fp16 -DOTYPE=fp32" ./ci/blackbox.sh --driver=rtlsim --app=sgemm_tcu

rtlsim reports Found 64 / 4096 errors!, all of row 0 of C, e.g. expected=0.000873, actual=0.003491. simx passes, and so do the TFR and DPI types on rtlsim with the same data. A single product shows it directly: A = 0x0001 (2^-24) times B = 1.0 gives 0x34800000 (2^-22) instead of 0x33800000, and 0x03ff gives 2.44e-4, which is larger than the smallest normal 0x0400 (6.10e-5, converted correctly).

The cause is fp16_to_fp32 in hw/rtl/tcu/dsp/VX_tcu_fedp_dsp.sv:60:

is_denormal ? 8'd127 - 8'd14 - {3'b0, leading_zeros} + 8'd1 :

A subnormal 0.f x 2^-14 equals 1.f' x 2^(-15 - leading_zeros), so its biased fp32 exponent is 112 - leading_zeros; the code gives 114 - leading_zeros. The mantissa bits are already right. bf16 and the integer formats do not use this converter. On an FPGA build the converted value is a normal fp32 number, so the flush-to-zero of the vendor floating-point cores does not hide it.

Suggested fix: is_denormal ? 8'd112 - {3'b0, leading_zeros} :. With it, all 2046 fp16 subnormal codes convert exactly and the run above passes. A PR follows.

Thanks!

Dominant language
Verilog
Stars
2.4k
Forks
563
Avg merge
1d 7h
Merged PRs (30d)
71

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from vortexgpgpu/vortex

All issues in vortexgpgpu/vortex

Similar issues

More Computer Graphics issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.