From 8f3ed2289f12d5e6d8d40f9e97189667c4217f3b Mon Sep 17 00:00:00 2001 From: Nicolas Sarlin Date: Tue, 7 Jan 2025 17:35:42 +0100 Subject: [PATCH] fix(bench): use correct name for parameters in wasm benches --- tfhe/src/js_on_wasm_api/shortint.rs | 12 +++++++ tfhe/web_wasm_parallel_tests/worker.js | 45 ++++++++++++-------------- 2 files changed, 32 insertions(+), 25 deletions(-) diff --git a/tfhe/src/js_on_wasm_api/shortint.rs b/tfhe/src/js_on_wasm_api/shortint.rs index 8d9fa6d05b..22da007bce 100644 --- a/tfhe/src/js_on_wasm_api/shortint.rs +++ b/tfhe/src/js_on_wasm_api/shortint.rs @@ -284,6 +284,7 @@ macro_rules! expose_predefined_parameters { $(,)? ) => { #[wasm_bindgen] + #[derive(Clone, Copy)] #[allow(non_camel_case_types)] pub enum ShortintParametersName { $( @@ -291,6 +292,17 @@ macro_rules! expose_predefined_parameters { )* } + // 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)] diff --git a/tfhe/web_wasm_parallel_tests/worker.js b/tfhe/web_wasm_parallel_tests/worker.js index 4090e73b24..6fc498c069 100644 --- a/tfhe/web_wasm_parallel_tests/worker.js +++ b/tfhe/web_wasm_parallel_tests/worker.js @@ -3,6 +3,7 @@ import init, { initThreadPool, init_panic_hook, set_server_key, + shortint_params_name, ShortintParametersName, ShortintParameters, TfheClientKey, @@ -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), ); } @@ -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), ); } @@ -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, ),