-
Notifications
You must be signed in to change notification settings - Fork 65
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
Adjust the way of determining FileHandle's compatibility mode for sync and async I/O to improve code readability #608
Open
kingcrimsontianyu
wants to merge
7
commits into
rapidsai:branch-25.04
Choose a base branch
from
kingcrimsontianyu:simplify-compat-mode-impl
base: branch-25.04
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
736e8c3
Solve rebase conflict
kingcrimsontianyu 617463a
Make copy default
kingcrimsontianyu f00f0d4
Address review comments
kingcrimsontianyu be63409
Fix the ill-formed problem by giving compat mode manager a default ctor
kingcrimsontianyu 6ca9c8b
Add comments. Minor adjustment
kingcrimsontianyu 8b6ca7b
Tweak comment format
kingcrimsontianyu 790c40e
Address review comments
kingcrimsontianyu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
/* | ||
* Copyright (c) 2025, NVIDIA CORPORATION. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <cstdint> | ||
#include <string> | ||
|
||
#include <kvikio/file_utils.hpp> | ||
|
||
namespace kvikio { | ||
/** | ||
* @brief I/O compatibility mode. | ||
*/ | ||
enum class CompatMode : uint8_t { | ||
OFF, ///< Enforce cuFile I/O. GDS will be activated if the system requirements for cuFile are met | ||
///< and cuFile is properly configured. However, if the system is not suited for cuFile, I/O | ||
///< operations under the OFF option may error out. | ||
ON, ///< Enforce POSIX I/O. | ||
AUTO, ///< Try cuFile I/O first, and fall back to POSIX I/O if the system requirements for cuFile | ||
///< are not met. | ||
}; | ||
|
||
namespace detail { | ||
/** | ||
* @brief Parse a string into a CompatMode enum. | ||
* | ||
* @param compat_mode_str Compatibility mode in string format (case-insensitive). Valid values | ||
* include: | ||
* - `ON` (alias: `TRUE`, `YES`, `1`) | ||
* - `OFF` (alias: `FALSE`, `NO`, `0`) | ||
* - `AUTO` | ||
* @return A CompatMode enum. | ||
*/ | ||
CompatMode parse_compat_mode_str(std::string_view compat_mode_str); | ||
|
||
} // namespace detail | ||
|
||
// Forward declaration. | ||
class FileHandle; | ||
|
||
/** | ||
* @brief Store and manage the compatibility mode data associated with a FileHandle. | ||
*/ | ||
class CompatModeManager { | ||
private: | ||
CompatMode _compat_mode_requested{CompatMode::AUTO}; | ||
bool _is_compat_mode_preferred{true}; | ||
bool _is_compat_mode_preferred_for_async{true}; | ||
|
||
public: | ||
/** | ||
* @brief Construct an empty compatibility mode manager. | ||
*/ | ||
CompatModeManager() noexcept = default; | ||
|
||
/** | ||
* @brief Construct a compatibility mode manager associated with a FileHandle. | ||
* | ||
* According to the file path, requested compatibility mode, and the system configuration, the | ||
* compatibility manager: | ||
* - Infers the final compatibility modes for synchronous and asynchronous I/O paths, | ||
* respectively. | ||
* - Initializes the file wrappers and cuFile handle associated with a FileHandle. | ||
* | ||
* @param file_path Refer to | ||
* FileHandle::FileHandle(std::string const&, std::string const&, mode_t, CompatMode). | ||
* @param flags Same as above. | ||
* @param mode Same as above. | ||
* @param compat_mode_requested Same as above. | ||
* @param file_handle Point to the FileHandle object that owns this compatibility mode manager. | ||
*/ | ||
CompatModeManager(std::string const& file_path, | ||
std::string const& flags, | ||
mode_t mode, | ||
CompatMode compat_mode_requested, | ||
FileHandle* file_handle); | ||
|
||
~CompatModeManager() noexcept = default; | ||
CompatModeManager(const CompatModeManager&) = default; | ||
CompatModeManager& operator=(const CompatModeManager&) = default; | ||
CompatModeManager(CompatModeManager&&) noexcept = default; | ||
CompatModeManager& operator=(CompatModeManager&&) noexcept = default; | ||
|
||
/** | ||
* @brief Functionally identical to defaults::infer_compat_mode_if_auto(CompatMode). | ||
* | ||
* @param compat_mode Compatibility mode. | ||
* @return If the given compatibility mode is CompatMode::AUTO, infer the final compatibility | ||
* mode. | ||
*/ | ||
CompatMode infer_compat_mode_if_auto(CompatMode compat_mode) noexcept; | ||
|
||
/** | ||
* @brief Functionally identical to defaults::is_compat_mode_preferred(CompatMode). | ||
* | ||
* @param compat_mode Compatibility mode. | ||
* @return Boolean answer. | ||
*/ | ||
bool is_compat_mode_preferred(CompatMode compat_mode) noexcept; | ||
|
||
/** | ||
* @brief Check if the compatibility mode for synchronous I/O of the associated FileHandle is | ||
* expected to be CompatMode::ON. | ||
* | ||
* @return Boolean answer. | ||
*/ | ||
bool is_compat_mode_preferred() const noexcept; | ||
|
||
/** | ||
* @brief Check if the compatibility mode for asynchronous I/O of the associated FileHandle is | ||
* expected to be CompatMode::ON. | ||
* | ||
* @return Boolean answer. | ||
*/ | ||
bool is_compat_mode_preferred_for_async() const noexcept; | ||
|
||
/** | ||
* @brief Retrieve the original compatibility mode requested. | ||
* | ||
* @return The original compatibility mode requested. | ||
*/ | ||
CompatMode compat_mode_requested() const noexcept; | ||
|
||
/** | ||
* @brief Determine if the asynchronous I/O can be performed or not (throw exceptions) | ||
* according to the existing compatibility mode data in the manager. | ||
* | ||
* The asynchronous I/O cannot be performed, for instance, when compat_mode_requested() is | ||
* CompatMode::OFF, is_compat_mode_preferred() is CompatMode::OFF, but | ||
* is_compat_mode_preferred_for_async() is CompatMode::ON (due to missing cuFile stream API or | ||
* cuFile configuration file). | ||
*/ | ||
void validate_compat_mode_for_async() const; | ||
}; | ||
|
||
} // namespace kvikio |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Docs of
CompatModeManager
would be goodThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure! Will do!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.