-
Notifications
You must be signed in to change notification settings - Fork 158
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
33 changed files
with
1,209 additions
and
354 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#ifndef CUDA_FUNCTIONS_H_ | ||
#define CUDA_FUNCTIONS_H_ | ||
|
||
#include <cstdint> | ||
#include "polynomial/parameters.cuh" | ||
#include "polynomial/functions.cuh" | ||
|
||
extern "C" { | ||
void cuda_glwe_sample_extract_64( | ||
void **streams, uint32_t *gpu_indexes, uint32_t gpu_count, void *lwe_array_out, | ||
void *glwe_array_in, uint32_t *nth_array, uint32_t num_samples, uint32_t glwe_dimension, | ||
uint32_t | ||
polynomial_size); | ||
} | ||
|
||
#endif |
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
51 changes: 51 additions & 0 deletions
51
backends/tfhe-cuda-backend/cuda/src/integer/compression/compression.cu
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,51 @@ | ||
#include "compression.cuh" | ||
|
||
void scratch_cuda_compression_integer_radix_ciphertext_64( | ||
void **streams, uint32_t *gpu_indexes, uint32_t gpu_count, int8_t **mem_ptr, | ||
uint32_t glwe_dimension, uint32_t polynomial_size, uint32_t lwe_dimension, | ||
uint32_t ks_level, uint32_t ks_base_log, uint32_t pbs_level, | ||
uint32_t pbs_base_log, uint32_t grouping_factor, uint32_t num_lwes, | ||
uint32_t message_modulus, uint32_t carry_modulus, PBS_TYPE pbs_type, | ||
uint32_t lwe_per_glwe, uint32_t storage_log_modulus, COMPRESSION_MODE mode, | ||
bool allocate_gpu_memory) { | ||
|
||
int_radix_params params(pbs_type, glwe_dimension, polynomial_size, | ||
glwe_dimension * polynomial_size, lwe_dimension, | ||
ks_level, ks_base_log, pbs_level, pbs_base_log, | ||
grouping_factor, message_modulus, carry_modulus); | ||
|
||
scratch_cuda_compression_integer_radix_ciphertext_64( | ||
(cudaStream_t *)(streams), gpu_indexes, gpu_count, | ||
(int_compression<uint64_t> **)mem_ptr, num_lwes, params, lwe_per_glwe, | ||
storage_log_modulus, mode, allocate_gpu_memory); | ||
} | ||
void cuda_compression_compress_integer_radix_ciphertext_64( | ||
void **streams, uint32_t *gpu_indexes, uint32_t gpu_count, | ||
void *glwe_array_out, void *lwe_array_in, void **fp_ksk, uint32_t num_lwes, | ||
int8_t *mem_ptr) { | ||
|
||
host_integer_compression_compress<uint64_t>( | ||
(cudaStream_t *)(streams), gpu_indexes, gpu_count, | ||
static_cast<uint64_t *>(glwe_array_out), | ||
static_cast<uint64_t *>(lwe_array_in), (uint64_t **)(fp_ksk), num_lwes, | ||
(int_compression<uint64_t> *)mem_ptr); | ||
} | ||
void cuda_compression_decompress_integer_radix_ciphertext_64( | ||
void **streams, uint32_t *gpu_indexes, uint32_t gpu_count, void *lwe_out, | ||
void *glwe_array_in, void **bsks, int8_t *mem_ptr) { | ||
|
||
host_integer_compression_decompress<uint64_t>( | ||
(cudaStream_t *)(streams), gpu_indexes, gpu_count, | ||
static_cast<uint64_t *>(lwe_out), | ||
static_cast<uint64_t *>(glwe_array_in),bsks, | ||
(int_compression<uint64_t> *)mem_ptr); | ||
} | ||
|
||
void cleanup_cuda_compression_integer_radix_ciphertext_64( | ||
void **streams, uint32_t *gpu_indexes, uint32_t gpu_count, | ||
int8_t **mem_ptr_void) { | ||
|
||
int_compression<uint64_t> *mem_ptr = | ||
(int_compression<uint64_t> *)(*mem_ptr_void); | ||
mem_ptr->release((cudaStream_t *)(streams), gpu_indexes, gpu_count); | ||
} |
68 changes: 68 additions & 0 deletions
68
backends/tfhe-cuda-backend/cuda/src/integer/compression/compression.cuh
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,68 @@ | ||
#ifndef CUDA_INTEGER_COMPRESSION_CUH | ||
#define CUDA_INTEGER_COMPRESSION_CUH | ||
|
||
#include "crypto/keyswitch.cuh" | ||
#include "device.h" | ||
#include "integer.h" | ||
#include "integer/integer.cuh" | ||
#include "linearalgebra/multiplication.cuh" | ||
#include "polynomial/functions.cuh" | ||
#include "utils/kernel_dimensions.cuh" | ||
|
||
template <typename Torus> | ||
__host__ void host_integer_compression_compress( | ||
cudaStream_t *streams, uint32_t *gpu_indexes, uint32_t gpu_count, | ||
Torus *glwe_array_out, Torus *lwe_array_in, Torus **fp_ksk, | ||
uint32_t num_lwes, int_compression<Torus> *mem_ptr) { | ||
auto params = mem_ptr->params; | ||
|
||
// Shift | ||
auto lwe_shifted = mem_ptr->tmp_lwe_shifted; | ||
host_cleartext_multiplication(streams[0], gpu_indexes[0], lwe_shifted, | ||
lwe_array_in, (uint64_t)params.message_modulus, | ||
params.big_lwe_dimension, num_lwes); | ||
|
||
uint32_t lwe_in_size = params.big_lwe_dimension + 1; | ||
uint32_t glwe_out_size = (params.glwe_dimension + 1) * params.polynomial_size; | ||
uint32_t num_glwes = num_lwes / mem_ptr->lwe_per_glwe; | ||
|
||
// Keyswitch LWEs to GLWE | ||
for (int i = 0; i < num_glwes; i++) { | ||
auto lwe_subset = lwe_shifted + i * lwe_in_size; | ||
auto glwe_out = glwe_array_out + i * glwe_out_size; | ||
|
||
host_fp_keyswitch_lwe_list_to_glwe( | ||
streams[0], gpu_indexes[0], glwe_out, lwe_subset, fp_ksk[0], | ||
params.big_lwe_dimension, params.glwe_dimension, params.polynomial_size, | ||
params.ks_base_log, params.ks_level, mem_ptr->lwe_per_glwe); | ||
} | ||
|
||
// Modulus switch | ||
int num_blocks = 0, num_threads = 0; | ||
getNumBlocksAndThreads(glwe_out_size, 512, num_blocks, num_threads); | ||
apply_modulus_switch_inplace<<<num_blocks, num_threads, 0, streams[0]>>>( | ||
glwe_array_out, num_glwes * glwe_out_size, mem_ptr->storage_log_modulus); | ||
} | ||
|
||
|
||
template <typename Torus> | ||
__host__ void host_integer_compression_decompress( | ||
cudaStream_t *streams, uint32_t *gpu_indexes, uint32_t gpu_count, | ||
Torus *lwe_out, Torus *glwe_array_in, void **bsks, | ||
int_compression<Torus> *mem_ptr) { | ||
|
||
} | ||
|
||
template <typename Torus> | ||
__host__ void scratch_cuda_compression_integer_radix_ciphertext_64( | ||
cudaStream_t *streams, uint32_t *gpu_indexes, uint32_t gpu_count, | ||
int_compression<Torus> **mem_ptr, uint32_t num_lwes, | ||
int_radix_params params, uint32_t lwe_per_glwe, | ||
uint32_t storage_log_modulus, COMPRESSION_MODE mode, | ||
bool allocate_gpu_memory) { | ||
|
||
*mem_ptr = new int_compression<Torus>( | ||
streams, gpu_indexes, gpu_count, params, num_lwes, lwe_per_glwe, | ||
storage_log_modulus, mode, allocate_gpu_memory); | ||
} | ||
#endif |
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
Oops, something went wrong.