Skip to content

Commit

Permalink
Minor fix
Browse files Browse the repository at this point in the history
  • Loading branch information
kingcrimsontianyu committed Feb 1, 2025
1 parent bfdf3fe commit 4e0c305
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion cpp/include/kvikio/file_handle.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class FileWrapper {

public:
/**
* @brief Open file using `open(2)`.
* @brief Open file.
*
* @param file_path File path.
* @param flags Open flags given as a string.
Expand Down
14 changes: 7 additions & 7 deletions cpp/src/file_handle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,9 @@ FileHandle::FileHandle(std::string const& file_path,

// For the AUTO mode, if the first cuFile API call fails, fall back to the compatibility
// mode.
if (compat_mode_requested() == CompatMode::AUTO && !_handle.registered()) {
if (compat_mode_requested() == CompatMode::AUTO && error_code.value().err != CU_FILE_SUCCESS) {
_is_compat_mode_preferred = true;
} else { // OFF mode
} else {
CUFILE_TRY(error_code.value());
}

Expand Down Expand Up @@ -502,10 +502,7 @@ void FileWrapper::close() noexcept

int FileWrapper::fd() const noexcept { return _fd; }

CUFileHandleWrapper::~CUFileHandleWrapper()
{
if (_registered) { cuFileAPI::instance().HandleDeregister(_handle); }
}
CUFileHandleWrapper::~CUFileHandleWrapper() { unregister_handle(); }

CUFileHandleWrapper::CUFileHandleWrapper(CUFileHandleWrapper&& o) noexcept
: _handle{std::exchange(o._handle, {})}, _registered{std::exchange(o._registered, false)}
Expand Down Expand Up @@ -540,7 +537,10 @@ CUfileHandle_t CUFileHandleWrapper::handle() const noexcept { return _handle; }

void CUFileHandleWrapper::unregister_handle() noexcept
{
if (registered()) { cuFileAPI::instance().HandleDeregister(_handle); }
if (registered()) {
cuFileAPI::instance().HandleDeregister(_handle);
_registered = false;
}
}

} // namespace kvikio

0 comments on commit 4e0c305

Please sign in to comment.