Skip to content

Commit

Permalink
Enable multithread on OpenFHE with OpenMP support
Browse files Browse the repository at this point in the history
Included suggested flags from discussion #1209. In addition,
compile and link flags added to `tests/Examples/openfhe` to support
OpenMP. Multithreaded execution is enabled by default with this setup.
Clang based toolchain is supported currently.
  • Loading branch information
eymay committed Jan 26, 2025
1 parent dd91785 commit 1c42eb8
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 11 deletions.
19 changes: 19 additions & 0 deletions bazel/openfhe/copts.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
"""Build settings for OpenFHE and OpenMP."""

OPENFHE_COPTS = [
"-Wno-non-virtual-dtor",
"-Wno-shift-op-parentheses",
"-Wno-unused-private-field",
"-fexceptions",
]

OPENFHE_LINKOPTS = [
"-fopenmp",
"-lomp",
]

OPENMP_COPTS = [
"-fopenmp",
"-Xpreprocessor",
"-Wno-unused-command-line-argument",
]
19 changes: 8 additions & 11 deletions bazel/openfhe/openfhe.BUILD
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# BUILD file for a bazel-native OpenFHE build
load("@heir//bazel/openfhe:copts.bzl", "OPENFHE_COPTS", "OPENFHE_LINKOPTS", "OPENMP_COPTS")

package(
default_visibility = ["//visibility:public"],
Expand All @@ -18,17 +19,10 @@ OPENFHE_VERSION_PATCH = 3

OPENFHE_VERSION = "{}.{}.{}".format(OPENFHE_VERSION_MAJOR, OPENFHE_VERSION_MINOR, OPENFHE_VERSION_PATCH)

OPENFHE_COPTS = [
"-Wno-non-virtual-dtor",
"-Wno-shift-op-parentheses",
"-Wno-unused-private-field",
"-fexceptions",
]

OPENFHE_DEFINES = [
"MATHBACKEND=2",
"OMP_NUM_THREADS=1",
"OPENFHE_VERSION=" + OPENFHE_VERSION,
"PARALLEL",
]

# This rule exists so that the python frontend can get access to the headers to
Expand All @@ -48,7 +42,7 @@ cc_library(
"src/core/lib/**/*.c",
"src/core/lib/**/*.cpp",
]),
copts = OPENFHE_COPTS + [
copts = OPENFHE_COPTS + OPENMP_COPTS + [
# /utils/blockAllocator/blockAllocator.cpp has misaligned-pointer-use
"-fno-sanitize=alignment",
],
Expand All @@ -57,6 +51,7 @@ cc_library(
"src/core/include",
"src/core/lib",
],
linkopts = OPENFHE_LINKOPTS,
textual_hdrs = glob([
"src/core/include/**/*.h",
"src/core/lib/**/*.cpp",
Expand All @@ -70,12 +65,13 @@ cc_library(
"src/binfhe/lib/**/*.c",
"src/binfhe/lib/**/*.cpp",
]),
copts = OPENFHE_COPTS,
copts = OPENFHE_COPTS + OPENMP_COPTS,
defines = OPENFHE_DEFINES,
includes = [
"src/binfhe/include",
"src/binfhe/lib",
],
linkopts = OPENFHE_LINKOPTS,
textual_hdrs = glob(["src/binfhe/include/**/*.h"]),
deps = [
"@openfhe//:core",
Expand All @@ -87,14 +83,15 @@ cc_library(
srcs = glob([
"src/pke/lib/**/*.cpp",
]),
copts = OPENFHE_COPTS + [
copts = OPENFHE_COPTS + OPENMP_COPTS + [
"-Wno-vla-extension",
],
defines = OPENFHE_DEFINES,
includes = [
"src/pke/include",
"src/pke/lib",
],
linkopts = OPENFHE_LINKOPTS,
textual_hdrs = glob([
"src/pke/include/**/*.h",
"src/pke/lib/**/*.cpp",
Expand Down
5 changes: 5 additions & 0 deletions tests/Examples/openfhe/test.bzl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""A macro providing an end-to-end test for OpenFHE codegen."""

load("@heir//bazel/openfhe:copts.bzl", "OPENFHE_LINKOPTS", "OPENMP_COPTS")
load("@heir//tools:heir-opt.bzl", "heir_opt")
load("@heir//tools:heir-translate.bzl", "heir_translate")

Expand Down Expand Up @@ -55,6 +56,8 @@ def openfhe_end_to_end_test(name, mlir_src, test_src, generated_lib_header, heir
hdrs = [":" + generated_lib_header],
deps = deps + ["@openfhe//:pke"],
tags = tags,
copts = OPENMP_COPTS,
linkopts = OPENFHE_LINKOPTS,
**kwargs
)
native.cc_test(
Expand All @@ -68,5 +71,7 @@ def openfhe_end_to_end_test(name, mlir_src, test_src, generated_lib_header, heir
],
tags = tags,
data = data,
copts = OPENMP_COPTS,
linkopts = OPENFHE_LINKOPTS,
**kwargs
)

0 comments on commit 1c42eb8

Please sign in to comment.