Skip to content

Commit

Permalink
Add experimental FFT-like transform (intel#104)
Browse files Browse the repository at this point in the history
  • Loading branch information
joserochh authored Jul 4, 2022
1 parent 034c1b9 commit 00aeed9
Show file tree
Hide file tree
Showing 43 changed files with 3,997 additions and 200 deletions.
24 changes: 15 additions & 9 deletions benchmark/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,14 @@ set(SRC main.cpp
bench-eltwise-reduce-mod.cpp
)

add_executable(bench_hexl ${SRC})

target_include_directories(bench_hexl PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}
${HEXL_SRC_ROOT_DIR} # Private headers
if (HEXL_EXPERIMENTAL)
list(APPEND SRC
bench-fft-like.cpp
)

target_link_libraries(bench_hexl PRIVATE hexl benchmark::benchmark Threads::Threads)
if (HEXL_DEBUG)
target_link_libraries(bench_hexl PRIVATE easyloggingpp)
endif()

add_executable(bench_hexl ${SRC})

if (CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
target_compile_options(bench_hexl PRIVATE -Wall -Wextra -march=native -O3)
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
Expand All @@ -32,3 +28,13 @@ elseif (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
/wd5105 # warning C5105: macro expansion producing 'defined' has undefined behavior
)
endif()

target_include_directories(bench_hexl PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}
${HEXL_SRC_ROOT_DIR} # Private headers
)

target_link_libraries(bench_hexl PRIVATE hexl benchmark::benchmark Threads::Threads)
if (HEXL_DEBUG)
target_link_libraries(bench_hexl PRIVATE easyloggingpp)
endif()
16 changes: 8 additions & 8 deletions benchmark/bench-eltwise-add-mod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ static void BM_EltwiseVectorVectorAddModNative(
size_t input_size = state.range(0);
uint64_t modulus = 0xffffffffffc0001ULL;

auto input1 = GenerateInsecureUniformRandomValues(input_size, 0, modulus);
auto input2 = GenerateInsecureUniformRandomValues(input_size, 0, modulus);
auto input1 = GenerateInsecureUniformIntRandomValues(input_size, 0, modulus);
auto input2 = GenerateInsecureUniformIntRandomValues(input_size, 0, modulus);
AlignedVector64<uint64_t> output(input_size, 0);

for (auto _ : state) {
Expand All @@ -47,8 +47,8 @@ static void BM_EltwiseVectorVectorAddModAVX512(
size_t input_size = state.range(0);
size_t modulus = 1152921504606877697;

auto input1 = GenerateInsecureUniformRandomValues(input_size, 0, modulus);
auto input2 = GenerateInsecureUniformRandomValues(input_size, 0, modulus);
auto input1 = GenerateInsecureUniformIntRandomValues(input_size, 0, modulus);
auto input2 = GenerateInsecureUniformIntRandomValues(input_size, 0, modulus);
AlignedVector64<uint64_t> output(input_size, 0);

for (auto _ : state) {
Expand All @@ -71,8 +71,8 @@ static void BM_EltwiseVectorScalarAddModNative(
size_t input_size = state.range(0);
uint64_t modulus = 0xffffffffffc0001ULL;

auto input1 = GenerateInsecureUniformRandomValues(input_size, 0, modulus);
uint64_t input2 = GenerateInsecureUniformRandomValue(0, modulus);
auto input1 = GenerateInsecureUniformIntRandomValues(input_size, 0, modulus);
uint64_t input2 = GenerateInsecureUniformIntRandomValue(0, modulus);
AlignedVector64<uint64_t> output(input_size, 0);

for (auto _ : state) {
Expand All @@ -96,8 +96,8 @@ static void BM_EltwiseVectorScalarAddModAVX512(
size_t input_size = state.range(0);
size_t modulus = 1152921504606877697;

auto input1 = GenerateInsecureUniformRandomValues(input_size, 0, modulus);
uint64_t input2 = GenerateInsecureUniformRandomValue(0, modulus);
auto input1 = GenerateInsecureUniformIntRandomValues(input_size, 0, modulus);
uint64_t input2 = GenerateInsecureUniformIntRandomValue(0, modulus);
AlignedVector64<uint64_t> output(input_size, 0);

for (auto _ : state) {
Expand Down
10 changes: 5 additions & 5 deletions benchmark/bench-eltwise-cmp-add.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ static void BM_EltwiseCmpAddNative(benchmark::State& state) { // NOLINT

uint64_t modulus = 100;

uint64_t bound = GenerateInsecureUniformRandomValue(0, modulus);
uint64_t diff = GenerateInsecureUniformRandomValue(1, modulus - 1);
auto input1 = GenerateInsecureUniformRandomValues(input_size, 0, modulus);
uint64_t bound = GenerateInsecureUniformIntRandomValue(0, modulus);
uint64_t diff = GenerateInsecureUniformIntRandomValue(1, modulus - 1);
auto input1 = GenerateInsecureUniformIntRandomValues(input_size, 0, modulus);

for (auto _ : state) {
EltwiseCmpAddNative(input1.data(), input1.data(), input_size, CMPINT::NLT,
Expand All @@ -48,8 +48,8 @@ static void BM_EltwiseCmpAddAVX512(benchmark::State& state) { // NOLINT

uint64_t bound = 50;
// must be non-zero
uint64_t diff = GenerateInsecureUniformRandomValue(1, bound - 1);
auto input1 = GenerateInsecureUniformRandomValues(input_size, 0, bound);
uint64_t diff = GenerateInsecureUniformIntRandomValue(1, bound - 1);
auto input1 = GenerateInsecureUniformIntRandomValues(input_size, 0, bound);

for (auto _ : state) {
EltwiseCmpAddAVX512(input1.data(), input1.data(), input_size, CMPINT::NLT,
Expand Down
12 changes: 6 additions & 6 deletions benchmark/bench-eltwise-cmp-sub-mod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ static void BM_EltwiseCmpSubModNative(benchmark::State& state) { // NOLINT
size_t input_size = state.range(0);

uint64_t modulus = 100;
uint64_t bound = GenerateInsecureUniformRandomValue(1, modulus);
uint64_t diff = GenerateInsecureUniformRandomValue(1, modulus);
auto input1 = GenerateInsecureUniformRandomValues(input_size, 0, modulus);
uint64_t bound = GenerateInsecureUniformIntRandomValue(1, modulus);
uint64_t diff = GenerateInsecureUniformIntRandomValue(1, modulus);
auto input1 = GenerateInsecureUniformIntRandomValues(input_size, 0, modulus);

for (auto _ : state) {
EltwiseCmpSubModNative(input1.data(), input1.data(), input_size, modulus,
Expand All @@ -45,9 +45,9 @@ BENCHMARK(BM_EltwiseCmpSubModNative)
static void BM_EltwiseCmpSubModAVX512_64(benchmark::State& state) { // NOLINT
size_t input_size = state.range(0);
uint64_t modulus = 100;
uint64_t bound = GenerateInsecureUniformRandomValue(0, modulus);
uint64_t diff = GenerateInsecureUniformRandomValue(1, modulus);
auto input1 = GenerateInsecureUniformRandomValues(input_size, 0, modulus);
uint64_t bound = GenerateInsecureUniformIntRandomValue(0, modulus);
uint64_t diff = GenerateInsecureUniformIntRandomValue(1, modulus);
auto input1 = GenerateInsecureUniformIntRandomValues(input_size, 0, modulus);

for (auto _ : state) {
EltwiseCmpSubModAVX512<64>(input1.data(), input1.data(), input_size,
Expand Down
18 changes: 9 additions & 9 deletions benchmark/bench-eltwise-fma-mod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ static void BM_EltwiseFMAModAddNative(benchmark::State& state) { // NOLINT
uint64_t modulus = 0xffffffffffc0001ULL;
bool add = state.range(1);

auto input1 = GenerateInsecureUniformRandomValues(input_size, 0, modulus);
uint64_t input2 = GenerateInsecureUniformRandomValue(0, modulus);
auto input1 = GenerateInsecureUniformIntRandomValues(input_size, 0, modulus);
uint64_t input2 = GenerateInsecureUniformIntRandomValue(0, modulus);
AlignedVector64<uint64_t> input3 =
GenerateInsecureUniformRandomValues(input_size, 0, modulus);
GenerateInsecureUniformIntRandomValues(input_size, 0, modulus);
uint64_t* arg3 = add ? input3.data() : nullptr;

for (auto _ : state) {
Expand All @@ -47,10 +47,10 @@ static void BM_EltwiseFMAModAVX512DQ(benchmark::State& state) { // NOLINT
size_t modulus = 100;
bool add = state.range(1);

auto input1 = GenerateInsecureUniformRandomValues(input_size, 0, modulus);
uint64_t input2 = GenerateInsecureUniformRandomValue(0, modulus);
auto input1 = GenerateInsecureUniformIntRandomValues(input_size, 0, modulus);
uint64_t input2 = GenerateInsecureUniformIntRandomValue(0, modulus);
AlignedVector64<uint64_t> input3 =
GenerateInsecureUniformRandomValues(input_size, 0, modulus);
GenerateInsecureUniformIntRandomValues(input_size, 0, modulus);

uint64_t* arg3 = add ? input3.data() : nullptr;

Expand All @@ -73,9 +73,9 @@ static void BM_EltwiseFMAModAVX512IFMA(benchmark::State& state) { // NOLINT
size_t modulus = 100;
bool add = state.range(1);

auto input1 = GenerateInsecureUniformRandomValues(input_size, 0, modulus);
uint64_t input2 = GenerateInsecureUniformRandomValue(0, modulus);
auto input3 = GenerateInsecureUniformRandomValues(input_size, 0, modulus);
auto input1 = GenerateInsecureUniformIntRandomValues(input_size, 0, modulus);
uint64_t input2 = GenerateInsecureUniformIntRandomValue(0, modulus);
auto input3 = GenerateInsecureUniformIntRandomValues(input_size, 0, modulus);

uint64_t* arg3 = add ? input3.data() : nullptr;

Expand Down
32 changes: 16 additions & 16 deletions benchmark/bench-eltwise-mult-mod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ static void BM_EltwiseMultMod(benchmark::State& state) { // NOLINT
size_t input_mod_factor = state.range(2);
uint64_t modulus = (1ULL << bit_width) + 7;

auto input1 = GenerateInsecureUniformRandomValues(input_size, 0, modulus);
auto input2 = GenerateInsecureUniformRandomValues(input_size, 0, modulus);
auto input1 = GenerateInsecureUniformIntRandomValues(input_size, 0, modulus);
auto input2 = GenerateInsecureUniformIntRandomValues(input_size, 0, modulus);
AlignedVector64<uint64_t> output(input_size, 2);

for (auto _ : state) {
Expand All @@ -47,8 +47,8 @@ static void BM_EltwiseMultModNative(benchmark::State& state) { // NOLINT
size_t input_size = state.range(0);
uint64_t modulus = 0xffffffffffc0001ULL;

auto input1 = GenerateInsecureUniformRandomValues(input_size, 0, modulus);
auto input2 = GenerateInsecureUniformRandomValues(input_size, 0, modulus);
auto input1 = GenerateInsecureUniformIntRandomValues(input_size, 0, modulus);
auto input2 = GenerateInsecureUniformIntRandomValues(input_size, 0, modulus);
AlignedVector64<uint64_t> output(input_size, 2);

for (auto _ : state) {
Expand All @@ -73,8 +73,8 @@ static void BM_EltwiseMultModAVX512Float(benchmark::State& state) { // NOLINT
size_t input_mod_factor = state.range(1);
size_t modulus = 100;

auto input1 = GenerateInsecureUniformRandomValues(input_size, 0, modulus);
auto input2 = GenerateInsecureUniformRandomValues(input_size, 0, modulus);
auto input1 = GenerateInsecureUniformIntRandomValues(input_size, 0, modulus);
auto input2 = GenerateInsecureUniformIntRandomValues(input_size, 0, modulus);
AlignedVector64<uint64_t> output(input_size, 2);

for (auto _ : state) {
Expand Down Expand Up @@ -110,8 +110,8 @@ static void BM_EltwiseMultModAVX512DQInt(benchmark::State& state) { // NOLINT
size_t input_mod_factor = state.range(1);
size_t modulus = 0xffffffffffc0001ULL;

auto input1 = GenerateInsecureUniformRandomValues(input_size, 0, modulus);
auto input2 = GenerateInsecureUniformRandomValues(input_size, 0, modulus);
auto input1 = GenerateInsecureUniformIntRandomValues(input_size, 0, modulus);
auto input2 = GenerateInsecureUniformIntRandomValues(input_size, 0, modulus);
AlignedVector64<uint64_t> output(input_size, 3);

for (auto _ : state) {
Expand Down Expand Up @@ -146,10 +146,10 @@ static void BM_EltwiseMultModAVX512IFMAInt(
size_t input_mod_factor = state.range(1);
size_t modulus = 100;

auto input1 = GenerateInsecureUniformRandomValues(input_size, 0,
input_mod_factor * modulus);
auto input2 = GenerateInsecureUniformRandomValues(input_size, 0,
input_mod_factor * modulus);
auto input1 = GenerateInsecureUniformIntRandomValues(
input_size, 0, input_mod_factor * modulus);
auto input2 = GenerateInsecureUniformIntRandomValues(
input_size, 0, input_mod_factor * modulus);
AlignedVector64<uint64_t> output(input_size, 3);

for (auto _ : state) {
Expand Down Expand Up @@ -187,10 +187,10 @@ static void BM_EltwiseMultModMontAVX512IFMAIntEConv(
size_t input_size = state.range(0);
size_t input_mod_factor = state.range(1);
uint64_t modulus = (1ULL << 50) + 7; // 1125899906842631
auto op1 = GenerateInsecureUniformRandomValues(input_size, 0,
input_mod_factor * modulus);
auto op2 = GenerateInsecureUniformRandomValues(input_size, 0,
input_mod_factor * modulus);
auto op1 = GenerateInsecureUniformIntRandomValues(input_size, 0,
input_mod_factor * modulus);
auto op2 = GenerateInsecureUniformIntRandomValues(input_size, 0,
input_mod_factor * modulus);
AlignedVector64<uint64_t> output(input_size, 3);

int r = 51; // R = 2251799813685248
Expand Down
24 changes: 12 additions & 12 deletions benchmark/bench-eltwise-reduce-mod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ static void BM_EltwiseReduceModInPlace(benchmark::State& state) { // NOLINT
uint64_t modulus = 0xffffffffffc0001ULL;

auto input1 =
GenerateInsecureUniformRandomValues(input_size, 0, 100 * modulus);
GenerateInsecureUniformIntRandomValues(input_size, 0, 100 * modulus);
const uint64_t input_mod_factor = modulus;
const uint64_t output_mod_factor = 1;
for (auto _ : state) {
Expand All @@ -45,7 +45,7 @@ static void BM_EltwiseReduceModCopy(benchmark::State& state) { // NOLINT
uint64_t modulus = 0xffffffffffc0001ULL;

auto input1 =
GenerateInsecureUniformRandomValues(input_size, 0, 100 * modulus);
GenerateInsecureUniformIntRandomValues(input_size, 0, 100 * modulus);
const uint64_t input_mod_factor = modulus;
const uint64_t output_mod_factor = 1;
AlignedVector64<uint64_t> output(input_size, 0);
Expand All @@ -70,7 +70,7 @@ static void BM_EltwiseReduceModNative(benchmark::State& state) { // NOLINT
uint64_t modulus = 0xffffffffffc0001ULL;

auto input1 =
GenerateInsecureUniformRandomValues(input_size, 0, 100 * modulus);
GenerateInsecureUniformIntRandomValues(input_size, 0, 100 * modulus);
const uint64_t input_mod_factor = modulus;
const uint64_t output_mod_factor = 1;
AlignedVector64<uint64_t> output(input_size, 0);
Expand All @@ -96,7 +96,7 @@ static void BM_EltwiseReduceModAVX512(benchmark::State& state) { // NOLINT
size_t modulus = 0xffffffffffc0001ULL;

auto input1 =
GenerateInsecureUniformRandomValues(input_size, 0, 100 * modulus);
GenerateInsecureUniformIntRandomValues(input_size, 0, 100 * modulus);
const uint64_t input_mod_factor = modulus;
const uint64_t output_mod_factor = 1;
AlignedVector64<uint64_t> output(input_size, 0);
Expand Down Expand Up @@ -124,7 +124,7 @@ static void BM_EltwiseReduceModAVX512BitShift64(
size_t modulus = 0xffffffffffc0001ULL;

auto input1 =
GenerateInsecureUniformRandomValues(input_size, 0, 100 * modulus);
GenerateInsecureUniformIntRandomValues(input_size, 0, 100 * modulus);
const uint64_t input_mod_factor = modulus;
const uint64_t output_mod_factor = 2;
AlignedVector64<uint64_t> output(input_size, 0);
Expand Down Expand Up @@ -152,7 +152,7 @@ static void BM_EltwiseReduceModAVX512BitShift52(
size_t modulus = 0xffffffffffc0001ULL;

auto input1 =
GenerateInsecureUniformRandomValues(input_size, 0, 100 * modulus);
GenerateInsecureUniformIntRandomValues(input_size, 0, 100 * modulus);
const uint64_t input_mod_factor = modulus;
const uint64_t output_mod_factor = 2;
AlignedVector64<uint64_t> output(input_size, 0);
Expand All @@ -179,7 +179,7 @@ static void BM_EltwiseReduceModAVX512BitShift52GT(
size_t input_size = state.range(0);
size_t modulus = 0xffffffffffc0001ULL;

auto input1 = GenerateInsecureUniformRandomValues(
auto input1 = GenerateInsecureUniformIntRandomValues(
input_size, 4503599627370496, 100 * modulus);
const uint64_t input_mod_factor = modulus;
const uint64_t output_mod_factor = 1;
Expand All @@ -203,7 +203,7 @@ static void BM_EltwiseReduceModAVX512BitShift52LT(
size_t modulus = 0xffffffffffc0001ULL;

auto input1 =
GenerateInsecureUniformRandomValues(input_size, 0, 2251799813685248);
GenerateInsecureUniformIntRandomValues(input_size, 0, 2251799813685248);
const uint64_t input_mod_factor = modulus;
const uint64_t output_mod_factor = 1;
AlignedVector64<uint64_t> output(input_size, 0);
Expand All @@ -229,7 +229,7 @@ static void BM_EltwiseReduceModMontAVX512BitShift52LT(
size_t input_size = state.range(0);
uint64_t modulus = 67280421310725ULL;

auto input_a = GenerateInsecureUniformRandomValues(input_size, 0, modulus);
auto input_a = GenerateInsecureUniformIntRandomValues(input_size, 0, modulus);
AlignedVector64<uint64_t> input_b(input_size, 42006526039321);

int r = 46; // R^2 mod N = 42006526039321
Expand All @@ -256,7 +256,7 @@ static void BM_EltwiseReduceModMontFormInAVX512BitShift52LT(
size_t input_size = state.range(0);
uint64_t modulus = 67280421310725ULL;

auto input_a = GenerateInsecureUniformRandomValues(input_size, 0, modulus);
auto input_a = GenerateInsecureUniformIntRandomValues(input_size, 0, modulus);
AlignedVector64<uint64_t> input_b(input_size, 42006526039321);

int r = 46; // R^2 mod N = 42006526039321
Expand All @@ -282,7 +282,7 @@ static void BM_EltwiseReduceModMontFormInAVX512BitShift64LT(
size_t input_size = state.range(0);
uint64_t modulus = 67280421310725ULL;

auto input_a = GenerateInsecureUniformRandomValues(input_size, 0, modulus);
auto input_a = GenerateInsecureUniformIntRandomValues(input_size, 0, modulus);
AlignedVector64<uint64_t> input_b(input_size, 42006526039321);

int r = 46; // R^2 mod N = 42006526039321
Expand All @@ -308,7 +308,7 @@ static void BM_EltwiseReduceModInOutMontFormAVX512BitShift52LT(
size_t input_size = state.range(0);
uint64_t modulus = 67280421310725ULL;

auto input_a = GenerateInsecureUniformRandomValues(input_size, 0, modulus);
auto input_a = GenerateInsecureUniformIntRandomValues(input_size, 0, modulus);

int r = 46; // R^2 mod N = 42006526039321
const uint64_t R2_mod_q = 42006526039321;
Expand Down
16 changes: 8 additions & 8 deletions benchmark/bench-eltwise-sub-mod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ static void BM_EltwiseVectorVectorSubModNative(
size_t input_size = state.range(0);
uint64_t modulus = 0xffffffffffc0001ULL;

auto input1 = GenerateInsecureUniformRandomValues(input_size, 0, modulus);
auto input2 = GenerateInsecureUniformRandomValues(input_size, 0, modulus);
auto input1 = GenerateInsecureUniformIntRandomValues(input_size, 0, modulus);
auto input2 = GenerateInsecureUniformIntRandomValues(input_size, 0, modulus);
AlignedVector64<uint64_t> output(input_size, 0);

for (auto _ : state) {
Expand All @@ -47,8 +47,8 @@ static void BM_EltwiseVectorVectorSubModAVX512(
size_t input_size = state.range(0);
size_t modulus = 1152921504606877697;

auto input1 = GenerateInsecureUniformRandomValues(input_size, 0, modulus);
auto input2 = GenerateInsecureUniformRandomValues(input_size, 0, modulus);
auto input1 = GenerateInsecureUniformIntRandomValues(input_size, 0, modulus);
auto input2 = GenerateInsecureUniformIntRandomValues(input_size, 0, modulus);
AlignedVector64<uint64_t> output(input_size, 0);

for (auto _ : state) {
Expand All @@ -71,8 +71,8 @@ static void BM_EltwiseVectorScalarSubModNative(
size_t input_size = state.range(0);
uint64_t modulus = 0xffffffffffc0001ULL;

auto input1 = GenerateInsecureUniformRandomValues(input_size, 0, modulus);
uint64_t input2 = GenerateInsecureUniformRandomValue(0, modulus);
auto input1 = GenerateInsecureUniformIntRandomValues(input_size, 0, modulus);
uint64_t input2 = GenerateInsecureUniformIntRandomValue(0, modulus);
AlignedVector64<uint64_t> output(input_size, 0);

for (auto _ : state) {
Expand All @@ -96,8 +96,8 @@ static void BM_EltwiseVectorScalarSubModAVX512(
size_t input_size = state.range(0);
size_t modulus = 1152921504606877697;

auto input1 = GenerateInsecureUniformRandomValues(input_size, 0, modulus);
uint64_t input2 = GenerateInsecureUniformRandomValue(0, modulus);
auto input1 = GenerateInsecureUniformIntRandomValues(input_size, 0, modulus);
uint64_t input2 = GenerateInsecureUniformIntRandomValue(0, modulus);
AlignedVector64<uint64_t> output(input_size, 0);

for (auto _ : state) {
Expand Down
Loading

0 comments on commit 00aeed9

Please sign in to comment.