FHE Accelerator Simulators — Presentation 01

FHE for Hardware Engineers: CKKS as a Workload

CKKS seen from the datapath, not the proof: RNS polynomials in Zq[X]/(XN+1), how big ciphertexts and evaluation keys really are, the five primitive kernels (NTT, modular multiply-add, automorphism, base conversion, rescale), noise and levels, and why key switching dominates. Includes a live parameter calculator.

CKKS RNS NTT Key switching dnum Evaluation keys
Encode → Encrypt → HMult / HRot → Key switch → Rescale → Bootstrap
00

Topics We'll Cover

Concepts used here, and where they are explained. Each links to its series glossary entry: a short explanation, then links to the slides that explain it in depth, in this series, the Cryptography decks or LLM Inference Simulators.

01

Why FHE Is a Hardware Problem

Fully homomorphic encryption lets a server compute on data it cannot read. The price is speed: the F1 paper (Feldmann et al., MICRO 2021) puts software FHE at four to five orders of magnitude slower than computing on plaintext. Closing that gap is an architecture problem, so it is a simulation problem.

What makes it hard for hardware

  • Every value is a polynomial with tens of thousands of coefficients, stored as dozens of machine-word residues.
  • Multiplying two ciphertexts needs a key switch: hundreds of transforms and a read of an evaluation key over 100 MiB in size.
  • Noise accumulates; bootstrapping resets it, at a cost of hundreds of key switches (deck 02).

What this series does with it

  • Treats CKKS as a workload: shapes, sizes, kernel counts and bytes.
  • Simulates an accelerator running bootstrapping in SimPy (deck 03), live in the browser.
  • Asks whether an optical transform engine helps (deck 04) and what the design space looks like (deck 05).
Scope

This deck is about cost, not security. It uses the cryptography only as far as a datapath designer needs it, and points to the Cryptography series for the rest.

02

Fundamentals: Where to Learn the Mathematics

The mathematics is covered elsewhere on this GitHub, and this series stays consistent with its notation (one change: the ring degree is written N here, as in the bootstrapping literature, where Cryptography deck 08 writes n).

03

The Data: RNS Polynomials

A CKKS ciphertext is a pair of polynomials (c0, c1) in RQ = ZQ[X]/(XN+1). Q is a product of word-sized primes, Q = q0q1…qℓ, so each polynomial is stored as one row of N residues per prime: the residue number system (RNS). Arithmetic never needs multi-word integers.

One ciphertext at level ℓ: 2 polynomials × (ℓ+1) limbs × N words c0 mod q0 [N = 65,536 coefficients] c0 mod q1 ⋮ c0 mod qℓ c1 mod q0 c1 mod q1 ⋮ c1 mod qℓ rows ("limbs") are independent: every limb can be processed in parallel columns are coupled only by base conversion (moving between prime sets) and rescale N = 2^16, L = 23: 2 x 24 x 65,536 x 8 B = 24 MiB per fresh ciphertext Slots: N/2 = 32,768 complex numbers packed into one ciphertext (SIMD)
04

How Big Things Are

Sizes for the parameter sets used throughout the series, as computed by params.py. The ARK and Lattigo rows match Table III of ARK (Kim et al., MICRO 2022, arXiv:2205.00922) exactly.

SetNLdnumαCiphertext (top)Evaluation keylog PQ (approx.)
ark216234624.0 MiB120.0 MiB1,570
lattigo216245525.0 MiB150.0 MiB1,560
gpu100x216345735.0 MiB210.0 MiB2,180
openfhe-sparse216183719.0 MiB78.0 MiB1,542
05

The Primitive Kernels

Every HE operation decomposes into five kernels. These are the units a hardware designer builds and a simulator models.

KernelWhat it doesWork per limbHardware
NTT / iNTTCoefficient ↔ evaluation form; the finite-field FFT(N/2) log2N butterflies: 524,288 at N = 216Pipelined butterfly arrays (deck 10 of Cryptography)
Modular multiply-addElement-wise products and sums: tensor products, plaintext multiplies, key inner productsN multiply-addsWide SIMD lanes with Barrett or Montgomery reduction
AutomorphismX → X5r: permutes coefficients to rotate slotsN words movedA permutation network; no arithmetic
Base conversionRe-expresses a polynomial from one prime set in another (ModUp, ModDown)N × (input limbs) multiply-adds per output limbMatrix-vector datapath; often the second-largest cost
RescaleDivides by the last prime, dropping a limbAn iNTT, an NTT per remaining limb, a multiply-addBuilt from the above

The companion simulator's trace format (deck 03) is exactly this list: every HE operation becomes a sequence of these kernels, each with an amount of work and a number of on-chip words touched.

06

Noise, Scale and Levels

CKKS in four lines

  • A real or complex vector is encoded with a scale Δ (for example 250), so the plaintext carries fixed-point numbers.
  • Encryption adds small noise; CKKS treats it as part of the approximation error.
  • A multiplication doubles the scale (Δ2). Rescale divides by a prime qℓ ≈ Δ to bring it back, and drops one limb.
  • So each multiplicative level costs one prime. A ciphertext at level 0 has one limb left and can no longer be multiplied.

What that means for hardware

  • Work shrinks with depth: an operation at level ℓ touches ℓ+1 limbs, so the same HMult is cheaper late in a computation.
  • L is a budget: more levels mean bigger ciphertexts and keys for every operation, not only the deep ones.
  • Bootstrapping raises a level-0 ciphertext back to a high level, but spends about 16 of the L = 23 levels in our model doing so (deck 02). The useful levels between bootstraps are what applications are left with.
The level is part of the workload

A cost model that ignores the level an operation runs at is wrong by up to a factor of L+1. The companion simulator tracks the level of every ciphertext object.

07

Key Switching, Step by Step

After a multiplication (relinearisation) or an automorphism (rotation), part of the ciphertext is "encrypted" under the wrong key. Key switching fixes it using an evaluation key. The hybrid method (Han & Ki, CT-RSA 2020, ePrint 2019/688) splits the limbs into dnum digits of α limbs each:

iNTTℓ+1 limbs ModUp: BConveach digit → P·Q NTTnew limbs inner productwith evk (HBM!) iNTT2×k special ModDown: BConv+ NTT 2(ℓ+1) ark set, one HRotate at the top level: 180 limb transforms (NTT + iNTT), 62.1 M base-conversion multiply-adds, 15.7 M other multiply-adds, and a 120 MiB evaluation key read once. counts from summarise_trace(he_op_trace(ark, "hrot")); tests re-derive them from hand formulas

Transforms per key switch at level ℓ (with ℓ+1 limbs, k = α special primes and β = ⌈(ℓ+1)/α⌉ digits): (ℓ+1) + Σdigits(ℓ+1+k−αi) + 2k + 2(ℓ+1). For the ark set at the top level: 24 + 96 + 12 + 48 = 180.

08

Why Key Switching Dominates

One op, ark set, top levelNTT + iNTT limbsBase-conversion multiply-addsOther multiply-addsKey loadedTime on the ARK-class model
HMult (with relinearisation and rescale)22862.1 M28.2 M120 MiB263.4 µs
HRotate18062.1 M15.7 M120 MiB220.7 µs
The one-sentence version

FHE accelerators are NTT engines welded to a memory system that must stream evaluation keys, and the hard part is the memory system.

09

Interactive: Parameter Calculator

Choose N, L, dnum and the level an operation runs at. Sizes come from the same formulas as params.py; kernel counts come from the simulator's own trace generator (the JavaScript port, tested to match the Python exactly).

16
23
4
23
50
10

The dnum Trade-Off

dnum sets how many digits the key-switch input is split into. Fewer digits mean fewer, wider special primes: smaller keys and less work, but a larger total modulus PQ, which at fixed N reduces security or levels. From examples/results.py (N = 216, L = 23, top level):

dnumα = klog PQEvaluation keyLimb transforms per HRotBase-conversion multiply-addsHRot on ARK-class
1242,65048 MiB144121 M143 µs
2121,93072 MiB14482 M164 µs
461,570120 MiB18062 M221 µs
831,390216 MiB27052 M341 µs
2411,270600 MiB65046 M832 µs
11

What a Simulator Needs from All This

Must modelBecauseIn the companion simulator
Level of every ciphertextWork and bytes scale with ℓ+1Trace.levels; every kernel sized at its level
Key identity, not just key sizeReuse decides whether SRAM helpsKeys are named objects in the scratchpad
NTT, base conversion, multiply-add, automorphism separatelyThey map to different units with different throughputsFour kernel kinds, three digital units plus an optional optical unit
DependenciesBootstrapping is a DAG with limited parallelismProducer/consumer edges between HE ops
Parameter sets as dataN, L and dnum are design choices to sweepCKKSParams presets and the calculator above
12

What to Take Away

Next

Deck 02 opens up bootstrapping, the operation that strings hundreds of these key switches together and turns FHE into a memory-bandwidth problem.