From d93455395086ec9903a28d1db5902042b383093f Mon Sep 17 00:00:00 2001 From: Quentin Bourgerie Date: Fri, 14 Oct 2022 17:48:43 +0200 Subject: [PATCH] feat(compiler/gpu): Integrate gpu crypto optimization --- compiler/concrete-optimizer | 2 +- compiler/include/concretelang/Support/V0Parameters.h | 12 +++++++++--- compiler/lib/Support/CompilerEngine.cpp | 4 ++++ compiler/lib/Support/V0Parameters.cpp | 1 + 4 files changed, 15 insertions(+), 4 deletions(-) diff --git a/compiler/concrete-optimizer b/compiler/concrete-optimizer index 1f15162b3..a4a1f4b11 160000 --- a/compiler/concrete-optimizer +++ b/compiler/concrete-optimizer @@ -1 +1 @@ -Subproject commit 1f15162b39103f5a3bf08dff4e4c4a3ac410b755 +Subproject commit a4a1f4b112033c96f8a3b5c9d5664415e5b0de8f diff --git a/compiler/include/concretelang/Support/V0Parameters.h b/compiler/include/concretelang/Support/V0Parameters.h index a6d03d08e..1d51201ac 100644 --- a/compiler/include/concretelang/Support/V0Parameters.h +++ b/compiler/include/concretelang/Support/V0Parameters.h @@ -23,6 +23,7 @@ constexpr uint DEFAULT_SECURITY = 128; constexpr uint DEFAULT_FALLBACK_LOG_NORM_WOPPBS = 8; constexpr bool DEFAULT_DISPLAY = false; constexpr bool DEFAULT_STARTEGY_V0 = false; +constexpr bool DEFAULT_USE_GPU_CONSTRAINTS = false; struct Config { double p_error; @@ -31,11 +32,16 @@ struct Config { bool strategy_v0; std::uint64_t security; double fallback_log_norm_woppbs; + bool use_gpu_constraints; }; -constexpr Config DEFAULT_CONFIG = { - UNSPECIFIED_P_ERROR, NO_GLOBAL_P_ERROR, DEFAULT_DISPLAY, - DEFAULT_STARTEGY_V0, DEFAULT_SECURITY, DEFAULT_FALLBACK_LOG_NORM_WOPPBS}; +constexpr Config DEFAULT_CONFIG = {UNSPECIFIED_P_ERROR, + NO_GLOBAL_P_ERROR, + DEFAULT_DISPLAY, + DEFAULT_STARTEGY_V0, + DEFAULT_SECURITY, + DEFAULT_FALLBACK_LOG_NORM_WOPPBS, + DEFAULT_USE_GPU_CONSTRAINTS}; using Dag = rust::Box; using Solution = concrete_optimizer::v0::Solution; diff --git a/compiler/lib/Support/CompilerEngine.cpp b/compiler/lib/Support/CompilerEngine.cpp index 85ac53261..10386fde7 100644 --- a/compiler/lib/Support/CompilerEngine.cpp +++ b/compiler/lib/Support/CompilerEngine.cpp @@ -198,6 +198,10 @@ llvm::Error CompilerEngine::determineFHEParameters(CompilationResult &res) { return llvm::Error::success(); } CompilationFeedback feedback; + // Make sure to use the gpu constraint of the optimizer if we use gpu + // backend. + compilerOptions.optimizerConfig.use_gpu_constraints = + compilerOptions.emitGPUOps; auto v0Params = getParameter(descr.get().value(), feedback, compilerOptions.optimizerConfig); if (auto err = v0Params.takeError()) { diff --git a/compiler/lib/Support/V0Parameters.cpp b/compiler/lib/Support/V0Parameters.cpp index 2da7de4d4..43afeef25 100644 --- a/compiler/lib/Support/V0Parameters.cpp +++ b/compiler/lib/Support/V0Parameters.cpp @@ -28,6 +28,7 @@ concrete_optimizer::Options options_from_config(optimizer::Config config) { options.security_level = config.security; options.maximum_acceptable_error_probability = config.p_error; options.default_log_norm2_woppbs = config.fallback_log_norm_woppbs; + options.use_gpu_constraints = config.use_gpu_constraints; return options; }