From 064c32bb7b1cfba5874e9730ae479c2bbf63ad41 Mon Sep 17 00:00:00 2001 From: shpark Date: Wed, 25 Oct 2023 10:46:26 +0900 Subject: [PATCH] [chore] Support build on macOS. --- CMakeLists.txt | 6 +++++- README.md | 1 + python/hecate/hecate/expr.py | 11 ++++++++++- python/hecate/hecate/runner.py | 12 +++++++++++- requirements.txt | 24 ++++++++++++------------ 5 files changed, 39 insertions(+), 15 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4692033..b67e303 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -36,7 +36,11 @@ project(HECATE set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED True) set(CMAKE_EXPORT_COMPILE_COMMANDS ON) -set(CMAKE_SHARED_LINKER_FLAGS "-Wl,--no-undefined") +if (NOT DEFINED CMAKE_OSX_ARCHITECTURES) + set(CMAKE_SHARED_LINKER_FLAGS "-Wl,--no-undefined") +else() + set(CMAKE_SHARED_LINKER_FLAGS "-Wl,-undefined,error") +endif() if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) message(STATUS "No build type selected, default to Release") diff --git a/README.md b/README.md index 1953601..3fe001c 100644 --- a/README.md +++ b/README.md @@ -35,6 +35,7 @@ clang,clang++ >= 14.0.0 git clone https://github.com/llvm/llvm-project.git cd llvm-project git checkout llvmorg-16.0.0 +# To build HECATE on macOS, please add `-DLLVM_BUILD_LLVM_DYLIB=ON`. cmake -GNinja -Bbuild \ -DCMAKE_C_COMPILER=clang \ -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_BUILD_TYPE=Release \ diff --git a/python/hecate/hecate/expr.py b/python/hecate/hecate/expr.py index c7aba2a..d6f6900 100644 --- a/python/hecate/hecate/expr.py +++ b/python/hecate/hecate/expr.py @@ -4,6 +4,7 @@ import inspect from subprocess import Popen from collections.abc import Iterable +from platform import system # import torch import os @@ -15,7 +16,15 @@ hecateBuild = hecate_dir+"/build" heaan_keyset = "/heaan_keyset" libpath = hecateBuild + "/lib/" -lt = ctypes.CDLL(libpath+"libHecateFrontend.so") +libname = libpath +osname = system() +if osname == 'Linux': + libname = libpath + "libHecateFrontend.so" +elif osname == 'Darwin': + libname = libpath + "libHecateFrontend.dylib" +else: + raise UnsupportedPlatform +lt = ctypes.CDLL(libname) os.environ['PATH'] = libpath + os.pathsep + os.environ['PATH'] diff --git a/python/hecate/hecate/runner.py b/python/hecate/hecate/runner.py index 1bc9e92..de8ad50 100644 --- a/python/hecate/hecate/runner.py +++ b/python/hecate/hecate/runner.py @@ -6,6 +6,7 @@ import inspect from subprocess import Popen from collections.abc import Iterable +from platform import system # import torch import os @@ -24,7 +25,15 @@ hecateBuild = hecate_dir libpath = hecateBuild / "lib" -lw = ctypes.CDLL(libpath / "libSEAL_HEVM.so") +libname = libpath +osname = system() +if osname == 'Linux': + libname = libpath / "libSEAL_HEVM.so" +elif osname == 'Darwin': + libname = libpath / "libSEAL_HEVM.dylib" +else: + raise UnsupportedPlatform +lw = ctypes.CDLL(libname) os.environ['PATH'] = str(libpath) + os.pathsep + os.environ['PATH'] @@ -106,6 +115,7 @@ def setInput(self, i, data) : if not isinstance(data, np.ndarray) : data = np.array(data, dtype=np.float64) carr = data.ctypes.data_as(ctypes.POINTER(ctypes.c_double)) + print(data) lw.encrypt(self.vm, i, carr, len(data)) def setDebug (self, enable) : diff --git a/requirements.txt b/requirements.txt index b21a404..a205fb8 100644 --- a/requirements.txt +++ b/requirements.txt @@ -9,22 +9,22 @@ MarkupSafe==2.1.3 mpmath==1.3.0 networkx==3.1 numpy==1.25.2 -nvidia-cublas-cu11==11.10.3.66 -nvidia-cuda-cupti-cu11==11.7.101 -nvidia-cuda-nvrtc-cu11==11.7.99 -nvidia-cuda-runtime-cu11==11.7.99 -nvidia-cudnn-cu11==8.5.0.96 -nvidia-cufft-cu11==10.9.0.58 -nvidia-curand-cu11==10.2.10.91 -nvidia-cusolver-cu11==11.4.0.1 -nvidia-cusparse-cu11==11.7.4.91 -nvidia-nccl-cu11==2.14.3 -nvidia-nvtx-cu11==11.7.91 +nvidia-cublas-cu11==11.10.3.66 ; platform_system=="Linux" +nvidia-cuda-cupti-cu11==11.7.101 ; platform_system=="Linux" +nvidia-cuda-nvrtc-cu11==11.7.99 ; platform_system=="Linux" +nvidia-cuda-runtime-cu11==11.7.99 ; platform_system=="Linux" +nvidia-cudnn-cu11==8.5.0.96 ; platform_system=="Linux" +nvidia-cufft-cu11==10.9.0.58 ; platform_system=="Linux" +nvidia-curand-cu11==10.2.10.91 ; platform_system=="Linux" +nvidia-cusolver-cu11==11.4.0.1 ; platform_system=="Linux" +nvidia-cusparse-cu11==11.7.4.91 ; platform_system=="Linux" +nvidia-nccl-cu11==2.14.3 ; platform_system=="Linux" +nvidia-nvtx-cu11==11.7.91 ; platform_system=="Linux" Pillow==10.0.0 requests==2.31.0 sympy==1.12 torch==2.0.1 torchvision==0.15.2 -triton==2.0.0 +triton==2.0.0 ; platform_system=="Linux" typing_extensions==4.7.1 urllib3==2.0.4