-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathDeviceInfoUtils.cpp
More file actions
executable file
·442 lines (350 loc) · 12.9 KB
/
DeviceInfoUtils.cpp
File metadata and controls
executable file
·442 lines (350 loc) · 12.9 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
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
//==============================================================================
// Copyright (c) 2010-2026 Advanced Micro Devices, Inc. All rights reserved.
/// @author AMD Developer Tools Team
/// @file
/// @brief Device info utils class.
//==============================================================================
#include <algorithm>
#include <cassert>
#include <string_view>
#include <ranges>
#include "DeviceInfoUtils.h"
namespace
{
AMDTDeviceInfoUtils::DeviceNameTranslatorFunction deviceNameTranslatorFunction = nullptr; ///< The function to call to translate device names.
constexpr unsigned int kGfxToGdtHwGenConversionFactor = 3; ///< Factor to apply when converting between GFX IP version and GDT_HW_GENERATION.
}
bool AMDTDeviceInfoUtils::GetDeviceInfo(uint32_t deviceID, uint32_t revisionID, GDT_DeviceInfo &deviceInfo)
{
auto find_device = [&](GDT_GfxCardInfo const &info)
{
if (info.m_deviceID != deviceID)
{
return false;
}
return (kRevisionIdAny == revisionID || info.m_revID == revisionID);
};
const auto it = std::ranges::find_if(gs_cardInfo, find_device);
const bool found = it != gs_cardInfo.end();
if (found)
{
deviceInfo = GetDeviceInfoForAsicType(it->m_asicType);
}
return found;
}
/// NOTE: this might not return the correct GDT_DeviceInfo instance, since some devices with the same CAL name might have different GDT_DeviceInfo instances
bool AMDTDeviceInfoUtils::GetDeviceInfo(const char *szCALDeviceName, GDT_DeviceInfo &deviceInfo)
{
const std::string strDeviceName = TranslateDeviceName(szCALDeviceName);
auto same_name = [&strDeviceName](GDT_GfxCardInfo const &info)
{ return strDeviceName == info.m_szCALName; };
const auto it = std::ranges::find_if(gs_cardInfo, same_name);
const bool found = it != gs_cardInfo.end();
if (found)
{
deviceInfo = GetDeviceInfoForAsicType(it->m_asicType);
}
return found;
}
[[nodiscard]] std::optional<uint32_t> AMDTDeviceInfoUtils::GetTotalLdsSizeInBytes(const GDT_HW_GENERATION gen, GDT_DeviceInfo const &info)
{
static_assert(GDT_HW_GENERATION_LAST == 15, "Update this function!");
// Anything less than GFX9 is not supported.
if (gen < GDT_HW_GENERATION_GFX9)
{
return std::nullopt;
}
// GFX9 to GFX12 all have the same amount of LDS bytes per CU.
if (gen < GDT_HW_GENERATION_CDNA4)
{
constexpr uint32_t kLdsBytesPerCu = 64 * 1024;
return info.numberCUs() * kLdsBytesPerCu;
}
if(gen == GDT_HW_GENERATION_CDNA4)
{
constexpr uint32_t kLdsBytesPerCu = 160 * 1024;
return info.numberCUs() * kLdsBytesPerCu;
}
return std::nullopt;
}
bool AMDTDeviceInfoUtils::GetDeviceInfo(uint32_t deviceID, uint32_t revisionID, GDT_GfxCardInfo &cardInfo)
{
auto find_device = [&](GDT_GfxCardInfo const &info)
{
if (info.m_deviceID != deviceID)
{
return false;
}
return (kRevisionIdAny == revisionID || info.m_revID == revisionID);
};
const auto it = std::ranges::find_if(gs_cardInfo, find_device);
const bool found = it != gs_cardInfo.end();
if (found)
{
cardInfo = *it;
}
return found;
}
bool AMDTDeviceInfoUtils::GetDeviceInfo(const char *szCALDeviceName, std::vector<GDT_GfxCardInfo> &cardList)
{
cardList.clear();
const std::string strDeviceName = TranslateDeviceName(szCALDeviceName);
auto same_name = [&strDeviceName](GDT_GfxCardInfo const &info)
{ return strDeviceName == info.m_szMarketingName; };
std::ranges::copy_if(gs_cardInfo, std::back_inserter(cardList),
same_name);
return !cardList.empty();
}
bool AMDTDeviceInfoUtils::GetDeviceInfoMarketingName(const char *szMarketingDeviceName, std::vector<GDT_GfxCardInfo> &cardList)
{
cardList.clear();
const std::string_view marketing_name = szMarketingDeviceName;
auto same_name = [&marketing_name](GDT_GfxCardInfo const &info)
{ return marketing_name == info.m_szMarketingName; };
std::ranges::copy_if(gs_cardInfo, std::back_inserter(cardList),
same_name);
return !cardList.empty();
}
bool AMDTDeviceInfoUtils::IsAPU(const char *szCALDeviceName, bool &bIsAPU)
{
const std::string strDeviceName = TranslateDeviceName(szCALDeviceName);
auto same_name = [&strDeviceName](GDT_GfxCardInfo const &info)
{ return strDeviceName == info.m_szCALName; };
const auto it = std::ranges::find_if(gs_cardInfo, same_name);
const bool found = it != gs_cardInfo.end();
if (found)
{
bIsAPU = it->m_bAPU;
}
return found;
}
bool AMDTDeviceInfoUtils::IsAPU(uint32_t deviceID, bool &isAPU)
{
auto find_device = [&](GDT_GfxCardInfo const &info)
{
return info.m_deviceID != deviceID;
};
const auto it = std::ranges::find_if(gs_cardInfo, find_device);
const bool found = it != gs_cardInfo.end();
if (found)
{
isAPU = it->m_bAPU;
}
return found;
}
bool AMDTDeviceInfoUtils::IsXFamily(uint32_t deviceID, GDT_HW_GENERATION generation, bool &isXFamily)
{
GDT_HW_GENERATION gen = GDT_HW_GENERATION_NONE;
if (GetHardwareGeneration(deviceID, gen))
{
isXFamily = gen == generation;
return true;
}
else
{
return false;
}
}
bool AMDTDeviceInfoUtils::IsGfx12Family(uint32_t deviceID, bool &isGfx12)
{
return IsXFamily(deviceID, GDT_HW_GENERATION_GFX12, isGfx12);
}
bool AMDTDeviceInfoUtils::IsGfx11Family(uint32_t deviceID, bool &isGfx11)
{
return IsXFamily(deviceID, GDT_HW_GENERATION_GFX11, isGfx11);
}
bool AMDTDeviceInfoUtils::IsGfx10Family(uint32_t deviceID, bool &isGfx10)
{
return IsXFamily(deviceID, GDT_HW_GENERATION_GFX10, isGfx10);
}
bool AMDTDeviceInfoUtils::IsGfx9Family(uint32_t deviceID, bool &isGfx9)
{
return IsXFamily(deviceID, GDT_HW_GENERATION_GFX9, isGfx9);
}
bool AMDTDeviceInfoUtils::IsVIFamily(uint32_t deviceID, bool &isVI)
{
return IsXFamily(deviceID, GDT_HW_GENERATION_VOLCANICISLAND, isVI);
}
bool AMDTDeviceInfoUtils::IsCIFamily(uint32_t deviceID, bool &isCI)
{
return IsXFamily(deviceID, GDT_HW_GENERATION_SEAISLAND, isCI);
}
bool AMDTDeviceInfoUtils::IsSIFamily(uint32_t deviceID, bool &isSI)
{
return IsXFamily(deviceID, GDT_HW_GENERATION_SOUTHERNISLAND, isSI);
}
bool AMDTDeviceInfoUtils::GetHardwareGeneration(uint32_t deviceID, GDT_HW_GENERATION &gen)
{
// revId not needed here, since all revs will have the same hardware family
auto find_device = [&](GDT_GfxCardInfo const &info)
{
return info.m_deviceID != deviceID;
};
const auto it = std::ranges::find_if(gs_cardInfo, find_device);
const bool found = it != gs_cardInfo.end();
if (found)
{
gen = it->m_generation;
}
return found;
}
bool AMDTDeviceInfoUtils::GetHardwareGeneration(const char *szCALDeviceName, GDT_HW_GENERATION &gen)
{
const std::string strDeviceName = TranslateDeviceName(szCALDeviceName);
auto same_name = [&strDeviceName](GDT_GfxCardInfo const &info)
{ return strDeviceName == info.m_szCALName; };
const auto it = std::ranges::find_if(gs_cardInfo, same_name);
const bool found = it != gs_cardInfo.end();
if (found)
{
gen = it->m_generation;
}
return found;
}
void AMDTDeviceInfoUtils::GetAllCards(std::vector<GDT_GfxCardInfo> &cardList)
{
cardList.clear();
cardList.reserve(gs_cardInfo.size());
std::ranges::copy(gs_cardInfo, std::back_inserter(cardList));
}
bool AMDTDeviceInfoUtils::GetAllCardsWithName(const char *szCALDeviceName, std::vector<GDT_GfxCardInfo> &cardList)
{
return GetDeviceInfo(szCALDeviceName, cardList);
}
bool AMDTDeviceInfoUtils::GetAllCardsInHardwareGeneration(GDT_HW_GENERATION gen, std::vector<GDT_GfxCardInfo> &cardList)
{
cardList.clear();
auto same_gen = [&gen](GDT_GfxCardInfo const &info)
{ return gen == info.m_generation; };
std::ranges::copy_if(gs_cardInfo, std::back_inserter(cardList),
same_gen);
return !cardList.empty();
}
bool AMDTDeviceInfoUtils::GetAllCardsWithDeviceId(uint32_t deviceID, std::vector<GDT_GfxCardInfo> &cardList)
{
cardList.clear();
auto same_device_id = [&deviceID](GDT_GfxCardInfo const &info)
{ return deviceID == info.m_deviceID; };
std::ranges::copy_if(gs_cardInfo, std::back_inserter(cardList),
same_device_id);
return !cardList.empty();
}
bool AMDTDeviceInfoUtils::GetAllCardsWithAsicType(GDT_HW_ASIC_TYPE asicType, std::vector<GDT_GfxCardInfo> &cardList)
{
cardList.clear();
auto same_asic = [&asicType](GDT_GfxCardInfo const &info)
{ return asicType == info.m_asicType; };
std::ranges::copy_if(gs_cardInfo, std::back_inserter(cardList),
same_asic);
return !cardList.empty();
}
bool AMDTDeviceInfoUtils::GetHardwareGenerationDisplayName(GDT_HW_GENERATION gen, std::string &strGenerationDisplayName)
{
static constexpr std::string_view s_SI_FAMILY_NAME = "Graphics IP v6";
static constexpr std::string_view s_CI_FAMILY_NAME = "Graphics IP v7";
static constexpr std::string_view s_VI_FAMILY_NAME = "Graphics IP v8";
static constexpr std::string_view s_GFX9_FAMILY_NAME = "Vega";
static constexpr std::string_view s_RDNA_FAMILY_NAME = "RDNA";
static constexpr std::string_view s_RDNA2_FAMILY_NAME = "RDNA2";
static constexpr std::string_view s_RDNA3_FAMILY_NAME = "RDNA3";
static constexpr std::string_view s_RDNA4_FAMILY_NAME = "RDNA4";
static constexpr std::string_view s_CDNA_FAMILY_NAME = "CDNA";
static constexpr std::string_view s_CDNA2_FAMILY_NAME = "CDNA2";
static constexpr std::string_view s_CDNA3_FAMILY_NAME = "CDNA3";
static constexpr std::string_view s_CDNA4_FAMILY_NAME = "CDNA4";
bool retVal = true;
switch (gen)
{
case GDT_HW_GENERATION_SOUTHERNISLAND:
strGenerationDisplayName = s_SI_FAMILY_NAME;
break;
case GDT_HW_GENERATION_SEAISLAND:
strGenerationDisplayName = s_CI_FAMILY_NAME;
break;
case GDT_HW_GENERATION_VOLCANICISLAND:
strGenerationDisplayName = s_VI_FAMILY_NAME;
break;
case GDT_HW_GENERATION_GFX9:
strGenerationDisplayName = s_GFX9_FAMILY_NAME;
break;
case GDT_HW_GENERATION_GFX10:
strGenerationDisplayName = s_RDNA_FAMILY_NAME;
break;
case GDT_HW_GENERATION_GFX103:
strGenerationDisplayName = s_RDNA2_FAMILY_NAME;
break;
case GDT_HW_GENERATION_GFX11:
strGenerationDisplayName = s_RDNA3_FAMILY_NAME;
break;
case GDT_HW_GENERATION_GFX12:
strGenerationDisplayName = s_RDNA4_FAMILY_NAME;
break;
case GDT_HW_GENERATION_CDNA:
strGenerationDisplayName = s_CDNA_FAMILY_NAME;
break;
case GDT_HW_GENERATION_CDNA2:
strGenerationDisplayName = s_CDNA2_FAMILY_NAME;
break;
case GDT_HW_GENERATION_CDNA3:
strGenerationDisplayName = s_CDNA3_FAMILY_NAME;
break;
case GDT_HW_GENERATION_CDNA4:
strGenerationDisplayName = s_CDNA4_FAMILY_NAME;
break;
default:
strGenerationDisplayName.clear();
assert(false);
retVal = false;
break;
}
return retVal;
}
std::string AMDTDeviceInfoUtils::TranslateDeviceName(const char *strDeviceName)
{
std::string retVal(strDeviceName);
if (retVal.compare("gfx901") == 0) // some gfx900 boards are identified as gfx901 by some drivers
{
retVal = "gfx900";
}
if (retVal.compare("gfx903") == 0) // some gfx902 APUs are identified as gfx903 by some drivers
{
retVal = "gfx902";
}
if (retVal.compare("gfx905") == 0) // some gfx904 boards are identified as gfx905
{
retVal = "gfx904";
}
if (retVal.compare("gfx907") == 0) // some gfx906 boards are identified as gfx907
{
retVal = "gfx906";
}
if (nullptr != deviceNameTranslatorFunction)
{
retVal = deviceNameTranslatorFunction(retVal.c_str());
}
return retVal;
}
bool AMDTDeviceInfoUtils::GfxIPVerToHwGeneration(uint32_t gfxIPVer, GDT_HW_GENERATION &hwGen)
{
hwGen = static_cast<GDT_HW_GENERATION>(gfxIPVer - kGfxToGdtHwGenConversionFactor);
bool retVal = hwGen >= GDT_HW_GENERATION_FIRST_AMD && hwGen < GDT_HW_GENERATION_LAST;
if (!retVal)
{
hwGen = GDT_HW_GENERATION_NONE;
}
return retVal;
}
bool AMDTDeviceInfoUtils::HwGenerationToGfxIPVer(GDT_HW_GENERATION hwGen, uint32_t &gfxIPVer)
{
gfxIPVer = 0;
bool retVal = hwGen >= GDT_HW_GENERATION_FIRST_AMD && hwGen < GDT_HW_GENERATION_LAST;
if (retVal)
{
gfxIPVer = static_cast<uint32_t>(hwGen) + kGfxToGdtHwGenConversionFactor;
}
return retVal;
}
void AMDTDeviceInfoUtils::SetDeviceNameTranslator(DeviceNameTranslatorFunction func)
{
deviceNameTranslatorFunction = func;
}