fhe-sdk 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- fhe_sdk-0.1.0/.gitignore +11 -0
- fhe_sdk-0.1.0/CMakeLists.txt +32 -0
- fhe_sdk-0.1.0/LICENSE +32 -0
- fhe_sdk-0.1.0/MANIFEST.in +35 -0
- fhe_sdk-0.1.0/PKG-INFO +330 -0
- fhe_sdk-0.1.0/README.md +266 -0
- fhe_sdk-0.1.0/docs/CONFIG.md +190 -0
- fhe_sdk-0.1.0/docs/GUIDELINES.md +266 -0
- fhe_sdk-0.1.0/docs/INTRO.md +33 -0
- fhe_sdk-0.1.0/docs/RELU_APPROXIMATION.md +170 -0
- fhe_sdk-0.1.0/examples/bootstrapping.py +56 -0
- fhe_sdk-0.1.0/examples/classifier/concrete_bench.py +62 -0
- fhe_sdk-0.1.0/examples/classifier/network.py +101 -0
- fhe_sdk-0.1.0/examples/classifier/plaintext_bench.py +58 -0
- fhe_sdk-0.1.0/examples/classifier/sdk_bench.py +94 -0
- fhe_sdk-0.1.0/examples/classifier/tenseal_bench.py +82 -0
- fhe_sdk-0.1.0/examples/simple_nn.py +84 -0
- fhe_sdk-0.1.0/examples/square.py +65 -0
- fhe_sdk-0.1.0/external/HEonGPU/.clang-format +36 -0
- fhe_sdk-0.1.0/external/HEonGPU/.gitignore +29 -0
- fhe_sdk-0.1.0/external/HEonGPU/.gitmodules +9 -0
- fhe_sdk-0.1.0/external/HEonGPU/.readthedocs.yaml +31 -0
- fhe_sdk-0.1.0/external/HEonGPU/CMakeLists.txt +168 -0
- fhe_sdk-0.1.0/external/HEonGPU/CONTRIBUTING.md +49 -0
- fhe_sdk-0.1.0/external/HEonGPU/LICENSE +201 -0
- fhe_sdk-0.1.0/external/HEonGPU/README.md +414 -0
- fhe_sdk-0.1.0/external/HEonGPU/benchmark/CMakeLists.txt +35 -0
- fhe_sdk-0.1.0/external/HEonGPU/benchmark/benchmark_bfv.cpp +216 -0
- fhe_sdk-0.1.0/external/HEonGPU/benchmark/benchmark_ckks.cpp +234 -0
- fhe_sdk-0.1.0/external/HEonGPU/benchmark/benchmark_tfhe.cpp +122 -0
- fhe_sdk-0.1.0/external/HEonGPU/cmake/Config.cmake.in +40 -0
- fhe_sdk-0.1.0/external/HEonGPU/cmake/DetectCudaArch.cmake +71 -0
- fhe_sdk-0.1.0/external/HEonGPU/cmake/FindCCCL.cmake +48 -0
- fhe_sdk-0.1.0/external/HEonGPU/cmake/FindThrust.cmake +26 -0
- fhe_sdk-0.1.0/external/HEonGPU/cmake/cmake_uninstall.cmake.in +221 -0
- fhe_sdk-0.1.0/external/HEonGPU/dev-tools/clang-format-all +85 -0
- fhe_sdk-0.1.0/external/HEonGPU/docs/.gitignore +11 -0
- fhe_sdk-0.1.0/external/HEonGPU/docs/Doxyfile +2932 -0
- fhe_sdk-0.1.0/external/HEonGPU/docs/_extra/robots.txt +2 -0
- fhe_sdk-0.1.0/external/HEonGPU/docs/advanced_topics.rst +63 -0
- fhe_sdk-0.1.0/external/HEonGPU/docs/api_reference.rst +169 -0
- fhe_sdk-0.1.0/external/HEonGPU/docs/appendix.rst +135 -0
- fhe_sdk-0.1.0/external/HEonGPU/docs/bootstrapping.rst +72 -0
- fhe_sdk-0.1.0/external/HEonGPU/docs/conf.py +94 -0
- fhe_sdk-0.1.0/external/HEonGPU/docs/contributing.rst +34 -0
- fhe_sdk-0.1.0/external/HEonGPU/docs/examples.rst +114 -0
- fhe_sdk-0.1.0/external/HEonGPU/docs/getting_started.rst +161 -0
- fhe_sdk-0.1.0/external/HEonGPU/docs/index.rst +31 -0
- fhe_sdk-0.1.0/external/HEonGPU/docs/introduction.rst +90 -0
- fhe_sdk-0.1.0/external/HEonGPU/docs/make.bat +35 -0
- fhe_sdk-0.1.0/external/HEonGPU/docs/requirements.txt +4 -0
- fhe_sdk-0.1.0/external/HEonGPU/docs/technical_deep_dive.rst +64 -0
- fhe_sdk-0.1.0/external/HEonGPU/docs/user_guide.rst +135 -0
- fhe_sdk-0.1.0/external/HEonGPU/example/CMakeLists.txt +8 -0
- fhe_sdk-0.1.0/external/HEonGPU/example/basic/10_basic_ckks_logic.cpp +170 -0
- fhe_sdk-0.1.0/external/HEonGPU/example/basic/11_bfv_serialization.cpp +167 -0
- fhe_sdk-0.1.0/external/HEonGPU/example/basic/12_ckks_serialization.cpp +165 -0
- fhe_sdk-0.1.0/external/HEonGPU/example/basic/13_basic_tfhe.cpp +183 -0
- fhe_sdk-0.1.0/external/HEonGPU/example/basic/1_basic_bfv.cpp +190 -0
- fhe_sdk-0.1.0/external/HEonGPU/example/basic/2_basic_ckks.cpp +179 -0
- fhe_sdk-0.1.0/external/HEonGPU/example/basic/3_basic_memorypool_config.cpp +56 -0
- fhe_sdk-0.1.0/external/HEonGPU/example/basic/4_switchkey_methods_bfv.cpp +203 -0
- fhe_sdk-0.1.0/external/HEonGPU/example/basic/5_switchkey_methods_ckks.cpp +165 -0
- fhe_sdk-0.1.0/external/HEonGPU/example/basic/6_default_stream_usage.cpp +152 -0
- fhe_sdk-0.1.0/external/HEonGPU/example/basic/7_multi_stream_usage_way1.cpp +175 -0
- fhe_sdk-0.1.0/external/HEonGPU/example/basic/8_multi_stream_usage_way2.cpp +170 -0
- fhe_sdk-0.1.0/external/HEonGPU/example/basic/9_basic_bfv_logic.cpp +183 -0
- fhe_sdk-0.1.0/external/HEonGPU/example/basic/CMakeLists.txt +46 -0
- fhe_sdk-0.1.0/external/HEonGPU/example/basic/README.md +31 -0
- fhe_sdk-0.1.0/external/HEonGPU/example/bootstrapping/1_ckks_regular_bootstrapping.cpp +130 -0
- fhe_sdk-0.1.0/external/HEonGPU/example/bootstrapping/2_ckks_slim_bootstrapping.cpp +131 -0
- fhe_sdk-0.1.0/external/HEonGPU/example/bootstrapping/3_ckks_bit_bootstrapping.cpp +130 -0
- fhe_sdk-0.1.0/external/HEonGPU/example/bootstrapping/4_ckks_gate_bootstrapping.cpp +153 -0
- fhe_sdk-0.1.0/external/HEonGPU/example/bootstrapping/5_ckks_regular_bootstrapping_v2.cpp +175 -0
- fhe_sdk-0.1.0/external/HEonGPU/example/bootstrapping/CMakeLists.txt +38 -0
- fhe_sdk-0.1.0/external/HEonGPU/example/bootstrapping/README.md +141 -0
- fhe_sdk-0.1.0/external/HEonGPU/example/example_util.h +109 -0
- fhe_sdk-0.1.0/external/HEonGPU/example/mpc/1_multiparty_computation_bfv.cpp +321 -0
- fhe_sdk-0.1.0/external/HEonGPU/example/mpc/2_multiparty_computation_ckks.cpp +327 -0
- fhe_sdk-0.1.0/external/HEonGPU/example/mpc/3_mpc_collective_bootstrapping_bfv.cpp +255 -0
- fhe_sdk-0.1.0/external/HEonGPU/example/mpc/4_mpc_collective_bootstrapping_ckks.cpp +264 -0
- fhe_sdk-0.1.0/external/HEonGPU/example/mpc/CMakeLists.txt +37 -0
- fhe_sdk-0.1.0/external/HEonGPU/example/mpc/README.md +73 -0
- fhe_sdk-0.1.0/external/HEonGPU/multiparty_computation.svg +348 -0
- fhe_sdk-0.1.0/external/HEonGPU/src/CMakeLists.txt +308 -0
- fhe_sdk-0.1.0/external/HEonGPU/src/include/heongpu/heongpu.hpp +52 -0
- fhe_sdk-0.1.0/external/HEonGPU/src/include/heongpu/host/bfv/ciphertext.cuh +302 -0
- fhe_sdk-0.1.0/external/HEonGPU/src/include/heongpu/host/bfv/context.cuh +302 -0
- fhe_sdk-0.1.0/external/HEonGPU/src/include/heongpu/host/bfv/decryptor.cuh +199 -0
- fhe_sdk-0.1.0/external/HEonGPU/src/include/heongpu/host/bfv/encoder.cuh +309 -0
- fhe_sdk-0.1.0/external/HEonGPU/src/include/heongpu/host/bfv/encryptor.cuh +154 -0
- fhe_sdk-0.1.0/external/HEonGPU/src/include/heongpu/host/bfv/evaluationkey.cuh +830 -0
- fhe_sdk-0.1.0/external/HEonGPU/src/include/heongpu/host/bfv/keygenerator.cuh +275 -0
- fhe_sdk-0.1.0/external/HEonGPU/src/include/heongpu/host/bfv/mpcmanager.cuh +655 -0
- fhe_sdk-0.1.0/external/HEonGPU/src/include/heongpu/host/bfv/operator.cuh +2375 -0
- fhe_sdk-0.1.0/external/HEonGPU/src/include/heongpu/host/bfv/plaintext.cuh +223 -0
- fhe_sdk-0.1.0/external/HEonGPU/src/include/heongpu/host/bfv/publickey.cuh +314 -0
- fhe_sdk-0.1.0/external/HEonGPU/src/include/heongpu/host/bfv/secretkey.cuh +330 -0
- fhe_sdk-0.1.0/external/HEonGPU/src/include/heongpu/host/ckks/chebyshev_interpolation.cuh +54 -0
- fhe_sdk-0.1.0/external/HEonGPU/src/include/heongpu/host/ckks/ciphertext.cuh +349 -0
- fhe_sdk-0.1.0/external/HEonGPU/src/include/heongpu/host/ckks/context.cuh +182 -0
- fhe_sdk-0.1.0/external/HEonGPU/src/include/heongpu/host/ckks/cosine_approx.cuh +36 -0
- fhe_sdk-0.1.0/external/HEonGPU/src/include/heongpu/host/ckks/decryptor.cuh +153 -0
- fhe_sdk-0.1.0/external/HEonGPU/src/include/heongpu/host/ckks/encoder.cuh +472 -0
- fhe_sdk-0.1.0/external/HEonGPU/src/include/heongpu/host/ckks/encryptor.cuh +154 -0
- fhe_sdk-0.1.0/external/HEonGPU/src/include/heongpu/host/ckks/evaluationkey.cuh +984 -0
- fhe_sdk-0.1.0/external/HEonGPU/src/include/heongpu/host/ckks/keygenerator.cuh +286 -0
- fhe_sdk-0.1.0/external/HEonGPU/src/include/heongpu/host/ckks/mpcmanager.cuh +675 -0
- fhe_sdk-0.1.0/external/HEonGPU/src/include/heongpu/host/ckks/operator.cuh +3493 -0
- fhe_sdk-0.1.0/external/HEonGPU/src/include/heongpu/host/ckks/plaintext.cuh +246 -0
- fhe_sdk-0.1.0/external/HEonGPU/src/include/heongpu/host/ckks/precision.cuh +93 -0
- fhe_sdk-0.1.0/external/HEonGPU/src/include/heongpu/host/ckks/publickey.cuh +312 -0
- fhe_sdk-0.1.0/external/HEonGPU/src/include/heongpu/host/ckks/secretkey.cuh +329 -0
- fhe_sdk-0.1.0/external/HEonGPU/src/include/heongpu/host/tfhe/ciphertext.cuh +270 -0
- fhe_sdk-0.1.0/external/HEonGPU/src/include/heongpu/host/tfhe/context.cuh +89 -0
- fhe_sdk-0.1.0/external/HEonGPU/src/include/heongpu/host/tfhe/decryptor.cuh +78 -0
- fhe_sdk-0.1.0/external/HEonGPU/src/include/heongpu/host/tfhe/encryptor.cuh +112 -0
- fhe_sdk-0.1.0/external/HEonGPU/src/include/heongpu/host/tfhe/evaluationkey.cuh +386 -0
- fhe_sdk-0.1.0/external/HEonGPU/src/include/heongpu/host/tfhe/keygenerator.cuh +99 -0
- fhe_sdk-0.1.0/external/HEonGPU/src/include/heongpu/host/tfhe/operator.cuh +887 -0
- fhe_sdk-0.1.0/external/HEonGPU/src/include/heongpu/host/tfhe/secretkey.cuh +364 -0
- fhe_sdk-0.1.0/external/HEonGPU/src/include/heongpu/kernel/addition.cuh +80 -0
- fhe_sdk-0.1.0/external/HEonGPU/src/include/heongpu/kernel/bootstrapping.cuh +206 -0
- fhe_sdk-0.1.0/external/HEonGPU/src/include/heongpu/kernel/contextpool.hpp +105 -0
- fhe_sdk-0.1.0/external/HEonGPU/src/include/heongpu/kernel/decryption.cuh +105 -0
- fhe_sdk-0.1.0/external/HEonGPU/src/include/heongpu/kernel/defines.h +40 -0
- fhe_sdk-0.1.0/external/HEonGPU/src/include/heongpu/kernel/encoding.cuh +50 -0
- fhe_sdk-0.1.0/external/HEonGPU/src/include/heongpu/kernel/encryption.cuh +54 -0
- fhe_sdk-0.1.0/external/HEonGPU/src/include/heongpu/kernel/keygeneration.cuh +178 -0
- fhe_sdk-0.1.0/external/HEonGPU/src/include/heongpu/kernel/multiplication.cuh +84 -0
- fhe_sdk-0.1.0/external/HEonGPU/src/include/heongpu/kernel/small_ntt.cuh +26 -0
- fhe_sdk-0.1.0/external/HEonGPU/src/include/heongpu/kernel/switchkey.cuh +190 -0
- fhe_sdk-0.1.0/external/HEonGPU/src/include/heongpu/util/bigintegerarith.cuh +206 -0
- fhe_sdk-0.1.0/external/HEonGPU/src/include/heongpu/util/defaultmodulus.hpp +37 -0
- fhe_sdk-0.1.0/external/HEonGPU/src/include/heongpu/util/devicevector.cuh +176 -0
- fhe_sdk-0.1.0/external/HEonGPU/src/include/heongpu/util/hostvector.cuh +33 -0
- fhe_sdk-0.1.0/external/HEonGPU/src/include/heongpu/util/memorypool.cuh +150 -0
- fhe_sdk-0.1.0/external/HEonGPU/src/include/heongpu/util/random.cuh +714 -0
- fhe_sdk-0.1.0/external/HEonGPU/src/include/heongpu/util/schemes.h +122 -0
- fhe_sdk-0.1.0/external/HEonGPU/src/include/heongpu/util/secstdparams.h +82 -0
- fhe_sdk-0.1.0/external/HEonGPU/src/include/heongpu/util/serializer.h +132 -0
- fhe_sdk-0.1.0/external/HEonGPU/src/include/heongpu/util/storagemanager.cuh +278 -0
- fhe_sdk-0.1.0/external/HEonGPU/src/include/heongpu/util/util.cuh +319 -0
- fhe_sdk-0.1.0/external/HEonGPU/src/lib/heongpu.cpp +11 -0
- fhe_sdk-0.1.0/external/HEonGPU/src/lib/host/bfv/ciphertext.cu +371 -0
- fhe_sdk-0.1.0/external/HEonGPU/src/lib/host/bfv/context.cu +1430 -0
- fhe_sdk-0.1.0/external/HEonGPU/src/lib/host/bfv/decryptor.cu +273 -0
- fhe_sdk-0.1.0/external/HEonGPU/src/lib/host/bfv/encoder.cu +336 -0
- fhe_sdk-0.1.0/external/HEonGPU/src/lib/host/bfv/encryptor.cu +136 -0
- fhe_sdk-0.1.0/external/HEonGPU/src/lib/host/bfv/evaluationkey.cu +1035 -0
- fhe_sdk-0.1.0/external/HEonGPU/src/lib/host/bfv/keygenerator.cu +1113 -0
- fhe_sdk-0.1.0/external/HEonGPU/src/lib/host/bfv/mpcmanager.cu +1663 -0
- fhe_sdk-0.1.0/external/HEonGPU/src/lib/host/bfv/operator.cu +1633 -0
- fhe_sdk-0.1.0/external/HEonGPU/src/lib/host/bfv/plaintext.cu +271 -0
- fhe_sdk-0.1.0/external/HEonGPU/src/lib/host/bfv/publickey.cu +293 -0
- fhe_sdk-0.1.0/external/HEonGPU/src/lib/host/bfv/secretkey.cu +433 -0
- fhe_sdk-0.1.0/external/HEonGPU/src/lib/host/ckks/chebyshev_interpolation.cu +84 -0
- fhe_sdk-0.1.0/external/HEonGPU/src/lib/host/ckks/ciphertext.cu +387 -0
- fhe_sdk-0.1.0/external/HEonGPU/src/lib/host/ckks/context.cu +843 -0
- fhe_sdk-0.1.0/external/HEonGPU/src/lib/host/ckks/cosine_approx.cu +378 -0
- fhe_sdk-0.1.0/external/HEonGPU/src/lib/host/ckks/decryptor.cu +66 -0
- fhe_sdk-0.1.0/external/HEonGPU/src/lib/host/ckks/encoder.cu +614 -0
- fhe_sdk-0.1.0/external/HEonGPU/src/lib/host/ckks/encryptor.cu +128 -0
- fhe_sdk-0.1.0/external/HEonGPU/src/lib/host/ckks/evaluationkey.cu +1275 -0
- fhe_sdk-0.1.0/external/HEonGPU/src/lib/host/ckks/keygenerator.cu +1269 -0
- fhe_sdk-0.1.0/external/HEonGPU/src/lib/host/ckks/mpcmanager.cu +1783 -0
- fhe_sdk-0.1.0/external/HEonGPU/src/lib/host/ckks/operator.cu +7278 -0
- fhe_sdk-0.1.0/external/HEonGPU/src/lib/host/ckks/plaintext.cu +282 -0
- fhe_sdk-0.1.0/external/HEonGPU/src/lib/host/ckks/precision.cu +246 -0
- fhe_sdk-0.1.0/external/HEonGPU/src/lib/host/ckks/publickey.cu +293 -0
- fhe_sdk-0.1.0/external/HEonGPU/src/lib/host/ckks/secretkey.cu +435 -0
- fhe_sdk-0.1.0/external/HEonGPU/src/lib/host/tfhe/ciphertext.cu +152 -0
- fhe_sdk-0.1.0/external/HEonGPU/src/lib/host/tfhe/context.cu +107 -0
- fhe_sdk-0.1.0/external/HEonGPU/src/lib/host/tfhe/decryptor.cu +49 -0
- fhe_sdk-0.1.0/external/HEonGPU/src/lib/host/tfhe/encryptor.cu +121 -0
- fhe_sdk-0.1.0/external/HEonGPU/src/lib/host/tfhe/evaluationkey.cu +184 -0
- fhe_sdk-0.1.0/external/HEonGPU/src/lib/host/tfhe/keygenerator.cu +208 -0
- fhe_sdk-0.1.0/external/HEonGPU/src/lib/host/tfhe/operator.cu +332 -0
- fhe_sdk-0.1.0/external/HEonGPU/src/lib/host/tfhe/secretkey.cu +172 -0
- fhe_sdk-0.1.0/external/HEonGPU/src/lib/kernel/addition.cu +321 -0
- fhe_sdk-0.1.0/external/HEonGPU/src/lib/kernel/bootstrapping.cu +1438 -0
- fhe_sdk-0.1.0/external/HEonGPU/src/lib/kernel/contextpool.cpp +999 -0
- fhe_sdk-0.1.0/external/HEonGPU/src/lib/kernel/decryption.cu +669 -0
- fhe_sdk-0.1.0/external/HEonGPU/src/lib/kernel/encoding.cu +354 -0
- fhe_sdk-0.1.0/external/HEonGPU/src/lib/kernel/encryption.cu +329 -0
- fhe_sdk-0.1.0/external/HEonGPU/src/lib/kernel/keygeneration.cu +1448 -0
- fhe_sdk-0.1.0/external/HEonGPU/src/lib/kernel/multiplication.cu +577 -0
- fhe_sdk-0.1.0/external/HEonGPU/src/lib/kernel/small_ntt.cu +146 -0
- fhe_sdk-0.1.0/external/HEonGPU/src/lib/kernel/switchkey.cu +1718 -0
- fhe_sdk-0.1.0/external/HEonGPU/src/lib/util/defaultmodulus.cpp +175 -0
- fhe_sdk-0.1.0/external/HEonGPU/src/lib/util/memorypool.cu +405 -0
- fhe_sdk-0.1.0/external/HEonGPU/src/lib/util/random.cu +191 -0
- fhe_sdk-0.1.0/external/HEonGPU/src/lib/util/serializer.cpp +52 -0
- fhe_sdk-0.1.0/external/HEonGPU/src/lib/util/util.cu +878 -0
- fhe_sdk-0.1.0/external/HEonGPU/test/CMakeLists.txt +68 -0
- fhe_sdk-0.1.0/external/HEonGPU/test/test_bfv_addition.cpp +515 -0
- fhe_sdk-0.1.0/external/HEonGPU/test/test_bfv_encoding.cpp +205 -0
- fhe_sdk-0.1.0/external/HEonGPU/test/test_bfv_encryption.cpp +290 -0
- fhe_sdk-0.1.0/external/HEonGPU/test/test_bfv_multiplication.cpp +810 -0
- fhe_sdk-0.1.0/external/HEonGPU/test/test_bfv_relinearization.cpp +1262 -0
- fhe_sdk-0.1.0/external/HEonGPU/test/test_bfv_rotation_method_1.cpp +435 -0
- fhe_sdk-0.1.0/external/HEonGPU/test/test_bfv_rotation_method_2.cpp +436 -0
- fhe_sdk-0.1.0/external/HEonGPU/test/test_ckks_addition.cpp +780 -0
- fhe_sdk-0.1.0/external/HEonGPU/test/test_ckks_encoding.cpp +281 -0
- fhe_sdk-0.1.0/external/HEonGPU/test/test_ckks_encryption.cpp +311 -0
- fhe_sdk-0.1.0/external/HEonGPU/test/test_ckks_multiplication.cpp +795 -0
- fhe_sdk-0.1.0/external/HEonGPU/test/test_ckks_relinearization.cpp +830 -0
- fhe_sdk-0.1.0/external/HEonGPU/test/test_ckks_rotation_method_1.cpp +517 -0
- fhe_sdk-0.1.0/external/HEonGPU/test/test_ckks_rotation_method_2.cpp +517 -0
- fhe_sdk-0.1.0/external/HEonGPU/test/test_tfhe_gate_boot.cpp +93 -0
- fhe_sdk-0.1.0/external/HEonGPU/thirdparty/CMakeLists.txt +34 -0
- fhe_sdk-0.1.0/external/HEonGPU/thirdparty/build.sh +1 -0
- fhe_sdk-0.1.0/pyproject.toml +89 -0
- fhe_sdk-0.1.0/scripts/build.sh +29 -0
- fhe_sdk-0.1.0/scripts/clean.sh +13 -0
- fhe_sdk-0.1.0/scripts/install_system_deps.sh +49 -0
- fhe_sdk-0.1.0/scripts/run_example.sh +25 -0
- fhe_sdk-0.1.0/scripts/run_tests.sh +8 -0
- fhe_sdk-0.1.0/src/api/__init__.py +15 -0
- fhe_sdk-0.1.0/src/api/ciphertext.py +207 -0
- fhe_sdk-0.1.0/src/api/context.py +327 -0
- fhe_sdk-0.1.0/src/api/functions/__init__.py +4 -0
- fhe_sdk-0.1.0/src/api/functions/relu.py +127 -0
- fhe_sdk-0.1.0/src/api/functions/square.py +30 -0
- fhe_sdk-0.1.0/src/api/input.py +25 -0
- fhe_sdk-0.1.0/src/api/layers/__init__.py +5 -0
- fhe_sdk-0.1.0/src/api/layers/conv2d.py +114 -0
- fhe_sdk-0.1.0/src/api/layers/linear.py +43 -0
- fhe_sdk-0.1.0/src/api/sequential.py +178 -0
- fhe_sdk-0.1.0/src/api/tensor.py +158 -0
- fhe_sdk-0.1.0/src/backend/CMakeLists.txt +1 -0
- fhe_sdk-0.1.0/src/backend/bindings/CMakeLists.txt +32 -0
- fhe_sdk-0.1.0/src/backend/bindings/bind_context.cu +85 -0
- fhe_sdk-0.1.0/src/backend/bindings/bind_crypto.cu +51 -0
- fhe_sdk-0.1.0/src/backend/bindings/bind_data.cu +123 -0
- fhe_sdk-0.1.0/src/backend/bindings/bind_enums.cu +30 -0
- fhe_sdk-0.1.0/src/backend/bindings/bind_keys.cu +109 -0
- fhe_sdk-0.1.0/src/backend/bindings/bind_operator.cu +249 -0
- fhe_sdk-0.1.0/src/backend/bindings/bindings.cu +35 -0
- fhe_sdk-0.1.0/src/backend/core/plaintext_matrix.hpp +24 -0
- fhe_sdk-0.1.0/src/core/__init__.py +7 -0
- fhe_sdk-0.1.0/src/core/enums.py +1 -0
- fhe_sdk-0.1.0/src/core/errors.py +16 -0
- fhe_sdk-0.1.0/src/core/layer.py +91 -0
- fhe_sdk-0.1.0/src/core/plaintext.py +55 -0
- fhe_sdk-0.1.0/src/core/utils/__init__.py +4 -0
- fhe_sdk-0.1.0/src/core/utils/convert.py +15 -0
- fhe_sdk-0.1.0/src/core/utils/validate.py +27 -0
- fhe_sdk-0.1.0/tests/conftest.py +22 -0
- fhe_sdk-0.1.0/tests/test_ciphertext.py +169 -0
- fhe_sdk-0.1.0/tests/test_context.py +80 -0
- fhe_sdk-0.1.0/tests/test_conv2d.py +184 -0
- fhe_sdk-0.1.0/tests/test_errors.py +69 -0
- fhe_sdk-0.1.0/tests/test_linear.py +46 -0
- fhe_sdk-0.1.0/tests/test_plaintext.py +97 -0
- fhe_sdk-0.1.0/tests/test_relu.py +42 -0
- fhe_sdk-0.1.0/tests/test_sequential.py +41 -0
- fhe_sdk-0.1.0/tests/test_tensor.py +188 -0
fhe_sdk-0.1.0/.gitignore
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
cmake_minimum_required(VERSION 3.25)
|
|
2
|
+
project(fhe-sdk LANGUAGES CXX CUDA)
|
|
3
|
+
|
|
4
|
+
set(CMAKE_CXX_STANDARD 17)
|
|
5
|
+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
|
6
|
+
set(CMAKE_CUDA_STANDARD 17)
|
|
7
|
+
set(CMAKE_CUDA_STANDARD_REQUIRED ON)
|
|
8
|
+
|
|
9
|
+
# Auto-build HEonGPU from submodule if not already installed.
|
|
10
|
+
# This runs during `pip install .` so the package is fully self-contained.
|
|
11
|
+
set(HEONGPU_INSTALL_DIR "${CMAKE_SOURCE_DIR}/build/heongpu")
|
|
12
|
+
file(GLOB _heongpu_cmake_dirs "${HEONGPU_INSTALL_DIR}/lib/cmake/HEonGPU*")
|
|
13
|
+
if(NOT _heongpu_cmake_dirs)
|
|
14
|
+
message(STATUS "HEonGPU not found at ${HEONGPU_INSTALL_DIR} — building from submodule...")
|
|
15
|
+
execute_process(
|
|
16
|
+
COMMAND bash "${CMAKE_SOURCE_DIR}/scripts/install_system_deps.sh"
|
|
17
|
+
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
|
|
18
|
+
RESULT_VARIABLE _heongpu_result
|
|
19
|
+
)
|
|
20
|
+
if(NOT _heongpu_result EQUAL 0)
|
|
21
|
+
message(FATAL_ERROR "install_system_deps.sh failed (exit ${_heongpu_result}). "
|
|
22
|
+
"Run it manually and check the output.")
|
|
23
|
+
endif()
|
|
24
|
+
endif()
|
|
25
|
+
list(APPEND CMAKE_PREFIX_PATH "${HEONGPU_INSTALL_DIR}")
|
|
26
|
+
|
|
27
|
+
find_package(CUDAToolkit REQUIRED)
|
|
28
|
+
find_package(HEonGPU REQUIRED)
|
|
29
|
+
find_package(pybind11 REQUIRED)
|
|
30
|
+
find_package(Python REQUIRED COMPONENTS Interpreter Development.Module)
|
|
31
|
+
|
|
32
|
+
add_subdirectory(src/backend)
|
fhe_sdk-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
FHE SDK - Proprietary License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Rcontre360. All rights reserved.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted to any person obtaining a copy of this software
|
|
6
|
+
and associated documentation files (the "Software"), to use the Software
|
|
7
|
+
solely for the purpose of installing, running, and interfacing with it as a
|
|
8
|
+
software development kit (SDK) for GPU-accelerated homomorphic encryption
|
|
9
|
+
inference.
|
|
10
|
+
|
|
11
|
+
The following restrictions apply:
|
|
12
|
+
|
|
13
|
+
1. The Software may not be modified, adapted, or used to create derivative
|
|
14
|
+
works without prior written permission from the copyright holder.
|
|
15
|
+
|
|
16
|
+
2. The Software may not be redistributed, sublicensed, sold, or otherwise
|
|
17
|
+
transferred to third parties, in whole or in part, without prior written
|
|
18
|
+
permission from the copyright holder.
|
|
19
|
+
|
|
20
|
+
3. The Software may not be used for purposes other than its intended use as
|
|
21
|
+
an SDK for homomorphic encryption inference.
|
|
22
|
+
|
|
23
|
+
4. The above copyright notice and this permission notice shall be included
|
|
24
|
+
in all copies or substantial portions of the Software.
|
|
25
|
+
|
|
26
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
27
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
28
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
29
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
30
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
31
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
32
|
+
SOFTWARE.
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# Files shipped in the source distribution (sdist).
|
|
2
|
+
# `python -m build --sdist` reads this; anything not listed is left out.
|
|
3
|
+
|
|
4
|
+
include CMakeLists.txt LICENSE README.md MANIFEST.in pyproject.toml
|
|
5
|
+
include docs/INTRO.md docs/API.md docs/CONFIG.md
|
|
6
|
+
|
|
7
|
+
# Python source
|
|
8
|
+
recursive-include src *.py
|
|
9
|
+
|
|
10
|
+
# C++/CUDA sources for the pybind11 backend
|
|
11
|
+
recursive-include src *.cu *.cpp *.hpp *.cuh *.h CMakeLists.txt
|
|
12
|
+
|
|
13
|
+
# Build helpers run during `pip install`
|
|
14
|
+
recursive-include scripts *.sh
|
|
15
|
+
|
|
16
|
+
# HEonGPU submodule — required for the CMake build to succeed.
|
|
17
|
+
# Git submodules are NOT auto-included in sdists, so we list the source tree
|
|
18
|
+
# explicitly. Built artifacts and tests are excluded to keep the tarball lean.
|
|
19
|
+
recursive-include external/HEonGPU *.cu *.cpp *.hpp *.cuh *.h
|
|
20
|
+
recursive-include external/HEonGPU CMakeLists.txt *.cmake
|
|
21
|
+
include external/HEonGPU/LICENSE external/HEonGPU/README.md
|
|
22
|
+
recursive-include external/HEonGPU/cmake *
|
|
23
|
+
recursive-include external/HEonGPU/thirdparty CMakeLists.txt *.sh
|
|
24
|
+
|
|
25
|
+
# Exclusions — never ship these even if they match an include above
|
|
26
|
+
global-exclude __pycache__
|
|
27
|
+
global-exclude *.pyc *.pyo
|
|
28
|
+
global-exclude .DS_Store
|
|
29
|
+
prune build
|
|
30
|
+
prune external/HEonGPU/build
|
|
31
|
+
prune external/HEonGPU/test
|
|
32
|
+
prune external/HEonGPU/benchmark
|
|
33
|
+
prune external/HEonGPU/example
|
|
34
|
+
prune external/HEonGPU/dev-tools
|
|
35
|
+
prune external/HEonGPU/docs
|
fhe_sdk-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,330 @@
|
|
|
1
|
+
Metadata-Version: 2.2
|
|
2
|
+
Name: fhe-sdk
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Python SDK for GPU-accelerated CKKS homomorphic encryption inference
|
|
5
|
+
Keywords: homomorphic-encryption,CKKS,FHE,privacy-preserving-ml,GPU,CUDA,neural-networks,bootstrapping
|
|
6
|
+
Author-Email: Rafael Contreras Pimentel <rcontreraspimentel@gmail.com>
|
|
7
|
+
Maintainer-Email: Rafael Contreras Pimentel <rcontreraspimentel@gmail.com>
|
|
8
|
+
License: FHE SDK - Proprietary License
|
|
9
|
+
|
|
10
|
+
Copyright (c) 2025 Rcontre360. All rights reserved.
|
|
11
|
+
|
|
12
|
+
Permission is hereby granted to any person obtaining a copy of this software
|
|
13
|
+
and associated documentation files (the "Software"), to use the Software
|
|
14
|
+
solely for the purpose of installing, running, and interfacing with it as a
|
|
15
|
+
software development kit (SDK) for GPU-accelerated homomorphic encryption
|
|
16
|
+
inference.
|
|
17
|
+
|
|
18
|
+
The following restrictions apply:
|
|
19
|
+
|
|
20
|
+
1. The Software may not be modified, adapted, or used to create derivative
|
|
21
|
+
works without prior written permission from the copyright holder.
|
|
22
|
+
|
|
23
|
+
2. The Software may not be redistributed, sublicensed, sold, or otherwise
|
|
24
|
+
transferred to third parties, in whole or in part, without prior written
|
|
25
|
+
permission from the copyright holder.
|
|
26
|
+
|
|
27
|
+
3. The Software may not be used for purposes other than its intended use as
|
|
28
|
+
an SDK for homomorphic encryption inference.
|
|
29
|
+
|
|
30
|
+
4. The above copyright notice and this permission notice shall be included
|
|
31
|
+
in all copies or substantial portions of the Software.
|
|
32
|
+
|
|
33
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
34
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
35
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
36
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
37
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
38
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
39
|
+
SOFTWARE.
|
|
40
|
+
|
|
41
|
+
Classifier: Development Status :: 3 - Alpha
|
|
42
|
+
Classifier: Intended Audience :: Science/Research
|
|
43
|
+
Classifier: License :: Other/Proprietary License
|
|
44
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
45
|
+
Classifier: Environment :: GPU :: NVIDIA CUDA :: 12
|
|
46
|
+
Classifier: Programming Language :: Python :: 3
|
|
47
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
48
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
49
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
50
|
+
Classifier: Topic :: Security :: Cryptography
|
|
51
|
+
Project-URL: Homepage, https://github.com/Rcontre360/thesis-ucv-FHE
|
|
52
|
+
Project-URL: Repository, https://github.com/Rcontre360/thesis-ucv-FHE
|
|
53
|
+
Project-URL: Issues, https://github.com/Rcontre360/thesis-ucv-FHE/issues
|
|
54
|
+
Requires-Python: >=3.11
|
|
55
|
+
Requires-Dist: numpy>=1.26
|
|
56
|
+
Provides-Extra: dev
|
|
57
|
+
Requires-Dist: pytest>=8.0; extra == "dev"
|
|
58
|
+
Requires-Dist: pytest-cov>=5.0; extra == "dev"
|
|
59
|
+
Requires-Dist: mypy>=1.10; extra == "dev"
|
|
60
|
+
Requires-Dist: ruff>=0.4; extra == "dev"
|
|
61
|
+
Requires-Dist: black>=24.0; extra == "dev"
|
|
62
|
+
Requires-Dist: hypothesis>=6.100; extra == "dev"
|
|
63
|
+
Description-Content-Type: text/markdown
|
|
64
|
+
|
|
65
|
+
# fhe-sdk
|
|
66
|
+
|
|
67
|
+
Python library for GPU-accelerated fully homomorphic encryption (FHE) inference over neural networks. Wraps [HEonGPU](https://github.com/Alisah-Ozcan/HEonGPU) (C++/CUDA) via pybind11. Scheme is always CKKS; users never interact with raw cryptographic objects.
|
|
68
|
+
|
|
69
|
+
Two public packages: **`api`** (high-level — `FHEContext`, `Sequential`, `Linear`, `Conv2D`, `ReLU`, `Square`) and **`core`** (enums, errors, base `Layer` ABC). The `_backend` extension is an implementation detail and not part of the public API.
|
|
70
|
+
|
|
71
|
+
Full API reference: [`docs/API.md`](docs/API.md).
|
|
72
|
+
|
|
73
|
+
---
|
|
74
|
+
|
|
75
|
+
## System requirements
|
|
76
|
+
|
|
77
|
+
This is a CUDA library — every install runs `nvcc`. The CI / development target is the stack below; older or newer versions may work but are not tested.
|
|
78
|
+
|
|
79
|
+
| Component | Required version | Notes |
|
|
80
|
+
| --- | --- | --- |
|
|
81
|
+
| NVIDIA GPU | Compute capability ≥ 7.0 (Volta or newer) | Pascal and older lack the tensor-core primitives HEonGPU uses. |
|
|
82
|
+
| NVIDIA driver | ≥ 535 | Whatever ships with CUDA 12.8. |
|
|
83
|
+
| **CUDA Toolkit** | **12.8** | `nvcc --version` must report 12.8. Set `CUDA_HOME` so `find_package(CUDAToolkit)` resolves. |
|
|
84
|
+
| Python | 3.11 or 3.12 | 3.13 untested; 3.10 and below not supported. |
|
|
85
|
+
| CMake | ≥ 3.30 | HEonGPU's requirement. `pip install cmake` works if your distro ships an older one. |
|
|
86
|
+
| GCC / G++ | 11–13 | Must be CUDA-12.8 compatible. GCC 14 is rejected by `nvcc`. |
|
|
87
|
+
| Ninja | optional | Speeds up the build (`pip install ninja`); CMake falls back to Make otherwise. |
|
|
88
|
+
| Git | any recent | Needed to clone the HEonGPU submodule at install time. |
|
|
89
|
+
| Disk | ~2 GB free | HEonGPU + bindings build artifacts. |
|
|
90
|
+
|
|
91
|
+
OS support: **Linux only.** Tested on Ubuntu 22.04 / 24.04. WSL2 works if CUDA is correctly forwarded. macOS and Windows native are not supported (HEonGPU is CUDA-only).
|
|
92
|
+
|
|
93
|
+
---
|
|
94
|
+
|
|
95
|
+
## Installation
|
|
96
|
+
|
|
97
|
+
### From PyPI
|
|
98
|
+
|
|
99
|
+
```bash
|
|
100
|
+
pip install fhe-sdk
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
This downloads the source distribution and triggers a local CMake + CUDA build (≈ 8–15 minutes on a modern desktop). HEonGPU is cloned and built as part of the install.
|
|
104
|
+
|
|
105
|
+
### From source (development)
|
|
106
|
+
|
|
107
|
+
```bash
|
|
108
|
+
git clone --recurse-submodules https://github.com/Rcontre360/thesis-ucv-FHE.git
|
|
109
|
+
cd thesis-ucv-FHE/sdk
|
|
110
|
+
pip install -e .
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
If you forgot `--recurse-submodules`:
|
|
114
|
+
|
|
115
|
+
```bash
|
|
116
|
+
git submodule update --init --recursive
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
### Verify
|
|
120
|
+
|
|
121
|
+
```python
|
|
122
|
+
from api import FHEContext
|
|
123
|
+
from core.enums import SecurityLevel
|
|
124
|
+
|
|
125
|
+
ctx = (
|
|
126
|
+
FHEContext()
|
|
127
|
+
.set_poly_modulus_degree(8192)
|
|
128
|
+
.set_coeff_modulus_bit_sizes([60, 40, 40, 60])
|
|
129
|
+
.set_scale(2**40)
|
|
130
|
+
.set_security_level(SecurityLevel.SEC128)
|
|
131
|
+
.build()
|
|
132
|
+
)
|
|
133
|
+
print("OK")
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
If the import fails with `ImportError: libheongpu.so` or similar, the install completed but the runtime can't locate the C++ library — usually because `CUDA_HOME` / `LD_LIBRARY_PATH` is unset. Re-run the install in a fresh terminal after sourcing your CUDA env.
|
|
137
|
+
|
|
138
|
+
---
|
|
139
|
+
|
|
140
|
+
## Quickstart
|
|
141
|
+
|
|
142
|
+
### Crypto primitives
|
|
143
|
+
|
|
144
|
+
```python
|
|
145
|
+
from fhe_sdk import FHEContext
|
|
146
|
+
from fhe_sdk.enums import SecurityLevel
|
|
147
|
+
|
|
148
|
+
# Build a context (fluent setter API)
|
|
149
|
+
ctx = (
|
|
150
|
+
FHEContext()
|
|
151
|
+
.set_poly_modulus_degree(8192)
|
|
152
|
+
.set_coeff_modulus_bit_sizes([60, 40, 40, 60])
|
|
153
|
+
.set_scale(2**40)
|
|
154
|
+
.set_security_level(SecurityLevel.SEC128)
|
|
155
|
+
.build()
|
|
156
|
+
)
|
|
157
|
+
|
|
158
|
+
# Or use the one-call default (equivalent to the above)
|
|
159
|
+
ctx = FHEContext.default()
|
|
160
|
+
|
|
161
|
+
# Encode only — produces a Plaintext (not encrypted)
|
|
162
|
+
values: list[float] = [0.1, 0.5, -0.3, 0.9]
|
|
163
|
+
pt = ctx.encode(values)
|
|
164
|
+
|
|
165
|
+
# Encrypt — accepts list[float] or Plaintext
|
|
166
|
+
ct = ctx.encrypt(values) # encode + encrypt in one step
|
|
167
|
+
ct = ctx.encrypt(pt) # encrypt an already-encoded Plaintext
|
|
168
|
+
|
|
169
|
+
# Arithmetic on Ciphertext
|
|
170
|
+
a = ctx.encrypt([1.0, 2.0, 3.0, 4.0])
|
|
171
|
+
b = ctx.encrypt([0.5, 0.5, 0.5, 0.5])
|
|
172
|
+
pt_b = ctx.encode([0.5, 0.5, 0.5, 0.5])
|
|
173
|
+
|
|
174
|
+
c = a + b # ct + ct — homomorphic addition, free
|
|
175
|
+
d = a * b # ct * ct — homomorphic multiply, consumes one level
|
|
176
|
+
e = a + pt_b # ct + Plaintext — free
|
|
177
|
+
f = a * pt_b # ct * Plaintext — consumes one level
|
|
178
|
+
g = a * 2.0 # ct * scalar
|
|
179
|
+
h = a + [1.0, 2.0, 3.0, 4.0] # ct + list[float] — auto-encodes on the fly
|
|
180
|
+
|
|
181
|
+
# Decrypt
|
|
182
|
+
result: list[float] = ctx.decrypt(d)
|
|
183
|
+
result: list[float] = d.decrypt() # shorthand
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
### Neural network inference
|
|
187
|
+
|
|
188
|
+
This example loads a pre-trained PyTorch model and runs encrypted inference.
|
|
189
|
+
|
|
190
|
+
```python
|
|
191
|
+
import torch
|
|
192
|
+
import torch.nn as torch_nn
|
|
193
|
+
|
|
194
|
+
from fhe_sdk import FHEContext
|
|
195
|
+
from fhe_sdk.nn import Sequential, Linear, Square
|
|
196
|
+
|
|
197
|
+
# Pre-trained PyTorch model
|
|
198
|
+
class SmallNet(torch_nn.Module):
|
|
199
|
+
def __init__(self):
|
|
200
|
+
super().__init__()
|
|
201
|
+
self.fc1 = torch_nn.Linear(64, 64)
|
|
202
|
+
self.fc2 = torch_nn.Linear(64, 10)
|
|
203
|
+
|
|
204
|
+
def forward(self, x):
|
|
205
|
+
return self.fc2(self.fc1(x) ** 2)
|
|
206
|
+
|
|
207
|
+
torch_model = SmallNet()
|
|
208
|
+
# torch_model.load_state_dict(torch.load("weights.pt"))
|
|
209
|
+
|
|
210
|
+
# FHE context — default gives 2 usable levels, enough for one Square activation
|
|
211
|
+
ctx = FHEContext.default()
|
|
212
|
+
|
|
213
|
+
# Build the FHE model
|
|
214
|
+
fhe_model = Sequential(
|
|
215
|
+
Linear(in_features=64, out_features=64),
|
|
216
|
+
Square(),
|
|
217
|
+
Linear(in_features=64, out_features=10),
|
|
218
|
+
)
|
|
219
|
+
|
|
220
|
+
# Load weights from the pre-trained PyTorch layers
|
|
221
|
+
fhe_model[0].load_from_torch(torch_model.fc1)
|
|
222
|
+
fhe_model[2].load_from_torch(torch_model.fc2)
|
|
223
|
+
|
|
224
|
+
# Encrypted inference
|
|
225
|
+
plaintext_input: list[float] = [0.0] * 64 # replace with real features
|
|
226
|
+
|
|
227
|
+
enc_input = ctx.encrypt(plaintext_input)
|
|
228
|
+
enc_output = fhe_model(enc_input) # Ciphertext of size 10
|
|
229
|
+
result: list[float] = enc_output.decrypt() # list[float] of length 10
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
`fhe_model(enc_input)` is identical to `fhe_model.forward(enc_input)`.
|
|
233
|
+
|
|
234
|
+
### Loading weights from NumPy
|
|
235
|
+
|
|
236
|
+
```python
|
|
237
|
+
import numpy as np
|
|
238
|
+
from fhe_sdk.nn import Linear
|
|
239
|
+
|
|
240
|
+
W = np.random.randn(10, 64).astype(np.float64)
|
|
241
|
+
b = np.random.randn(10).astype(np.float64)
|
|
242
|
+
|
|
243
|
+
layer = Linear(in_features=64, out_features=10)
|
|
244
|
+
layer.load_weights(W, b) # accepts numpy.ndarray, torch.Tensor, or list[list[float]]
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
---
|
|
248
|
+
|
|
249
|
+
## Depth Budget Guide
|
|
250
|
+
|
|
251
|
+
CKKS represents ciphertexts relative to a chain of modulus primes (`q_0 * q_1 * ... * q_L`). Each multiplication consumes one prime. When all intermediate primes are exhausted, no further multiplications are possible.
|
|
252
|
+
|
|
253
|
+
```
|
|
254
|
+
usable_levels = len(coeff_modulus_bit_sizes) - 2
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
The first and last primes are special and not consumed by computations — a chain of length 4 gives 2 usable levels.
|
|
258
|
+
|
|
259
|
+
### Level cost per layer type
|
|
260
|
+
|
|
261
|
+
| Layer / Operation | Levels consumed |
|
|
262
|
+
|---|---|
|
|
263
|
+
| `Linear` | 0 — matrix-vector multiply uses plaintext weights |
|
|
264
|
+
| `Square` | 1 |
|
|
265
|
+
| `ApproxReLU(degree=3)` | 2 |
|
|
266
|
+
| `ApproxReLU(degree=5)` | 3 |
|
|
267
|
+
| `ApproxSigmoid(degree=3)` | 2 |
|
|
268
|
+
| `ApproxSigmoid(degree=5)` | 3 |
|
|
269
|
+
|
|
270
|
+
Add 1 extra level as a safety margin.
|
|
271
|
+
|
|
272
|
+
### Example: 2-layer network with Square
|
|
273
|
+
|
|
274
|
+
```
|
|
275
|
+
Sequential(Linear(64,64), Square(), Linear(64,10))
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
Levels needed: 1. With margin: 2. Chain length: 4.
|
|
279
|
+
|
|
280
|
+
```python
|
|
281
|
+
ctx = (
|
|
282
|
+
FHEContext()
|
|
283
|
+
.set_poly_modulus_degree(8192)
|
|
284
|
+
.set_coeff_modulus_bit_sizes([60, 40, 40, 60]) # 2 usable levels
|
|
285
|
+
.set_scale(2**40)
|
|
286
|
+
.build()
|
|
287
|
+
)
|
|
288
|
+
# Equivalent: FHEContext.default()
|
|
289
|
+
```
|
|
290
|
+
|
|
291
|
+
### Example: deeper network with ApproxReLU
|
|
292
|
+
|
|
293
|
+
```
|
|
294
|
+
Sequential(
|
|
295
|
+
Linear(128, 64), ApproxReLU(degree=3), # 2 levels
|
|
296
|
+
Linear(64, 64), ApproxReLU(degree=3), # 2 levels
|
|
297
|
+
Linear(64, 10),
|
|
298
|
+
)
|
|
299
|
+
```
|
|
300
|
+
|
|
301
|
+
Levels needed: 4. With margin: 5. Chain length: 7. Requires `poly_modulus_degree=16384` to keep the larger modulus sum within the 128-bit security bound.
|
|
302
|
+
|
|
303
|
+
```python
|
|
304
|
+
ctx = (
|
|
305
|
+
FHEContext()
|
|
306
|
+
.set_poly_modulus_degree(16384)
|
|
307
|
+
.set_coeff_modulus_bit_sizes([60, 40, 40, 40, 40, 40, 60]) # 5 usable levels
|
|
308
|
+
.set_scale(2**40)
|
|
309
|
+
.build()
|
|
310
|
+
)
|
|
311
|
+
```
|
|
312
|
+
|
|
313
|
+
---
|
|
314
|
+
|
|
315
|
+
## Crypto Parameter Reference
|
|
316
|
+
|
|
317
|
+
| `poly_modulus_degree` | `coeff_modulus_bit_sizes` | Total bits | Usable levels | Max slots | Notes |
|
|
318
|
+
|---|---|---|---|---|---|
|
|
319
|
+
| `4096` | `[40, 20, 40]` | 100 | 1 | 2048 | Minimal. Linear models only. |
|
|
320
|
+
| `8192` | `[60, 40, 40, 60]` | 200 | 2 | 4096 | **Default.** One Square or one ApproxReLU(degree=3) + margin. |
|
|
321
|
+
| `8192` | `[60, 40, 40, 40, 60]` | 240 | 3 | 4096 | One ApproxReLU(degree=3) + one Square, with margin. |
|
|
322
|
+
| `16384` | `[60, 40, 40, 40, 40, 40, 60]` | 320 | 5 | 8192 | Two ApproxReLU(degree=3) activations, with margin. |
|
|
323
|
+
| `16384` | `[60, 50, 50, 50, 50, 50, 50, 60]` | 420 | 6 | 8192 | Deeper models or degree-5 activations. |
|
|
324
|
+
| `32768` | `[60, 40, 40, 40, 40, 40, 40, 40, 40, 60]` | 540 | 8 | 16384 | Deep models; large input vectors. |
|
|
325
|
+
|
|
326
|
+
- `poly_modulus_degree` must be a power of 2.
|
|
327
|
+
- Max encrypted vector length is `poly_modulus_degree / 2`.
|
|
328
|
+
- Interior primes should have bit size equal to `log2(scale)`. Mismatches cause growing noise after rescaling.
|
|
329
|
+
- Exceeding the security-level bit-sum limit causes `build()` to raise `ValueError`.
|
|
330
|
+
- Use `SecurityLevel.SEC192` or `SEC256` for tighter security; this requires a larger `poly_modulus_degree` or shorter chain.
|