mirror of
https://github.com/zama-ai/concrete.git
synced 2026-02-08 03:25:05 -05:00
test(concrete_cuda): test more PBS parameters
This commit is contained in:
6
.github/workflows/concrete_cuda_test.yml
vendored
6
.github/workflows/concrete_cuda_test.yml
vendored
@@ -83,6 +83,12 @@ jobs:
|
||||
echo "CXX=/usr/bin/g++-${{ matrix.gcc }}" >> "${GITHUB_ENV}"
|
||||
echo "CUDAHOSTCXX=/usr/bin/g++-${{ matrix.gcc }}" >> "${GITHUB_ENV}"
|
||||
echo "HOME=/home/ubuntu" >> "${GITHUB_ENV}"
|
||||
|
||||
- name: Rust install
|
||||
uses: actions-rs/toolchain@v1
|
||||
with:
|
||||
toolchain: stable
|
||||
|
||||
- name: Build concrete-cuda
|
||||
if: ${{ !cancelled() }}
|
||||
run: |
|
||||
|
||||
@@ -88,8 +88,10 @@ public:
|
||||
int input_lwe_dimension = glwe_dimension * polynomial_size;
|
||||
int output_lwe_dimension = lwe_dimension;
|
||||
// Generate the keys
|
||||
generate_lwe_secret_keys(&lwe_sk_in_array, input_lwe_dimension, csprng, REPETITIONS);
|
||||
generate_lwe_secret_keys(&lwe_sk_out_array, output_lwe_dimension, csprng, REPETITIONS);
|
||||
generate_lwe_secret_keys(&lwe_sk_in_array, input_lwe_dimension, csprng,
|
||||
REPETITIONS);
|
||||
generate_lwe_secret_keys(&lwe_sk_out_array, output_lwe_dimension, csprng,
|
||||
REPETITIONS);
|
||||
generate_lwe_keyswitch_keys(
|
||||
stream, gpu_index, &d_ksk_array, lwe_sk_in_array, lwe_sk_out_array,
|
||||
input_lwe_dimension, output_lwe_dimension, ks_level, ks_base_log,
|
||||
@@ -98,8 +100,9 @@ public:
|
||||
stream, gpu_index, &d_fourier_bsk_array, lwe_sk_out_array,
|
||||
lwe_sk_in_array, lwe_dimension, glwe_dimension, polynomial_size,
|
||||
pbs_level, pbs_base_log, csprng, glwe_modular_variance, REPETITIONS);
|
||||
plaintexts = generate_plaintexts(
|
||||
number_of_bits_of_message_including_padding, delta, number_of_inputs, REPETITIONS, SAMPLES);
|
||||
plaintexts =
|
||||
generate_plaintexts(number_of_bits_of_message_including_padding, delta,
|
||||
number_of_inputs, REPETITIONS, SAMPLES);
|
||||
|
||||
d_lwe_out_ct_array = (uint64_t *)cuda_malloc_async(
|
||||
(output_lwe_dimension + 1) * number_of_bits_to_extract *
|
||||
@@ -224,9 +227,11 @@ TEST_P(BitExtractionTestPrimitives_u64, bit_extraction) {
|
||||
// ks_base_log, ks_level, number_of_message_bits,
|
||||
// number_of_bits_to_extract
|
||||
(BitExtractionTestParams){585, 1, 1024, 7.52316384526264e-37,
|
||||
7.52316384526264e-37, 10, 2, 4, 7, 5, 5, 1});//,
|
||||
7.52316384526264e-37, 10, 2, 4, 7, 5, 5,
|
||||
1}); //,
|
||||
// (BitExtractionTestParams){585, 1, 1024, 7.52316384526264e-37,
|
||||
// 7.52316384526264e-37, 10, 2, 4, 7, 5, 5, 2});
|
||||
// 7.52316384526264e-37, 10, 2, 4, 7, 5, 5,
|
||||
// 2});
|
||||
|
||||
std::string
|
||||
printParamName(::testing::TestParamInfo<BitExtractionTestParams> p) {
|
||||
|
||||
@@ -81,15 +81,17 @@ public:
|
||||
csprng, Uint128{.little_endian_bytes = {*seed}});
|
||||
|
||||
// Generate the keys
|
||||
generate_lwe_secret_keys(&lwe_sk_in_array, lwe_dimension, csprng, REPETITIONS);
|
||||
generate_lwe_secret_keys(&lwe_sk_in_array, lwe_dimension, csprng,
|
||||
REPETITIONS);
|
||||
generate_lwe_secret_keys(&lwe_sk_out_array,
|
||||
glwe_dimension * polynomial_size, csprng, REPETITIONS);
|
||||
glwe_dimension * polynomial_size, csprng,
|
||||
REPETITIONS);
|
||||
generate_lwe_bootstrap_keys(
|
||||
stream, gpu_index, &d_fourier_bsk_array, lwe_sk_in_array,
|
||||
lwe_sk_out_array, lwe_dimension, glwe_dimension, polynomial_size,
|
||||
pbs_level, pbs_base_log, csprng, glwe_modular_variance, REPETITIONS);
|
||||
plaintexts = generate_plaintexts(payload_modulus, delta, number_of_inputs, REPETITIONS,
|
||||
SAMPLES);
|
||||
plaintexts = generate_plaintexts(payload_modulus, delta, number_of_inputs,
|
||||
REPETITIONS, SAMPLES);
|
||||
|
||||
// Create the LUT
|
||||
uint64_t *lut_pbs_identity = generate_identity_lut_pbs(
|
||||
@@ -290,13 +292,56 @@ TEST_P(BootstrapTestPrimitives_u64, low_latency_bootstrap) {
|
||||
::testing::internal::ParamGenerator<BootstrapTestParams> pbs_params_u64 =
|
||||
::testing::Values(
|
||||
// n, k, N, lwe_variance, glwe_variance, pbs_base_log, pbs_level,
|
||||
// message_modulus, carry_modulus
|
||||
(BootstrapTestParams){500, 1, 1024, 0.000007069849454709433,
|
||||
0.00000000000000029403601535432533, 23, 2, 4, 4,
|
||||
// message_modulus, carry_modulus, number_of_inputs
|
||||
// 1 bit message 0 bit carry parameters
|
||||
(BootstrapTestParams){567, 5, 256, 0.000007069849454709433,
|
||||
0.00000000000000029403601535432533, 15, 1, 2, 1,
|
||||
1},
|
||||
(BootstrapTestParams){500, 1, 1024, 0.000007069849454709433,
|
||||
0.00000000000000029403601535432533, 23, 2, 4, 4,
|
||||
3});
|
||||
(BootstrapTestParams){567, 5, 256, 0.000007069849454709433,
|
||||
0.00000000000000029403601535432533, 15, 1, 2, 1,
|
||||
10},
|
||||
// 2 bit message 3 bit carry parameters
|
||||
(BootstrapTestParams){623, 6, 256, 0.000007069849454709433,
|
||||
0.00000000000000029403601535432533, 9, 3, 3, 4,
|
||||
1},
|
||||
(BootstrapTestParams){623, 6, 256, 0.000007069849454709433,
|
||||
0.00000000000000029403601535432533, 9, 3, 3, 4,
|
||||
10},
|
||||
// 3 bits message 0 bit carry parameters
|
||||
(BootstrapTestParams){694, 3, 512, 0.000007069849454709433,
|
||||
0.00000000000000029403601535432533, 18, 1, 4, 1,
|
||||
1},
|
||||
(BootstrapTestParams){694, 3, 512, 0.000007069849454709433,
|
||||
0.00000000000000029403601535432533, 18, 1, 4, 1,
|
||||
10},
|
||||
// 4 bits message 0 bit carry parameters
|
||||
(BootstrapTestParams){769, 2, 1024, 0.000007069849454709433,
|
||||
0.00000000000000029403601535432533, 23, 1, 5, 1,
|
||||
1},
|
||||
(BootstrapTestParams){769, 2, 1024, 0.000007069849454709433,
|
||||
0.00000000000000029403601535432533, 23, 1, 5, 1,
|
||||
10},
|
||||
// 5 bits message 0 bit carry parameters
|
||||
(BootstrapTestParams){754, 1, 2048, 0.000007069849454709433,
|
||||
0.00000000000000029403601535432533, 23, 1, 6, 1,
|
||||
1},
|
||||
(BootstrapTestParams){754, 1, 2048, 0.000007069849454709433,
|
||||
0.00000000000000029403601535432533, 23, 1, 6, 1,
|
||||
10},
|
||||
// 6 bits message 0 bit carry parameters
|
||||
(BootstrapTestParams){847, 1, 4096, 0.000007069849454709433,
|
||||
0.00000000000000029403601535432533, 1, 22, 7, 1,
|
||||
1},
|
||||
(BootstrapTestParams){847, 1, 4096, 0.000007069849454709433,
|
||||
0.00000000000000029403601535432533, 1, 22, 7, 1,
|
||||
10},
|
||||
// 7 bits message 0 bit carry parameters
|
||||
(BootstrapTestParams){881, 1, 8192, 0.000007069849454709433,
|
||||
0.00000000000000029403601535432533, 1, 22, 8, 1,
|
||||
1},
|
||||
(BootstrapTestParams){881, 1, 8192, 0.000007069849454709433,
|
||||
0.00000000000000029403601535432533, 1, 22, 8, 1,
|
||||
2});
|
||||
|
||||
std::string printParamName(::testing::TestParamInfo<BootstrapTestParams> p) {
|
||||
BootstrapTestParams params = p.param;
|
||||
|
||||
@@ -89,9 +89,11 @@ public:
|
||||
csprng, Uint128{.little_endian_bytes = {*seed}});
|
||||
|
||||
// Generate the keys
|
||||
generate_lwe_secret_keys(&lwe_sk_in_array, lwe_dimension, csprng, REPETITIONS);
|
||||
generate_lwe_secret_keys(&lwe_sk_in_array, lwe_dimension, csprng,
|
||||
REPETITIONS);
|
||||
generate_lwe_secret_keys(&lwe_sk_out_array,
|
||||
glwe_dimension * polynomial_size, csprng, REPETITIONS);
|
||||
glwe_dimension * polynomial_size, csprng,
|
||||
REPETITIONS);
|
||||
generate_lwe_bootstrap_keys(
|
||||
stream, gpu_index, &d_fourier_bsk_array, lwe_sk_in_array,
|
||||
lwe_sk_out_array, lwe_dimension, glwe_dimension, polynomial_size,
|
||||
@@ -100,8 +102,9 @@ public:
|
||||
stream, gpu_index, &d_pksk_array, lwe_sk_out_array, lwe_sk_out_array,
|
||||
glwe_dimension * polynomial_size, glwe_dimension, polynomial_size,
|
||||
pksk_level, pksk_base_log, csprng, lwe_modular_variance, REPETITIONS);
|
||||
plaintexts = generate_plaintexts(
|
||||
number_of_bits_of_message_including_padding, delta, 1, REPETITIONS, SAMPLES);
|
||||
plaintexts =
|
||||
generate_plaintexts(number_of_bits_of_message_including_padding, delta,
|
||||
1, REPETITIONS, SAMPLES);
|
||||
|
||||
d_ggsw_out_ct = (uint64_t *)cuda_malloc_async(ggsw_size * sizeof(uint64_t),
|
||||
stream, gpu_index);
|
||||
|
||||
@@ -68,8 +68,8 @@ public:
|
||||
csprng, Uint128{.little_endian_bytes = {*seed}});
|
||||
|
||||
// Generate the keys
|
||||
generate_glwe_secret_keys(&glwe_sk, glwe_dimension, polynomial_size,
|
||||
csprng, REPETITIONS);
|
||||
generate_glwe_secret_keys(&glwe_sk, glwe_dimension, polynomial_size, csprng,
|
||||
REPETITIONS);
|
||||
plaintexts = generate_plaintexts(r_lut, 1, 1, REPETITIONS, SAMPLES);
|
||||
|
||||
// Create the LUT
|
||||
|
||||
@@ -73,13 +73,16 @@ public:
|
||||
csprng, Uint128{.little_endian_bytes = {*seed}});
|
||||
|
||||
// Generate the keys
|
||||
generate_lwe_secret_keys(&lwe_sk_in_array, input_lwe_dimension, csprng, REPETITIONS);
|
||||
generate_lwe_secret_keys(&lwe_sk_out_array, output_lwe_dimension, csprng, REPETITIONS);
|
||||
generate_lwe_secret_keys(&lwe_sk_in_array, input_lwe_dimension, csprng,
|
||||
REPETITIONS);
|
||||
generate_lwe_secret_keys(&lwe_sk_out_array, output_lwe_dimension, csprng,
|
||||
REPETITIONS);
|
||||
generate_lwe_keyswitch_keys(
|
||||
stream, gpu_index, &d_ksk_array, lwe_sk_in_array, lwe_sk_out_array,
|
||||
input_lwe_dimension, output_lwe_dimension, ksk_level, ksk_base_log,
|
||||
csprng, noise_variance, REPETITIONS);
|
||||
plaintexts = generate_plaintexts(payload_modulus, delta, 1, REPETITIONS, SAMPLES);
|
||||
plaintexts =
|
||||
generate_plaintexts(payload_modulus, delta, 1, REPETITIONS, SAMPLES);
|
||||
|
||||
d_lwe_out_ct = (uint64_t *)cuda_malloc_async(
|
||||
(output_lwe_dimension + 1) * sizeof(uint64_t), stream, gpu_index);
|
||||
|
||||
@@ -66,8 +66,10 @@ public:
|
||||
|
||||
// Generate the keys
|
||||
generate_lwe_secret_keys(&lwe_sk_array, lwe_dimension, csprng, REPETITIONS);
|
||||
plaintexts_1 = generate_plaintexts(payload_modulus, delta, 1, REPETITIONS, SAMPLES);
|
||||
plaintexts_2 = generate_plaintexts(payload_modulus, delta, 1, REPETITIONS, SAMPLES);
|
||||
plaintexts_1 =
|
||||
generate_plaintexts(payload_modulus, delta, 1, REPETITIONS, SAMPLES);
|
||||
plaintexts_2 =
|
||||
generate_plaintexts(payload_modulus, delta, 1, REPETITIONS, SAMPLES);
|
||||
|
||||
d_lwe_in_1_ct = (uint64_t *)cuda_malloc_async(
|
||||
(lwe_dimension + 1) * sizeof(uint64_t), stream, gpu_index);
|
||||
|
||||
@@ -70,7 +70,6 @@ public:
|
||||
// Test arithmetic functions
|
||||
void SetUp() {
|
||||
stream = cuda_create_stream(0);
|
||||
void *v_stream = (void *)stream;
|
||||
|
||||
// TestParams
|
||||
lwe_dimension = (int)GetParam().lwe_dimension;
|
||||
@@ -101,12 +100,14 @@ public:
|
||||
|
||||
int input_lwe_dimension = glwe_dimension * polynomial_size;
|
||||
// Generate the keys
|
||||
generate_lwe_secret_keys(&lwe_sk_in_array, input_lwe_dimension, csprng, REPETITIONS);
|
||||
generate_lwe_secret_keys(&lwe_sk_out_array, lwe_dimension, csprng, REPETITIONS);
|
||||
generate_lwe_keyswitch_keys(stream, gpu_index, &d_ksk_array,
|
||||
lwe_sk_in_array, lwe_sk_out_array,
|
||||
input_lwe_dimension, lwe_dimension, ks_level,
|
||||
ks_base_log, csprng, lwe_modular_variance, REPETITIONS);
|
||||
generate_lwe_secret_keys(&lwe_sk_in_array, input_lwe_dimension, csprng,
|
||||
REPETITIONS);
|
||||
generate_lwe_secret_keys(&lwe_sk_out_array, lwe_dimension, csprng,
|
||||
REPETITIONS);
|
||||
generate_lwe_keyswitch_keys(
|
||||
stream, gpu_index, &d_ksk_array, lwe_sk_in_array, lwe_sk_out_array,
|
||||
input_lwe_dimension, lwe_dimension, ks_level, ks_base_log, csprng,
|
||||
lwe_modular_variance, REPETITIONS);
|
||||
generate_lwe_bootstrap_keys(
|
||||
stream, gpu_index, &d_fourier_bsk_array, lwe_sk_out_array,
|
||||
lwe_sk_in_array, lwe_dimension, glwe_dimension, polynomial_size,
|
||||
@@ -249,8 +250,8 @@ TEST_P(WopBootstrapTestPrimitives_u64, wop_pbs) {
|
||||
// n, k, N, lwe_variance, glwe_variance, pbs_base_log, pbs_level,
|
||||
// ks_base_log, ks_level, tau
|
||||
(WopBootstrapTestParams){481, 2, 512, 7.52316384526264e-37,
|
||||
7.52316384526264e-37, 4,
|
||||
9, 1, 9, 4, 9, 6, 4, 1}//,
|
||||
7.52316384526264e-37, 4, 9, 1, 9, 4, 9, 6, 4,
|
||||
1} //,
|
||||
//(WopBootstrapTestParams){481, 2, 512, 7.52316384526264e-37,
|
||||
// 7.52316384526264e-37, 4, 9, 1, 9, 4, 9, 6, 4,
|
||||
// 2} //,
|
||||
|
||||
@@ -12,8 +12,8 @@
|
||||
// The payload_modulus is the message modulus times the carry modulus
|
||||
// (so the total message modulus)
|
||||
uint64_t *generate_plaintexts(uint64_t payload_modulus, uint64_t delta,
|
||||
int number_of_inputs, const unsigned repetitions, const unsigned
|
||||
samples) {
|
||||
int number_of_inputs, const unsigned repetitions,
|
||||
const unsigned samples) {
|
||||
uint64_t *plaintext_array = (uint64_t *)malloc(
|
||||
repetitions * samples * number_of_inputs * sizeof(uint64_t));
|
||||
std::random_device rd;
|
||||
@@ -134,7 +134,8 @@ void generate_lwe_secret_keys(uint64_t **lwe_sk_array, int lwe_dimension,
|
||||
|
||||
// Generate repetitions GLWE secret keys
|
||||
void generate_glwe_secret_keys(uint64_t **glwe_sk_array, int glwe_dimension,
|
||||
int polynomial_size, Csprng *csprng, const unsigned repetitions) {
|
||||
int polynomial_size, Csprng *csprng,
|
||||
const unsigned repetitions) {
|
||||
int glwe_sk_array_size = glwe_dimension * polynomial_size * repetitions;
|
||||
*glwe_sk_array = (uint64_t *)malloc(glwe_sk_array_size * sizeof(uint64_t));
|
||||
int shift = 0;
|
||||
@@ -148,13 +149,11 @@ void generate_glwe_secret_keys(uint64_t **glwe_sk_array, int glwe_dimension,
|
||||
}
|
||||
|
||||
// Generate repetitions LWE bootstrap keys
|
||||
void generate_lwe_bootstrap_keys(cudaStream_t *stream, int gpu_index,
|
||||
double **d_fourier_bsk_array,
|
||||
uint64_t *lwe_sk_in_array,
|
||||
uint64_t *lwe_sk_out_array, int lwe_dimension,
|
||||
int glwe_dimension, int polynomial_size,
|
||||
int pbs_level, int pbs_base_log,
|
||||
Csprng *csprng, double variance, const unsigned repetitions) {
|
||||
void generate_lwe_bootstrap_keys(
|
||||
cudaStream_t *stream, int gpu_index, double **d_fourier_bsk_array,
|
||||
uint64_t *lwe_sk_in_array, uint64_t *lwe_sk_out_array, int lwe_dimension,
|
||||
int glwe_dimension, int polynomial_size, int pbs_level, int pbs_base_log,
|
||||
Csprng *csprng, double variance, const unsigned repetitions) {
|
||||
void *v_stream = (void *)stream;
|
||||
int bsk_size = (glwe_dimension + 1) * (glwe_dimension + 1) * pbs_level *
|
||||
polynomial_size * (lwe_dimension + 1);
|
||||
@@ -190,11 +189,14 @@ void generate_lwe_bootstrap_keys(cudaStream_t *stream, int gpu_index,
|
||||
}
|
||||
|
||||
// Generate repetitions keyswitch keys
|
||||
void generate_lwe_keyswitch_keys(
|
||||
cudaStream_t *stream, int gpu_index, uint64_t **d_ksk_array,
|
||||
uint64_t *lwe_sk_in_array, uint64_t *lwe_sk_out_array,
|
||||
int input_lwe_dimension, int output_lwe_dimension, int ksk_level,
|
||||
int ksk_base_log, Csprng *csprng, double variance, const unsigned repetitions) {
|
||||
void generate_lwe_keyswitch_keys(cudaStream_t *stream, int gpu_index,
|
||||
uint64_t **d_ksk_array,
|
||||
uint64_t *lwe_sk_in_array,
|
||||
uint64_t *lwe_sk_out_array,
|
||||
int input_lwe_dimension,
|
||||
int output_lwe_dimension, int ksk_level,
|
||||
int ksk_base_log, Csprng *csprng,
|
||||
double variance, const unsigned repetitions) {
|
||||
|
||||
int ksk_size = ksk_level * (output_lwe_dimension + 1) * input_lwe_dimension;
|
||||
int ksk_array_size = ksk_size * repetitions;
|
||||
|
||||
@@ -6,8 +6,8 @@
|
||||
#include <functional>
|
||||
|
||||
uint64_t *generate_plaintexts(uint64_t payload_modulus, uint64_t delta,
|
||||
int number_of_inputs, const unsigned repetitions, const unsigned
|
||||
samples);
|
||||
int number_of_inputs, const unsigned repetitions,
|
||||
const unsigned samples);
|
||||
|
||||
uint64_t *generate_identity_lut_pbs(int polynomial_size, int glwe_dimension,
|
||||
int message_modulus, int carry_modulus,
|
||||
@@ -20,21 +20,23 @@ void generate_lwe_secret_keys(uint64_t **lwe_sk_array, int lwe_dimension,
|
||||
Csprng *csprng, const unsigned repetitions);
|
||||
|
||||
void generate_glwe_secret_keys(uint64_t **glwe_sk_array, int glwe_dimension,
|
||||
int polynomial_size, Csprng *csprng, const unsigned repetitions);
|
||||
int polynomial_size, Csprng *csprng,
|
||||
const unsigned repetitions);
|
||||
|
||||
void generate_lwe_bootstrap_keys(cudaStream_t *stream, int gpu_index,
|
||||
double **d_fourier_bsk_array,
|
||||
void generate_lwe_bootstrap_keys(
|
||||
cudaStream_t *stream, int gpu_index, double **d_fourier_bsk_array,
|
||||
uint64_t *lwe_sk_in_array, uint64_t *lwe_sk_out_array, int lwe_dimension,
|
||||
int glwe_dimension, int polynomial_size, int pbs_level, int pbs_base_log,
|
||||
Csprng *csprng, double variance, const unsigned repetitions);
|
||||
|
||||
void generate_lwe_keyswitch_keys(cudaStream_t *stream, int gpu_index,
|
||||
uint64_t **d_ksk_array,
|
||||
uint64_t *lwe_sk_in_array,
|
||||
uint64_t *lwe_sk_out_array, int lwe_dimension,
|
||||
int glwe_dimension, int polynomial_size,
|
||||
int pbs_level, int pbs_base_log,
|
||||
Csprng *csprng, double variance, const unsigned repetitions);
|
||||
|
||||
void generate_lwe_keyswitch_keys(
|
||||
cudaStream_t *stream, int gpu_index, uint64_t **d_ksk_array,
|
||||
uint64_t *lwe_sk_in_array, uint64_t *lwe_sk_out_array,
|
||||
int input_lwe_dimension, int output_lwe_dimension, int ksk_level,
|
||||
int ksk_base_log, Csprng *csprng, double variance, const unsigned repetitions);
|
||||
uint64_t *lwe_sk_out_array,
|
||||
int input_lwe_dimension,
|
||||
int output_lwe_dimension, int ksk_level,
|
||||
int ksk_base_log, Csprng *csprng,
|
||||
double variance, const unsigned repetitions);
|
||||
|
||||
void generate_lwe_private_functional_keyswitch_key_lists(
|
||||
cudaStream_t *stream, int gpu_index, uint64_t **d_pksk_array,
|
||||
|
||||
Reference in New Issue
Block a user