Skip to content

Commit

Permalink
skip libraries that do not seem to be icicle backend libs
Browse files Browse the repository at this point in the history
  • Loading branch information
yshekel committed Aug 27, 2024
1 parent 8bc7aec commit 99a7ef3
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 9 deletions.
12 changes: 6 additions & 6 deletions icicle/include/icicle/msm.h
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down
24 changes: 21 additions & 3 deletions icicle/src/runtime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down

0 comments on commit 99a7ef3

Please sign in to comment.