Repository navigation
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
268 lines (249 loc) · 8.61 KB
/
Copy pathCMakeLists.txt
File metadata and controls
268 lines (249 loc) · 8.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
cmake_minimum_required(VERSION 3.16)
project(tfhe++ CXX C)
set(CMAKE_CXX_STANDARD 20)
option(DEBUG "Debug mode" OFF)
# TFHEPP_MARCH: target architecture for -march flag (default: native).
# Set to e.g. "x86-64-v3" for a portable AVX2 build.
if(NOT DEFINED TFHEPP_MARCH)
set(TFHEPP_MARCH "native")
endif()
if(DEBUG)
set(CMAKE_CXX_FLAGS
"-march=${TFHEPP_MARCH} -g -Wall -Wextra -pedantic -Wno-sign-compare")
else()
set(CMAKE_CXX_FLAGS
"-march=${TFHEPP_MARCH} -O3 -g -funroll-loops -Wall -Wextra -pedantic -Wno-sign-compare"
)
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
endif()
option(USE_80BIT_SECURITY "Use 80bit security parameter(faster)" OFF)
option(USE_CGGI19 "Use the parameter set proposed in CGGI19" OFF)
option(USE_BLOCK_BINARY "Use Concrete-based parameters with block-binary lvl0 keys" ON)
option(USE_CONCRETE "Use the parameter set proposed in CONCRETE" OFF)
option(USE_TFHE_RS "Use the parameter set proposed in TFHE-rs" OFF)
option(USE_TERNARY "Use ternary secret keys" OFF)
option(USE_COMPRESS "Use compressed ciphertexts" OFF)
option(USE_TERNARY_CMUX "Use ternary cmux" OFF)
option(USE_KEY_BUNDLE "Use key bundle algorithm" OFF)
option(USE_BLAKE3 "Use blake3 as CSPRNG" ON)
option(USE_RANDEN "Use randen as CSPRNG" OFF)
# Detect AVX-512 support at configure time.
# Strategy (in priority order):
# 1. /proc/cpuinfo — works in containers (Apptainer/Docker) without executing
# a compiled binary, because the host kernel's /proc is always visible.
# 2. check_cxx_source_compiles with -mavx512f — compile-only check for
# non-Linux or cross-compile environments (macOS, Windows, etc.).
# check_cxx_source_runs is intentionally avoided: it fails in container build
# environments (Apptainer %post, Docker RUN) where sandbox restrictions prevent
# executing compiled binaries during cmake configuration.
if(NOT DEFINED AVX512_SUPPORTED)
set(AVX512_SUPPORTED FALSE)
if(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64|AMD64|amd64")
if(EXISTS "/proc/cpuinfo")
file(READ "/proc/cpuinfo" TFHEPP_CPUINFO)
if(TFHEPP_CPUINFO MATCHES "avx512f")
set(AVX512_SUPPORTED TRUE)
endif()
else()
# No /proc/cpuinfo — non-Linux environment (macOS, Windows, etc.).
# Use a compile-only check as a proxy for AVX-512 availability.
include(CheckCXXSourceCompiles)
set(CMAKE_REQUIRED_FLAGS "-mavx512f")
check_cxx_source_compiles("
#include <immintrin.h>
int main() {
__m512d a = _mm512_setzero_pd();
(void)a;
return 0;
}
" AVX512_COMPILE_SUPPORTED)
unset(CMAKE_REQUIRED_FLAGS)
if(AVX512_COMPILE_SUPPORTED)
set(AVX512_SUPPORTED TRUE)
endif()
endif()
endif()
endif()
if(AVX512_SUPPORTED)
message(STATUS "AVX-512 support detected, USE_AVX512 defaults to ON")
set(USE_AVX512_DEFAULT ON)
else()
message(STATUS "AVX-512 support not detected, USE_AVX512 defaults to OFF")
set(USE_AVX512_DEFAULT OFF)
endif()
option(USE_AVX512 "Use AVX512 ver. SPQLIOS" ${USE_AVX512_DEFAULT})
option(USE_CONCRETE_FFT "Use concrete-fft" OFF)
option(USE_MKL "Use Intel MKL" OFF)
option(USE_FFTW3 "Use FFTW3" OFF)
option(USE_SPQLIOX_AARCH64 "Use spqliox_aarch64" OFF)
option(USE_SPQLIOS_ARITHMETIC "Use spqlios-arithmetic backend" OFF)
option(USE_SPQLIOS_INTL "Use interleaved-format SPQLIOS" ON)
option(USE_SPQLIOS_STOCKHAM "Use Stockham radix-4 SPQLIOS (split layout)" OFF)
option(USE_HEXL "Use Intel HEXL" OFF)
option(ENABLE_TEST "Build tests" OFF)
option(ENABLE_BENCHMARK "Build benchmarks" OFF)
option(ENABLE_TUTORIAL "Build tutorial" OFF)
option(USE_PERF "Use Google Profiler" OFF)
option(ENABLE_SHARED "Build as shared libraries" OFF)
set(TFHEpp_DEFINITIONS
""
PARENT_SCOPE)
if(USE_BLAKE3)
set(TFHEpp_DEFINITIONS
"${TFHEpp_DEFINITIONS};USE_BLAKE3"
PARENT_SCOPE)
add_compile_definitions(USE_BLAKE3)
add_subdirectory(thirdparties/BLAKE3/c)
elseif(USE_RANDEN)
set(TFHEpp_DEFINITIONS
"${TFHEpp_DEFINITIONS};USE_RANDEN"
PARENT_SCOPE)
add_compile_definitions(USE_RANDEN)
endif()
if(USE_80BIT_SECURITY)
set(TFHEpp_DEFINITIONS
"${TFHEpp_DEFINITIONS};USE_80BIT_SECURITY"
PARENT_SCOPE)
add_compile_definitions(USE_80BIT_SECURITY)
elseif(USE_COMPRESS)
set(TFHEpp_DEFINITIONS
"${TFHEpp_DEFINITIONS};USE_COMPRESS"
PARENT_SCOPE)
add_compile_definitions(USE_COMPRESS)
elseif(USE_CGGI19)
set(TFHEpp_DEFINITIONS
"${TFHEpp_DEFINITIONS};USE_CGGI19"
PARENT_SCOPE)
add_compile_definitions(USE_CGGI19)
elseif(USE_BLOCK_BINARY)
set(TFHEpp_DEFINITIONS
"${TFHEpp_DEFINITIONS};USE_BLOCK_BINARY"
PARENT_SCOPE)
add_compile_definitions(USE_BLOCK_BINARY)
elseif(USE_CONCRETE)
set(TFHEpp_DEFINITIONS
"${TFHEpp_DEFINITIONS};USE_CONCRETE"
PARENT_SCOPE)
add_compile_definitions(USE_CONCRETE)
elseif(USE_TFHE_RS)
set(TFHEpp_DEFINITIONS
"${TFHEpp_DEFINITIONS};USE_TFHE_RS"
PARENT_SCOPE)
add_compile_definitions(USE_TFHE_RS)
elseif(USE_TERNARY_CMUX)
set(TFHEpp_DEFINITIONS
"${TFHEpp_DEFINITIONS};USE_TERNARY_CMUX;USE_TERNARY"
PARENT_SCOPE)
add_compile_definitions(USE_TERNARY)
add_compile_definitions(USE_TERNARY_CMUX)
elseif(USE_TERNARY)
set(TFHEpp_DEFINITIONS
"${TFHEpp_DEFINITIONS};USE_TERNARY"
PARENT_SCOPE)
add_compile_definitions(USE_TERNARY)
endif()
if(NOT USE_TERNARY)
if(USE_KEY_BUNDLE)
set(TFHEpp_DEFINITIONS
"${TFHEpp_DEFINITIONS};USE_KEY_BUNDLE"
PARENT_SCOPE)
add_compile_definitions(USE_KEY_BUNDLE)
endif()
endif()
# if(USE_AVX512) string(APPEND CMAKE_CXX_FLAGS " -mprefer-vector-width=512")
# endif()
if(USE_FFTW3)
set(TFHEpp_DEFINITIONS
"${TFHEpp_DEFINITIONS};USE_FFTW3"
PARENT_SCOPE)
add_compile_definitions(USE_FFTW3)
add_subdirectory(thirdparties/fftw)
elseif(USE_MKL)
set(TFHEpp_DEFINITIONS
"${TFHEpp_DEFINITIONS};USE_MKL;USE_INTERLEAVED_FORMAT"
PARENT_SCOPE)
add_compile_definitions(USE_MKL)
add_compile_definitions(USE_INTERLEAVED_FORMAT)
find_package(MKL CONFIG REQUIRED PATHS $ENV{MKLROOT})
include_directories(${MKLROOT}/include)
add_subdirectory(thirdparties/mkl)
elseif(USE_SPQLIOX_AARCH64)
set(TFHEpp_DEFINITIONS
"${TFHEpp_DEFINITIONS};USE_SPQLIOX_AARCH64"
PARENT_SCOPE)
add_compile_definitions(USE_SPQLIOX_AARCH64)
add_subdirectory(thirdparties/spqliox_aarch64)
# Check if the platform is macOS and the architecture is ARM64
if(APPLE AND CMAKE_SYSTEM_PROCESSOR MATCHES "arm64")
include_directories(/opt/homebrew/include)
endif()
elseif(USE_CONCRETE_FFT)
set(TFHEpp_DEFINITIONS
"${TFHEpp_DEFINITIONS};USE_CONCRETE_FFT;USE_INTERLEAVED_FORMAT"
PARENT_SCOPE)
add_compile_definitions(USE_CONCRETE_FFT)
add_compile_definitions(USE_INTERLEAVED_FORMAT)
add_subdirectory(thirdparties/concrete-fft)
elseif(USE_SPQLIOS_INTL)
set(TFHEpp_DEFINITIONS
"${TFHEpp_DEFINITIONS};USE_SPQLIOS_INTL;USE_INTERLEAVED_FORMAT"
PARENT_SCOPE)
add_compile_definitions(USE_SPQLIOS_INTL)
add_compile_definitions(USE_INTERLEAVED_FORMAT)
add_subdirectory(thirdparties/spqlios-intl)
elseif(USE_SPQLIOS_STOCKHAM)
set(TFHEpp_DEFINITIONS
"${TFHEpp_DEFINITIONS};USE_SPQLIOS_STOCKHAM"
PARENT_SCOPE)
add_compile_definitions(USE_SPQLIOS_STOCKHAM)
add_subdirectory(thirdparties/spqlios-stockham)
elseif(USE_SPQLIOS_ARITHMETIC)
set(TFHEpp_DEFINITIONS
"${TFHEpp_DEFINITIONS};USE_SPQLIOS_ARITHMETIC"
PARENT_SCOPE)
add_compile_definitions(USE_SPQLIOS_ARITHMETIC)
# Disable spqlios-arithmetic tests to avoid gtest dependency
set(ENABLE_TESTING
OFF
CACHE BOOL "Disable spqlios-arithmetic tests" FORCE)
add_subdirectory(thirdparties/spqlios-arithmetic)
# Restore ENABLE_TEST for the parent project
set(ENABLE_TESTING ${ENABLE_TEST})
else()
if(USE_AVX512)
set(TFHEpp_DEFINITIONS
"${TFHEpp_DEFINITIONS};USE_AVX512"
PARENT_SCOPE)
add_compile_definitions(USE_AVX512)
endif()
add_subdirectory(thirdparties/spqlios)
endif()
if(USE_HEXL)
set(TFHEpp_DEFINITIONS
"${TFHEpp_DEFINITIONS};USE_HEXL"
PARENT_SCOPE)
add_compile_definitions(USE_HEXL)
add_subdirectory(thirdparties/hexl)
# set(CMAKE_CXX_FLAGS "-march=native -O3 -g -funroll-loops -Wall -Wextra
# -pedantic -Wno-sign-compare -mprefer-vector-width=512" )
endif()
# For OpenMP
find_package(OpenMP)
if(OpenMP_FOUND)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
endif()
if(USE_RANDEN)
add_subdirectory(thirdparties/randen)
endif()
add_subdirectory(src)
if(ENABLE_TEST)
add_subdirectory(test)
add_subdirectory(thirdparties/AES)
endif()
if(ENABLE_BENCHMARK)
add_subdirectory(benchmark)
endif()
if(ENABLE_TUTORIAL)
add_subdirectory(tutorial)
endif()
install(TARGETS tfhe++ LIBRARY DESTINATION lib)