One operation, a hundred billion times
A neural network of any architecture spends almost all of its time doing one thing: multiplying a number by a weight and adding it to a running total. Everything else — the nonlinearities, the normalisations, the attention — is arranged around that operation. This is the shortest path from zero to understanding why specialised inference hardware exists.
The claim
Strip away the vocabulary and a neural network does one thing, enormously often: multiply a number by a weight, and add the result to a running total.
That operation is the multiply-accumulate, and everything else a network does — the nonlinearities, the normalisations, the attention — is arranged around it and costs a small fraction of it. The whole field of inference hardware exists because there is one operation worth specialising for rather than a hundred.
If you read nothing else here, read that. The rest of this post is why it is true.
One unit
A single artificial neuron takes several numbers in and produces one number out. Each input has a weight. Multiply each input by its weight, add them all together, add a constant called the bias, and pass the total through a simple function.
The expensive part is on the left and scales with the number of inputs; the activation on the right is one cheap operation however many inputs there were. Drawn for this post.
Three inputs mean three multiplies and three adds. A neuron in the middle of a real network has hundreds or thousands of inputs, and the count follows directly.
A layer is a matrix
A layer is many neurons reading the same inputs. Neuron one has its own set of weights, neuron two has another, and so on.
Stack those weight sets as rows and you have a matrix. The inputs are a vector. Every output of the layer at once is the matrix multiplied by the vector — which is why linear algebra, not biology, is the language this field actually runs on.
Each row of the weight matrix is one neuron, and each output is one dot product. Drawn for this post; the 16,777,216 figure is arithmetic, not a measurement.
Where the time actually goes
A network is layers in sequence, and running one is called inference. Count the multiply-accumulates and you have accounted for nearly all of the work.
The other operations are real but cheap. An activation function runs once per output, not once per input, so a neuron with a thousand inputs does a thousand multiply-accumulates and one activation. Normalisation and pooling are the same shape of cost. They matter for accuracy and they round to nothing in the energy budget.
This is why hardware for neural networks is, almost entirely, hardware for one operation [2]. The convolutional architecture that made vision work [1] and the attention mechanism behind language models both reduce to the same multiply-accumulate, differently arranged.
The part that is not obvious
Here is the fact the rest of this site is built on: the multiplication is not the expensive part.
A multiply in fixed-point arithmetic is small and cheap. What costs is getting the two numbers to the circuit that multiplies them — addressing the memory, reading it, driving the value down a bus, latching it. That journey has cost far more energy than the arithmetic at the end of it for as long as anyone has measured carefully [3].
So the engineering problem is not "how do we multiply faster". It is "how do we stop moving the operands". Every serious inference architecture is an answer to that question, and ours is the answer that puts the weights inside the array doing the multiplication so they never move at all.
Where to go next
Convolutional networks — how the same operation is arranged for images, and the worked count for one layer: 36,864 weights, 115 million multiply-accumulates, each weight used 3,136 times.
The crossbar — doing the multiply-accumulate as a physical consequence of two circuit laws instead of as an instruction.
References
- , “Gradient-based learning applied to document recognition,” Proceedings of the IEEE, vol. 86, pp. 2278–2324, 1998. doi:10.1109/5.726791reviewVolume and pages confirmed from Semantic Scholar; the issue number is corroborated only by a third-party reference list, so it is not asserted.
- , “Efficient processing of deep neural networks: a tutorial and survey,” Proceedings of the IEEE, vol. 105, no. 12, pp. 2295–2329, 2017. doi:10.1109/JPROC.2017.2761740reviewThe standard survey of how this one operation is arranged in hardware, and why achieved throughput falls short of peak.
- , “1.1 Computing's energy problem (and what we can do about it),” IEEE International Solid-State Circuits Conference (ISSCC) Digest of Technical Papers, pp. 10–14, 2014. doi:10.1109/ISSCC.2014.6757323reviewThe 45 nm accounting behind the claim that fetching an operand costs more than the arithmetic done on it.