Inferensys

Glossary

Multiply-Accumulate Operations (MACs)

Multiply-Accumulate Operations (MACs) are the fundamental computations in neural network inference, involving a multiplication followed by an addition, and are commonly used as a hardware-agnostic metric for estimating the computational cost of a model.
Enterprise console with connected nodes and monitoring panels for orchestrated systems.
HARDWARE-AWARE MODEL DESIGN

What is Multiply-Accumulate Operations (MACs)?

A fundamental metric for quantifying the computational workload of neural networks, independent of specific hardware.

Multiply-Accumulate Operations (MACs) are the fundamental arithmetic computations at the core of neural network inference and training, each consisting of a multiplication followed by an addition. They serve as a hardware-agnostic metric for estimating the computational cost, or FLOPs (Floating Point Operations), of a model, with one MAC typically counted as two FLOPs. This count is crucial for hardware-aware model design, directly correlating with inference latency and energy consumption on target silicon like NPUs (Neural Processing Units) or mobile CPUs.

In practice, MAC counts are derived from a model's architecture—most densely in convolutional and fully connected layers. Engineers use MAC estimates during Design Space Exploration (DSE) to compare model efficiency, guide model compression via pruning or quantization, and ensure designs meet the constraints of edge AI deployment. While a critical proxy, MACs alone do not capture memory access costs, which are often the true bottleneck, as analyzed by performance models like the Roofline Model.

COMPUTATIONAL PRIMITIVE

Key Characteristics of MACs

Multiply-Accumulate (MAC) operations are the atomic computations of neural networks. Understanding their properties is essential for hardware-aware model design and performance estimation.

01

Fundamental Neural Network Building Block

A Multiply-Accumulate (MAC) operation computes a = a + (b * c), where the product of two operands is added to an accumulator. This is the core computation in fully connected (dense) layers, convolutional layers, and attention mechanisms. The total number of MACs in a model, often reported as FLOPs (Floating Point Operations), serves as a hardware-agnostic proxy for computational cost and energy consumption, guiding architecture selection for target hardware.

02

Hardware Performance Bottleneck

The throughput of MAC units defines a processor's peak theoretical performance, measured in GMACs/sec or TOPS (Tera Operations Per Second). However, real-world performance is often limited by the memory wall—the time and energy cost of moving operands (weights, activations) from memory to the compute unit. Efficient model design focuses on increasing operational intensity (MACs per byte of data moved) to approach the hardware's compute roof, as visualized by the Roofline Model.

03

Precision and Quantization

MACs are performed at a specific numerical precision, which directly impacts model size, speed, and power.

  • Training: Typically uses FP32 or BF16 for gradient stability.
  • Inference: Often uses lower precision like INT8 or FP16 via quantization to reduce memory bandwidth and leverage faster integer or mixed-precision hardware (e.g., Tensor Cores, NPUs).
  • Quantization-Aware Training (QAT) simulates low-precision MACs during training to maintain accuracy, whereas Post-Training Quantization (PTQ) calibrates a pre-trained model.
04

Sparsity and Conditional Computation

Not all MACs are equally important. Exploiting sparsity is key to efficiency.

  • Weight Sparsity: Many model weights are near zero after pruning. Skipping these MACs can save compute.
  • Activation Sparsity: Functions like ReLU generate zeros, creating dynamic sparsity.
  • Conditional Execution: Architectures like Mixture of Experts (MoE) or Early Exit Networks activate only a subset of model parameters per input, performing a sparse subset of total possible MACs. Hardware must support sparse computation and efficient sparsity encoding (e.g., CSR format) to realize these gains.
05

Compiler & Hardware Optimizations

Modern ML compilers transform high-level model graphs into highly optimized sequences of hardware MAC instructions.

  • Operator Fusion: Combines consecutive ops (e.g., Conv + BatchNorm + ReLU) into a single kernel, reducing intermediate memory writes and increasing MAC density.
  • Kernel Auto-Tuning: Searches for optimal tile sizes and loop orders to maximize MAC throughput on specific hardware (used by TVM, TensorRT).
  • Memory Hierarchy Management: Strategies like tiling orchestrate data movement between DRAM, caches, and registers to keep MAC units fed, minimizing stalls.
06

MACs vs. Model Quality Trade-off

In hardware-aware design, MAC count is a primary optimization target, but not in isolation. The goal is to find architectures on the Pareto frontier of accuracy vs. MACs. Techniques include:

  • Efficient Layer Designs: Using depthwise separable convolutions over standard convolutions drastically reduces MACs.
  • Neural Architecture Search (NAS): Automatically explores the design space for models that maximize accuracy under a MAC budget.
  • Knowledge Distillation: Trains a low-MAC student model to mimic a high-accuracy teacher model, preserving performance with fewer computations.
HARDWARE-AWARE MODEL DESIGN

How Multiply-Accumulate Operations Work

Multiply-Accumulate Operations are the atomic computations of neural network inference, forming the basis for measuring computational cost.

A Multiply-Accumulate Operation is a fundamental computation that performs a multiplication followed by an addition to a running sum, expressed as a = a + (b * c). In neural networks, this pattern is ubiquitous in linear layers and convolutions, where weights are multiplied by activations and summed. The total number of MACs in a model serves as a hardware-agnostic proxy for its computational complexity and energy consumption, directly informing hardware-aware design.

Hardware accelerators like NPUs and Tensor Cores are optimized to execute massive arrays of MACs in parallel. The efficiency of these units defines a system's peak theoretical performance, often visualized using the Roofline Model. When designing models for edge deployment, engineers minimize MAC counts through techniques like depthwise separable convolutions and pruning to stay within the memory bandwidth and compute constraints of target silicon, a core practice in TinyML.

FORMULA REFERENCE

MACs Calculation Examples for Common Layers

Formulas for calculating Multiply-Accumulate Operations (MACs) for standard neural network layers, assuming a batch size of 1. MACs are a hardware-agnostic metric for computational cost.

Layer TypeKey ParametersMACs FormulaExample CalculationNotes

Standard Convolution (Conv2D)

Input: (H_in, W_in, C_in), Kernel: (K_h, K_w), Output Channels: C_out, Stride: S, Padding: P

C_out * H_out * W_out * C_in * K_h * K_w

Input: 224x224x3, Kernel: 3x3, C_out: 64, Stride: 1, Padding: 'same' → H_out=W_out=224 → 64 * 224 * 224 * 3 * 3 * 3 = ~173M MACs

Dominant cost. 'same' padding implies H_out = H_in / S (rounded up).

Depthwise Separable Convolution

Input: (H_in, W_in, C_in), Kernel: (K_h, K_w), Output Channels: C_out

(H_out * W_out * C_in * K_h * K_w) + (H_out * W_out * C_in * C_out)

Input: 224x224x32, Kernel: 3x3, C_out: 64 → DW: 2242243233 ≈ 14.5M MACs; PW: 22422432*64 ≈ 103M MACs; Total: ~117M MACs

Factorizes standard conv into Depthwise (DW) + Pointwise (PW) conv. Significant MACs reduction vs. standard conv.

Fully Connected (Linear/Dense)

Input Features: F_in, Output Features: F_out

F_in * F_out

F_in: 1024, F_out: 4096 → 1024 * 4096 = ~4.2M MACs

Also counts as MACs. Often a bottleneck in MLPs and transformer FFN layers.

Multi-Head Self-Attention (Transformer)

Sequence Length: L, Embedding Dim: D, Number of Heads: H

4 * L^2 * D + 2 * L * D^2

L: 256, D: 768, H: 12 → Term1: 4256^2768 ≈ 201M MACs; Term2: 2256768^2 ≈ 302M MACs; Total: ~503M MACs

Approximation. Term1 is attention score calc (QK^T). Term2 is projection layers. Complexity is O(L^2).

Batch Normalization

Spatial Dimensions: H, W, Channels: C

2 * H * W * C

Feature map: 28x28x256 → 2 * 28 * 28 * 256 = ~401k MACs

Inference: fused into preceding conv. Counts as MACs if computed separately (mean subtraction, scaling).

Average/Max Pooling

Input: (H_in, W_in, C), Pool Size: (P_h, P_w)

H_out * W_out * C * P_h * P_w (Average Pooling only)

Input: 28x28x128, Pool: 2x2, Stride: 2 → H_out=14, W_out=14 → 141412822 = ~100k MACs (Avg Pool)

Max Pooling uses comparisons, not multiplies, so often considered 0 MACs. Average Pooling involves divisions.

Pointwise Convolution (1x1 Conv)

Input: (H, W, C_in), Output Channels: C_out

H * W * C_in * C_out

Input: 56x56x256, C_out: 512 → 56 * 56 * 256 * 512 = ~411M MACs

Heavy cost due to channel interaction. Core of 'bottleneck' blocks and pointwise stage in depthwise separable conv.

Grouped Convolution

Input: (H_in, W_in, C_in), Kernel: (K_h, K_w), C_out, Groups: G

(C_out / G) * H_out * W_out * (C_in / G) * K_h * K_w * G

Input: 112x112x128, Kernel: 3x3, C_out: 128, Groups: 32 → (128/32)112112*(128/32)3332 = 1121121283*3 = ~14.4M MACs

Reduces connections between input/output channels. G=1 is standard conv. G=C_in is depthwise conv.

HARDWARE-AWARE MODEL DESIGN

Frequently Asked Questions

Essential questions about Multiply-Accumulate Operations (MACs), the fundamental unit of computation in neural networks and a critical metric for hardware-aware model design.

A Multiply-Accumulate Operation (MAC) is the fundamental arithmetic computation at the core of neural network inference, consisting of a multiplication followed by an addition to an accumulator register. It is expressed as a = a + (b * c), where the product of two operands (b and c) is added to a running sum (a). This operation is the primary workload for matrix multiplications and convolutions, which dominate the compute in deep learning models. As a hardware-agnostic metric, the total number of MACs required to process an input through a model provides a first-order estimate of its computational cost, directly influencing latency and energy consumption on target hardware.

Prasad Kumkar

About the author

Prasad Kumkar

CEO & MD, Inference Systems

Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.

His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.