Skip to content

Commit

Permalink
Rename a compat mode function according to reviewer suggestion
Browse files Browse the repository at this point in the history
  • Loading branch information
kingcrimsontianyu committed Nov 19, 2024
1 parent d332da4 commit 64490d2
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 26 deletions.
4 changes: 2 additions & 2 deletions cpp/examples/basic_io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ int main()
check(cudaSetDevice(0) == cudaSuccess);

cout << "KvikIO defaults: " << endl;
if (kvikio::defaults::is_compat_mode_expected()) {
if (kvikio::defaults::is_compat_mode_preferred()) {
cout << " Compatibility mode: enabled" << endl;
} else {
kvikio::DriverInitializer manual_init_driver;
Expand Down Expand Up @@ -181,7 +181,7 @@ int main()
cout << "Parallel POSIX read (" << kvikio::defaults::thread_pool_nthreads()
<< " threads): " << read << endl;
}
if (kvikio::is_batch_and_stream_available() && !kvikio::defaults::is_compat_mode_expected()) {
if (kvikio::is_batch_and_stream_available() && !kvikio::defaults::is_compat_mode_preferred()) {
std::cout << std::endl;
Timer timer;
// Here we use the batch API to read "/tmp/test-file" into `b_dev` by
Expand Down
2 changes: 1 addition & 1 deletion cpp/examples/basic_no_cuda.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ constexpr int LARGE_SIZE = 8 * SIZE; // LARGE SIZE to test partial s
int main()
{
cout << "KvikIO defaults: " << endl;
if (kvikio::defaults::is_compat_mode_expected()) {
if (kvikio::defaults::is_compat_mode_preferred()) {
cout << " Compatibility mode: enabled" << endl;
} else {
kvikio::DriverInitializer manual_init_driver;
Expand Down
2 changes: 1 addition & 1 deletion cpp/include/kvikio/batch.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ class BatchHandle {
std::vector<CUfileIOParams_t> io_batch_params;
io_batch_params.reserve(operations.size());
for (const auto& op : operations) {
if (op.file_handle.is_compat_mode_expected()) {
if (op.file_handle.is_compat_mode_preferred()) {
throw CUfileException("Cannot submit a FileHandle opened in compatibility mode");
}

Expand Down
4 changes: 2 additions & 2 deletions cpp/include/kvikio/buffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ inline void buffer_register(const void* devPtr_base,
int flags = 0,
const std::vector<int>& errors_to_ignore = std::vector<int>())
{
if (defaults::is_compat_mode_expected()) { return; }
if (defaults::is_compat_mode_preferred()) { return; }
CUfileError_t status = cuFileAPI::instance().BufRegister(devPtr_base, size, flags);
if (status.err != CU_FILE_SUCCESS) {
// Check if `status.err` is in `errors_to_ignore`
Expand All @@ -67,7 +67,7 @@ inline void buffer_register(const void* devPtr_base,
*/
inline void buffer_deregister(const void* devPtr_base)
{
if (defaults::is_compat_mode_expected()) { return; }
if (defaults::is_compat_mode_preferred()) { return; }
CUFILE_TRY(cuFileAPI::instance().BufDeregister(devPtr_base));
}

Expand Down
4 changes: 2 additions & 2 deletions cpp/include/kvikio/defaults.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ class defaults {
* @param compat_mode Compatibility mode.
* @return Boolean answer.
*/
static bool is_compat_mode_expected(CompatMode compat_mode)
static bool is_compat_mode_preferred(CompatMode compat_mode)
{
if (compat_mode == CompatMode::ON ||
(compat_mode == CompatMode::AUTO &&
Expand All @@ -284,7 +284,7 @@ class defaults {
*
* @return Boolean answer.
*/
static bool is_compat_mode_expected() { return is_compat_mode_expected(compat_mode()); }
static bool is_compat_mode_preferred() { return is_compat_mode_preferred(compat_mode()); }

/**
* @brief Get the default thread pool.
Expand Down
32 changes: 16 additions & 16 deletions cpp/include/kvikio/file_handle.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ class FileHandle {
* @exception std::runtime_error When the requested compatibility mode is `OFF`, but cuFile
* batch/stream library symbol is missing, or cuFile configuration file is missing.
*/
bool is_compat_mode_expected_for_async(CompatMode requested_compat_mode)
bool is_compat_mode_preferred_for_async(CompatMode requested_compat_mode)
{
if (!defaults::is_compat_mode_expected(requested_compat_mode)) {
if (!defaults::is_compat_mode_preferred(requested_compat_mode)) {
if (!is_batch_and_stream_available()) {
if (requested_compat_mode == CompatMode::AUTO) { return true; }
throw std::runtime_error("Missing cuFile batch or stream library symbol.");
Expand Down Expand Up @@ -146,7 +146,7 @@ class FileHandle {
{
if (closed()) { return; }

if (!is_compat_mode_expected()) { cuFileAPI::instance().HandleDeregister(_handle); }
if (!is_compat_mode_preferred()) { cuFileAPI::instance().HandleDeregister(_handle); }
_compat_mode = CompatMode::AUTO;
::close(_fd_direct_off);
if (_fd_direct_on != -1) { ::close(_fd_direct_on); }
Expand All @@ -159,14 +159,14 @@ class FileHandle {
* @brief Get the underlying cuFile file handle
*
* The file handle must be open and not in compatibility mode i.e.
* both `closed()` and `is_compat_mode_expected()` must be false.
* both `closed()` and `is_compat_mode_preferred()` must be false.
*
* @return cuFile's file handle
*/
[[nodiscard]] CUfileHandle_t handle()
{
if (closed()) { throw CUfileException("File handle is closed"); }
if (is_compat_mode_expected()) {
if (is_compat_mode_preferred()) {
throw CUfileException("The underlying cuFile handle isn't available in compatibility mode");
}
return _handle;
Expand Down Expand Up @@ -239,7 +239,7 @@ class FileHandle {
std::size_t devPtr_offset,
bool sync_default_stream = true)
{
if (is_compat_mode_expected()) {
if (is_compat_mode_preferred()) {
return detail::posix_device_read(
_fd_direct_off, devPtr_base, size, file_offset, devPtr_offset);
}
Expand Down Expand Up @@ -291,7 +291,7 @@ class FileHandle {
{
_nbytes = 0; // Invalidate the computed file size

if (is_compat_mode_expected()) {
if (is_compat_mode_preferred()) {
return detail::posix_device_write(
_fd_direct_off, devPtr_base, size, file_offset, devPtr_offset);
}
Expand Down Expand Up @@ -370,7 +370,7 @@ class FileHandle {
}

// Let's synchronize once instead of in each task.
if (sync_default_stream && !is_compat_mode_expected()) {
if (sync_default_stream && !is_compat_mode_preferred()) {
PushAndPopContext c(ctx);
CUDA_DRIVER_TRY(cudaAPI::instance().StreamSynchronize(nullptr));
}
Expand Down Expand Up @@ -447,7 +447,7 @@ class FileHandle {
}

// Let's synchronize once instead of in each task.
if (sync_default_stream && !is_compat_mode_expected()) {
if (sync_default_stream && !is_compat_mode_preferred()) {
PushAndPopContext c(ctx);
CUDA_DRIVER_TRY(cudaAPI::instance().StreamSynchronize(nullptr));
}
Expand Down Expand Up @@ -506,7 +506,7 @@ class FileHandle {
ssize_t* bytes_read_p,
CUstream stream)
{
if (is_compat_mode_expected_for_async(_compat_mode)) {
if (is_compat_mode_preferred_for_async(_compat_mode)) {
CUDA_DRIVER_TRY(cudaAPI::instance().StreamSynchronize(stream));
*bytes_read_p =
static_cast<ssize_t>(read(devPtr_base, *size_p, *file_offset_p, *devPtr_offset_p));
Expand Down Expand Up @@ -596,7 +596,7 @@ class FileHandle {
ssize_t* bytes_written_p,
CUstream stream)
{
if (is_compat_mode_expected_for_async(_compat_mode)) {
if (is_compat_mode_preferred_for_async(_compat_mode)) {
CUDA_DRIVER_TRY(cudaAPI::instance().StreamSynchronize(stream));
*bytes_written_p =
static_cast<ssize_t>(write(devPtr_base, *size_p, *file_offset_p, *devPtr_offset_p));
Expand Down Expand Up @@ -653,9 +653,9 @@ class FileHandle {
*
* @return Boolean answer.
*/
[[nodiscard]] bool is_compat_mode_expected() const noexcept
[[nodiscard]] bool is_compat_mode_preferred() const noexcept
{
return defaults::is_compat_mode_expected(_compat_mode);
return defaults::is_compat_mode_preferred(_compat_mode);
}

/**
Expand All @@ -664,15 +664,15 @@ class FileHandle {
*
* For asynchronous I/O, the compatibility mode can be automatically enabled if the cuFile batch
* and stream symbols are missing, or if the cuFile configuration file is missing, or if
* `is_compat_mode_expected()` returns true.
* `is_compat_mode_preferred()` returns true.
*
* @return Boolean answer.
*/
[[nodiscard]] bool is_compat_mode_expected_for_async() const noexcept
[[nodiscard]] bool is_compat_mode_preferred_for_async() const noexcept
{
static bool is_extra_symbol_available = is_batch_and_stream_available();
static bool is_config_path_empty = config_path().empty();
return is_compat_mode_expected() || !is_extra_symbol_available || is_config_path_empty;
return is_compat_mode_preferred() || !is_extra_symbol_available || is_config_path_empty;
}
};

Expand Down
4 changes: 2 additions & 2 deletions cpp/src/file_handle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ FileHandle::FileHandle(const std::string& file_path,
_initialized{true},
_compat_mode{compat_mode}
{
if (is_compat_mode_expected()) {
if (is_compat_mode_preferred()) {
return; // Nothing to do in compatibility mode
}

Expand All @@ -138,7 +138,7 @@ FileHandle::FileHandle(const std::string& file_path,
}

// Create a cuFile handle, if not in compatibility mode
if (!is_compat_mode_expected()) {
if (!is_compat_mode_preferred()) {
CUfileDescr_t desc{}; // It is important to set to zero!
desc.type = CU_FILE_HANDLE_TYPE_OPAQUE_FD;
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-union-access)
Expand Down

0 comments on commit 64490d2

Please sign in to comment.