Skip to content

Commit e64817d

Browse files
authored
Experimental HEXL Acceleration Integration
Experimental HEXL Acceleration Integration Update build to use NTL 11.5.1 and GMP 6.2.1 Co-authored-by: @hamishun Co-authored-by: @jlhcrawford Co-authored-by: @faberga Co-authored-by: @fboemer
2 parents 9973ccc + 0f21f50 commit e64817d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+2007
-562
lines changed

CHANGES.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,19 @@
11
Release Changes
22
===============
33

4+
HElib 2.2.0, September 2021
5+
=========================
6+
(tagged as v2.2.0)
7+
8+
* Intel HEXL integration (experimental)
9+
* HEXL NTT acceleration for m as a power of 2
10+
* HEXL acceleration to fundamental ciphertext operations
11+
* Documentation update
12+
* Update NTL dependency to version 11.5.1
13+
* Update GMP dependency to version 6.2.1
14+
* Update to benchmarks
15+
* Bug fixes
16+
417
HElib 2.1.0, March 2021
518
=========================
619
(tagged as v2.1.0)

CMakeLists.txt

Lines changed: 59 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,12 @@
1010
# See the License for the specific language governing permissions and
1111
# limitations under the License. See accompanying LICENSE file.
1212

13-
cmake_minimum_required(VERSION 3.10.2 FATAL_ERROR)
13+
# Enforce CMake v3.20 on MacOS else set minimum to v3.16
14+
if (APPLE)
15+
cmake_minimum_required(VERSION 3.20 FATAL_ERROR)
16+
else ()
17+
cmake_minimum_required(VERSION 3.16 FATAL_ERROR)
18+
endif ()
1419

1520
project(helib_superbuild LANGUAGES C CXX)
1621

@@ -67,9 +72,9 @@ set(HELIB_DEPENDENCIES_DIR "${PROJECT_SOURCE_DIR}/dependencies")
6772
set(HELIB_TEST_BIN_DIR "${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_BINDIR}")
6873

6974
# GMP minimal version to be used if not PACKAGE_BUILD
70-
set(GMP_MINIMAL_VERSION "6.0.0")
75+
set(GMP_MINIMAL_VERSION "6.2.0")
7176
# NTL minimal version to be used if NOT PACKAGE_BUILD
72-
set(NTL_MINIMAL_VERSION "11.0.0")
77+
set(NTL_MINIMAL_VERSION "11.4.3")
7378

7479
# The -isysroot flag needs set.
7580
if ((APPLE OR (CMAKE_CXX_PLATFORM_ID STREQUAL "Darwin")) AND
@@ -108,6 +113,17 @@ if (NOT TARGET_ARCHITECTURE)
108113
FORCE)
109114
endif (NOT TARGET_ARCHITECTURE)
110115

116+
set(HELIB_SP_NBITS "0"
117+
CACHE
118+
STRING "Override the bitsize for the ciphertext primes used")
119+
if (NOT HELIB_SP_NBITS EQUAL 0)
120+
# Now check within bounds. NB. zero is special value to not override
121+
if (HELIB_SP_NBITS LESS 1 OR HELIB_SP_NBITS GREATER 64)
122+
message(FATAL_ERROR "HELIB_SP_NBITS must be in range [1, 64].")
123+
endif()
124+
add_compile_definitions(HELIB_SP_NBITS=${HELIB_SP_NBITS})
125+
endif()
126+
111127
# Path containing FindGMP.cmake and FindNTL.cmake
112128
list(APPEND CMAKE_MODULE_PATH "${HELIB_CMAKE_EXTRA_DIR}")
113129

@@ -125,6 +141,7 @@ option(HELIB_DEBUG
125141
"Build with HELIB_DEBUG (enables extra debugging info, but needs to be initialized)"
126142
OFF)
127143
option(ENABLE_TEST "Enable tests" OFF)
144+
option(USE_INTEL_HEXL "Use Intel HEXL library" OFF)
128145
option(PEDANTIC_BUILD "Use -Wall -Wpedantic -Wextra -Werror during build" ON)
129146

130147
# Add properties dependent to PACKAGE_BUILD
@@ -176,6 +193,43 @@ if (ENABLE_THREADS AND Threads_NOTFOUND)
176193
message(FATAL_ERROR "Cannot find pthreads (ENABLE_THREADS is ON).")
177194
endif ()
178195

196+
# Build optional Intel HEXL library
197+
if(USE_INTEL_HEXL)
198+
# HEXL currently only supported using Library Build
199+
if(PACKAGE_BUILD)
200+
message(FATAL_ERROR "Intel HEXL currently not supported with Package "
201+
"Build. Please use the Library Build when enabling Intel HEXL.")
202+
endif(PACKAGE_BUILD)
203+
204+
if(HEXL_DIR)
205+
set(HEXL_DIR
206+
""
207+
CACHE
208+
STRING "Set location of HEXL cmake data for linking."
209+
)
210+
set(INIT_HEXL_DIR ${HEXL_DIR})
211+
endif()
212+
213+
# Set minimum version of HEXL
214+
set(HEXL_MIN_VERSION 1.2.1)
215+
216+
find_package(HEXL HINTS ${HEXL_DIR} REQUIRED)
217+
218+
# Check the version found is greater than the minimum
219+
if(HEXL_MIN_VERSION GREATER HEXL_VERSION)
220+
message(FATAL_ERROR "Minimum Intel HEXL version required is ${HEXL_MIN_VERSION}, found ${HEXL_VERSION}")
221+
else()
222+
message("-- Intel HEXL Version: ${HEXL_VERSION} found (minimum required is ${HEXL_MIN_VERSION})")
223+
endif()
224+
225+
if(INIT_HEXL_DIR AND NOT INIT_HEXL_DIR STREQUAL HEXL_DIR)
226+
message(WARNING "HEXL location provided '${INIT_HEXL_DIR}' \
227+
does not equal chosen '${HEXL_DIR}'.")
228+
endif()
229+
include_directories(${HEXL_INCLUDE_DIRS})
230+
add_compile_definitions(USE_INTEL_HEXL)
231+
endif(USE_INTEL_HEXL)
232+
179233
# NOTE: Consider reconfiguring everything when PACKAGE_BUILD changes value.
180234
# Options from the previous value will remain otherwise.
181235
# Set up extra properties depending on the value of PACKAGE_BUILD
@@ -184,7 +238,7 @@ if (PACKAGE_BUILD)
184238
# GMP version to be used (and eventually downloaded) if PACKAGE_BUILD
185239
set(FETCHED_GMP_VERSION "6.2.1")
186240
# NTL version to be used (and eventually downloaded) if PACKAGE_BUILD
187-
set(FETCHED_NTL_VERSION "11.4.3")
241+
set(FETCHED_NTL_VERSION "11.5.1")
188242
# Setting up default compilation output directory
189243
if (NOT PACKAGE_DIR)
190244
set(PACKAGE_DIR "helib_pack")
@@ -334,6 +388,7 @@ if (PACKAGE_BUILD)
334388
-DFETCH_GMP=${FETCH_GMP}
335389
-DENABLE_TEST=${ENABLE_TEST}
336390
-DHELIB_DEBUG=${HELIB_DEBUG}
391+
-DUSE_INTEL_HEXL=${USE_INTEL_HEXL}
337392
-DHELIB_PROJECT_ROOT_DIR=${HELIB_PROJECT_ROOT_DIR}
338393
-DHELIB_CMAKE_EXTRA_DIR=${HELIB_CMAKE_EXTRA_DIR}
339394
-DHELIB_INCLUDE_DIR=${HELIB_INCLUDE_DIR}

Dockerfile

Lines changed: 0 additions & 21 deletions
This file was deleted.

INSTALL.md

Lines changed: 65 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,45 @@
11
# Building and installing HElib
22

3-
The HElib build, install, and regression tests suite have been built and tested
4-
on Ubuntu 18.04, Ubuntu 20.04, Fedora 32, Fedora 33, CentOS 7.8, CentOS 8.2,
5-
macOS Mojave >=10.14.6, and macOS Catalina >=10.15.7.
3+
The current HElib build, install, and regression tests suite have been built
4+
and tested on Ubuntu 20.04 and macOS Catalina >=10.15.7. Previous versions
5+
have also included Ubuntu 18.04, Fedora 33, CentOS 8.2, macOS Mojave >=10.14.6.
66

77
There are two different ways to build and install HElib. The first one will
88
automatically download and build the GMP and NTL dependencies and pack the
99
libraries in a relocatable folder. The second way, instead, requires the
1010
dependencies to be installed by you and available in the system.
1111

12-
**Please read these instructions in full to better choose the type of build that
13-
is better for you.**
12+
This release of HElib has experimental support for the Intel® [HEXL](https://github.com/intel/hexl)
13+
acceleration library for homomorphic encryption that exploits Intel® Advanced Vector Extensions 512.
14+
Instructions to enable and link to HEXL are given
15+
[below](#enabling-and-linking-to-intel-hexl).
16+
17+
```diff
18+
- Please read these instructions in full to better choose the type of build that is best for you.
19+
```
1420

1521
## General prerequisites
1622

17-
- GNU make >= 3.82
1823
- pthreads
19-
- git >= 1.8.3 (required to build and run the HElib test suite)
24+
- git >= 2.27 (required to build and run the HElib test suite)
2025

21-
**Linux environment:**
26+
**Default Linux environment:**
2227

23-
- g++ >= 7.3.1
24-
- cmake >= 3.10.2
28+
- GNU make >= 4.2
29+
- g++ >= 9.3.0 (recommended g++ 10.3.0)
30+
- cmake >= 3.16
2531

2632
**macOS environment:**
2733

28-
- Apple clang >= 11.0.0 (available with the latest Xcode for the tested versions of macOS)
34+
- Apple clang >= 12.0.0 (available with the latest Xcode for the tested versions of macOS)
2935
- Xcode Command Line Tools (can be installed with the command `xcode-select
30-
--install` in a teminal)
31-
- cmake >= 3.17.3 (available from [CMake](https://cmake.org/) or [MacPorts
36+
--install` in a terminal)
37+
- cmake >= 3.20 (available from [CMake](https://cmake.org/) or [MacPorts
3238
Project](https://www.macports.org/) and [Homebrew](https://brew.sh/) as
3339
packages)
40+
- GNU make >= 3.81
3441

35-
**For development:**
42+
**For HElib development:**
3643

3744
- clang-format >= 9.0.0 (available with your linux distribution and for macOS
3845
from [MacPorts Project](https://www.macports.org/) and
@@ -108,7 +115,7 @@ some other system-wide path, step 5 may require `sudo` privileges.
108115
This option involves building HElib on its own, linking against pre-existing
109116
dependencies (NTL and GMP) on the system. In this way, the HElib library can be
110117
moved around, but its dependencies (NTL and GMP) cannot, as they are absolute
111-
paths. For this option, you must build GMP >=6.0.0 and NTL >=11.4.3 yourself.
118+
paths. For this option, you must build GMP >=6.2.1 and NTL >=11.5.1 yourself.
112119
For details on how to do this, please see the section on building dependencies
113120
later. It is assumed throughout this installation option that the environment
114121
variables `$GMPDIR` and `$NTLDIR` are set to point to the installation
@@ -170,8 +177,8 @@ Many distributions come with GMP pre-installed. If not, you can install GMP as
170177
follows.
171178

172179
1. Download GMP from [http://www.gmplib.org](http://www.gmplib.org) -- make sure
173-
that you get GMP >=6.0.0 (current version is 6.2.0).
174-
2. Decompress and cd into the gmp directory (e.g., `gmp-6.2.0`).
180+
that you get GMP >=6.2.0 (current version is 6.2.1).
181+
2. Decompress and cd into the gmp directory (e.g., `gmp-6.2.1`).
175182
3. GMP is compiled in the standard unix way:
176183

177184
```bash
@@ -189,9 +196,9 @@ step 3.
189196

190197
You can install NTL as follows:
191198

192-
1. Download NTL >=11.4.3 (current version is 11.4.3) from
193-
[http://www.shoup.net/ntl/download.html](http://www.shoup.net/ntl/download.html)
194-
2. Decompress and cd into the directory, e.g., `ntl-11.4.3/src`
199+
1. Download NTL >=11.5.1 from
200+
[https://libntl.org/download.html](https://libntl.org/download.html)
201+
2. Decompress and cd into the directory, e.g., `ntl-11.5.1/src`
195202
3. NTL is configured, built and installed in the standard Unix way (but remember
196203
to specify the following flags to `configure`):
197204

@@ -209,6 +216,42 @@ step 3.
209216
**NOTE**: if linking against a non-system GMP, pass `GMP_PREFIX=<path/to/gmp>`
210217
to the `./configure` step.
211218

219+
## Enabling and linking to Intel® HEXL
220+
**NOTE:** HElib with HEXL acceleration is only supported on the processors with AVX512DQ and
221+
AVX512-IFMA such as the 3rd generation Intel® Xeon® or the 11th generation Intel® Core®
222+
223+
**NOTE:** It is currently only possible to use HEXL with HElib when using the
224+
library build and when building HElib as a static library. i.e.
225+
`-DPACKAGE_BUILD=OFF` and `-DBUILD_SHARED=OFF`.
226+
227+
First you must download and build HEXL from source. Currently, HElib only
228+
works with HEXL version >= 1.2.1 Using git this would be
229+
230+
```bash
231+
git clone https://github.com/intel/hexl --branch 1.2.1
232+
```
233+
Follow the instructions for HEXL installation in the README.md for all
234+
available options. Note previous versions of HEXL requires the deprecated
235+
`-DENABLE_EXPORT=ON` otherwise the cmake metadata for linking a cmake project
236+
is not created. Modern versions do not have this flag and the metadata is
237+
created by default. For a quick start most people will want,
238+
239+
```bash
240+
cd hexl
241+
cmake -S . -B build/ [-DCMAKE_INSTALL_PREFIX=<install-location-for-HEXL>/lib/cmake/hexl-1.2.1]
242+
cmake --build build -j [<parallel-jobs>]
243+
cmake --install build
244+
```
245+
If you do not provide an optional install location for HEXL the default is
246+
`/usr/local`.
247+
248+
To enable and link HEXL in HElib, you must configure cmake for HElib with
249+
`-DUSE_INTEL_HEXL=ON`. If HEXL is not in the default system location or you
250+
wish to use another installation tell HElib where to find it using
251+
`-DHEXL_DIR=<install-location-for-hexl>`.
252+
There is no requirement to provide any HElib subprojects with the location of
253+
HEXL.
254+
212255
## HElib build options
213256

214257
### Generic options
@@ -248,6 +291,8 @@ to the `./configure` step.
248291

249292
- `GMP_DIR`: Prefix of the GMP library.
250293
- `NTL_DIR`: Prefix of the NTL library.
294+
- `USE_INTEL_HEXL`: Enable the Intel HEXL library.
295+
- `HEXL_DIR`: Prefix of the Intel HEXL library.
251296

252297
# Using HElib in a project
253298

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.1.0
1+
2.2.0

benchmarks/CMakeLists.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS
4848
"Debug" "RelWithDebInfo" "Release" "MinSizeRel")
4949

5050
# STRINGS avoids having the 2 newline characters at the end of the string.
51-
# Alternatively it's possible to use file(READ ...) and then
51+
# Alternatively it is possible to use file(READ ...) and then
5252
# string(REGEX REPLACE "\n$" "" HELIB_VERSION "${HELIB_VERSION}")
5353
file(STRINGS "../VERSION" HELIB_VERSION)
5454

@@ -61,7 +61,8 @@ set(TRGTS bgv_basic
6161
bgv_thinboot
6262
bgv_fatboot
6363
ckks_basic
64-
IO)
64+
IO
65+
fft_bench)
6566

6667
# Sources derived from their targets.
6768
set(SRCS "")

benchmarks/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ Build and install HElib as described in [INSTALL.md](../INSTALL.md).
99
### Build and install google benchmark
1010

1111
Download the library https://github.com/google/benchmark from github, build and
12-
then install it.
12+
then install it. We tested with Google Benchmark v1.5.6
1313

1414
```
15-
git clone https://github.com/google/benchmark
15+
git clone https://github.com/google/benchmark.git -b v1.5.6
1616
cd benchmark
1717
mkdir build
1818
cd build

benchmarks/bench_common.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/* Copyright (C) 2021 Intel Corporation
2+
* Licensed under the Apache License, Version 2.0 (the "License");
3+
* you may not use this file except in compliance with the License.
4+
* You may obtain a copy of the License at
5+
* http://www.apache.org/licenses/LICENSE-2.0
6+
* Unless required by applicable law or agreed to in writing, software
7+
* distributed under the License is distributed on an "AS IS" BASIS,
8+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
9+
* See the License for the specific language governing permissions and
10+
* limitations under the License.
11+
*/
12+
13+
#ifndef HELIB_BENCH_COMMON_H
14+
#define HELIB_BENCH_COMMON_H
15+
16+
#define HE_BENCH_CAPTURE(adding_two_ciphertexts, tiny_params, fn) \
17+
BENCHMARK_CAPTURE(adding_two_ciphertexts, tiny_params, fn(tiny_params))
18+
19+
#endif // HELIB_BENCH_COMMON_H

0 commit comments

Comments
 (0)