Skip to content

Commit

Permalink
Remove inline. Move getenv_or outside the detail namespace. Add noexc…
Browse files Browse the repository at this point in the history
…ept to dtor
  • Loading branch information
kingcrimsontianyu committed Jan 9, 2025
1 parent 07ad349 commit 688ceed
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 26 deletions.
2 changes: 1 addition & 1 deletion cpp/include/kvikio/cufile/driver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class DriverInitializer {
DriverInitializer(DriverInitializer&&) noexcept = delete;
DriverInitializer& operator=(DriverInitializer&&) noexcept = delete;

~DriverInitializer();
~DriverInitializer() noexcept;
};

class DriverProperties {
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 @@ -57,6 +57,8 @@ namespace detail {
*/
CompatMode parse_compat_mode_str(std::string_view compat_mode_str);

} // namespace detail

template <typename T>
T getenv_or(std::string_view env_var_name, T default_val)
{
Expand All @@ -79,8 +81,6 @@ bool getenv_or(std::string_view env_var_name, bool default_val);
template <>
CompatMode getenv_or(std::string_view env_var_name, CompatMode default_val);

} // namespace detail

/**
* @brief Singleton class of default values used throughout KvikIO.
*
Expand Down
2 changes: 1 addition & 1 deletion cpp/include/kvikio/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ constexpr bool is_host_memory(const void* ptr) { return true; }
* @param ordinal Device ordinal - an integer between 0 and the number of CUDA devices
* @return Primary CUDA context
*/
[[nodiscard]] KVIKIO_EXPORT inline CUcontext get_primary_cuda_context(int ordinal);
[[nodiscard]] KVIKIO_EXPORT CUcontext get_primary_cuda_context(int ordinal);

/**
* @brief Return the CUDA context associated the given device pointer, if any.
Expand Down
2 changes: 1 addition & 1 deletion cpp/src/cufile/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
namespace kvikio {
namespace {

[[nodiscard]] inline const char* lookup_config_path()
[[nodiscard]] const char* lookup_config_path()
{
const char* env = std::getenv("CUFILE_ENV_PATH_JSON");
if (env != nullptr && std::filesystem::exists(env)) { return env; }
Expand Down
6 changes: 3 additions & 3 deletions cpp/src/cufile/driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@
namespace kvikio {
namespace {

[[nodiscard]] inline bool get_driver_flag(unsigned int prop, unsigned int flag) noexcept
[[nodiscard]] bool get_driver_flag(unsigned int prop, unsigned int flag) noexcept
{
return (prop & (1U << flag)) != 0;
}

inline void set_driver_flag(unsigned int& prop, unsigned int flag, bool val) noexcept
void set_driver_flag(unsigned int& prop, unsigned int flag, bool val) noexcept
{
if (val) {
prop |= (1U << flag);
Expand All @@ -44,7 +44,7 @@ inline void set_driver_flag(unsigned int& prop, unsigned int flag, bool val) noe

DriverInitializer::DriverInitializer() { cuFileAPI::instance().driver_open(); }

DriverInitializer::~DriverInitializer()
DriverInitializer::~DriverInitializer() noexcept
{
try {
cuFileAPI::instance().driver_close();
Expand Down
20 changes: 10 additions & 10 deletions cpp/src/defaults.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,10 @@ CompatMode parse_compat_mode_str(std::string_view compat_mode_str)
return res;
}

} // namespace detail

template <>
inline bool getenv_or(std::string_view env_var_name, bool default_val)
bool getenv_or(std::string_view env_var_name, bool default_val)
{
const auto* env_val = std::getenv(env_var_name.data());
if (env_val == nullptr) { return default_val; }
Expand Down Expand Up @@ -82,18 +84,16 @@ inline bool getenv_or(std::string_view env_var_name, bool default_val)
}

template <>
inline CompatMode getenv_or(std::string_view env_var_name, CompatMode default_val)
CompatMode getenv_or(std::string_view env_var_name, CompatMode default_val)
{
auto* env_val = std::getenv(env_var_name.data());
if (env_val == nullptr) { return default_val; }
return parse_compat_mode_str(env_val);
return detail::parse_compat_mode_str(env_val);
}

} // namespace detail

unsigned int defaults::get_num_threads_from_env()
{
const int ret = detail::getenv_or("KVIKIO_NTHREADS", 1);
const int ret = getenv_or("KVIKIO_NTHREADS", 1);
if (ret <= 0) {
throw std::invalid_argument("KVIKIO_NTHREADS has to be a positive integer greater than zero");
}
Expand All @@ -104,11 +104,11 @@ defaults::defaults()
{
// Determine the default value of `compat_mode`
{
_compat_mode = detail::getenv_or("KVIKIO_COMPAT_MODE", CompatMode::AUTO);
_compat_mode = getenv_or("KVIKIO_COMPAT_MODE", CompatMode::AUTO);
}
// Determine the default value of `task_size`
{
const ssize_t env = detail::getenv_or("KVIKIO_TASK_SIZE", 4 * 1024 * 1024);
const ssize_t env = getenv_or("KVIKIO_TASK_SIZE", 4 * 1024 * 1024);
if (env <= 0) {
throw std::invalid_argument(
"KVIKIO_TASK_SIZE has to be a positive integer greater than zero");
Expand All @@ -117,15 +117,15 @@ defaults::defaults()
}
// Determine the default value of `gds_threshold`
{
const ssize_t env = detail::getenv_or("KVIKIO_GDS_THRESHOLD", 1024 * 1024);
const ssize_t env = getenv_or("KVIKIO_GDS_THRESHOLD", 1024 * 1024);
if (env < 0) {
throw std::invalid_argument("KVIKIO_GDS_THRESHOLD has to be a positive integer");
}
_gds_threshold = env;
}
// Determine the default value of `bounce_buffer_size`
{
const ssize_t env = detail::getenv_or("KVIKIO_BOUNCE_BUFFER_SIZE", 16 * 1024 * 1024);
const ssize_t env = getenv_or("KVIKIO_BOUNCE_BUFFER_SIZE", 16 * 1024 * 1024);
if (env <= 0) {
throw std::invalid_argument(
"KVIKIO_BOUNCE_BUFFER_SIZE has to be a positive integer greater than zero");
Expand Down
10 changes: 2 additions & 8 deletions cpp/src/remote_handle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -299,10 +299,7 @@ struct CallbackContext {
* @param nmemb Size of the data in `nmemb`.
* @param context A pointer to an instance of `CallbackContext`.
*/
inline std::size_t callback_host_memory(char* data,
std::size_t size,
std::size_t nmemb,
void* context)
std::size_t callback_host_memory(char* data, std::size_t size, std::size_t nmemb, void* context)
{
auto ctx = reinterpret_cast<CallbackContext*>(context);
std::size_t const nbytes = size * nmemb;
Expand All @@ -326,10 +323,7 @@ inline std::size_t callback_host_memory(char* data,
* @param nmemb Size of the data in `nmemb`.
* @param context A pointer to an instance of `CallbackContext`.
*/
inline std::size_t callback_device_memory(char* data,
std::size_t size,
std::size_t nmemb,
void* context)
std::size_t callback_device_memory(char* data, std::size_t size, std::size_t nmemb, void* context)
{
auto ctx = reinterpret_cast<CallbackContext*>(context);
std::size_t const nbytes = size * nmemb;
Expand Down

0 comments on commit 688ceed

Please sign in to comment.