Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 16 additions & 11 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,24 @@ set(OPENFHE_PYTHON_VERSION_PATCH 0)
set(OPENFHE_PYTHON_VERSION_TWEAK 0)
set(OPENFHE_PYTHON_VERSION ${OPENFHE_PYTHON_VERSION_MAJOR}.${OPENFHE_PYTHON_VERSION_MINOR}.${OPENFHE_PYTHON_VERSION_PATCH}.${OPENFHE_PYTHON_VERSION_TWEAK})

# OpenFHE version can be specified externally (-DOPENFHE_REQUIRED_VERSION=1.3.0)
if(NOT DEFINED OPENFHE_REQUIRED_VERSION)
set(OPENFHE_REQUIRED_VERSION "1.3.0" CACHE STRING "Required OpenFHE version")
else()
# User provided OPENFHE_REQUIRED_VERSION via -D
message(STATUS "Using user-specified OpenFHE version: ${OPENFHE_REQUIRED_VERSION}")
endif()

set(CMAKE_CXX_STANDARD 17)
option( BUILD_STATIC "Set to ON to include static versions of the library" OFF)

if(APPLE)
set(CMAKE_CXX_VISIBILITY_PRESET default)
endif()

find_package(OpenFHE 1.3.0 REQUIRED)
find_package(OpenFHE ${OPENFHE_REQUIRED_VERSION} REQUIRED)
message(STATUS "Building with OpenFHE version: ${OPENFHE_REQUIRED_VERSION}")

set(PYBIND11_FINDPYTHON ON)
find_package(pybind11 REQUIRED)

Expand Down Expand Up @@ -66,20 +76,13 @@ pybind11_add_module(openfhe
### Python installation
# Allow the user to specify the path to Python executable (if not provided, find it)
option(PYTHON_EXECUTABLE_PATH "Path to Python executable" "")

if(NOT PYTHON_EXECUTABLE_PATH)
# Find Python and its development components
find_package(Python REQUIRED COMPONENTS Interpreter Development)
else()
# Set Python_EXECUTABLE to the specified path
if(PYTHON_EXECUTABLE_PATH)
set(Python_EXECUTABLE "${PYTHON_EXECUTABLE_PATH}")
endif()

# Find Python interpreter
find_package(PythonInterp REQUIRED)
find_package(Python REQUIRED COMPONENTS Interpreter Development)

# Check Python version
if(${PYTHON_VERSION_MAJOR} EQUAL 3 AND ${PYTHON_VERSION_MINOR} GREATER_EQUAL 10)
if(${Python_VERSION_MAJOR} EQUAL 3 AND ${Python_VERSION_MINOR} GREATER_EQUAL 10)
execute_process(
COMMAND "${Python_EXECUTABLE}" -c "from sys import exec_prefix; print(exec_prefix)"
OUTPUT_VARIABLE PYTHON_SITE_PACKAGES
Expand All @@ -101,3 +104,5 @@ else()
endif()
message("***** INSTALL IS AT ${Python_Install_Location}; to change, run cmake with -DCMAKE_INSTALL_PREFIX=/your/path")
install(TARGETS openfhe LIBRARY DESTINATION ${Python_Install_Location})
install(FILES ${CMAKE_SOURCE_DIR}/__init__.py DESTINATION ${Python_Install_Location})

48 changes: 48 additions & 0 deletions __init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import os
import ctypes


def load_shared_library(libname, paths):
for path in paths:
lib_path = os.path.join(path, libname)
if os.path.exists(lib_path):
return ctypes.CDLL(lib_path, mode=ctypes.RTLD_GLOBAL)

raise FileNotFoundError(
f"Shared library {libname} not found in {paths}"
)

# Search LD_LIBRARY_PATH
ld_paths = os.environ.get("LD_LIBRARY_PATH", "").split(":")

if not any(ld_paths):
# Path to the bundled `lib/` directory inside site-packages
package_dir = os.path.abspath(os.path.dirname(__file__))
internal_lib_dir = [os.path.join(package_dir, 'lib')]

# Shared libraries required
shared_libs = [
'libgomp.so',
'libOPENFHEcore.so.1',
'libOPENFHEbinfhe.so.1',
'libOPENFHEpke.so.1',
]

for libname in shared_libs:
load_shared_library(libname, internal_lib_dir)

from .openfhe import *

else:
# Shared libraries required
# skip 'libgomp.so' if LD_LIBRARY_PATH is set as we should get it from the libgomp.so location
shared_libs = [
'libOPENFHEcore.so.1',
'libOPENFHEbinfhe.so.1',
'libOPENFHEpke.so.1',
]

for libname in shared_libs:
load_shared_library(libname, ld_paths)

# from .openfhe import *
1 change: 0 additions & 1 deletion openfhe/__init__.py

This file was deleted.

81 changes: 0 additions & 81 deletions setup.py

This file was deleted.

1 change: 1 addition & 0 deletions src/include/pke/cryptocontext_wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ Plaintext MultipartyDecryptFusionWrapper(CryptoContext<DCRTPoly>& self,const std

const std::shared_ptr<std::map<uint32_t, EvalKey<DCRTPoly>>> GetEvalSumKeyMapWrapper(CryptoContext<DCRTPoly>& self, const std::string &id);
PlaintextModulus GetPlaintextModulusWrapper(CryptoContext<DCRTPoly>& self);
uint32_t GetBatchSizeWrapper(CryptoContext<DCRTPoly>& self);
double GetModulusWrapper(CryptoContext<DCRTPoly>& self);
void RemoveElementWrapper(Ciphertext<DCRTPoly>& self, uint32_t index);
double GetScalingFactorRealWrapper(CryptoContext<DCRTPoly>& self, uint32_t l);
Expand Down
Loading