|
| 1 | +Bootstrap: docker |
| 2 | +From: ubuntu:24.04 |
| 3 | + |
| 4 | +# ============================================================================ |
| 5 | +# compare-tfhers.def — Apptainer image for local TFHEpp vs tfhe-rs comparison |
| 6 | +# |
| 7 | +# Build (from the TFHEpp repository root, submodules must be initialised): |
| 8 | +# git submodule update --init --recursive # if not done yet |
| 9 | +# apptainer build compare-tfhers.sif compare-tfhers.def |
| 10 | +# |
| 11 | +# Run the benchmark: |
| 12 | +# apptainer run compare-tfhers.sif |
| 13 | +# |
| 14 | +# Both sides use identical parameters (tfhe-rs DEFAULT_PARAMETERS, 132-bit): |
| 15 | +# n=805, k=3, N=512, pbs_level=2, pbs_base_log=10, |
| 16 | +# ks_level=5, ks_base_log=3 |
| 17 | +# ============================================================================ |
| 18 | + |
| 19 | +%labels |
| 20 | + Description TFHEpp vs tfhe-rs NAND-gate PBS comparison on Ubuntu 24.04 |
| 21 | + |
| 22 | +%environment |
| 23 | + export PATH="/root/.cargo/bin:${PATH}" |
| 24 | + export WORKSPACE="/opt/tfhe-compare" |
| 25 | + |
| 26 | +# Copy the local TFHEpp source tree (including initialised submodules) into |
| 27 | +# the container at build time. Run `apptainer build` from the TFHEpp root. |
| 28 | +%files |
| 29 | + CMakeLists.txt /opt/tfhe-compare/TFHEpp/CMakeLists.txt |
| 30 | + include /opt/tfhe-compare/TFHEpp/include |
| 31 | + src /opt/tfhe-compare/TFHEpp/src |
| 32 | + test /opt/tfhe-compare/TFHEpp/test |
| 33 | + bench-tfhers /opt/tfhe-compare/TFHEpp/bench-tfhers |
| 34 | + thirdparties /opt/tfhe-compare/TFHEpp/thirdparties |
| 35 | + |
| 36 | +%post |
| 37 | + export DEBIAN_FRONTEND=noninteractive |
| 38 | + export PATH="/root/.cargo/bin:${PATH}" |
| 39 | + export WORKSPACE="/opt/tfhe-compare" |
| 40 | + |
| 41 | + # ── System packages ────────────────────────────────────────────────────── |
| 42 | + apt-get update |
| 43 | + apt-get upgrade -y |
| 44 | + apt-get install -y \ |
| 45 | + build-essential g++ libomp-dev cmake ninja-build \ |
| 46 | + git curl wget ca-certificates |
| 47 | + |
| 48 | + # ── Rust toolchain (stable + let tfhe-rs pin its own version) ──────────── |
| 49 | + curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs \ |
| 50 | + | sh -s -- -y --default-toolchain stable --no-modify-path |
| 51 | + |
| 52 | + # ── Clone tfhe-rs alongside TFHEpp ─────────────────────────────────────── |
| 53 | + # bench-tfhers/Cargo.toml expects: ../tfhe-rs/tfhe (relative to bench-tfhers/) |
| 54 | + cd "${WORKSPACE}/TFHEpp" |
| 55 | + git clone --depth 1 https://github.com/zama-ai/tfhe-rs.git tfhe-rs |
| 56 | + |
| 57 | + # ── Build TFHEpp pbs_tfhers benchmark ──────────────────────────────────── |
| 58 | + cmake . -B build -G Ninja \ |
| 59 | + -DCMAKE_BUILD_TYPE=Release \ |
| 60 | + -DUSE_TFHE_RS=ON \ |
| 61 | + -DENABLE_TEST=ON |
| 62 | + cmake --build build --target pbs_tfhers |
| 63 | + |
| 64 | + # ── Build tfhe-rs Rust benchmark ───────────────────────────────────────── |
| 65 | + cd bench-tfhers |
| 66 | + # Download the Rust toolchain pinned in rust-toolchain.toml |
| 67 | + rustup show |
| 68 | + cargo build --release |
| 69 | + cd .. |
| 70 | + |
| 71 | + # Remove large intermediate artefacts to keep image size small |
| 72 | + rm -rf build/_deps build/CMakeFiles |
| 73 | + |
| 74 | +%runscript |
| 75 | + export PATH="/root/.cargo/bin:${PATH}" |
| 76 | + TFHEPP_ROOT="/opt/tfhe-compare/TFHEpp" |
| 77 | + |
| 78 | + echo "============================================================" |
| 79 | + echo " TFHEpp vs tfhe-rs — NAND gate bootstrap comparison" |
| 80 | + echo " Parameter set: tfhe-rs DEFAULT_PARAMETERS (132-bit security)" |
| 81 | + echo " n=805 k=3 N=512 pbs_level=2 pbs_base_log=10" |
| 82 | + echo " ks_level=5 ks_base_log=3" |
| 83 | + echo "============================================================" |
| 84 | + echo "" |
| 85 | + |
| 86 | + echo "--- Machine info ---" |
| 87 | + lscpu 2>/dev/null | grep -E "Model name|CPU\(s\)|Thread|MHz" || true |
| 88 | + free -h 2>/dev/null || true |
| 89 | + echo "" |
| 90 | + |
| 91 | + echo "--- TFHEpp (C++, USE_TFHE_RS) ---" |
| 92 | + "${TFHEPP_ROOT}/build/test/pbs_tfhers" |
| 93 | + echo "" |
| 94 | + |
| 95 | + echo "--- tfhe-rs (Rust, DEFAULT_PARAMETERS) ---" |
| 96 | + "${TFHEPP_ROOT}/bench-tfhers/target/release/pbs-tfhers-bench" |
| 97 | + echo "" |
| 98 | + echo "Done." |
| 99 | + |
| 100 | +%help |
| 101 | + Runs a NAND gate bootstrapping benchmark comparing TFHEpp and tfhe-rs |
| 102 | + using identical parameters (tfhe-rs DEFAULT_PARAMETERS, 132-bit security). |
| 103 | + |
| 104 | + Prerequisites (on the build host): |
| 105 | + git submodule update --init --recursive |
| 106 | + |
| 107 | + Build the image (requires internet access, run from TFHEpp root): |
| 108 | + apptainer build compare-tfhers.sif compare-tfhers.def |
| 109 | + |
| 110 | + Run: |
| 111 | + apptainer run compare-tfhers.sif |
0 commit comments