Unverified Commit bbb22395 authored by Kirthi Shankar Sivamani's avatar Kirthi Shankar Sivamani Committed by GitHub
Browse files

Make transformer_engine::getenv arguments independent of C++ ABI version (#896)



Make transformer_engine::getenv independent of C++ ABI version
Signed-off-by: default avatarKirthi Shankar Sivamani <ksivamani@nvidia.com>
parent 16f3f897
......@@ -98,7 +98,7 @@ const std::string &include_directory(bool required) {
{"", "/usr/local/cuda"}};
for (auto &[env, p] : search_paths) {
if (p.empty()) {
p = getenv<Path>(env);
p = getenv<Path>(env.c_str());
}
if (!p.empty()) {
if (file_exists(p / "cuda_runtime.h")) {
......
......@@ -20,9 +20,9 @@ namespace {
template <typename T>
inline typename std::enable_if<std::is_arithmetic<T>::value, T>::type
getenv_helper(const std::string &variable, const T &default_value) {
getenv_helper(const char *variable, const T &default_value) {
// Implementation for numeric types
const char *env = std::getenv(variable.c_str());
const char *env = std::getenv(variable);
if (env == nullptr || env[0] == '\0') {
return default_value;
}
......@@ -35,9 +35,9 @@ getenv_helper(const std::string &variable, const T &default_value) {
template <typename T>
inline typename std::enable_if<!std::is_arithmetic<T>::value, T>::type
getenv_helper(const std::string &variable, const T &default_value) {
getenv_helper(const char *variable, const T &default_value) {
// Implementation for string-like types
const char *env = std::getenv(variable.c_str());
const char *env = std::getenv(variable);
if (env == nullptr || env[0] == '\0') {
return default_value;
} else {
......@@ -47,13 +47,13 @@ getenv_helper(const std::string &variable, const T &default_value) {
} // namespace
#define NVTE_INSTANTIATE_GETENV(T, default_value) \
template <> T getenv<T>(const std::string &variable, \
const T &default_value_) { \
return getenv_helper<T>(variable, default_value_); \
} \
template <> T getenv<T>(const std::string &variable) { \
return getenv_helper<T>(variable, default_value); \
#define NVTE_INSTANTIATE_GETENV(T, default_value) \
template <> T getenv<T>(const char *variable, \
const T &default_value_) { \
return getenv_helper<T>(variable, default_value_); \
} \
template <> T getenv<T>(const char *variable) { \
return getenv_helper<T>(variable, default_value); \
}
NVTE_INSTANTIATE_GETENV(bool, false);
NVTE_INSTANTIATE_GETENV(float, 0.f);
......
......@@ -19,11 +19,11 @@ namespace transformer_engine {
* returned.
*/
template <typename T = std::string>
T getenv(const std::string &variable);
T getenv(const char *variable);
/*! \brief Get environment variable and convert to type */
template <typename T = std::string>
T getenv(const std::string &variable, const T &default_value);
T getenv(const char *variable, const T &default_value);
/*! \brief Check if a file exists and can be read */
bool file_exists(const std::string &path);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment