Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrated OpenMP-enabled HEXL #145

Open
wants to merge 1 commit into
base: development
Choose a base branch
from
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
18 changes: 17 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,24 @@ set(CMAKE_INSTALL_RPATH "\$ORIGIN")
#------------------------------------------------------------------------------
# Compiler options...
#------------------------------------------------------------------------------
#twy
option(MY_OPENMP "Enable multithreading" ON)

option(HEXL_BENCHMARK "Enable benchmarking" ON)
option(HEXL_COVERAGE "Enables coverage for unit tests" OFF)
option(HEXL_DOCS "Enable documentation building" OFF)
option(HEXL_EXPERIMENTAL "Enable experimental features" OFF)
option(HEXL_SHARED_LIB "Generate a shared library" OFF)
option(HEXL_SHARED_LIB "Generate a shared library" ON)
option(HEXL_TESTING "Enables unit-tests" ON)
option(HEXL_TREAT_WARNING_AS_ERROR "Treat all compile-time warnings as errors" OFF)

if (NOT HEXL_FPGA_COMPATIBILITY)
set(HEXL_FPGA_COMPATIBILITY "0" CACHE INTERNAL "Set FPGA compatibility mask" FORCE)
endif()

#twy
message(STATUS "OpenMP_OPTION: ${MY_OPENMP}")

message(STATUS "CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}")
message(STATUS "CMAKE_C_COMPILER: ${CMAKE_C_COMPILER}")
message(STATUS "CMAKE_CXX_COMPILER: ${CMAKE_CXX_COMPILER}")
Expand All @@ -82,6 +87,11 @@ message(STATUS "HEXL_FPGA_COMPATIBILITY: ${HEXL_FPGA_COMPATIBILITY}")
hexl_check_compiler_version()
hexl_add_compiler_definition()

#twy
if (OpenMP_OPTION)
add_compile_options(-fopenmp)
endif()

if (HEXL_COVERAGE)
if (NOT HEXL_USE_GNU)
message(FATAL_ERROR "HEXL_COVERAGE only supported on GCC.")
Expand Down Expand Up @@ -183,6 +193,12 @@ if (HEXL_DEBUG)
endif()
endif()

find_package(OpenMP)
if (OpenMP_FOUND)
message(STATUS "OpenMP_CXX_INCLUDE_DIRS: ${OpenMP_CXX_INCLUDE_DIRS}")
message(STATUS "OpenMP_CXX_LIBRARIES: ${OpenMP_CXX_LIBRARIES}")
endif()

#------------------------------------------------------------------------------
# Subfolders...
#------------------------------------------------------------------------------
Expand Down
169 changes: 142 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[![Build and Test](https://github.com/intel/hexl/actions/workflows/github-ci.yml/badge.svg?branch=main)](https://github.com/intel/hexl/actions/workflows/github-ci.yml)

# Intel Homomorphic Encryption (HE) Acceleration Library
# OpenMP-enabled Intel Homomorphic Encryption (HE) Acceleration Library
Intel:registered: HE Acceleration Library is an open-source library which
provides efficient implementations of integer arithmetic on Galois fields. Such
arithmetic is prevalent in cryptography, particularly in homomorphic encryption
Expand All @@ -11,6 +11,8 @@ Intel HE Acceleration Library, see our
[whitepaper](https://arxiv.org/abs/2103.16400.pdf). For tips on best
performance, see [Performance](#performance).

The project extends HEXL's capabilities by incorporating OpenMP for multi-threaded parallelization, in order to reduce computational latency without compromising security.

## Contents
- [Intel Homomorphic Encryption (HE) Acceleration Library](#intel-homomorphic-encryption-he-acceleration-library)
- [Contents](#contents)
Expand All @@ -20,7 +22,7 @@ performance, see [Performance](#performance).
- [Compile-time options](#compile-time-options)
- [Compiling Intel HE Acceleration Library](#compiling-intel-he-acceleration-library)
- [Linux and Mac](#linux-and-mac)
- [Windows](#windows)
- [Build the OpenMP-enabled Version](#build-the-openmp-enabled-version)
- [Performance](#performance)
- [Testing Intel HE Acceleration Library](#testing-intel-he-acceleration-library)
- [Benchmarking Intel HE Acceleration Library](#benchmarking-intel-he-acceleration-library)
Expand Down Expand Up @@ -98,20 +100,15 @@ from source using CMake.
### Dependencies
We have tested Intel HE Acceleration Library on the following operating systems:
- Ubuntu 20.04
- macOS 10.15 Catalina
- Microsoft Windows 10
- macOS 13.4.1 (22F82) Vertura

Intel HE Acceleration Library requires the following dependencies:

| Dependency | Version |
|-------------|----------------------------------------------|
| CMake | >= 3.13 \* |
| Compiler | gcc >= 7.0, clang++ >= 5.0, MSVC >= 2019 |
| Compiler | gcc >= 7.0, clang++ >= 5.0 |

\* For Windows 10, you must check whether the version on CMake you have can
generate the necessary Visual Studio project files. For example, only from
[CMake 3.14 onwards can MSVC 2019 project files be
generated](https://cmake.org/cmake/help/git-stage/generator/Visual%20Studio%2016%202019.html).


### Compile-time options
Expand Down Expand Up @@ -162,33 +159,151 @@ To install Intel HE Acceleration Library to the installation directory, run
```bash
cmake --install build
```
## Build the OpenMP-enabled Version
1. First start from a clean project in the ‘hexl’ folder
```bash
rm -rf CMakeCache.txt CMakeFiles/
```
2. Go to the build folder
```bash
cd build
```
3. Repeat the first command to clean the cmake cache in the build folder
```bash
rm -rf CMakeCache.txt CMakeFiles/
```

#### Windows
To compile Intel HE Acceleration Library on Windows using Visual Studio in
Release mode, configure the build via
4. Now configure the build
```bash
cmake -S . -B build -G "Visual Studio 16 2019" -DCMAKE_BUILD_TYPE=Release
cmake -S . -B build -DCMAKE_INSTALL_PREFIX=/path/to/install/hexl_v2 -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++
```
or
```bash
cmake -S . -B build -DCMAKE_INSTALL_PREFIX=/path/to/installhexl_v1 -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++
```
or
```bash
cmake -S . -B build -DCMAKE_INSTALL_PREFIX=/path/to/install/hexl_v3 -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++
```
adding the desired compile-time options with a `-D` flag (see [Compile-time
options](#compile-time-options)). For instance, to use a non-standard
installation directory, configure the build with
Notice that, hexl_v0 is the original serial version; hexl_v1 stands for the serial but removed or unroll techniques version; hexl_v2 stands for the OpenMP-enabled multi-threading version; hexl_v3 stands for the OpenMP-enabled multi-threading and allow OpenMP region timing test version.
```bash
cmake -S . -B build -G "Visual Studio 16 2019" -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/path/to/install
cmake --build build
cmake --install build
```

To specify the desired build configuration, pass either `--config Debug` or
`--config Release` to the build step and install steps. For instance, to build
Intel HE Acceleration Library in Release mode, call
## Test the parallel performance of OpenMP-enabled Version
1. Go into the OpenMP enabled example test directory
```bash
cmake --build build --config Release
cd omp_example
```
2. Define the directory containing HEXLConfig.cmake (save but don’t close)
```bash
vim camke/CMakeLists.txt
```
```bash
set(HEXL_HINT_DIR "path/to/install/hexl_v2/lib/cmake/hexl-1.2.5")
```
This will build the Intel HE Acceleration Library library in the
`build/hexl/lib/` or `build/hexl/Release/lib` directory.

To install Intel HE Acceleration Library to the installation directory, run
3. Help to find OpenMP in the CMakeLists.txt
```bash
find_package(OpenMP)
if (OpenMP_FOUND)
message(STATUS "OpenMP_CXX_INCLUDE_DIRS: ${OpenMP_CXX_INCLUDE_DIRS}")
message(STATUS "OpenMP_CXX_LIBRARIES: ${OpenMP_CXX_LIBRARIES}")
endif()
```

N.B. Don’t forget to edit the execution file name!

4. Build the example
```bash
cmake -S cmake -B build
cmake --build build -j
```

5. Set the desired thread number and execute

```bash
./build/omp_example 1000 4 1234
time ./build/omp_example 1000 1,2,4,8,16 16384
```
or directly run the script
```bash
cd ..
./hexl_omp.sh
```

## Test the serial performance of OpenMP-enabled Version
1. Go into the serial example test directory
```bash
cd ser_example
```
2. Define the directory containing HEXLConfig.cmake (save but don’t close)
```bash
vim camke/CMakeLists.txt
```
```bash
set(HEXL_HINT_DIR "path/to/install/hexl_v1/lib/cmake/hexl-1.2.5")
```
N.B. Don’t forget to edit the execution file name!

3. Build the example
```bash
cmake -S cmake -B build
cmake --build build -j
```

4. Set the desired thread number and execute

```bash
./build/example 1000 4096,65536
time ./build/example 1000 4096,65536
```
or directly run the script
```bash
cd ..
./hexl_serial.sh
```

## Test the parallel performance of OpenMP-enabled Version
1. Go into the OpenMP enabled example test directory
```bash
cd time_example
```
2. Define the directory containing HEXLConfig.cmake (save but don’t close)
```bash
vim camke/CMakeLists.txt
```
```bash
set(HEXL_HINT_DIR "path/to/install/hexl_v3/lib/cmake/hexl-1.2.5")
```

3. Help to find OpenMP in the CMakeLists.txt
```bash
find_package(OpenMP)
if (OpenMP_FOUND)
message(STATUS "OpenMP_CXX_INCLUDE_DIRS: ${OpenMP_CXX_INCLUDE_DIRS}")
message(STATUS "OpenMP_CXX_LIBRARIES: ${OpenMP_CXX_LIBRARIES}")
endif()
```

4. Build the example
```bash
cmake -S cmake -B build
cmake --build build -j
```

5. Set the desired thread number and execute

```bash
cmake --build build --target install --config Release
./build/time_example 100 4 1024 0
time ./build/omp_example 100 4 1024 0
```
or directly run the script
```bash
cd ..
./hexl_time.sh
```

## Performance
For best performance, we recommend using Intel HE Acceleration Library on a
Expand Down Expand Up @@ -352,7 +467,7 @@ To cite Intel HE Acceleration Library, please use the following BibTeX entry.
```

# Contributors
The Intel contributors to this project, sorted by last name, are
The Intel contributors to the original HEXL project, sorted by last name, are
- [Paky Abu-Alam](https://www.linkedin.com/in/paky-abu-alam-89797710/)
- [Flavio Bergamaschi](https://www.linkedin.com/in/flavio-bergamaschi-1634141/)
- [Fabian Boemer](https://www.linkedin.com/in/fabian-boemer-5a40a9102/)
Expand All @@ -370,5 +485,5 @@ The Intel contributors to this project, sorted by last name, are
- [Gelila Seifu](https://www.linkedin.com/in/gelila-seifu/)

In addition to the Intel contributors listed, we are also grateful to
contributions to this project that are not reflected in the Git history:
contributions to the original HEXL project that are not reflected in the Git history:
- [Antonis Papadimitriou](https://www.linkedin.com/in/apapadimitriou/)
6 changes: 5 additions & 1 deletion benchmark/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@
// SPDX-License-Identifier: Apache-2.0

#include <benchmark/benchmark.h>

#include <omp.h>
#include <iostream>
#include "hexl/logging/logging.hpp"

int main(int argc, char** argv) {
int max_threads = omp_get_max_threads();
std::cout << "Maximum number of threads = " << max_threads << std::endl;

START_EASYLOGGINGPP(argc, argv);

benchmark::Initialize(&argc, argv);
Expand Down
34 changes: 34 additions & 0 deletions example/Serial_result
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
Method Input_size=65536Input_size=1048576Input_size=16777216Input_size=268435456
BM_EltwiseCmpAdd 0.017372 0.360454 10.3044 101.545
BM_EltwiseCmpSubMod 0.293158 5.49905 37.7997 569.832
BM_EltwiseFMAModAdd 0.403343 3.77922 48.3154 736.565
BM_EltwiseMultMod 0.225371 2.10433 49.6537 917.409
BM_EltwiseReduceModInPlace 0.324567 2.90482 45.3023 708.633
BM_EltwiseVectorScalarAddMod 0.035236 0.67465 16.7397 157.531
BM_EltwiseVectorVectorAddMod 0.054301 0.941839 20.3437 221.558
BM_EltwiseVectorVectorSubMod 0.05375 0.946959 21.3859 216.095
BM_NTTInPlace 0 0 0 0

s1820742psd@eidf018-s1820742msc:~/hexl/example$ ./build/example 1 4096,65536,1048576,16777216,268435456
Method Threads=4096 Threads=65536 Threads=1048576Threads=16777216Threads=268435456
BM_EltwiseCmpAdd 0.002144 0.01595 0.406509 10.3117 113.003
BM_EltwiseCmpSubMod 0.039855 0.318033 3.72818 36.4171 644.48
BM_EltwiseFMAModAdd 0.01605 0.248584 3.99384 57.2828 724.992
BM_EltwiseMultMod 0.015299 0.168785 3.30193 48.9081 728.924
BM_EltwiseReduceModInPlace 0.016561 0.234798 3.21797 38.945 659.401
BM_EltwiseVectorScalarAddMod 0.001934 0.026049 0.538125 15.2527 175.121
BM_EltwiseVectorVectorAddMod 0.003437 0.039815 0.918195 19.7483 212.407
BM_EltwiseVectorVectorSubMod 0.001643 0.039985 0.743188 20.7958 196.669
BM_NTTInPlace 0 0 0 0 0

s1820742psd@eidf018-s1820742msc:~/hexl/example$ ./build/example 10 4096,65536,1048576,16777216,268435456
Method Threads=4096 Threads=65536 Threads=1048576 Threads=16777216 Threads=268435456
BM_EltwiseCmpAdd 0.0013718 0.0193352 0.208849 10.9892 108.882
BM_EltwiseCmpSubMod 0.0277949 0.370251 3.56102 56.7082 885.602
BM_EltwiseFMAModAdd 0.0240648 0.351835 2.94638 54.911 1103.29
BM_EltwiseMultMod 0.0194895 0.241749 2.1714 61.7039 793.763
BM_EltwiseReduceModInPlace 0.0193062 0.287436 2.48417 44.0457 660.978
BM_EltwiseVectorScalarAddMod 0.001593 0.0340157 0.425441 16.1058 172.764
BM_EltwiseVectorVectorAddMod 0.0021721 0.050867 0.720809 20.2879 224.474
BM_EltwiseVectorVectorSubMod 0.002193 0.0495797 0.733838 20.3605 215.544
BM_NTTInPlace 0.0003798 0.0007619 0.0090708 0.171779 3.80078
3 changes: 3 additions & 0 deletions example/cmake/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ project(hexl_example LANGUAGES C CXX)
cmake_minimum_required(VERSION 3.13)
set(CMAKE_CXX_STANDARD 17)

# Define the directory containing HEXLConfig.cmake
set(HEXL_HINT_DIR "/home/eidf018/eidf018/s1820742psd/hexl/hexl_v1")

# Example using source
find_package(HEXL 1.2.5
HINTS ${HEXL_HINT_DIR}
Expand Down
Loading