Skip to content
Open

abe #159

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 24 additions & 47 deletions .github/workflows/benchmark-self-hosted.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,40 +4,25 @@ on:
workflow_dispatch:
inputs:
param_id:
description: 'Configuration ID (e.g. 36)'
description: "Configuration ID (e.g. 36)"
required: true
default: '36'
default: "36"
data_id:
description: 'Data ID (e.g. 53)'
description: "Data ID (e.g. 53)"
required: true
default: '53'
bench_type:
description: 'Benchmark type'
default: "53"
height:
description: "Height of binary tree"
required: true
type: choice
options:
- add-mul
- plt
default: 'add-mul'
add_num:
description: 'Number of additions (add-mul only)'
required: false
default: '0'
mul_num:
description: 'Number of multiplications (add-mul only)'
required: false
default: '0'
t_num:
description: 't parameter (plt only)'
required: false
default: '0'
default: "1"

env:
CARGO_TERM_COLOR: always

permissions:
id-token: write
contents: read

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref }}
cancel-in-progress: true
Expand Down Expand Up @@ -127,11 +112,18 @@ jobs:
- name: Verify OpenFHE install
run: ls -lah /usr/local/lib | grep OpenFHE

- name: Install dio
run: cargo install --path dio
- name: Checkout arithmetic-abe
uses: actions/checkout@v4
with:
repository: MachinaIO/arithmetic-abe
ref: fix/dir
path: arithmetic-abe

- name: Verify dio
run: which dio
- name: Install abe
run: cargo install --path arithmetic-abe/abe

- name: Verify abe
run: which abe

- name: Run benchmarks (stream + log)
env:
Expand All @@ -140,27 +132,12 @@ jobs:
run: |
mkdir -p logs

case "${{ github.event.inputs.bench_type }}" in
"add-mul")
BENCH_FLAGS="--bench-type add-mul \
--add-num ${{ github.event.inputs.add_num }} \
--mul-num ${{ github.event.inputs.mul_num }}"
;;
"plt")
BENCH_FLAGS="--bench-type plt \
--t-num ${{ github.event.inputs.t_num }}"
;;
*)
echo "Unknown bench_type"; exit 1
;;
esac
echo "Using flags: $BENCH_FLAGS"

# Run abe with hardcoded config path as requested
(
dio run-bench \
-c e2e/dio-config.${{ github.event.inputs.param_id }}.toml \
-o /tmp/data_${{ github.event.inputs.data_id }}_param_${{ github.event.inputs.param_id }} \
$BENCH_FLAGS \
abe run \
--config e2e/dummy.param.toml \
-h ${{ github.event.inputs.height }} \
-d /tmp/data_${{ github.event.inputs.data_id }}_param_${{ github.event.inputs.param_id }} \
2>&1 | tee logs/data_${{ github.event.inputs.data_id }}_param_${{ github.event.inputs.param_id }}.log
) &
pid=$!
Expand Down
15 changes: 15 additions & 0 deletions dio/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,18 @@ pub struct SimBenchNormConfig {
pub base_bits: u32,
pub d: usize,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SimABEConfig {
/// Log2 of the ring dimension
pub log_ring_dim: u32,
/// maximum size of the tower
pub max_crt_depth: usize,
/// number of bits of each tower's modulus
pub crt_bits: usize,
/// bit size of the base for the gadget vector and decomposition
pub base_bits: u32,
pub d: usize,
pub limb_bit_size: usize,
pub input_len: usize,
}
39 changes: 39 additions & 0 deletions dio/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use diamond_io::{
utils::{calculate_directory_size, init_tracing},
};
use mxx::{
arithmetic::circuit::{ArithGateId, ArithmeticCircuit},
bgg::public_key::BggPublicKey,
element::{PolyElem, finite_ring::FinRingElem},
lookup::poly::PolyPltEvaluator,
Expand All @@ -38,6 +39,8 @@ use std::{
};
use tracing::info;

use crate::config::SimABEConfig;

pub mod circuit;
pub mod config;

Expand Down Expand Up @@ -100,6 +103,13 @@ enum Commands {
#[arg(long, requires_if("plt", "bench_type"))]
t_num: Option<usize>,
},
SimABENorm {
#[arg(short, long)]
config: PathBuf,

#[arg(short, long)]
out_path: PathBuf,
},
BuildCircuit {
#[arg(short, long)]
config: PathBuf,
Expand Down Expand Up @@ -287,6 +297,35 @@ async fn main() {
let norm_json = serde_json::to_string(&norms).unwrap();
fs::write(out_path, norm_json.as_bytes()).unwrap()
}
Commands::SimABENorm { config, out_path } => {
let dio_config: SimABEConfig =
serde_json::from_reader(fs::File::open(&config).unwrap()).unwrap();
let log_n = dio_config.log_ring_dim;
let n = 2u32.pow(log_n);
let max_crt_depth = dio_config.max_crt_depth;
let crt_bits = dio_config.crt_bits;
let base_bits = dio_config.base_bits;
let params = DCRTPolyParams::new(n, max_crt_depth, crt_bits, base_bits);
let mut arith = ArithmeticCircuit::<DCRTPoly>::setup(
&params,
dio_config.limb_bit_size,
dio_config.input_len,
false,
true,
);
let add_idx = arith.add(ArithGateId::new(0), ArithGateId::new(1)); // a + b
let mul_idx = arith.mul(add_idx, ArithGateId::new(2)); // (a + b) * c
let final_idx = arith.sub(mul_idx, ArithGateId::new(0)); // (a + b) * c - a
arith.output(final_idx);
let packed_input_norms = vec![BigUint::one(), params.modulus().as_ref().clone()];
let norms = arith.poly_circuit.simulate_bgg_norm(
params.ring_dimension(),
params.base_bits(),
packed_input_norms,
);
let norm_json = serde_json::to_string(&norms).unwrap();
fs::write(out_path, norm_json.as_bytes()).unwrap()
}
Commands::BuildCircuit { config, add_num, mul_num } => {
let contents = fs::read_to_string(&config).unwrap();
let dio_config: RunBenchConfig = toml::from_str(&contents).unwrap();
Expand Down
8 changes: 8 additions & 0 deletions e2e/dummy.param.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
limb_bit_size = 5
crt_depth = 3
crt_bits = 17
e_b_sigma = 0.0
message = [true, false, true, false]
ring_dimension = 4
base_bits = 17
input = [["10", "3", "5", "7"], ["2", "4", "6", "8"], ["1", "1", "1", "1"]]
Loading