diff --git a/cpp/include/kvikio/file_handle.hpp b/cpp/include/kvikio/file_handle.hpp index 79a782c654..95bbdcf0dd 100644 --- a/cpp/include/kvikio/file_handle.hpp +++ b/cpp/include/kvikio/file_handle.hpp @@ -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. diff --git a/cpp/src/file_handle.cpp b/cpp/src/file_handle.cpp index 313909eac3..7670e055a9 100644 --- a/cpp/src/file_handle.cpp +++ b/cpp/src/file_handle.cpp @@ -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()); } @@ -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)} @@ -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