-
Notifications
You must be signed in to change notification settings - Fork 51
Expand file tree
/
Copy pathGPAHWInfo.cpp
More file actions
289 lines (251 loc) · 8.09 KB
/
GPAHWInfo.cpp
File metadata and controls
289 lines (251 loc) · 8.09 KB
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
//==============================================================================
// Copyright (c) 2016 Advanced Micro Devices, Inc. All rights reserved.
/// \author AMD Developer Tools Team
/// \file
/// \brief A class for managing hardware information
//==============================================================================
#include "GPAHWInfo.h"
#include <assert.h>
#include <DeviceInfoUtils.h>
#include "Logging.h"
#include "Logging.h"
GPA_HWInfo::GPA_HWInfo()
:
m_deviceId(0),
m_deviceIdSet(false),
m_revisionId(0),
m_revisionIdSet(false),
m_vendorId(0),
m_vendorIdSet(false),
m_deviceName(""),
m_deviceNameSet(false),
m_gpuIndex(0),
m_gpuIndexSet(false),
m_generation(GDT_HW_GENERATION_NONE),
m_generationSet(false),
m_timeStampFrequency(1),
m_timeStampFrequencySet(false),
m_asicType(GDT_ASIC_TYPE_NONE),
m_numShaderEngines(0),
m_numSIMDs(0),
m_suClockPrim(0),
m_numPrimPipes(0)
{
}
GPA_HWInfo::~GPA_HWInfo()
{
}
bool GPA_HWInfo::GetDeviceID(gpa_uint32& id)
{
id = m_deviceId;
return m_deviceIdSet;
}
bool GPA_HWInfo::GetRevisionID(gpa_uint32& id)
{
id = m_revisionId;
return m_revisionIdSet;
}
bool GPA_HWInfo::GetVendorID(gpa_uint32& vid)
{
vid = m_vendorId;
return m_vendorIdSet;
}
bool GPA_HWInfo::GetDeviceName(const char*& pName)
{
pName = m_deviceName.c_str();
return m_deviceNameSet;
}
bool GPA_HWInfo::GetGpuIndex(unsigned int& gpuIndex)
{
gpuIndex = m_gpuIndex;
return m_gpuIndexSet;
}
bool GPA_HWInfo::GetHWGeneration(GDT_HW_GENERATION& gen)
{
gen = m_generation;
return m_generationSet;
}
bool GPA_HWInfo::GetHWAsicType(GDT_HW_ASIC_TYPE& type)
{
type = m_asicType;
return m_asicType != GDT_ASIC_TYPE_NONE;
}
void GPA_HWInfo::SetDeviceID(gpa_uint32 id)
{
m_deviceIdSet = true;
m_deviceId = id;
}
void GPA_HWInfo::SetRevisionID(gpa_uint32 id)
{
m_revisionIdSet = true;
m_revisionId = id;
}
void GPA_HWInfo::SetVendorID(gpa_uint32 vid)
{
m_vendorIdSet = true;
m_vendorId = vid;
}
void GPA_HWInfo::SetDeviceName(const char* pName)
{
m_deviceNameSet = true;
m_deviceName = pName;
}
void GPA_HWInfo::SetGpuIndex(const unsigned int gpuIndex)
{
m_gpuIndexSet = true;
m_gpuIndex = gpuIndex;
}
void GPA_HWInfo::SetHWGeneration(GDT_HW_GENERATION generation)
{
m_generationSet = true;
m_generation = generation;
}
void GPA_HWInfo::SetTimeStampFrequency(gpa_uint64 frequency)
{
m_timeStampFrequencySet = true;
m_timeStampFrequency = frequency;
}
//-----------------------------------------------------------------------------
bool GPA_HWInfo::UpdateDeviceInfoBasedOnDeviceID()
{
GDT_GfxCardInfo cardInfo;
if (AMDTDeviceInfoUtils::Instance()->GetDeviceInfo(m_deviceId, m_revisionId, cardInfo))
{
GPA_LogDebugMessage("Found device ID: %X which is generation %d.", cardInfo.m_deviceID, cardInfo.m_generation);
GDT_DeviceInfo deviceInfo;
if (AMDTDeviceInfoUtils::Instance()->GetDeviceInfo(m_deviceId, m_revisionId, deviceInfo))
{
m_numShaderEngines = deviceInfo.m_nNumShaderEngines;
m_numSIMDs = deviceInfo.numberSIMDs();
m_suClockPrim = deviceInfo.m_suClocksPrim;
m_numPrimPipes = deviceInfo.m_nNumPrimPipes;
m_asicType = cardInfo.m_asicType;
SetDeviceName(cardInfo.m_szMarketingName);
SetHWGeneration(cardInfo.m_generation);
return true;
}
}
#if defined(WIN32) && defined(AMDT_INTERNAL)
//only emit an error for AMD devices
if (IsAMD())
{
GPA_LogDebugError("Unrecognized device ID %X", m_deviceId);
GPA_LogError("Unrecognized device ID.");
}
#else
GPA_LogDebugError("Unrecognized device ID %X.", m_deviceId);
GPA_LogError("Unrecognized device ID.");
#endif
return false;
}
bool GPA_HWInfo::UpdateRevisionIdBasedOnDeviceIDAndName()
{
std::vector<GDT_GfxCardInfo> cardList;
if (m_deviceNameSet)
{
if (AMDTDeviceInfoUtils::Instance()->GetAllCardsWithDeviceId(m_deviceId, cardList))
{
for (auto it = cardList.begin(); it != cardList.end(); ++it)
{
string thisMarketingName(it->m_szMarketingName);
if (m_deviceName.find(thisMarketingName) != std::string::npos)
{
SetRevisionID(static_cast<gpa_uint32>(it->m_revID));
return true;
}
}
}
}
SetRevisionID(0);
return false;
}
GPA_Status CompareHwInfo(GPA_HWInfo* pFirst, GPA_HWInfo* pSecond)
{
GPA_Status result = GPA_STATUS_OK;
if ((nullptr == pFirst) || (nullptr == pSecond))
{
result = GPA_STATUS_ERROR_NULL_POINTER;
}
else
{
gpa_uint32 firstVendorId;
if (pFirst->GetVendorID(firstVendorId))
{
gpa_uint32 secondVendorId;
if (pSecond->GetVendorID(secondVendorId))
{
if (firstVendorId != secondVendorId)
{
GPA_LogError("Vendor ID mismatch.");
result = GPA_STATUS_ERROR_FAILED;
}
else
{
if (pFirst->IsAMD() && pSecond->IsAMD())
{
gpa_uint32 firstDeviceId;
if (pFirst->GetDeviceID(firstDeviceId))
{
gpa_uint32 secondDeviceId;
if (pSecond->GetDeviceID(secondDeviceId))
{
if (firstDeviceId != secondDeviceId)
{
GPA_LogError("Device ID mismatch.");
result = GPA_STATUS_ERROR_FAILED;
}
else
{
gpa_uint32 firstRevisionId;
if (pFirst->GetRevisionID(firstRevisionId))
{
gpa_uint32 secondRevisionId;
if (pSecond->GetRevisionID(secondRevisionId))
{
if (firstRevisionId != secondRevisionId)
{
GPA_LogError("Revision ID mismatch.");
result = GPA_STATUS_ERROR_FAILED;
}
}
else
{
GPA_LogError("Failed to get revision ID.");
result = GPA_STATUS_ERROR_FAILED;
}
}
else
{
GPA_LogError("Failed to get revision ID.");
result = GPA_STATUS_ERROR_FAILED;
}
}
}
else
{
GPA_LogError("Failed to get device ID.");
result = GPA_STATUS_ERROR_FAILED;
}
}
else
{
GPA_LogError("Failed to get device ID.");
result = GPA_STATUS_ERROR_FAILED;
}
}
}
}
else
{
GPA_LogError("Failed to get vendor ID.");
result = GPA_STATUS_ERROR_FAILED;
}
}
else
{
GPA_LogError("Failed to get vendor ID.");
result = GPA_STATUS_ERROR_FAILED;
}
}
return result;
}