Home › Practice › Accelerators › Multiply and keep a running total (MAC)

Multiply and keep a running total (MAC)

EasyRTLAcceleratorssequential

A GPU, a TPU and the AI engine in a phone all spend most of their time on one tiny job: multiply two numbers, add the answer to a running total. It is called a MAC (multiply-accumulate). Build one and you have built the smallest piece of every accelerator.

Concept first. The running total lives in a register called the accumulator. On every clock tick the circuit can read the register, add something to it, and write the new total back. Example with other numbers: total is 10, inputs are 3 and 5, and the circuit is switched on. At the next tick the total becomes 10 + 3×5 = 25. If it is switched off, the total stays 10.

Why is the total wider than the inputs? Two 4-bit numbers can multiply to a number that needs 8 bits, and adding many of those needs even more room. Signal-processing chips have always used an accumulator wider than the numbers they multiply, for exactly this reason.

Solve in your browser →

No install and no sign-up needed. You write your answer in the editor and Nishkam checks it.

More in this track

← 2-stage pipelined mid-price checkDot product of two lists of four →