-
Notifications
You must be signed in to change notification settings - Fork 722
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add CKKS/BFV Negate and Sub Ptxt/Ctxt benchmarks
Add benchmarks of high and low level NTT API Add faster low level NTT benchmark
- Loading branch information
1 parent
c2f4d37
commit 99a952c
Showing
6 changed files
with
228 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT license. | ||
|
||
#include "seal/seal.h" | ||
#include "seal/util/rlwe.h" | ||
#include "bench.h" | ||
|
||
using namespace benchmark; | ||
using namespace sealbench; | ||
using namespace seal; | ||
using namespace std; | ||
|
||
/** | ||
This file defines benchmarks for NTT-related HE primitives. | ||
*/ | ||
|
||
namespace sealbench | ||
{ | ||
void bm_forward_ntt(State &state, shared_ptr<BMEnv> bm_env) | ||
{ | ||
vector<Ciphertext> &ct = bm_env->ct(); | ||
for (auto _ : state) | ||
{ | ||
state.PauseTiming(); | ||
bm_env->randomize_ct_bfv(ct[0]); | ||
|
||
state.ResumeTiming(); | ||
bm_env->evaluator()->transform_to_ntt(ct[0], ct[2]); | ||
} | ||
} | ||
|
||
void bm_inverse_ntt(State &state, shared_ptr<BMEnv> bm_env) | ||
{ | ||
vector<Ciphertext> &ct = bm_env->ct(); | ||
for (auto _ : state) | ||
{ | ||
state.PauseTiming(); | ||
bm_env->randomize_ct_bfv(ct[0]); | ||
bm_env->evaluator()->transform_to_ntt_inplace(ct[0]); | ||
|
||
state.ResumeTiming(); | ||
bm_env->evaluator()->transform_from_ntt(ct[0], ct[2]); | ||
} | ||
} | ||
|
||
void bm_forward_ntt_low_level(State &state, shared_ptr<BMEnv> bm_env) | ||
{ | ||
parms_id_type parms_id = bm_env->context().first_parms_id(); | ||
auto context_data = bm_env->context().get_context_data(parms_id); | ||
const auto &small_ntt_tables = context_data->small_ntt_tables(); | ||
vector<Ciphertext> &ct = bm_env->ct(); | ||
for (auto _ : state) | ||
{ | ||
state.PauseTiming(); | ||
bm_env->randomize_ct_bfv(ct[0]); | ||
|
||
state.ResumeTiming(); | ||
ntt_negacyclic_harvey(ct[0].data(), small_ntt_tables[0]); | ||
} | ||
} | ||
|
||
void bm_inverse_ntt_low_level(State &state, shared_ptr<BMEnv> bm_env) | ||
{ | ||
parms_id_type parms_id = bm_env->context().first_parms_id(); | ||
auto context_data = bm_env->context().get_context_data(parms_id); | ||
const auto &small_ntt_tables = context_data->small_ntt_tables(); | ||
vector<Ciphertext> &ct = bm_env->ct(); | ||
for (auto _ : state) | ||
{ | ||
state.PauseTiming(); | ||
bm_env->randomize_ct_bfv(ct[0]); | ||
|
||
state.ResumeTiming(); | ||
inverse_ntt_negacyclic_harvey(ct[0].data(), small_ntt_tables[0]); | ||
} | ||
} | ||
|
||
void bm_forward_ntt_low_level_lazy(State &state, shared_ptr<BMEnv> bm_env) | ||
{ | ||
parms_id_type parms_id = bm_env->context().first_parms_id(); | ||
auto context_data = bm_env->context().get_context_data(parms_id); | ||
const auto &small_ntt_tables = context_data->small_ntt_tables(); | ||
vector<Ciphertext> &ct = bm_env->ct(); | ||
for (auto _ : state) | ||
{ | ||
state.PauseTiming(); | ||
bm_env->randomize_ct_bfv(ct[0]); | ||
|
||
state.ResumeTiming(); | ||
ntt_negacyclic_harvey_lazy(ct[0].data(), small_ntt_tables[0]); | ||
} | ||
} | ||
|
||
void bm_inverse_ntt_low_level_lazy(State &state, shared_ptr<BMEnv> bm_env) | ||
{ | ||
parms_id_type parms_id = bm_env->context().first_parms_id(); | ||
auto context_data = bm_env->context().get_context_data(parms_id); | ||
const auto &small_ntt_tables = context_data->small_ntt_tables(); | ||
vector<Ciphertext> &ct = bm_env->ct(); | ||
for (auto _ : state) | ||
{ | ||
state.PauseTiming(); | ||
bm_env->randomize_ct_bfv(ct[0]); | ||
|
||
state.ResumeTiming(); | ||
inverse_ntt_negacyclic_harvey_lazy(ct[0].data(), small_ntt_tables[0]); | ||
} | ||
} | ||
} // namespace sealbench |