Adapting AlphaEvolve to Optimize Fully Homomorphic Encryption on TPUs

Shruthi Gorantala, Jianming Tong, Asra Ali, Baiyu Li, Jonathan Katz, Jeremy Kun, Thomas Steinke, Abhradeep Thakurta, Julian Walker, Amir Yazdanbakhsh

TL;DR

Fully Homomorphic Encryption (FHE) allows secure computation on encrypted data but suffers from massive computational overhead. This paper introduces a hardware-in-the-loop framework using AlphaEvolve—an LLM-driven evolutionary search agent—to automatically optimize FHE kernels on Google TPUs, achieving up to a 2.5× speedup over human-expert baselines within just 24 hours.

What Problem Does This Paper Address?

Fully Homomorphic Encryption (FHE) is the holy grail of privacy-preserving computation, enabling data to be processed without ever being decrypted. However, FHE is notoriously slow, incurring a 2-to-5 order-of-magnitude computational and memory overhead.

To make scale deployment feasible, researchers have turned to specialized hardware accelerators like Google Tensor Processing Units (TPUs). Unfortunately, optimizing FHE primitives for TPUs is incredibly challenging. It requires meticulous co-optimization between the Matrix Multiplication Unit (MXU) and Vector Processing Units (VPUs), alongside precise data layout orchestration.

Modern compiler stacks like XLA abstract away these low-level microarchitectural details. As a result, performance engineering becomes a slow, blind "trial-and-error" process where developers must guess which high-level code modifications will nudge the compiler into generating efficient hardware instructions. Furthermore, using AI/LLMs blindly for code generation risks introducing security vulnerabilities or mathematical hallucinations, which are unacceptable in cryptography.

Methods

The authors address this challenge by adapting AlphaEvolve, an agentic framework that combines Large Language Models (LLMs) with evolutionary search algorithms, to automate kernel optimization.

Fig. 3: Workflow for adapting AlphaEvolve to cryptographic kernel optimization. AlphaEvolve samples parent programs, prompts an LLM to generate candidate JAX/Pallas implemen- tations, and evaluates each candidate in a sandbox on TPU hardware. Invalid candidates are rejected by correctness and security checks. Valid candidates are scored by latency and profiled through execution traces. Fast candidates are returned to the evolutionary population for further search.

The workflow operates as a closed-loop system:

  1. Initialization: The system is seeded with expert-crafted reference code from existing TPU-based FHE libraries (Jaxite for TFHE and CROSS for CKKS).
  2. Mutation: Guided by hardware-aware prompts, an LLM generates candidate code modifications (e.g., altering tensor shapes, loop structures, or data types).
  3. Hardware-in-the-Loop Evaluation: Candidate kernels are compiled via XLA and executed in a sandbox on physical Google Cloud TPUv5e hardware.
  4. Multi-Tiered Validation:
  5. Correctness Checks: Candidates undergo rigorous end-to-end functional testing using randomized input vectors to eliminate LLM hallucinations.
  6. Security Checks: A lattice estimator ensures that code modifications do not compromise standard security guarantees (e.g., maintaining at least 128-bit security).
  7. Feedback: Successful candidates are scored based on real-world microsecond-level execution latency. High-fidelity hardware execution traces (via Xprof) are fed back to the LLM as diagnostic feedback to guide the next generation of mutations.

Datasets

Because this paper focuses on cryptographic kernel optimization rather than machine learning training, standard datasets were not used. Instead, the framework was evaluated using:

  • Jaxite: An open-source, expert-crafted TFHE implementation targeting TPUs.
  • CROSS: A state-of-the-art TPU-based CKKS library.
  • Functional Testbeds: Randomized input vectors and fixed ciphertext-plaintext pairs used to validate mathematical correctness across 3-bit lookup tables and polynomial rings.

Key Insights and Ideas

AlphaEvolve discovered several highly effective, non-intuitive optimization patterns that human engineers frequently miss:

  • Elimination of Redundant Type Casts: In the TFHE implementation, human experts explicitly cast an operand to 8-bit integers (int8). AlphaEvolve realized that the dynamic range was already safely captured by bf16 precision. Removing this expensive bitcast operator single-handedly cut execution time nearly in half.
  • XLA-Favorable Tiling: The compiler often leaves substantial Vector Register (VReg) capacity unused if operations don't match the hardware grain. AlphaEvolve discovered specific tensor shapes that forced XLA to maximize VReg utilization.
Fig. 4: Effect of the discovered layout changes. The initial program leaves substantial VReg capacity unused because operations are expressed at a granularity that does not match VReg. The evolved program exposes fuller VReg utilization.
  • Fine-Grained Memory Scheduling: By tiling a massive JAX tensor into two smaller blocks, the agent allowed the XLA compiler to schedule data loading from off-chip memory more efficiently, effectively hiding memory latency behind active computation.

Key Results

Within a 24-hour exploration window using 100 TPUv5e chips, AlphaEvolve significantly outperformed domain-expert baselines:

  • TFHE Bootstrapping: Achieved a 2.5× reduction in overall latency (dropping from 10 ms to 4 ms), driven by a 2.85× speedup in the critical blind_rotate kernel.
  • CKKS Operations: Discovered optimizations yielding a 1.31× speedup for slot rotation (CKKS-Rot) and a 1.18× speedup for slot-wise multiplication (CKKS-Mult).
TABLE I: Latency Comparison to SoTA [2], [18]

Limitations and Future Work

While highly effective, the authors note a few limitations and areas for future development:

  • Human-in-the-Loop Review: Currently, a human programmer must manually review and merge the best-performing code blocks because automated functional equivalence checking remains an unsolved research problem.
  • Hardware Specificity: The current study focused exclusively on Google TPUs. Future work includes extending the framework to other hardware accelerators (like GPUs) and integrating it with hardware simulators to enable hardware-software co-design.
  • Algorithmic Discovery: The reward functions are currently constrained to implementation-level tuning. A fundamental open question is how to safely design reward functions that allow AI agents to discover entirely novel cryptographic algorithms without breaking security guarantees.

Summary updated

BibTeX
@inproceedings{gorantala2026adapting,
  author = {Shruthi Gorantala and Jianming Tong and Asra Ali and Baiyu Li and Jonathan Katz and Jeremy Kun and Thomas Steinke and Abhradeep Thakurta and Julian Walker and Amir Yazdanbakhsh},
  title = {{Adapting AlphaEvolve to Optimize Fully Homomorphic Encryption on TPUs}},
  booktitle = {MLArchSys @ ISCA},
  year = {2026},
  url = {https://openreview.net/forum?id=ZPQh6Fkctd},
}

Loading related content...

Figure