diff --git a/.github/workflows/benchmark-self-hosted.yml b/.github/workflows/benchmark-self-hosted.yml index 5197d3ea..0beaf202 100644 --- a/.github/workflows/benchmark-self-hosted.yml +++ b/.github/workflows/benchmark-self-hosted.yml @@ -4,33 +4,17 @@ 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 @@ -38,6 +22,7 @@ env: permissions: id-token: write contents: read + concurrency: group: ${{ github.workflow }}-${{ github.head_ref }} cancel-in-progress: true @@ -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: @@ -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=$! diff --git a/dio/src/config.rs b/dio/src/config.rs index 424e9831..dc320fd1 100644 --- a/dio/src/config.rs +++ b/dio/src/config.rs @@ -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, +} diff --git a/dio/src/main.rs b/dio/src/main.rs index fd3560fc..d32e9236 100644 --- a/dio/src/main.rs +++ b/dio/src/main.rs @@ -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, @@ -38,6 +39,8 @@ use std::{ }; use tracing::info; +use crate::config::SimABEConfig; + pub mod circuit; pub mod config; @@ -100,6 +103,13 @@ enum Commands { #[arg(long, requires_if("plt", "bench_type"))] t_num: Option, }, + SimABENorm { + #[arg(short, long)] + config: PathBuf, + + #[arg(short, long)] + out_path: PathBuf, + }, BuildCircuit { #[arg(short, long)] config: PathBuf, @@ -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::::setup( + ¶ms, + 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(); diff --git a/e2e/dummy.param.toml b/e2e/dummy.param.toml new file mode 100644 index 00000000..60bf636b --- /dev/null +++ b/e2e/dummy.param.toml @@ -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"]]