From 063d563e5e3b10125579f7df34fe44beb8cd54d6 Mon Sep 17 00:00:00 2001 From: "Mads R. B. Kristensen" Date: Thu, 27 Oct 2022 08:58:40 +0200 Subject: [PATCH 1/2] dlopen: now trying "libcufile.so.1", "libcufile.so.0", "libcufile.so" --- cpp/include/kvikio/shim/cufile.hpp | 2 +- cpp/include/kvikio/shim/utils.hpp | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/cpp/include/kvikio/shim/cufile.hpp b/cpp/include/kvikio/shim/cufile.hpp index a9976fb915..d0cd56fbcd 100644 --- a/cpp/include/kvikio/shim/cufile.hpp +++ b/cpp/include/kvikio/shim/cufile.hpp @@ -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)); diff --git a/cpp/include/kvikio/shim/utils.hpp b/cpp/include/kvikio/shim/utils.hpp index 4dda66ff21..bcf6f450b7 100644 --- a/cpp/include/kvikio/shim/utils.hpp +++ b/cpp/include/kvikio/shim/utils.hpp @@ -18,6 +18,7 @@ #include #include #include +#include namespace kvikio { @@ -38,6 +39,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& 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` * From 267efbcf4ae1e40581e647b2c458f14f7f014e52 Mon Sep 17 00:00:00 2001 From: "Mads R. B. Kristensen" Date: Thu, 27 Oct 2022 09:02:00 +0200 Subject: [PATCH 2/2] added #include --- cpp/include/kvikio/shim/utils.hpp | 1 + 1 file changed, 1 insertion(+) diff --git a/cpp/include/kvikio/shim/utils.hpp b/cpp/include/kvikio/shim/utils.hpp index bcf6f450b7..2a500db20c 100644 --- a/cpp/include/kvikio/shim/utils.hpp +++ b/cpp/include/kvikio/shim/utils.hpp @@ -18,6 +18,7 @@ #include #include #include +#include #include namespace kvikio {