Skip to content

Commit

Permalink
Apply noexcept for compat mode-related functions wherever application
Browse files Browse the repository at this point in the history
  • Loading branch information
kingcrimsontianyu committed Jan 21, 2025
1 parent 1251210 commit 19a6ef1
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 23 deletions.
4 changes: 2 additions & 2 deletions cpp/include/kvikio/defaults.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ class defaults {
* (`ON`/`OFF`/`AUTO`) to two (`ON`/`OFF`) so as to determine the actual I/O path. This function
* is lightweight as the inferred result is cached.
*/
static CompatMode infer_compat_mode_if_auto(CompatMode compat_mode);
static CompatMode infer_compat_mode_if_auto(CompatMode compat_mode) noexcept;

/**
* @brief Given a requested compatibility mode, whether it is expected to reduce to `ON`.
Expand All @@ -156,7 +156,7 @@ class defaults {
* @param compat_mode Compatibility mode.
* @return Boolean answer.
*/
static bool is_compat_mode_preferred(CompatMode compat_mode);
static bool is_compat_mode_preferred(CompatMode compat_mode) noexcept;

/**
* @brief Whether the global compatibility mode from class defaults is expected to be `ON`.
Expand Down
10 changes: 5 additions & 5 deletions cpp/include/kvikio/shim/cufile.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,9 @@ class cuFileAPI {
* @return The boolean answer
*/
#ifdef KVIKIO_CUFILE_FOUND
bool is_cufile_library_available();
bool is_cufile_library_available() noexcept;
#else
constexpr bool is_cufile_library_available() { return false; }
constexpr bool is_cufile_library_available() noexcept { return false; }
#endif

/**
Expand All @@ -115,7 +115,7 @@ constexpr bool is_cufile_library_available() { return false; }
*
* @return The boolean answer
*/
bool is_cufile_available();
bool is_cufile_available() noexcept;

/**
* @brief Get cufile version (or zero if older than v1.8).
Expand All @@ -129,9 +129,9 @@ bool is_cufile_available();
* @return The version (1000*major + 10*minor) or zero if older than 1080.
*/
#ifdef KVIKIO_CUFILE_FOUND
int cufile_version();
int cufile_version() noexcept;
#else
constexpr int cufile_version() { return 0; }
constexpr int cufile_version() noexcept { return 0; }
#endif

/**
Expand Down
4 changes: 2 additions & 2 deletions cpp/include/kvikio/shim/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ void get_symbol(T& handle, void* lib, const char* name)
*
* @return The boolean answer
*/
[[nodiscard]] bool is_running_in_wsl();
[[nodiscard]] bool is_running_in_wsl() noexcept;

/**
* @brief Check if `/run/udev` is readable
Expand All @@ -91,6 +91,6 @@ void get_symbol(T& handle, void* lib, const char* name)
*
* @return The boolean answer
*/
[[nodiscard]] bool run_udev_readable();
[[nodiscard]] bool run_udev_readable() noexcept;

} // namespace kvikio
4 changes: 2 additions & 2 deletions cpp/src/defaults.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ CompatMode defaults::compat_mode() { return instance()->_compat_mode; }

void defaults::compat_mode_reset(CompatMode compat_mode) { instance()->_compat_mode = compat_mode; }

CompatMode defaults::infer_compat_mode_if_auto(CompatMode compat_mode)
CompatMode defaults::infer_compat_mode_if_auto(CompatMode compat_mode) noexcept
{
if (compat_mode == CompatMode::AUTO) {
static auto inferred_compat_mode_for_auto = []() -> CompatMode {
Expand All @@ -154,7 +154,7 @@ CompatMode defaults::infer_compat_mode_if_auto(CompatMode compat_mode)
return compat_mode;
}

bool defaults::is_compat_mode_preferred(CompatMode compat_mode)
bool defaults::is_compat_mode_preferred(CompatMode compat_mode) noexcept
{
return compat_mode == CompatMode::ON ||
(compat_mode == CompatMode::AUTO &&
Expand Down
6 changes: 3 additions & 3 deletions cpp/src/shim/cufile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ void cuFileAPI::driver_close()
}

#ifdef KVIKIO_CUFILE_FOUND
bool is_cufile_library_available()
bool is_cufile_library_available() noexcept
{
try {
cuFileAPI::instance();
Expand All @@ -134,13 +134,13 @@ bool is_cufile_library_available()
}
#endif

bool is_cufile_available()
bool is_cufile_available() noexcept
{
return is_cufile_library_available() && run_udev_readable() && !is_running_in_wsl();
}

#ifdef KVIKIO_CUFILE_FOUND
int cufile_version()
int cufile_version() noexcept
{
try {
return cuFileAPI::instance().version;
Expand Down
22 changes: 13 additions & 9 deletions cpp/src/shim/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,23 @@ void* load_library(const std::vector<const char*>& names, int mode)
throw std::runtime_error("cannot open shared object file, tried: " + ss.str());
}

bool is_running_in_wsl()
bool is_running_in_wsl() noexcept
{
struct utsname buf {};
int err = ::uname(&buf);
if (err == 0) {
const std::string name(static_cast<char*>(buf.release));
// 'Microsoft' for WSL1 and 'microsoft' for WSL2
return name.find("icrosoft") != std::string::npos;
try {
struct utsname buf {};
int err = ::uname(&buf);
if (err == 0) {
const std::string name(static_cast<char*>(buf.release));
// 'Microsoft' for WSL1 and 'microsoft' for WSL2
return name.find("icrosoft") != std::string::npos;
}
return false;
} catch (...) {
return false;
}
return false;
}

bool run_udev_readable()
bool run_udev_readable() noexcept
{
try {
return std::filesystem::is_directory("/run/udev");
Expand Down

0 comments on commit 19a6ef1

Please sign in to comment.