This repository has been archived by the owner on Apr 30, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
GPUPerfAPIRegistry.cpp
executable file
·103 lines (87 loc) · 2.63 KB
/
GPUPerfAPIRegistry.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
//==============================================================================
// Copyright (c) 2016 Advanced Micro Devices, Inc. All rights reserved.
/// \author AMD Developer Tools Team
/// \file
/// \brief Functions for setting driver-specific registry keys or env variables
/// to enable perf counter collection
//==============================================================================
#include "GPUPerfAPIRegistry.h"
#include <iostream>
#ifdef _WIN32
#include <windows.h>
#include <atlbase.h>
#include <atlstr.h>
#endif // _WIN32
#ifdef _WIN32
static const LPCTSTR HSA_SOFTCP_ENV_VAR_NAME = _T("HSA_EMULATE_AQL");
static const LPCTSTR HSA_SOFTCP_ENV_VAR_VALUE = _T("1");
#else
static const char* HSA_SOFTCP_ENV_VAR_NAME = "HSA_EMULATE_AQL";
static const char* HSA_SOFTCP_ENV_VAR_VALUE = "1";
#endif
bool SetHSASoftCPEnvVar(bool shouldPrintDbgMsg, std::string& strErrorMsg)
{
bool retVal = true;
#ifdef _WIN32
BOOL result = SetEnvironmentVariable(HSA_SOFTCP_ENV_VAR_NAME, HSA_SOFTCP_ENV_VAR_VALUE);
retVal = (TRUE == result);
#else
int result = setenv(HSA_SOFTCP_ENV_VAR_NAME, HSA_SOFTCP_ENV_VAR_VALUE, 1);
retVal = (0 == result);
#endif
if (!retVal)
{
strErrorMsg = "Error: Unable to enable HSA Performance Counters in Driver";
}
else
{
strErrorMsg = "Successfully enabled HSA Performance Counters in Driver";
}
if (shouldPrintDbgMsg)
{
std::cout << strErrorMsg << std::endl;
}
return retVal;
}
bool SetHSASoftCPEnvVar(bool shouldPrintDbgMsg)
{
std::string strErrorMsg;
return SetHSASoftCPEnvVar(shouldPrintDbgMsg, strErrorMsg);
}
bool SetHSASoftCPEnvVar(std::string& strErrorMsg)
{
return SetHSASoftCPEnvVar(false, strErrorMsg);
}
bool UnsetHSASoftCPEnvVar(bool shouldPrintDbgMsg, std::string strErrorMsg)
{
bool retVal = true;
#ifdef _WIN32
BOOL result = SetEnvironmentVariable(HSA_SOFTCP_ENV_VAR_NAME, NULL);
retVal = (TRUE == result);
#else
int result = unsetenv(HSA_SOFTCP_ENV_VAR_NAME);
retVal = (0 == result);
#endif
if (!retVal)
{
strErrorMsg = "Error: Unable to disable HSA Performance Counters in Driver";
}
else
{
strErrorMsg = "Successfully disabled HSA Performance Counters in Driver";
}
if (shouldPrintDbgMsg)
{
std::cout << strErrorMsg << std::endl;
}
return retVal;
}
bool UnsetHSASoftCPEnvVar(bool shouldPrintDbgMsg)
{
std::string strErrorMsg;
return UnsetHSASoftCPEnvVar(shouldPrintDbgMsg, strErrorMsg);
}
bool UnsetHSASoftCPEnvVar(std::string& strErrorMsg)
{
return UnsetHSASoftCPEnvVar(false, strErrorMsg);
}