Skip to content
Open
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
8 changes: 8 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[flake8]
select = E901,E999,F821,F822,F823
max-line-length = 100
exclude = .git,.eggs,__pycache__,build,dist,venv,third_party,_deps
max-complexity = 11
show-source = true
statistics = true
count = true
3 changes: 3 additions & 0 deletions .github/workflows/scripts/build_nix.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh

pip install .
9 changes: 9 additions & 0 deletions .github/workflows/scripts/install_req_macos.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/sh

set -e

python -m pip install --upgrade pip
pip install -r requirements_dev.txt
brew install protobuf

pip install setuptools wheel twine auditwheel
11 changes: 11 additions & 0 deletions .github/workflows/scripts/install_req_ubuntu.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/sh

set -e

sudo apt update -y
sudo apt install libboost-all-dev libprotobuf-dev protobuf-compiler curl git build-essential cmake automake libtool libtool-bin -y

python -m pip install --upgrade pip
pip install -r requirements_dev.txt

pip install setuptools wheel twine auditwheel
14 changes: 14 additions & 0 deletions .github/workflows/scripts/lint_cpp.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/sh
set -e

# Lint files (all .cpp and .h files) inplace.
find ./eva/ \( -iname *.h -o -iname *.cpp \) | xargs clang-format -i -style='file'
if [ $? -ne 0 ]
then
exit 1
fi

# Print changes.
git diff
# Already well formated if 'git diff' doesn't output anything.
! ( git diff | grep -q ^ ) || exit 1
8 changes: 8 additions & 0 deletions .github/workflows/scripts/lint_python.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/sh
set -e

# stop the build if there are Python syntax errors or undefined names
flake8 --config=.flake8 python/
black --check python/ tests/
# exit-zero treats all errors as warnings.
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=100 --statistics
61 changes: 61 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: Tests

on:
push:
branches: [main]
pull_request:
types: [opened, synchronize, reopened]

jobs:
Linter:
runs-on: ${{ matrix.os }}
strategy:
matrix:
python-version: [3.8]
os: [ubuntu-latest]
steps:
- uses: actions/checkout@v2
with:
submodules: true
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v1
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: .github/workflows/scripts/install_req_ubuntu.sh
if: ${{ matrix.os == 'ubuntu-latest' }}
- name: Lint with flake8
run: .github/workflows/scripts/lint_python.sh
- name: Lint with clang-format
run: .github/workflows/scripts/lint_cpp.sh

Tests:
needs: [Linter]
runs-on: ${{ matrix.os }}
strategy:
matrix:
python-version: [3.6, 3.7, 3.8, 3.9]
os: [ubuntu-latest, macos-latest]
steps:
- uses: actions/checkout@v2
with:
submodules: true
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v1
with:
python-version: ${{ matrix.python-version }}
- name: Prepare ENV
run: |
echo "CC=clang" >> $GITHUB_ENV
echo "CXX=clang++" >> $GITHUB_ENV
if: ${{ matrix.os == 'ubuntu-latest' }}
- name: Install dependencies Ubuntu
run: .github/workflows/scripts/install_req_ubuntu.sh
if: ${{ matrix.os == 'ubuntu-latest' }}
- name: Install dependencies MacOS
run: .github/workflows/scripts/install_req_macos.sh
if: ${{ matrix.os == 'macos-latest' }}
- name: Build the library for Ubuntu/MacOS
run: .github/workflows/scripts/build_nix.sh
- name: Test
run: python tests/all.py
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/.*/
/build/
/dist/
eva.egg-info/
Expand All @@ -16,4 +15,5 @@ CMakeFiles/
*.pb.h
*.a
*.so
*.whl
*.whl
_deps
8 changes: 0 additions & 8 deletions .gitmodules

This file was deleted.

16 changes: 5 additions & 11 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,13 @@ if(USE_GALOIS)
add_definitions(-DEVA_USE_GALOIS)
endif()

find_package(SEAL 3.6 REQUIRED)
find_package(Protobuf 3.6 REQUIRED)
find_package(Python COMPONENTS Interpreter Development)

if(NOT Python_VERSION_MAJOR EQUAL 3)
message(FATAL_ERROR "EVA requires Python 3. Please ensure you have it
installed in a location searched by CMake.")
endif()

add_subdirectory(third_party/pybind11)
include(cmake/seal.cmake)
include(cmake/pybind11.cmake)
if(USE_GALOIS)
add_subdirectory(third_party/Galois EXCLUDE_FROM_ALL)
include(cmake/galois.cmake)
endif()

add_subdirectory(eva)
add_subdirectory(python)
include(cmake/eva.cmake)
include(cmake/python.cmake)
34 changes: 7 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ EVA is a native library written in C++17 with bindings for Python. Both Linux an

To install dependencies on Ubuntu 20.04:
```
sudo apt install cmake libboost-all-dev libprotobuf-dev protobuf-compiler
sudo apt install cmake libboost-all-dev libprotobuf-dev protobuf-compiler libfmt-dev
```

Clang is recommended for compilation, as SEAL is faster when compiled with it. To install clang and set it as default:
Expand All @@ -25,36 +25,16 @@ sudo update-alternatives --install /usr/bin/cc cc /usr/bin/clang 100
sudo update-alternatives --install /usr/bin/c++ c++ /usr/bin/clang++ 100
```

Next install Microsoft SEAL version 3.6:
```
git clone -b v3.6.4 https://github.com/microsoft/SEAL.git
cd SEAL
cmake -DSEAL_THROW_ON_TRANSPARENT_CIPHERTEXT=OFF .
make -j
sudo make install
```
*Note that SEAL has to be installed with transparent ciphertext checking turned off, as it is not possible in general to statically ensure a program will not produce a transparent ciphertext. This does not affect the security of ciphertexts encrypted with SEAL.*

### Building and Installing EVA

#### Building EVA

EVA builds with CMake version ≥ 3.13:
```
git submodule update --init
cmake .
make -j
```
The build process creates a `setup.py` file in `python/`. To install the package for development with PIP:
```
python3 -m pip install -e python/
```
To create a Python Wheel package for distribution in `dist/`:
To install the package with PIP:
```
python3 python/setup.py bdist_wheel --dist-dir='.'
python3 -m pip install .
```

To check that the installed Python package is working correctly, run all tests with:
To check that EVA is working correctly, run all tests with:
```
python3 tests/all.py
```
Expand All @@ -63,9 +43,9 @@ EVA does not yet support installing the native library for use in other CMake pr

#### Multicore Support

EVA features highly scalable multicore support using the [Galois library](https://github.com/IntelligentSoftwareSystems/Galois). It is included as a submodule, but is turned off by default for faster builds and easier debugging. To build EVA with Galois configure with `USE_GALOIS=ON`:
EVA features highly scalable multicore support using the [Galois library](https://github.com/IntelligentSoftwareSystems/Galois), which is turned off by default for faster builds and easier debugging. To install EVA with multicore support use `setup.py` directly:
```
cmake -DUSE_GALOIS=ON .
python3 setup.py install --use-galois
```

### Running the Examples
Expand Down Expand Up @@ -174,4 +154,4 @@ Many thanks to [Sangeeta Chowdhary](https://www.ilab.cs.rutgers.edu/~sc1696/), w

Roshan Dathathri, Blagovesta Kostova, Olli Saarikivi, Wei Dai, Kim Laine, Madanlal Musuvathi. *EVA: An Encrypted Vector Arithmetic Language and Compiler for Efficient Homomorphic Computation*. PLDI 2020. [arXiv](https://arxiv.org/abs/1912.11951) [DOI](https://doi.org/10.1145/3385412.3386023)

Roshan Dathathri, Olli Saarikivi, Hao Chen, Kim Laine, Kristin Lauter, Saeed Maleki, Madanlal Musuvathi, Todd Mytkowicz. *CHET: An Optimizing Compiler for Fully-Homomorphic Neural-Network Inferencing*. PLDI 2019. [DOI](https://doi.org/10.1145/3314221.3314628)
Roshan Dathathri, Olli Saarikivi, Hao Chen, Kim Laine, Kristin Lauter, Saeed Maleki, Madanlal Musuvathi, Todd Mytkowicz. *CHET: An Optimizing Compiler for Fully-Homomorphic Neural-Network Inferencing*. PLDI 2019. [DOI](https://doi.org/10.1145/3314221.3314628)
33 changes: 23 additions & 10 deletions eva/CMakeLists.txt → cmake/eva.cmake
Original file line number Diff line number Diff line change
@@ -1,11 +1,31 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT license.

set(EVA_SOURCES
eva/seal/seal.cpp
eva/util/logging.cpp
eva/common/reference_executor.cpp
eva/ckks/ckks_config.cpp

add_library(eva STATIC
eva.cpp
version.cpp
eva/ir/term.cpp
eva/ir/program.cpp
eva/ir/attribute_list.cpp
eva/ir/attributes.cpp

eva/eva.cpp
eva/version.cpp
)

if(USE_GALOIS)
set(EVA_SOURCES ${EVA_SOURCES}
eva/util/galois.cpp
)
endif()

add_library(eva STATIC ${EVA_SOURCES})

add_subdirectory(${PROJECT_SOURCE_DIR}/eva/serialization/)

# TODO: everything except SEAL::seal should be make PRIVATE
target_link_libraries(eva PUBLIC SEAL::seal protobuf::libprotobuf)
if(USE_GALOIS)
Expand All @@ -18,10 +38,3 @@ target_include_directories(eva
$<INSTALL_INTERFACE:include>
)
target_compile_definitions(eva PRIVATE EVA_VERSION_STR="${PROJECT_VERSION}")

add_subdirectory(util)
add_subdirectory(serialization)
add_subdirectory(ir)
add_subdirectory(common)
add_subdirectory(ckks)
add_subdirectory(seal)
16 changes: 16 additions & 0 deletions cmake/galois.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
include(FetchContent)

FetchContent_Declare(
com_intelligentsoftwaresystems_galois
GIT_REPOSITORY https://github.com/IntelligentSoftwareSystems/Galois
GIT_TAG release-6.0
)
FetchContent_MakeAvailable(com_intelligentsoftwaresystems_galois)

if(IS_DIRECTORY "${com_intelligentsoftwaresystems_galois_SOURCE_DIR}")
set_property(DIRECTORY ${com_intelligentsoftwaresystems_galois_SOURCE_DIR} PROPERTY EXCLUDE_FROM_ALL YES)
endif()

include_directories(
${com_intelligentsoftwaresystems_galois_SOURCE_DIR}/include
)
12 changes: 12 additions & 0 deletions cmake/pybind11.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
include(FetchContent)

FetchContent_Declare(
com_pybind_pybind11
GIT_REPOSITORY https://github.com/pybind/pybind11
GIT_TAG v2.6.2
)
FetchContent_MakeAvailable(com_pybind_pybind11)

include_directories(
${com_pybind_pybind11_SOURCE_DIR}/include
)
13 changes: 13 additions & 0 deletions cmake/python.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT license.

pybind11_add_module(eva_py
python/eva/wrapper.cpp
)

target_compile_features(eva_py PUBLIC cxx_std_17)
target_link_libraries(eva_py PRIVATE eva)
if (MSVC)
target_link_libraries(eva_py PUBLIC bcrypt)
endif()
set_target_properties(eva_py PROPERTIES OUTPUT_NAME _eva)
17 changes: 17 additions & 0 deletions cmake/seal.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
include(FetchContent)

set(SEAL_BUILD_DEPS ON)
set(SEAL_USE_MSGSL ON)
option(SEAL_THROW_ON_TRANSPARENT_CIPHERTEXT OFF)

FetchContent_Declare(
com_microsoft_seal
GIT_REPOSITORY https://github.com/microsoft/SEAL
GIT_TAG v3.6.4
)
FetchContent_MakeAvailable(com_microsoft_seal)

include_directories(${com_microsoft_seal_SOURCE_DIR}/native/src)
include_directories(${com_microsoft_seal_SOURCE_DIR}/thirdparty/msgsl-src/include/)
include_directories(${com_microsoft_seal_SOURCE_DIR}/thirdparty/hexl-src/hexl/include/)
include_directories(${com_microsoft_seal_BINARY_DIR}/native/src)
6 changes: 0 additions & 6 deletions eva/ckks/CMakeLists.txt

This file was deleted.

2 changes: 1 addition & 1 deletion eva/ckks/mod_switcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class ModSwitcher {
Term::Ptr &term) { // must only be used with backward pass traversal
if (term->numUses() == 0) return;

//we do not want to add modswitch for nodes of type raw
// we do not want to add modswitch for nodes of type raw
if (type[term] == Type::Raw) return;

if (term->op == Op::Encode) {
Expand Down
6 changes: 0 additions & 6 deletions eva/common/CMakeLists.txt

This file was deleted.

9 changes: 0 additions & 9 deletions eva/ir/CMakeLists.txt

This file was deleted.

12 changes: 0 additions & 12 deletions eva/util/CMakeLists.txt

This file was deleted.

Loading