All Classes Namespaces Functions Enumerations Enumerator Modules Pages
compat_mode.hpp
1 /*
2  * Copyright (c) 2025, NVIDIA CORPORATION.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #pragma once
18 
19 #include <cstdint>
20 #include <string>
21 
22 #include <kvikio/file_utils.hpp>
23 
24 namespace kvikio {
28 enum class CompatMode : uint8_t {
29  OFF,
32  ON,
33  AUTO,
35 };
36 
37 namespace detail {
48 CompatMode parse_compat_mode_str(std::string_view compat_mode_str);
49 
50 } // namespace detail
51 
52 // Forward declaration.
53 class FileHandle;
54 
59  private:
60  CompatMode _compat_mode_requested{CompatMode::AUTO};
61  bool _is_compat_mode_preferred{true};
62  bool _is_compat_mode_preferred_for_async{true};
63 
64  public:
68  CompatModeManager() noexcept = default;
69 
86  CompatModeManager(std::string const& file_path,
87  std::string const& flags,
88  mode_t mode,
90  FileHandle* file_handle);
91 
92  ~CompatModeManager() noexcept = default;
93  CompatModeManager(const CompatModeManager&) = default;
94  CompatModeManager& operator=(const CompatModeManager&) = default;
95  CompatModeManager(CompatModeManager&&) noexcept = default;
96  CompatModeManager& operator=(CompatModeManager&&) noexcept = default;
97 
106 
113  bool is_compat_mode_preferred(CompatMode compat_mode) noexcept;
114 
121  bool is_compat_mode_preferred() const noexcept;
122 
129  bool is_compat_mode_preferred_for_async() const noexcept;
130 
137 
148 };
149 
150 } // namespace kvikio
Store and manage the compatibility mode data associated with a FileHandle.
Definition: compat_mode.hpp:58
CompatMode compat_mode_requested() const noexcept
Retrieve the original compatibility mode requested.
bool is_compat_mode_preferred_for_async() const noexcept
Check if the compatibility mode for asynchronous I/O of the associated FileHandle is expected to be C...
CompatMode infer_compat_mode_if_auto(CompatMode compat_mode) noexcept
Functionally identical to defaults::infer_compat_mode_if_auto(CompatMode).
bool is_compat_mode_preferred() const noexcept
Check if the compatibility mode for synchronous I/O of the associated FileHandle is expected to be Co...
CompatModeManager() noexcept=default
Construct an empty compatibility mode manager.
void validate_compat_mode_for_async() const
Determine if asynchronous I/O can be performed or not (throw exceptions) according to the existing co...
Handle of an open file registered with cufile.
Definition: file_handle.hpp:47
KvikIO namespace.
Definition: batch.hpp:27
CompatMode
I/O compatibility mode.
Definition: compat_mode.hpp:28
@ ON
Enforce POSIX I/O.