Skip to content
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
5 changes: 3 additions & 2 deletions cpp/src/filesystem/cufile_driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ namespace cucim::filesystem
{
static constexpr unsigned int PAGE_SIZE = 4096;
static constexpr uint64_t DEFAULT_MAX_CACHE_SIZE = 128 << 20; // 128MiB
static CuFileStub s_cufile_stub;
static CuFileDriverInitializer s_cufile_initializer;
thread_local static CuFileDriverCache s_cufile_cache;
Mutex CuFileDriver::driver_mutex_;
Expand Down Expand Up @@ -300,7 +301,7 @@ bool discard_page_cache(const char* file_path)
CuFileDriverInitializer::CuFileDriverInitializer()
{
// Initialize libcufile library
open_cufile_stub();
s_cufile_stub.load();

CUfileError_t status = cuFileDriverOpen();
if (status.err == CU_FILE_SUCCESS)
Expand Down Expand Up @@ -347,7 +348,7 @@ CuFileDriverInitializer::~CuFileDriverInitializer()
}

// Close cufile stub
close_cufile_stub();
s_cufile_stub.unload();
}

CuFileDriverCache::CuFileDriverCache()
Expand Down
14 changes: 12 additions & 2 deletions gds/include/cufile_stub.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,17 @@

#include "cufile.h"

extern "C" void open_cufile_stub();
extern "C" void close_cufile_stub();
#include "cucim/dynlib/helper.h"

class CuFileStub
{
public:
void load();
void unload();
~CuFileStub();

private:
cucim::dynlib::LibraryHandle handle_ = nullptr;
};

#endif // CUCIM_CUFILE_STUB_H
46 changes: 17 additions & 29 deletions gds/src/cufile_stub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,8 @@ static t_cuFileDriverSetMaxCacheSize impl_cuFileDriverSetMaxCacheSize = nullptr;
static t_cuFileDriverSetMaxPinnedMemSize impl_cuFileDriverSetMaxPinnedMemSize = nullptr;


class CuFileStub
void CuFileStub::load()
{
public:
void load()
{
#if !CUCIM_SUPPORT_GDS
return;
#endif
Expand Down Expand Up @@ -83,17 +80,22 @@ class CuFileStub
IMPORT_FUNCTION(handle_, cuFileDriverSetMaxPinnedMemSize);
}
#endif
}
void unload()
{
}
void CuFileStub::unload()
{
#if !CUCIM_SUPPORT_GDS
return;
#endif

#if !CUCIM_STATIC_GDS
if (handle_)
{
cucim::dynlib::unload_library(handle_);
// Do not unload the cufile (GDS) library as libcufile registers a cleanup function with atexit() and
// unloading the library will cause a segfault (calling the cleanup function that doesn't exist anymore).
// Just leave the library loaded.
// See https://github.com/rapidsai/cucim/pull/153

// cucim::dynlib::unload_library(handle_);
handle_ = nullptr;

impl_cuFileDriverOpen = nullptr;
Expand All @@ -112,34 +114,20 @@ class CuFileStub
impl_cuFileDriverSetMaxPinnedMemSize = nullptr;
}
#endif
}
~CuFileStub()
{
// Note: unload() would be called explicitly by CuFileDriverInitializer to unload the shared library after calling
// cuFileDriverClose() in CuFileDriverInitializer::~CuFileDriverInitializer()
// unload();
}

private:
cucim::dynlib::LibraryHandle handle_ = nullptr;
};
}

static CuFileStub g_cufile_stub;
CuFileStub::~CuFileStub()
{
// Note: unload() would be called explicitly by CuFileDriverInitializer to unload the shared library after
// calling cuFileDriverClose() in CuFileDriverInitializer::~CuFileDriverInitializer()
// unload();
}

#if __cplusplus
extern "C"
{
#endif

void open_cufile_stub()
{
g_cufile_stub.load();
}
void close_cufile_stub()
{
g_cufile_stub.unload();
}

#if !CUCIM_STATIC_GDS
CUfileError_t cuFileHandleRegister(CUfileHandle_t* fh, CUfileDescr_t* descr)
{
Expand Down