Skip to content

Commit

Permalink
rm copy in torus64 ver.
Browse files Browse the repository at this point in the history
  • Loading branch information
nindanaoto committed Jul 13, 2024
1 parent 05e07f7 commit f554442
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 50 deletions.
18 changes: 6 additions & 12 deletions include/cloudkey.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -528,18 +528,15 @@ struct EvalKey {
void emplaceiksk(const SecretKey& sk)
{
if constexpr (std::is_same_v<P, lvl10param>) {
iksklvl10 =
std::make_unique_for_overwrite<KeySwitchingKey<lvl10param>>();
iksklvl10 = std::unique_ptr<KeySwitchingKey<lvl10param>>(new (std::align_val_t(64)) KeySwitchingKey<lvl10param>());
ikskgen<lvl10param>(*iksklvl10, sk);
}
else if constexpr (std::is_same_v<P, lvl1hparam>) {
iksklvl1h =
std::make_unique_for_overwrite<KeySwitchingKey<lvl1hparam>>();
iksklvl1h = std::unique_ptr<KeySwitchingKey<lvl1hparam>>(new (std::align_val_t(64)) KeySwitchingKey<lvl1hparam>());
ikskgen<lvl1hparam>(*iksklvl1h, sk);
}
else if constexpr (std::is_same_v<P, lvl20param>) {
iksklvl20 =
std::make_unique_for_overwrite<KeySwitchingKey<lvl20param>>();
iksklvl20 = std::unique_ptr<KeySwitchingKey<lvl20param>>(new (std::align_val_t(64)) KeySwitchingKey<lvl20param>());
ikskgen<lvl20param>(*iksklvl20, sk);
}
// else if constexpr (std::is_same_v<P, lvl2hparam>) {
Expand All @@ -548,18 +545,15 @@ struct EvalKey {
// ikskgen<lvlh2param>(*iksklvlh2, sk);
// }
else if constexpr (std::is_same_v<P, lvl21param>) {
iksklvl21 =
std::make_unique_for_overwrite<KeySwitchingKey<lvl21param>>();
iksklvl21 = std::unique_ptr<KeySwitchingKey<lvl21param>>(new (std::align_val_t(64)) KeySwitchingKey<lvl21param>());
ikskgen<lvl21param>(*iksklvl21, sk);
}
else if constexpr (std::is_same_v<P, lvl22param>) {
iksklvl22 =
std::make_unique_for_overwrite<KeySwitchingKey<lvl22param>>();
iksklvl22 = std::unique_ptr<KeySwitchingKey<lvl22param>>(new (std::align_val_t(64)) KeySwitchingKey<lvl22param>());
ikskgen<lvl22param>(*iksklvl22, sk);
}
else if constexpr (std::is_same_v<P, lvl31param>) {
iksklvl31 =
std::make_unique_for_overwrite<KeySwitchingKey<lvl31param>>();
iksklvl31 = std::unique_ptr<KeySwitchingKey<lvl31param>>(new (std::align_val_t(64)) KeySwitchingKey<lvl31param>());
ikskgen<lvl31param>(*iksklvl31, sk);
}
else
Expand Down
16 changes: 8 additions & 8 deletions include/gatebootstrapping.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ void GateBootstrappingTLWE2TLWEFFT(
const BootstrappingKeyFFT<P> &bkfft,
const Polynomial<typename P::targetP> &testvector)
{
TRLWE<typename P::targetP> acc;
alignas(64) TRLWE<typename P::targetP> acc;
BlindRotate<P>(acc, tlwe, bkfft, testvector);
SampleExtractIndex<typename P::targetP>(res, acc, 0);
}
Expand All @@ -202,7 +202,7 @@ void GateBootstrappingTLWE2TLWENTT(
const BootstrappingKeyNTT<P> &bkntt,
const Polynomial<typename P::targetP> &testvector)
{
TRLWE<typename P::targetP> acc;
alignas(64) TRLWE<typename P::targetP> acc;
BlindRotate<P>(acc, tlwe, bkntt, testvector);
SampleExtractIndex<typename P::targetP>(res, acc, 0);
}
Expand All @@ -213,7 +213,7 @@ void GateBootstrappingTLWE2TLWERAINTT(
const BootstrappingKeyRAINTT<P> &bkraintt,
const Polynomial<typename P::targetP> &testvector)
{
TRLWE<typename P::targetP> acc;
alignas(64) TRLWE<typename P::targetP> acc;
BlindRotate<P>(acc, tlwe, bkraintt, testvector);
SampleExtractIndex<typename P::targetP>(res, acc, 0);
}
Expand All @@ -224,7 +224,7 @@ void GateBootstrappingManyLUT(
const TLWE<typename P::domainP> &tlwe, const BootstrappingKeyFFT<P> &bkfft,
const Polynomial<typename P::targetP> &testvector)
{
TRLWE<typename P::targetP> acc;
alignas(64) TRLWE<typename P::targetP> acc;
BlindRotate<P, num_out>(acc, tlwe, bkfft, testvector);
for (int i = 0; i < num_out; i++)
SampleExtractIndex<typename P::targetP>(res[i], acc, i);
Expand All @@ -243,7 +243,7 @@ void GateBootstrapping(TLWE<typename bkP::domainP> &res,
const TLWE<typename bkP::domainP> &tlwe,
const EvalKey &ek)
{
TLWE<typename bkP::targetP> tlwelvl1;
alignas(64) TLWE<typename bkP::targetP> tlwelvl1;
GateBootstrappingTLWE2TLWEFFT<bkP>(tlwelvl1, tlwe, ek.getbkfft<bkP>(),
μpolygen<typename bkP::targetP, μ>());
IdentityKeySwitch<iksP>(res, tlwelvl1, ek.getiksk<iksP>());
Expand All @@ -254,7 +254,7 @@ void GateBootstrapping(TLWE<typename iksP::domainP> &res,
const TLWE<typename iksP::domainP> &tlwe,
const EvalKey &ek)
{
TLWE<typename iksP::targetP> tlwelvl0;
alignas(64) TLWE<typename iksP::targetP> tlwelvl0;
IdentityKeySwitch<iksP>(tlwelvl0, tlwe, ek.getiksk<iksP>());
GateBootstrappingTLWE2TLWEFFT<bkP>(res, tlwelvl0, ek.getbkfft<bkP>(),
μpolygen<typename bkP::targetP, μ>());
Expand All @@ -265,7 +265,7 @@ void GateBootstrappingNTT(TLWE<typename iksP::tagetP> &res,
const TLWE<typename bkP::domainP> &tlwe,
const EvalKey &ek)
{
TLWE<typename bkP::targetP> tlwelvl1;
alignas(64) TLWE<typename bkP::targetP> tlwelvl1;
GateBootstrappingTLWE2TLWENTT<bkP>(tlwelvl1, tlwe, ek.getbkntt<bkP>(),
μpolygen<typename bkP::targetP, μ>());
IdentityKeySwitch<iksP>(res, tlwelvl1, ek.getiksk<iksP>());
Expand All @@ -276,7 +276,7 @@ void GateBootstrappingNTT(TLWE<typename bkP::targetP> &res,
const TLWE<typename iksP::domainP> &tlwe,
const EvalKey &ek)
{
TLWE<typename iksP::targetP> tlwelvl0;
alignas(64) TLWE<typename iksP::targetP> tlwelvl0;
IdentityKeySwitch<iksP>(tlwelvl0, tlwe, ek.getiksk<iksP>());
GateBootstrappingTLWE2TLWENTT<bkP>(res, tlwelvl0, ek.getbkntt<bkP>(),
μpolygen<typename bkP::targetP, μ>());
Expand Down
33 changes: 5 additions & 28 deletions thirdparties/spqlios/fft_processor_spqlios.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ FFT_Processor_Spqlios::FFT_Processor_Spqlios(const int32_t N) : _2N(2 * N), N(N)
tables_reverse = new_ifft_table(N);
real_inout_direct = fft_table_get_buffer(tables_direct);
imag_inout_direct = real_inout_direct + Ns2;
real_inout_rev = fft_table_get_buffer(tables_reverse);
imag_inout_rev = real_inout_rev + Ns2;
reva = new int32_t[Ns2];
cosomegaxminus1 = new double[2 * _2N];
sinomegaxminus1 = cosomegaxminus1 + _2N;
Expand Down Expand Up @@ -61,26 +59,6 @@ void FFT_Processor_Spqlios::execute_reverse_int(double *res, const int32_t *a) {
);
}
ifft(tables_reverse, res);
// ifft(tables_reverse, real_inout_rev);
//for (int32_t i=0; i<N; i++) res[i]=real_inout_rev[i];
// {
// double *dst = res;
// double *sit = real_inout_rev;
// double *send = real_inout_rev + N;
// __asm__ __volatile__ (
// "1:\n"
// "vmovapd (%1),%%ymm0\n"
// "vmovupd %%ymm0,(%0)\n"
// "addq $32,%1\n"
// "addq $32,%0\n"
// "cmpq %2,%1\n"
// "jb 1b\n"
// "vzeroall\n"
// : "=r"(dst), "=r"(sit), "=r"(send)
// : "0"(dst), "1"(sit), "2"(send)
// : "%ymm0", "memory"
// );
// }
}

void FFT_Processor_Spqlios::execute_reverse_torus32(double *res, const uint32_t *a) {
Expand All @@ -90,15 +68,14 @@ void FFT_Processor_Spqlios::execute_reverse_torus32(double *res, const uint32_t

void FFT_Processor_Spqlios::execute_reverse_torus64(double* res, const uint64_t* a) {
#ifdef USE_AVX512
__m512d * ri512 = (__m512d *) proc->real_inout_rev;
__m512d * ri512 = (__m512d *) res;
__m512i * aa = (__m512i *) a;
for (size_t i = 0; i < proc->N/8; i++) ri512[i] = _mm512_cvtepi64_pd (aa[i]);
#else
int64_t *aa = (int64_t *)a;
for (int i=0; i<N; i++) real_inout_rev[i]=(double)aa[i];
for (int i=0; i<N; i++) res[i]=(double)aa[i];
#endif
ifft(tables_reverse,real_inout_rev);
for (int i=0; i<N; i++) res[i]=real_inout_rev[i];
ifft(tables_reverse,res);
}

void FFT_Processor_Spqlios::execute_direct_torus32(uint32_t *res, const double *a) {
Expand Down Expand Up @@ -272,8 +249,8 @@ void FFT_Processor_Spqlios::execute_direct_torus64_rescale(uint64_t* res, const
}

FFT_Processor_Spqlios::~FFT_Processor_Spqlios() {
//delete (tables_direct);
//delete (tables_reverse);
delete (tables_direct);
delete (tables_reverse);
delete[] cosomegaxminus1;
}

Expand Down
2 changes: 0 additions & 2 deletions thirdparties/spqlios/fft_processor_spqlios.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ class FFT_Processor_Spqlios {
private:
double *real_inout_direct;
double *imag_inout_direct;
double *real_inout_rev;
double *imag_inout_rev;
void *tables_direct;
void *tables_reverse;
public:
Expand Down

0 comments on commit f554442

Please sign in to comment.