From 99a7ef3098557f5d9aeec7d7554c7e5d887b4524 Mon Sep 17 00:00:00 2001 From: Yuval Shekel Date: Tue, 27 Aug 2024 19:26:48 +0300 Subject: [PATCH] skip libraries that do not seem to be icicle backend libs --- icicle/include/icicle/msm.h | 12 ++++++------ icicle/src/runtime.cpp | 24 +++++++++++++++++++++--- 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/icicle/include/icicle/msm.h b/icicle/include/icicle/msm.h index 834fe8d525..90cf530249 100644 --- a/icicle/include/icicle/msm.h +++ b/icicle/include/icicle/msm.h @@ -29,12 +29,12 @@ namespace icicle { * the MSM problem. Larger value means more on-line memory footprint but also more parallelism and less * computational complexity (up to a certain point). Default value: 0 (the optimal value of \f$ c \f$ is * chosen automatically). */ - int bitsize; /**< Number of bits of the largest scalar. Typically equals the bitsize of scalar field, - * but if a different (better) upper bound is known, it should be reflected in this variable. - * Default value: 0 (set to the bitsize of scalar field). */ - int batch_size; /**< Number of MSMs to compute. Default value: 1. */ - bool are_bases_shared; /**< Bases are shared for batch. Set to true if all MSMs use the same bases. Otherwise, the number - of bases and number of scalars are expected to be equal. Default value: true. */ + int bitsize; /**< Number of bits of the largest scalar. Typically equals the bitsize of scalar field, + * but if a different (better) upper bound is known, it should be reflected in this variable. + * Default value: 0 (set to the bitsize of scalar field). */ + int batch_size; /**< Number of MSMs to compute. Default value: 1. */ + bool are_bases_shared; /**< Bases are shared for batch. Set to true if all MSMs use the same bases. Otherwise, the + number of bases and number of scalars are expected to be equal. Default value: true. */ bool are_scalars_on_device; /**< True if scalars are on device, false if they're on host. Default value: false. */ bool are_scalars_montgomery_form; /**< True if scalars are in Montgomery form, false otherwise. Default value: true. */ diff --git a/icicle/src/runtime.cpp b/icicle/src/runtime.cpp index ce36de773c..f0e3d00637 100644 --- a/icicle/src/runtime.cpp +++ b/icicle/src/runtime.cpp @@ -274,9 +274,27 @@ extern "C" eIcicleError icicle_load_backend(const char* path, bool is_recursive) }; auto load_library = [](const char* filePath) { - ICICLE_LOG_DEBUG << "Attempting load: " << filePath; - void* handle = dlopen(filePath, RTLD_LAZY | RTLD_GLOBAL); - if (!handle) { ICICLE_LOG_ERROR << "Failed to load " << filePath << ": " << dlerror(); } + // Convert the file path to a std::string for easier manipulation + std::string path(filePath); + + // Extract the library name from the full path + std::string fileName = path.substr(path.find_last_of("/\\") + 1); + + // Check if the library name contains "icicle" and if the path contains "/backend/" + if (fileName.find("icicle") == std::string::npos || path.find("/backend/") == std::string::npos) { + ICICLE_LOG_INFO << "Skipping: " << filePath << " - Not an Icicle backend library."; + return; + } + + // Check if the library name contains "device". If yes, load it with GLOBAL visibility, otherwise LOCAL. + // The logic behind it is to avoid symbol conflicts by using LOCAL visibility but allow backends to expose symbols to the other backend libs. + // For example to reuse some device context or any initialization required by APIs that we want to do once. + int flags = (fileName.find("device") != std::string::npos) ? (RTLD_LAZY | RTLD_GLOBAL) : (RTLD_LAZY | RTLD_LOCAL); + + // Attempt to load the library with the appropriate flags + ICICLE_LOG_INFO << "Attempting to load: " << filePath; + void* handle = dlopen(filePath, flags); + if (!handle) { ICICLE_LOG_INFO << "Failed to load " << filePath << ": " << dlerror(); } }; if (is_directory(path)) {