From 403fb5d5dfd9849671afc34ae3dda69120ff9a8a Mon Sep 17 00:00:00 2001 From: Tianyu Liu Date: Thu, 10 Oct 2024 00:18:53 -0400 Subject: [PATCH] Special treatment of Grace Hopper on the choice of default env var --- cpp/include/cudf/io/config_utils.hpp | 5 +++ cpp/src/io/utilities/config_utils.cpp | 45 ++++++++++++++++++++++----- 2 files changed, 43 insertions(+), 7 deletions(-) diff --git a/cpp/include/cudf/io/config_utils.hpp b/cpp/include/cudf/io/config_utils.hpp index 1827ba0e3e6..5b4393540f2 100644 --- a/cpp/include/cudf/io/config_utils.hpp +++ b/cpp/include/cudf/io/config_utils.hpp @@ -35,6 +35,11 @@ bool is_gds_enabled(); */ bool is_kvikio_enabled(); +/** + * @brief Returns true if the system is Grace Hopper + */ +bool is_using_grace_hopper(); + } // namespace io::cufile_integration namespace io::nvcomp_integration { diff --git a/cpp/src/io/utilities/config_utils.cpp b/cpp/src/io/utilities/config_utils.cpp index a3afbd52896..93dc03da41c 100644 --- a/cpp/src/io/utilities/config_utils.cpp +++ b/cpp/src/io/utilities/config_utils.cpp @@ -17,10 +17,10 @@ #include "getenv_or.hpp" #include +#include #include #include -#include #include namespace cudf::io { @@ -38,12 +38,21 @@ enum class usage_policy : uint8_t { OFF, GDS, ALWAYS, KVIKIO }; */ usage_policy get_env_policy() { - static auto const env_val = getenv_or("LIBCUDF_CUFILE_POLICY", "KVIKIO"); - if (env_val == "OFF") return usage_policy::OFF; - if (env_val == "GDS") return usage_policy::GDS; - if (env_val == "ALWAYS") return usage_policy::ALWAYS; - if (env_val == "KVIKIO") return usage_policy::KVIKIO; - CUDF_FAIL("Invalid LIBCUDF_CUFILE_POLICY value: " + env_val); + auto get_policy = [](const std::string& env_val) { + if (env_val == "OFF") return usage_policy::OFF; + if (env_val == "GDS") return usage_policy::GDS; + if (env_val == "ALWAYS") return usage_policy::ALWAYS; + if (env_val == "KVIKIO") return usage_policy::KVIKIO; + CUDF_FAIL("Invalid LIBCUDF_CUFILE_POLICY value: " + env_val); + }; + + if (is_using_grace_hopper()) { + static auto const env_val = getenv_or("LIBCUDF_CUFILE_POLICY", "OFF"); + return get_policy(env_val); + } else { + static auto const env_val = getenv_or("LIBCUDF_CUFILE_POLICY", "KVIKIO"); + return get_policy(env_val); + } } } // namespace @@ -53,6 +62,28 @@ bool is_gds_enabled() { return is_always_enabled() or get_env_policy() == usage_ bool is_kvikio_enabled() { return get_env_policy() == usage_policy::KVIKIO; } +bool is_using_grace_hopper() +{ + int device_idx{}; + CUDF_CUDA_TRY(cudaGetDevice(&device_idx)); + + // Cache the query result to avoid the expensive call to cudaGetDeviceProperties(). + // Key: device index. + // Value: whether the device is a Grace Hopper. + static std::unordered_map memo; + + if (auto search = memo.find(device_idx); search == memo.end()) { + cudaDeviceProp property{}; + CUDF_CUDA_TRY(cudaGetDeviceProperties(&property, device_idx)); + auto* substr_exists = std::strstr(property.name, "GH200"); + bool result{substr_exists != nullptr}; + memo[device_idx] = result; + return result; + } else { + return search->second; + } +} + } // namespace cufile_integration namespace nvcomp_integration {