Debian Codegraph @

example/amd_smi_drm_example.cc

raw
1 /*
2 * Copyright (c) Advanced Micro Devices, Inc. All rights reserved.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 * THE SOFTWARE.
21 */
22
23 #include <pwd.h>
24 #include <sys/stat.h>
25 #include <unistd.h>
26 #include <cinttypes>
27
28 #include <cassert>
29 #include <cstdint>
30 #include <cstring>
31 #include <iostream>
32 #include <map>
33 #include <vector>
34 #include <sstream>
35
36 #include "amd_smi/amdsmi.h"
37
38
39 #define CHK_AMDSMI_RET(RET) \
40 { \
41 if (RET != AMDSMI_STATUS_SUCCESS) { \
42 const char *err_str; \
43 std::cout << "AMDSMI call returned " << RET << " at line " \
44 << __LINE__ << std::endl; \
45 amdsmi_status_code_to_string(RET, &err_str); \
46 std::cout << err_str << std::endl; \
47 return RET; \
48 } \
49 }
50
51 #define PRINT_AMDSMI_RET(RET) \
52 { \
53 if (RET != AMDSMI_STATUS_SUCCESS) { \
54 const char *err_str; \
55 std::cout << "AMDSMI call returned " << RET << " at line " \
56 << __LINE__ << std::endl; \
57 amdsmi_status_code_to_string(RET, &err_str); \
58 std::cout << err_str << std::endl; \
59 } \
60 }
61
62
63 void getFWNameFromId(int id, char *name)
64 {
65 switch (id) {
66 case AMDSMI_FW_ID_SMU:
67 strcpy(name, "SMU");
68 break;
69 case AMDSMI_FW_ID_CP_CE:
70 strcpy(name, "CP_CE");
71 break;
72 case AMDSMI_FW_ID_CP_PFP:
73 strcpy(name, "CP_PFP");
74 break;
75 case AMDSMI_FW_ID_CP_ME:
76 strcpy(name, "CP_ME");
77 break;
78 case AMDSMI_FW_ID_CP_MEC_JT1:
79 strcpy(name, "CP_MEC_JT1");
80 break;
81 case AMDSMI_FW_ID_CP_MEC_JT2:
82 strcpy(name, "CP_MEC_JT2");
83 break;
84 case AMDSMI_FW_ID_CP_MEC1:
85 strcpy(name, "CP_MEC1");
86 break;
87 case AMDSMI_FW_ID_CP_MEC2:
88 strcpy(name, "CP_MEC2");
89 break;
90 case AMDSMI_FW_ID_RLC:
91 strcpy(name, "RLC");
92 break;
93 case AMDSMI_FW_ID_SDMA0:
94 strcpy(name, "SDMA0");
95 break;
96 case AMDSMI_FW_ID_SDMA1:
97 strcpy(name, "SDMA1");
98 break;
99 case AMDSMI_FW_ID_SDMA2:
100 strcpy(name, "SDMA2");
101 break;
102 case AMDSMI_FW_ID_SDMA3:
103 strcpy(name, "SDMA3");
104 break;
105 case AMDSMI_FW_ID_SDMA4:
106 strcpy(name, "SDMA4");
107 break;
108 case AMDSMI_FW_ID_SDMA5:
109 strcpy(name, "SDMA5");
110 break;
111 case AMDSMI_FW_ID_SDMA6:
112 strcpy(name, "SDMA6");
113 break;
114 case AMDSMI_FW_ID_SDMA7:
115 strcpy(name, "SDMA7");
116 break;
117 case AMDSMI_FW_ID_VCN:
118 strcpy(name, "VCN");
119 break;
120 case AMDSMI_FW_ID_UVD:
121 strcpy(name, "UVD");
122 break;
123 case AMDSMI_FW_ID_VCE:
124 strcpy(name, "VCE");
125 break;
126 case AMDSMI_FW_ID_ISP:
127 strcpy(name, "ISP");
128 break;
129 case AMDSMI_FW_ID_DMCU_ERAM:
130 strcpy(name, "DMCU_ERAM");
131 break;
132 case AMDSMI_FW_ID_DMCU_ISR:
133 strcpy(name, "DMCU_ISR");
134 break;
135 case AMDSMI_FW_ID_RLC_RESTORE_LIST_GPM_MEM:
136 strcpy(name, "RLC_RESTORE_LIST_GPM_MEM");
137 break;
138 case AMDSMI_FW_ID_RLC_RESTORE_LIST_SRM_MEM:
139 strcpy(name, "RLC_RESTORE_LIST_SRM_MEM");
140 break;
141 case AMDSMI_FW_ID_RLC_RESTORE_LIST_CNTL:
142 strcpy(name, "RLC_RESTORE_LIST_CNTL");
143 break;
144 case AMDSMI_FW_ID_RLC_V:
145 strcpy(name, "RLC_V");
146 break;
147 case AMDSMI_FW_ID_MMSCH:
148 strcpy(name, "MMSCH");
149 break;
150 case AMDSMI_FW_ID_PSP_SYSDRV:
151 strcpy(name, "PSP_SYSDRV");
152 break;
153 case AMDSMI_FW_ID_PSP_SOSDRV:
154 strcpy(name, "PSP_SOSDRV");
155 break;
156 case AMDSMI_FW_ID_PSP_TOC:
157 strcpy(name, "PSP_TOC");
158 break;
159 case AMDSMI_FW_ID_PSP_KEYDB:
160 strcpy(name, "PSP_KEYDB");
161 break;
162 case AMDSMI_FW_ID_DFC:
163 strcpy(name, "DFC");
164 break;
165 case AMDSMI_FW_ID_PSP_SPL:
166 strcpy(name, "PSP_SPL");
167 break;
168 case AMDSMI_FW_ID_DRV_CAP:
169 strcpy(name, "DRV_CAP");
170 break;
171 case AMDSMI_FW_ID_MC:
172 strcpy(name, "MC");
173 break;
174 case AMDSMI_FW_ID_PSP_BL:
175 strcpy(name, "PSP_BL");
176 break;
177 case AMDSMI_FW_ID_CP_PM4:
178 strcpy(name, "CP_PM4");
179 break;
180 case AMDSMI_FW_ID_ASD:
181 strcpy(name, "ID_ASD");
182 break;
183 case AMDSMI_FW_ID_TA_RAS:
184 strcpy(name, "ID_TA_RAS");
185 break;
186 case AMDSMI_FW_ID_TA_XGMI:
187 strcpy(name, "ID_TA_XGMI");
188 break;
189 case AMDSMI_FW_ID_RLC_SRLG:
190 strcpy(name, "ID_RLC_SRLG");
191 break;
192 case AMDSMI_FW_ID_RLC_SRLS:
193 strcpy(name, "ID_RLC_SRLS");
194 break;
195 case AMDSMI_FW_ID_PM:
196 strcpy(name, "ID_PM");
197 break;
198 case AMDSMI_FW_ID_DMCU:
199 strcpy(name, "ID_DMCU");
200 break;
201 case AMDSMI_FW_ID_PLDM_BUNDLE:
202 strcpy(name, "PLDM_BUNDLE");
203 break;
204 default:
205 strcpy(name, "");
206 break;
207 }
208 }
209
210 template <typename T>
211 std::string print_unsigned_int(T value) {
212 std::stringstream ss;
213 ss << static_cast<uint64_t>(value | 0);
214
215 return ss.str();
216 }
217
218 static const std::string
219 computePartitionString(amdsmi_compute_partition_type_t computeParitionType) {
220 switch (computeParitionType) {
221 case AMDSMI_COMPUTE_PARTITION_SPX:
222 return "SPX";
223 case AMDSMI_COMPUTE_PARTITION_DPX:
224 return "DPX";
225 case AMDSMI_COMPUTE_PARTITION_TPX:
226 return "TPX";
227 case AMDSMI_COMPUTE_PARTITION_QPX:
228 return "QPX";
229 case AMDSMI_COMPUTE_PARTITION_CPX:
230 return "CPX";
231 default:
232 return "N/A";
233 }
234 }
235
236 static const std::map<std::string, amdsmi_compute_partition_type_t>
237 mapStringToSMIComputePartitionTypes {
238 {"SPX", AMDSMI_COMPUTE_PARTITION_SPX},
239 {"DPX", AMDSMI_COMPUTE_PARTITION_DPX},
240 {"TPX", AMDSMI_COMPUTE_PARTITION_TPX},
241 {"QPX", AMDSMI_COMPUTE_PARTITION_QPX},
242 {"CPX", AMDSMI_COMPUTE_PARTITION_CPX},
243 {"N/A", AMDSMI_COMPUTE_PARTITION_INVALID}
244 };
245
246 static const std::string
247 memoryPartitionString(amdsmi_memory_partition_type_t memoryParitionType) {
248 switch (memoryParitionType) {
249 case AMDSMI_MEMORY_PARTITION_NPS1:
250 return "NPS1";
251 case AMDSMI_MEMORY_PARTITION_NPS2:
252 return "NPS2";
253 case AMDSMI_MEMORY_PARTITION_NPS4:
254 return "NPS4";
255 case AMDSMI_MEMORY_PARTITION_NPS8:
256 return "NPS8";
257 default:
258 return "N/A";
259 }
260 }
261
262 static const std::map<std::string, amdsmi_memory_partition_type_t>
263 mapStringToSMIMemoryPartitionTypes {
264 {"NPS1", AMDSMI_MEMORY_PARTITION_NPS1},
265 {"NPS2", AMDSMI_MEMORY_PARTITION_NPS2},
266 {"NPS4", AMDSMI_MEMORY_PARTITION_NPS4},
267 {"NPS8", AMDSMI_MEMORY_PARTITION_NPS8},
268 {"N/A", AMDSMI_MEMORY_PARTITION_UNKNOWN}
269 };
270
271 static const std::map<amdsmi_virtualization_mode_t, std::string>
272 virtualization_mode_map = {
273 {AMDSMI_VIRTUALIZATION_MODE_UNKNOWN, "UNKNOWN"},
274 {AMDSMI_VIRTUALIZATION_MODE_BAREMETAL, "BAREMETAL"},
275 {AMDSMI_VIRTUALIZATION_MODE_HOST, "HOST"},
276 {AMDSMI_VIRTUALIZATION_MODE_GUEST, "GUEST"},
277 {AMDSMI_VIRTUALIZATION_MODE_PASSTHROUGH, "PASSTHROUGH"}
278 };
279
280 static const std::map<processor_type_t, std::string>
281 processor_type_map = {
282 {AMDSMI_PROCESSOR_TYPE_UNKNOWN, "UNKNOWN"},
283 {AMDSMI_PROCESSOR_TYPE_AMD_GPU, "AMD_GPU"},
284 {AMDSMI_PROCESSOR_TYPE_AMD_CPU, "AMD_CPU"},
285 {AMDSMI_PROCESSOR_TYPE_NON_AMD_GPU, "NON_AMD_GPU"},
286 {AMDSMI_PROCESSOR_TYPE_NON_AMD_CPU, "NON_AMD_CPU"},
287 {AMDSMI_PROCESSOR_TYPE_AMD_CPU_CORE, "AMD_CPU_CORE"},
288 {AMDSMI_PROCESSOR_TYPE_AMD_APU, "AMD_APU"}
289 };
290
291 static const std::map<amdsmi_link_type_t, std::string>
292 link_type_map = {
293 {AMDSMI_LINK_TYPE_INTERNAL, "INTERNAL"},
294 {AMDSMI_LINK_TYPE_PCIE, "PCIE"},
295 {AMDSMI_LINK_TYPE_XGMI, "XGMI"},
296 {AMDSMI_LINK_TYPE_NOT_APPLICABLE, "NOT_APPLICABLE"},
297 {AMDSMI_LINK_TYPE_UNKNOWN, "UNKNOWN"}
298 };
299
300 int main() {
301 amdsmi_status_t ret;
302 std::vector<amdsmi_compute_partition_type_t> orig_accelerator_partitions;
303 std::vector<amdsmi_memory_partition_type_t> orig_memory_partitions;
304 uint32_t gpu_number = 0;
305
306 // Init amdsmi for sockets and devices.
307 // Here we are only interested in AMD_GPUS.
308 ret = amdsmi_init(AMDSMI_INIT_AMD_GPUS);
309 CHK_AMDSMI_RET(ret)
310
311 // Get all sockets
312 uint32_t socket_count = 0;
313
314 // Get the socket count available for the system.
315 ret = amdsmi_get_socket_handles(&socket_count, nullptr);
316 CHK_AMDSMI_RET(ret)
317
318 // Allocate the memory for the sockets
319 std::vector<amdsmi_socket_handle> sockets(socket_count);
320 // Get the sockets of the system
321 ret = amdsmi_get_socket_handles(&socket_count, &sockets[0]);
322 CHK_AMDSMI_RET(ret)
323
324 std::cout << "Total Socket: " << socket_count << std::endl;
325
326 // WARNING: Do not put any other settings before/inside/or between these lambda functions
327 // Required to save/change/reset the compute/accelerator & memory partition settings
328 // Reason: Modifies total number of gpu count, which will affect other API calls.
329 // Requires amdsmi_shut_down()/amdsmi_init(AMDSMI_INIT_AMD_GPUS) to re-enumerate
330 // total number of GPUs (AKA "processors per socket").
331 // Changing back to original settings (compute/accelerator & memory partition)
332 // will not modify the GPU count.
333 // Save all original partition settings for later
334 auto save_original_partitions = [socket_count, &ret, sockets](
335 std::vector<amdsmi_compute_partition_type_t>& orig_partitions,
336 std::vector<amdsmi_memory_partition_type_t>& orig_memory_partitions,
337 uint32_t& gpu_number) -> void {
338 std::cout << " **Saving Original Compute/Accelerator & Memory Partition Settings**\n";
339
340 // For each socket, get identifier and devices
341 for (uint32_t i = 0; i < socket_count; i++) {
342 // Get Socket info
343 char socket_info[128];
344 ret = amdsmi_get_socket_info(sockets[i], 128, socket_info);
345 PRINT_AMDSMI_RET(ret)
346 std::cout << "\t**Socket Info: " << socket_info << std::endl;
347
348 // Get the device count available for the socket.
349 uint32_t device_count = 0;
350 ret = amdsmi_get_processor_handles(sockets[i], &device_count, nullptr);
351 PRINT_AMDSMI_RET(ret)
352
353 // Allocate the memory for the device handlers on the socket
354 std::vector<amdsmi_processor_handle> processor_handles(device_count);
355 // Get all devices of the socket
356 ret = amdsmi_get_processor_handles(sockets[i],
357 &device_count, &processor_handles[0]);
358 PRINT_AMDSMI_RET(ret)
359
360 std::cout << "\t**Processor Count: " << device_count << std::endl;
361
362 // For each device of the socket, get name and temperature.
363 for (uint32_t device_index = 0; device_index < device_count; device_index++) {
364 std::cout << "\t**Device Index: " << device_index << std::endl;
365 std::cout << "\t**Device Handle: " << processor_handles[device_index] << std::endl;
366 std::cout << "\t**GPU Number: " << gpu_number << std::endl;
367
368 // Get the original compute partition
369 char original_compute_partition[AMDSMI_MAX_STRING_LENGTH];
370 ret = amdsmi_get_gpu_compute_partition(processor_handles[device_index],
371 original_compute_partition,
372 static_cast<uint32_t>(AMDSMI_MAX_STRING_LENGTH));
373
374 const char* err_str;
375 amdsmi_status_code_to_string(ret, &err_str);
376 if (ret == AMDSMI_STATUS_SUCCESS) {
377 PRINT_AMDSMI_RET(ret)
378 std::cout << " Output of amdsmi_get_gpu_compute_partition:\n";
379 std::cout << "\tamdsmi_get_gpu_compute_partition(" << gpu_number << ", "
380 << mapStringToSMIComputePartitionTypes.at(original_compute_partition)
381 << "): " << err_str << "\n\n";
382 std::cout << "\tCompute Partition (original): "
383 << original_compute_partition << "\n\n";
384 } else {
385 std::cout << "\tamdsmi_get_gpu_compute_partition(" << gpu_number << ", "
386 << computePartitionString(AMDSMI_COMPUTE_PARTITION_INVALID) << "): "
387 << err_str << "\n\n";
388 }
389
390 // Save the original compute/accelerator partition
391 if (ret == AMDSMI_STATUS_SUCCESS) {
392 orig_partitions.push_back(
393 mapStringToSMIComputePartitionTypes.at(original_compute_partition));
394 } else {
395 orig_partitions.push_back(AMDSMI_COMPUTE_PARTITION_INVALID);
396 }
397
398 // Get the original memory partition
399 char original_memory_partition[AMDSMI_MAX_STRING_LENGTH];
400 ret = amdsmi_get_gpu_memory_partition(processor_handles[device_index],
401 original_memory_partition,
402 static_cast<uint32_t>(AMDSMI_MAX_STRING_LENGTH));
403 amdsmi_status_code_to_string(ret, &err_str);
404 if (ret == AMDSMI_STATUS_SUCCESS) {
405 PRINT_AMDSMI_RET(ret)
406 std::cout << " Output of amdsmi_get_gpu_memory_partition:\n";
407 std::cout << "\tamdsmi_get_gpu_memory_partition(" << gpu_number << ", "
408 << mapStringToSMIMemoryPartitionTypes.at(original_memory_partition)
409 << "): " << err_str << "\n\n";
410 std::cout << "\tMemory Partition (original): "
411 << original_memory_partition << "\n\n";
412 } else {
413 std::cout << "\tamdsmi_get_gpu_memory_partition(" << gpu_number << ", "
414 << memoryPartitionString(AMDSMI_MEMORY_PARTITION_UNKNOWN) << "): "
415 << err_str << "\n\n";
416 }
417
418 // Save the original memory partition
419 if (ret == AMDSMI_STATUS_SUCCESS) {
420 orig_memory_partitions.push_back(
421 mapStringToSMIMemoryPartitionTypes.at(original_memory_partition));
422 } else {
423 orig_memory_partitions.push_back(AMDSMI_MEMORY_PARTITION_UNKNOWN);
424 }
425 gpu_number++;
426 }
427 }
428 // Reset GPU number for the next loop
429 gpu_number = 0;
430 };
431 // Save the original compute/accelerator & memory partition settings
432 save_original_partitions(orig_accelerator_partitions, orig_memory_partitions, gpu_number);
433
434 std::cout << " **Version 1: Accelerator/Compute Partition & memory API Examples**\n";
435 auto process_accelerator_partitions = [socket_count, &ret, sockets](
436 uint32_t& gpu_number) -> void {
437 std::cout << " **Process Compute/Accelerator & Memory Partition Settings**\n";
438
439 // For each socket, get identifier and devices
440 for (uint32_t i = 0; i < socket_count; i++) {
441 // Get Socket info
442 char socket_info[128];
443 ret = amdsmi_get_socket_info(sockets[i], 128, socket_info);
444 PRINT_AMDSMI_RET(ret)
445 std::cout << "\t**Socket Info: " << socket_info << std::endl;
446
447 // Get the device count available for the socket.
448 uint32_t device_count = 0;
449 ret = amdsmi_get_processor_handles(sockets[i], &device_count, nullptr);
450 PRINT_AMDSMI_RET(ret)
451
452 // Allocate the memory for the device handlers on the socket
453 std::vector<amdsmi_processor_handle> processor_handles(device_count);
454 // Get all devices of the socket
455 ret = amdsmi_get_processor_handles(sockets[i],
456 &device_count, &processor_handles[0]);
457 PRINT_AMDSMI_RET(ret)
458
459 std::cout << "\t**Processor Count: " << device_count << std::endl;
460
461 // For each device of the socket, get name and temperature.
462 for (uint32_t device_index = 0; device_index < device_count; device_index++) {
463 std::cout << "\t**Device Index: " << device_index << std::endl;
464 std::cout << "\t**Device Handle: " << processor_handles[device_index] << std::endl;
465 std::cout << "\t**GPU Number: " << gpu_number << std::endl;
466
467 // Get the original compute partition
468 char original_compute_partition[AMDSMI_MAX_STRING_LENGTH];
469 ret = amdsmi_get_gpu_compute_partition(processor_handles[device_index],
470 original_compute_partition,
471 static_cast<uint32_t>(AMDSMI_MAX_STRING_LENGTH));
472
473 const char* err_str;
474 amdsmi_status_code_to_string(ret, &err_str);
475 if (ret == AMDSMI_STATUS_SUCCESS) {
476 PRINT_AMDSMI_RET(ret)
477 std::cout << " Output of amdsmi_get_gpu_compute_partition:\n";
478 std::cout << "\tamdsmi_get_gpu_compute_partition(" << gpu_number << ", "
479 << mapStringToSMIComputePartitionTypes.at(original_compute_partition)
480 << "): " << err_str << "\n\n";
481 std::cout << "\tCompute Partition (original): "
482 << original_compute_partition << "\n\n";
483 } else {
484 std::cout << "\tamdsmi_get_gpu_compute_partition(" << gpu_number << ", "
485 << computePartitionString(AMDSMI_COMPUTE_PARTITION_INVALID) << "): "
486 << err_str << "\n\n";
487 }
488
489 // Iterate through all compute partitions
490 for (int partition = static_cast<int>(AMDSMI_COMPUTE_PARTITION_SPX);
491 partition <= static_cast<int>(AMDSMI_COMPUTE_PARTITION_CPX);
492 partition++) {
493 amdsmi_compute_partition_type_t updatePartition =
494 static_cast<amdsmi_compute_partition_type_t>(partition);
495 amdsmi_status_t ret_set = amdsmi_set_gpu_compute_partition(
496 processor_handles[device_index],
497 updatePartition);
498 amdsmi_status_code_to_string(ret_set, &err_str);
499 if (ret_set == AMDSMI_STATUS_SUCCESS) {
500 PRINT_AMDSMI_RET(ret_set)
501 }
502 std::cout << "\tamdsmi_set_gpu_compute_partition(" << gpu_number << ", "
503 << computePartitionString(updatePartition) << "): "
504 << err_str << "\n\n";
505
506 // Get the current compute partition
507 char current_compute_partition[AMDSMI_MAX_STRING_LENGTH];
508 ret = amdsmi_get_gpu_compute_partition(processor_handles[device_index],
509 current_compute_partition,
510 static_cast<uint32_t>(AMDSMI_MAX_STRING_LENGTH));
511 amdsmi_status_code_to_string(ret, &err_str);
512 if (ret == AMDSMI_STATUS_SUCCESS) {
513 PRINT_AMDSMI_RET(ret)
514 std::cout << " Output of amdsmi_get_gpu_compute_partition:\n";
515 std::cout << "\tamdsmi_get_gpu_compute_partition(" << gpu_number << ", "
516 << computePartitionString(updatePartition) << "): "
517 << err_str << "\n\n";
518 std::cout << "\tCompute Partition (current): "
519 << current_compute_partition << "\n\n";
520 } else {
521 std::cout << "\tamdsmi_get_gpu_compute_partition(" << gpu_number << ", "
522 << computePartitionString(AMDSMI_COMPUTE_PARTITION_INVALID) << "): "
523 << err_str << "\n\n";
524 }
525 }
526 gpu_number++;
527 }
528 }
529 // Reset GPU number for the next loop
530 gpu_number = 0;
531 };
532 process_accelerator_partitions(gpu_number);
533
534 auto process_memory_partitions = [socket_count, &ret, sockets](
535 uint32_t& gpu_number) -> void {
536 std::cout << " **Process Memory Partition Settings**\n";
537
538 // For each socket, get identifier and devices
539 for (uint32_t i = 0; i < socket_count; i++) {
540 // Get Socket info
541 char socket_info[128];
542 ret = amdsmi_get_socket_info(sockets[i], 128, socket_info);
543 PRINT_AMDSMI_RET(ret)
544 std::cout << "\t**Socket Info: " << socket_info << std::endl;
545
546 // Get the device count available for the socket.
547 uint32_t device_count = 0;
548 ret = amdsmi_get_processor_handles(sockets[i], &device_count, nullptr);
549 PRINT_AMDSMI_RET(ret)
550
551 // Allocate the memory for the device handlers on the socket
552 std::vector<amdsmi_processor_handle> processor_handles(device_count);
553 // Get all devices of the socket
554 ret = amdsmi_get_processor_handles(sockets[i],
555 &device_count, &processor_handles[0]);
556 PRINT_AMDSMI_RET(ret)
557
558 std::cout << "\t**Processor Count: " << device_count << std::endl;
559
560 // For each device of the socket, get name and temperature.
561 for (uint32_t device_index = 0; device_index < device_count; device_index++) {
562 std::cout << "\t**Device Index: " << device_index << std::endl;
563 std::cout << "\t**Device Handle: " << processor_handles[device_index] << std::endl;
564 std::cout << "\t**GPU Number: " << gpu_number << std::endl;
565
566 // Get the original memory partition
567 char original_memory_partition[AMDSMI_MAX_STRING_LENGTH];
568 ret = amdsmi_get_gpu_memory_partition(processor_handles[device_index],
569 original_memory_partition,
570 static_cast<uint32_t>(AMDSMI_MAX_STRING_LENGTH));
571 const char* err_str;
572 amdsmi_status_code_to_string(ret, &err_str);
573 if (ret == AMDSMI_STATUS_SUCCESS) {
574 PRINT_AMDSMI_RET(ret)
575 std::cout << " Output of amdsmi_get_gpu_memory_partition:\n";
576 std::cout << "\tamdsmi_get_gpu_memory_partition(" << gpu_number << ", "
577 << mapStringToSMIMemoryPartitionTypes.at(original_memory_partition)
578 << "): " << err_str << "\n\n";
579 std::cout << "\tMemory Partition (original): " << original_memory_partition
580 << "\n\n";
581 } else {
582 std::cout << "\tamdsmi_get_gpu_memory_partition(" << gpu_number << ", "
583 << memoryPartitionString(AMDSMI_MEMORY_PARTITION_UNKNOWN) << "): "
584 << err_str << "\n\n";
585 }
586
587 // Since memory partition effects entire GPU hive (and modifies current
588 // compute/accelerator partition), we'll default to only changing the
589 // first device for the first socket (GPU #0)
590 // Note: Any device can be requested to change memory partition,
591 // but for simplicity, we will only change GPU #0.
592 if (gpu_number == 0) {
593 std::cout << " **Changing memory partition for GPU #"
594 << gpu_number << "...**\n";
595 for (int partition = static_cast<int>(AMDSMI_MEMORY_PARTITION_NPS1);
596 partition <= static_cast<int>(AMDSMI_MEMORY_PARTITION_NPS8);
597 partition++) {
598 if (partition != static_cast<int>(AMDSMI_MEMORY_PARTITION_NPS1) &&
599 partition != static_cast<int>(AMDSMI_MEMORY_PARTITION_NPS2) &&
600 partition != static_cast<int>(AMDSMI_MEMORY_PARTITION_NPS4) &&
601 partition != static_cast<int>(AMDSMI_MEMORY_PARTITION_NPS8)) {
602 continue;
603 }
604 amdsmi_memory_partition_type_t updatePartition =
605 static_cast<amdsmi_memory_partition_type_t>(partition);
606 auto ret_set = amdsmi_set_gpu_memory_partition(
607 processor_handles[device_index], updatePartition);
608 amdsmi_status_code_to_string(ret_set, &err_str);
609 if (ret_set == AMDSMI_STATUS_SUCCESS) {
610 PRINT_AMDSMI_RET(ret_set)
611 std::cout << " Output of amdsmi_set_gpu_memory_partition:\n";
612 }
613 std::cout << "\tamdsmi_set_gpu_memory_partition(" << gpu_number << ", "
614 << memoryPartitionString(updatePartition) << "): "
615 << err_str << "\n\n";
616
617 // Reload only if the memory partition was set successfully
618 if (ret_set == AMDSMI_STATUS_SUCCESS) {
619 std::cout << "\t**Reloading GPU driver to apply memory "
620 << "partition change, this may take some time... **\n";
621 amdsmi_status_t reload_status = amdsmi_gpu_driver_reload();
622 amdsmi_status_code_to_string(reload_status, &err_str);
623 if (reload_status == AMDSMI_STATUS_SUCCESS) {
624 PRINT_AMDSMI_RET(reload_status)
625 std::cout << "\tamdsmi_gpu_driver_reload(): " << err_str << "\n\n";
626 } else {
627 std::cout << "\tamdsmi_gpu_driver_reload(): " << err_str << "\n\n";
628 }
629 }
630
631 // Get the current memory partition
632 char current_memory_partition[AMDSMI_MAX_STRING_LENGTH];
633 ret = amdsmi_get_gpu_memory_partition(processor_handles[device_index],
634 current_memory_partition,
635 static_cast<uint32_t>(AMDSMI_MAX_STRING_LENGTH));
636 amdsmi_status_code_to_string(ret, &err_str);
637 if (ret == AMDSMI_STATUS_SUCCESS) {
638 PRINT_AMDSMI_RET(ret)
639 std::cout << "\tamdsmi_get_gpu_memory_partition(" << gpu_number
640 << ", " << memoryPartitionString(updatePartition) << "): "
641 << err_str << "\n\n";
642 std::cout << "\tMemory Partition (current): "
643 << current_memory_partition << "\n\n";
644 } else {
645 std::cout << "\tamdsmi_get_gpu_memory_partition("
646 << gpu_number << ", "
647 << memoryPartitionString(AMDSMI_MEMORY_PARTITION_UNKNOWN)
648 << "): " << err_str << "\n\n";
649 }
650 }
651 } else {
652 std::cout << " **Skipping memory partition change for GPU #" << gpu_number
653 << "...**\n";
654 }
655 gpu_number++;
656 }
657 }
658 // Reset GPU number for the next loop
659 gpu_number = 0;
660 };
661 process_memory_partitions(gpu_number);
662
663 auto reset_memory_partitions = [socket_count, &ret, sockets](
664 const std::vector<amdsmi_memory_partition_type_t>& orig_partitions,
665 uint32_t& gpu_number) -> void {
666 std::cout << " **Version 1: Memory Partition API Examples**\n";
667 std::cout << " **Resetting Memory Partition Settings**\n";
668
669 // For each socket, get identifier and devices
670 for (uint32_t i = 0; i < socket_count; i++) {
671 // Get Socket info
672 char socket_info[128];
673 ret = amdsmi_get_socket_info(sockets[i], 128, socket_info);
674 PRINT_AMDSMI_RET(ret)
675 std::cout << "\t**Socket Info: " << socket_info << std::endl;
676
677 // Get the device count available for the socket.
678 uint32_t device_count = 0;
679 ret = amdsmi_get_processor_handles(sockets[i], &device_count, nullptr);
680 PRINT_AMDSMI_RET(ret)
681
682 // Allocate the memory for the device handlers on the socket
683 std::vector<amdsmi_processor_handle> processor_handles(device_count);
684 // Get all devices of the socket
685 ret = amdsmi_get_processor_handles(sockets[i],
686 &device_count, &processor_handles[0]);
687 PRINT_AMDSMI_RET(ret)
688
689 std::cout << "\t**Processor Count: " << device_count << std::endl;
690
691 // For each device of the socket, get name and temperature.
692 for (uint32_t device_index = 0; device_index < device_count; device_index++) {
693 std::cout << "\t**Device Index: " << device_index << std::endl;
694 std::cout << "\t**Device Handle: " << processor_handles[device_index] << std::endl;
695 std::cout << "\t**GPU Number: " << gpu_number << std::endl;
696 // Since memory partition effects entire GPU hive (and modifies current
697 // compute/accelerator partition), we'll default to only changing the
698 // first device for the first socket (GPU #0)
699 // Note: Any device can be requested to change memory partition,
700 // but for simplicity, we will only change GPU #0.
701 if (gpu_number != 0) {
702 std::cout << " **Skipping memory partition reset for GPU #"
703 << gpu_number << "...**\n";
704 gpu_number++;
705 continue;
706 }
707
708 // Reset to original memory partition settings
709 amdsmi_memory_partition_type_t orig_partition =
710 orig_partitions[gpu_number];
711 amdsmi_status_t ret_set = amdsmi_set_gpu_memory_partition(
712 processor_handles[device_index], orig_partition);
713 const char* err_str;
714 amdsmi_status_code_to_string(ret_set, &err_str);
715 if (ret_set == AMDSMI_STATUS_SUCCESS) {
716 PRINT_AMDSMI_RET(ret_set)
717 std::cout << " Output of amdsmi_set_gpu_memory_partition:\n";
718 }
719 std::cout << "\tamdsmi_set_gpu_memory_partition(" << gpu_number << ", "
720 << memoryPartitionString(orig_partition) << "): "
721 << err_str << "\n\n";
722 // Reload only if the memory partition was set successfully
723 if (ret_set == AMDSMI_STATUS_SUCCESS) {
724 std::cout << "\t**Reloading GPU driver to apply memory "
725 << "partition change, this may take some time... **\n";
726 amdsmi_status_t reload_status = amdsmi_gpu_driver_reload();
727 amdsmi_status_code_to_string(reload_status, &err_str);
728 if (reload_status == AMDSMI_STATUS_SUCCESS) {
729 PRINT_AMDSMI_RET(reload_status)
730 std::cout << "\tamdsmi_gpu_driver_reload(): " << err_str << "\n\n";
731 } else {
732 std::cout << "\tamdsmi_gpu_driver_reload(): " << err_str << "\n\n";
733 }
734 }
735 // Get the current memory partition
736 char current_memory_partition[AMDSMI_MAX_STRING_LENGTH];
737 ret = amdsmi_get_gpu_memory_partition(processor_handles[device_index],
738 current_memory_partition,
739 static_cast<uint32_t>(AMDSMI_MAX_STRING_LENGTH));
740 amdsmi_status_code_to_string(ret, &err_str);
741 if (ret == AMDSMI_STATUS_SUCCESS) {
742 PRINT_AMDSMI_RET(ret)
743 std::cout << " Output of amdsmi_get_gpu_memory_partition:\n";
744 std::cout << "\tamdsmi_get_gpu_memory_partition(" << gpu_number << ", "
745 << memoryPartitionString(orig_partition) << "): "
746 << err_str << "\n\n";
747 std::cout << "\tMemory Partition (current): "
748 << current_memory_partition << "\n\n";
749 } else {
750 std::cout << "\tamdsmi_get_gpu_memory_partition(" << gpu_number << ", "
751 << memoryPartitionString(AMDSMI_MEMORY_PARTITION_UNKNOWN) << "): "
752 << err_str << "\n\n";
753 }
754 gpu_number++;
755 }
756 }
757 // Reset GPU number for the next loop
758 gpu_number = 0;
759 };
760 // Reset to original memory partition settings
761 reset_memory_partitions(orig_memory_partitions, gpu_number);
762
763 auto reset_accelerator_partitions = [socket_count, &ret, sockets](
764 const std::vector<amdsmi_compute_partition_type_t>& orig_partitions,
765 uint32_t& gpu_number) -> void {
766 std::cout << " **Version 1: Memory Partition API Examples**\n";
767 std::cout << " **Resetting Compute/Accelerator Partition Settings**\n";
768
769 // For each socket, get identifier and devices
770 for (uint32_t i = 0; i < socket_count; i++) {
771 // Get Socket info
772 char socket_info[128];
773 ret = amdsmi_get_socket_info(sockets[i], 128, socket_info);
774 PRINT_AMDSMI_RET(ret)
775 std::cout << "\t**Socket Info: " << socket_info << std::endl;
776
777 // Get the device count available for the socket.
778 uint32_t device_count = 0;
779 ret = amdsmi_get_processor_handles(sockets[i], &device_count, nullptr);
780 PRINT_AMDSMI_RET(ret)
781
782 // Allocate the memory for the device handlers on the socket
783 std::vector<amdsmi_processor_handle> processor_handles(device_count);
784 // Get all devices of the socket
785 ret = amdsmi_get_processor_handles(sockets[i],
786 &device_count, &processor_handles[0]);
787 PRINT_AMDSMI_RET(ret)
788
789 std::cout << "\t**Processor Count: " << device_count << std::endl;
790
791 // For each device of the socket, get name and temperature.
792 for (uint32_t device_index = 0; device_index < device_count; device_index++) {
793 std::cout << "\t**Device Index: " << device_index << std::endl;
794 std::cout << "\t**Device Handle: " << processor_handles[device_index] << std::endl;
795 std::cout << "\t**GPU Number: " << gpu_number << std::endl;
796
797 // Reset to original compute/accelerator partition settings
798 amdsmi_compute_partition_type_t orig_partition =
799 orig_partitions[gpu_number];
800 amdsmi_status_t ret_set = amdsmi_set_gpu_compute_partition(
801 processor_handles[device_index], orig_partition);
802 const char* err_str;
803 amdsmi_status_code_to_string(ret_set, &err_str);
804 if (ret_set == AMDSMI_STATUS_SUCCESS) {
805 PRINT_AMDSMI_RET(ret_set)
806 std::cout << " Output of amdsmi_set_gpu_compute_partition:\n";
807 }
808 std::cout << "\tamdsmi_set_gpu_compute_partition(" << gpu_number << ", "
809 << computePartitionString(orig_partition) << "): "
810 << err_str << "\n\n";
811
812 // Get the current compute/accelerator partition
813 char current_compute_partition[AMDSMI_MAX_STRING_LENGTH];
814 ret = amdsmi_get_gpu_compute_partition(processor_handles[device_index],
815 current_compute_partition,
816 static_cast<uint32_t>(AMDSMI_MAX_STRING_LENGTH));
817 amdsmi_status_code_to_string(ret, &err_str);
818 if (ret == AMDSMI_STATUS_SUCCESS) {
819 PRINT_AMDSMI_RET(ret)
820 std::cout << " Output of amdsmi_get_gpu_compute_partition:\n";
821 std::cout << "\tamdsmi_get_gpu_compute_partition(" << gpu_number << ", "
822 << computePartitionString(orig_partition) << "): "
823 << err_str << "\n\n";
824 std::cout << "\tCompute Partition (current): "
825 << current_compute_partition << "\n\n";
826 } else {
827 std::cout << "\tamdsmi_get_gpu_compute_partition(" << gpu_number << ", "
828 << computePartitionString(AMDSMI_COMPUTE_PARTITION_INVALID) << "): "
829 << err_str << "\n\n";
830 }
831 gpu_number++;
832 }
833 }
834 // Reset GPU number for the next loop
835 gpu_number = 0;
836 };
837 // Reset to original compute/accelerator partition settings
838 reset_accelerator_partitions(orig_accelerator_partitions, gpu_number);
839
840 // WARNING: Do not put any other settings before/inside/or between these lambda functions
841 // Required to save/change/reset the compute/accelerator & memory partition settings
842 // Reason: Modifies total number of gpu count, which will affect other API calls.
843 // Requires amdsmi_shut_down()/amdsmi_init(AMDSMI_INIT_AMD_GPUS) to re-enumerate
844 // total number of GPUs (AKA "processors per socket").
845 // Changing back to original settings (compute/accelerator & memory partition)
846 // will not modify the GPU count.
847 // Add new functionality below this line!
848
849 // For each socket, get identifier and devices
850 for (uint32_t i = 0; i < socket_count; i++) {
851 // Get Socket info
852 char socket_info[128];
853 ret = amdsmi_get_socket_info(sockets[i], 128, socket_info);
854 CHK_AMDSMI_RET(ret)
855 std::cout << "Socket Info: " << socket_info << std::endl;
856
857 // Get the device count available for the socket.
858 uint32_t device_count = 0;
859 ret = amdsmi_get_processor_handles(sockets[i], &device_count, nullptr);
860 CHK_AMDSMI_RET(ret)
861
862 // Allocate the memory for the device handlers on the socket
863 std::vector<amdsmi_processor_handle> processor_handles(device_count);
864 // Get all devices of the socket
865 ret = amdsmi_get_processor_handles(sockets[i],
866 &device_count, &processor_handles[0]);
867 CHK_AMDSMI_RET(ret)
868
869 std::cout << "Processor Count: " << device_count << std::endl;
870
871 // For each device of the socket, get name and temperature.
872 for (uint32_t device_index = 0; device_index < device_count; device_index++) {
873 std::cout << "Device Index: " << device_index << std::endl;
874 std::cout << "SMI gpu #: " << gpu_number << std::endl;
875
876 // Commenting out the code to get CPU socket count and GPU count
877 // Doesn't work on system with no supported CPU sockets
878 #if 0
879 uint32_t cpu_sockets = 0;
880 uint32_t gpus = 0;
881 ret = amdsmi_get_processor_count_from_handles(&processor_handles[device_index], &device_count, &cpu_sockets, nullptr, &gpus);
882 CHK_AMDSMI_RET(ret)
883 std::cout << "CPU socket count: " << cpu_sockets << std::endl;
884 std::cout << "GPU count: " << gpus << std::endl;
885 #endif
886
887 // Commenting out since, not verified to work on all ASICs yet.
888 #if 0
889 amdsmi_name_value_t *pm_metrics = {};
890 uint32_t num_metrics = 0;
891 ret = amdsmi_get_gpu_pm_metrics_info(processor_handles[device_index],
892 &pm_metrics, &num_metrics);
893 const char* err_str;
894 amdsmi_status_code_to_string(ret, &err_str);
895 std::cout << " Output of amdsmi_get_gpu_pm_metrics_info:" << err_str << "\n";
896 if (ret == AMDSMI_STATUS_SUCCESS) {
897 CHK_AMDSMI_RET(ret)
898 std::cout << "\tNumber of PM metrics: " << num_metrics << std::endl;
899 for (uint32_t j = 0; j < num_metrics; j++) {
900 std::cout << "\tPM Metric Name: " << pm_metrics[j].name
901 << ", Value: " << pm_metrics[j].value << std::endl;
902 }
903 }
904 free(pm_metrics);
905
906 // typedef enum {
907 // AMDSMI_REG_XGMI, //!< XGMI registers
908 // AMDSMI_REG_WAFL, //!< WAFL registers
909 // AMDSMI_REG_PCIE, //!< PCIe registers
910 // AMDSMI_REG_USR, //!< Usr registers
911 // AMDSMI_REG_USR1 //!< Usr1 registers
912 // } amdsmi_reg_type_t;
913 std::map<amdsmi_reg_type_t, std::string> reg_type_map = {
914 {AMDSMI_REG_XGMI, "XGMI"},
915 {AMDSMI_REG_WAFL, "WAFL"},
916 {AMDSMI_REG_PCIE, "PCIE"},
917 {AMDSMI_REG_USR, "USR"},
918 {AMDSMI_REG_USR1, "USR1"}
919 };
920
921 for (uint32_t j = static_cast<uint32_t>(AMDSMI_REG_XGMI);
922 j <= static_cast<uint32_t>(AMDSMI_REG_USR1); j++) {
923 amdsmi_name_value_t *reg_metrics = {};
924 amdsmi_reg_type_t reg_type = static_cast<amdsmi_reg_type_t>(j);
925 std::string reg_type_str = "N/A";
926 ret = amdsmi_get_gpu_reg_table_info(processor_handles[device_index],
927 reg_type, &reg_metrics, &num_metrics);
928 if (auto it = reg_type_map.find(reg_type); it != reg_type_map.end()) {
929 reg_type_str = it->second;
930 }
931 // Skipping these for now due to some ASICS having issues
932 if (reg_type == AMDSMI_REG_USR1 || reg_type == AMDSMI_REG_XGMI ||
933 reg_type == AMDSMI_REG_USR) {
934 std::cout << "\tSkipping " << reg_type_str << " registers for now."
935 << std::endl;
936 free(reg_metrics);
937 continue;
938 }
939
940 amdsmi_status_code_to_string(ret, &err_str);
941 std::cout << " Output of amdsmi_get_gpu_reg_table_info(" << gpu_number << ", "
942 << reg_type_str << "): " << err_str << "\n";
943 if (ret == AMDSMI_STATUS_SUCCESS) {
944 CHK_AMDSMI_RET(ret)
945 std::cout << "\tNumber of Register metrics: " << num_metrics << std::endl;
946 for (uint32_t k = 0; k < num_metrics; k++) {
947 if (reg_metrics == nullptr) {
948 std::cout << "\tRegister Number: " << k
949 << ", Type: " << reg_type_str
950 << ", Register Metric Name: N/A, Value: N/A" << std::endl;
951 continue;
952 }
953 if (reg_metrics[k].name == nullptr) {
954 std::cout << "\tRegister Number: " << k
955 << ", Type: " << reg_type_str
956 << ", Register Metric Name: "
957 << (reg_metrics[k].name != nullptr ?
958 reg_metrics[k].name : "N/A")
959 << ", Value: N/A" << std::endl;
960 continue;
961 }
962 std::cout << "\tRegister Number: " << k
963 << ", Type: " << reg_type_str
964 << ", Register Metric Name: "
965 << (reg_metrics[k].name != nullptr ?
966 reg_metrics[k].name : "N/A")
967 << ", Value: " << reg_metrics[k].value << std::endl;
968 }
969 }
970 free(reg_metrics);
971 std::cout << std::endl;
972 }
973 std::cout << std::endl;
974 #endif
975
976 // Get device type. Since the amdsmi is initialized with
977 // AMD_SMI_INIT_AMD_GPUS, the processor_type must be AMDSMI_PROCESSOR_TYPE_AMD_GPU.
978 processor_type_t processor_type = {};
979 ret = amdsmi_get_processor_type(processor_handles[device_index], &processor_type);
980 CHK_AMDSMI_RET(ret)
981
982 if (auto it = processor_type_map.find(processor_type); it != processor_type_map.end()) {
983 std::cout << "\t**Processor Type: " << it->second << std::endl;
984 } else {
985 std::cout << "\t**Processor Type: MAP TYPE UNKNOWN?" << std::endl;
986 }
987 if (processor_type != AMDSMI_PROCESSOR_TYPE_AMD_GPU) {
988 std::cout << "Expect AMDSMI_PROCESSOR_TYPE_AMD_GPU device type!\n";
989 return AMDSMI_STATUS_NOT_SUPPORTED;
990 }
991
992 // Get BDF info
993 amdsmi_bdf_t bdf = {};
994 ret = amdsmi_get_gpu_device_bdf(processor_handles[device_index], &bdf);
995 CHK_AMDSMI_RET(ret)
996 printf(" Output of amdsmi_get_gpu_device_bdf:\n");
997 printf("\tDevice[%d] BDF %04" PRIx64 ":%02" PRIx32 ":%02" PRIx32 ".%" PRIu32 "\n\n", i,
998 static_cast<uint64_t>(bdf.domain_number),
999 static_cast<uint32_t>(bdf.bus_number),
1000 static_cast<uint32_t>(bdf.device_number),
1001 static_cast<uint32_t>(bdf.function_number));
1002
1003 // Get handle from BDF
1004 amdsmi_processor_handle dev_handle;
1005 ret = amdsmi_get_processor_handle_from_bdf(bdf, &dev_handle);
1006 CHK_AMDSMI_RET(ret)
1007
1008 // Get ASIC info
1009 amdsmi_asic_info_t asic_info = {};
1010 ret = amdsmi_get_gpu_asic_info(processor_handles[device_index], &asic_info);
1011 CHK_AMDSMI_RET(ret)
1012 printf(" Output of amdsmi_get_gpu_asic_info:\n");
1013 printf("\tMarket Name: %s\n", asic_info.market_name);
1014 printf("\tDeviceID: 0x%04lx\n", asic_info.device_id);
1015 printf("\tVendorID: 0x%04x\n", asic_info.vendor_id);
1016 printf("\tVendor Name: %s\n", asic_info.vendor_name);
1017 printf("\tSubVendorID: 0x%04x\n", asic_info.subvendor_id);
1018 printf("\tRevisionID: 0x%02x\n", asic_info.rev_id);
1019 printf("\tSubSystemID: 0x%04x\n", asic_info.subsystem_id);
1020 printf("\tAsic serial: 0x%s\n", asic_info.asic_serial);
1021 if (asic_info.oam_id != UINT32_MAX) {
1022 // OAM ID is not supported on all devices
1023 printf("\tOAM ID: %" PRIu32"\n", asic_info.oam_id);
1024 } else {
1025 // OAM ID is not supported on this device
1026 printf("\tOAM ID: N/A\n");
1027 }
1028 printf("\tNum of Computes: %d\n", asic_info.num_of_compute_units);
1029 printf("\tTarget Graphics Version: gfx%lx\n\n", asic_info.target_graphics_version);
1030
1031 bool is_power_management_enabled = false;
1032 ret = amdsmi_is_gpu_power_management_enabled(processor_handles[device_index],
1033 &is_power_management_enabled);
1034 printf(" Output of amdsmi_is_gpu_power_management_enabled:\n");
1035 if (ret != AMDSMI_STATUS_NOT_SUPPORTED) {
1036 CHK_AMDSMI_RET(ret)
1037 }
1038 if (is_power_management_enabled && ret != AMDSMI_STATUS_NOT_SUPPORTED) {
1039 std::cout << "\tPower Management is enabled" << std::endl;
1040 } else {
1041 std::cout << "\tPower Management is disabled" << std::endl;
1042 }
1043
1044
1045 amdsmi_virtualization_mode_t vmode;
1046 ret = amdsmi_get_gpu_virtualization_mode(processor_handles[device_index], &vmode);
1047 if (ret != AMDSMI_STATUS_NOT_SUPPORTED) {
1048 CHK_AMDSMI_RET(ret)
1049 }
1050
1051 if (auto it = virtualization_mode_map.find(vmode);
1052 it != virtualization_mode_map.end()) {
1053 std::cout << "\t**Virtualization Mode: " << it->second << std::endl;
1054 } else {
1055 std::cout << "\t**Virtualization Mode: MAP TYPE UNKNOWN?" << std::endl;
1056 }
1057
1058 // Get VRAM info
1059 amdsmi_vram_info_t vram_info = {};
1060 ret = amdsmi_get_gpu_vram_info(processor_handles[device_index], &vram_info);
1061 if (ret != AMDSMI_STATUS_NOT_SUPPORTED) {
1062 CHK_AMDSMI_RET(ret)
1063 printf(" Output of amdsmi_get_gpu_vram_info:\n");
1064 printf("\tVRAM Size: 0x%lx (%ld) \n", vram_info.vram_size, vram_info.vram_size);
1065 printf("\tBIT Width: 0x%x (%d) \n\n", vram_info.vram_bit_width,
1066 vram_info.vram_bit_width);
1067 printf("\tVRAM max bandwidth: 0x%lx (%lu) \n\n", vram_info.vram_max_bandwidth,
1068 vram_info.vram_max_bandwidth);
1069 } else {
1070 printf("\t**amdsmi_get_gpu_vram_info(): not supported on this device.\n");
1071 }
1072
1073 uint32_t mem_type = AMDSMI_MEM_TYPE_VRAM;
1074 uint64_t total = 0;
1075 ret = amdsmi_get_gpu_memory_total(processor_handles[device_index],
1076 static_cast<amdsmi_memory_type_t>(mem_type), &total);
1077 if (ret != AMDSMI_STATUS_SUCCESS) {
1078 PRINT_AMDSMI_RET(ret)
1079 std::cout << "\t**amdsmi_get_gpu_memory_total(): not supported on this device."
1080 << std::endl;
1081 } else {
1082 CHK_AMDSMI_RET(ret)
1083 std::cout << "\tGPU: " << gpu_number
1084 << "; VRAM TOTAL: " << total / (1024 * 1024) << "MB\n";
1085 }
1086 uint64_t usage = 0;
1087 ret = amdsmi_get_gpu_memory_usage(processor_handles[device_index],
1088 static_cast<amdsmi_memory_type_t>(mem_type), &usage);
1089 if (ret != AMDSMI_STATUS_SUCCESS) {
1090 PRINT_AMDSMI_RET(ret)
1091 std::cout << "\t**amdsmi_get_gpu_memory_usage(): not supported on this device."
1092 << std::endl;
1093 } else {
1094 CHK_AMDSMI_RET(ret)
1095 std::cout << "\tGPU: " << gpu_number
1096 << "; VRAM USED: " << usage / (1024 * 1024) << "MB\n";
1097 }
1098
1099 // Get VBIOS info
1100 amdsmi_vbios_info_t vbios_info = {};
1101 ret = amdsmi_get_gpu_vbios_info(processor_handles[device_index], &vbios_info);
1102 CHK_AMDSMI_RET(ret)
1103 printf(" Output of amdsmi_get_gpu_vbios_info:\n");
1104 printf("\tVBIOS/IFWI Name: %s\n", vbios_info.name);
1105 printf("\tVBIOS/IFWI Build Date: %s\n", vbios_info.build_date);
1106 printf("\tVBIOS/IFWI Part Number: %s\n", vbios_info.part_number);
1107 printf("\tVBIOS/IFWI Version String: %s\n\n", vbios_info.version);
1108 printf("\tVBIOS/IFWI Boot Firmware: %s\n\n", vbios_info.boot_firmware);
1109
1110 // Get Cache info
1111 amdsmi_gpu_cache_info_t cache_info = {};
1112 ret = amdsmi_get_gpu_cache_info(processor_handles[device_index], &cache_info);
1113 CHK_AMDSMI_RET(ret)
1114 printf(" Output of amdsmi_get_gpu_cache_info:\n");
1115 for (unsigned int i = 0 ; i < cache_info.num_cache_types; i++) {
1116 printf("\tCache Level: %d, Cache Size: %d KB, Cache type: 0x%x\n",
1117 cache_info.cache[i].cache_level,
1118 cache_info.cache[i].cache_size,
1119 cache_info.cache[i].cache_properties);
1120 printf("\tMax number CU shared: %d, Number of instances: %d\n",
1121 cache_info.cache[i].max_num_cu_shared,
1122 cache_info.cache[i].num_cache_instance);
1123 }
1124
1125 // Get power measure
1126 amdsmi_power_info_t power_measure = {};
1127 ret = amdsmi_get_power_info(processor_handles[device_index], &power_measure);
1128 printf(" Output of amdsmi_get_power_info:\n");
1129 if (ret != AMDSMI_STATUS_NOT_SUPPORTED) {
1130 CHK_AMDSMI_RET(ret)
1131 printf("\tCurrent GFX Voltage: %ld\n", power_measure.gfx_voltage);
1132 printf("\tAverage socket power: %d\n", power_measure.average_socket_power);
1133 printf("\tGPU Power limit: %d\n\n", power_measure.power_limit);
1134 } else {
1135 printf("\tamdsmi_get_power_info(): not supported on this device.\n");
1136 }
1137
1138 // Get driver version
1139 amdsmi_driver_info_t driver_info;
1140 ret = amdsmi_get_gpu_driver_info(processor_handles[device_index], &driver_info);
1141 CHK_AMDSMI_RET(ret)
1142 printf(" Output of amdsmi_get_gpu_driver_info:\n");
1143 printf("\tDriver name: %s\n", driver_info.driver_name);
1144 printf("\tDriver version: %s\n", driver_info.driver_version);
1145 printf("\tDriver date: %s\n\n", driver_info.driver_date);
1146
1147 // Get device uuid
1148 unsigned int uuid_length = AMDSMI_GPU_UUID_SIZE;
1149 char uuid[AMDSMI_GPU_UUID_SIZE];
1150 ret = amdsmi_get_gpu_device_uuid(processor_handles[device_index], &uuid_length, uuid);
1151 CHK_AMDSMI_RET(ret)
1152 printf(" Output of amdsmi_get_gpu_device_uuid:\n");
1153 printf("\tDevice uuid: %s\n\n", uuid);
1154
1155 // Get engine usage info
1156 amdsmi_engine_usage_t engine_usage = {};
1157 ret = amdsmi_get_gpu_activity(processor_handles[device_index], &engine_usage);
1158 printf(" Output of amdsmi_get_gpu_activity:\n");
1159 if (ret != AMDSMI_STATUS_NOT_SUPPORTED) {
1160 CHK_AMDSMI_RET(ret)
1161 printf("\tAverage GFX Activity: %d\n", engine_usage.gfx_activity);
1162 printf("\tAverage MM Activity: %d\n", engine_usage.mm_activity);
1163 printf("\tAverage UMC Activity: %d\n\n", engine_usage.umc_activity);
1164 } else {
1165 printf("\tamdsmi_get_gpu_activity(): not supported on this device.\n");
1166 }
1167
1168 // Get firmware info
1169 amdsmi_fw_info_t fw_information = {};
1170 char ucode_name[AMDSMI_MAX_STRING_LENGTH];
1171 ret = amdsmi_get_fw_info(processor_handles[device_index], &fw_information);
1172 CHK_AMDSMI_RET(ret)
1173 printf(" Output of amdsmi_get_fw_info:\n");
1174 printf("Number of Microcodes: %d\n", fw_information.num_fw_info);
1175 for (int j = 0; j < fw_information.num_fw_info; j++) {
1176 getFWNameFromId(fw_information.fw_info_list[j].fw_id, ucode_name);
1177 printf(" %s: %ld\n", ucode_name, fw_information.fw_info_list[j].fw_version);
1178 }
1179
1180 // Get GFX clock measurements
1181 amdsmi_clk_info_t gfx_clk_values = {};
1182 ret = amdsmi_get_clock_info(processor_handles[device_index], AMDSMI_CLK_TYPE_GFX,
1183 &gfx_clk_values);
1184 printf(" Output of amdsmi_get_clock_info:\n");
1185 if (ret != AMDSMI_STATUS_NOT_SUPPORTED) {
1186 CHK_AMDSMI_RET(ret)
1187 printf("\tGPU GFX Max Clock: %d\n", gfx_clk_values.max_clk);
1188 printf("\tGPU GFX Current Clock: %d\n", gfx_clk_values.clk);
1189 } else {
1190 printf("\tamdsmi_get_clock_info(AMDSMI_CLK_TYPE_GFX): "
1191 "not supported on this device.\n");
1192 }
1193
1194 // Get MEM clock measurements
1195 amdsmi_clk_info_t mem_clk_values = {};
1196 ret = amdsmi_get_clock_info(processor_handles[device_index], AMDSMI_CLK_TYPE_MEM,
1197 &mem_clk_values);
1198 if (ret != AMDSMI_STATUS_NOT_SUPPORTED) {
1199 CHK_AMDSMI_RET(ret)
1200 printf("\tGPU MEM Max Clock: %d\n", mem_clk_values.max_clk);
1201 printf("\tGPU MEM Current Clock: %d\n\n", mem_clk_values.clk);
1202 } else {
1203 printf("\tamdsmi_get_clock_info(AMDSMI_CLK_TYPE_MEM): "
1204 "not supported on this device.\n");
1205 }
1206
1207 // Get PCIe status
1208 amdsmi_pcie_info_t pcie_info = {};
1209 ret = amdsmi_get_pcie_info(processor_handles[device_index], &pcie_info);
1210 printf(" Output of amdsmi_get_pcie_info:\n");
1211 if (ret != AMDSMI_STATUS_NOT_SUPPORTED) {
1212 CHK_AMDSMI_RET(ret)
1213 printf("\tCurrent PCIe lanes: %d\n", pcie_info.pcie_metric.pcie_width);
1214 printf("\tCurrent PCIe speed: %d\n", pcie_info.pcie_metric.pcie_speed);
1215 printf("\tCurrent PCIe Interface Version: %d\n",
1216 pcie_info.pcie_static.pcie_interface_version);
1217 printf("\tPCIe slot type: %d\n", pcie_info.pcie_static.slot_type);
1218 printf("\tPCIe max lanes: %d\n", pcie_info.pcie_static.max_pcie_width);
1219 printf("\tPCIe max speed: %d\n", pcie_info.pcie_static.max_pcie_speed);
1220
1221 // additional pcie related metrics
1222 printf("\tPCIe bandwidth: %u\n", pcie_info.pcie_metric.pcie_bandwidth);
1223 printf("\tPCIe replay count: %" PRIu64 "\n",
1224 pcie_info.pcie_metric.pcie_replay_count);
1225 printf("\tPCIe L0 recovery count: %" PRIu64 "\n",
1226 pcie_info.pcie_metric.pcie_l0_to_recovery_count);
1227 printf("\tPCIe rollover count: %" PRIu64 "\n",
1228 pcie_info.pcie_metric.pcie_replay_roll_over_count);
1229 printf("\tPCIe nak received count: %" PRIu64 "\n",
1230 pcie_info.pcie_metric.pcie_nak_received_count);
1231 printf("\tPCIe nak sent count: %" PRIu64 "\n",
1232 pcie_info.pcie_metric.pcie_nak_sent_count);
1233 }
1234
1235 // Get VRAM temperature limit
1236 int64_t temperature = 0;
1237 ret = amdsmi_get_temp_metric(
1238 processor_handles[device_index], AMDSMI_TEMPERATURE_TYPE_VRAM,
1239 AMDSMI_TEMP_CRITICAL, &temperature);
1240 if (ret != AMDSMI_STATUS_NOT_SUPPORTED) {
1241 CHK_AMDSMI_RET(ret)
1242 printf(" Output of amdsmi_get_temp_metric:\n");
1243 printf("\tGPU VRAM temp limit: %ld\n", temperature);
1244 } else {
1245 printf("\tamdsmi_get_temp_metric(AMDSMI_TEMPERATURE_TYPE_VRAM): "
1246 "not supported on this device.\n");
1247 }
1248
1249 // Get GFX temperature limit
1250 ret = amdsmi_get_temp_metric(
1251 processor_handles[device_index], AMDSMI_TEMPERATURE_TYPE_EDGE,
1252 AMDSMI_TEMP_CRITICAL, &temperature);
1253 if (ret != AMDSMI_STATUS_NOT_SUPPORTED) {
1254 CHK_AMDSMI_RET(ret)
1255 printf("\tGPU GFX temp limit: %ld\n\n", temperature);
1256 } else {
1257 printf("\tamdsmi_get_temp_metric(AMDSMI_TEMPERATURE_TYPE_EDGE): "
1258 "not supported on this device.\n");
1259 }
1260
1261 // Get temperature measurements
1262 // amdsmi_temperature_t edge_temp, hotspot_temp, vram_temp,
1263 // plx_temp;
1264 int64_t temp_measurements[AMDSMI_TEMPERATURE_TYPE__MAX + 1];
1265 amdsmi_temperature_type_t temp_types[4] = {
1266 AMDSMI_TEMPERATURE_TYPE_EDGE, AMDSMI_TEMPERATURE_TYPE_HOTSPOT,
1267 AMDSMI_TEMPERATURE_TYPE_VRAM, AMDSMI_TEMPERATURE_TYPE_PLX};
1268 for (const auto &temp_type : temp_types) {
1269 ret = amdsmi_get_temp_metric(
1270 processor_handles[device_index], temp_type,
1271 AMDSMI_TEMP_CURRENT,
1272 &temp_measurements[static_cast<int>(temp_type)]);
1273 if (ret != AMDSMI_STATUS_NOT_SUPPORTED) {
1274 CHK_AMDSMI_RET(ret)
1275 }
1276 }
1277 printf(" Output of amdsmi_get_temp_metric:\n");
1278 printf("\tGPU Edge temp measurement: %ld\n",
1279 temp_measurements[AMDSMI_TEMPERATURE_TYPE_EDGE]);
1280 printf("\tGPU Hotspot temp measurement: %ld\n",
1281 temp_measurements[AMDSMI_TEMPERATURE_TYPE_HOTSPOT]);
1282 printf("\tGPU VRAM temp measurement: %ld\n",
1283 temp_measurements[AMDSMI_TEMPERATURE_TYPE_VRAM]);
1284 printf("\tGPU PLX temp measurement: %ld\n\n",
1285 temp_measurements[AMDSMI_TEMPERATURE_TYPE_PLX]);
1286
1287 // Get RAS features enabled
1288 char block_names[14][10] = {"UMC", "SDMA", "GFX", "MMHUB",
1289 "ATHUB", "PCIE_BIF", "HDP", "XGMI_WAFL",
1290 "DF", "SMN", "SEM", "MP0",
1291 "MP1", "FUSE"};
1292 char status_names[7][10] = {"NONE", "DISABLED", "PARITY",
1293 "SING_C", "MULT_UC", "POISON",
1294 "ENABLED"};
1295 amdsmi_ras_err_state_t state = {};
1296 int index = 0;
1297 printf(" Output of amdsmi_get_gpu_ras_block_features_enabled:\n");
1298 for (auto block = AMDSMI_GPU_BLOCK_FIRST;
1299 block <= AMDSMI_GPU_BLOCK_LAST;
1300 block = (amdsmi_gpu_block_t)(block * 2)) {
1301 ret = amdsmi_get_gpu_ras_block_features_enabled(processor_handles[device_index], block,
1302 &state);
1303 if (ret != AMDSMI_STATUS_API_FAILED && ret != AMDSMI_STATUS_NOT_SUPPORTED) {
1304 CHK_AMDSMI_RET(ret)
1305 }
1306
1307 printf("\tBlock: %s\n", block_names[index]);
1308 printf("\tStatus: %s\n", status_names[state]);
1309 index++;
1310 }
1311 printf("\n");
1312
1313 // Get bad pages
1314 char bad_page_status_names[3][15] = {"RESERVED", "PENDING",
1315 "UNRESERVABLE"};
1316 uint32_t num_pages = 0;
1317 ret = amdsmi_get_gpu_bad_page_info(processor_handles[device_index], &num_pages,
1318 nullptr);
1319 if (ret != AMDSMI_STATUS_NOT_SUPPORTED) {
1320 CHK_AMDSMI_RET(ret)
1321 }
1322 printf(" Output of amdsmi_get_gpu_bad_page_info:\n");
1323 if (!num_pages) {
1324 printf("\tNo bad pages found.\n");
1325 } else {
1326 std::vector<amdsmi_retired_page_record_t> bad_page_info(num_pages);
1327 ret = amdsmi_get_gpu_bad_page_info(processor_handles[device_index], &num_pages,
1328 bad_page_info.data());
1329 CHK_AMDSMI_RET(ret)
1330 for (uint32_t page_it = 0; page_it < num_pages; page_it += 1) {
1331 printf(" Page[%d]\n", page_it);
1332 printf("\tAddress: %lu\n",
1333 bad_page_info[page_it].page_address);
1334 printf("\tSize: %lu\n", bad_page_info[page_it].page_size);
1335 printf(
1336 "\tStatus: %s\n",
1337 bad_page_status_names[bad_page_info[page_it].status]);
1338 }
1339 }
1340 printf("\n");
1341
1342 // Get ECC error counts
1343 amdsmi_error_count_t err_cnt_info = {};
1344 ret = amdsmi_get_gpu_total_ecc_count(processor_handles[device_index], &err_cnt_info);
1345 if (ret != AMDSMI_STATUS_NOT_SUPPORTED) {
1346 CHK_AMDSMI_RET(ret)
1347 }
1348 printf(" Output of amdsmi_get_gpu_total_ecc_count:\n");
1349 printf("\tCorrectable errors: %lu\n", err_cnt_info.correctable_count);
1350 printf("\tUncorrectable errors: %lu\n\n",
1351 err_cnt_info.uncorrectable_count);
1352
1353 uint32_t num_process = 0;
1354 ret = amdsmi_get_gpu_process_list(processor_handles[device_index], &num_process, nullptr);
1355 CHK_AMDSMI_RET(ret)
1356 if (!num_process) {
1357 printf("amdsmi_get_gpu_process_list(): No processes found.\n\n");
1358 } else {
1359 std::cout << "Processes found: " << num_process << "\n";
1360 amdsmi_proc_info_t process_info_list[num_process];
1361 amdsmi_proc_info_t process = {};
1362 uint64_t mem = 0, gtt_mem = 0, cpu_mem = 0, vram_mem = 0;
1363 uint64_t gfx = 0, enc = 0;
1364 uint32_t cu_occupancy = 0;
1365 char bdf_str[64] = {0};
1366 snprintf(bdf_str, sizeof(bdf_str), "%04" PRIx64 ":%02" PRIx32 ":%02" PRIx32 ".%" PRIu32,
1367 static_cast<uint64_t>(bdf.domain_number),
1368 static_cast<uint32_t>(bdf.bus_number),
1369 static_cast<uint32_t>(bdf.device_number),
1370 static_cast<uint32_t>(bdf.function_number));
1371 ret = amdsmi_get_gpu_process_list(processor_handles[device_index], &num_process, process_info_list);
1372 std::cout << "Allocation size for process list: " << num_process << "\n";
1373 CHK_AMDSMI_RET(ret);
1374 for (auto idx = uint32_t(0); idx < num_process; ++idx) {
1375 process = static_cast<amdsmi_proc_info_t>(process_info_list[idx]);
1376 printf("\t *Process id: %d / Name: %s / VRAM: %ld \n", process.pid, process.name, process.memory_usage.vram_mem);
1377 }
1378
1379 printf("+=======+==================+============+=============="
1380 "+=============+=============+=============+============"
1381 "==+=========================================+\n");
1382 printf(
1383 "| pid | name | user | gpu bdf | "
1384 "fb usage | gtt memory | cpu memory | vram memory | "
1385 "engine usage (ns) | cu occupancy |\n");
1386 printf("| | | | "
1387 "| | | | "
1388 " | gfx enc |\n");
1389 printf("+=======+"
1390 "+=============+=============+=============+============"
1391 "==+=========================================+\n");
1392 for (int it = 0; it < static_cast<int>(num_process); it++) {
1393 char command[30];
1394 struct passwd *pwd = nullptr;
1395 struct stat st;
1396
1397 snprintf(command, sizeof(command), "/proc/%d", process_info_list[it].pid);
1398 if (stat(command, &st))
1399 continue;
1400 pwd = getpwuid(st.st_uid);
1401 if (!pwd)
1402 printf("| %5d | %16s | %10d | %s | %7ld KB | %7ld KB "
1403 "| %7ld KB | %7ld KB | %lu %lu | %u |\n",
1404 process_info_list[it].pid, process_info_list[it].name, st.st_uid,
1405 bdf_str, process_info_list[it].mem / 1024,
1406 process_info_list[it].memory_usage.gtt_mem / 1024,
1407 process_info_list[it].memory_usage.cpu_mem / 1024,
1408 process_info_list[it].memory_usage.vram_mem / 1024,
1409 process_info_list[it].engine_usage.gfx,
1410 process_info_list[it].engine_usage.enc,
1411 process_info_list[it].cu_occupancy);
1412 else
1413 printf("| %5d | %16s | %10s | %s | %7ld KB | %7ld KB "
1414 "| %7ld KB | %7ld KB | %lu %lu | %u |\n",
1415 process_info_list[it].pid, process_info_list[it].name,
1416 pwd->pw_name, bdf_str, process_info_list[it].mem / 1024,
1417 process_info_list[it].memory_usage.gtt_mem / 1024,
1418 process_info_list[it].memory_usage.cpu_mem / 1024,
1419 process_info_list[it].memory_usage.vram_mem / 1024,
1420 process_info_list[it].engine_usage.gfx,
1421 process_info_list[it].engine_usage.enc,
1422 process_info_list[it].cu_occupancy);
1423
1424 mem += process_info_list[it].mem / 1024;
1425 gtt_mem += process_info_list[it].memory_usage.gtt_mem / 1024;
1426 cpu_mem += process_info_list[it].memory_usage.cpu_mem / 1024;
1427 vram_mem += process_info_list[it].memory_usage.vram_mem / 1024;
1428 gfx = process_info_list[it].engine_usage.gfx;
1429 enc = process_info_list[it].engine_usage.enc;
1430 cu_occupancy = process_info_list[it].cu_occupancy;
1431 printf(
1432 "+-------+------------------+------------+-------------"
1433 "-+-------------+-------------+-------------+----------"
1434 "----+-----------------------------------------+\n");
1435 }
1436 // TODO: To remove compiler warning, the last 3 values in this printf were
1437 // set to 0L. Need to find out what these values need to be.
1438 printf("| TOTAL:| %s | %7ld "
1439 "KB | %7ld KB | %7ld KB | %7ld KB | %lu %lu | %u |\n",
1440 bdf_str, mem, gtt_mem, cpu_mem, vram_mem, gfx,
1441 enc, cu_occupancy);
1442 printf("+=======+==================+============+=============="
1443 "+=============+=============+=============+============"
1444 "=+==========================================+\n");
1445 }
1446
1447 // Get device name
1448 amdsmi_board_info_t board_info = {};
1449 ret = amdsmi_get_gpu_board_info(processor_handles[device_index], &board_info);
1450 CHK_AMDSMI_RET(ret)
1451 printf(" Output of amdsmi_get_gpu_board_info:\n");
1452 std::cout << "\tdevice [" << device_index
1453 << "]\n\t\tProduct name: " << board_info.product_name
1454 << "\n"
1455 << "\t\tModel Number: " << board_info.model_number
1456 << "\n"
1457 << "\t\tBoard Serial: " << board_info.product_serial
1458 << "\n"
1459 << "\t\tManufacturer Name: " << board_info.manufacturer_name
1460 << "\n\n";
1461
1462 // Get temperature
1463 int64_t val_i64 = 0;
1464 ret = amdsmi_get_temp_metric(processor_handles[device_index], AMDSMI_TEMPERATURE_TYPE_EDGE,
1465 AMDSMI_TEMP_CURRENT, &val_i64);
1466 if (ret != AMDSMI_STATUS_NOT_SUPPORTED) {
1467 CHK_AMDSMI_RET(ret)
1468 }
1469 printf(" Output of amdsmi_get_temp_metric:\n");
1470 std::cout << "\t\tTemperature: " << std::dec << val_i64 << "C"
1471 << "\n\n";
1472
1473 // Get frame buffer
1474 amdsmi_vram_usage_t vram_usage = {};
1475 ret = amdsmi_get_gpu_vram_usage(processor_handles[device_index], &vram_usage);
1476 CHK_AMDSMI_RET(ret)
1477 printf(" Output of amdsmi_get_gpu_vram_usage:\n");
1478 std::cout << "\t\tFrame buffer usage (MB): " << vram_usage.vram_used
1479 << "/" << vram_usage.vram_total << "\n\n";
1480
1481 amdsmi_power_cap_info_t cap_info = {};
1482 ret = amdsmi_get_power_cap_info(processor_handles[device_index], 0, &cap_info);
1483 if (ret != AMDSMI_STATUS_NOT_SUPPORTED) {
1484 CHK_AMDSMI_RET(ret)
1485 printf(" Output of amdsmi_get_power_cap_info:\n");
1486 std::cout << "\t\t Power Cap: " << cap_info.power_cap
1487 << " uW\n";
1488 std::cout << "\t\t Default Power Cap: " << cap_info.default_power_cap
1489 << " uW\n\n";
1490 std::cout << "\t\t Dpm Cap: " << cap_info.dpm_cap
1491 << " MHz\n\n";
1492 std::cout << "\t\t Min Power Cap: " << cap_info.min_power_cap
1493 << " uW\n\n";
1494 std::cout << "\t\t Max Power Cap: " << cap_info.max_power_cap
1495 << " uW\n\n";
1496 } else {
1497 std::cout << "\tamdsmi_get_power_cap_info(): not supported on this device.\n";
1498 }
1499
1500 /// Get GPU Metrics info
1501 std::cout << "\n\n";
1502 amdsmi_gpu_metrics_t smu;
1503 ret = amdsmi_get_gpu_metrics_info(processor_handles[device_index], &smu);
1504 if (ret == AMDSMI_STATUS_NOT_SUPPORTED) {
1505 std::cout << "\tamdsmi_get_gpu_metrics_info(): not supported on this device.\n";
1506 } else { // START GPU METRICS OUTPUTS
1507 CHK_AMDSMI_RET(ret)
1508 printf(" Output of amdsmi_get_gpu_metrics_info:\n");
1509 printf("\tDevice[%d] BDF %04" PRIx64 ":%02" PRIx32 ":%02" PRIx32 ".%" PRIu32 "\n\n",
1510 i, static_cast<uint64_t>(bdf.domain_number),
1511 static_cast<uint32_t>(bdf.bus_number),
1512 static_cast<uint32_t>(bdf.device_number),
1513 static_cast<uint32_t>(bdf.function_number));
1514
1515 std::cout << "METRIC TABLE HEADER:\n";
1516 std::cout << "structure_size=" << std::dec
1517 << static_cast<uint16_t>(smu.common_header.structure_size) << "\n";
1518 std::cout << "\tformat_revision=" << std::dec
1519 << static_cast<uint16_t>(smu.common_header.format_revision) << "\n";
1520 std::cout << "\tcontent_revision=" << std::dec
1521 << static_cast<uint16_t>(smu.common_header.content_revision) << "\n";
1522
1523 std::cout << "\n";
1524 std::cout << "TIME STAMPS (ns):\n";
1525 std::cout << std::dec << "\tsystem_clock_counter=" << smu.system_clock_counter << "\n";
1526 std::cout << "\tfirmware_timestamp (10ns resolution)=" << std::dec << smu.firmware_timestamp
1527 << "\n";
1528
1529 std::cout << "\n";
1530 std::cout << "TEMPERATURES (C):\n";
1531 std::cout << std::dec << "\ttemperature_edge= " << smu.temperature_edge << "\n";
1532 std::cout << std::dec << "\ttemperature_hotspot= " << smu.temperature_hotspot << "\n";
1533 std::cout << std::dec << "\ttemperature_mem= " << smu.temperature_mem << "\n";
1534 std::cout << std::dec << "\ttemperature_vrgfx= " << smu.temperature_vrgfx << "\n";
1535 std::cout << std::dec << "\ttemperature_vrsoc= " << smu.temperature_vrsoc << "\n";
1536 std::cout << std::dec << "\ttemperature_vrmem= " << smu.temperature_vrmem << "\n";
1537 std::cout << "\ttemperature_hbm = [";
1538 auto idx = 0;
1539 for (const auto& temp : smu.temperature_hbm) {
1540 std::cout << temp;
1541 if ((idx + 1) != static_cast<int>(std::size(smu.temperature_hbm))) {
1542 std::cout << ", ";
1543 } else {
1544 std::cout << "]\n";
1545 }
1546 ++idx;
1547 }
1548
1549 std::cout << "\n";
1550 std::cout << "UTILIZATION (%):\n";
1551 std::cout << std::dec << "\taverage_gfx_activity=" << smu.average_gfx_activity << "\n";
1552 std::cout << std::dec << "\taverage_umc_activity=" << smu.average_umc_activity << "\n";
1553 std::cout << std::dec << "\taverage_mm_activity=" << smu.average_mm_activity << "\n";
1554 std::cout << std::dec << "\tvcn_activity= [";
1555 idx = 0;
1556 for (const auto& temp : smu.vcn_activity) {
1557 std::cout << temp;
1558 if ((idx + 1) != static_cast<int>(std::size(smu.vcn_activity))) {
1559 std::cout << ", ";
1560 } else {
1561 std::cout << "]\n";
1562 }
1563 ++idx;
1564 }
1565
1566 std::cout << "\n";
1567 std::cout << std::dec << "\tjpeg_activity= [";
1568 idx = 0;
1569 for (const auto& temp : smu.jpeg_activity) {
1570 std::cout << temp;
1571 if ((idx + 1) != static_cast<int>(std::size(smu.jpeg_activity))) {
1572 std::cout << ", ";
1573 } else {
1574 std::cout << "]\n";
1575 }
1576 ++idx;
1577 }
1578
1579 std::cout << "\n";
1580 std::cout << "POWER (W)/ENERGY (15.259uJ per 1ns):\n";
1581 std::cout << std::dec << "\taverage_socket_power=" << smu.average_socket_power << "\n";
1582 std::cout << std::dec << "\tcurrent_socket_power=" << smu.current_socket_power << "\n";
1583 std::cout << std::dec << "\tenergy_accumulator=" << smu.energy_accumulator << "\n";
1584
1585 std::cout << "\n";
1586 std::cout << "AVG CLOCKS (MHz):\n";
1587 std::cout << std::dec << "\taverage_gfxclk_frequency=" << smu.average_gfxclk_frequency
1588 << "\n";
1589 std::cout << std::dec << "\taverage_gfxclk_frequency=" << smu.average_gfxclk_frequency
1590 << "\n";
1591 std::cout << std::dec << "\taverage_uclk_frequency=" << smu.average_uclk_frequency << "\n";
1592 std::cout << std::dec << "\taverage_vclk0_frequency=" << smu.average_vclk0_frequency
1593 << "\n";
1594 std::cout << std::dec << "\taverage_dclk0_frequency=" << smu.average_dclk0_frequency
1595 << "\n";
1596 std::cout << std::dec << "\taverage_vclk1_frequency=" << smu.average_vclk1_frequency
1597 << "\n";
1598 std::cout << std::dec << "\taverage_dclk1_frequency=" << smu.average_dclk1_frequency
1599 << "\n";
1600
1601 std::cout << "\n";
1602 std::cout << "CURRENT CLOCKS (MHz):\n";
1603 std::cout << std::dec << "\tcurrent_gfxclk=" << smu.current_gfxclk << "\n";
1604 std::cout << std::dec << "\tcurrent_gfxclks= [";
1605 idx = 0;
1606 for (const auto& temp : smu.current_gfxclks) {
1607 std::cout << temp;
1608 if ((idx + 1) != static_cast<int>(std::size(smu.current_gfxclks))) {
1609 std::cout << ", ";
1610 } else {
1611 std::cout << "]\n";
1612 }
1613 ++idx;
1614 }
1615
1616 std::cout << std::dec << "\tcurrent_socclk=" << smu.current_socclk << "\n";
1617 std::cout << std::dec << "\tcurrent_socclks= [";
1618 idx = 0;
1619 for (const auto& temp : smu.current_socclks) {
1620 std::cout << temp;
1621 if ((idx + 1) != static_cast<int>(std::size(smu.current_socclks))) {
1622 std::cout << ", ";
1623 } else {
1624 std::cout << "]\n";
1625 }
1626 ++idx;
1627 }
1628
1629 std::cout << std::dec << "\tcurrent_uclk=" << smu.current_uclk << "\n";
1630 std::cout << std::dec << "\tcurrent_vclk0=" << smu.current_vclk0 << "\n";
1631 std::cout << std::dec << "\tcurrent_vclk0s= [";
1632 idx = 0;
1633 for (const auto& temp : smu.current_vclk0s) {
1634 std::cout << temp;
1635 if ((idx + 1) != static_cast<int>(std::size(smu.current_vclk0s))) {
1636 std::cout << ", ";
1637 } else {
1638 std::cout << "]\n";
1639 }
1640 ++idx;
1641 }
1642
1643 std::cout << std::dec << "\tcurrent_dclk0=" << smu.current_dclk0 << "\n";
1644 std::cout << std::dec << "\tcurrent_dclk0s= [";
1645 idx = 0;
1646 for (const auto& temp : smu.current_dclk0s) {
1647 std::cout << temp;
1648 if ((idx + 1) != static_cast<int>(std::size(smu.current_dclk0s))) {
1649 std::cout << ", ";
1650 } else {
1651 std::cout << "]\n";
1652 }
1653 ++idx;
1654 }
1655
1656 std::cout << std::dec << "\tcurrent_vclk1=" << smu.current_vclk1 << "\n";
1657 std::cout << std::dec << "\tcurrent_dclk1=" << smu.current_dclk1 << "\n";
1658
1659 std::cout << "\n";
1660 std::cout << "TROTTLE STATUS:\n";
1661 std::cout << std::dec << "\tthrottle_status=" << smu.throttle_status << "\n";
1662
1663 std::cout << "\n";
1664 std::cout << "FAN SPEED:\n";
1665 std::cout << std::dec << "\tcurrent_fan_speed=" << smu.current_fan_speed << "\n";
1666
1667 std::cout << "\n";
1668 std::cout << "LINK WIDTH (number of lanes) /SPEED (0.1 GT/s):\n";
1669 std::cout << "\tpcie_link_width=" << smu.pcie_link_width << "\n";
1670 std::cout << "\tpcie_link_speed=" << smu.pcie_link_speed << "\n";
1671 std::cout << "\txgmi_link_width=" << smu.xgmi_link_width << "\n";
1672 std::cout << "\txgmi_link_speed=" << smu.xgmi_link_speed << "\n";
1673
1674 std::cout << "\n";
1675 std::cout << "Utilization Accumulated(%):\n";
1676 std::cout << "\tgfx_activity_acc=" << std::dec << smu.gfx_activity_acc << "\n";
1677 std::cout << "\tmem_activity_acc=" << std::dec << smu.mem_activity_acc << "\n";
1678
1679 std::cout << "\n";
1680 std::cout << "XGMI ACCUMULATED DATA TRANSFER SIZE (KB):\n";
1681 std::cout << std::dec << "\txgmi_read_data_acc= [";
1682 idx = 0;
1683 for (const auto& temp : smu.xgmi_read_data_acc) {
1684 std::cout << temp;
1685 if ((idx + 1) != static_cast<int>(std::size(smu.xgmi_read_data_acc))) {
1686 std::cout << ", ";
1687 } else {
1688 std::cout << "]\n";
1689 }
1690 ++idx;
1691 }
1692
1693 std::cout << std::dec << "\txgmi_write_data_acc= [";
1694 idx = 0;
1695 for (const auto& temp : smu.xgmi_write_data_acc) {
1696 std::cout << temp;
1697 if ((idx + 1) != static_cast<int>(std::size(smu.xgmi_write_data_acc))) {
1698 std::cout << ", ";
1699 } else {
1700 std::cout << "]\n";
1701 }
1702 ++idx;
1703 }
1704
1705 std::cout << std::dec << "\txgmi_link_status= [";
1706 idx = 0;
1707 for (const auto& temp : smu.xgmi_link_status) {
1708 std::cout << temp;
1709 if ((idx + 1) != static_cast<int>(std::size(smu.xgmi_link_status))) {
1710 std::cout << ", ";
1711 } else {
1712 std::cout << "]\n";
1713 }
1714 ++idx;
1715 }
1716
1717 // Voltage (mV)
1718 std::cout << "\tvoltage_soc = " << std::dec << smu.voltage_soc << "\n";
1719 std::cout << "\tvoltage_gfx = " << std::dec << smu.voltage_gfx << "\n";
1720 std::cout << "\tvoltage_mem = " << std::dec << smu.voltage_mem << "\n";
1721
1722 std::cout << "\tindep_throttle_status = " << std::dec << smu.indep_throttle_status << "\n";
1723
1724 // Clock Lock Status. Each bit corresponds to clock instance
1725 std::cout << "\tgfxclk_lock_status (in hex) = " << std::hex
1726 << smu.gfxclk_lock_status << std::dec <<"\n";
1727
1728 // Bandwidth (GB/sec)
1729 std::cout << "\tpcie_bandwidth_acc=" << std::dec << smu.pcie_bandwidth_acc << "\n";
1730 std::cout << "\tpcie_bandwidth_inst=" << std::dec << smu.pcie_bandwidth_inst << "\n";
1731
1732 // VRAM max bandwidth at max memory clock
1733 std::cout << "\tvram_max_bandwidth=" << std::dec << smu.vram_max_bandwidth << "\n";
1734
1735 // Counts
1736 std::cout << "\tpcie_l0_to_recov_count_acc= " << std::dec << smu.pcie_l0_to_recov_count_acc
1737 << "\n";
1738 std::cout << "\tpcie_replay_count_acc= " << std::dec << smu.pcie_replay_count_acc << "\n";
1739 std::cout << "\tpcie_replay_rover_count_acc= " << std::dec
1740 << smu.pcie_replay_rover_count_acc << "\n";
1741 std::cout << "\tpcie_nak_sent_count_acc= " << std::dec << smu.pcie_nak_sent_count_acc
1742 << "\n";
1743 std::cout << "\tpcie_nak_rcvd_count_acc= " << std::dec << smu.pcie_nak_rcvd_count_acc
1744 << "\n";
1745
1746 // Accumulation cycle counter
1747 // Accumulated throttler residencies
1748 std::cout << "\n";
1749 std::cout << "RESIDENCY ACCUMULATION / COUNTER:\n";
1750 std::cout << "\taccumulation_counter = " << std::dec << smu.accumulation_counter << "\n";
1751 std::cout << "\tprochot_residency_acc = " << std::dec << smu.prochot_residency_acc << "\n";
1752 std::cout << "\tppt_residency_acc = " << std::dec << smu.ppt_residency_acc << "\n";
1753 std::cout << "\tsocket_thm_residency_acc = " << std::dec << smu.socket_thm_residency_acc
1754 << "\n";
1755 std::cout << "\tvr_thm_residency_acc = " << std::dec << smu.vr_thm_residency_acc
1756 << "\n";
1757 std::cout << "\thbm_thm_residency_acc = " << std::dec << smu.hbm_thm_residency_acc << "\n";
1758
1759 // Number of current partitions
1760 std::cout << "\tnum_partition = " << std::dec << smu.num_partition << "\n";
1761
1762 // PCIE other end recovery counter
1763 std::cout << "\tpcie_lc_perf_other_end_recovery = "
1764 << std::dec << smu.pcie_lc_perf_other_end_recovery << "\n";
1765
1766 idx = 0;
1767 auto idy = 0;
1768 std::cout << "\txcp_stats.gfx_busy_inst: " << "\n";
1769 for (auto& row : smu.xcp_stats) {
1770 std::cout << "\t XCP [" << idx << "] : [";
1771 for (auto& col : row.gfx_busy_inst) {
1772 if ((idy + 1) != static_cast<int>(std::size(row.gfx_busy_inst))) {
1773 std::cout << col << ", ";
1774 } else {
1775 std::cout << col;
1776 }
1777 idy++;
1778 }
1779 std::cout << "]\n";
1780 idy = 0;
1781 idx++;
1782 }
1783
1784 idx = 0;
1785 idy = 0;
1786 std::cout << "\txcp_stats.vcn_busy: " << "\n";
1787 for (auto& row : smu.xcp_stats) {
1788 std::cout << "\t XCP [" << idx << "] : [";
1789 for (auto& col : row.vcn_busy) {
1790 if ((idy + 1) != static_cast<int>(std::size(row.vcn_busy))) {
1791 std::cout << col << ", ";
1792 } else {
1793 std::cout << col;
1794 }
1795 idy++;
1796 }
1797 std::cout << "]\n";
1798 idy = 0;
1799 idx++;
1800 }
1801
1802 idx = 0;
1803 idy = 0;
1804 std::cout << "\txcp_stats.jpeg_busy: " << "\n";
1805 for (auto& row : smu.xcp_stats) {
1806 std::cout << "\t XCP [" << idx << "] : [";
1807 for (auto& col : row.jpeg_busy) {
1808 if ((idy + 1) != static_cast<int>(std::size(row.jpeg_busy))) {
1809 std::cout << col << ", ";
1810 } else {
1811 std::cout << col;
1812 }
1813 idy++;
1814 }
1815 std::cout << "]\n";
1816 idy = 0;
1817 idx++;
1818 }
1819
1820 idx = 0;
1821 idy = 0;
1822 std::cout << "\txcp_stats.gfx_busy_acc: " << "\n";
1823 for (auto& row : smu.xcp_stats) {
1824 std::cout << "\t XCP [" << idx << "] : [";
1825 for (auto& col : row.gfx_busy_acc) {
1826 if ((idy + 1) != static_cast<int>(std::size(row.gfx_busy_acc))) {
1827 std::cout << col << ", ";
1828 } else {
1829 std::cout << col;
1830 }
1831 idy++;
1832 }
1833 std::cout << "]\n";
1834 idy = 0;
1835 idx++;
1836 }
1837
1838 idx = 0;
1839 idy = 0;
1840 std::cout << "\txcp_stats.gfx_below_host_limit_acc: " << "\n";
1841 for (auto& row : smu.xcp_stats) {
1842 std::cout << "\t XCP [" << idx << "] : [";
1843 for (auto& col : row.gfx_below_host_limit_acc) {
1844 if ((idy + 1) != static_cast<int>(std::size(row.gfx_below_host_limit_acc))) {
1845 std::cout << col << ", ";
1846 } else {
1847 std::cout << col;
1848 }
1849 idy++;
1850 }
1851 std::cout << "]\n";
1852 idy = 0;
1853 idx++;
1854 }
1855
1856 /*New scp stats v1.8*/
1857 idx = 0;
1858 idy = 0;
1859 std::cout << "\txcp_stats.gfx_below_host_limit_ppt_acc: " << "\n";
1860 for (auto& row : smu.xcp_stats) {
1861 std::cout << "\t XCP [" << idx << "] : [";
1862 for (auto& col : row.gfx_below_host_limit_ppt_acc) {
1863 if ((idy + 1) != static_cast<int>(
1864 std::size(row.gfx_below_host_limit_ppt_acc))) {
1865 std::cout << col << ", ";
1866 } else {
1867 std::cout << col;
1868 }
1869 idy++;
1870 }
1871 std::cout << "]\n";
1872 idy = 0;
1873 idx++;
1874 }
1875
1876 idx = 0;
1877 idy = 0;
1878 std::cout << "\txcp_stats.gfx_below_host_limit_thm_acc: " << "\n";
1879 for (auto& row : smu.xcp_stats) {
1880 std::cout << "\t XCP [" << idx << "] : [";
1881 for (auto& col : row.gfx_below_host_limit_thm_acc) {
1882 if ((idy + 1) != static_cast<int>(
1883 std::size(row.gfx_below_host_limit_thm_acc))) {
1884 std::cout << col << ", ";
1885 } else {
1886 std::cout << col;
1887 }
1888 idy++;
1889 }
1890 std::cout << "]\n";
1891 idy = 0;
1892 idx++;
1893 }
1894
1895 idx = 0;
1896 idy = 0;
1897 std::cout << "\txcp_stats.gfx_low_utilization_acc: " << "\n";
1898 for (auto& row : smu.xcp_stats) {
1899 std::cout << "\t XCP [" << idx << "] : [";
1900 for (auto& col : row.gfx_low_utilization_acc) {
1901 if ((idy + 1) != static_cast<int>(std::size(row.gfx_low_utilization_acc))) {
1902 std::cout << col << ", ";
1903 } else {
1904 std::cout << col;
1905 }
1906 idy++;
1907 }
1908 std::cout << "]\n";
1909 idy = 0;
1910 idx++;
1911 }
1912
1913 idx = 0;
1914 idy = 0;
1915 std::cout << "\txcp_stats.gfx_below_host_limit_total_acc: " << "\n";
1916 for (auto& row : smu.xcp_stats) {
1917 std::cout << "\t XCP [" << idx << "] : [";
1918 for (auto& col : row.gfx_below_host_limit_total_acc) {
1919 if ((idy + 1) != static_cast<int>(
1920 std::size(row.gfx_below_host_limit_total_acc))) {
1921 std::cout << col << ", ";
1922 } else {
1923 std::cout << col;
1924 }
1925 idy++;
1926 }
1927 std::cout << "]\n";
1928 idy = 0;
1929 idx++;
1930 }
1931
1932 std::cout << "\n\n";
1933 std::cout << "\t ** -> Checking metrics with constant changes ** " << "\n";
1934 constexpr uint16_t kMAX_ITER_TEST = 10;
1935 amdsmi_gpu_metrics_t gpu_metrics_check = {};
1936 for (auto idx = uint16_t(1); idx <= kMAX_ITER_TEST; ++idx) {
1937 amdsmi_get_gpu_metrics_info(processor_handles[device_index],
1938 &gpu_metrics_check);
1939 std::cout << "\t\t -> firmware_timestamp [" << idx << "/"
1940 << kMAX_ITER_TEST << "]: "
1941 << gpu_metrics_check.firmware_timestamp << "\n";
1942 }
1943
1944 std::cout << "\n";
1945 for (auto idx = uint16_t(1); idx <= kMAX_ITER_TEST; ++idx) {
1946 amdsmi_get_gpu_metrics_info(processor_handles[device_index],
1947 &gpu_metrics_check);
1948 std::cout << "\t\t -> system_clock_counter [" << idx << "/"
1949 << kMAX_ITER_TEST << "]: "
1950 << gpu_metrics_check.system_clock_counter << "\n";
1951 }
1952
1953 std::cout << "\n";
1954 std::cout << " ** Note: Values MAX'ed out "
1955 << "(UINTX MAX are unsupported for the version in question) ** "
1956 << "\n\n";
1957 } // END GPU METRICS OUTPUTS
1958
1959 // Get nearest GPUs
1960 const char *topology_link_type_str[] = {
1961 "AMDSMI_LINK_TYPE_INTERNAL",
1962 "AMDSMI_LINK_TYPE_PCIE",
1963 "AMDSMI_LINK_TYPE_XGMI",
1964 "AMDSMI_LINK_TYPE_NOT_APPLICABLE",
1965 "AMDSMI_LINK_TYPE_UNKNOWN",
1966 };
1967 printf("\tOutput of amdsmi_get_link_topology_nearest:\n");
1968 for (uint32_t topo_link_type = AMDSMI_LINK_TYPE_INTERNAL;
1969 topo_link_type <= AMDSMI_LINK_TYPE_UNKNOWN; topo_link_type++) {
1970 auto topology_nearest_info = amdsmi_topology_nearest_t();
1971 ret = amdsmi_get_link_topology_nearest(processor_handles[device_index],
1972 static_cast<amdsmi_link_type_t>(topo_link_type), nullptr);
1973 if (ret != AMDSMI_STATUS_INVAL) {
1974 CHK_AMDSMI_RET(ret);
1975 }
1976
1977 ret = amdsmi_get_link_topology_nearest(processor_handles[device_index],
1978 static_cast<amdsmi_link_type_t>(topo_link_type),
1979 &topology_nearest_info);
1980 if (ret != AMDSMI_STATUS_INVAL) {
1981 CHK_AMDSMI_RET(ret);
1982 }
1983
1984 printf("\tNearest GPUs found at %s\n", topology_link_type_str[topo_link_type]);
1985 printf("\tNearest Count: %d\n", topology_nearest_info.count);
1986 for (uint32_t k = 0; k < topology_nearest_info.count; k++) {
1987 amdsmi_bdf_t bdf = {};
1988 ret = amdsmi_get_gpu_device_bdf(topology_nearest_info.processor_list[k], &bdf);
1989 PRINT_AMDSMI_RET(ret)
1990 if (ret == AMDSMI_STATUS_SUCCESS) {
1991 printf("\t\tGPU BDF %04" PRIx64 ":%02" PRIx32 ":%02" PRIx32 ".%" PRIu32 "\n",
1992 static_cast<uint64_t>(bdf.domain_number),
1993 static_cast<uint32_t>(bdf.bus_number),
1994 static_cast<uint32_t>(bdf.device_number),
1995 static_cast<uint32_t>(bdf.function_number));
1996 } else {
1997 printf("\t\tGPU BDF not available\n");
1998 }
1999 }
2000 }
2001 gpu_number++;
2002 }
2003 }
2004
2005 // Clean up resources allocated at amdsmi_init. It will invalidate sockets
2006 // and devices pointers
2007 ret = amdsmi_shut_down();
2008 CHK_AMDSMI_RET(ret)
2009
2010 return 0;
2011 }