Skip to content

Commit

Permalink
Only load versioned libcufile (#548)
Browse files Browse the repository at this point in the history
Fixes the `dlopen` logic around `libcufile` to load either the SOVERSION library or the fully versioned library. This includes logic to handle the missing SOVERSION library on older CUDA versions. Drops loading the stub library, which typically only shows up in development environments.

<hr>

Fixes #504

Borrows from PR ( rapidsai/cudf#13210 ) and PR ( rapidsai/kvikio#203 ). Also adapts this logic to cuCIM ( rapidsai/kvikio#141 )

Authors:
  - https://github.com/jakirkham
  - Gregory Lee (https://github.com/grlee77)

Approvers:
  - Bradley Dice (https://github.com/bdice)
  - Gregory Lee (https://github.com/grlee77)
  - Gigon Bae (https://github.com/gigony)

URL: #548
  • Loading branch information
jakirkham authored Apr 27, 2023
1 parent 2a562c1 commit 8cbbe8f
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
20 changes: 20 additions & 0 deletions cpp/include/cucim/dynlib/helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "../macros/defines.h"

#include <string>
#include <vector>

#if CUCIM_PLATFORM_LINUX
# include <dlfcn.h>
Expand Down Expand Up @@ -74,6 +75,25 @@ inline LibraryHandle load_library(const char* library_name, int mode = -1)
#endif
}

inline LibraryHandle load_library(const std::vector<const char*>& names,
int mode = -1)
{
#if CUCIM_PLATFORM_LINUX
LibraryHandle handle_ = nullptr;
for (const char* name : names)
{
handle_= load_library(name, mode);
if (handle_ != nullptr)
{
return handle_;
}
}
return nullptr;
#else
# error "This platform is not supported!"
#endif
}

inline std::string get_last_load_library_error()
{
#if CUCIM_PLATFORM_LINUX
Expand Down
18 changes: 16 additions & 2 deletions gds/src/cufile_stub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,23 @@ void CuFileStub::load()
#if !CUCIM_STATIC_GDS
if (handle_ == nullptr)
{
// Note: Load the dynamic library with RTLD_NODELETE flag because libcufile.so uses therad_local which can
// Note: Load the dynamic library with RTLD_NODELETE flag because libcufile.so uses thread_local which can
// cause a segmentation fault if the library is dynamically loaded/unloaded. (See #158)
handle_ = cucim::dynlib::load_library("libcufile.so", RTLD_LAZY | RTLD_LOCAL | RTLD_NODELETE);
// CUDA versions before CUDA 11.7.1 did not ship libcufile.so.0, so this is
// a workaround that adds support for all prior versions of libcufile.
handle_ = cucim::dynlib::load_library(
{
"libcufile.so.0",
"libcufile.so.1.3.0" /* 11.7.0 */,
"libcufile.so.1.2.1" /* 11.6.2, 11.6.1 */,
"libcufile.so.1.2.0" /* 11.6.0 */,
"libcufile.so.1.1.1" /* 11.5.1 */,
"libcufile.so.1.1.0" /* 11.5.0 */,
"libcufile.so.1.0.2" /* 11.4.4, 11.4.3, 11.4.2 */,
"libcufile.so.1.0.1" /* 11.4.1 */,
"libcufile.so.1.0.0" /* 11.4.0 */
},
RTLD_LAZY | RTLD_LOCAL | RTLD_NODELETE);
if (handle_ == nullptr)
{
return;
Expand Down

0 comments on commit 8cbbe8f

Please sign in to comment.