Skip to content

Commit

Permalink
chore(gpu): reintroduce a GpuIndex type
Browse files Browse the repository at this point in the history
  • Loading branch information
agnesLeroy committed Nov 29, 2024
1 parent 2bf19b6 commit df68e54
Show file tree
Hide file tree
Showing 34 changed files with 1,654 additions and 1,110 deletions.
6 changes: 3 additions & 3 deletions tfhe/benches/core_crypto/ks_bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ mod cuda {
use tfhe::core_crypto::gpu::lwe_ciphertext_list::CudaLweCiphertextList;
use tfhe::core_crypto::gpu::lwe_keyswitch_key::CudaLweKeyswitchKey;
use tfhe::core_crypto::gpu::lwe_packing_keyswitch_key::CudaLwePackingKeyswitchKey;
use tfhe::core_crypto::gpu::vec::CudaVec;
use tfhe::core_crypto::gpu::vec::{CudaVec, GpuIndex};
use tfhe::core_crypto::gpu::{
cuda_keyswitch_lwe_ciphertext, cuda_keyswitch_lwe_ciphertext_list_into_glwe_ciphertext,
CudaStreams,
Expand All @@ -330,7 +330,7 @@ mod cuda {
SecretRandomGenerator::<ActivatedRandomGenerator>::new(seeder.seed());

let gpu_index = 0;
let streams = CudaStreams::new_single_gpu(gpu_index);
let streams = CudaStreams::new_single_gpu(GpuIndex(gpu_index));

for (name, params) in parameters.iter() {
let lwe_dimension = params.lwe_dimension.unwrap();
Expand Down Expand Up @@ -433,7 +433,7 @@ mod cuda {
SecretRandomGenerator::<ActivatedRandomGenerator>::new(seeder.seed());

let gpu_index = 0;
let streams = CudaStreams::new_single_gpu(gpu_index);
let streams = CudaStreams::new_single_gpu(GpuIndex(gpu_index));

for (name, params) in parameters.iter() {
let lwe_dimension = params.lwe_dimension.unwrap();
Expand Down
10 changes: 5 additions & 5 deletions tfhe/benches/core_crypto/pbs_bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -830,7 +830,7 @@ mod cuda {
use tfhe::core_crypto::gpu::lwe_bootstrap_key::CudaLweBootstrapKey;
use tfhe::core_crypto::gpu::lwe_ciphertext_list::CudaLweCiphertextList;
use tfhe::core_crypto::gpu::lwe_multi_bit_bootstrap_key::CudaLweMultiBitBootstrapKey;
use tfhe::core_crypto::gpu::vec::CudaVec;
use tfhe::core_crypto::gpu::vec::{CudaVec, GpuIndex};
use tfhe::core_crypto::gpu::{
cuda_multi_bit_programmable_bootstrap_lwe_ciphertext,
cuda_programmable_bootstrap_lwe_ciphertext, CudaStreams,
Expand Down Expand Up @@ -900,7 +900,7 @@ mod cuda {
SecretRandomGenerator::<ActivatedRandomGenerator>::new(seeder.seed());

let gpu_index = 0;
let stream = CudaStreams::new_single_gpu(gpu_index);
let stream = CudaStreams::new_single_gpu(GpuIndex(gpu_index));

for (name, params) in parameters.iter() {
// Create the LweSecretKey
Expand Down Expand Up @@ -1021,7 +1021,7 @@ mod cuda {
SecretRandomGenerator::<ActivatedRandomGenerator>::new(seeder.seed());

let gpu_index = 0;
let stream = CudaStreams::new_single_gpu(gpu_index);
let stream = CudaStreams::new_single_gpu(GpuIndex(gpu_index));

for (name, params, grouping_factor) in parameters.iter() {
// Create the LweSecretKey
Expand Down Expand Up @@ -1143,7 +1143,7 @@ mod cuda {
SecretRandomGenerator::<ActivatedRandomGenerator>::new(seeder.seed());

let gpu_index = 0;
let stream = CudaStreams::new_single_gpu(gpu_index);
let stream = CudaStreams::new_single_gpu(GpuIndex(gpu_index));

for (name, params) in parameters.iter() {
let input_lwe_secret_key = allocate_and_generate_new_binary_lwe_secret_key(
Expand Down Expand Up @@ -1283,7 +1283,7 @@ mod cuda {
SecretRandomGenerator::<ActivatedRandomGenerator>::new(seeder.seed());

let gpu_index = 0;
let stream = CudaStreams::new_single_gpu(gpu_index);
let stream = CudaStreams::new_single_gpu(GpuIndex(gpu_index));

for (name, params, grouping_factor) in parameters.iter() {
let input_lwe_secret_key = allocate_and_generate_new_binary_lwe_secret_key(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ pub unsafe fn cuda_extract_lwe_samples_from_glwe_ciphertext_list_async<Scalar>(
let nth_array: Vec<u32> = vec_nth.iter().map(|x| x.0 as u32).collect_vec();
let gpu_indexes = &streams.gpu_indexes;
unsafe {
let d_nth_array = CudaVec::from_cpu_async(&nth_array, streams, gpu_indexes[0]);
let d_nth_array = CudaVec::from_cpu_async(&nth_array, streams, gpu_indexes[0].0);
extract_lwe_samples_from_glwe_ciphertext_list_async(
streams,
&mut output_lwe_list.0.d_vec,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use super::*;
use crate::core_crypto::gpu::glwe_ciphertext_list::CudaGlweCiphertextList;
use crate::core_crypto::gpu::glwe_sample_extraction::cuda_extract_lwe_samples_from_glwe_ciphertext_list;
use crate::core_crypto::gpu::lwe_ciphertext_list::CudaLweCiphertextList;
use crate::core_crypto::gpu::vec::GpuIndex;
use crate::core_crypto::gpu::CudaStreams;
use itertools::Itertools;

Expand All @@ -26,7 +27,7 @@ fn glwe_encrypt_sample_extract_decrypt_custom_mod<Scalar: UnsignedTorus + Send +
let delta: Scalar = encoding_with_padding / msg_modulus;

let gpu_index = 0;
let streams = CudaStreams::new_single_gpu(gpu_index);
let streams = CudaStreams::new_single_gpu(GpuIndex(gpu_index));

let mut msgs = vec![];

Expand Down
4 changes: 2 additions & 2 deletions tfhe/src/core_crypto/gpu/algorithms/test/lwe_keyswitch.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use super::*;
use crate::core_crypto::gpu::lwe_ciphertext_list::CudaLweCiphertextList;
use crate::core_crypto::gpu::lwe_keyswitch_key::CudaLweKeyswitchKey;
use crate::core_crypto::gpu::vec::CudaVec;
use crate::core_crypto::gpu::vec::{CudaVec, GpuIndex};
use crate::core_crypto::gpu::{cuda_keyswitch_lwe_ciphertext, CudaStreams};
use itertools::Itertools;

Expand All @@ -18,7 +18,7 @@ fn lwe_encrypt_ks_decrypt_custom_mod<Scalar: UnsignedTorus + CastFrom<usize>>(
let ks_decomp_base_log = params.ks_base_log;
let ks_decomp_level_count = params.ks_level;

let stream = CudaStreams::new_single_gpu(0);
let stream = CudaStreams::new_single_gpu(GpuIndex(0));

let mut rsc = TestResources::new();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use super::*;
use crate::core_crypto::gpu::glwe_ciphertext_list::CudaGlweCiphertextList;
use crate::core_crypto::gpu::lwe_ciphertext_list::CudaLweCiphertextList;
use crate::core_crypto::gpu::lwe_multi_bit_bootstrap_key::CudaLweMultiBitBootstrapKey;
use crate::core_crypto::gpu::vec::CudaVec;
use crate::core_crypto::gpu::vec::{CudaVec, GpuIndex};
use crate::core_crypto::gpu::{cuda_multi_bit_programmable_bootstrap_lwe_ciphertext, CudaStreams};
use itertools::Itertools;

Expand All @@ -28,7 +28,7 @@ fn lwe_encrypt_multi_bit_pbs_decrypt_custom_mod<
let grouping_factor = params.grouping_factor;

let gpu_index = 0;
let stream = CudaStreams::new_single_gpu(gpu_index);
let stream = CudaStreams::new_single_gpu(GpuIndex(gpu_index));

let mut rsc = TestResources::new();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use super::*;
use crate::core_crypto::gpu::algorithms::lwe_packing_keyswitch::cuda_keyswitch_lwe_ciphertext_list_into_glwe_ciphertext_async;
use crate::core_crypto::gpu::glwe_ciphertext_list::CudaGlweCiphertextList;
use crate::core_crypto::gpu::lwe_ciphertext_list::CudaLweCiphertextList;
use crate::core_crypto::gpu::vec::GpuIndex;
use crate::core_crypto::gpu::CudaStreams;
use serde::de::DeserializeOwned;
use serde::Serialize;
Expand Down Expand Up @@ -67,7 +68,7 @@ where
let delta: Scalar = encoding_with_padding / msg_modulus;

let gpu_index = 0;
let stream = CudaStreams::new_single_gpu(gpu_index);
let stream = CudaStreams::new_single_gpu(GpuIndex(gpu_index));

while msg != Scalar::ZERO {
msg = msg.wrapping_sub(Scalar::ONE);
Expand Down Expand Up @@ -151,7 +152,7 @@ where
let delta: Scalar = encoding_with_padding / msg_modulus;

let gpu_index = 0;
let stream = CudaStreams::new_single_gpu(gpu_index);
let stream = CudaStreams::new_single_gpu(GpuIndex(gpu_index));

while msg != Scalar::ZERO {
msg = msg.wrapping_sub(Scalar::ONE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use super::*;
use crate::core_crypto::gpu::glwe_ciphertext_list::CudaGlweCiphertextList;
use crate::core_crypto::gpu::lwe_bootstrap_key::CudaLweBootstrapKey;
use crate::core_crypto::gpu::lwe_ciphertext_list::CudaLweCiphertextList;
use crate::core_crypto::gpu::vec::CudaVec;
use crate::core_crypto::gpu::vec::{CudaVec, GpuIndex};
use crate::core_crypto::gpu::{cuda_programmable_bootstrap_lwe_ciphertext, CudaStreams};
use itertools::Itertools;

Expand All @@ -26,7 +26,7 @@ fn lwe_encrypt_pbs_decrypt<
let decomp_level_count = params.pbs_level;

let gpu_index = 0;
let stream = CudaStreams::new_single_gpu(gpu_index);
let stream = CudaStreams::new_single_gpu(GpuIndex(gpu_index));

let mut rsc = TestResources::new();

Expand Down
4 changes: 2 additions & 2 deletions tfhe/src/core_crypto/gpu/entities/lwe_ciphertext_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ impl<T: UnsignedInteger> CudaLweCiphertextList<T> {
first_item.0.d_vec.as_c_ptr(0),
size as u64,
streams.ptr[0],
streams.gpu_indexes[0],
streams.gpu_indexes[0].0,
);
ptr = ptr.wrapping_byte_add(size);
for list in cuda_ciphertexts_list_vec {
Expand All @@ -137,7 +137,7 @@ impl<T: UnsignedInteger> CudaLweCiphertextList<T> {
list.0.d_vec.as_c_ptr(0),
size as u64,
streams.ptr[0],
streams.gpu_indexes[0],
streams.gpu_indexes[0].0,
);
ptr = ptr.wrapping_byte_add(size);
}
Expand Down
Loading

0 comments on commit df68e54

Please sign in to comment.