Skip to content
This repository was archived by the owner on Dec 25, 2023. It is now read-only.

Commit 3c6d427

Browse files
committed
Initial commit
1 parent d2c1aa8 commit 3c6d427

File tree

689 files changed

+9150
-66479
lines changed

Some content is hidden

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

689 files changed

+9150
-66479
lines changed

.clang-format

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Copyright (C) 2020-2021 Intel Corporation
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
BasedOnStyle: Google
5+
Language: Cpp
6+
DerivePointerAlignment: false
7+
PointerAlignment: Left
8+
IndentWidth: 4
9+
AccessModifierOffset: -4
10+
IndentCaseLabels: false

.github/workflows/ci.yml

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
name: ci
2+
3+
on:
4+
# By default this will run when the activity type is "opened", "synchronize",
5+
# or "reopened".
6+
pull_request:
7+
branches:
8+
- main
9+
- development
10+
- "[0-9]+.[0-9]+" # Run on release branch, e.g. 1.0
11+
# Run when protected branches are pushed to, e.g. via merge
12+
push:
13+
branches:
14+
- main
15+
- development
16+
- "[0-9]+.[0-9]+" # Run on release branch, e.g. 1.0
17+
workflow_dispatch:
18+
19+
defaults:
20+
run:
21+
shell: bash -il -eo pipefail {0}
22+
23+
jobs:
24+
run_ci:
25+
runs-on: [self-hosted, fpga]
26+
27+
steps:
28+
- name: checkout_repo
29+
uses: actions/checkout@v2
30+
31+
- name: pre-commit
32+
run: pre-commit run --all-files
33+
34+
- name: show_details
35+
run: |
36+
echo 'pwd'
37+
pwd
38+
echo 'whoami'
39+
whoami
40+
echo 'hostname'
41+
hostname
42+
43+
- name: build_he-fpga
44+
run: |
45+
mkdir build
46+
cd build
47+
cmake .. -DCMAKE_INSTALL_PREFIX=install -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_COMPILER=g++ -DCMAKE_C_COMPILER=gcc -DENABLE_FPGA_DEBUG=ON -DENABLE_TESTS=ON -DENABLE_BENCHMARK=ON
48+
make -j
49+
50+
- name: build_emulation
51+
run: |
52+
source /disk1/tools/init_env.sh
53+
source /disk1/tools/new_env_setup.sh
54+
cd build
55+
make emulation
56+
57+
- name: build_install
58+
run: |
59+
cd build
60+
make install
61+
62+
- name: run_tests
63+
run: |
64+
source /disk1/tools/init_env.sh
65+
source /disk1/tools/new_env_setup.sh
66+
cd build
67+
RUN_CHOICE=1 make tests
68+
69+
- name: run_bench
70+
run: |
71+
source /disk1/tools/init_env.sh
72+
source /disk1/tools/new_env_setup.sh
73+
cd build
74+
RUN_CHOICE=1 make bench
75+
76+
- name: build_examples
77+
run: |
78+
mkdir build-examples
79+
cd build-examples
80+
cmake ../examples/ -DCMAKE_PREFIX_PATH=$(realpath ..)/build/install/lib/cmake/ -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_COMPILER=g++ -DCMAKE_C_COMPILER=gcc
81+
make -j
82+
83+
- name: run_examples
84+
run: |
85+
source /disk1/tools/init_env.sh
86+
source /disk1/tools/new_env_setup.sh
87+
cd build-examples
88+
RUN_CHOICE=1 make examples

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
*.aoclib
2+
*.aocx
3+
*.pdf
4+
build/
5+
build-examples/
6+
hexl-fpga-install/

.pre-commit-config.yaml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Copyright (C) 2020-2021 Intel Corporation
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
repos:
5+
- repo: https://github.com/pre-commit/pre-commit-hooks
6+
rev: v2.5.0
7+
hooks:
8+
- id: trailing-whitespace
9+
exclude: ^(doc/|README.md)
10+
- id: end-of-file-fixer
11+
- id: check-merge-conflict
12+
- id: mixed-line-ending
13+
- id: check-byte-order-marker
14+
- id: check-yaml
15+
- repo: local
16+
hooks:
17+
- id: clang-format
18+
name: clang-format
19+
entry: clang-format
20+
language: system
21+
exclude: ^(host/common/)
22+
files: \.(c|cc|cxx|cpp|cl|h|hpp|hxx)$
23+
args:
24+
- -i
25+
- id: cpplint
26+
name: cpplint
27+
entry: cpplint
28+
language: system
29+
exclude: ^(host/common/)
30+
files: \.(c|cc|cxx|cpp|h|hpp|hxx)$
31+
args:
32+
- --recursive

CMakeLists.txt

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
# Copyright (C) 2020-2021 Intel Corporation
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
cmake_minimum_required(VERSION 3.5.1)
5+
6+
project(hexl-fpga LANGUAGES C CXX)
7+
set(hexl-fpga_VERSION 1.0)
8+
9+
set(CMAKE_CONFIGURATION_TYPES Debug Release CACHE STRING INTERNAL FORCE)
10+
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Build Type: Debug or Release")
11+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
12+
set(CMAKE_CXX_STANDARD 11)
13+
set(CMAKE_CXX_FLAGS_DEBUG "-g3 -O0 -Wall")
14+
set(CMAKE_C_FLAGS_DEBUG "-g3 -O0 -Wall")
15+
set(CMAKE_CXX_FLAGS_RELEASE "-march=native -O3 -funroll-loops -Wall ")
16+
set(CMAKE_C_FLAGS_RELEASE "-march=native -O3 -funroll-loops -Wall ")
17+
18+
set(OPENCL_ROOT_PATH $ENV{INTELFPGAOCLSDKROOT})
19+
set(FPGA_SRC_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR})
20+
21+
option(ENABLE_FPGA_DEBUG "Enable FPGA debugging info" OFF)
22+
message(STATUS "ENABLE_FPGA_DEBUG: ${ENABLE_FPGA_DEBUG}")
23+
option(ENABLE_TESTS "Enable Tests" OFF)
24+
message(STATUS "ENABLE_TESTS: ${ENABLE_TESTS}")
25+
option(ENABLE_BENCHMARK "Enable Benchmark" OFF)
26+
message(STATUS "ENABLE_BENCHMARK: ${ENABLE_BENCHMARK}")
27+
option(ENABLE_DOCS "Enable Documentation" OFF)
28+
message(STATUS "ENABLE_DOCS: ${ENABLE_DOCS}")
29+
30+
if (LINUX)
31+
include(GNUInstallDirs)
32+
else()
33+
set(CMAKE_INSTALL_INCLUDEDIR "include")
34+
set(CMAKE_INSTALL_LIBDIR "lib")
35+
endif()
36+
37+
add_subdirectory(host)
38+
add_subdirectory(device)
39+
40+
if(ENABLE_DOCS)
41+
find_package(Doxygen)
42+
option(BUILD_DOCUMENTATION "Create and install the HTML based API documentation (requires Doxygen)" ${DOXYGEN_FOUND})
43+
if(BUILD_DOCUMENTATION)
44+
if(NOT DOXYGEN_FOUND)
45+
message(FATAL_ERROR "Doxygen was not found (Required)")
46+
else()
47+
add_subdirectory(doc)
48+
endif()
49+
endif()
50+
endif()
51+
52+
if (ENABLE_TESTS)
53+
add_subdirectory(cmake/gtest)
54+
add_subdirectory(tests)
55+
endif (ENABLE_TESTS)
56+
57+
if (ENABLE_BENCHMARK)
58+
add_subdirectory(cmake/gbenchmark)
59+
add_subdirectory(benchmark)
60+
endif (ENABLE_BENCHMARK)
61+
62+
include(CMakePackageConfigHelpers)
63+
write_basic_package_version_file(
64+
"${CMAKE_CURRENT_BINARY_DIR}/hexl-fpga/hexl-fpgaConfigVersion.cmake"
65+
VERSION ${hexl-fpga_VERSION}
66+
COMPATIBILITY AnyNewerVersion
67+
)
68+
69+
export(EXPORT hexl-fpgaTargets
70+
FILE "${CMAKE_CURRENT_BINARY_DIR}/hexl-fpga/hexl-fpgaTargets.cmake"
71+
NAMESPACE hexl-fpga::
72+
)
73+
configure_file(cmake/hexl-fpga/hexl-fpgaConfig.cmake
74+
"${CMAKE_CURRENT_BINARY_DIR}/hexl-fpga/hexl-fpgaConfig.cmake"
75+
)
76+
77+
set(ConfigPackageLocation ${CMAKE_INSTALL_LIBDIR}/cmake/hexl-fpga)
78+
install (
79+
EXPORT hexl-fpgaTargets
80+
FILE hexl-fpgaTargets.cmake
81+
NAMESPACE hexl-fpga::
82+
DESTINATION ${ConfigPackageLocation}
83+
)
84+
85+
install(
86+
FILES
87+
cmake/hexl-fpga/hexl-fpgaConfig.cmake
88+
"${CMAKE_CURRENT_BINARY_DIR}/hexl-fpga/hexl-fpgaConfigVersion.cmake"
89+
DESTINATION
90+
${ConfigPackageLocation}
91+
COMPONENT
92+
Devel
93+
)
94+
if(ENABLE_DOCS)
95+
install(DIRECTORY ${DOXYGEN_DOC_DIR}
96+
DESTINATION ${CMAKE_INSTALL_PREFIX}/doc)
97+
endif()

CPPLINT.cfg

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Copyright (C) 2020-2021 Intel Corporation
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
filter=-readability/casting
5+
filter=-whitespace/indent
6+
filter=-build/header_guard
7+
filter=-runtime/references
8+
filter=-runtime/int
9+
filter=-readability/braces
10+
filter=-build/include_subdir
11+
filter=-build/c++11
12+
filter=-build/include_what_you_use

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
main: [![Build and Test](https://github.com/intel/hexl-fpga/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/intel/hexl-fpga/actions/workflows/ci.yml)
2+
development: [![Build and Test](https://github.com/intel/hexl-fpga/actions/workflows/ci.yml/badge.svg?branch=development)](https://github.com/intel/hexl-fpga/actions/workflows/ci.yml)
3+
14
# Intel Homomorphic Encryption Acceleration Library for FPGAs <br>(Intel HEXL for FPGA)
25
Intel:registered: HEXL for FPGA is an open-source library that provides an implementation of homomorphic encryption primitives on Intel FPGAs. Intel HEXL for FPGA targets integer arithmetic with word-sized primes, typically 40-60 bits. Intel HEXL for FPGA provides an API for 64-bit unsigned integers and targets Intel FPGAs.
36

@@ -188,7 +191,7 @@ cmake --build build --target bench
188191
The benchmark executables are located in `build/benchmark/` directory <br>
189192

190193
## Using Intel HEXL for FPGA
191-
The `examples` folder contains an example showing how to use Intel HEXL for FPGA library in a third-party project. <br>
194+
The `examples` folder contains an example showing how to use Intel HEXL for FPGA library in a third-party project. See [examples/README.md](examples/README.md) for details. <br>
192195

193196
## Debugging
194197
For optimal performance, Intel HEXL for FPGA does not perform input validation. In many cases the time required for the validation would be longer than the execution of the function itself. To debug Intel HEXL for FPGA, configure and build Intel HEXL for FPGA with the option <br>

benchmark/CMakeLists.txt

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Copyright (C) 2020-2021 Intel Corporation
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
cmake_minimum_required(VERSION 3.5.1)
5+
6+
function(bench_function kernel)
7+
set (KERNEL ${kernel})
8+
set (SRC
9+
${CMAKE_CURRENT_SOURCE_DIR}/main.cpp
10+
${CMAKE_CURRENT_SOURCE_DIR}/bench_${KERNEL}.cpp
11+
)
12+
13+
add_executable(bench_${KERNEL} ${SRC})
14+
15+
target_compile_options(bench_${KERNEL} PRIVATE -fPIE -fPIC -fstack-protector -Wformat -Wformat-security)
16+
target_compile_options(bench_${KERNEL} PRIVATE -z noexecstack -Wl,-z,relro,-z,now -Wl,-Bsymbolic)
17+
target_include_directories(bench_${KERNEL} PRIVATE $<BUILD_INTERFACE:${CMAKE_INSTALL_PREFIX}/inc>)
18+
target_link_directories(bench_${KERNEL} PUBLIC ${CMAKE_INSTALL_PREFIX}/lib)
19+
target_link_directories(bench_${KERNEL} PUBLIC ${CMAKE_BINARY_DIR}/hexl-install/lib)
20+
target_link_libraries(bench_${KERNEL} PUBLIC hexl-fpga)
21+
target_link_libraries(bench_${KERNEL} PRIVATE benchmark::benchmark)
22+
23+
add_custom_command(
24+
TARGET bench_${KERNEL} POST_BUILD
25+
COMMAND rm -f ${KERNEL}.aocx
26+
COMMAND ln -s ${CMAKE_INSTALL_PREFIX}/fpga/${KERNEL}.aocx .
27+
VERBATIM
28+
)
29+
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/micro_${KERNEL}.sh
30+
DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
31+
endfunction()
32+
33+
bench_function(dyadic_multiply)
34+
bench_function(fwd_ntt)
35+
bench_function(inv_ntt)
36+
37+
add_custom_target(bench
38+
COMMAND ./micro_dyadic_multiply.sh DEPENDS bench_dyadic_multiply
39+
COMMAND ./micro_fwd_ntt.sh DEPENDS bench_fwd_ntt
40+
COMMAND ./micro_inv_ntt.sh DEPENDS bench_inv_ntt
41+
)
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
// Copyright (C) 2020-2021 Intel Corporation
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
#include <benchmark/benchmark.h>
5+
6+
#include <vector>
7+
8+
#include "hexl-fpga.h"
9+
10+
class dyadic_multiply : public benchmark::Fixture {
11+
public:
12+
void setup_dyadic_multiply_io(uint64_t n_dyadic_multiply,
13+
uint64_t num_moduli, uint64_t coeff_count);
14+
void bench_dyadic_multiply(std::vector<uint64_t>& out,
15+
uint64_t n_dyadic_multiply, uint64_t num_moduli,
16+
uint64_t coeff_count);
17+
18+
private:
19+
std::vector<uint64_t> moduli;
20+
std::vector<uint64_t> op1;
21+
std::vector<uint64_t> op2;
22+
};
23+
24+
void dyadic_multiply::setup_dyadic_multiply_io(uint64_t n_dyadic_multiply,
25+
uint64_t num_moduli,
26+
uint64_t coeff_count) {
27+
for (uint64_t b = 0; b < n_dyadic_multiply; b++) {
28+
for (uint64_t m = 0; m < num_moduli; m++) {
29+
moduli.push_back((b + m + 1) * 10);
30+
}
31+
32+
for (uint64_t m = 0; m < num_moduli; m++) {
33+
for (uint64_t i = 0; i < coeff_count; i++) {
34+
op1.push_back(b + i + 1 + m * coeff_count);
35+
op2.push_back(b + i + 2 + m * coeff_count);
36+
}
37+
}
38+
39+
for (uint64_t m = 0; m < num_moduli; m++) {
40+
for (uint64_t i = 0; i < coeff_count; i++) {
41+
op1.push_back(b + i + 11 + m * coeff_count);
42+
op2.push_back(b + i + 22 + m * coeff_count);
43+
}
44+
}
45+
}
46+
}
47+
48+
void dyadic_multiply::bench_dyadic_multiply(std::vector<uint64_t>& out,
49+
uint64_t n_dyadic_multiply,
50+
uint64_t num_moduli,
51+
uint64_t coeff_count) {
52+
intel::hexl::set_worksize_DyadicMultiply(n_dyadic_multiply);
53+
for (uint64_t b = 0; b < n_dyadic_multiply; b++) {
54+
uint64_t* pout = &out[0] + b * num_moduli * coeff_count * 3;
55+
uint64_t* pop1 = &op1[0] + b * num_moduli * coeff_count * 2;
56+
uint64_t* pop2 = &op2[0] + b * num_moduli * coeff_count * 2;
57+
uint64_t* pmoduli = &moduli[0] + b * num_moduli;
58+
intel::hexl::DyadicMultiply(pout, pop1, pop2, coeff_count, pmoduli,
59+
num_moduli);
60+
}
61+
intel::hexl::DyadicMultiplyCompleted();
62+
}
63+
64+
BENCHMARK_F(dyadic_multiply, dyadic_multiply_p16384_m7_b1_4096)
65+
(benchmark::State& state) {
66+
uint64_t coeff_count = 16384 / 2;
67+
uint64_t num_moduli = 7;
68+
uint64_t n_dyadic_multiply = 4096;
69+
70+
setup_dyadic_multiply_io(n_dyadic_multiply, num_moduli, coeff_count);
71+
72+
std::vector<uint64_t> out(n_dyadic_multiply * 3 * num_moduli * coeff_count,
73+
0);
74+
75+
for (auto st : state) {
76+
bench_dyadic_multiply(out, n_dyadic_multiply, num_moduli, coeff_count);
77+
}
78+
}

0 commit comments

Comments
 (0)