Skip to content

Commit

Permalink
fix(bench): use correct name for parameters in wasm benches
Browse files Browse the repository at this point in the history
  • Loading branch information
nsarlin-zama committed Jan 7, 2025
1 parent e0a264d commit 8f3ed22
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 25 deletions.
12 changes: 12 additions & 0 deletions tfhe/src/js_on_wasm_api/shortint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,13 +284,25 @@ macro_rules! expose_predefined_parameters {
$(,)?
) => {
#[wasm_bindgen]
#[derive(Clone, Copy)]
#[allow(non_camel_case_types)]
pub enum ShortintParametersName {
$(
$param_name,
)*
}

// wasm bindgen does not support methods on enums
#[wasm_bindgen]
pub fn shortint_params_name(param: ShortintParametersName) -> String {
match param {
$(
ShortintParametersName::$param_name => stringify!($param_name).to_string(),
)*
}
}


#[wasm_bindgen]
impl ShortintParameters {
#[wasm_bindgen(constructor)]
Expand Down
45 changes: 20 additions & 25 deletions tfhe/web_wasm_parallel_tests/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import init, {
initThreadPool,
init_panic_hook,
set_server_key,
shortint_params_name,
ShortintParametersName,
ShortintParameters,
TfheClientKey,
Expand Down Expand Up @@ -159,28 +160,26 @@ async function compactPublicKeyBench32BitOnConfig(config) {
}

async function compactPublicKeyBench32BitBig() {
const block_params = new ShortintParameters(
ShortintParametersName.V0_11_PARAM_MESSAGE_2_CARRY_2_COMPACT_PK_KS_PBS_GAUSSIAN_2M64,
);
const params = ShortintParametersName.V0_11_PARAM_MESSAGE_2_CARRY_2_COMPACT_PK_KS_PBS_GAUSSIAN_2M64;
const block_params = new ShortintParameters(params);
let config = TfheConfigBuilder.default()
.use_custom_parameters(block_params)
.build();
return append_param_name(
await compactPublicKeyBench32BitOnConfig(config),
"PARAM_MESSAGE_2_CARRY_2_COMPACT_PK_KS_PBS_GAUSSIAN_2M64",
shortint_params_name(params),
);
}

async function compactPublicKeyBench32BitSmall() {
const block_params = new ShortintParameters(
ShortintParametersName.V0_11_PARAM_MESSAGE_2_CARRY_2_COMPACT_PK_PBS_KS_GAUSSIAN_2M64,
);
const params = ShortintParametersName.V0_11_PARAM_MESSAGE_2_CARRY_2_COMPACT_PK_PBS_KS_GAUSSIAN_2M64;
const block_params = new ShortintParameters(params);
let config = TfheConfigBuilder.default()
.use_custom_parameters(block_params)
.build();
return append_param_name(
await compactPublicKeyBench32BitOnConfig(config),
"PARAM_MESSAGE_2_CARRY_2_COMPACT_PK_PBS_KS_GAUSSIAN_2M64",
shortint_params_name(params),
);
}

Expand Down Expand Up @@ -556,28 +555,26 @@ async function compactPublicKeyBench256BitOnConfig(config) {
}

async function compactPublicKeyBench256BitBig() {
const block_params = new ShortintParameters(
ShortintParametersName.V0_11_PARAM_MESSAGE_2_CARRY_2_COMPACT_PK_KS_PBS_GAUSSIAN_2M64,
);
const params = ShortintParametersName.V0_11_PARAM_MESSAGE_2_CARRY_2_COMPACT_PK_KS_PBS_GAUSSIAN_2M64;
const block_params = new ShortintParameters(params);
let config = TfheConfigBuilder.default()
.use_custom_parameters(block_params)
.build();
return append_param_name(
await compactPublicKeyBench256BitOnConfig(config),
"PARAM_MESSAGE_2_CARRY_2_COMPACT_PK_KS_PBS_GAUSSIAN_2M64",
shortint_params_name(params),
);
}

async function compactPublicKeyBench256BitSmall() {
const block_params = new ShortintParameters(
ShortintParametersName.V0_11_PARAM_MESSAGE_2_CARRY_2_COMPACT_PK_PBS_KS_GAUSSIAN_2M64,
);
const params = ShortintParametersName.V0_11_PARAM_MESSAGE_2_CARRY_2_COMPACT_PK_PBS_KS_GAUSSIAN_2M64;
const block_params = new ShortintParameters(params);
let config = TfheConfigBuilder.default()
.use_custom_parameters(block_params)
.build();
return append_param_name(
await compactPublicKeyBench256BitOnConfig(config),
"PARAM_MESSAGE_2_CARRY_2_COMPACT_PK_PBS_KS_GAUSSIAN_2M64",
shortint_params_name(params),
);
}

Expand Down Expand Up @@ -616,35 +613,33 @@ async function compressedServerKeyBenchConfig(config) {
}

async function compressedServerKeyBenchMessage1Carry1() {
const block_params = new ShortintParameters(
ShortintParametersName.V0_11_PARAM_MESSAGE_1_CARRY_1_KS_PBS_GAUSSIAN_2M64,
);
const params = ShortintParametersName.V0_11_PARAM_MESSAGE_1_CARRY_1_KS_PBS_GAUSSIAN_2M64;
const block_params = new ShortintParameters(params);
let config = TfheConfigBuilder.default()
.use_custom_parameters(block_params)
.build();
return append_param_name(
await compressedServerKeyBenchConfig(config),
"PARAM_MESSAGE_1_CARRY_1_KS_PBS_GAUSSIAN_2M64",
shortint_params_name(params),
);
}

async function compressedServerKeyBenchMessage2Carry2() {
const block_params = new ShortintParameters(
ShortintParametersName.V0_11_PARAM_MESSAGE_2_CARRY_2_KS_PBS_GAUSSIAN_2M64,
);
const params = ShortintParametersName.V0_11_PARAM_MESSAGE_2_CARRY_2_KS_PBS_GAUSSIAN_2M64;
const block_params = new ShortintParameters(params);
let config = TfheConfigBuilder.default()
.use_custom_parameters(block_params)
.build();
return append_param_name(
await compressedServerKeyBenchConfig(config),
"PARAM_MESSAGE_2_CARRY_2_KS_PBS_GAUSSIAN_2M64",
shortint_params_name(params),
);
}

async function compactPublicKeyZeroKnowledgeBench() {
let params_to_bench = [
{
name: "PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M64",
name: shortint_params_name(ShortintParametersName.PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M64),
block_params: new ShortintParameters(
ShortintParametersName.PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M64,
),
Expand Down

0 comments on commit 8f3ed22

Please sign in to comment.