"git@developer.sourcefind.cn:OpenDAS/TransformerEngine.git" did not exist on "94ba75d7f470a412a5d4f3cea3728792f49b38f7"
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) { ...@@ -98,7 +98,7 @@ const std::string &include_directory(bool required) {
{"", "/usr/local/cuda"}}; {"", "/usr/local/cuda"}};
for (auto &[env, p] : search_paths) { for (auto &[env, p] : search_paths) {
if (p.empty()) { if (p.empty()) {
p = getenv<Path>(env); p = getenv<Path>(env.c_str());
} }
if (!p.empty()) { if (!p.empty()) {
if (file_exists(p / "cuda_runtime.h")) { if (file_exists(p / "cuda_runtime.h")) {
......
...@@ -20,9 +20,9 @@ namespace { ...@@ -20,9 +20,9 @@ namespace {
template <typename T> template <typename T>
inline typename std::enable_if<std::is_arithmetic<T>::value, T>::type 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 // Implementation for numeric types
const char *env = std::getenv(variable.c_str()); const char *env = std::getenv(variable);
if (env == nullptr || env[0] == '\0') { if (env == nullptr || env[0] == '\0') {
return default_value; return default_value;
} }
...@@ -35,9 +35,9 @@ getenv_helper(const std::string &variable, const T &default_value) { ...@@ -35,9 +35,9 @@ getenv_helper(const std::string &variable, const T &default_value) {
template <typename T> template <typename T>
inline typename std::enable_if<!std::is_arithmetic<T>::value, T>::type 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 // 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') { if (env == nullptr || env[0] == '\0') {
return default_value; return default_value;
} else { } else {
...@@ -48,11 +48,11 @@ getenv_helper(const std::string &variable, const T &default_value) { ...@@ -48,11 +48,11 @@ getenv_helper(const std::string &variable, const T &default_value) {
} // namespace } // namespace
#define NVTE_INSTANTIATE_GETENV(T, default_value) \ #define NVTE_INSTANTIATE_GETENV(T, default_value) \
template <> T getenv<T>(const std::string &variable, \ template <> T getenv<T>(const char *variable, \
const T &default_value_) { \ const T &default_value_) { \
return getenv_helper<T>(variable, default_value_); \ return getenv_helper<T>(variable, default_value_); \
} \ } \
template <> T getenv<T>(const std::string &variable) { \ template <> T getenv<T>(const char *variable) { \
return getenv_helper<T>(variable, default_value); \ return getenv_helper<T>(variable, default_value); \
} }
NVTE_INSTANTIATE_GETENV(bool, false); NVTE_INSTANTIATE_GETENV(bool, false);
......
...@@ -19,11 +19,11 @@ namespace transformer_engine { ...@@ -19,11 +19,11 @@ namespace transformer_engine {
* returned. * returned.
*/ */
template <typename T = std::string> template <typename T = std::string>
T getenv(const std::string &variable); T getenv(const char *variable);
/*! \brief Get environment variable and convert to type */ /*! \brief Get environment variable and convert to type */
template <typename T = std::string> 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 */ /*! \brief Check if a file exists and can be read */
bool file_exists(const std::string &path); 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