From 521a88b9c0aed317af78a4689ed080f6f88d502b Mon Sep 17 00:00:00 2001 From: "Mads R. B. Kristensen" Date: Tue, 23 Jul 2024 08:37:11 +0200 Subject: [PATCH 1/2] Don't open with `O_DIRECT` when in compat mode --- cpp/include/kvikio/file_handle.hpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/cpp/include/kvikio/file_handle.hpp b/cpp/include/kvikio/file_handle.hpp index 7def2c2b4b..f51a411e82 100644 --- a/cpp/include/kvikio/file_handle.hpp +++ b/cpp/include/kvikio/file_handle.hpp @@ -164,10 +164,12 @@ class FileHandle { _initialized{true}, _compat_mode{compat_mode} { - try { - _fd_direct_on = detail::open_fd(file_path, flags, true, mode); - } catch (const std::system_error&) { - _compat_mode = true; // Fall back to compat mode if we cannot open the file with O_DIRECT + if (!_compat_mode) { + try { + _fd_direct_on = detail::open_fd(file_path, flags, true, mode); + } catch (const std::system_error&) { + _compat_mode = true; // Fall back to compat mode if we cannot open the file with O_DIRECT + } } if (!_compat_mode) { From 86c424bf90f670b7ae7bb0c280bfb6923e7a338d Mon Sep 17 00:00:00 2001 From: "Mads R. B. Kristensen" Date: Tue, 23 Jul 2024 09:08:27 +0200 Subject: [PATCH 2/2] cleanup --- cpp/include/kvikio/file_handle.hpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/cpp/include/kvikio/file_handle.hpp b/cpp/include/kvikio/file_handle.hpp index f51a411e82..2f467b5d0d 100644 --- a/cpp/include/kvikio/file_handle.hpp +++ b/cpp/include/kvikio/file_handle.hpp @@ -165,13 +165,17 @@ class FileHandle { _compat_mode{compat_mode} { if (!_compat_mode) { - try { - _fd_direct_on = detail::open_fd(file_path, flags, true, mode); - } catch (const std::system_error&) { - _compat_mode = true; // Fall back to compat mode if we cannot open the file with O_DIRECT - } + return; // Nothing to do in compatibility mode } + // Try to open the file with the O_DIRECT flag. Fall back to compatibility mode, if it fails. + try { + _fd_direct_on = detail::open_fd(file_path, flags, true, mode); + } catch (const std::system_error&) { + _compat_mode = true; + } + + // Create a cuFile handle, if not in compatibility mode if (!_compat_mode) { CUfileDescr_t desc{}; // It is important to set to zero! desc.type = CU_FILE_HANDLE_TYPE_OPAQUE_FD;