encryptorion-lab / phantom-fhe

PhantomFHE: A CUDA-Accelerated Homomorphic Encryption Library
https://encryptorion-lab.gitbook.io/phantom-fhe/
GNU General Public License v3.0
80 stars 9 forks source link

Error freeing 1 * 24 bytes at 0x3025dbe00 on stream 0x5594aba0fa80 Error code: context is destroyed #11

Closed gogo9th closed 2 months ago

gogo9th commented 2 months ago

Hi,

I always appreciate your fast reply and help on using PhantomFHE. I ran a quick benchmark on CKKS and BFV, and it seems that PhantomFHE is faster than any other open source FHE libraries available on the internet.

While I was trying to port PhantomFHE into my application, I encountered some errors, so I came up with the minimal reproducible example code as follows:

#include <iostream>
#include "phantom.h"

using namespace std;
using namespace phantom;
using namespace phantom::arith;
using namespace phantom::util;

int main()
{  int poly_mod_degree = 16384;
   int prime_bitlength = 20;
   shared_ptr<EncryptionParameters> q1 = make_unique<EncryptionParameters>(scheme_type::bfv);
   q1->set_poly_modulus_degree(poly_mod_degree);
   q1->set_coeff_modulus(CoeffModulus::Create(poly_mod_degree, { 48, 48, 48, 48, 48, 48 }));
   q1->set_plain_modulus(PlainModulus::Batching(poly_mod_degree, prime_bitlength + 2));
   shared_ptr<PhantomContext> context = make_unique<PhantomContext>(*(q1));

   shared_ptr<EncryptionParameters> q2 = make_unique<EncryptionParameters>(scheme_type::bfv);
   q2->set_poly_modulus_degree(poly_mod_degree);
   q2->set_coeff_modulus(CoeffModulus::Create(poly_mod_degree, { 48, 48, 48, 48, 48, 48 }));
   q2->set_plain_modulus(PlainModulus::Batching(poly_mod_degree, prime_bitlength + 2));
   shared_ptr<PhantomContext> context2 = make_unique<PhantomContext>(*q2);
} 

If I run the above code, I get the following error:

Error freeing 16384 * 8 bytes at 0x302b18800 on stream 0x55a960564900
Error code: context is destroyed

I get 1802 such error messages as above.

I created a runnable example ready for you. I added your public key to the ssh server, so you can log in via:

ssh -p 27654 root@195.0.159.206 -L 8080:localhost:8080

and do

/root/my-example/src/build
./main

g

D4rkCrypto commented 2 months ago

Sorry for the delay. Been on a vacation recently. I will come back and check this issue within this week.

D4rkCrypto commented 2 months ago

May due to the shared/unique ptr usage, such smart pointer on GPU class may cause unexpected error.

gogo9th commented 2 months ago

I hope you had a great vacation. Thanks for the note. I just re-test this example code from a different physical machine (not a VM) and it works fine. It's strange why it does not work in the docker VM...