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  * https://apache.ac.cn/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
存储和管理与 FileHandle 相关的兼容模式数据。
CompatMode compat_mode_requested() const noexcept
检索原始请求的兼容模式。
bool is_compat_mode_preferred_for_async() const noexcept
检查关联 FileHandle 的异步 I/O 兼容模式是否应为 C...
CompatMode infer_compat_mode_if_auto(CompatMode compat_mode) noexcept
功能上等同于 defaults::infer_compat_mode_if_auto(CompatMode)。
bool is_compat_mode_preferred() const noexcept
检查关联 FileHandle 的同步 I/O 兼容模式是否应为 Co...
CompatModeManager() noexcept=default
构造一个空的兼容模式管理器。
void validate_compat_mode_for_async() const
根据现有的兼容模式确定是否可以执行异步 I/O(或抛出异常)。
已向 cufile 注册的打开文件的句柄。
KvikIO 命名空间。
定义: batch.hpp:27
CompatMode
I/O 兼容模式。
@ ON
强制使用 POSIX I/O。