Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Forward-merge branch-24.08 into branch-24.10 #415

Merged
merged 1 commit into from
Jul 24, 2024
Merged
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
14 changes: 13 additions & 1 deletion cpp/include/kvikio/file_handle.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <iostream>
#include <numeric>
#include <optional>
#include <stdexcept>
#include <system_error>
#include <utility>

Expand All @@ -47,6 +48,9 @@ namespace detail {
* @param flags The flags
* @param o_direct Append O_DIRECT to the open flags
* @return oflags
*
* @throw std::invalid_argument if the specified flags are not supported.
* @throw std::invalid_argument if `o_direct` is true, but `O_DIRECT` is not supported.
*/
inline int open_fd_parse_flags(const std::string& flags, bool o_direct)
{
Expand All @@ -66,7 +70,13 @@ inline int open_fd_parse_flags(const std::string& flags, bool o_direct)
default: throw std::invalid_argument("Unknown file open flag");
}
file_flags |= O_CLOEXEC;
if (o_direct) { file_flags |= O_DIRECT; }
if (o_direct) {
#if defined(O_DIRECTT)
file_flags |= O_DIRECT;
#else
throw std::invalid_argument("'o_direct' flag unsupported on this platform");
#endif
}
return file_flags;
}

Expand Down Expand Up @@ -173,6 +183,8 @@ class FileHandle {
_fd_direct_on = detail::open_fd(file_path, flags, true, mode);
} catch (const std::system_error&) {
_compat_mode = true;
} catch (const std::invalid_argument&) {
_compat_mode = true;
}

// Create a cuFile handle, if not in compatibility mode
Expand Down