betaFeedback

WorksComputer Science

Decode Late, Multiply Once: Rethinking the Dot Product for Quantized Weights

Abstract

Large neural networks are increasingly deployed with 1-4 bit weights and 16- or 32-bit activations, yet their dot products still use one multiplier per element. We show that a length-n dot product with k-bit weight codes can be computed with n+2^k additions and at most 2^k decodes and 2^k multiplications. Each weight code is used directly as an address offset that selects one of 2^k accumulators; each activation is added into the selected accumulator; and the accumulated sums are decoded and multiplied only once, at the end, in a fused decode-and-multiply step. The decoded weight vector is never formed. The refactoring is exact for integer arithmetic, works with integer or floating-point operands and with arbitrary, including nonlinear, decoders, and extends to group-wise scales and to matrix and tensor products. The multiplier count falls by n/2^k, while total arithmetic energy improves by a smaller, bounded factor that we quantify with a cost model. We describe a scatter-accumulate processing element (SA-PE) that replaces the MAC unit in a weight-stationary systolic array, with a load/stream/reduce/drain schedule in which a small, time-shareable multiplier runs only 2^k times per tile. Because decoded weights are not stored, local weight memory shrinks by up to w_d/k for w_d-bit decoded weights. An RTL implementation synthesized for FPGA and compared with a matched MAC array shows that an unshared SA-PE is larger than a MAC PE, and that the saving appears when the reduction multiplier is shared across PEs. Software models confirm exact integer equivalence and floating-point error no worse than the conventional pipeline. We do not claim the underlying identity is new, and we discuss related work on weight sharing and lookup-based kernels.

Introduction

A recent development in AI is the use of low-resolution (1–4 bit) weights in very large neural networks, such as the foundation models behind modern LLMs [1, 8]. The inference throughput of these models is generally limited by the rate at which weights can be loaded from memory, so low-resolution weights allow more weights to be delivered in a given time at fixed memory bandwidth.

The resulting workload is one in which a processing unit mostly multiplies a low-resolution weight (say 1–4 bits) by a high-resolution activation or other data variable (say 16 or 32 bits). These calculations normally take the form of large matrix or tensor multiplications, at the core of which are dot products: two vectors, which may be rows or columns of a matrix or tensor, are combined to produce a scalar. When optimizing matrix computation in a CPU, GPU or NPU, the best results require the minimum movement of data, the minimum use of local memory, and the minimum number of computations. Multipliers are the most expensive of the arithmetic units involved [2], yet in a low-bit-weight setting most of their capability is wasted: a kk-bit weight takes only 2k2^k distinct values, so a long dot product multiplies the activations by the same few numbers over and over.

This paper describes a way of computing such dot products that exploits this repetition. The method works whether the weights are integer or floating-point encoded and whether the data variables are integer or floating-point encoded. A conventional dot product between a weight vector of resolution kk bits and a data vector of arbitrary resolution, each of length nn, requires nn multiply-accumulate (MAC) operations, i.e. nn multiplications and nn additions. The new method decodes late: activations are summed by code first, and decoding and multiplication are fused into one step per bin, so it requires 2k2^k decodes, 2k2^k multiplications and n+2kn + 2^k additions (the 2k2^k products must still be summed). Since kk is usually 1–4 and nn may exceed 1000, the number of multiplications falls by n/2kn/2^k, which can exceed 100×100\times; there is a gain for any computation in which 2k≪n2^k \ll n. Because the nn additions remain, the achievable energy gain is bounded by the cost ratio of a decode–multiply–accumulate to a plain accumulate; we quantify this in § 4.

Relation to prior work and contributions. Related ideas exist. Weight-shared CNN accelerators bin inputs by weight index and multiply the bins by shared weights [3, 4]; UCNN factorizes dot products over repeated weights [5]; lookup-table kernels such as LUT-GEMM and T-MAC replace multiplications in low-bit LLM inference [6, 7]; and ternary models such as BitNet b1.58 reduce multiplication to addition by construction [8]. We do not claim the identity is new. Our contributions are (i) extending it to floating-point operands and group-scaled decoders, stated for matrix and tensor products, and, as we read [5], without the weight sorting and index metadata that UCNN uses to exploit repeated weights, and beyond the fixed-point CNN setting of [3, 4] (§ 3 to § 6); (ii) integrating a scatter-accumulate processing element (SA-PE) as a drop-in node of an otherwise unchanged weight-stationary systolic array, with its load/stream/reduce/drain schedule, time-shared reduction engine, and closed-form sizing and local-memory models (§ 7 and § 8); and (iii) validation of exactness, floating-point rounding error and operation counts, plus RTL sizing against a matched MAC array (§ 9 and § 10).

Background and Notation

The dot product of two vectors a\mathbf{a} and b\mathbf{b} of length nn is

a⋅b=∑i=1naibi=a1b1+a2b2+⋯+anbn.(1)\mathbf{a}\cdot\mathbf{b} = \sum_{i=1}^{n} a_i b_i = a_1b_1 + a_2b_2 + \cdots+ a_nb_n. \tag*{(1)}

When the elements of a\mathbf{a} have a low resolution of kk bits, they take only 2k2^k distinct values, which we write as integer weight codes ai∈{0,1,…,2k−1}a_i \in\{0,1,\ldots,2^k-1\}. Many AI algorithms exploit quantized weights by scaling them after they are loaded, so that each code is mapped to a more precise value; the mapping may be linear (scale and offset), a nonlinear function, or an arbitrary table. We represent it by a decoding vector c=(c0,…,c2k−1)\mathbf{c} = (c_0,\ldots,c_{2^k-1}) of precise coefficients: a code vv is replaced by cvc_v. The mapping may be computed as cv=f(v)c_v = f(v) for a linear or nonlinear decoding function ff, or stored as a lookup table addressed by the code. Any such mapping is compatible with the method below.

The conventional computation begins with a decoding step that turns a\mathbf{a} into a vector d\mathbf{d} of precise weights, di=caid_i = c_{a_i}, and then evaluates

d⋅b=∑i=1ndibi,(2)\mathbf{d}\cdot\mathbf{b} = \sum_{i=1}^{n} d_i b_i, \tag*{(2)}

requiring nn decode (lookup) operations, nn multiplications, nn additions, and storage for d\mathbf{d} or a pipeline that produces it on the fly. We call b\mathbf{b} the activations, whatever its role in the network.

The Add-Before-Multiply Method

Refactoring

All the elements of a\mathbf{a} that share a code are multiplied by the same coefficient, so the corresponding elements of b\mathbf{b} can be added together first and multiplied once. Define the accumulated group values (bin sums)

qv=∑i:ai=vbi,v=0,1,…,2k−1,(3)q_v = \sum_{i:a_i=v} b_i,\qquad v=0,1,\ldots,2^k-1, \tag*{(3)}

with the empty sum equal to zero.

Proposition 1. For all a,b,c\mathbf{a},\mathbf{b},\mathbf{c} as above, d⋅b=∑v=02k−1cvqv\mathbf{d}\cdot\mathbf{b} = \sum_{v=0}^{2^k-1} c_v q_v.

Algorithm 1 Conventional vs. add-before-multiply dot product. Inputs: codes a[1..n]a[1..n], data b[1..n]b[1..n], decode table c[0..2k−1]c[0..2^k-1].

Conventional

  1. p←0p \leftarrow0

  2. for i=1i=1 to nn do ▷ parallelizable

  3. d←c[a[i]]d \leftarrow c[a[i]] ▷ decode

  4. p←p+d⋅b[i]p \leftarrow p+d\cdot b[i] ▷ MAC

  5. end for

  6. return pp

Add-before-multiply

  1. q[0..2k−1]←0q[0..2^k-1] \leftarrow0

  2. for i=1i=1 to nn do ▷ parallelizable

  3. q[a[i]]←q[a[i]]+b[i]q[a[i]] \leftarrow q[a[i]]+b[i] ▷ add at offset

  4. end for

  5. p←0p \leftarrow0

  6. for v=0v=0 to 2k−12^k-1 do

  7. p←p+c[v]⋅q[v]p \leftarrow p+c[v]\cdot q[v]

  8. end for

  9. return pp

Proof. Partition {1,…,n}\{1,\ldots,n\} by the value of aia_i. Then ∑icaibi=∑v∑i:ai=vcvbi=∑vcv∑i:ai=vbi=∑vcvqv\sum_i c_{a_i}b_i=\sum_v\sum_{i:a_i=v}c_vb_i=\sum_v c_v\sum_{i:a_i=v}b_i=\sum_v c_vq_v by the distributive law.

Written out in full,

d⋅b=c0∑i:ai=0bi+c1∑i:ai=1bi+⋯+c2k−1∑i:ai=2k−1bi.(4)\mathbf{d}\cdot\mathbf{b}=c_0\sum_{i:a_i=0}b_i+c_1\sum_{i:a_i=1}b_i+\cdots+c_{2^k-1}\sum_{i:a_i=2^k-1}b_i. \tag*{(4)}

The number of multiplications and of decoding operations drops from nn to at most 2k2^k (fewer if only some codes occur in the vector and empty bins are skipped). The number of additions stays at nn, plus at most 2k−12^k-1 to combine the weighted bins. What is introduced is the need to classify the elements of bb by the corresponding code.

Weight codes as addresses

One way to classify is to expand each kk-bit code into a 2k2^k-bit one-hot mask that gates the activation into the matching accumulator. This is simple, but costs one mask-generation operation per element and a mask-directed selection network. It is unnecessary: the code can be used directly as a binary address, or as an offset from a base address, of the accumulator in which its activation is summed. For k=2k=2 there are four codes and four bin sums, held in four registers at base+{0,1,2,3}\mathrm{base}+\{0,1,2,3\} and selected by aia_i. The decoder can be a kk-bit passthrough or a small adder; no comparator or classifier is involved. Algorithm 1 gives the conventional and new procedures, and Figure 1 shows the dataflow.

Dataflow of the conventional and add-before-multiply dot products

Figure 1. Dataflow of the conventional and add-before-multiply dot products. In (b) the nn-element decoded vector dd and the nn products are never formed; only 2k2^k bin sums are held.

Delayed decoding, and two corollaries

Decoding is delayed: the codes are used directly during the long accumulation loop, and the coefficients are fetched or computed only for the 2k2^k bins afterwards. The storage that would hold the high-precision d\mathbf{d} is saved; d\mathbf{d} is never needed. The coefficient may come from a lookup table, a linear decoding function, or a nonlinear decoding function, and the three give identical results for a given code set.

Group-wise scales. Practical quantization schemes often give each group of gg consecutive weights its own decode vector (a block scale, and possibly an offset). The method applies per group, with (n/g)2k(n/g)2^k multiplications in total; the advantage then requires 2k≪g2^k \ll g rather than 2k≪n2^k \ll n.

One bin is redundant. Because ∑vqv=T≡∑ibi\sum_v q_v = T \equiv\sum_i b_i depends only on the activations, one bin (say q0q_0) can be recovered as T−∑v≥1qvT-\sum_{v\ge1}q_v. When one activation vector is multiplied by many weight rows, TT is computed once and shared. For k=1k=1 this means only elements with ai=1a_i=1 need be accumulated.

Cost Model

Let EdE_d, EmE_m, EaE_a denote the energy (or latency, or area-delay product) of one decode, one multiplication and one accumulation, and EoE_o the cost of forming the kk-bit address offset for a bin update (about a kk-bit integer addition, often absorbed in the addressing hardware). Table 1 lists operation counts per dot product, including the one-hot variant.

ConventionalOne-hot maskedDirect address offset
Decode / mask generationnn decodesnn masks00 (offset only)
Coefficient decodesnn≤2k\le2^k≤2k\le2^k
Multiplicationsnn≤2k\le2^k≤2k\le2^k
Accumulator updatesnnn+≤2kn + \le2^kn+≤2kn + \le2^k
Address-offset ops (kk-bit)0000nn
Decoded-weight storagenn values≤2k\le2^k coefficients≤2k\le2^k coefficients
Accumulation locations11≤2k\le2^k≤2k\le2^k

Table 1. Operation counts for one length-nn dot product with kk-bit weight codes. Counts are upper bounds if empty bins are skipped.

Taking the bin additions to cost the same as a conventional accumulation, the energy ratio is

G(n,k)=n(Ed+Em+Ea)n(Ea+Eo)+2k(Ed+Em+Ea)→n→∞Ed+Em+EaEa+Eo.(5)G(n,k)=\frac{n(E_d+E_m+E_a)}{n(E_a+E_o)+2^k(E_d+E_m+E_a)} \xrightarrow{n\to\infty} \frac{E_d+E_m+E_a}{E_a+E_o}. \tag*{(5)}

With ρ=(Ed+Em)/Ea\rho=(E_d+E_m)/E_a and EoE_o neglected, G=(1+ρ)/(1+2k(1+ρ)/n)G=(1+\rho)/(1+2^k(1+\rho)/n). The multiplier count falls by exactly n/2kn/2^k, but the total arithmetic gain saturates at 1+ρ1+\rho. For floating-point operands a multiplier typically costs several times an adder [2], so ρ\rho between 2 and 8 is a reasonable range for exploration (Figure 2); for example G≈3.0G\approx3.0 (ρ=2\rho=2) to 8.7 (ρ=8\rho=8) at n=1024n=1024, k=2k=2. The headline “more than 100×” therefore refers to the number of multiplications; the energy of the arithmetic falls by a factor approaching 1+ρ1+\rho, with larger gains where multipliers or lookups are comparatively expensive (wide floating-point formats, nonlinear decoders) or where the removed decoded-weight storage and traffic are significant. The saving also appears as area and switching activity: the per-cycle datapath needs an adder and a small accumulator file rather than a multiplier.

Arithmetic energy gain curves

Figure 2. Arithmetic energy gain G(n,k)G(n,k) from Eq. (5) with Eo=0E_o=0. The curves saturate at 1+ρ1+\rho once n≫2k(1+ρ)n \gg2^k(1+\rho).

Worked Example

Take n=10n=10, k=2k=2, activations b=(.12,.34,.45,.56,.78,.90,.01,.23,.45,.67)\mathbf{b}=(.12,.34,.45,.56,.78,.90,.01,.23,.45,.67), codes a=(2,1,3,1,0,2,3,2,1,0)\mathbf{a}=(2,1,3,1,0,2,3,2,1,0) and a nonlinear decode vector c=(.06,.11,.37,.79)\mathbf{c}=(.06,.11,.37,.79). Conventionally, the codes are decoded to d=(.37,.11,.79,.11,.06,.37,.79,.37,.11,.06)\mathbf{d}=(.37,.11,.79,.11,.06,.37,.79,.37,.11,.06), ten products are formed and summed: ten lookups, ten multiplications, ten additions, ten stored FP16 values, result 1.0614.

With add-before-multiply, Table 2 shows the streaming phase: in each cycle one activation is added to the bin addressed by its code. The bins end at q=(1.45,1.35,1.25,0.46)q=(1.45, 1.35, 1.25, 0.46), and the reduction gives

cycle ii0123456789
bib_i.12.34.45.56.78.90.01.23.45.67
code aia_i2131023210
updateq2q_2q1q_1q3q_3q1q_1q0q_0q2q_2q3q_3q2q_2q1q_1q0q_0
bin vv0123
accumulated qvq_v1.451.351.250.46
coefficient cvc_v.06.11.37.79
product cvqvc_vq_v.0870.1485.4625.3634

Table 2. Stream-phase scatter trace and reduce-phase products for the worked example (n=10n=10, k=2k=2).

1.45(.06)+1.35(.11)+1.25(.37)+0.46(.79)=.0870+.1485+.4625+.3634=1.0614,1.45(.06)+1.35(.11)+1.25(.37)+0.46(.79)=.0870+.1485+.4625+.3634=1.0614,

using ten bin updates, four decodes, four multiplications and four further additions, and holding only four values. The two results agree.

Matrix and Tensor Products

Any matrix multiplication decomposes into dot products, so the method applies element by element. Let A∈RB×KA \in\mathbb{R}^{B \times K} be the activation matrix and Q∈{0,…,2k−1}K×DQ \in\{0,\ldots,2^k-1\}^{K \times D} the weight-code matrix with decode vector c\mathbf{c}. For each output element yb,dy_{b,d} and each code vv there is an accumulator

Zb,d,v=∑κ:Qκ,d=vAb,κ,yb,d=∑v=02k−1cvZb,d,v,(6)Z_{b,d,v}=\sum_{\kappa:Q_{\kappa,d}=v} A_{b,\kappa}, \qquad y_{b,d}=\sum_{v=0}^{2^k-1} c_v Z_{b,d,v}, \tag*{(6)}

i.e. Ab,κA_{b,\kappa} is added into Zb,d,vZ_{b,d,v} whenever Qκ,d=vQ_{\kappa,d}=v, and the decode and multiply happen once per output element, after the KK-element accumulation. The result Y=AQ′Y=AQ' equals the product with the decoded matrix Qκ,d′=cQκ,dQ'_{\kappa,d}=c_{Q_{\kappa,d}}, but Q′Q' is never formed. The same holds for tensor contractions: the selected numerical values and codes participating in one output element are accumulated by code. A matrix–vector product with D×KD \times K weight codes needs DKDK accumulations and D2kD2^k multiplications. Per output element the bin storage is 2k2^k accumulators, so the aggregate storage scales with the number of output elements processed concurrently—the design trade-off addressed by the weight-stationary schedule below.

Hardware Realization

The scatter-accumulate processing element

A scatter-accumulate processing element (SA-PE, Figure 3) replaces the per-cycle multiplication of a conventional MAC element by a per-cycle address-selected accumulation, and defers all multiplication until accumulation is complete. It comprises: a weight-code storage structure holding the code set for the current weight-stationary period, optionally double-buffered so the next period’s codes load while the current one runs; an address decoder producing a selection signal from the selected code (a kk-to-2k2^{k} one-hot decode, or base-plus-offset address generation, in the extreme a kk-bit passthrough); a write-select circuit (decoded per-bin write enables, a demultiplexer, or a decoded register-file or SRAM write address) that steers the incoming activation to the selected bin; an adder that adds it to the value held in that bin; a bin accumulator bank of 2k2^{k} locations; a 2k2^{k}-entry decode LUT (or decoding-function evaluator); and a reduction unit that forms ∑jcjBin⁡[j]\sum_j c_j \operatorname{Bin}[j] and presents it as the PE’s partial sum; it fuses decode and multiply, since the decoded coefficient cjc_j feeds the multiplier directly and the operation runs only 2k2^{k} times per tile. Signed codes are handled entirely in the decode LUT, so the address path operates only on unsigned kk-bit codes. In the streaming datapath each cycle performs one address-selected add; the multiplier is not in the loop.

Figure 3. Scatter-accumulate processing element. During streaming, the stored code selects a bin and the adder updates it; during the reduce phase the reduction unit multiplies each bin by its decoded coefficient and sums.

Weight-stationary systolic array

SA-PEs can replace the MAC unit at each node of a conventional weight-stationary systolic array (Figure 4); array-level control, tiling and interconnect of an existing design can be reused. Weight codes are loaded into the PEs once per weight tile and held stationary while activations are streamed. Each output element corresponds to a row of the array; the dot product is split into slices of LL elements processed by the CC PEs of that row (n=CLn = CL), each scatter-accumulating its slice of the activations into its own independently addressed bin bank. In each stream cycle a PE consumes one stationary code, read from its code store, and one activation; the gain needs L≫2kL \gg2^{k}, since otherwise the bins collect too few terms to amortize the reduction. After a full pass of the activation slice, each PE holds 2k2^{k} partial bin sums and its reduction unit produces a partial dot product; a conventional row adder chain sums the partial results across the row to produce the output. With HH rows the array computes HH output elements per pass. A problem larger than the physical array is partitioned into weight tiles in the usual way, with row-partial results accumulated across tiles in an output accumulator.

Figure 4. Weight-stationary array of SA-PEs. Activation slices are broadcast down columns; the PEs of a row hold codes for the same output element and their partial sums are combined by a row adder chain. (Schematic; array size is arbitrary.)

Schedule

A weight-stationary period has four phases (Figure 5): load (about one cycle: write the code set, initialize bins, load the decode LUT, reset counters), stream (LL cycles, one scatter-accumulate per activation), reduce (2k2^{k} cycles of multiply-add in the reduction unit) and drain (CC cycles to flush the CC partial sums of a row through the CC-stage adder chain). The next tile’s load can overlap the current tile’s work through double buffering. Because 2k≪L2^{k} \ll L, load, reduce and drain are short compared with the stream phase, so throughput is set by one addition per activation per cycle; the period grows only by the 2k2^{k} reduce cycles relative to a conventional MAC pipeline (6% for k=2k = 2, L=64L = 64, and 25% for k=4k = 4), unless the reduce phase is overlapped with the next tile’s stream, which requires double-buffered bins. The reduction multiplier runs only 2k2^k times per LL cycles, so it can be small, clocked slower than the stream path, or time-shared among all PEs of a row or column. A small controller finite-state machine with phase counters (a ⌈log⁡2L⌉\lceil\log_2 L\rceil-bit stream counter and a kk-bit reduce counter) sequences the phases through load, stream, reduce and drain states, asserting enables such as load-weights, init-bins, stream-enable and reduce-enable.

Phase schedule

Figure 5. Phase schedule (not to scale). The load of the next tile overlaps the reduce and drain of the current one; the reduce phase lasts 2k≪L2^k \ll L cycles.

Accumulator width and multi-precision design

Bin width. In the worst case all activations of a slice map to one code and sum into a single bin, so a fixed-point bin needs wact+⌈log⁡2nmax⁡⌉w_{\mathrm{act}}+\lceil\log_2 n_{\max}\rceil bits, where nmax⁡n_{\max} is the number of activations accumulated into one bin (the slice length LL in an array); for 16-bit activations and nmax⁡=1024n_{\max}=1024 that is ten guard bits. Alternatively the bins can be wider floating-point accumulators (e.g. FP32 for FP16 inputs), as is common practice in accelerators, which avoids bit growth. Multi-precision. A single SA-PE can support k=1k=1 to 4 (or more) by parameterizing the bin count and the address-decoder width. A design provisions the maximum bin count (16 for k=4k=4); at lower kk the unused bins can be power- or clock-gated. The bin bank, whether registers or SRAM, is the dominant area of the PE, while the multiplier cost is amortized over the stream length regardless of kk, so the design trade-off is set mainly by bin-bank size rather than arithmetic width. Resource comparison. Table 3 summarizes the per-PE comparison, and Table 4 gives the multiplication reduction n/2kn/2^k.

Conventional MAC PESA-PE
Multiplications per dot productnn≤2k\le2^k, independent of nn
Additions per dot productnn accumulator updatesnn scatter updates + ≤2k\le2^k reduce updates
Per-cycle streaming operation1 multiply + 1 accumulate1 address-selected add
Extra addressing logicnonekk-bit address decode / base+offset
Storage per PE1 accumulator2k2^k bins (width = data + ⌈log⁡2n⌉\lceil\log_2 n\rceil)
Weight storage per PEdecoded weight, or kk-bit + decodekk-bit codes only; decode LUT shared

Table 3. Per-PE resources for an nn-length period: conventional MAC systolic PE versus SA-PE.

kkmults (2k2^k)n=256n=256n=1024n=1024n=4096n=4096
12128×512×2048×
2464×256×1024×
3832×128×512×
41616×64×256×

Table 4. Multiplication reduction factor n/2kn/2^k per PE per tile.

Software and vector processors

The same refactoring runs in software or on SIMD hardware: the loop of Algorithm 1 is efficient on any core with cheap indexed read-modify-write to a small cache-resident table, and the address is formed as a base register plus the code offset. On a vector ISA with indexed stores (e.g. RISC-V vsoxei*), an implementation scatters each activation into a zero-filled 2k×2^k \times VL block at the row given by its code and then reduces the block. Because an indexed store overwrites rather than accumulates, the reduction then also adds the zeros (2k2^k VL lane-additions rather than VL), so on such hardware the gain is confined to decode and multiplication; a scatter-accumulate primitive or an accumulator file addressed by the code, as in the SA-PE, recovers the full operation count of Table 1.

Local Memory Reduction

Delayed decoding also shrinks the local weight memory. Consider one PE holding a weight-stationary tile of LL weights. Let wdw_d be the decoded-weight width, wbw_b the bin width, and PP the number of PEs that share one decode table; activation buffers are identical in all designs and are excluded. Three organizations are compared, with sizes in bits:

MA=Lwd(decode, then store the decoded weights)(7)M_A = Lw_d \qquad\text{(decode, then store the decoded weights)} \tag*{(7)}
MB=Lk+2kwd(store codes, decode per element)(8)M_B = Lk + 2^k w_d \qquad\text{(store codes, decode per element)} \tag*{(8)}
MN=Lk+2k(wd/P+wb)(scatter-accumulate)(9)M_N = Lk + 2^k(w_d/P + w_b) \qquad\text{(scatter-accumulate)} \tag*{(9)}

Relative to a decoded tile the reduction is

R=MAMN=LwdLk+2k(wd/P+wb)→L→∞wdk,(10)R = \frac{M_A}{M_N} = \frac{Lw_d}{Lk + 2^k(w_d/P + w_b)} \xrightarrow{L\to\infty} \frac{w_d}{k}, \tag*{(10)}

and MN<MAM_N < M_A once L>2k(wd/P+wb)/(wd−k)L > 2^k(w_d/P+w_b)/(w_d-k). Table 5 gives values for L=1024L=1024, wd=16w_d=16, FP32 bins (wb=32w_b=32) and P=1P=1, and Figure 6 shows R(L)R(L). For a row of 32 PEs with 1024-weight slices, 64 KiB of decoded weights becomes 8.8 KiB for k=2k=2 or 19 KiB for k=4k=4. Using fixed-point bins of wact+⌈log⁡2L⌉=26w_{act}+\lceil\log_2 L\rceil=26 bits instead of FP32, or sharing the decode table across 32 PEs, changes RR by at most about 5%.

kkMAM_A (B)MBM_B (B)MNM_N (B)R=MA/MNR = M_A/M_NMN/MBM_N/M_B
1204813214014.61.06
220482642807.31.06
420485446083.41.12

Table 5. Local weight memory per PE (L=1024L = 1024, wd=16w_d = 16, wb=32w_b = 32, P=1P = 1).

Memory reduction curves

Figure 6. Memory reduction R(L)R(L) from Eq. (10) for wd=16w_d = 16, wb=32w_b = 32, P=1P = 1. The curves approach wd/k=16w_d/k = 16, 88, 44; the thin line marks R=1R = 1.

The benefit depends on the baseline. It applies when the conventional design holds decoded weights locally (MAM_A). If the conventional design instead keeps kk-bit codes and decodes per element (MBM_B), scatter-accumulate needs 6–12% more memory for the bins, and its advantage is the removed per-element decode and multiply rather than memory. The saving also requires L≫2kL\gg2^k; for k=4k=4 it vanishes at L=64L=64.

RTL Implementation and Sizing

Design. We implemented the SA-PE and an H×CH\times C array in synthesizable Verilog, parameterized by kk, slice length LL, activation width wactw_{act}, rows HH and columns CC. Each PE holds an L×kL\times k-bit weight-code memory, 2k2^k signed bins and a multiply-accumulator used only in the reduce phase (bin ×\times decode value, accumulated into a partial sum). A bin must hold the sum of LL activations and so needs at least wact+⌈log⁡2L⌉w_{act}+\lceil\log_2 L\rceil bits (22 for wact=16w_{act}=16, L=64L=64); the RTL adds one guard bit, using ⌈log⁡2(L+1)⌉\lceil\log_2(L+1)\rceil (23 bits), which gives a 42-bit partial sum. One 2k2^k-entry decode LUT is shared by the whole array and broadcast during the reduce phase. A six-state controller (idle, flush, stream, reduce, drain, done) with stream, reduce and drain counters sequences each tile, and a registered adder chain sums the CC PE partial sums of each row over CC drain cycles.

Verification and baseline. A self-checking testbench loads random codes, a random decode table and random activations into a 4×34 \times3 array and compares each output with an integer decode-then-MAC reference (8 random tiles, no mismatches). As baseline we built a matched MAC array with identical interfaces, code memories, shared LUT and controller (minus the reduce state); its PE decodes and multiplies every element, and it passes the same test. Sharing the structure keeps the comparison confined to the PE datapath.

Per-PE sizing. Both arrays were synthesized with Yosys 0.33 to Xilinx 7-series LUT6 and DSP48E1 primitives (k=2k = 2, L=64L = 64, wact=16w_{act} = 16). Table 6 gives per-PE results; the code memory (one RAM64M) is identical in the two designs and is omitted. The last two rows are projections obtained by removing the multiplier from the PE and adding a separately synthesized reduction engine amortized over σ=16\sigma= 16 PEs.

PELUTFFDSP48
MAC, multiplier in DSP55391
MAC, multiplier in fabric819390
SA-PE (RTL), multiplier in DSP1611341
SA-PE (RTL), multiplier in fabric11931340
SA-PE shared†, DSP engine122950.06
SA-PE shared†, fabric engine179950

Table 6. Per-PE FPGA resources (k=2k = 2, L=64L = 64, wact=16w_{act} = 16, Yosys 0.33). †: projection with the reduction multiplier shared by σ=16\sigma= 16 PEs.

Array sizing. A 4×34 \times3 array (L=64L = 64, 12 PEs, DSP-mapped) needs 2368 LUTs, 1807 FFs and 12 DSP48 for the SA array, against 1335 LUTs, 719 FFs and 12 DSP48 for the MAC array.

Interpretation. The unshared SA-PE is larger than a MAC PE (161 versus 55 LUTs and 134 versus 39 FFs with a DSP multiplier) because of the bin bank (92 flip-flops here), the partial-sum register and the bin-select multiplexer, and because it still contains one multiplier. The saving appears only when that multiplier is removed from the PE. A PE without the multiplier needs 119 LUTs and 92 FFs, and a stand-alone reduction engine needs 42 LUTs, 42 FFs and one DSP48 (960 LUTs if the multiplier is built in fabric). Shared by σ=16\sigma= 16 PEs the engine adds about 3 LUTs per PE, so DSP use falls from one per PE to 1/161/16, and with fabric multipliers the per-PE cost falls from 819 LUTs (MAC) to 179, a factor of 4.6.

Sharing limit. Each PE needs only 2k2^k multiplications per LL cycles, so one multiplier can serve at most σ=L/2k\sigma= L/2^k PEs: 16 for k=2k = 2, L=64L = 64, and 4 for k=4k = 4, L=64L = 64. The implemented RTL keeps one multiplier per PE. Sharing additionally requires the reduction of tile tt to overlap the stream of tile t+1t+1, which needs double-buffered bins (about 92 more flip-flops per PE); otherwise the reduce phase grows to σ2k\sigma2^k cycles.

Dependence on kk. The bin bank grows with $2^k$. At k=4k = 4 the SA-PE needs 359 LUTs and 412 FFs against 119 LUTs and 39 FFs for the MAC PE, and the serial reduce phase costs 2k2^k cycles per tile: 6% of a 64-cycle stream at $k = 2 and 25% at k=4k = 4. The code memory per PE is Lk=128Lk = 128 bits for k=2k = 2, L=64L = 64, plus the bins, against 1024 bits for a decoded 16-bit tile.

Caveats. These are figures from an open-source FPGA flow. They indicate relative sizing, not ASIC area, power or Vivado results; the sharing figures are projections from synthesized components rather than synthesis of a complete shared design; and the comparison is for the specific datapath widths and parameters listed.

Evaluation by Software Models

Numerical behaviour. For integer activations and integer decoded weights the refactoring is exact, since integer addition is associative and the distributive law holds; we verified this on random 8-bit data (n=1000n = 1000, k=2k = 2). For floating point, reordering the additions changes rounding but not its order of magnitude. We measured this with a model in which cvc_v are sorted normal variates in FP16, activations are normal in FP16 and codes are uniform; 40 random trials per row, FP64 reference. Table 7 reports the mean error relative to ∑i∣dibi∣\sum_i \lvert d_i b_i\rvert for (i) the conventional method with FP32 multiply-accumulate, (ii) the conventional method with a fully FP16 datapath, (iii) the new method with FP16 bins and (iv) the new method with FP32 bins.

kknnConv. FP32 acc.Conv. FP16New, FP16 binsNew, FP32 bins
12561.9×10−81.9 \times10^{-8}1.6×10−41.6 \times10^{-4}1.1×10−41.1 \times10^{-4}2.6×10−92.6 \times10^{-9}
140961.7×10−81.7 \times10^{-8}1.3×10−41.3 \times10^{-4}1.1×10−41.1 \times10^{-4}1.1×10−91.1 \times10^{-9}
22562.2×10−82.2 \times10^{-8}2.1×10−42.1 \times10^{-4}8.5×10−58.5 \times10^{-5}3.7×10−93.7 \times10^{-9}
240961.8×10−81.8 \times10^{-8}1.5×10−41.5 \times10^{-4}7.3×10−57.3 \times10^{-5}1.2×10−91.2 \times10^{-9}
42561.7×10−81.7 \times10^{-8}1.6×10−41.6 \times10^{-4}7.9×10−57.9 \times10^{-5}3.4×10−93.4 \times10^{-9}
440961.9×10−81.9 \times10^{-8}1.8×10−41.8 \times10^{-4}5.8×10−55.8 \times10^{-5}1.2×10−91.2 \times10^{-9}

Table 7. Mean relative error (normalized by ∑i∣dibi∣\sum_i \lvert d_i b_i\rvert) against an FP64 reference.

At equal accumulator width the new method is no less accurate than the conventional one, and more accurate in the FP16 setting, since the per-element product rounding is removed. Because the bins perform only additions of activations they can be widened cheaply; with FP32 bins the error is roughly an order of magnitude below the FP32 conventional pipeline, since only about n+2kn + 2^k rather than 3n3n roundings occur.

Array-level functional check. We also modelled the tiled weight-stationary organization of § 7: 30 random GEMV configurations (k∈[1,4]k \in[1,4], up to 32 output rows, KK up to 700, random slice lengths LL per PE) in FP64 gave a maximum absolute difference of 4.3×10−144.3 \times10^{-14} from the reference (c[Q]xc[Q]x), integer-exact results in an INT64 test, and a multiplication count of exactly H⌈K/L⌉2kH\lceil K/L\rceil2^k, confirming the reduction factors of Table 4 (e.g. a 4096 × 4096 GEMV with k=4k = 4 and 1024-element slices uses 64× fewer multiplications).

These are software emulations on synthetic data, not measurements on silicon or trained networks; end-to-end model accuracy and energy should be confirmed on real hardware.

Discussion

Relation to prior work. Exploiting repeated weights to factor out multiplications is an established idea, and this paper should be read in that context. Weight sharing with codebooks, which creates the few-distinct-values structure used here, was popularized by Deep Compression [1]. Accumulate-then-multiply units for weight-shared CNN accelerators, which bin inputs by weight index and multiply the bins by the shared weights, were proposed by Garland and Gregg [3, 4], and UCNN [5] exploits weight repetition by factorizing dot products and sharing partial sums. A separate, active line of work replaces multiplications in low-bit LLM inference by lookup tables of precomputed activation combinations (LUT-GEMM [6], T-MAC [7]), and ternary-weight models such as BitNet b1.58 [8] reduce multiplications to additions by construction. Relative to these, the formulation here is deliberately general: it handles integer or floating-point operands and linear or nonlinear decoders, uses the weight code itself as the accumulator address so that neither a one-hot mask nor a decoded weight vector is formed, delays decoding until after accumulation, and is packaged as a drop-in PE for weight-stationary arrays with a streaming schedule and multi-precision provisioning. We make no claim that the algebraic identity is new; a detailed comparison with these earlier proposals would be needed to establish precisely where the benefit lies for a given target.

When it helps, and when it does not. The benefit requires 2k≪n2^k \ll n (or ≪g\ll g for group-wise scales), multiplication and decode to be a meaningful part of the cost, and hardware that performs address-selected accumulation cheaply. In memory-bandwidth-bound inference, which motivates low-bit weights, reduced arithmetic does not by itself raise throughput, but the saved multiplier area and switching power can be spent on wider on-chip weight buffers or more parallel PEs within the same budget. Costs include the bin bank (the dominant PE area, 2k2^k wide accumulators per PE), a read-after-write hazard when consecutive activations share a code (requiring forwarding or interleaved bin sets), and, for large kk, diminishing returns as 2k2^k approaches nn. The RTL results of § 9 show the first cost concretely: an unshared SA-PE is larger than a MAC PE, so the area benefit depends on sharing the reduction multiplier and on a bin bank that is cheap relative to the multiplier it replaces. The local-memory saving of § 8 likewise applies only against a baseline that stores decoded weights.

Alternatives. For linearly coded weights one can split aa into bit planes and compute kk masked sums scaled by powers of two; this needs no multiplications but kk conditional passes over bb, versus one pass here, and does not handle nonlinear decoders without an extra step.

Conclusion

Refactoring a low-bit dot product so that activations are added into code-addressed accumulators before any multiplication reduces the multiplier and decode count from nn to at most 2k2^k, eliminates the decoded weight vector, and keeps the addition count at n+2kn+2^k rather than nn. A scatter-accumulate PE realizes this in a weight-stationary systolic array with a 2k2^k-cycle reduce phase per tile and a small time-shared multiplier, and an RTL implementation shows the sizing trade-offs against a matched MAC array. The arithmetic gain saturates at the cost ratio of a decode–multiply–accumulate to a plain accumulate, so the method is most attractive where multipliers and decoders are expensive and accumulators can be made wide cheaply. Next steps are ASIC synthesis of the SA-PE and array with a shared reduction engine, to replace the abstract energy model with measured area and power, and evaluation of end-to-end accuracy on quantized models.

References

  1. [1]S. Han, H. Mao, W. J. Dally. Deep Compression: Compressing deep neural networks with pruning, trained quantization and Huffman coding. ICLR, 2016.arxiv.org/abs/1510.00149
  2. [2]M. Horowitz. Computing’s energy problem (and what we can do about it). IEEE ISSCC, 2014.
  3. [3]J. Garland, D. Gregg. Low complexity multiply accumulate unit for weight-sharing convolutional neural networks. IEEE Computer Architecture Letters, 2017 (arXiv:1609.05132).DOI
  4. [4]J. Garland, D. Gregg. Low complexity multiply-accumulate units for convolutional neural networks with weight-sharing. ACM Trans. Architecture and Code Optimization, 15(3), 2018 (arXiv:1801.10219).arxiv.org/abs/1801.10219
  5. [5]K. Hegde, J. Yu, R. Agrawal, M. Yan, M. Pellauer, C. W. Fletcher. UCNN: Exploiting computational reuse in deep neural networks via weight repetition. ISCA, 2018.arxiv.org/abs/1804.06508
  6. [6]G. Park et al. LUT-GEMM: Quantized matrix multiplication based on LUTs for efficient inference in large-scale generative language models. arXiv:2206.09557, 2022.arxiv.org/abs/2206.09557
  7. [7]J. Wei et al. T-MAC: CPU renaissance via table lookup for low-bit LLM deployment on edge. arXiv:2407.00088, 2024.DOI
  8. [8]S. Ma et al. The era of 1-bit LLMs: All large language models are in 1.58 bits. arXiv:2402.17764, 2024.arxiv.org/abs/2402.17764

Paper details

vlnc:W_9t2gcvhu
Version
v1 · latest
Published
Fresh — added to the Hub within the last 30 days
Added
License
CC BY 4.0
Usage

views · 0

downloads · 0

A view counts once per browser per day, a download each time the PDF is requested.

  • Computer Science

Not recorded for this paper

View statement
Looking for related papers…
Contents