Skip to content

§ 7.9. Experiments

Campaign 2 closes the chapter. The questions, fixed before any run:

  1. Cost. What does a float multiply-add cost in gates and delay against Part I's int8 one? Does fusing a multiply and an add pay off? How does the 4 × 4 × 4 tensor core compare with the 4 × 4 systolic array per gate?
  2. Accuracy. What do the MNIST networks of § 6.5 lose in FP16 with FP32 sums, as a tensor core computes, and in int8, against FP32? Does Volta's truncating sum matter?
  3. Tensor-core numerics. How far from the exact result are long dot products chained through Volta's 4-element steps, against IEEE FMAs in FP32 and in FP16?
  4. Floats on the CPU. How much faster is the RV32IMF core of 7.7 than software floats on the RV32IM core?

Nothing was tuned after seeing a result; each run was made once (the simulator and the host references are deterministic).

Setup

Item Setting
Hardware The units of 7.2–7.8, all gates (float_experiment --cost); Part I's MacCell and SystolicArray<4> (§ 6.1–6.2)
Timing The unit profile (every gate one tick), as campaign 1
Networks Part I's trained MNIST MLP and CNN (§ 6.5), the same float model for every arithmetic, no retuning
Numerics float_experiment --numerics: 2,000 trials per case, seed 20261113
CPU programs accelerator-machine-cpu (§ 6.5) with SRAM, its default bus and array multiplier, Compact; the RV32IM core (software floats, libgcc) or the RV32IMF core (7.7)
Tool tools/float/FloatExperiment.cpp (float_experiment), with the bit-exact reference of 7.1

1. Cost

Gates are the leaf gates of the all-gates build. A combinational part's delay is its latest output settling after an input change; a clocked part's is the period the safe-clock analyzer certifies with the part between registers (the tensor core's with its dot-product units on their delay tables, which are proven on their gates; timing its 381,786 gates at once takes too long). "MACs per tick per million gates" divides the multiply-adds per edge by that delay and by the gates.

Part Gates Delay or period (ticks) MACs per edge MACs per tick per 10⁶ gates
MacCell (int8 × int8 + int32, registered) 2,184 46 1 9.95
FloatAdder<FP16> 2,516 105
FloatMultiplier<FP16> 3,524 97
FloatFma<FP16> 9,880 188 1 0.54
FloatFmaPipelined<FP16> (6 edges) 16,696 78 1 0.77
FloatAdder<FP32> 5,516 123
FloatMultiplier<FP32> 9,613 111
FloatFma<FP32> 19,470 214 1 0.24
FloatFmaPipelined<FP32> (4 edges) 28,226 90 1 0.39
DotProductUnit<4> (FP16, Volta) 21,837 249 4 0.74
SystolicArray<4> (int8) 40,008 46 16 8.69
TensorCore<4,4,4> 381,786 262 64 0.64
FloatExecuteUnit 57,948 92
FloatRegisterFile 33,757
RV32IMFiveStageCore (array multiplier) 79,654
RV32IMFFiveStageCore (array multiplier) 174,639
  • Float against int8. An int8 multiply-add takes a fourth of an FP16 FMA's gates and a ninth of an FP32 FMA's, and is four to five times faster. Per gate and tick, the int8 cell does 13 times the work of the FP16 dot-product unit and 26 times that of the pipelined FP32 FMA. This is why inference accelerators quantize to int8 (chapter 6).
  • Fusing. The FP32 FMA has 29 % more gates than an adder and a multiplier together (19,470 against 15,129) and is 9 % faster than the two in series (214 against 234 ticks), with one rounding instead of two; at FP16 it has 64 % more gates and is 7 % faster. A unit that must both add and multiply, as an RV32F or GPU lane does, is cheaper as one FMA than as two units side by side.
  • Pipelining. With Volta's latencies (Jia et al. 2018: FFMA 4 cycles, HFMA2 6) the FMAs clock 2.4 times faster for 45 % (FP32) and 69 % (FP16) more gates. The stages are not balanced: 214 ticks over four stages would allow 54 per stage, and the slowest takes 90. At the CPU's certified 160-tick clock the pipelined FMA fits one cycle per stage; the combinational one would not fit at all.
  • Tensor core against systolic array. 9.5 times the gates for 4 times the multiply-adds per edge, at a 5.7 times longer period: per gate and tick the int8 array does 13.6 times as much. The tensor core's period is one dot-product unit's delay plus registers; at the CPU's clock it would need a second stage. Volta's HMMA latency is not published (Jia et al. give none), so it cannot be compared.
  • RV32F more than doubles the core: 57,948 gates of execute unit and 33,757 of float registers (32 words, three read ports for the fused operations).

2. Accuracy

The full 10,000-image MNIST test set through the host's bit-exact references: FP32 (each multiply and add rounded); FP16 inputs and weights with FP32 sums through Volta's dot product, four products a step, as kernels chain tensor-core steps; the same FP16 values with exact products and one IEEE FP32 addition per term; and Part I's int8 networks quantized from the same model.

Network FP32 FP16, Volta sums FP16, IEEE sums int8 (Part I)
MLP 96.87 % 96.87 % 96.87 % 96.79 %
CNN 97.39 % 97.39 % 97.39 % 97.34 %

Both FP16 arithmetics give FP32's answer on every one of the 10,000 images for both networks: neither FP16's shorter significand nor Volta's truncating sums move one prediction. int8 loses 0.08 and 0.05 points. For inference on this task, FP16 with FP32 sums is as good as FP32, and int8 nearly so.

To show the host model is the hardware, the first 16 hidden-unit sums of the MLP's first image (784 terms each) ran through the simulated DotProductUnit<4> (196 chained steps each, Compact) and FloatFma<FP32> (12,544 steps): every result equals the host's bit for bit. (The plan named 2–4 whole images; one image's 16 sums were run, as each simulated step takes milliseconds.)

3. Tensor-core numerics

Dot products of FP16 values of length 4 to 256, the sum carried in FP32: through Volta's 4-element steps (the model of 7.8), through an FP32 IEEE FMA chain (one product per step, round to nearest even), and in FP16 throughout (an FP16 FMA chain). Relative error against the exact sum, mean and largest of 2,000 trials:

Length Values Volta mean Volta max FP32 FMA mean FP32 FMA max FP16 mean FP16 max
4 uniform [0, 1) 2.7e-8 1.4e-7 1.8e-8 1.2e-7 2.4e-4 9.1e-4
4 normal 5.0e-8 1.1e-5 2.9e-8 5.9e-6 6.0e-4 0.10
4 wide exponents 6.9e-8 2.1e-6 3.4e-8 2.1e-6 4.1e-4 0.11
16 uniform 1.4e-7 4.0e-7 4.5e-8 2.1e-7 4.0e-4 2.0e-3
16 normal 2.6e-7 8.0e-5 1.4e-7 1.9e-5 1.5e-3 0.15
16 wide exponents 7.2e-7 8.7e-4 5.9e-7 8.7e-4 2.7e-3 3.3
64 uniform 9.1e-7 1.5e-6 8.9e-8 4.8e-7 7.5e-4 3.8e-3
64 normal 7.0e-7 9.7e-5 6.9e-7 4.5e-4 5.6e-3 3.5
64 wide exponents 8.1e-7 3.1e-4 3.5e-7 1.1e-4 2.9e-3 0.75
256 uniform 4.6e-6 5.8e-6 1.8e-7 8.6e-7 1.5e-3 6.4e-3
256 normal 5.7e-6 8.3e-3 4.5e-6 6.4e-3 1.7e-2 19
256 wide exponents 2.3e-6 2.3e-3 6.1e-7 6.8e-5 4.3e-3 0.77
any near-cancelling pairs 0 0 0 0 0.47–1.0 47–510
  • With values of one sign, Volta's error grows about linearly with the length (2.7 × 10⁻⁸ at 4, 4.6 × 10⁻⁶ at 256), the IEEE chain's slowly (1.8 × 10⁻⁸ to 1.8 × 10⁻⁷): truncating always errs the same way, so its errors add up instead of cancelling. At 256 the tensor core is 26 times less accurate on average.
  • With mixed signs (normal values) the two come close (5.7 against 4.5 × 10⁻⁶ at 256): truncation errors of both signs partly cancel.
  • FP16 throughout is a thousand to ten thousand times worse and loses near-cancelling sums entirely; FP32 sums are what make FP16 inputs usable.
  • The realism check: the model reproduces every one of the eleven V100 probes of Fasi et al. (2021) with the outputs they report (FloatReferenceTest, 7.8).

The accuracy results above show what this means in practice: the tensor core's larger error, at these lengths (784 terms at most), changes no prediction.

4. Floats on the CPU

The CPU alone (accelerator-machine-cpu, SRAM, Compact) runs the same C programs built twice: for RV32IM, where every float operation is a call into software (libgcc's __addsf3, __mulsf3, __divsf3; the square root a bit-by-bit integer routine, since libgcc has none), and for the RV32IMF core of 7.7, where it is one instruction. Both builds use -ffp-contract=off, so they do the same rounded operations, and every result equals the host's run of the same kernels bit for bit.

Program RV32IM, software floats RV32IMF Fewer cycles
Divide and square root: normalize 256 vectors 1,546,481 51,491 30×
Divide and square root: distances of 48 points 5,119,400 116,228 44×
Whole fdivsqrt program 7,244,834 cycles, 2,026,203 instructions 245,480 cycles, 38,824 instructions 29.5×
Float MLP, one image (784 → 64 → 10) 26,559,722 1,985,052 13.4×
Whole fmlp program 26,906,682 cycles, 6,829,432 instructions 2,044,720 cycles, 365,598 instructions 13.2×
Matrix multiply 4 × 32 → 16, 8 × 64 → 32, 16 × 64 → 64 1,468,379; 11,711,925; 46,821,911 82,084; 647,280; 2,588,296 18× each
Whole fmatmul program 65,509,052 cycles, 17,563,177 instructions 3,890,870 cycles, 748,246 instructions 16.8×

With hardware floats the normalize kernel takes 51,491 cycles for 256 vectors, about 200 cycles each, most of it its one square root and three divides on the unit that makes one bit per edge (27 edges each, 7.6); a distance takes about 100 cycles (one square root and a few 4-edge FMA operations). In software a vector takes about 6,000 cycles and a distance about 4,500: each square root is a loop of about 30 integer steps, each divide a library call of dozens of instructions.

The MLP's 50,816 multiply-adds take about 520 cycles each in software (two library calls) and about 39 with RV32F; the matrix multiplies take about 715 in software and 39.5–40 with RV32F, at every size. (Why the software matrix multiply costs more per multiply-add than the software MLP was not analyzed; the two loops differ in their indexing and in the values the library calls see.) Set beside campaign 1 on the same machine: the int8 MLP took 1,636,072 cycles on the CPU alone, so the RV32F MLP is 1.2 times slower than the int8 one in software, and the 16 × 16 int8 accelerator (117,321 cycles) is 17 times faster than RV32F. A likely reason RV32F does not beat integer code here (not measured separately): each float multiply and add waits for the 4-edge FMA unit (-ffp-contract=off keeps them two dependent operations), while the int8 loop uses the one-edge array multiplier.

Reproducing a run

build-accel/float_experiment --cost
build-accel/float_experiment --accuracy MNIST_DIR --images 10000 --bench 16
build-accel/float_experiment --numerics --trials 2000
build-accel/float_experiment --program fdivsqrt --core hard

Each prints its results as JSON. --accuracy reads the MNIST test files (gunzipped) from MNIST_DIR; the guest programs are built by tools/accelerator/build-guests.py.

Limits

  • Cost is gates and delay in the unit profile (every gate one tick), not area or energy; the int8 and float parts are compared on the same terms, not against a real process.
  • Volta's HMMA latency is not published, so the tensor core's latency is not compared with a measurement.
  • The accuracy figures are for two small networks on MNIST; harder tasks can show differences where these show none.
  • The tensor-core numerics use host references of the hardware (checked bit for bit against the simulated unit on a test bench), not runs of the simulated tensor core itself, which would take days.

Source: experiment tool, float kernels, guest programs, reference.