From 6972e6d87ab698bea2be2ff96598633abf24f0b2 Mon Sep 17 00:00:00 2001 From: Ben Sander Date: Wed, 26 Oct 2016 09:41:47 -0500 Subject: [PATCH] Allow HIP_DB to be number or string flags (ie HIP_DB=api+mem+sync) Add callbacks for processing env vars. Change-Id: I4ddf50e2da56b1dae43f50657bc693b07b23c03d [ROCm/hip commit: f5e8090f2f2d812d400c3b6b8f8febdb2a4cb49d] --- projects/hip/src/hip_hcc.cpp | 96 ++++++++++++++++++++++++++++++------ projects/hip/src/hip_hcc.h | 2 +- 2 files changed, 82 insertions(+), 16 deletions(-) diff --git a/projects/hip/src/hip_hcc.cpp b/projects/hip/src/hip_hcc.cpp index 6ea07adb87..3a62f63d0a 100644 --- a/projects/hip/src/hip_hcc.cpp +++ b/projects/hip/src/hip_hcc.cpp @@ -1113,7 +1113,7 @@ void ihipReadEnv_S(std::string *var_ptr, const char *var_name1, const char *var_ } if (env) { - *var_ptr = env; + *static_cast(var_ptr) = env; } if (HIP_PRINT_ENV) { printf ("%-30s = %s : %s\n", var_name1, var_ptr->c_str(), description); @@ -1121,6 +1121,25 @@ void ihipReadEnv_S(std::string *var_ptr, const char *var_name1, const char *var_ } +void ihipReadEnv_Callback(void *var_ptr, const char *var_name1, const char *var_name2, const char *description, std::string (*setterCallback)(void * var_ptr, const char * env)) +{ + char * env = getenv(var_name1); + + // Check second name if first not defined, used to allow HIP_ or CUDA_ env vars. + if ((env == NULL) && strcmp(var_name2, "0")) { + env = getenv(var_name2); + } + + std::string var_string = "TBD"; + if (env) { + var_string = setterCallback(var_ptr, env); + } + if (HIP_PRINT_ENV) { + printf ("%-30s = %s : %s\n", var_name1, var_string.c_str(), description); + } +} + + #if defined (DEBUG) #define READ_ENV_I(_build, _ENV_VAR, _ENV_VAR2, _description) \ @@ -1131,6 +1150,10 @@ void ihipReadEnv_S(std::string *var_ptr, const char *var_name1, const char *var_ if ((_build == release) || (_build == debug) {\ ihipReadEnv_S(&_ENV_VAR, #_ENV_VAR, #_ENV_VAR2, _description);\ }; +#define READ_ENV_C(_build, _ENV_VAR, _ENV_VAR2, _description, _callback) \ + if ((_build == release) || (_build == debug) {\ + ihipReadEnv_Callback(&_ENV_VAR, #_ENV_VAR, #_ENV_VAR2, _description, _callback);\ + }; #else @@ -1143,6 +1166,10 @@ void ihipReadEnv_S(std::string *var_ptr, const char *var_name1, const char *var_ if (_build == release) {\ ihipReadEnv_S(&_ENV_VAR, #_ENV_VAR, #_ENV_VAR2, _description);\ }; +#define READ_ENV_C(_build, _ENV_VAR, _ENV_VAR2, _description, _callback) \ + if (_build == release) {\ + ihipReadEnv_Callback(&_ENV_VAR, #_ENV_VAR, #_ENV_VAR2, _description, _callback);\ + }; #endif @@ -1212,6 +1239,57 @@ void parseTrigger(std::string triggerString, std::vector &profTrigg } } +std::string HIP_DB_string(unsigned db) +{ + std::string dbStr; + bool first=true; + for (int i=0; i (var_ptr); + + std::string e(envVarString); + trim(&e); + if (!e.empty() && isdigit(e.c_str()[0])) { + long int v = strtol(envVarString, NULL, 0); + *var_ptr_int = (int) (v); + } else { + *var_ptr_int = 0; + std::vector tokens; + tokenize(e, '+', &tokens); + for (auto t=tokens.begin(); t!= tokens.end(); t++) { + for (int i=0; ic_str(), dbName[i]._shortName)) { + *var_ptr_int |= (1<