Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dlopen: now trying "libcufile.so.1", "libcufile.so.0", "libcufile.so" #141

Merged
merged 2 commits into from
Oct 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cpp/include/kvikio/shim/cufile.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class cuFileAPI {
private:
cuFileAPI()
{
void* lib = load_library("libcufile.so.1");
void* lib = load_library({"libcufile.so.1", "libcufile.so.0", "libcufile.so"});
get_symbol(HandleRegister, lib, KVIKIO_STRINGIFY(cuFileHandleRegister));
get_symbol(HandleDeregister, lib, KVIKIO_STRINGIFY(cuFileHandleDeregister));
get_symbol(Read, lib, KVIKIO_STRINGIFY(cuFileRead));
Expand Down
22 changes: 22 additions & 0 deletions cpp/include/kvikio/shim/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
#include <dlfcn.h>
#include <sys/utsname.h>
#include <filesystem>
#include <sstream>
#include <vector>

namespace kvikio {

Expand All @@ -38,6 +40,26 @@ inline void* load_library(const char* name, int mode = RTLD_LAZY | RTLD_LOCAL |
return ret;
}

/**
* @brief Load shared library
*
* @param names Vector of names to try when loading shared library.
* @return The library handle.
*/
inline void* load_library(const std::vector<const char*>& names,
int mode = RTLD_LAZY | RTLD_LOCAL | RTLD_NODELETE)
{
std::stringstream ss;
for (const char* name : names) {
ss << name << " ";
try {
return load_library(name);
} catch (const std::runtime_error&) {
}
}
throw std::runtime_error("cannot open shared object file, tried: " + ss.str());
}

/**
* @brief Get symbol using `dlsym`
*
Expand Down