Skip to content

Commit

Permalink
dlopen: now trying "libcufile.so.1", "libcufile.so.0", "libcufile.so" (
Browse files Browse the repository at this point in the history
…#141)

Fixes #140

Authors:
  - Mads R. B. Kristensen (https://github.com/madsbk)

Approvers:
  - Benjamin Zaitlen (https://github.com/quasiben)

URL: #141
  • Loading branch information
madsbk committed Oct 28, 2022
1 parent 7b4bee7 commit b0c6ced
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
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

0 comments on commit b0c6ced

Please sign in to comment.