diff --git a/compiler/include/concretelang/Runtime/context.h b/compiler/include/concretelang/Runtime/context.h index 9274dc1e3..1bd4edf9d 100644 --- a/compiler/include/concretelang/Runtime/context.h +++ b/compiler/include/concretelang/Runtime/context.h @@ -8,7 +8,7 @@ #include #include -#include +#include extern "C" { #include "concrete-ffi.h" @@ -20,53 +20,23 @@ namespace concretelang { typedef struct RuntimeContext { LweKeyswitchKey_u64 *ksk; LweBootstrapKey_u64 *bsk; -#ifdef CONCRETELANG_PARALLEL_EXECUTION_ENABLED - std::map engines; + std::map engines; std::mutex engines_map_guard; -#else - Engine *engine; -#endif - RuntimeContext() -#ifndef CONCRETELANG_PARALLEL_EXECUTION_ENABLED - : engine(nullptr) -#endif - { - } + RuntimeContext() {} // Ensure that the engines map is not copied - RuntimeContext(const RuntimeContext &ctx) - : ksk(ctx.ksk), bsk(ctx.bsk) -#ifndef CONCRETELANG_PARALLEL_EXECUTION_ENABLED - , - engine(nullptr) -#endif - { - } + RuntimeContext(const RuntimeContext &ctx) : ksk(ctx.ksk), bsk(ctx.bsk) {} RuntimeContext(const RuntimeContext &&other) - : ksk(other.ksk), bsk(other.bsk) -#ifndef CONCRETELANG_PARALLEL_EXECUTION_ENABLED - , - engine(nullptr) -#endif - { - } + : ksk(other.ksk), bsk(other.bsk) {} ~RuntimeContext() { -#ifdef CONCRETELANG_PARALLEL_EXECUTION_ENABLED for (const auto &key : engines) { free_engine(key.second); } -#else - if (engine != nullptr) - free_engine(engine); -#endif } RuntimeContext &operator=(const RuntimeContext &rhs) { ksk = rhs.ksk; bsk = rhs.bsk; -#ifndef CONCRETELANG_PARALLEL_EXECUTION_ENABLED - engine = nullptr; -#endif return *this; } } RuntimeContext; diff --git a/compiler/lib/Runtime/CMakeLists.txt b/compiler/lib/Runtime/CMakeLists.txt index 8c95b67e7..286677bce 100644 --- a/compiler/lib/Runtime/CMakeLists.txt +++ b/compiler/lib/Runtime/CMakeLists.txt @@ -4,6 +4,10 @@ add_library(ConcretelangRuntime SHARED dfr_terminate.cpp ) +if (NOT ${CMAKE_SYSTEM_NAME} MATCHES "Darwin") + link_libraries(-Wl,--no-as-needed omp) +endif() + if(CONCRETELANG_PARALLEL_EXECUTION_ENABLED) add_library(DFRuntime SHARED DFRuntime.cpp) target_link_libraries(DFRuntime PUBLIC pthread m dl HPX::hpx HPX::iostreams_component -rdynamic) @@ -21,9 +25,9 @@ if(CONCRETELANG_PARALLEL_EXECUTION_ENABLED) -Wl,--no-as-needed DFRuntime omp - ) + ) else() - target_link_libraries(ConcretelangRuntime Concrete pthread m dl $) + target_link_libraries(ConcretelangRuntime Concrete pthread m dl $ omp) endif() install(TARGETS ConcretelangRuntime omp EXPORT ConcretelangRuntime) diff --git a/compiler/lib/Runtime/context.cpp b/compiler/lib/Runtime/context.cpp index e51df477b..a524a140a 100644 --- a/compiler/lib/Runtime/context.cpp +++ b/compiler/lib/Runtime/context.cpp @@ -7,10 +7,6 @@ #include #include -#ifdef CONCRETELANG_PARALLEL_EXECUTION_ENABLED -#include -#endif - LweKeyswitchKey_u64 * get_keyswitch_key_u64(mlir::concretelang::RuntimeContext *context) { return context->ksk; @@ -23,20 +19,15 @@ get_bootstrap_key_u64(mlir::concretelang::RuntimeContext *context) { // Instantiate one engine per thread on demand Engine *get_engine(mlir::concretelang::RuntimeContext *context) { -#ifdef CONCRETELANG_PARALLEL_EXECUTION_ENABLED - std::string threadName = hpx::get_thread_name(); + pthread_t threadId = pthread_self(); std::lock_guard guard(context->engines_map_guard); - auto engineIt = context->engines.find(threadName); + auto engineIt = context->engines.find(threadId); if (engineIt == context->engines.end()) { engineIt = context->engines - .insert(std::pair(threadName, new_engine())) + .insert(std::pair(threadId, new_engine())) .first; } assert(engineIt->second && "No engine available in context"); return engineIt->second; -#else - return (context->engine == nullptr) ? context->engine = new_engine() - : context->engine; -#endif }