Src/GPUPerfAPIHSA/GPUPerfAPIHSA.cpp
/// Sets the necessary environment variable to enable the HSA runtime Tools lib
/// \return true on success
Sets the necessary environment variable to enable the HSA runtime Tools lib
\return true on success
Sets the necessary environment variable to enable the HSA runtime Tools lib \ return true on success
bool SetHSAToolsLibEnvVar()
{
    bool retVal = false;
    static const char* szHSAToolsLibEnvVar = "HSA_TOOLS_LIB";
    std::string thisLib;
#ifdef _WIN32
    std::string toolsLibVal = "hsa-runtime-tools64.dll";
#else
    std::string toolsLibVal = "libhsa-runtime-tools64.so.1";
#endif
#ifdef _WIN32
    char szEnvVarVal[MAX_PATH] = { 0 };
    GetEnvironmentVariable(szHSAToolsLibEnvVar, szEnvVarVal, MAX_PATH);
    toolsLibVal = szEnvVarVal;
    char szThisModuleName[MAX_PATH] = { 0 };
    retVal = 0 != GetModuleFileName(HINST_THISCOMPONENT, szThisModuleName, MAX_PATH);
    if (retVal)
    {
        if (!toolsLibVal.empty())
        {
            toolsLibVal.append(" ");
        }
        toolsLibVal.append(szThisModuleName);
        retVal = 0 != SetEnvironmentVariable(szHSAToolsLibEnvVar, toolsLibVal.c_str());
    }
#else
    char* szEnvVarVal = getenv(szHSAToolsLibEnvVar);
    if (nullptr != szEnvVarVal)
    {
        toolsLibVal = szEnvVarVal;
    }
    Dl_info dlInfo;
    retVal = 0 != dladdr(reinterpret_cast<void*>(SetHSAToolsLibEnvVar), &dlInfo);
    if (retVal)
    {
        if (!toolsLibVal.empty())
        {
            toolsLibVal.append(" ");
        }
        toolsLibVal.append(dlInfo.dli_fname);
        retVal = 0 == setenv(szHSAToolsLibEnvVar, toolsLibVal.c_str(), 1);
    }
#endif
    return retVal;
}
bool SetHSAToolsLibEnvVar ( ) { bool retVal = false ; static const char * szHSAToolsLibEnvVar = " " ; std :: string thisLib ; #ifdef _WIN32 std :: string toolsLibVal = " " ; #else std :: string toolsLibVal = " " ; #endif #ifdef _WIN32 char szEnvVarVal [ MAX_PATH ] = { 0 } ; GetEnvironmentVariable ( szHSAToolsLibEnvVar , szEnvVarVal , MAX_PATH ) ; toolsLibVal = szEnvVarVal ; char szThisModuleName [ MAX_PATH ] = { 0 } ; retVal = 0 != GetModuleFileName ( HINST_THISCOMPONENT , szThisModuleName , MAX_PATH ) ; if ( retVal ) { if ( ! toolsLibVal . empty ( ) ) { toolsLibVal . append ( " " ) ; } toolsLibVal . append ( szThisModuleName ) ; retVal = 0 != SetEnvironmentVariable ( szHSAToolsLibEnvVar , toolsLibVal . c_str ( ) ) ; } #else char * szEnvVarVal = getenv ( szHSAToolsLibEnvVar ) ; if ( nullptr != szEnvVarVal ) { toolsLibVal = szEnvVarVal ; } Dl_info dlInfo ; retVal = 0 != dladdr ( reinterpret_cast < void * > ( SetHSAToolsLibEnvVar ) , & dlInfo ) ; if ( retVal ) { if ( ! toolsLibVal . empty ( ) ) { toolsLibVal . append ( " " ) ; } toolsLibVal . append ( dlInfo . dli_fname ) ; retVal = 0 == setenv ( szHSAToolsLibEnvVar , toolsLibVal . c_str ( ) , 1 ) ; } #endif return retVal ; }
Sets the necessary environment variable to enable the HSA runtime Tools lib
\return true on success
Sets the necessary environment variable to enable the HSA runtime Tools lib \ return true on success