{"id":"mac","level":"logic","name":"Multiply–accumulate and fused arithmetic","shortName":"Multiply–accumulate","role":"Combines products into the accumulated sums used by dot products and matrices.","description":"A multiply–accumulate operation updates a running sum with a product. Repeating this pattern computes a dot product, and many dot products form a matrix multiplication. In floating-point hardware, a fused multiply-add computes a product plus an addend with one final rounding rather than separately rounding the product first. That numerical distinction matters: mathematically equivalent evaluation orders need not produce identical finite-precision results. The atlas shows operands entering a product path and a retained sum returning through a feedback path. It represents the operation's dependencies, not a vendor's internal tensor-core layout. Precision, accumulation width, and throughput belong to a particular implementation and must be specified separately.","specs":[{"label":"Update equation","value":"acc ← acc + a × b","context":"Conceptual multiply–accumulate recurrence."},{"label":"FMA rounding","value":"One final rounding","context":"Floating-point fused multiply-add semantic distinction."},{"label":"Operation count","value":"Often counted as 2 FLOPs","context":"One multiply plus one add; not two clock cycles."}],"interfaces":[{"name":"a, b, and accumulator","direction":"in","signal":"Operands in a defined numeric format"},{"name":"Updated accumulator","direction":"out","signal":"Partial or final dot-product result"}],"tradeoff":"Low precision can reduce hardware and data costs. Numerical error and accumulation behavior require evaluation.","whyAI":"MAC patterns implement the dense linear algebra of AI. Reuse and parallel scheduling determine how efficiently the hardware stays busy.","related":["multiplier","adder","flipflop","sram","tensor-core"],"sources":[{"title":"NVIDIA CUDA — Floating-Point Computation and FMA","url":"https://docs.nvidia.com/cuda/cuda-programming-guide/05-appendices/mathematical-functions.html"}],"scale":"Arithmetic datapath; exact size and throughput are implementation-specific","kind":"mac","mechanism":["Multiply the two current operand values.","Combine their product with the accumulator according to the arithmetic format.","Retain or forward the new sum and repeat for the next dot-product term."],"misconception":"Counting a multiply–add as two FLOPs says nothing by itself about clock cycles, units, or achieved application throughput.","check":{"question":"What distinguishes floating-point FMA from separately rounded multiply and add?","options":["FMA never produces rounding error","FMA uses no multiplication","FMA has one final rounding rather than an intermediate product rounding"],"answer":2,"explanation":"The fused operation preserves the product through the addition before rounding, which can change the numerical result."},"branch":"Arithmetic circuits","subbranch":"Accumulation","science":[{"title":"Dot product and matrix entry","equation":"y = Σ_k a_k b_k; C_ij = Σ_k A_ik B_kj","explanation":"A matrix multiplication entry is a dot product. Repeated multiply–accumulate operations combine the contributions while the dataflow determines which values can be reused.","assumptions":"Exact algebra shown; finite-precision evaluation order, rounding, overflow, and accumulation format affect computed values."}],"history":[],"prerequisites":["multiplier","adder"],"learningObjective":"Compute a dot product as successive multiply–accumulate updates and declare the arithmetic format.","engineeringExample":"Worked exact integer dot product: [2, −1, 3] · [4, 5, 2] = 8 − 5 + 6 = 9. Starting at zero, the accumulator holds 8, then 3, then 9. This requires three multiplications and two nontrivial additions; a hardware convention may count three MACs as six operations.","evidenceNotes":"The dot-product identity is exact; the linked floating-point discussion explains why FMA and separately rounded operations can differ. This integer example assumes enough range and does not demonstrate floating-point error.","labId":"matrix","scope":"Inspect row–column products and accumulated results in a small integer matrix; this does not simulate the individual gate network.","investigationId":"switching","labScope":"Inspect row–column products and accumulated results in a small integer matrix; this does not simulate the individual gate network."}