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.
The workflow operates as a closed-loop system:
- Initialization: The system is seeded with expert-crafted reference code from existing TPU-based FHE libraries (Jaxite for TFHE and CROSS for CKKS).
- Mutation: Guided by hardware-aware prompts, an LLM generates candidate code modifications (e.g., altering tensor shapes, loop structures, or data types).
- Hardware-in-the-Loop Evaluation: Candidate kernels are compiled via XLA and executed in a sandbox on physical Google Cloud TPUv5e hardware.
- Multi-Tiered Validation:
- Correctness Checks: Candidates undergo rigorous end-to-end functional testing using randomized input vectors to eliminate LLM hallucinations.
- Security Checks: A lattice estimator ensures that code modifications do not compromise standard security guarantees (e.g., maintaining at least 128-bit security).
- 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 bybf16precision. 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.
- 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_rotatekernel. - 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).
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