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 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 4311 4312 4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369 4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387 4388 4389 4390 4391 4392 4393 4394 4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410 4411 4412 4413 4414 4415 4416 4417 4418 4419 4420 4421 4422 4423 4424 4425 4426 4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 4441 4442 4443 4444 4445 4446 4447 4448 4449 4450 4451 4452 4453 4454 4455 4456 4457 4458 4459 4460 4461 4462 4463 4464 4465 4466 4467 4468 4469 4470 4471 4472 4473 4474 4475 4476 4477 4478 4479 4480 4481 4482 4483 4484 4485 4486 4487 4488 4489 4490 4491 4492 4493 4494 4495 4496 4497 4498 4499 4500 4501 4502 4503 4504 4505 4506 4507 4508 4509 4510 4511 4512 4513 4514 4515 4516 4517 4518 4519 4520 4521 4522 4523 4524 4525 4526 4527 4528 4529 4530 4531 4532 4533 4534 4535 4536 4537 4538 4539 4540 4541 4542 4543 4544 4545 4546 4547 4548 4549 4550 4551 4552 4553 4554 4555 4556 4557 4558 4559 4560 4561 4562 4563 4564 4565 4566 4567 4568 4569 4570 4571 4572 4573 4574 4575 4576 4577 4578 4579 4580 4581 4582 4583 4584 4585 4586 4587 4588 4589 4590 4591 4592 4593 4594 4595 4596 4597 4598 4599 4600 4601 4602 4603 4604 4605 4606 4607 4608 4609 4610 4611 4612 4613 4614 4615 4616 4617 4618 4619 4620 4621 4622 4623 4624 4625 4626 4627 4628 4629 4630 4631 4632 4633 4634 4635 4636 4637 4638 4639 4640 4641 4642 4643 4644 4645 4646 4647 4648 4649 4650 4651 4652 4653 4654 4655 4656 4657 4658 4659 4660 4661 4662 4663 4664 4665 4666 4667 4668 4669 4670 4671 4672 4673 4674 4675 4676 4677 4678 4679 4680 4681 4682 4683 4684 4685 4686 4687 4688 4689 4690 4691 4692 4693 4694 4695 4696 4697 4698 4699 4700 4701 4702 4703 4704 4705 4706 4707 4708 4709 4710 4711 4712 4713 4714 4715 4716 4717 4718 4719 4720 4721 4722 4723 4724 4725 4726 4727 4728 4729 4730 4731 4732 4733 4734 4735 4736 4737 4738 4739 4740 4741 4742 4743 4744 4745 4746 4747 4748 4749 4750 4751 4752 4753 4754 4755 4756 4757 4758 4759 4760 4761 4762 4763 4764 4765 4766 4767 4768 4769 4770 4771 4772 4773 4774 4775 4776 4777 4778 4779 4780 4781 4782 4783 4784 4785 4786 4787 4788 4789 4790 4791 4792 4793 4794 4795 4796 4797 4798 4799 4800 4801 4802 4803 4804 4805 4806 4807 4808 4809 4810 4811 4812 4813 4814 4815 4816 4817 4818 4819 4820 4821 4822 4823 4824 4825 4826 4827 4828 4829 4830 4831 4832 4833 4834 4835 4836 4837 4838 4839 4840 4841 4842 4843 4844 4845 4846 4847 4848 4849 4850 4851 4852 4853 4854 4855 4856 4857 4858 4859 4860 4861 4862 4863 4864 4865 4866 4867 4868 4869 4870 4871 4872 4873 4874 4875 4876 4877 4878 4879 4880 4881 4882 4883 4884 4885 4886 4887 4888 4889 4890 4891 4892 4893 4894 4895 4896 4897 4898 4899 4900 4901 4902 4903 4904 4905 4906 4907 4908 4909 4910 4911 4912 4913 4914 4915 4916 4917 4918 4919 4920 4921 4922 4923 4924 4925 4926 4927 4928 4929 4930 4931 4932 4933 4934 4935 4936 4937 4938 4939 4940 4941 4942 4943 4944 4945 4946 4947 4948 4949 4950 4951 4952 4953 4954 4955 4956 4957 4958 4959 4960 4961 4962 4963 4964 4965 4966 4967 4968 4969 4970 4971 4972 4973 4974 4975 4976 4977 4978 4979 4980 4981 4982 4983 4984 4985 4986 4987 4988 4989 4990 4991 4992 4993 4994 4995 4996 4997 4998 4999 5000 5001 5002 5003 5004 5005 5006 5007 5008 5009 5010 5011 5012 5013 5014 5015 5016 5017 5018 5019 5020 5021 5022 5023 5024 5025 5026 5027 5028 5029 5030 5031 5032 5033 5034 5035 5036 5037 5038 5039 5040 5041 5042 5043 5044 5045 5046 5047 5048 5049 5050 5051 5052 5053 5054 5055 5056 5057 5058 5059 5060 5061 5062 5063 5064 5065 5066 5067 5068 5069 5070 5071 5072 5073 5074 5075 5076 5077 5078 5079 5080 5081 5082 5083 5084 5085 5086 5087 5088 5089 5090 5091 5092 5093 5094 5095 5096 5097 5098 5099 5100 5101 5102 5103 5104 5105 5106 5107 5108 5109 5110 5111 5112 5113 5114 5115 5116 5117 5118 5119 5120 5121 5122 5123 5124 5125 5126 5127 5128 5129 5130 5131 5132 5133 5134 5135 5136 5137 5138 5139 5140 5141 5142 5143 5144 5145 5146 5147 5148 5149 5150 5151 5152 5153 5154 5155 5156 5157 5158 5159 5160 5161 5162 5163 5164 5165 5166 5167 5168 5169 5170 5171 5172 5173 5174 5175 5176 5177 5178 5179 5180 5181 5182 5183 5184 5185 5186 5187 5188 5189 5190 5191 5192 5193 5194 5195 5196 5197 5198 5199 5200 5201 5202 5203 5204 5205 5206 5207 5208 5209 5210 5211 5212 5213 5214 5215 5216 5217 5218 5219 5220 5221 5222 5223 5224 5225 5226 5227 5228 5229 5230 5231 5232 5233 5234 5235 5236 5237 5238 5239 5240 5241 5242 5243 5244 5245 5246 5247 5248 5249 5250 5251 5252 5253 5254 5255 5256 5257 5258 5259 5260 5261 5262 5263 5264 5265 5266 5267 5268 5269 5270 5271 5272 5273 5274 5275 5276 5277 5278 5279 5280 5281 5282 5283 5284 5285 5286 5287 5288 5289 5290 5291 5292 5293 5294 5295 5296 5297 5298 5299 5300 5301 5302 5303 5304 5305 5306 5307 5308 5309 5310 5311 5312 5313 5314 5315 5316 5317 5318 5319 5320 5321 5322 5323 5324 5325 5326 5327 5328 5329 5330 5331 5332 5333 5334 5335 5336 5337 5338 5339 5340 5341 5342 5343 5344 5345 5346 5347 5348 5349 5350 5351 5352 5353 5354 5355 5356 5357 5358 5359 5360 5361 5362 5363 5364 5365 5366 5367 5368 5369 5370 5371 5372 5373 5374 5375 5376 5377 5378 5379 5380 5381 5382 5383 5384 5385 5386 5387 5388 5389 5390 5391 5392 5393 5394 5395 5396 5397 5398 5399 5400 5401 5402 5403 5404 5405 5406 5407 5408 5409 5410 5411 5412 5413 5414 5415 5416 5417 5418 5419 5420 5421 5422 5423 5424 5425 5426 5427 5428 5429 5430 5431 5432 5433 5434 5435 5436 5437 5438 5439 5440 5441 5442 5443 5444 5445 5446 5447
|
# Copyright (C) Advanced Micro Devices. All rights reserved.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of
# this software and associated documentation files (the "Software"), to deal in
# the Software without restriction, including without limitation the rights to
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
# the Software, and to permit persons to whom the Software is furnished to do so,
# subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
import ctypes
import math
import os
import re
import sys
from collections.abc import Iterable
from ctypes import POINTER, c_void_p
from enum import IntEnum, Enum
from pathlib import Path
from time import asctime, localtime, time
from typing import Any, Dict, List, Tuple, Union
from . import amdsmi_wrapper
from .amdsmi_exception import *
### Non Library Specific Constants ###
class MaxUIntegerTypes(IntEnum):
UINT8_T = 0xFF
UINT16_T = 0xFFFF
UINT32_T = 0xFFFFFFFF
UINT64_T = 0xFFFFFFFFFFFFFFFF
NO_OF_32BITS = (sys.getsizeof(ctypes.c_uint32) * 8)
NO_OF_64BITS = (sys.getsizeof(ctypes.c_uint64) * 8)
KILO = math.pow(10, 3)
processor_handle = c_void_p
###############################
MAX_NUM_PROCESSES = 1024
# gpu metrics macros defined in amdsmi.h
AMDSMI_NUM_HBM_INSTANCES = 4
AMDSMI_MAX_NUM_VCN = 4
AMDSMI_MAX_NUM_CLKS = 4
AMDSMI_MAX_NUM_XGMI_LINKS = 8
AMDSMI_MAX_NUM_GFX_CLKS = 8
AMDSMI_MAX_AID = 4
AMDSMI_MAX_ENGINES = 8
AMDSMI_MAX_NUM_JPEG = 32
AMDSMI_MAX_NUM_XCC = 8
AMDSMI_MAX_NUM_XCP = 8
# max num afids per cper record
MAX_NUMBER_OF_AFIDS_PER_RECORD = 12
# Max number of DPM policies
AMDSMI_MAX_NUM_PM_POLICIES = 32
# Max supported frequencies
AMDSMI_MAX_NUM_FREQUENCIES = 33
# Max Fan speed
AMDSMI_MAX_FAN_SPEED = 255
# Max Votlage Curve Points
AMDSMI_NUM_VOLTAGE_CURVE_POINTS = 3
# Max size definitions
AMDSMI_MAX_MM_IP_COUNT = 8
AMDSMI_MAX_STRING_LENGTH = 256
AMDSMI_MAX_DEVICES = 32
AMDSMI_MAX_CONTAINER_TYPE = 2
AMDSMI_MAX_CACHE_TYPES = 10
AMDSMI_MAX_NUM_XGMI_PHYSICAL_LINK = 64
AMDSMI_GPU_UUID_SIZE = 38
_AMDSMI_STRING_LENGTH = 80
class AmdSmiInitFlags(IntEnum):
INIT_ALL_PROCESSORS = amdsmi_wrapper.AMDSMI_INIT_ALL_PROCESSORS
INIT_AMD_CPUS = amdsmi_wrapper.AMDSMI_INIT_AMD_CPUS
INIT_AMD_GPUS = amdsmi_wrapper.AMDSMI_INIT_AMD_GPUS
INIT_AMD_APUS = amdsmi_wrapper.AMDSMI_INIT_AMD_APUS
INIT_NON_AMD_CPUS = amdsmi_wrapper.AMDSMI_INIT_NON_AMD_CPUS
INIT_NON_AMD_GPUS = amdsmi_wrapper.AMDSMI_INIT_NON_AMD_GPUS
class AmdSmiContainerTypes(IntEnum):
LXC = amdsmi_wrapper.AMDSMI_CONTAINER_LXC
DOCKER = amdsmi_wrapper.AMDSMI_CONTAINER_DOCKER
class AmdSmiDeviceType(IntEnum):
UNKNOWN_DEVICE = amdsmi_wrapper.AMDSMI_PROCESSOR_TYPE_UNKNOWN
AMD_GPU_DEVICE = amdsmi_wrapper.AMDSMI_PROCESSOR_TYPE_AMD_GPU
AMD_CPU_DEVICE = amdsmi_wrapper.AMDSMI_PROCESSOR_TYPE_AMD_CPU
NON_AMD_GPU_DEVICE = amdsmi_wrapper.AMDSMI_PROCESSOR_TYPE_NON_AMD_GPU
NON_AMD_CPU_DEVICE = amdsmi_wrapper.AMDSMI_PROCESSOR_TYPE_NON_AMD_CPU
class AmdSmiMmIp(IntEnum):
UVD = amdsmi_wrapper.AMDSMI_MM_UVD
VCE = amdsmi_wrapper.AMDSMI_MM_VCE
VCN = amdsmi_wrapper.AMDSMI_MM_VCN
class AmdSmiFwBlock(IntEnum):
AMDSMI_FW_ID_SMU = amdsmi_wrapper.AMDSMI_FW_ID_SMU
AMDSMI_FW_ID_CP_CE = amdsmi_wrapper.AMDSMI_FW_ID_CP_CE
AMDSMI_FW_ID_CP_PFP = amdsmi_wrapper.AMDSMI_FW_ID_CP_PFP
AMDSMI_FW_ID_CP_ME = amdsmi_wrapper.AMDSMI_FW_ID_CP_ME
AMDSMI_FW_ID_CP_MEC_JT1 = amdsmi_wrapper.AMDSMI_FW_ID_CP_MEC_JT1
AMDSMI_FW_ID_CP_MEC_JT2 = amdsmi_wrapper.AMDSMI_FW_ID_CP_MEC_JT2
AMDSMI_FW_ID_CP_MEC1 = amdsmi_wrapper.AMDSMI_FW_ID_CP_MEC1
AMDSMI_FW_ID_CP_MEC2 = amdsmi_wrapper.AMDSMI_FW_ID_CP_MEC2
AMDSMI_FW_ID_RLC = amdsmi_wrapper.AMDSMI_FW_ID_RLC
AMDSMI_FW_ID_SDMA0 = amdsmi_wrapper.AMDSMI_FW_ID_SDMA0
AMDSMI_FW_ID_SDMA1 = amdsmi_wrapper.AMDSMI_FW_ID_SDMA1
AMDSMI_FW_ID_SDMA2 = amdsmi_wrapper.AMDSMI_FW_ID_SDMA2
AMDSMI_FW_ID_SDMA3 = amdsmi_wrapper.AMDSMI_FW_ID_SDMA3
AMDSMI_FW_ID_SDMA4 = amdsmi_wrapper.AMDSMI_FW_ID_SDMA4
AMDSMI_FW_ID_SDMA5 = amdsmi_wrapper.AMDSMI_FW_ID_SDMA5
AMDSMI_FW_ID_SDMA6 = amdsmi_wrapper.AMDSMI_FW_ID_SDMA6
AMDSMI_FW_ID_SDMA7 = amdsmi_wrapper.AMDSMI_FW_ID_SDMA7
AMDSMI_FW_ID_VCN = amdsmi_wrapper.AMDSMI_FW_ID_VCN
AMDSMI_FW_ID_UVD = amdsmi_wrapper.AMDSMI_FW_ID_UVD
AMDSMI_FW_ID_VCE = amdsmi_wrapper.AMDSMI_FW_ID_VCE
AMDSMI_FW_ID_ISP = amdsmi_wrapper.AMDSMI_FW_ID_ISP
AMDSMI_FW_ID_DMCU_ERAM = amdsmi_wrapper.AMDSMI_FW_ID_DMCU_ERAM
AMDSMI_FW_ID_DMCU_ISR = amdsmi_wrapper.AMDSMI_FW_ID_DMCU_ISR
AMDSMI_FW_ID_RLC_RESTORE_LIST_GPM_MEM = amdsmi_wrapper.AMDSMI_FW_ID_RLC_RESTORE_LIST_GPM_MEM
AMDSMI_FW_ID_RLC_RESTORE_LIST_SRM_MEM = amdsmi_wrapper.AMDSMI_FW_ID_RLC_RESTORE_LIST_SRM_MEM
AMDSMI_FW_ID_RLC_RESTORE_LIST_CNTL = amdsmi_wrapper.AMDSMI_FW_ID_RLC_RESTORE_LIST_CNTL
AMDSMI_FW_ID_RLC_V = amdsmi_wrapper.AMDSMI_FW_ID_RLC_V
AMDSMI_FW_ID_MMSCH = amdsmi_wrapper.AMDSMI_FW_ID_MMSCH
AMDSMI_FW_ID_PSP_SYSDRV = amdsmi_wrapper.AMDSMI_FW_ID_PSP_SYSDRV
AMDSMI_FW_ID_PSP_SOSDRV = amdsmi_wrapper.AMDSMI_FW_ID_PSP_SOSDRV
AMDSMI_FW_ID_PSP_TOC = amdsmi_wrapper.AMDSMI_FW_ID_PSP_TOC
AMDSMI_FW_ID_PSP_KEYDB = amdsmi_wrapper.AMDSMI_FW_ID_PSP_KEYDB
AMDSMI_FW_ID_DFC = amdsmi_wrapper.AMDSMI_FW_ID_DFC
AMDSMI_FW_ID_PSP_SPL = amdsmi_wrapper.AMDSMI_FW_ID_PSP_SPL
AMDSMI_FW_ID_DRV_CAP = amdsmi_wrapper.AMDSMI_FW_ID_DRV_CAP
AMDSMI_FW_ID_MC = amdsmi_wrapper.AMDSMI_FW_ID_MC
AMDSMI_FW_ID_PSP_BL = amdsmi_wrapper.AMDSMI_FW_ID_PSP_BL
AMDSMI_FW_ID_CP_PM4 = amdsmi_wrapper.AMDSMI_FW_ID_CP_PM4
AMDSMI_FW_ID_RLC_P = amdsmi_wrapper.AMDSMI_FW_ID_RLC_P
AMDSMI_FW_ID_SEC_POLICY_STAGE2 = amdsmi_wrapper.AMDSMI_FW_ID_SEC_POLICY_STAGE2
AMDSMI_FW_ID_REG_ACCESS_WHITELIST = amdsmi_wrapper.AMDSMI_FW_ID_REG_ACCESS_WHITELIST
AMDSMI_FW_ID_IMU_DRAM = amdsmi_wrapper.AMDSMI_FW_ID_IMU_DRAM
AMDSMI_FW_ID_IMU_IRAM = amdsmi_wrapper.AMDSMI_FW_ID_IMU_IRAM
AMDSMI_FW_ID_SDMA_TH0 = amdsmi_wrapper.AMDSMI_FW_ID_SDMA_TH0
AMDSMI_FW_ID_SDMA_TH1 = amdsmi_wrapper.AMDSMI_FW_ID_SDMA_TH1
AMDSMI_FW_ID_CP_MES = amdsmi_wrapper.AMDSMI_FW_ID_CP_MES
AMDSMI_FW_ID_MES_STACK = amdsmi_wrapper.AMDSMI_FW_ID_MES_STACK
AMDSMI_FW_ID_MES_THREAD1 = amdsmi_wrapper.AMDSMI_FW_ID_MES_THREAD1
AMDSMI_FW_ID_MES_THREAD1_STACK = amdsmi_wrapper.AMDSMI_FW_ID_MES_THREAD1_STACK
AMDSMI_FW_ID_RLX6 = amdsmi_wrapper.AMDSMI_FW_ID_RLX6
AMDSMI_FW_ID_RLX6_DRAM_BOOT = amdsmi_wrapper.AMDSMI_FW_ID_RLX6_DRAM_BOOT
AMDSMI_FW_ID_RS64_ME = amdsmi_wrapper.AMDSMI_FW_ID_RS64_ME
AMDSMI_FW_ID_RS64_ME_P0_DATA = amdsmi_wrapper.AMDSMI_FW_ID_RS64_ME_P0_DATA
AMDSMI_FW_ID_RS64_ME_P1_DATA = amdsmi_wrapper.AMDSMI_FW_ID_RS64_ME_P1_DATA
AMDSMI_FW_ID_RS64_PFP = amdsmi_wrapper.AMDSMI_FW_ID_RS64_PFP
AMDSMI_FW_ID_RS64_PFP_P0_DATA = amdsmi_wrapper.AMDSMI_FW_ID_RS64_PFP_P0_DATA
AMDSMI_FW_ID_RS64_PFP_P1_DATA = amdsmi_wrapper.AMDSMI_FW_ID_RS64_PFP_P1_DATA
AMDSMI_FW_ID_RS64_MEC = amdsmi_wrapper.AMDSMI_FW_ID_RS64_MEC
AMDSMI_FW_ID_RS64_MEC_P0_DATA = amdsmi_wrapper.AMDSMI_FW_ID_RS64_MEC_P0_DATA
AMDSMI_FW_ID_RS64_MEC_P1_DATA = amdsmi_wrapper.AMDSMI_FW_ID_RS64_MEC_P1_DATA
AMDSMI_FW_ID_RS64_MEC_P2_DATA = amdsmi_wrapper.AMDSMI_FW_ID_RS64_MEC_P2_DATA
AMDSMI_FW_ID_RS64_MEC_P3_DATA = amdsmi_wrapper.AMDSMI_FW_ID_RS64_MEC_P3_DATA
AMDSMI_FW_ID_PPTABLE = amdsmi_wrapper.AMDSMI_FW_ID_PPTABLE
AMDSMI_FW_ID_PSP_SOC = amdsmi_wrapper.AMDSMI_FW_ID_PSP_SOC
AMDSMI_FW_ID_PSP_DBG = amdsmi_wrapper.AMDSMI_FW_ID_PSP_DBG
AMDSMI_FW_ID_PSP_INTF = amdsmi_wrapper.AMDSMI_FW_ID_PSP_INTF
AMDSMI_FW_ID_RLX6_CORE1 = amdsmi_wrapper.AMDSMI_FW_ID_RLX6_CORE1
AMDSMI_FW_ID_RLX6_DRAM_BOOT_CORE1 = amdsmi_wrapper.AMDSMI_FW_ID_RLX6_DRAM_BOOT_CORE1
AMDSMI_FW_ID_RLCV_LX7 = amdsmi_wrapper.AMDSMI_FW_ID_RLCV_LX7
AMDSMI_FW_ID_RLC_SAVE_RESTORE_LIST = amdsmi_wrapper.AMDSMI_FW_ID_RLC_SAVE_RESTORE_LIST
AMDSMI_FW_ID_ASD = amdsmi_wrapper.AMDSMI_FW_ID_ASD
AMDSMI_FW_ID_TA_RAS = amdsmi_wrapper.AMDSMI_FW_ID_TA_RAS
AMDSMI_FW_ID_TA_XGMI = amdsmi_wrapper.AMDSMI_FW_ID_TA_XGMI
AMDSMI_FW_ID_RLC_SRLG = amdsmi_wrapper.AMDSMI_FW_ID_RLC_SRLG
AMDSMI_FW_ID_RLC_SRLS = amdsmi_wrapper.AMDSMI_FW_ID_RLC_SRLS
AMDSMI_FW_ID_PM = amdsmi_wrapper.AMDSMI_FW_ID_PM
AMDSMI_FW_ID_DMCU = amdsmi_wrapper.AMDSMI_FW_ID_DMCU
AMDSMI_FW_ID_PLDM_BUNDLE = amdsmi_wrapper.AMDSMI_FW_ID_PLDM_BUNDLE
class AmdSmiClkType(IntEnum):
SYS = amdsmi_wrapper.AMDSMI_CLK_TYPE_SYS
GFX = amdsmi_wrapper.AMDSMI_CLK_TYPE_GFX
DF = amdsmi_wrapper.AMDSMI_CLK_TYPE_DF
DCEF = amdsmi_wrapper.AMDSMI_CLK_TYPE_DCEF
SOC = amdsmi_wrapper.AMDSMI_CLK_TYPE_SOC
MEM = amdsmi_wrapper.AMDSMI_CLK_TYPE_MEM
PCIE = amdsmi_wrapper.AMDSMI_CLK_TYPE_PCIE
VCLK0 = amdsmi_wrapper.AMDSMI_CLK_TYPE_VCLK0
VCLK1 = amdsmi_wrapper.AMDSMI_CLK_TYPE_VCLK1
DCLK0 = amdsmi_wrapper.AMDSMI_CLK_TYPE_DCLK0
DCLK1 = amdsmi_wrapper.AMDSMI_CLK_TYPE_DCLK1
class AmdSmiClkLimitType(IntEnum):
MIN = amdsmi_wrapper.CLK_LIMIT_MIN
MAX = amdsmi_wrapper.CLK_LIMIT_MAX
class AmdSmiTemperatureType(IntEnum):
EDGE = amdsmi_wrapper.AMDSMI_TEMPERATURE_TYPE_EDGE
HOTSPOT = amdsmi_wrapper.AMDSMI_TEMPERATURE_TYPE_HOTSPOT
JUNCTION = amdsmi_wrapper.AMDSMI_TEMPERATURE_TYPE_JUNCTION
VRAM = amdsmi_wrapper.AMDSMI_TEMPERATURE_TYPE_VRAM
HBM_0 = amdsmi_wrapper.AMDSMI_TEMPERATURE_TYPE_HBM_0
HBM_1 = amdsmi_wrapper.AMDSMI_TEMPERATURE_TYPE_HBM_1
HBM_2 = amdsmi_wrapper.AMDSMI_TEMPERATURE_TYPE_HBM_2
HBM_3 = amdsmi_wrapper.AMDSMI_TEMPERATURE_TYPE_HBM_3
PLX = amdsmi_wrapper.AMDSMI_TEMPERATURE_TYPE_PLX
# GPU Board Node temperature
GPUBOARD_NODE_RETIMER_X = amdsmi_wrapper.AMDSMI_TEMPERATURE_TYPE_GPUBOARD_NODE_RETIMER_X # Retimer X temperature
GPUBOARD_NODE_OAM_X_IBC = amdsmi_wrapper.AMDSMI_TEMPERATURE_TYPE_GPUBOARD_NODE_OAM_X_IBC # OAM X IBC temperature
GPUBOARD_NODE_OAM_X_IBC_2 = amdsmi_wrapper.AMDSMI_TEMPERATURE_TYPE_GPUBOARD_NODE_OAM_X_IBC_2 # OAM X IBC 2 temperature
GPUBOARD_NODE_OAM_X_VDD18_VR = amdsmi_wrapper.AMDSMI_TEMPERATURE_TYPE_GPUBOARD_NODE_OAM_X_VDD18_VR # OAM X VDD 1.8V voltage regulator temperature
GPUBOARD_NODE_OAM_X_04_HBM_B_VR = amdsmi_wrapper.AMDSMI_TEMPERATURE_TYPE_GPUBOARD_NODE_OAM_X_04_HBM_B_VR # OAM X 0.4V HBM B voltage regulator temperature
GPUBOARD_NODE_OAM_X_04_HBM_D_VR = amdsmi_wrapper.AMDSMI_TEMPERATURE_TYPE_GPUBOARD_NODE_OAM_X_04_HBM_D_VR # OAM X 0.4V HBM D voltage regulator temperature
GPUBOARD_NODE_LAST = amdsmi_wrapper.AMDSMI_TEMPERATURE_TYPE_GPUBOARD_NODE_LAST
# GPU Board VR (Voltage Regulator) temperature
GPUBOARD_VDDCR_VDD0 = amdsmi_wrapper.AMDSMI_TEMPERATURE_TYPE_GPUBOARD_VDDCR_VDD0 # VDDCR VDD0 voltage regulator temperature
GPUBOARD_VDDCR_VDD1 = amdsmi_wrapper.AMDSMI_TEMPERATURE_TYPE_GPUBOARD_VDDCR_VDD1 # VDDCR VDD1 voltage regulator temperature
GPUBOARD_VDDCR_VDD2 = amdsmi_wrapper.AMDSMI_TEMPERATURE_TYPE_GPUBOARD_VDDCR_VDD2 # VDDCR VDD2 voltage regulator temperature
GPUBOARD_VDDCR_VDD3 = amdsmi_wrapper.AMDSMI_TEMPERATURE_TYPE_GPUBOARD_VDDCR_VDD3 # VDDCR VDD3 voltage regulator temperature
GPUBOARD_VDDCR_SOC_A = amdsmi_wrapper.AMDSMI_TEMPERATURE_TYPE_GPUBOARD_VDDCR_SOC_A # VDDCR SOC A voltage regulator temperature
GPUBOARD_VDDCR_SOC_C = amdsmi_wrapper.AMDSMI_TEMPERATURE_TYPE_GPUBOARD_VDDCR_SOC_C # VDDCR SOC C voltage regulator temperature
GPUBOARD_VDDCR_SOCIO_A = amdsmi_wrapper.AMDSMI_TEMPERATURE_TYPE_GPUBOARD_VDDCR_SOCIO_A # VDDCR SOCIO A voltage regulator temperature
GPUBOARD_VDDCR_SOCIO_C = amdsmi_wrapper.AMDSMI_TEMPERATURE_TYPE_GPUBOARD_VDDCR_SOCIO_C # VDDCR SOCIO C voltage regulator temperature
GPUBOARD_VDD_085_HBM = amdsmi_wrapper.AMDSMI_TEMPERATURE_TYPE_GPUBOARD_VDD_085_HBM # VDD 0.85V HBM voltage regulator temperature
GPUBOARD_VDDCR_11_HBM_B = amdsmi_wrapper.AMDSMI_TEMPERATURE_TYPE_GPUBOARD_VDDCR_11_HBM_B # VDDCR 1.1V HBM B voltage regulator temperature
GPUBOARD_VDDCR_11_HBM_D = amdsmi_wrapper.AMDSMI_TEMPERATURE_TYPE_GPUBOARD_VDDCR_11_HBM_D # VDDCR 1.1V HBM D voltage regulator temperature
GPUBOARD_VDD_USR = amdsmi_wrapper.AMDSMI_TEMPERATURE_TYPE_GPUBOARD_VDD_USR # VDD USR voltage regulator temperature
GPUBOARD_VDDIO_11_E32 = amdsmi_wrapper.AMDSMI_TEMPERATURE_TYPE_GPUBOARD_VDDIO_11_E32 # VDDIO 1.1V E32 voltage regulator temperature
GPUBOARD_VR_LAST = amdsmi_wrapper.AMDSMI_TEMPERATURE_TYPE_GPUBOARD_VR_LAST
# Baseboard System temperature
BASEBOARD_UBB_FPGA = amdsmi_wrapper.AMDSMI_TEMPERATURE_TYPE_BASEBOARD_UBB_FPGA # UBB FPGA temperature
BASEBOARD_UBB_FRONT = amdsmi_wrapper.AMDSMI_TEMPERATURE_TYPE_BASEBOARD_UBB_FRONT # UBB front temperature
BASEBOARD_UBB_BACK = amdsmi_wrapper.AMDSMI_TEMPERATURE_TYPE_BASEBOARD_UBB_BACK # UBB back temperature
BASEBOARD_UBB_OAM7 = amdsmi_wrapper.AMDSMI_TEMPERATURE_TYPE_BASEBOARD_UBB_OAM7 # UBB OAM7 temperature
BASEBOARD_UBB_IBC = amdsmi_wrapper.AMDSMI_TEMPERATURE_TYPE_BASEBOARD_UBB_IBC # UBB IBC temperature
BASEBOARD_UBB_UFPGA = amdsmi_wrapper.AMDSMI_TEMPERATURE_TYPE_BASEBOARD_UBB_UFPGA # UBB UFPGA temperature
BASEBOARD_UBB_OAM1 = amdsmi_wrapper.AMDSMI_TEMPERATURE_TYPE_BASEBOARD_UBB_OAM1 # UBB OAM1 temperature
BASEBOARD_OAM_0_1_HSC = amdsmi_wrapper.AMDSMI_TEMPERATURE_TYPE_BASEBOARD_OAM_0_1_HSC # OAM 0-1 HSC temperature
BASEBOARD_OAM_2_3_HSC = amdsmi_wrapper.AMDSMI_TEMPERATURE_TYPE_BASEBOARD_OAM_2_3_HSC # OAM 2-3 HSC temperature
BASEBOARD_OAM_4_5_HSC = amdsmi_wrapper.AMDSMI_TEMPERATURE_TYPE_BASEBOARD_OAM_4_5_HSC # OAM 4-5 HSC temperature
BASEBOARD_OAM_6_7_HSC = amdsmi_wrapper.AMDSMI_TEMPERATURE_TYPE_BASEBOARD_OAM_6_7_HSC # OAM 6-7 HSC temperature
BASEBOARD_UBB_FPGA_0V72_VR = amdsmi_wrapper.AMDSMI_TEMPERATURE_TYPE_BASEBOARD_UBB_FPGA_0V72_VR # UBB FPGA 0.72V voltage regulator temperature
BASEBOARD_UBB_FPGA_3V3_VR = amdsmi_wrapper.AMDSMI_TEMPERATURE_TYPE_BASEBOARD_UBB_FPGA_3V3_VR # UBB FPGA 3.3V voltage regulator temperature
BASEBOARD_RETIMER_0_1_2_3_1V2_VR = amdsmi_wrapper.AMDSMI_TEMPERATURE_TYPE_BASEBOARD_RETIMER_0_1_2_3_1V2_VR # Retimer 0-1-2-3 1.2V voltage regulator temperature
BASEBOARD_RETIMER_4_5_6_7_1V2_VR = amdsmi_wrapper.AMDSMI_TEMPERATURE_TYPE_BASEBOARD_RETIMER_4_5_6_7_1V2_VR # Retimer 4-5-6-7 1.2V voltage regulator temperature
BASEBOARD_RETIMER_0_1_0V9_VR = amdsmi_wrapper.AMDSMI_TEMPERATURE_TYPE_BASEBOARD_RETIMER_0_1_0V9_VR # Retimer 0-1 0.9V voltage regulator temperature
BASEBOARD_RETIMER_4_5_0V9_VR= amdsmi_wrapper.AMDSMI_TEMPERATURE_TYPE_BASEBOARD_RETIMER_4_5_0V9_VR # Retimer 4-5 0.9V voltage regulator temperature
BASEBOARD_RETIMER_2_3_0V9_VR = amdsmi_wrapper.AMDSMI_TEMPERATURE_TYPE_BASEBOARD_RETIMER_2_3_0V9_VR # Retimer 2-3 0.9V voltage regulator temperature
BASEBOARD_RETIMER_6_7_0V9_VR = amdsmi_wrapper.AMDSMI_TEMPERATURE_TYPE_BASEBOARD_RETIMER_6_7_0V9_VR # Retimer 6-7 0.9V voltage regulator temperature
BASEBOARD_OAM_0_1_2_3_3V3_VR = amdsmi_wrapper.AMDSMI_TEMPERATURE_TYPE_BASEBOARD_OAM_0_1_2_3_3V3_VR # OAM 0-1-2-3 3.3V voltage regulator temperature
BASEBOARD_OAM_4_5_6_7_3V3_VR = amdsmi_wrapper.AMDSMI_TEMPERATURE_TYPE_BASEBOARD_OAM_4_5_6_7_3V3_VR # OAM 4-5-6-7 3.3V voltage regulator temperature
BASEBOARD_IBC_HSC = amdsmi_wrapper.AMDSMI_TEMPERATURE_TYPE_BASEBOARD_IBC_HSC # IBC HSC temperature
BASEBOARD_IBC = amdsmi_wrapper.AMDSMI_TEMPERATURE_TYPE_BASEBOARD_IBC # IBC temperature
BASEBOARD_LAST = amdsmi_wrapper.AMDSMI_TEMPERATURE_TYPE_BASEBOARD_LAST
BASEBOARD__MAX = amdsmi_wrapper.AMDSMI_TEMPERATURE_TYPE__MAX # Maximum per GPU temperature type
class AmdSmiDevPerfLevel(IntEnum):
AUTO = amdsmi_wrapper.AMDSMI_DEV_PERF_LEVEL_AUTO
LOW = amdsmi_wrapper.AMDSMI_DEV_PERF_LEVEL_LOW
HIGH = amdsmi_wrapper.AMDSMI_DEV_PERF_LEVEL_HIGH
MANUAL = amdsmi_wrapper.AMDSMI_DEV_PERF_LEVEL_MANUAL
STABLE_STD = amdsmi_wrapper.AMDSMI_DEV_PERF_LEVEL_STABLE_STD
STABLE_PEAK = amdsmi_wrapper.AMDSMI_DEV_PERF_LEVEL_STABLE_PEAK
STABLE_MIN_MCLK = amdsmi_wrapper.AMDSMI_DEV_PERF_LEVEL_STABLE_MIN_MCLK
STABLE_MIN_SCLK = amdsmi_wrapper.AMDSMI_DEV_PERF_LEVEL_STABLE_MIN_SCLK
DETERMINISM = amdsmi_wrapper.AMDSMI_DEV_PERF_LEVEL_DETERMINISM
UNKNOWN = amdsmi_wrapper.AMDSMI_DEV_PERF_LEVEL_UNKNOWN
class AmdSmiEventGroup(IntEnum):
XGMI = amdsmi_wrapper.AMDSMI_EVNT_GRP_XGMI
XGMI_DATA_OUT = amdsmi_wrapper.AMDSMI_EVNT_GRP_XGMI_DATA_OUT
GRP_INVALID = amdsmi_wrapper.AMDSMI_EVNT_GRP_INVALID
class AmdSmiEventType(IntEnum):
XGMI_0_NOP_TX = amdsmi_wrapper.AMDSMI_EVNT_XGMI_0_NOP_TX
XGMI_0_REQUEST_TX = amdsmi_wrapper.AMDSMI_EVNT_XGMI_0_REQUEST_TX
XGMI_0_RESPONSE_TX = amdsmi_wrapper.AMDSMI_EVNT_XGMI_0_RESPONSE_TX
XGMI_0_BEATS_TX = amdsmi_wrapper.AMDSMI_EVNT_XGMI_0_BEATS_TX
XGMI_1_NOP_TX = amdsmi_wrapper.AMDSMI_EVNT_XGMI_1_NOP_TX
XGMI_1_REQUEST_TX = amdsmi_wrapper.AMDSMI_EVNT_XGMI_1_REQUEST_TX
XGMI_1_RESPONSE_TX = amdsmi_wrapper.AMDSMI_EVNT_XGMI_1_RESPONSE_TX
XGMI_1_BEATS_TX = amdsmi_wrapper.AMDSMI_EVNT_XGMI_1_BEATS_TX
XGMI_DATA_OUT_0 = amdsmi_wrapper.AMDSMI_EVNT_XGMI_DATA_OUT_0
XGMI_DATA_OUT_1 = amdsmi_wrapper.AMDSMI_EVNT_XGMI_DATA_OUT_1
XGMI_DATA_OUT_2 = amdsmi_wrapper.AMDSMI_EVNT_XGMI_DATA_OUT_2
XGMI_DATA_OUT_3 = amdsmi_wrapper.AMDSMI_EVNT_XGMI_DATA_OUT_3
XGMI_DATA_OUT_4 = amdsmi_wrapper.AMDSMI_EVNT_XGMI_DATA_OUT_4
XGMI_DATA_OUT_5 = amdsmi_wrapper.AMDSMI_EVNT_XGMI_DATA_OUT_5
class AmdSmiCounterCommand(IntEnum):
CMD_START = amdsmi_wrapper.AMDSMI_CNTR_CMD_START
CMD_STOP = amdsmi_wrapper.AMDSMI_CNTR_CMD_STOP
class AmdSmiEvtNotificationType(IntEnum):
NONE = amdsmi_wrapper.AMDSMI_EVT_NOTIF_NONE
VMFAULT = amdsmi_wrapper.AMDSMI_EVT_NOTIF_VMFAULT
THERMAL_THROTTLE = amdsmi_wrapper.AMDSMI_EVT_NOTIF_THERMAL_THROTTLE
GPU_PRE_RESET = amdsmi_wrapper.AMDSMI_EVT_NOTIF_GPU_PRE_RESET
GPU_POST_RESET = amdsmi_wrapper.AMDSMI_EVT_NOTIF_GPU_POST_RESET
MIGRATE_START = amdsmi_wrapper.AMDSMI_EVT_NOTIF_MIGRATE_START
MIGRATE_END = amdsmi_wrapper.AMDSMI_EVT_NOTIF_MIGRATE_END
PAGE_FAULT_START = amdsmi_wrapper.AMDSMI_EVT_NOTIF_PAGE_FAULT_END
PAGE_FAULT_END = amdsmi_wrapper.AMDSMI_EVT_NOTIF_PAGE_FAULT_END
QUEUE_EVICTION = amdsmi_wrapper.AMDSMI_EVT_NOTIF_QUEUE_EVICTION
QUEUE_RESTORE = amdsmi_wrapper.AMDSMI_EVT_NOTIF_QUEUE_RESTORE
UNMAP_FROM_GPU = amdsmi_wrapper.AMDSMI_EVT_NOTIF_UNMAP_FROM_GPU
PROCESS_START = amdsmi_wrapper.AMDSMI_EVT_NOTIF_PROCESS_START
PROCESS_END = amdsmi_wrapper.AMDSMI_EVT_NOTIF_PROCESS_END
class AmdSmiTemperatureMetric(IntEnum):
CURRENT = amdsmi_wrapper.AMDSMI_TEMP_CURRENT
MAX = amdsmi_wrapper.AMDSMI_TEMP_MAX
MIN = amdsmi_wrapper.AMDSMI_TEMP_MIN
MAX_HYST = amdsmi_wrapper.AMDSMI_TEMP_MAX_HYST
MIN_HYST = amdsmi_wrapper.AMDSMI_TEMP_MIN_HYST
CRITICAL = amdsmi_wrapper.AMDSMI_TEMP_CRITICAL
CRITICAL_HYST = amdsmi_wrapper.AMDSMI_TEMP_CRITICAL_HYST
EMERGENCY = amdsmi_wrapper.AMDSMI_TEMP_EMERGENCY
EMERGENCY_HYST = amdsmi_wrapper.AMDSMI_TEMP_EMERGENCY_HYST
CRIT_MIN = amdsmi_wrapper.AMDSMI_TEMP_CRIT_MIN
CRIT_MIN_HYST = amdsmi_wrapper.AMDSMI_TEMP_CRIT_MIN_HYST
OFFSET = amdsmi_wrapper.AMDSMI_TEMP_OFFSET
LOWEST = amdsmi_wrapper.AMDSMI_TEMP_LOWEST
HIGHEST = amdsmi_wrapper.AMDSMI_TEMP_HIGHEST
class AmdSmiVoltageMetric(IntEnum):
CURRENT = amdsmi_wrapper.AMDSMI_VOLT_CURRENT
MAX = amdsmi_wrapper.AMDSMI_VOLT_MAX
MIN_CRIT = amdsmi_wrapper.AMDSMI_VOLT_MIN_CRIT
MIN = amdsmi_wrapper.AMDSMI_VOLT_MIN
MAX_CRIT = amdsmi_wrapper.AMDSMI_VOLT_MAX_CRIT
AVERAGE = amdsmi_wrapper.AMDSMI_VOLT_AVERAGE
LOWEST = amdsmi_wrapper.AMDSMI_VOLT_LOWEST
HIGHEST = amdsmi_wrapper.AMDSMI_VOLT_HIGHEST
class AmdSmiVoltageType(IntEnum):
VDDGFX = amdsmi_wrapper.AMDSMI_VOLT_TYPE_VDDGFX
VDDBOARD = amdsmi_wrapper.AMDSMI_VOLT_TYPE_VDDBOARD
INVALID = amdsmi_wrapper.AMDSMI_VOLT_TYPE_INVALID
class AmdSmiAcceleratorPartitionResourceType(IntEnum):
XCC = amdsmi_wrapper.AMDSMI_ACCELERATOR_XCC
ENCODER = amdsmi_wrapper.AMDSMI_ACCELERATOR_ENCODER
DECODER = amdsmi_wrapper.AMDSMI_ACCELERATOR_DECODER
DMA = amdsmi_wrapper.AMDSMI_ACCELERATOR_DMA
JPEG = amdsmi_wrapper.AMDSMI_ACCELERATOR_JPEG
MAX = amdsmi_wrapper.AMDSMI_ACCELERATOR_MAX
class AmdSmiAcceleratorPartitionType(IntEnum):
SPX = amdsmi_wrapper.AMDSMI_ACCELERATOR_PARTITION_SPX
DPX = amdsmi_wrapper.AMDSMI_ACCELERATOR_PARTITION_DPX
TPX = amdsmi_wrapper.AMDSMI_ACCELERATOR_PARTITION_TPX
QPX = amdsmi_wrapper.AMDSMI_ACCELERATOR_PARTITION_QPX
CPX = amdsmi_wrapper.AMDSMI_ACCELERATOR_PARTITION_CPX
INVALID = amdsmi_wrapper.AMDSMI_ACCELERATOR_PARTITION_INVALID
class AmdSmiComputePartitionType(IntEnum):
SPX = amdsmi_wrapper.AMDSMI_COMPUTE_PARTITION_SPX
DPX = amdsmi_wrapper.AMDSMI_COMPUTE_PARTITION_DPX
TPX = amdsmi_wrapper.AMDSMI_COMPUTE_PARTITION_TPX
QPX = amdsmi_wrapper.AMDSMI_COMPUTE_PARTITION_QPX
CPX = amdsmi_wrapper.AMDSMI_COMPUTE_PARTITION_CPX
INVALID = amdsmi_wrapper.AMDSMI_COMPUTE_PARTITION_INVALID
class AmdSmiMemoryPartitionType(IntEnum):
NPS1 = amdsmi_wrapper.AMDSMI_MEMORY_PARTITION_NPS1
NPS2 = amdsmi_wrapper.AMDSMI_MEMORY_PARTITION_NPS2
NPS4 = amdsmi_wrapper.AMDSMI_MEMORY_PARTITION_NPS4
NPS8 = amdsmi_wrapper.AMDSMI_MEMORY_PARTITION_NPS8
UNKNOWN = amdsmi_wrapper.AMDSMI_MEMORY_PARTITION_UNKNOWN
class AmdSmiPowerProfilePresetMasks(IntEnum):
CUSTOM_MASK = amdsmi_wrapper.AMDSMI_PWR_PROF_PRST_CUSTOM_MASK
VIDEO_MASK = amdsmi_wrapper.AMDSMI_PWR_PROF_PRST_VIDEO_MASK
POWER_SAVING_MASK = amdsmi_wrapper.AMDSMI_PWR_PROF_PRST_POWER_SAVING_MASK
COMPUTE_MASK = amdsmi_wrapper.AMDSMI_PWR_PROF_PRST_COMPUTE_MASK
VR_MASK = amdsmi_wrapper.AMDSMI_PWR_PROF_PRST_VR_MASK
THREE_D_FULL_SCR_MASK = amdsmi_wrapper.AMDSMI_PWR_PROF_PRST_3D_FULL_SCR_MASK
BOOTUP_DEFAULT = amdsmi_wrapper.AMDSMI_PWR_PROF_PRST_BOOTUP_DEFAULT
INVALID = amdsmi_wrapper.AMDSMI_PWR_PROF_PRST_INVALID
class AmdSmiGpuBlock(IntEnum):
INVALID = amdsmi_wrapper.AMDSMI_GPU_BLOCK_INVALID
UMC = amdsmi_wrapper.AMDSMI_GPU_BLOCK_UMC
SDMA = amdsmi_wrapper.AMDSMI_GPU_BLOCK_SDMA
GFX = amdsmi_wrapper.AMDSMI_GPU_BLOCK_GFX
MMHUB = amdsmi_wrapper.AMDSMI_GPU_BLOCK_MMHUB
ATHUB = amdsmi_wrapper.AMDSMI_GPU_BLOCK_ATHUB
PCIE_BIF = amdsmi_wrapper.AMDSMI_GPU_BLOCK_PCIE_BIF
HDP = amdsmi_wrapper.AMDSMI_GPU_BLOCK_HDP
XGMI_WAFL = amdsmi_wrapper.AMDSMI_GPU_BLOCK_XGMI_WAFL
DF = amdsmi_wrapper.AMDSMI_GPU_BLOCK_DF
SMN = amdsmi_wrapper.AMDSMI_GPU_BLOCK_SMN
SEM = amdsmi_wrapper.AMDSMI_GPU_BLOCK_SEM
MP0 = amdsmi_wrapper.AMDSMI_GPU_BLOCK_MP0
MP1 = amdsmi_wrapper.AMDSMI_GPU_BLOCK_MP1
FUSE = amdsmi_wrapper.AMDSMI_GPU_BLOCK_FUSE
MCA = amdsmi_wrapper.AMDSMI_GPU_BLOCK_MCA
VCN = amdsmi_wrapper.AMDSMI_GPU_BLOCK_VCN
JPEG = amdsmi_wrapper.AMDSMI_GPU_BLOCK_JPEG
IH = amdsmi_wrapper.AMDSMI_GPU_BLOCK_IH
MPIO = amdsmi_wrapper.AMDSMI_GPU_BLOCK_MPIO
RESERVED = amdsmi_wrapper.AMDSMI_GPU_BLOCK_RESERVED
class AmdSmiRasErrState(IntEnum):
NONE = amdsmi_wrapper.AMDSMI_RAS_ERR_STATE_NONE
DISABLED = amdsmi_wrapper.AMDSMI_RAS_ERR_STATE_DISABLED
PARITY = amdsmi_wrapper.AMDSMI_RAS_ERR_STATE_PARITY
SING_C = amdsmi_wrapper.AMDSMI_RAS_ERR_STATE_SING_C
MULT_UC = amdsmi_wrapper.AMDSMI_RAS_ERR_STATE_MULT_UC
POISON = amdsmi_wrapper.AMDSMI_RAS_ERR_STATE_POISON
ENABLED = amdsmi_wrapper.AMDSMI_RAS_ERR_STATE_ENABLED
INVALID = amdsmi_wrapper.AMDSMI_RAS_ERR_STATE_INVALID
class AmdSmiCperNotifyType(Enum):
CMC = amdsmi_wrapper.AMDSMI_CPER_NOTIFY_TYPE_CMC
CPE = amdsmi_wrapper.AMDSMI_CPER_NOTIFY_TYPE_CPE
MCE = amdsmi_wrapper.AMDSMI_CPER_NOTIFY_TYPE_MCE
PCIE = amdsmi_wrapper.AMDSMI_CPER_NOTIFY_TYPE_PCIE
INIT = amdsmi_wrapper.AMDSMI_CPER_NOTIFY_TYPE_INIT
NMI = amdsmi_wrapper.AMDSMI_CPER_NOTIFY_TYPE_NMI
BOOT = amdsmi_wrapper.AMDSMI_CPER_NOTIFY_TYPE_BOOT
DMAr = amdsmi_wrapper.AMDSMI_CPER_NOTIFY_TYPE_DMAR
SEA = amdsmi_wrapper.AMDSMI_CPER_NOTIFY_TYPE_SEA
SEI = amdsmi_wrapper.AMDSMI_CPER_NOTIFY_TYPE_SEI
PEI = amdsmi_wrapper.AMDSMI_CPER_NOTIFY_TYPE_PEI
CXL_COMPONENT = amdsmi_wrapper.AMDSMI_CPER_NOTIFY_TYPE_CXL_COMPONENT
class AmdSmiMemoryType(IntEnum):
VRAM = amdsmi_wrapper.AMDSMI_MEM_TYPE_VRAM
VIS_VRAM = amdsmi_wrapper.AMDSMI_MEM_TYPE_VIS_VRAM
GTT = amdsmi_wrapper.AMDSMI_MEM_TYPE_GTT
class AmdSmiFreqInd(IntEnum):
MIN = amdsmi_wrapper.AMDSMI_FREQ_IND_MIN
MAX = amdsmi_wrapper.AMDSMI_FREQ_IND_MAX
INVALID = amdsmi_wrapper.AMDSMI_FREQ_IND_INVALID
class AmdSmiXgmiStatus(IntEnum):
NO_ERRORS = amdsmi_wrapper.AMDSMI_XGMI_STATUS_NO_ERRORS
ERROR = amdsmi_wrapper.AMDSMI_XGMI_STATUS_ERROR
MULTIPLE_ERRORS = amdsmi_wrapper.AMDSMI_XGMI_STATUS_MULTIPLE_ERRORS
class AmdSmiMemoryPageStatus(IntEnum):
RESERVED = amdsmi_wrapper.AMDSMI_MEM_PAGE_STATUS_RESERVED
PENDING = amdsmi_wrapper.AMDSMI_MEM_PAGE_STATUS_PENDING
UNRESERVABLE = amdsmi_wrapper.AMDSMI_MEM_PAGE_STATUS_UNRESERVABLE
class AmdSmiLinkType(IntEnum):
AMDSMI_LINK_TYPE_INTERNAL = amdsmi_wrapper.AMDSMI_LINK_TYPE_INTERNAL
AMDSMI_LINK_TYPE_XGMI = amdsmi_wrapper.AMDSMI_LINK_TYPE_XGMI
AMDSMI_LINK_TYPE_PCIE = amdsmi_wrapper.AMDSMI_LINK_TYPE_PCIE
AMDSMI_LINK_TYPE_NOT_APPLICABLE = amdsmi_wrapper.AMDSMI_LINK_TYPE_NOT_APPLICABLE
AMDSMI_LINK_TYPE_UNKNOWN = amdsmi_wrapper.AMDSMI_LINK_TYPE_UNKNOWN
class AmdSmiUtilizationCounterType(IntEnum):
COARSE_GRAIN_GFX_ACTIVITY = amdsmi_wrapper.AMDSMI_COARSE_GRAIN_GFX_ACTIVITY
COARSE_GRAIN_MEM_ACTIVITY = amdsmi_wrapper.AMDSMI_COARSE_GRAIN_MEM_ACTIVITY
COARSE_DECODER_ACTIVITY = amdsmi_wrapper.AMDSMI_COARSE_DECODER_ACTIVITY
FINE_GRAIN_GFX_ACTIVITY = amdsmi_wrapper.AMDSMI_FINE_GRAIN_GFX_ACTIVITY
FINE_GRAIN_MEM_ACTIVITY = amdsmi_wrapper.AMDSMI_FINE_GRAIN_MEM_ACTIVITY
FINE_DECODER_ACTIVITY = amdsmi_wrapper.AMDSMI_FINE_DECODER_ACTIVITY
UTILIZATION_COUNTER_FIRST = amdsmi_wrapper.AMDSMI_UTILIZATION_COUNTER_FIRST
UTILIZATION_COUNTER_LAST = amdsmi_wrapper.AMDSMI_UTILIZATION_COUNTER_LAST
class AmdSmiProcessorType(IntEnum):
UNKNOWN = amdsmi_wrapper.AMDSMI_PROCESSOR_TYPE_UNKNOWN
AMDSMI_PROCESSOR_TYPE_AMD_GPU = amdsmi_wrapper.AMDSMI_PROCESSOR_TYPE_AMD_GPU
AMDSMI_PROCESSOR_TYPE_AMD_CPU = amdsmi_wrapper.AMDSMI_PROCESSOR_TYPE_AMD_CPU
AMDSMI_PROCESSOR_TYPE_NON_AMD_GPU = amdsmi_wrapper.AMDSMI_PROCESSOR_TYPE_NON_AMD_GPU
AMDSMI_PROCESSOR_TYPE_NON_AMD_CPU = amdsmi_wrapper.AMDSMI_PROCESSOR_TYPE_NON_AMD_CPU
class AmdSmiRegType(IntEnum):
XGMI = amdsmi_wrapper.AMDSMI_REG_XGMI
WAFL = amdsmi_wrapper.AMDSMI_REG_WAFL
PCIE = amdsmi_wrapper.AMDSMI_REG_PCIE
USR = amdsmi_wrapper.AMDSMI_REG_USR
USR1 = amdsmi_wrapper.AMDSMI_REG_USR1
class AmdSmiVirtualizationMode(IntEnum):
UNKNOWN = amdsmi_wrapper.AMDSMI_VIRTUALIZATION_MODE_UNKNOWN
BAREMETAL = amdsmi_wrapper.AMDSMI_VIRTUALIZATION_MODE_BAREMETAL
HOST = amdsmi_wrapper.AMDSMI_VIRTUALIZATION_MODE_HOST
GUEST = amdsmi_wrapper.AMDSMI_VIRTUALIZATION_MODE_GUEST
PASSTHROUGH = amdsmi_wrapper.AMDSMI_VIRTUALIZATION_MODE_PASSTHROUGH
class AmdSmiVramType(IntEnum):
UNKNOWN = amdsmi_wrapper.AMDSMI_VRAM_TYPE_UNKNOWN
HBM = amdsmi_wrapper.AMDSMI_VRAM_TYPE_HBM
HBM2 = amdsmi_wrapper.AMDSMI_VRAM_TYPE_HBM2
HBM2E = amdsmi_wrapper.AMDSMI_VRAM_TYPE_HBM2E
HBM3 = amdsmi_wrapper.AMDSMI_VRAM_TYPE_HBM3
DDR2 = amdsmi_wrapper.AMDSMI_VRAM_TYPE_DDR2
DDR3 = amdsmi_wrapper.AMDSMI_VRAM_TYPE_DDR3
DDR4 = amdsmi_wrapper.AMDSMI_VRAM_TYPE_DDR4
GDDR1 = amdsmi_wrapper.AMDSMI_VRAM_TYPE_GDDR1
GDDR2 = amdsmi_wrapper.AMDSMI_VRAM_TYPE_GDDR2
GDDR3 = amdsmi_wrapper.AMDSMI_VRAM_TYPE_GDDR3
GDDR4 = amdsmi_wrapper.AMDSMI_VRAM_TYPE_GDDR4
GDDR5 = amdsmi_wrapper.AMDSMI_VRAM_TYPE_GDDR5
GDDR6 = amdsmi_wrapper.AMDSMI_VRAM_TYPE_GDDR6
GDDR7 = amdsmi_wrapper.AMDSMI_VRAM_TYPE_GDDR7
MAX = amdsmi_wrapper.AMDSMI_VRAM_TYPE__MAX
class AmdSmiAffinityScope(IntEnum):
NUMA_SCOPE = amdsmi_wrapper.AMDSMI_AFFINITY_SCOPE_NODE
SOCKET_SCOPE = amdsmi_wrapper.AMDSMI_AFFINITY_SCOPE_SOCKET
class AmdSmiEventReader:
def __init__(
self,
processor_handle: processor_handle,
event_types: List[AmdSmiEvtNotificationType]
):
if not isinstance(processor_handle, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(
processor_handle, amdsmi_wrapper.amdsmi_processor_handle
)
if not isinstance(event_types, Iterable):
raise AmdSmiParameterException(
event_types, Iterable
)
for event_type in event_types:
if not isinstance(event_type, AmdSmiEvtNotificationType):
raise AmdSmiParameterException(
event_type, AmdSmiEvtNotificationType
)
self.processor_handle = processor_handle
mask = 0
for event_type in event_types:
if event_type != AmdSmiEvtNotificationType.NONE:
mask |= (1 << (int(event_type) - 1))
_check_res(amdsmi_wrapper.amdsmi_init_gpu_event_notification(processor_handle))
_check_res(amdsmi_wrapper.amdsmi_set_gpu_event_notification_mask(
processor_handle, ctypes.c_uint64(mask)))
def read(self, timestamp, num_elem=10):
c_count = ctypes.c_uint32(num_elem)
self.event_info = (amdsmi_wrapper.amdsmi_evt_notification_data_t * num_elem)()
_check_res(
amdsmi_wrapper.amdsmi_get_gpu_event_notification(
ctypes.c_int(timestamp),
ctypes.byref(c_count),
self.event_info,
)
)
ret = []
for i in range(c_count.value):
unique_event_values = set(event.value for event in AmdSmiEvtNotificationType)
if self.event_info[i].event in unique_event_values:
if AmdSmiEvtNotificationType(self.event_info[i].event).name != "NONE":
processor_handle = amdsmi_wrapper.amdsmi_processor_handle(self.event_info[i].processor_handle)
ret.append(
{
"processor_handle": processor_handle,
"event": AmdSmiEvtNotificationType(self.event_info[i].event).name,
"message": self.event_info[i].message.decode("utf-8"),
}
)
return ret
def stop(self):
_check_res(amdsmi_wrapper.amdsmi_stop_gpu_event_notification(
self.processor_handle))
def __enter__(self):
return self
def __exit__(self, exc_type, exc_value, traceback):
self.stop()
def _format_bad_page_info(bad_page_info, bad_page_count: ctypes.c_uint32) -> List[Dict]:
"""
Format bad page info data retrieved.
Parameters:
bad_page_info(`amdsmi_retired_page_record_t`): A populated list of amdsmi_retired_page_record_t(s)
retrieved. Ex: (amdsmi_wrapper.amdsmi_retired_page_record_t * #)()
bad_page_count(`c_uint32`): Bad page count.
Returns:
`list`: List containing formatted bad pages. Can be empty
"""
if bad_page_count == 0:
return []
# Check if each struct within bad_page_info is valid
for bad_page in bad_page_info:
if not isinstance(bad_page, amdsmi_wrapper.amdsmi_retired_page_record_t):
raise AmdSmiParameterException(
bad_page, amdsmi_wrapper.amdsmi_retired_page_record_t
)
table_records = []
for i in range(bad_page_count.value):
table_records.append(
{
"value": i,
"page_address": bad_page_info[i].page_address,
"page_size": bad_page_info[i].page_size,
"status": bad_page_info[i].status,
}
)
return table_records
def _format_bdf(amdsmi_bdf: amdsmi_wrapper.amdsmi_bdf_t) -> str:
"""
Format BDF struct to readable data.
Parameters:
amdsmi_bdf(`amdsmi_bdf_t`): Struct containing BDF data that
will be formatted.
Returns:
`str`: String containing BDF data in a readable format.
"""
domain = hex(amdsmi_bdf.struct_amdsmi_bdf_t.domain_number)[2:].zfill(4)
bus = hex(amdsmi_bdf.struct_amdsmi_bdf_t.bus_number)[2:].zfill(2)
device = hex(amdsmi_bdf.struct_amdsmi_bdf_t.device_number)[2:].zfill(2)
function = hex(amdsmi_bdf.struct_amdsmi_bdf_t.function_number)[2:]
return domain + ":" + bus + ":" + device + "." + function
def _check_res(ret_code) -> None:
"""
Wrapper for amdsmi function calls. Checks the status returned
by the call. Raises exceptions if the status was inappropriate.
Parameters:
ret_code(`amdsmi_status_t`): Status code returned by function
call.
Returns:
`None`.
"""
if ret_code == amdsmi_wrapper.AMDSMI_STATUS_RETRY:
raise AmdSmiRetryException()
if ret_code == amdsmi_wrapper.AMDSMI_STATUS_TIMEOUT:
raise AmdSmiTimeoutException()
if ret_code != amdsmi_wrapper.AMDSMI_STATUS_SUCCESS:
raise AmdSmiLibraryException(ret_code)
def _parse_bdf(bdf):
if bdf is None:
return None
extended_regex = re.compile(
r'^([0-9a-fA-F]{4}):([0-9a-fA-F]{2}):([0-1][0-9a-fA-F])\.([0-7])$')
if extended_regex.match(bdf) is None:
simple_regex = re.compile(
r'^([0-9a-fA-F]{2}):([0-1][0-9a-fA-F])\.([0-7])$')
if simple_regex.match(bdf) is None:
return None
else:
match = simple_regex.match(bdf)
if match:
return [0] + [int(x, 16) for x in match.groups()]
else:
return None
else:
match = extended_regex.match(bdf)
if match:
return [int(x, 16) for x in match.groups()]
return None
def _make_amdsmi_bdf_from_list(bdf):
if len(bdf) != 4:
return None
amdsmi_bdf = amdsmi_wrapper.amdsmi_bdf_t()
amdsmi_bdf.struct_amdsmi_bdf_t.function_number = bdf[3]
amdsmi_bdf.struct_amdsmi_bdf_t.device_number = bdf[2]
amdsmi_bdf.struct_amdsmi_bdf_t.bus_number = bdf[1]
amdsmi_bdf.struct_amdsmi_bdf_t.domain_number = bdf[0]
return amdsmi_bdf
def _pad_hex_value(value, length):
""" Pad a hexadecimal value with a given length of zeros
:param value: A hexadecimal value to be padded with zeros
:param length: Number of zeros to pad the hexadecimal value
:param return original string string or
padded hex of confirmed hex output (using length provided)
"""
# Ensure value entered meets the minimum length and is hexadecimal
if len(value) > 2 and length > 1 and value[:2].lower() == '0x' \
and all(c in '0123456789abcdefABCDEF' for c in value[2:]):
# Pad with zeros after '0x' prefix
return '0x' + value[2:].zfill(length)
return value
def _validate_if_max_uint(value, uint_type: MaxUIntegerTypes, isActivity=False, isBool=False) -> Union[str, bool, int]:
return_val = "N/A"
if not isinstance(value, list):
if (value == uint_type) or (isActivity and value > 100):
return return_val
else:
if isBool:
return bool(value)
else:
return value
else:
return_val = []
for _, v in enumerate(value):
if (v == uint_type) or (isActivity and v > 100):
return_val.append("N/A")
else:
return_val.append(v)
if isBool:
return bool(return_val)
else:
return return_val
def _notifyTypeToString(notify_type_b):
guid = []
# Iterate over only the first 8 bytes, but backwards
for i in notify_type_b[7::-1]:
guid.append(format(i, '02x'))
hex_string = "".join(guid)
hex_value = int(hex_string, 16)
if hex_value in AmdSmiCperNotifyType._value2member_map_:
# Convert to the corresponding enum name
return AmdSmiCperNotifyType(hex_value).name
else:
return "Unknown"
def _NA_amdsmi_get_gpu_metrics_info() -> Dict[str, str]:
"""
Get 'N/A' metric values for gpu_metric, used for exception handling.
Parameters:
None
Returns:
Dict[str, str]: A dictionary with keys as metric names and values as 'N/A'.
This is used to indicate that the metric is not available or applicable.
Raises:
N/A
"""
na_gpu_metrics_info = {
"common_header.structure_size": "N/A",
"common_header.format_revision": "N/A",
"common_header.content_revision": "N/A",
"temperature_edge": "N/A",
"temperature_hotspot": "N/A",
"temperature_mem": "N/A",
"temperature_vrgfx": "N/A",
"temperature_vrsoc": "N/A",
"temperature_vrmem": "N/A",
"average_gfx_activity": "N/A",
"average_umc_activity": "N/A",
"average_mm_activity": "N/A",
"average_socket_power": "N/A",
"energy_accumulator": "N/A",
"system_clock_counter": "N/A",
"average_gfxclk_frequency": "N/A",
"average_socclk_frequency": "N/A",
"average_uclk_frequency": "N/A",
"average_vclk0_frequency": "N/A",
"average_dclk0_frequency": "N/A",
"average_vclk1_frequency": "N/A",
"average_dclk1_frequency": "N/A",
"current_gfxclk": "N/A",
"current_socclk": "N/A",
"current_uclk": "N/A",
"current_vclk0": "N/A",
"current_dclk0": "N/A",
"current_vclk1": "N/A",
"current_dclk1": "N/A",
"throttle_status": "N/A",
"current_fan_speed": "N/A",
"pcie_link_width": "N/A",
"pcie_link_speed": "N/A",
"gfx_activity_acc": "N/A",
"mem_activity_acc": "N/A",
"temperature_hbm": "N/A",
"firmware_timestamp": "N/A",
"voltage_soc": "N/A",
"voltage_gfx": "N/A",
"voltage_mem": "N/A",
"indep_throttle_status": "N/A",
"current_socket_power": "N/A",
"vcn_activity": "N/A",
"gfxclk_lock_status": "N/A",
"xgmi_link_width": "N/A",
"xgmi_link_speed": "N/A",
"pcie_bandwidth_acc": "N/A",
"pcie_bandwidth_inst": "N/A",
"pcie_l0_to_recov_count_acc": "N/A",
"pcie_replay_count_acc": "N/A",
"pcie_replay_rover_count_acc": "N/A",
"xgmi_read_data_acc": "N/A",
"xgmi_write_data_acc": "N/A",
"current_gfxclks": "N/A",
"current_socclks": "N/A",
"current_vclk0s": "N/A",
"current_dclk0s": "N/A",
"jpeg_activity": "N/A",
"pcie_nak_sent_count_acc": "N/A",
"pcie_nak_rcvd_count_acc": "N/A",
"accumulation_counter": "N/A",
"prochot_residency_acc": "N/A",
"ppt_residency_acc": "N/A",
"socket_thm_residency_acc": "N/A",
"vr_thm_residency_acc": "N/A",
"hbm_thm_residency_acc": "N/A",
"num_partition": "N/A",
"xcp_stats.gfx_busy_inst": "N/A",
"xcp_stats.jpeg_busy": "N/A",
"xcp_stats.vcn_busy": "N/A",
"xcp_stats.gfx_busy_acc": "N/A",
"xcp_stats.gfx_below_host_limit_acc": "N/A",
"xcp_stats.gfx_below_host_limit_ppt_acc": "N/A",
"xcp_stats.gfx_below_host_limit_thm_acc": "N/A",
"xcp_stats.gfx_low_utilization_acc": "N/A",
"xcp_stats.gfx_below_host_limit_total_acc": "N/A",
"pcie_lc_perf_other_end_recovery": "N/A",
"vram_max_bandwidth": "N/A",
"xgmi_link_status": "N/A"
}
return na_gpu_metrics_info
def amdsmi_get_socket_handles() -> List[c_void_p]:
"""
Function that gets socket handles. Wraps the same named function call.
Parameters:
`None`.
Returns:
`List`: List containing all of the found socket handles.
"""
socket_count = ctypes.c_uint32(0)
null_ptr = POINTER(amdsmi_wrapper.amdsmi_socket_handle)()
_check_res(
amdsmi_wrapper.amdsmi_get_socket_handles(
ctypes.byref(socket_count), null_ptr)
)
socket_handles = (amdsmi_wrapper.amdsmi_socket_handle *
socket_count.value)()
_check_res(
amdsmi_wrapper.amdsmi_get_socket_handles(
ctypes.byref(socket_count), socket_handles)
)
sockets = [
amdsmi_wrapper.amdsmi_socket_handle(socket_handles[sock_idx])
for sock_idx in range(socket_count.value)
]
return sockets
def amdsmi_get_cpusocket_handles() -> List[c_void_p]:
"""
Function that gets cpu socket handles. Wraps the same named function call.
Parameters:
`None`.
Returns:
`List`: List containing all of the found cpu socket handles.
"""
cpu_count = ctypes.c_uint32(0)
null_ptr = POINTER(amdsmi_wrapper.amdsmi_processor_handle)()
_check_res(
amdsmi_wrapper.amdsmi_get_cpu_handles(
ctypes.byref(cpu_count), null_ptr)
)
proc_handles = (amdsmi_wrapper.amdsmi_processor_handle *
cpu_count.value)()
_check_res(
amdsmi_wrapper.amdsmi_get_cpu_handles(
ctypes.byref(cpu_count), proc_handles)
)
cpu_handles = [
amdsmi_wrapper.amdsmi_processor_handle(proc_handles[sock_idx])
for sock_idx in range(cpu_count.value)
]
return cpu_handles
def amdsmi_get_socket_info(socket_handle):
if not isinstance(socket_handle, amdsmi_wrapper.amdsmi_socket_handle):
raise AmdSmiParameterException(
socket_handle, amdsmi_wrapper.amdsmi_socket_handle)
socket_info = ctypes.create_string_buffer(128)
_check_res(
amdsmi_wrapper.amdsmi_get_socket_info(
socket_handle, ctypes.c_size_t(128), socket_info)
)
return socket_info.value.decode()
def amdsmi_get_processor_info(processor_handle):
if not isinstance(processor_handle, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(
processor_handle, amdsmi_wrapper.amdsmi_processor_handle)
processor_info = ctypes.create_string_buffer(128)
core_id = ctypes.c_uint32()
_check_res(
amdsmi_wrapper.amdsmi_get_processor_info(
processor_handle, ctypes.c_size_t(128), processor_info)
)
return processor_info.value.decode()
def amdsmi_get_processor_handles() -> List[c_void_p]:
socket_handles = amdsmi_get_socket_handles()
devices = []
for socket in socket_handles:
device_count = ctypes.c_uint32()
null_ptr = POINTER(amdsmi_wrapper.amdsmi_processor_handle)()
_check_res(
amdsmi_wrapper.amdsmi_get_processor_handles(
socket,
ctypes.byref(device_count),
null_ptr,
)
)
processor_handles = (
amdsmi_wrapper.amdsmi_processor_handle * device_count.value)()
_check_res(
amdsmi_wrapper.amdsmi_get_processor_handles(
socket,
ctypes.byref(device_count),
processor_handles,
)
)
devices.extend(
[
amdsmi_wrapper.amdsmi_processor_handle(processor_handles[dev_idx])
for dev_idx in range(device_count.value)
]
)
return devices
def amdsmi_get_cpucore_handles() -> List[c_void_p]:
cores_count = ctypes.c_uint32(0)
null_ptr = POINTER(amdsmi_wrapper.amdsmi_processor_handle)()
_check_res(
amdsmi_wrapper.amdsmi_get_cpucore_handles(
ctypes.byref(cores_count), null_ptr)
)
proc_handles = (amdsmi_wrapper.amdsmi_processor_handle *
cores_count.value)()
_check_res(
amdsmi_wrapper.amdsmi_get_cpucore_handles(
ctypes.byref(cores_count), proc_handles)
)
core_handles = [
amdsmi_wrapper.amdsmi_processor_handle(proc_handles[sock_idx])
for sock_idx in range(cores_count.value)
]
return core_handles
def amdsmi_get_cpu_hsmp_proto_ver(processor_handle: processor_handle) -> int:
if not isinstance(processor_handle, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(
processor_handle, amdsmi_wrapper.amdsmi_processor_handle
)
proto_ver = ctypes.c_uint32()
_check_res(
amdsmi_wrapper.amdsmi_get_cpu_hsmp_proto_ver(
processor_handle, ctypes.byref(proto_ver)
)
)
return proto_ver.value
def amdsmi_get_cpu_smu_fw_version(
processor_handle: processor_handle) -> Dict[str, int]:
if not isinstance(processor_handle, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(
processor_handle, amdsmi_wrapper.amdsmi_processor_handle
)
smu_fw = amdsmi_wrapper.amdsmi_smu_fw_version_t()
_check_res(amdsmi_wrapper.amdsmi_get_cpu_smu_fw_version(processor_handle, smu_fw))
return {
"smu_fw_debug_ver_num": smu_fw.debug,
"smu_fw_minor_ver_num": smu_fw.minor,
"smu_fw_major_ver_num": smu_fw.major
}
def amdsmi_get_cpu_hsmp_driver_version(
processor_handle: processor_handle) -> Dict[str, int]:
if not isinstance(processor_handle, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(
processor_handle, amdsmi_wrapper.amdsmi_processor_handle
)
hsmp_driver_version = amdsmi_wrapper.amdsmi_hsmp_driver_version_t()
_check_res(amdsmi_wrapper.amdsmi_get_cpu_hsmp_driver_version(processor_handle, hsmp_driver_version))
return {
"hsmp_driver_major_ver_num": hsmp_driver_version.major,
"hsmp_driver_minor_ver_num": hsmp_driver_version.minor,
}
def amdsmi_get_cpu_core_energy(
processor_handle: processor_handle
) -> int:
if not isinstance(processor_handle, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(
processor_handle, amdsmi_wrapper.amdsmi_processor_handle
)
penergy = ctypes.c_uint64()
_check_res(
amdsmi_wrapper.amdsmi_get_cpu_core_energy(
processor_handle, ctypes.byref(penergy)
)
)
return f"{float(penergy.value * pow(10, -6))} J"
def amdsmi_get_cpu_socket_energy(
processor_handle: processor_handle
) -> int:
if not isinstance(processor_handle, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(
processor_handle, amdsmi_wrapper.amdsmi_processor_handle
)
penergy = ctypes.c_uint64()
_check_res(
amdsmi_wrapper.amdsmi_get_cpu_socket_energy(
processor_handle, ctypes.byref(penergy)
)
)
return f"{float(penergy.value * pow(10, -6))} J"
def amdsmi_get_threads_per_core():
threads_per_core = ctypes.c_uint32()
_check_res(
amdsmi_wrapper.amdsmi_get_threads_per_core(
ctypes.byref(threads_per_core)
)
)
return threads_per_core.value
def amdsmi_get_cpu_prochot_status(
processor_handle: processor_handle
) -> int:
if not isinstance(processor_handle, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(
processor_handle, amdsmi_wrapper.amdsmi_processor_handle
)
prochot = ctypes.c_uint32()
_check_res(
amdsmi_wrapper.amdsmi_get_cpu_prochot_status(
processor_handle, ctypes.byref(prochot)
)
)
return prochot.value
def amdsmi_get_cpu_fclk_mclk(
processor_handle: processor_handle
):
if not isinstance(processor_handle, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(
processor_handle, amdsmi_wrapper.amdsmi_processor_handle
)
fclk = ctypes.c_uint32()
mclk = ctypes.c_uint32()
_check_res(
amdsmi_wrapper.amdsmi_get_cpu_fclk_mclk(
processor_handle, ctypes.byref(fclk), ctypes.byref(mclk)
)
)
return {
"fclk": f"{fclk.value} MHz",
"mclk": f"{mclk.value} MHz"
}
def amdsmi_get_cpu_cclk_limit(
processor_handle: processor_handle
) -> int:
if not isinstance(processor_handle, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(
processor_handle, amdsmi_wrapper.amdsmi_processor_handle
)
cclk = ctypes.c_uint32()
_check_res(
amdsmi_wrapper.amdsmi_get_cpu_cclk_limit(
processor_handle, ctypes.byref(cclk)
)
)
return f"{cclk.value} MHz"
def amdsmi_get_cpu_socket_current_active_freq_limit(
processor_handle: processor_handle
):
if not isinstance(processor_handle, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(
processor_handle, amdsmi_wrapper.amdsmi_processor_handle
)
amdsmi_wrapper.amdsmi_get_cpu_socket_current_active_freq_limit.argtypes = [amdsmi_wrapper.amdsmi_processor_handle, POINTER(ctypes.c_uint16), POINTER(ctypes.c_char_p * len(amdsmi_wrapper.amdsmi_hsmp_freqlimit_src_names))]
freq = ctypes.c_uint16()
src_type = (ctypes.c_char_p * len(amdsmi_wrapper.amdsmi_hsmp_freqlimit_src_names))()
_check_res(
amdsmi_wrapper.amdsmi_get_cpu_socket_current_active_freq_limit(
processor_handle, ctypes.byref(freq), src_type
)
)
freq_src = []
for names in src_type:
if names is not None:
freq_src.append(names.decode('utf-8'))
return {
"freq": f"{freq.value} MHz",
"freq_src": f"{freq_src}"
}
def amdsmi_get_cpu_socket_freq_range(
processor_handle: processor_handle
):
if not isinstance(processor_handle, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(
processor_handle, amdsmi_wrapper.amdsmi_processor_handle
)
freq_max = ctypes.c_uint16()
freq_min = ctypes.c_uint16()
_check_res(
amdsmi_wrapper.amdsmi_get_cpu_socket_freq_range(
processor_handle, ctypes.byref(freq_max), ctypes.byref(freq_min)
)
)
return {
"max_socket_freq": f"{freq_max.value} MHz",
"min_socket_freq": f"{freq_min.value} MHz"
}
def amdsmi_get_cpu_core_current_freq_limit(
processor_handle: processor_handle
) -> int:
if not isinstance(processor_handle, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(
processor_handle, amdsmi_wrapper.amdsmi_processor_handle
)
freq = ctypes.c_uint32()
_check_res(
amdsmi_wrapper.amdsmi_get_cpu_core_current_freq_limit(
processor_handle, ctypes.byref(freq)
)
)
return f"{freq.value} MHz"
def amdsmi_get_cpu_socket_power(
processor_handle: processor_handle
) -> int:
if not isinstance(processor_handle, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(
processor_handle, amdsmi_wrapper.amdsmi_processor_handle
)
ppower = ctypes.c_uint32()
_check_res(
amdsmi_wrapper.amdsmi_get_cpu_socket_power(
processor_handle, ctypes.byref(ppower)
)
)
return f"{ppower.value} mW"
def amdsmi_get_cpu_socket_power_cap(
processor_handle: processor_handle
) -> int:
if not isinstance(processor_handle, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(
processor_handle, amdsmi_wrapper.amdsmi_processor_handle
)
pcap = ctypes.c_uint32()
_check_res(
amdsmi_wrapper.amdsmi_get_cpu_socket_power_cap(
processor_handle, ctypes.byref(pcap)
)
)
return f"{pcap.value} mW"
def amdsmi_get_cpu_socket_power_cap_max(
processor_handle: processor_handle
) -> int:
if not isinstance(processor_handle, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(
processor_handle, amdsmi_wrapper.amdsmi_processor_handle
)
pmax = ctypes.c_uint32()
_check_res(
amdsmi_wrapper.amdsmi_get_cpu_socket_power_cap_max(
processor_handle, ctypes.byref(pmax)
)
)
return f"{pmax.value} mW"
def amdsmi_get_cpu_pwr_svi_telemetry_all_rails(
processor_handle: processor_handle
) -> int:
if not isinstance(processor_handle, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(
processor_handle, amdsmi_wrapper.amdsmi_processor_handle
)
power = ctypes.c_uint32()
_check_res(
amdsmi_wrapper.amdsmi_get_cpu_pwr_svi_telemetry_all_rails(
processor_handle, ctypes.byref(power)
)
)
return f"{power.value} mW"
def amdsmi_set_cpu_socket_power_cap(
processor_handle: processor_handle, power_cap: int
):
if not isinstance(processor_handle, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(
processor_handle, amdsmi_wrapper.amdsmi_processor_handle
)
if not isinstance(power_cap, int):
raise AmdSmiParameterException(power_cap, int)
power_cap = ctypes.c_uint32(power_cap)
_check_res(
amdsmi_wrapper.amdsmi_set_cpu_socket_power_cap(
processor_handle, power_cap)
)
def amdsmi_set_cpu_pwr_efficiency_mode(
processor_handle: processor_handle, mode: int
):
if not isinstance(processor_handle, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(
processor_handle, amdsmi_wrapper.amdsmi_processor_handle
)
if not isinstance(mode, int):
raise AmdSmiParameterException(mode, int)
mode = ctypes.c_uint8(mode)
_check_res(
amdsmi_wrapper.amdsmi_set_cpu_pwr_efficiency_mode(
processor_handle, mode)
)
def amdsmi_get_cpu_core_boostlimit(
processor_handle: processor_handle
) -> int:
if not isinstance(processor_handle, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(
processor_handle, amdsmi_wrapper.amdsmi_processor_handle
)
boostlimit = ctypes.c_uint32()
_check_res(
amdsmi_wrapper.amdsmi_get_cpu_core_boostlimit(
processor_handle, ctypes.byref(boostlimit)
)
)
return f"{boostlimit.value} MHz"
def amdsmi_get_cpu_socket_c0_residency(
processor_handle: processor_handle
) -> int:
if not isinstance(processor_handle, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(
processor_handle, amdsmi_wrapper.amdsmi_processor_handle
)
c0_residency = ctypes.c_uint32()
_check_res(
amdsmi_wrapper.amdsmi_get_cpu_socket_c0_residency(
processor_handle, ctypes.byref(c0_residency)
)
)
return f"{c0_residency.value} %"
def amdsmi_set_cpu_core_boostlimit(
processor_handle: processor_handle, boostlimit: int
):
if not isinstance(processor_handle, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(
processor_handle, amdsmi_wrapper.amdsmi_processor_handle
)
if not isinstance(boostlimit, int):
raise AmdSmiParameterException(boostlimit, int)
boostlimit = ctypes.c_uint32(boostlimit)
_check_res(
amdsmi_wrapper.amdsmi_set_cpu_core_boostlimit(
processor_handle, boostlimit)
)
def amdsmi_set_cpu_socket_boostlimit(
processor_handle: processor_handle, boostlimit: int
):
if not isinstance(processor_handle, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(
processor_handle, amdsmi_wrapper.amdsmi_processor_handle
)
if not isinstance(boostlimit, int):
raise AmdSmiParameterException(boostlimit, int)
boostlimit = ctypes.c_uint32(boostlimit)
_check_res(
amdsmi_wrapper.amdsmi_set_cpu_socket_boostlimit(
processor_handle, boostlimit)
)
def amdsmi_get_cpu_ddr_bw(processor_handle: processor_handle):
if not isinstance(processor_handle, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(
processor_handle, amdsmi_wrapper.amdsmi_processor_handle
)
ddr_bw = amdsmi_wrapper.amdsmi_ddr_bw_metrics_t()
_check_res(amdsmi_wrapper.amdsmi_get_cpu_ddr_bw(processor_handle, ddr_bw))
return {
"ddr_bw_max_bw": f"{ddr_bw.max_bw} Gbps",
"ddr_bw_utilized_bw": f"{ddr_bw.utilized_bw} Gbps",
"ddr_bw_utilized_pct": f"{ddr_bw.utilized_pct} %"
}
def amdsmi_get_cpu_socket_temperature(
processor_handle: processor_handle
) -> int:
if not isinstance(processor_handle, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(
processor_handle, amdsmi_wrapper.amdsmi_processor_handle
)
ptmon = ctypes.c_uint32()
_check_res(
amdsmi_wrapper.amdsmi_get_cpu_socket_temperature(
processor_handle, ctypes.byref(ptmon)
)
)
return f"{ptmon.value} Degrees C"
def amdsmi_get_cpu_dimm_temp_range_and_refresh_rate(
processor_handle: processor_handle,
dimm_addr: int):
if not isinstance(processor_handle, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(
processor_handle, amdsmi_wrapper.amdsmi_processor_handle
)
if not isinstance(dimm_addr, int):
raise AmdSmiParameterException(dimm_addr, int)
dimm_addr = ctypes.c_uint8(dimm_addr)
dimm = amdsmi_wrapper.amdsmi_temp_range_refresh_rate_t()
_check_res(amdsmi_wrapper.amdsmi_get_cpu_dimm_temp_range_and_refresh_rate(processor_handle,
dimm_addr,
ctypes.byref(dimm)))
return {
"dimm_temperature_range": dimm.range,
"dimm_refresh_rate": dimm.ref_rate
}
def amdsmi_get_cpu_dimm_power_consumption(
processor_handle: processor_handle,
dimm_addr: int):
if not isinstance(processor_handle, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(
processor_handle, amdsmi_wrapper.amdsmi_processor_handle
)
if not isinstance(dimm_addr, int):
raise AmdSmiParameterException(dimm_addr, int)
dimm_addr = ctypes.c_uint8(dimm_addr)
dimm = amdsmi_wrapper.amdsmi_dimm_power_t()
_check_res(amdsmi_wrapper.amdsmi_get_cpu_dimm_power_consumption(processor_handle,
dimm_addr,
ctypes.byref(dimm)))
return {
"dimm_power_consumed": f"{dimm.power} mW",
"dimm_power_update_rate": f"{dimm.update_rate} ms",
"dimm_dimm_addr": dimm.dimm_addr
}
def amdsmi_get_cpu_dimm_thermal_sensor(
processor_handle: processor_handle,
dimm_addr: int):
if not isinstance(processor_handle, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(
processor_handle, amdsmi_wrapper.amdsmi_processor_handle
)
if not isinstance(dimm_addr, int):
raise AmdSmiParameterException(dimm_addr, int)
dimm_addr = ctypes.c_uint8(dimm_addr)
dimm_thermal = amdsmi_wrapper.amdsmi_dimm_thermal_t()
_check_res(amdsmi_wrapper.amdsmi_get_cpu_dimm_thermal_sensor(processor_handle,
dimm_addr,
ctypes.byref(dimm_thermal)))
return {
"dimm_thermal_sensor_value": dimm_thermal.sensor,
"dimm_thermal_update_rate": f"{dimm_thermal.update_rate} ms",
"dimm_thermal_dimm_addr": dimm_thermal.dimm_addr,
"dimm_thermal_temperature": f"{dimm_thermal.temp} Degrees C"
}
def amdsmi_set_cpu_xgmi_width(
processor_handle: processor_handle, min_width: int, max_width: int
):
if not isinstance(processor_handle, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(
processor_handle, amdsmi_wrapper.amdsmi_processor_handle
)
if not isinstance(min_width, int):
raise AmdSmiParameterException(min_width, int)
if not isinstance(max_width, int):
raise AmdSmiParameterException(max_width, int)
min_width = ctypes.c_uint8(min_width)
max_width = ctypes.c_uint8(max_width)
_check_res(
amdsmi_wrapper.amdsmi_set_cpu_xgmi_width(
processor_handle, min_width, max_width)
)
def amdsmi_set_cpu_gmi3_link_width_range(
processor_handle: processor_handle,
min_link_width: int, max_link_width: int
):
if not isinstance(processor_handle, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(
processor_handle, amdsmi_wrapper.amdsmi_processor_handle
)
if not isinstance(min_link_width, int):
raise AmdSmiParameterException(min_link_width, int)
if not isinstance(max_link_width, int):
raise AmdSmiParameterException(max_link_width, int)
min_link_width = ctypes.c_uint8(min_link_width)
max_link_width = ctypes.c_uint8(max_link_width)
_check_res(
amdsmi_wrapper.amdsmi_set_cpu_gmi3_link_width_range(
processor_handle, min_link_width, max_link_width)
)
def amdsmi_cpu_apb_enable(
processor_handle: processor_handle
):
if not isinstance(processor_handle, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(
processor_handle, amdsmi_wrapper.amdsmi_processor_handle
)
_check_res(
amdsmi_wrapper.amdsmi_cpu_apb_enable(processor_handle)
)
def amdsmi_cpu_apb_disable(
processor_handle: processor_handle,
pstate: int
):
if not isinstance(processor_handle, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(
processor_handle, amdsmi_wrapper.amdsmi_processor_handle
)
if not isinstance(pstate, int):
raise AmdSmiParameterException(pstate, int)
pstate = ctypes.c_uint8(pstate)
_check_res(
amdsmi_wrapper.amdsmi_cpu_apb_disable(
processor_handle, pstate)
)
def amdsmi_set_cpu_socket_lclk_dpm_level(
processor_handle: processor_handle,
nbio_id: int, min_val: int, max_val: int
):
if not isinstance(processor_handle, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(
processor_handle, amdsmi_wrapper.amdsmi_processor_handle
)
if not isinstance(nbio_id, int):
raise AmdSmiParameterException(nbio_id, int)
if not isinstance(min_val, int):
raise AmdSmiParameterException(min_val, int)
if not isinstance(max_val, int):
raise AmdSmiParameterException(max_val, int)
nbio_id = ctypes.c_uint8(nbio_id)
min_val = ctypes.c_uint8(min_val)
max_val = ctypes.c_uint8(max_val)
_check_res(
amdsmi_wrapper.amdsmi_set_cpu_socket_lclk_dpm_level(
processor_handle, nbio_id, min_val, max_val)
)
def amdsmi_get_cpu_socket_lclk_dpm_level(
processor_handle: processor_handle,
nbio_id: int
):
if not isinstance(processor_handle, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(
processor_handle, amdsmi_wrapper.amdsmi_processor_handle
)
if not isinstance(nbio_id, int):
raise AmdSmiParameterException(nbio_id, int)
nbio_id = ctypes.c_uint8(nbio_id)
dpm_level = amdsmi_wrapper.amdsmi_dpm_level_t()
_check_res(amdsmi_wrapper.amdsmi_get_cpu_socket_lclk_dpm_level(processor_handle, nbio_id, dpm_level))
return {
"nbio_max_dpm_level": dpm_level.max_dpm_level,
"nbio_min_dpm_level": dpm_level.min_dpm_level
}
def amdsmi_set_cpu_pcie_link_rate(
processor_handle: processor_handle,
rate_ctrl: int
):
if not isinstance(processor_handle, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(
processor_handle, amdsmi_wrapper.amdsmi_processor_handle
)
if not isinstance(rate_ctrl, int):
raise AmdSmiParameterException(rate_ctrl, int)
rate_ctrl = ctypes.c_uint8(rate_ctrl)
prev_mode = ctypes.c_uint8()
_check_res(
amdsmi_wrapper.amdsmi_set_cpu_pcie_link_rate(
processor_handle, rate_ctrl, ctypes.byref(prev_mode))
)
return f"{prev_mode.value}"
def amdsmi_set_cpu_df_pstate_range(
processor_handle: processor_handle,
max_pstate: int, min_pstate: int
):
if not isinstance(processor_handle, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(
processor_handle, amdsmi_wrapper.amdsmi_processor_handle
)
if not isinstance(max_pstate, int):
raise AmdSmiParameterException(max_pstate, int)
if not isinstance(min_pstate, int):
raise AmdSmiParameterException(min_pstate, int)
max_pstate = ctypes.c_uint8(max_pstate)
min_pstate = ctypes.c_uint8(min_pstate)
_check_res(
amdsmi_wrapper.amdsmi_set_cpu_df_pstate_range(
processor_handle, max_pstate, min_pstate))
def amdsmi_get_cpu_current_io_bandwidth(
processor_handle: processor_handle,
encoding: int,
link_name: str
):
if not isinstance(processor_handle, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(
processor_handle, amdsmi_wrapper.amdsmi_processor_handle
)
link = amdsmi_wrapper.amdsmi_link_id_bw_type_t()
link.bw_type = ctypes.c_uint32(encoding)
link.link_name = ctypes.create_string_buffer(link_name.encode('utf-8'))
io_bw = ctypes.c_uint32()
_check_res(
amdsmi_wrapper.amdsmi_get_cpu_current_io_bandwidth(
processor_handle, link, ctypes.byref(io_bw))
)
return f"{io_bw.value} Mbps"
def amdsmi_get_cpu_current_xgmi_bw(
processor_handle: processor_handle,
encoding: int,
link_name: str
):
if not isinstance(processor_handle, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(
processor_handle, amdsmi_wrapper.amdsmi_processor_handle
)
link = amdsmi_wrapper.amdsmi_link_id_bw_type_t()
link.bw_type = ctypes.c_uint32(encoding)
link.link_name = ctypes.create_string_buffer(link_name.encode('utf-8'))
xgmi_bw = ctypes.c_uint32()
_check_res(
amdsmi_wrapper.amdsmi_get_cpu_current_xgmi_bw(
processor_handle, link, ctypes.byref(xgmi_bw))
)
return f"{xgmi_bw.value} Mbps"
def amdsmi_get_hsmp_metrics_table_version(
processor_handle: processor_handle
):
if not isinstance(processor_handle, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(
processor_handle, amdsmi_wrapper.amdsmi_processor_handle
)
metric_tbl_version = ctypes.c_uint32()
_check_res(
amdsmi_wrapper.amdsmi_get_hsmp_metrics_table_version(
processor_handle, ctypes.byref(metric_tbl_version))
)
return metric_tbl_version.value
# Get 2's complement of 32 bit unsigned integer
def check_msb_32(num):
msb = 1 << (NO_OF_32BITS - 1)
'''If msb = 1 , then take 2's complement of the number'''
if num & msb:
num = ~num + 1
return num
else:
return num
# Get 2's complement of 64 bit unsigned integer
def check_msb_64(num):
msb = 1 << (NO_OF_64BITS - 1)
'''If msb = 1 , then take 2's complement of the number'''
if num & msb:
num = ~num + 1
return num
else:
return num
def amdsmi_get_hsmp_metrics_table(
processor_handle: processor_handle
):
if not isinstance(processor_handle, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(
processor_handle, amdsmi_wrapper.amdsmi_processor_handle
)
mtbl = amdsmi_wrapper.amdsmi_hsmp_metrics_table_t()
'''Encodings for the metric table defined for hsmp'''
fraction_q10 = 1 / math.pow(2, 10)
fraction_uq10 = fraction_q10
fraction_uq16 = 1 / math.pow(2, 16)
_check_res(
amdsmi_wrapper.amdsmi_get_hsmp_metrics_table(
processor_handle, mtbl
)
)
rawtime = int(mtbl.timestamp)
rawtime = time()
timeinfo = localtime(rawtime)
return {
"mtbl_accumulation_counter": mtbl.accumulation_counter,
"mtbl_max_socket_temperature": f"{round(check_msb_32(mtbl.max_socket_temperature) * fraction_q10 ,3)} °C",
"mtbl_max_vr_temperature": f"{round(check_msb_32(mtbl.max_vr_temperature) * fraction_q10 ,3)} °C",
"mtbl_max_hbm_temperature": f"{round(check_msb_32(mtbl.max_hbm_temperature) * fraction_q10 ,3)} °C",
"mtbl_max_socket_temperature_acc": f"{round(check_msb_64(mtbl.max_socket_temperature_acc) * fraction_q10 ,3)} °C",
"mtbl_max_vr_temperature_acc": f"{round(check_msb_64(mtbl.max_vr_temperature_acc) * fraction_q10 ,3)} °C",
"mtbl_max_hbm_temperature_acc": f"{round(check_msb_64(mtbl.max_hbm_temperature_acc) * fraction_q10 ,3)} °C",
"mtbl_socket_power_limit": f"{round(mtbl.socket_power_limit * fraction_uq10 ,3)} W",
"mtbl_max_socket_power_limit": f"{round(mtbl.max_socket_power_limit * fraction_uq10 ,3)} W",
"mtbl_socket_power": f"{round(mtbl.socket_power * fraction_uq10 ,3)} W",
"mtbl_timestamp_raw": mtbl.timestamp,
"mtbl_timestamp_readable": f"{asctime(timeinfo)}",
"mtbl_socket_energy_acc": f"{round((mtbl.socket_energy_acc * fraction_uq16)/KILO ,3)} kJ",
"mtbl_ccd_energy_acc": f"{round((mtbl.ccd_energy_acc * fraction_uq16)/KILO ,3)} kJ",
"mtbl_xcd_energy_acc": f"{round((mtbl.xcd_energy_acc * fraction_uq16)/KILO ,3)} kJ",
"mtbl_aid_energy_acc": f"{round((mtbl.aid_energy_acc * fraction_uq16)/KILO ,3)} kJ",
"mtbl_hbm_energy_acc": f"{round((mtbl.hbm_energy_acc * fraction_uq16)/KILO ,3)} kJ",
"mtbl_cclk_frequency_limit": f"{round(mtbl.cclk_frequency_limit * fraction_uq10 ,3)} GHz",
"mtbl_gfxclk_frequency_limit": f"{round(mtbl.gfxclk_frequency_limit * fraction_uq10 ,3)} MHz",
"mtbl_fclk_frequency": f"{round(mtbl.fclk_frequency * fraction_uq10 ,3)} MHz",
"mtbl_uclk_frequency": f"{round(mtbl.uclk_frequency * fraction_uq10 ,3)} MHz",
"mtbl_socclk_frequency": f"{[round(x*fraction_uq10 ,3) for x in list(mtbl.socclk_frequency)]} MHz",
"mtbl_vclk_frequency": f"{[round(x*fraction_uq10 ,3) for x in list(mtbl.vclk_frequency)]} MHz",
"mtbl_dclk_frequency": f"{[round(x*fraction_uq10 ,3) for x in list(mtbl.dclk_frequency)]} MHz",
"mtbl_lclk_frequency": f"{[round(x*fraction_uq10 ,3) for x in list(mtbl.lclk_frequency)]} MHz",
"mtbl_fclk_frequency_table": f"{[round(x*fraction_uq10 ,3) for x in list(mtbl.fclk_frequency_table)]} MHz",
"mtbl_uclk_frequency_table": f"{[round(x*fraction_uq10 ,3) for x in list(mtbl.uclk_frequency_table)]} MHz",
"mtbl_socclk_frequency_table": f"{[round(x*fraction_uq10 ,3) for x in list(mtbl.socclk_frequency_table)]} MHz",
"mtbl_vclk_frequency_table": f"{[round(x*fraction_uq10 ,3) for x in list(mtbl.vclk_frequency_table)]} MHz",
"mtbl_dclk_frequency_table": f"{[round(x*fraction_uq10 ,3) for x in list(mtbl.dclk_frequency_table)]} MHz",
"mtbl_lclk_frequency_table": f"{[round(x*fraction_uq10 ,3) for x in list(mtbl.lclk_frequency_table)]} MHz",
"mtbl_cclk_frequency_acc": f"{[round(x*fraction_uq10 ,3) for x in list(mtbl.cclk_frequency_acc)]} GHz",
"mtbl_gfxclk_frequency_acc": f"{[round(x*fraction_uq10 ,3) for x in list(mtbl.gfxclk_frequency_acc)]} MHz",
"mtbl_gfxclk_frequency": f"{[round(x*fraction_uq10 ,3) for x in list(mtbl.gfxclk_frequency)]} MHz",
"mtbl_max_cclk_frequency": f"{round(mtbl.max_cclk_frequency * fraction_uq10 ,3)} GHz",
"mtbl_min_cclk_frequency": f"{round(mtbl.min_cclk_frequency * fraction_uq10 ,3)} GHz",
"mtbl_max_gfxclk_frequency": f"{round(mtbl.max_gfxclk_frequency * fraction_uq10 ,3)} MHz",
"mtbl_min_gfxclk_frequency": f"{round(mtbl.min_gfxclk_frequency * fraction_uq10 ,3)} MHz",
"mtbl_max_lclk_dpm_range": mtbl.max_lclk_dpm_range,
"mtbl_min_lclk_dpm_range": mtbl.min_lclk_dpm_range,
"mtbl_xgmi_width": round(mtbl.xgmi_width * fraction_uq10 ,3),
"mtbl_xgmi_bitrate": f"{round(mtbl.xgmi_bitrate * fraction_uq10 ,3)} Gbps",
"mtbl_xgmi_read_bandwidth_acc": f"{[round(x*fraction_uq10 ,3) for x in list(mtbl.xgmi_read_bandwidth_acc)]} Gbps",
"mtbl_xgmi_write_bandwidth_acc": f"{[round(x*fraction_uq10 ,3) for x in list(mtbl.xgmi_write_bandwidth_acc)]} Gbps",
"mtbl_socket_c0_residency": f"{round(mtbl.socket_c0_residency * fraction_uq10 ,3)} %",
"mtbl_socket_gfx_busy": f"{round(mtbl.socket_gfx_busy * fraction_uq10 ,3)} %",
"mtbl_hbm_bandwidth_utilization": f"{round(mtbl.dram_bandwidth_utilization * fraction_uq10 ,3)} %",
"mtbl_socket_c0_residency_acc": round(mtbl.socket_c0_residency_acc * fraction_uq10 ,3),
"mtbl_socket_gfx_busy_acc": round(mtbl.socket_gfx_busy_acc * fraction_uq10 ,3),
"mtbl_hbm_bandwidth_acc": f"{round(mtbl.dram_bandwidth_acc * fraction_uq10 ,3)} Gbps",
"mtbl_max_hbm_bandwidth": f"{round(mtbl.max_dram_bandwidth * fraction_uq10 ,3)} Gbps",
"mtbl_dram_bandwidth_utilization_acc": round(mtbl.dram_bandwidth_utilization_acc * fraction_uq10 ,3),
"mtbl_pcie_bandwidth_acc": f"{[round(x*fraction_uq10 ,3) for x in list(mtbl.pcie_bandwidth_acc)]} Gbps",
"mtbl_prochot_residency_acc": mtbl.prochot_residency_acc,
"mtbl_ppt_residency_acc": mtbl.ppt_residency_acc,
"mtbl_socket_thm_residency_acc": mtbl.socket_thm_residency_acc,
"mtbl_vr_thm_residency_acc": mtbl.vr_thm_residency_acc,
"mtbl_hbm_thm_residency_acc": mtbl.hbm_thm_residency_acc,
}
def amdsmi_first_online_core_on_cpu_socket(
processor_handle: processor_handle
):
if not isinstance(processor_handle, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(
processor_handle, amdsmi_wrapper.amdsmi_processor_handle
)
pcore_ind = ctypes.c_uint32()
_check_res(
amdsmi_wrapper.amdsmi_first_online_core_on_cpu_socket(
processor_handle, ctypes.byref(pcore_ind))
)
return pcore_ind.value
def amdsmi_get_cpu_family():
family = ctypes.c_uint32()
_check_res(
amdsmi_wrapper.amdsmi_get_cpu_family(ctypes.byref(family))
)
return family.value
def amdsmi_get_cpu_model():
model = ctypes.c_uint32()
_check_res(
amdsmi_wrapper.amdsmi_get_cpu_model(ctypes.byref(model))
)
return model.value
def amdsmi_get_cpu_model_name(
processor_handle: processor_handle
):
if not isinstance(processor_handle, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(
processor_handle, amdsmi_wrapper.amdsmi_processor_handle
)
cpu_info = amdsmi_wrapper.amdsmi_cpu_info_t()
_check_res(
amdsmi_wrapper.amdsmi_get_cpu_model_name(
processor_handle, cpu_info
)
)
return f"{cpu_info.model_name}"
def amdsmi_get_cpu_cores_per_socket(sock_count: ctypes.c_uint32):
cps = amdsmi_wrapper.amdsmi_sock_info_t()
_check_res(
amdsmi_wrapper.amdsmi_get_cpu_cores_per_socket(sock_count, cps)
)
return {"socket_id": cps.socket_id,
"cores_per_socket": cps.cores_per_socket
}
def amdsmi_get_cpu_socket_count():
sock_count = ctypes.c_uint32()
_check_res(
amdsmi_wrapper.amdsmi_get_cpu_socket_count(ctypes.byref(sock_count))
)
return sock_count.value
def amdsmi_init(flag=AmdSmiInitFlags.INIT_AMD_GPUS):
if not isinstance(flag, AmdSmiInitFlags):
raise AmdSmiParameterException(flag, AmdSmiInitFlags)
_check_res(amdsmi_wrapper.amdsmi_init(flag))
def amdsmi_shut_down():
_check_res(amdsmi_wrapper.amdsmi_shut_down())
def amdsmi_get_processor_type(
processor_handle: processor_handle,
) -> ctypes.c_uint32:
if not isinstance(processor_handle, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(
processor_handle, amdsmi_wrapper.amdsmi_processor_handle
)
dev_type = amdsmi_wrapper.processor_type_t()
_check_res(
amdsmi_wrapper.amdsmi_get_processor_type(
processor_handle, ctypes.byref(dev_type))
)
return {
"processor_type": AmdSmiProcessorType(dev_type.value).name
}
def amdsmi_get_gpu_device_bdf(processor_handle: processor_handle) -> str:
if not isinstance(processor_handle, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(
processor_handle, amdsmi_wrapper.amdsmi_processor_handle
)
bdf_info = amdsmi_wrapper.amdsmi_bdf_t()
_check_res(
amdsmi_wrapper.amdsmi_get_gpu_device_bdf(
processor_handle, ctypes.byref(bdf_info))
)
return _format_bdf(bdf_info)
def amdsmi_get_gpu_device_uuid(processor_handle: processor_handle) -> str:
if not isinstance(processor_handle, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(
processor_handle, amdsmi_wrapper.amdsmi_processor_handle
)
uuid = ctypes.create_string_buffer(AMDSMI_GPU_UUID_SIZE)
uuid_length = ctypes.c_uint32()
uuid_length.value = AMDSMI_GPU_UUID_SIZE
_check_res(
amdsmi_wrapper.amdsmi_get_gpu_device_uuid(
processor_handle, ctypes.byref(uuid_length), uuid
)
)
return uuid.value.decode("utf-8")
def amdsmi_get_gpu_enumeration_info(processor_handle: processor_handle) -> Dict[str, Any]:
"""
Retrieves GPU enumeration information including DRM card ID, DRM render ID, HIP ID, and HIP UUID.
Parameters:
processor_handle (amdsmi_processor_handle): The processor handle.
Returns:
Dict[str, Any]: A dictionary containing the retrieved enumeration information.
Raises:
AmdSmiParameterException: If the input parameters are invalid.
"""
# Validate the processor handle
if not isinstance(processor_handle, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(
processor_handle, amdsmi_wrapper.amdsmi_processor_handle
)
# Create an instance of the enumeration info struct
enumeration_info = amdsmi_wrapper.amdsmi_enumeration_info_t()
# Call the C function to populate the struct
status = amdsmi_wrapper.amdsmi_get_gpu_enumeration_info(processor_handle, ctypes.byref(enumeration_info))
# Validate the status result
_check_res(status)
# Convert the struct fields into a dictionary and return
enumeration_info = {
"drm_render": _validate_if_max_uint(enumeration_info.drm_render, MaxUIntegerTypes.UINT32_T),
"drm_card": _validate_if_max_uint(enumeration_info.drm_card, MaxUIntegerTypes.UINT32_T),
"hsa_id": _validate_if_max_uint(enumeration_info.hsa_id, MaxUIntegerTypes.UINT32_T),
"hip_id": _validate_if_max_uint(enumeration_info.hip_id, MaxUIntegerTypes.UINT32_T),
"hip_uuid": enumeration_info.hip_uuid.decode('utf-8')
}
return enumeration_info
def amdsmi_get_cpu_affinity_with_scope(
processor_handle: processor_handle,
scope: AmdSmiAffinityScope
) -> List[int]:
if not isinstance(processor_handle, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(
processor_handle, amdsmi_wrapper.amdsmi_processor_handle
)
if not isinstance(scope, AmdSmiAffinityScope):
raise AmdSmiParameterException(scope, AmdSmiAffinityScope)
socket_count = amdsmi_get_cpu_socket_count()
sock_info = amdsmi_get_cpu_cores_per_socket(socket_count)
core_count = sock_info['cores_per_socket']
size = ctypes.c_uint32(0)
size = (socket_count * core_count)/ (ctypes.sizeof(ctypes.c_uint64) * 8)
size = int(math.ceil(size))
size = ctypes.c_uint32(size)
cpu_set = (ctypes.c_uint64 * size.value)()
_check_res(
amdsmi_wrapper.amdsmi_get_cpu_affinity_with_scope(
processor_handle, size, cpu_set, scope)
)
return cpu_set
def amdsmi_get_gpu_asic_info(
processor_handle: processor_handle,
) -> Dict[str, Any]:
if not isinstance(processor_handle, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(
processor_handle, amdsmi_wrapper.amdsmi_processor_handle
)
asic_info_struct = amdsmi_wrapper.amdsmi_asic_info_t()
_check_res(
amdsmi_wrapper.amdsmi_get_gpu_asic_info(
processor_handle, ctypes.byref(asic_info_struct))
)
market_name = _pad_hex_value(asic_info_struct.market_name.decode("utf-8"), 4)
target_graphics_version = hex(asic_info_struct.target_graphics_version)[2:]
subsystem_id = _validate_if_max_uint(asic_info_struct.subsystem_id, MaxUIntegerTypes.UINT32_T)
subvendor_id = _validate_if_max_uint(asic_info_struct.subvendor_id, MaxUIntegerTypes.UINT32_T)
if not isinstance(subsystem_id, str):
subsystem_id = _pad_hex_value(hex(subsystem_id), 4)
if not isinstance(subvendor_id, str):
subvendor_id = _pad_hex_value(hex(subvendor_id), 4)
asic_info = {
"market_name": market_name,
"vendor_id": asic_info_struct.vendor_id,
"vendor_name": asic_info_struct.vendor_name.decode("utf-8"),
"subvendor_id": subvendor_id,
"device_id": asic_info_struct.device_id,
"rev_id": _pad_hex_value(hex(asic_info_struct.rev_id), 2),
"asic_serial": asic_info_struct.asic_serial.decode("utf-8"),
"oam_id": _validate_if_max_uint(asic_info_struct.oam_id, MaxUIntegerTypes.UINT32_T),
"num_compute_units": _validate_if_max_uint(asic_info_struct.num_of_compute_units, MaxUIntegerTypes.UINT32_T),
"target_graphics_version": "gfx" + target_graphics_version,
"subsystem_id": subsystem_id
}
string_values = ["market_name", "vendor_name"]
for value in string_values:
if not asic_info[value]:
asic_info[value] = "N/A"
hex_values = ["vendor_id", "device_id"]
for value in hex_values:
if asic_info[value]:
asic_info[value] = hex(asic_info[value])
else:
asic_info[value] = "N/A"
# Convert asic serial (hex string) to hex output format
if asic_info["asic_serial"]:
asic_serial_string = asic_info["asic_serial"]
asic_serial_hex = int(asic_serial_string, base=16)
asic_info["asic_serial"] = str.format("0x{:016X}", asic_serial_hex)
else:
asic_info["asic_serial"] = "N/A"
# Remove commas from vendor name for clean output
asic_info["vendor_name"] = asic_info["vendor_name"].replace(',', '')
return asic_info
def amdsmi_get_gpu_kfd_info(
processor_handle: processor_handle,
) -> Dict[str, Any]:
if not isinstance(processor_handle, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(
processor_handle, amdsmi_wrapper.amdsmi_processor_handle
)
kfd_info_struct = amdsmi_wrapper.amdsmi_kfd_info_t()
_check_res(
amdsmi_wrapper.amdsmi_get_gpu_kfd_info(
processor_handle, ctypes.byref(kfd_info_struct))
)
kfd_info = {
"kfd_id": _validate_if_max_uint(kfd_info_struct.kfd_id, MaxUIntegerTypes.UINT64_T),
"node_id": _validate_if_max_uint(kfd_info_struct.node_id, MaxUIntegerTypes.UINT32_T),
"current_partition_id": _validate_if_max_uint(kfd_info_struct.current_partition_id, MaxUIntegerTypes.UINT32_T)
}
return kfd_info
def amdsmi_get_power_cap_info(
processor_handle: processor_handle,
) -> Dict[str, Any]:
if not isinstance(processor_handle, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(
processor_handle, amdsmi_wrapper.amdsmi_processor_handle
)
power_cap_info = amdsmi_wrapper.amdsmi_power_cap_info_t()
_check_res(
amdsmi_wrapper.amdsmi_get_power_cap_info(
processor_handle, ctypes.c_uint32(0), ctypes.byref(power_cap_info)
)
)
return {"power_cap": power_cap_info.power_cap,
"default_power_cap": power_cap_info.default_power_cap,
"dpm_cap": power_cap_info.dpm_cap,
"min_power_cap": power_cap_info.min_power_cap,
"max_power_cap": power_cap_info.max_power_cap}
def amdsmi_get_gpu_pm_metrics_info(
processor_handle: processor_handle,
) -> List[Dict[str, Any]]:
if not isinstance(processor_handle, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(
processor_handle, amdsmi_wrapper.amdsmi_processor_handle
)
pm_metrics = POINTER(amdsmi_wrapper.amdsmi_name_value_t)()
num_mets = ctypes.c_uint32()
_check_res(
amdsmi_wrapper.amdsmi_get_gpu_pm_metrics_info(
processor_handle, pm_metrics, ctypes.byref(num_mets)
)
)
results = []
for i in range(num_mets.value):
item = {
'name': pm_metrics[i].name,
'value': pm_metrics[i].value
}
results.append(item)
amdsmi_wrapper.amdsmi_free_name_value_pairs(pm_metrics)
return results
def amdsmi_get_gpu_reg_table_info(
processor_handle: processor_handle,
reg_type: AmdSmiRegType,
) -> List[Dict[str, Any]]:
if not isinstance(processor_handle, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(
processor_handle, amdsmi_wrapper.amdsmi_processor_handle
)
reg_metrics = POINTER(amdsmi_wrapper.amdsmi_name_value_t)()
num_regs = ctypes.c_uint32()
_check_res(
amdsmi_wrapper.amdsmi_get_gpu_reg_table_info(
processor_handle, reg_type, reg_metrics, ctypes.byref(num_regs)
)
)
results = []
for i in range(num_regs.value):
item = {
'name': reg_metrics[i].name,
'value': reg_metrics[i].value
}
results.append(item)
amdsmi_wrapper.amdsmi_free_name_value_pairs(reg_metrics)
return results
def amdsmi_get_gpu_vram_info(
processor_handle: processor_handle,
) -> Dict[str, Any]:
if not isinstance(processor_handle, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(
processor_handle, amdsmi_wrapper.amdsmi_processor_handle
)
vram_info = amdsmi_wrapper.amdsmi_vram_info_t()
_check_res(
amdsmi_wrapper.amdsmi_get_gpu_vram_info(
processor_handle, ctypes.byref(vram_info))
)
return {
"vram_type": vram_info.vram_type,
"vram_vendor": vram_info.vram_vendor.decode("utf-8"),
"vram_size": vram_info.vram_size,
"vram_bit_width": _validate_if_max_uint(vram_info.vram_bit_width, MaxUIntegerTypes.UINT32_T),
"vram_max_bandwidth": _validate_if_max_uint(vram_info.vram_max_bandwidth, MaxUIntegerTypes.UINT64_T),
}
def amdsmi_get_gpu_xgmi_link_status(
processor_handle: processor_handle,
) -> Dict[str, Any]:
if not isinstance(processor_handle, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(
processor_handle, amdsmi_wrapper.amdsmi_processor_handle
)
status_info = amdsmi_wrapper.amdsmi_xgmi_link_status_t()
_check_res(
amdsmi_wrapper.amdsmi_get_gpu_xgmi_link_status(
processor_handle, ctypes.byref(status_info))
)
link_status = []
count = 0
for link in status_info.status:
if count == status_info.total_links:
break
if amdsmi_wrapper.amdsmi_xgmi_link_status_type_t__enumvalues[link] == 'AMDSMI_XGMI_LINK_DISABLE': # XGMI link is disabled
link_status.append("X")
elif amdsmi_wrapper.amdsmi_xgmi_link_status_type_t__enumvalues[link] == 'AMDSMI_XGMI_LINK_UP': # XGMI Link is up
link_status.append("U")
elif amdsmi_wrapper.amdsmi_xgmi_link_status_type_t__enumvalues[link] == 'AMDSMI_XGMI_LINK_DOWN': # XGMI Link is down
link_status.append("D")
else:
link_status.append("N/A")
count += 1
return_dict = {
"status" : link_status,
"total_links": status_info.total_links,
}
return return_dict
def amdsmi_get_gpu_cache_info(
processor_handle: processor_handle,
) -> Dict[str, List]:
if not isinstance(processor_handle, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(
processor_handle, amdsmi_wrapper.amdsmi_processor_handle
)
cache_info_struct = amdsmi_wrapper.amdsmi_gpu_cache_info_t()
_check_res(
amdsmi_wrapper.amdsmi_get_gpu_cache_info(
processor_handle, ctypes.byref(cache_info_struct))
)
cache_info_list = []
for cache_index in range(cache_info_struct.num_cache_types):
# Put cache_properties at the start of the dictionary for readability
cache_dict = {
"cache_properties": [], # This will be a list of strings
"cache_size": cache_info_struct.cache[cache_index].cache_size,
"cache_level": cache_info_struct.cache[cache_index].cache_level,
"max_num_cu_shared": cache_info_struct.cache[cache_index].max_num_cu_shared,
"num_cache_instance": cache_info_struct.cache[cache_index].num_cache_instance
}
# Check against cache properties bitmask
cache_properties = cache_info_struct.cache[cache_index].cache_properties
data_cache = cache_properties & amdsmi_wrapper.AMDSMI_CACHE_PROPERTY_DATA_CACHE
inst_cache = cache_properties & amdsmi_wrapper.AMDSMI_CACHE_PROPERTY_INST_CACHE
cpu_cache = cache_properties & amdsmi_wrapper.AMDSMI_CACHE_PROPERTY_CPU_CACHE
simd_cache = cache_properties & amdsmi_wrapper.AMDSMI_CACHE_PROPERTY_SIMD_CACHE
cache_properties_status = [data_cache, inst_cache, cpu_cache, simd_cache]
cache_property_list = []
for cache_property in cache_properties_status:
if cache_property:
property_name = amdsmi_wrapper.amdsmi_cache_property_type_t__enumvalues[cache_property]
property_name = property_name.replace("AMDSMI_CACHE_PROPERTY_", "")
cache_property_list.append(property_name)
cache_dict["cache_properties"] = cache_property_list
cache_info_list.append(cache_dict)
if not cache_info_list:
raise AmdSmiLibraryException(amdsmi_wrapper.AMDSMI_STATUS_NO_DATA)
return {
"cache": cache_info_list
}
def amdsmi_get_gpu_vbios_info(
processor_handle: processor_handle,
) -> Dict[str, Any]:
if not isinstance(processor_handle, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(
processor_handle, amdsmi_wrapper.amdsmi_processor_handle
)
vbios_info = amdsmi_wrapper.amdsmi_vbios_info_t()
_check_res(
amdsmi_wrapper.amdsmi_get_gpu_vbios_info(
processor_handle, ctypes.byref(vbios_info))
)
boot_firmware = vbios_info.boot_firmware.decode("utf-8")
if boot_firmware == "":
boot_firmware = "N/A"
return {
"name": vbios_info.name.decode("utf-8"),
"build_date": vbios_info.build_date.decode("utf-8"),
"part_number": vbios_info.part_number.decode("utf-8"),
"version": vbios_info.version.decode("utf-8"),
"boot_firmware": boot_firmware,
}
def amdsmi_get_gpu_activity(
processor_handle: processor_handle,
) -> Dict[str, Any]:
if not isinstance(processor_handle, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(
processor_handle, amdsmi_wrapper.amdsmi_processor_handle
)
engine_usage = amdsmi_wrapper.amdsmi_engine_usage_t()
_check_res(
amdsmi_wrapper.amdsmi_get_gpu_activity(
processor_handle, ctypes.byref(engine_usage)
)
)
activity_dict = {
"gfx_activity": engine_usage.gfx_activity,
"umc_activity": engine_usage.umc_activity,
"mm_activity": engine_usage.mm_activity,
}
for key, value in activity_dict.items():
if value == 0xFFFF:
activity_dict[key] = "N/A"
return activity_dict
def amdsmi_get_clock_info(
processor_handle: processor_handle,
clock_type: AmdSmiClkType,
) -> Dict[str, Any]:
if not isinstance(processor_handle, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(
processor_handle, amdsmi_wrapper.amdsmi_processor_handle
)
if not isinstance(clock_type, AmdSmiClkType):
raise AmdSmiParameterException(clock_type, AmdSmiClkType)
clock_measure = amdsmi_wrapper.amdsmi_clk_info_t()
_check_res(
amdsmi_wrapper.amdsmi_get_clock_info(
processor_handle,
clock_type,
ctypes.byref(clock_measure),
)
)
dict_ret = {
"clk": _validate_if_max_uint(clock_measure.clk, MaxUIntegerTypes.UINT32_T),
"min_clk": _validate_if_max_uint(clock_measure.min_clk, MaxUIntegerTypes.UINT32_T),
"max_clk": _validate_if_max_uint(clock_measure.max_clk, MaxUIntegerTypes.UINT32_T),
"clk_locked": _validate_if_max_uint(clock_measure.clk_locked, MaxUIntegerTypes.UINT8_T, isBool=True),
"clk_deep_sleep" : _validate_if_max_uint(clock_measure.clk_deep_sleep, MaxUIntegerTypes.UINT8_T),
}
return dict_ret
def amdsmi_get_gpu_bad_page_info(
processor_handle: processor_handle,
) -> List[Dict[str, Any]]:
if not isinstance(processor_handle, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(
processor_handle, amdsmi_wrapper.amdsmi_processor_handle
)
num_pages = ctypes.c_uint32()
nullptr = POINTER(amdsmi_wrapper.amdsmi_retired_page_record_t)()
_check_res(
amdsmi_wrapper.amdsmi_get_gpu_bad_page_info(
processor_handle, ctypes.byref(num_pages), nullptr
)
)
if num_pages.value == 0:
return []
bad_pages = (amdsmi_wrapper.amdsmi_retired_page_record_t * num_pages.value)()
_check_res(
amdsmi_wrapper.amdsmi_get_gpu_bad_page_info(
processor_handle, ctypes.byref(num_pages), bad_pages
)
)
return _format_bad_page_info(bad_pages, num_pages)
def amdsmi_get_gpu_bad_page_threshold(
processor_handle: processor_handle,
) -> int:
if not isinstance(processor_handle, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(
processor_handle, amdsmi_wrapper.amdsmi_processor_handle
)
threshold = ctypes.c_uint32()
_check_res(
amdsmi_wrapper.amdsmi_get_gpu_bad_page_threshold(
processor_handle, ctypes.byref(threshold)
)
)
return threshold.value
def amdsmi_get_violation_status(
processor_handle: processor_handle,
) -> Dict[str, Any]:
if not isinstance(processor_handle, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(
processor_handle, amdsmi_wrapper.amdsmi_processor_handle
)
violation_status = amdsmi_wrapper.amdsmi_violation_status_t()
_check_res(
amdsmi_wrapper.amdsmi_get_violation_status(
processor_handle, ctypes.byref(violation_status))
)
dict_return = {
"reference_timestamp": _validate_if_max_uint(violation_status.reference_timestamp, MaxUIntegerTypes.UINT64_T),
"violation_timestamp": _validate_if_max_uint(violation_status.violation_timestamp, MaxUIntegerTypes.UINT64_T),
"acc_counter": _validate_if_max_uint(violation_status.acc_counter, MaxUIntegerTypes.UINT64_T),
"acc_prochot_thrm": _validate_if_max_uint(violation_status.acc_prochot_thrm, MaxUIntegerTypes.UINT64_T),
"acc_ppt_pwr": _validate_if_max_uint(violation_status.acc_ppt_pwr, MaxUIntegerTypes.UINT64_T), #PVIOL
"acc_socket_thrm": _validate_if_max_uint(violation_status.acc_socket_thrm, MaxUIntegerTypes.UINT64_T), #TVIOL
"acc_vr_thrm": _validate_if_max_uint(violation_status.acc_vr_thrm, MaxUIntegerTypes.UINT64_T),
"acc_hbm_thrm": _validate_if_max_uint(violation_status.acc_hbm_thrm, MaxUIntegerTypes.UINT64_T),
"acc_gfx_clk_below_host_limit": _validate_if_max_uint(violation_status.acc_gfx_clk_below_host_limit, MaxUIntegerTypes.UINT64_T),
"acc_gfx_clk_below_host_limit_pwr": list(violation_status.acc_gfx_clk_below_host_limit_pwr),
"acc_gfx_clk_below_host_limit_thm": list(violation_status.acc_gfx_clk_below_host_limit_thm),
"acc_gfx_clk_below_host_limit_total": list(violation_status.acc_gfx_clk_below_host_limit_total),
"acc_low_utilization": list(violation_status.acc_low_utilization),
"per_prochot_thrm": _validate_if_max_uint(violation_status.per_prochot_thrm, MaxUIntegerTypes.UINT64_T, isActivity=True),
"per_ppt_pwr": _validate_if_max_uint(violation_status.per_ppt_pwr, MaxUIntegerTypes.UINT64_T, isActivity=True), #PVIOL
"per_socket_thrm": _validate_if_max_uint(violation_status.per_socket_thrm, MaxUIntegerTypes.UINT64_T, isActivity=True), #TVIOL
"per_vr_thrm": _validate_if_max_uint(violation_status.per_vr_thrm, MaxUIntegerTypes.UINT64_T, isActivity=True),
"per_hbm_thrm": _validate_if_max_uint(violation_status.per_hbm_thrm, MaxUIntegerTypes.UINT64_T, isActivity=True),
"per_gfx_clk_below_host_limit": _validate_if_max_uint(violation_status.per_gfx_clk_below_host_limit, MaxUIntegerTypes.UINT64_T, isActivity=True),
"per_gfx_clk_below_host_limit_pwr": list(violation_status.per_gfx_clk_below_host_limit_pwr),
"per_gfx_clk_below_host_limit_thm": list(violation_status.per_gfx_clk_below_host_limit_thm),
"per_gfx_clk_below_host_limit_total": list(violation_status.per_gfx_clk_below_host_limit_total),
"per_low_utilization": list(violation_status.per_low_utilization),
"active_prochot_thrm": _validate_if_max_uint(violation_status.active_prochot_thrm, MaxUIntegerTypes.UINT8_T, isBool=True),
"active_ppt_pwr": _validate_if_max_uint(violation_status.active_ppt_pwr, MaxUIntegerTypes.UINT8_T, isBool=True), #PVIOL
"active_socket_thrm": _validate_if_max_uint(violation_status.active_socket_thrm, MaxUIntegerTypes.UINT8_T, isBool=True), #TVIOL
"active_vr_thrm": _validate_if_max_uint(violation_status.active_vr_thrm, MaxUIntegerTypes.UINT8_T, isBool=True),
"active_hbm_thrm": _validate_if_max_uint(violation_status.active_hbm_thrm, MaxUIntegerTypes.UINT8_T, isBool=True),
"active_gfx_clk_below_host_limit": _validate_if_max_uint(violation_status.active_gfx_clk_below_host_limit, MaxUIntegerTypes.UINT8_T, isBool=True),
"active_gfx_clk_below_host_limit_pwr": list(violation_status.active_gfx_clk_below_host_limit_pwr),
"active_gfx_clk_below_host_limit_thm": list(violation_status.active_gfx_clk_below_host_limit_thm),
"active_gfx_clk_below_host_limit_total": list(violation_status.active_gfx_clk_below_host_limit_total),
"active_low_utilization": list(violation_status.active_low_utilization),
}
# Create 2d array with each XCD's stats
if 'acc_gfx_clk_below_host_limit_pwr' in dict_return:
for xcp_index, xcp_metrics in enumerate(dict_return['acc_gfx_clk_below_host_limit_pwr']):
xcp_detail = []
for val in xcp_metrics:
xcp_detail.append(_validate_if_max_uint(val, MaxUIntegerTypes.UINT64_T))
dict_return['acc_gfx_clk_below_host_limit_pwr'][xcp_index] = xcp_detail
if 'acc_gfx_clk_below_host_limit_thm' in dict_return:
for xcp_index, xcp_metrics in enumerate(dict_return['acc_gfx_clk_below_host_limit_thm']):
xcp_detail = []
for val in xcp_metrics:
xcp_detail.append(_validate_if_max_uint(val, MaxUIntegerTypes.UINT64_T))
dict_return['acc_gfx_clk_below_host_limit_thm'][xcp_index] = xcp_detail
if 'acc_low_utilization' in dict_return:
for xcp_index, xcp_metrics in enumerate(dict_return['acc_low_utilization']):
xcp_detail = []
for val in xcp_metrics:
xcp_detail.append(_validate_if_max_uint(val, MaxUIntegerTypes.UINT64_T))
dict_return['acc_low_utilization'][xcp_index] = xcp_detail
if 'acc_gfx_clk_below_host_limit_total' in dict_return:
for xcp_index, xcp_metrics in enumerate(dict_return['acc_gfx_clk_below_host_limit_total']):
xcp_detail = []
for val in xcp_metrics:
xcp_detail.append(_validate_if_max_uint(val, MaxUIntegerTypes.UINT64_T))
dict_return['acc_gfx_clk_below_host_limit_total'][xcp_index] = xcp_detail
if 'per_gfx_clk_below_host_limit_pwr' in dict_return:
for xcp_index, xcp_metrics in enumerate(dict_return['per_gfx_clk_below_host_limit_pwr']):
xcp_detail = []
for val in xcp_metrics:
xcp_detail.append(_validate_if_max_uint(val, MaxUIntegerTypes.UINT64_T, isActivity=True))
dict_return['per_gfx_clk_below_host_limit_pwr'][xcp_index] = xcp_detail
if 'per_gfx_clk_below_host_limit_thm' in dict_return:
for xcp_index, xcp_metrics in enumerate(dict_return['per_gfx_clk_below_host_limit_thm']):
xcp_detail = []
for val in xcp_metrics:
xcp_detail.append(_validate_if_max_uint(val, MaxUIntegerTypes.UINT64_T, isActivity=True))
dict_return['per_gfx_clk_below_host_limit_thm'][xcp_index] = xcp_detail
if 'per_low_utilization' in dict_return:
for xcp_index, xcp_metrics in enumerate(dict_return['per_low_utilization']):
xcp_detail = []
for val in xcp_metrics:
xcp_detail.append(_validate_if_max_uint(val, MaxUIntegerTypes.UINT64_T, isActivity=True))
dict_return['per_low_utilization'][xcp_index] = xcp_detail
if 'per_gfx_clk_below_host_limit_total' in dict_return:
for xcp_index, xcp_metrics in enumerate(dict_return['per_gfx_clk_below_host_limit_total']):
xcp_detail = []
for val in xcp_metrics:
xcp_detail.append(_validate_if_max_uint(val, MaxUIntegerTypes.UINT64_T, isActivity=True))
dict_return['per_gfx_clk_below_host_limit_total'][xcp_index] = xcp_detail
if 'active_gfx_clk_below_host_limit_pwr' in dict_return:
for xcp_index, xcp_metrics in enumerate(dict_return['active_gfx_clk_below_host_limit_pwr']):
xcp_detail = []
for val in xcp_metrics:
xcp_detail.append(_validate_if_max_uint(val, MaxUIntegerTypes.UINT8_T, isBool=True))
dict_return['active_gfx_clk_below_host_limit_pwr'][xcp_index] = xcp_detail
if 'active_gfx_clk_below_host_limit_thm' in dict_return:
for xcp_index, xcp_metrics in enumerate(dict_return['active_gfx_clk_below_host_limit_thm']):
xcp_detail = []
for val in xcp_metrics:
xcp_detail.append(_validate_if_max_uint(val, MaxUIntegerTypes.UINT8_T, isBool=True))
dict_return['active_gfx_clk_below_host_limit_thm'][xcp_index] = xcp_detail
if 'active_low_utilization' in dict_return:
for xcp_index, xcp_metrics in enumerate(dict_return['active_low_utilization']):
xcp_detail = []
for val in xcp_metrics:
xcp_detail.append(_validate_if_max_uint(val, MaxUIntegerTypes.UINT8_T, isBool=True))
dict_return['active_low_utilization'][xcp_index] = xcp_detail
if 'active_gfx_clk_below_host_limit_total' in dict_return:
for xcp_index, xcp_metrics in enumerate(dict_return['active_gfx_clk_below_host_limit_total']):
xcp_detail = []
for val in xcp_metrics:
xcp_detail.append(_validate_if_max_uint(val, MaxUIntegerTypes.UINT8_T, isBool=True))
dict_return['active_gfx_clk_below_host_limit_total'][xcp_index] = xcp_detail
return dict_return
def amdsmi_get_gpu_total_ecc_count(
processor_handle: processor_handle,
) -> Dict[str, Any]:
if not isinstance(processor_handle, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(
processor_handle, amdsmi_wrapper.amdsmi_processor_handle
)
ec = amdsmi_wrapper.amdsmi_error_count_t()
_check_res(
amdsmi_wrapper.amdsmi_get_gpu_total_ecc_count(
processor_handle, ctypes.byref(ec)
)
)
return {
"correctable_count": ec.correctable_count,
"uncorrectable_count": ec.uncorrectable_count,
"deferred_count": ec.deferred_count,
}
def notifyTypeToString(notify_type_b):
idx = 0
guid = []
for i in notify_type_b:
guid.append(format(i, '02x'))
if idx == 7:
break
idx = idx +1
return "".join(guid[::-1])
def amdsmi_get_gpu_cper_entries(
processor_handle: processor_handle,
severity_mask: int,
buffer_size: int = 4 * 1048576,
cursor: int = 0
) -> Tuple[Dict[str, Any], int, List[Dict[str, Any]], int]:
if not isinstance(processor_handle, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(
processor_handle, amdsmi_wrapper.amdsmi_processor_handle
)
# Allocate a buffer for CPER data.
buf = ctypes.create_string_buffer(buffer_size)
buf_size = ctypes.c_uint64(buffer_size)
num_cper_hdrs = 20
entry_count = ctypes.c_uint64(num_cper_hdrs)
cur = ctypes.c_uint64(cursor)
# Allocate a pointer for the CPER header array.
cper_hdrs_array = (ctypes.POINTER(amdsmi_wrapper.amdsmi_cper_hdr_t) * num_cper_hdrs)()
cper_hdrs = ctypes.cast(cper_hdrs_array, ctypes.POINTER(ctypes.POINTER(amdsmi_wrapper.amdsmi_cper_hdr_t)))
# Call the underlying AMD-SMI API.
status_code = amdsmi_wrapper.amdsmi_get_gpu_cper_entries(
processor_handle,
ctypes.c_uint32(severity_mask),
buf,
ctypes.byref(buf_size),
cper_hdrs,
ctypes.byref(entry_count),
ctypes.byref(cur)
)
if status_code not in {amdsmi_wrapper.AMDSMI_STATUS_SUCCESS, amdsmi_wrapper.AMDSMI_STATUS_MORE_DATA}:
raise AmdSmiLibraryException(status_code)
entries = {}
cper_data = []
offset = 0
# Iterate over each entry using its variable record_length.
for i in range(entry_count.value):
entry_address = ctypes.addressof(buf) + offset
entry_ptr = ctypes.cast(entry_address, POINTER(amdsmi_wrapper.amdsmi_cper_hdr_t))
# Extract the raw bytes and size of the entry.
cper_data.append({
"bytes": list((entry_ptr.contents.record_length * ctypes.c_byte).from_address(entry_address)),
"size": entry_ptr.contents.record_length
})
# Extract the timestamp fields.
year = entry_ptr.contents.timestamp.year
if year < 100: # Adjust the year if it's less than 100.
year += 2000
formatted_timestamp = (
f"{year:04d}/"
f"{entry_ptr.contents.timestamp.month:02d}/"
f"{entry_ptr.contents.timestamp.day:02d} "
f"{entry_ptr.contents.timestamp.hours:02d}:"
f"{entry_ptr.contents.timestamp.minutes:02d}:"
f"{entry_ptr.contents.timestamp.seconds:02d}"
)
# Create a dictionary for the CPER entry.
cper_entry = {
"error_severity": amdsmi_wrapper.amdsmi_cper_sev_t__enumvalues.get(
entry_ptr.contents.error_severity, "AMDSMI_CPER_SEV_UNUSED"
).replace("AMDSMI_CPER_SEV_", "").lower(),
"notify_type": _notifyTypeToString(entry_ptr.contents.notify_type.b),
"timestamp": formatted_timestamp,
"signature": entry_ptr.contents.signature,
"revision": entry_ptr.contents.revision,
"signature_end": hex(entry_ptr.contents.signature_end),
"sec_cnt": entry_ptr.contents.sec_cnt,
"record_length": entry_ptr.contents.record_length,
"platform_id": entry_ptr.contents.platform_id,
"creator_id": entry_ptr.contents.creator_id,
"record_id": entry_ptr.contents.record_id,
"flags": entry_ptr.contents.flags,
"persistence_info": entry_ptr.contents.persistence_info,
#"reserved" : entry_ptr.contents.reserved
#"cper_valid_bit" : entry_ptr.contents.cper_valid_bits,
#"partition_id" : entry_ptr.contents.partition_id,
}
entries[i] = cper_entry.copy()
offset += entry_ptr.contents.record_length # Use the actual record length to advance the offset.
return entries, cur.value, cper_data, status_code
def amdsmi_get_afids_from_cper(
cper_afid_data: Union[bytes, bytearray, List[Dict[str, Any]]]
) -> Tuple[List[int], int]:
"""
Extract AFIDs from one or more CPER blobs.
Args:
cper_afid_data: Either
- raw bytes or bytearray of a single CPER record, or
- a list of dicts each with keys "bytes" (List[int]) and "size" (int).
Returns:
Tuple[List[int], int]: A tuple containing:
- A list of extracted AFIDs.
- The total count of AFIDs.
"""
# Normalize single blob into a list of records
if isinstance(cper_afid_data, (bytes, bytearray)):
cper_records = [{
"bytes": list(cper_afid_data),
"size": len(cper_afid_data)
}]
else:
cper_records = cper_afid_data
all_afids: List[int] = []
for record in cper_records:
if isinstance(record, dict) and "bytes" in record and "size" in record:
raw_bytes = bytes(record["bytes"])
record_size = record["size"]
else:
raise AmdSmiParameterException(record,
"dict with keys 'bytes' and 'size' or bytes/bytearray")
# Wrap as char*
buf = ctypes.create_string_buffer(raw_bytes, record_size)
buf_ptr = ctypes.cast(buf, POINTER(ctypes.c_char))
afid_array = (ctypes.c_uint64 * MAX_NUMBER_OF_AFIDS_PER_RECORD)()
num_afids_ct = ctypes.c_uint32(MAX_NUMBER_OF_AFIDS_PER_RECORD)
# Call the wrapper function
status = amdsmi_wrapper.amdsmi_get_afids_from_cper(
buf_ptr,
ctypes.c_uint32(record_size),
afid_array,
ctypes.byref(num_afids_ct)
)
if status != amdsmi_wrapper.AMDSMI_STATUS_SUCCESS:
raise AmdSmiLibraryException(status)
# Collect exactly the decoded AFIDs
count = num_afids_ct.value
all_afids.extend(afid_array[i] for i in range(count))
return all_afids, len(all_afids)
def amdsmi_get_gpu_board_info(
processor_handle: processor_handle,
) -> Dict[str, Any]:
if not isinstance(processor_handle, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(
processor_handle, amdsmi_wrapper.amdsmi_processor_handle
)
board_info = amdsmi_wrapper.amdsmi_board_info_t()
_check_res(
amdsmi_wrapper.amdsmi_get_gpu_board_info(
processor_handle, ctypes.byref(board_info))
)
board_info_dict = {
"model_number": _pad_hex_value(board_info.model_number.decode("utf-8").strip(), 4),
"product_serial": board_info.product_serial.decode("utf-8").strip(),
"fru_id": board_info.fru_id.decode("utf-8").strip(),
"product_name": _pad_hex_value(board_info.product_name.decode("utf-8").strip(), 4),
"manufacturer_name": board_info.manufacturer_name.decode("utf-8").strip()
}
for key, value in board_info_dict.items():
if value == "":
board_info_dict[key] = "N/A"
return board_info_dict
def amdsmi_get_gpu_ras_feature_info(
processor_handle: processor_handle,
) -> Dict[str, Any]:
if not isinstance(processor_handle, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(
processor_handle, amdsmi_wrapper.amdsmi_processor_handle
)
ras_feature = amdsmi_wrapper.amdsmi_ras_feature_t()
_check_res(
amdsmi_wrapper.amdsmi_get_gpu_ras_feature_info(
processor_handle, ctypes.byref(ras_feature)
)
)
return {
"eeprom_version": hex(ras_feature.ras_eeprom_version),
"parity_schema" : bool(ras_feature.ecc_correction_schema_flag & 1),
"single_bit_schema" : bool(ras_feature.ecc_correction_schema_flag & 2),
"double_bit_schema" : bool(ras_feature.ecc_correction_schema_flag & 4),
"poison_schema" : bool(ras_feature.ecc_correction_schema_flag & 8)
}
def amdsmi_get_gpu_ras_block_features_enabled(
processor_handle: processor_handle,
) -> List[Dict[str, Any]]:
if not isinstance(processor_handle, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(
processor_handle, amdsmi_wrapper.amdsmi_processor_handle
)
ras_state = amdsmi_wrapper.amdsmi_ras_err_state_t()
ras_states = []
for gpu_block in AmdSmiGpuBlock:
if gpu_block.name == "RESERVED" or gpu_block.name == "INVALID":
continue
if gpu_block.name == "LAST":
gpu_block.name = "MPIO"
_check_res(
amdsmi_wrapper.amdsmi_get_gpu_ras_block_features_enabled(
processor_handle,
amdsmi_wrapper.amdsmi_gpu_block_t(gpu_block.value),
ctypes.byref(ras_state),
)
)
ras_states.append(
{
"block": gpu_block.name,
"status": AmdSmiRasErrState(ras_state.value).name,
}
)
return ras_states
def amdsmi_get_gpu_process_list(
processor_handle: processor_handle,
) -> List[amdsmi_wrapper.amdsmi_proc_info_t]:
if not isinstance(processor_handle, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(
processor_handle, amdsmi_wrapper.amdsmi_processor_handle
)
# This will get populated with the number of processes found
max_processes = ctypes.c_uint32(MAX_NUM_PROCESSES)
process_list = (amdsmi_wrapper.amdsmi_proc_info_t * max_processes.value)()
_check_res(
amdsmi_wrapper.amdsmi_get_gpu_process_list(
processor_handle, ctypes.byref(max_processes), process_list
)
)
result = []
for index in range(max_processes.value):
process_name = process_list[index].name.decode("utf-8").strip()
if process_name == "":
process_name = "N/A"
result.append({
"name": process_name,
"pid": process_list[index].pid,
"mem": process_list[index].mem,
"engine_usage": {
"gfx": process_list[index].engine_usage.gfx,
"enc": process_list[index].engine_usage.enc
},
"memory_usage": {
"gtt_mem": process_list[index].memory_usage.gtt_mem,
"cpu_mem": process_list[index].memory_usage.cpu_mem,
"vram_mem": process_list[index].memory_usage.vram_mem,
},
"cu_occupancy": _validate_if_max_uint(process_list[index].cu_occupancy, MaxUIntegerTypes.UINT32_T)
})
return result
def amdsmi_get_gpu_driver_info(
processor_handle: processor_handle,
) -> Dict[str, Any]:
if not isinstance(processor_handle, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(
processor_handle, amdsmi_wrapper.amdsmi_processor_handle
)
info = amdsmi_wrapper.amdsmi_driver_info_t()
_check_res(
amdsmi_wrapper.amdsmi_get_gpu_driver_info(
processor_handle, ctypes.byref(info)
)
)
driver_info = {
"driver_name": info.driver_name.decode("utf-8"),
"driver_version": info.driver_version.decode("utf-8"),
"driver_date": info.driver_date.decode("utf-8")
}
for key, value in driver_info.items():
if value == "":
driver_info[key] = "N/A"
return driver_info
def amdsmi_get_power_info(
processor_handle: processor_handle
) -> Dict[str, ctypes.c_uint32]:
if not isinstance(processor_handle, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(
processor_handle, amdsmi_wrapper.amdsmi_processor_handle
)
power_info = amdsmi_wrapper.amdsmi_power_info_t()
_check_res(
amdsmi_wrapper.amdsmi_get_power_info(
processor_handle, ctypes.byref(power_info)
)
)
power_info_dict = {
"socket_power": power_info.socket_power,
"current_socket_power": power_info.current_socket_power,
"average_socket_power": power_info.average_socket_power,
"gfx_voltage": power_info.gfx_voltage,
"soc_voltage": power_info.soc_voltage,
"mem_voltage": power_info.mem_voltage,
"power_limit" : power_info.power_limit,
}
for key, value in power_info_dict.items():
if value == 0xFFFF:
power_info_dict[key] = "N/A"
return power_info_dict
def amdsmi_is_gpu_power_management_enabled(
processor_handle: processor_handle
) -> bool:
if not isinstance(processor_handle, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(processor_handle, amdsmi_wrapper.amdsmi_processor_handle)
is_power_management_enabled = ctypes.c_bool()
_check_res(
amdsmi_wrapper.amdsmi_is_gpu_power_management_enabled(
processor_handle, ctypes.byref(is_power_management_enabled)
)
)
return is_power_management_enabled.value
def amdsmi_get_fw_info(
processor_handle: processor_handle
) -> Dict[str, List[Dict[str, str]]]:
if not isinstance(processor_handle, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(
processor_handle, amdsmi_wrapper.amdsmi_processor_handle)
fw_info = amdsmi_wrapper.amdsmi_fw_info_t()
_check_res(
amdsmi_wrapper.amdsmi_get_fw_info(
processor_handle, ctypes.byref(fw_info)
)
)
# Certain FW blocks are padded with 0s in the front intentionally
# But the C library converts the hex to an integer which trims the leading 0s
# Nor do we have a flag that defines the expected format for each FW block
# We can expect the following blocks to have a padded value and a specified format
hex_format_fw = [AmdSmiFwBlock.AMDSMI_FW_ID_PSP_SOSDRV,
AmdSmiFwBlock.AMDSMI_FW_ID_TA_RAS,
AmdSmiFwBlock.AMDSMI_FW_ID_TA_XGMI,
AmdSmiFwBlock.AMDSMI_FW_ID_UVD,
AmdSmiFwBlock.AMDSMI_FW_ID_VCE,
AmdSmiFwBlock.AMDSMI_FW_ID_VCN]
# PM(AKA: SMC) firmware's hex value looks like 0x12345678
# However, they are parsed as: int(0x12).int(0x34).int(0x56).int(0x78)
# Which results in the following: 12.34.56.78
dec_format_fw = [AmdSmiFwBlock.AMDSMI_FW_ID_PM,
AmdSmiFwBlock.AMDSMI_FW_ID_PLDM_BUNDLE]
firmwares = []
for i in range(0, fw_info.num_fw_info):
fw_name = AmdSmiFwBlock(fw_info.fw_info_list[i].fw_id)
fw_version = fw_info.fw_info_list[i].fw_version # This is in int format (base 10)
if fw_name in hex_format_fw:
# Convert the fw_version from a int to a hex string padded leading 0s
fw_version_string = hex(fw_version)[2:].zfill(8)
# Join every two hex digits with a dot
fw_version_string = ".".join(re.findall('..?', fw_version_string))
elif fw_name in dec_format_fw:
# Convert the fw_version from a int to a hex string padded leading 0s
fw_version_string = hex(fw_version)[2:].zfill(8)
# Convert every two hex digits to decimal and join them with a dot
dec_version_string = ''
for index, _ in enumerate(fw_version_string):
if index % 2 != 0:
continue
hex_digits = f"0x{fw_version_string[index:index+2]}"
dec_version_string += str(int(hex_digits, 16)).zfill(2) + "."
fw_version_string = dec_version_string.strip('.')
else:
fw_version_string = str(fw_version)
firmwares.append({
'fw_name': fw_name,
'fw_version': fw_version_string.upper(),
})
return {'fw_list': firmwares}
def amdsmi_get_gpu_vram_usage(
processor_handle: processor_handle,
) -> Dict[str, Any]:
if not isinstance(processor_handle, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(
processor_handle, amdsmi_wrapper.amdsmi_processor_handle
)
vram_usage = amdsmi_wrapper.amdsmi_vram_usage_t()
_check_res(
amdsmi_wrapper.amdsmi_get_gpu_vram_usage(
processor_handle, ctypes.byref(vram_usage))
)
return {"vram_total": vram_usage.vram_total, "vram_used": vram_usage.vram_used}
def amdsmi_get_pcie_info(
processor_handle: processor_handle,
) -> Dict[str, Any]:
if not isinstance(processor_handle, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(
processor_handle, amdsmi_wrapper.amdsmi_processor_handle
)
pcie_info = amdsmi_wrapper.amdsmi_pcie_info_t()
_check_res(
amdsmi_wrapper.amdsmi_get_pcie_info(
processor_handle, ctypes.byref(pcie_info)
)
)
pcie_info_dict = {
"pcie_static": {
"max_pcie_width": _validate_if_max_uint(pcie_info.pcie_static.max_pcie_width, MaxUIntegerTypes.UINT16_T),
"max_pcie_speed": _validate_if_max_uint(pcie_info.pcie_static.max_pcie_speed, MaxUIntegerTypes.UINT32_T),
"pcie_interface_version": _validate_if_max_uint(pcie_info.pcie_static.pcie_interface_version, MaxUIntegerTypes.UINT32_T),
"slot_type": pcie_info.pcie_static.slot_type,
},
"pcie_metric": {
"pcie_width": _validate_if_max_uint(pcie_info.pcie_metric.pcie_width, MaxUIntegerTypes.UINT16_T),
"pcie_speed": _validate_if_max_uint(pcie_info.pcie_metric.pcie_speed, MaxUIntegerTypes.UINT32_T),
"pcie_bandwidth": _validate_if_max_uint(pcie_info.pcie_metric.pcie_bandwidth, MaxUIntegerTypes.UINT32_T),
"pcie_replay_count": _validate_if_max_uint(pcie_info.pcie_metric.pcie_replay_count, MaxUIntegerTypes.UINT64_T),
"pcie_l0_to_recovery_count": _validate_if_max_uint(pcie_info.pcie_metric.pcie_l0_to_recovery_count, MaxUIntegerTypes.UINT64_T),
"pcie_replay_roll_over_count": _validate_if_max_uint(pcie_info.pcie_metric.pcie_replay_roll_over_count, MaxUIntegerTypes.UINT64_T),
"pcie_nak_sent_count": _validate_if_max_uint(pcie_info.pcie_metric.pcie_nak_sent_count, MaxUIntegerTypes.UINT64_T),
"pcie_nak_received_count": _validate_if_max_uint(pcie_info.pcie_metric.pcie_nak_received_count, MaxUIntegerTypes.UINT64_T),
"pcie_lc_perf_other_end_recovery_count": _validate_if_max_uint(pcie_info.pcie_metric.pcie_lc_perf_other_end_recovery_count, MaxUIntegerTypes.UINT32_T)
}
}
slot_type = pcie_info_dict['pcie_static']['slot_type']
if isinstance(slot_type, int):
slot_types = amdsmi_wrapper.amdsmi_card_form_factor_t__enumvalues
if slot_type in slot_types:
pcie_info_dict['pcie_static']['slot_type'] = slot_types[slot_type].replace("AMDSMI_CARD_FORM_FACTOR_", "")
else:
pcie_info_dict['pcie_static']['slot_type'] = "Unknown"
else:
pcie_info_dict['pcie_static']['slot_type'] = "N/A"
return pcie_info_dict
def amdsmi_get_gpu_xcd_counter(processor_handle: processor_handle) -> int:
if not isinstance(processor_handle, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(processor_handle, amdsmi_wrapper.amdsmi_processor_handle)
xcd_counter = ctypes.c_uint16()
_check_res(
amdsmi_wrapper.amdsmi_get_gpu_xcd_counter(
processor_handle, ctypes.byref(xcd_counter)
)
)
return xcd_counter.value
def amdsmi_get_processor_handle_from_bdf(bdf):
bdf = _parse_bdf(bdf)
if bdf is None:
raise AmdSmiBdfFormatException(bdf)
amdsmi_bdf = _make_amdsmi_bdf_from_list(bdf)
processor_handle = amdsmi_wrapper.amdsmi_processor_handle()
_check_res(amdsmi_wrapper.amdsmi_get_processor_handle_from_bdf(
amdsmi_bdf, ctypes.byref(processor_handle)))
return processor_handle
def amdsmi_get_gpu_vendor_name(
processor_handle: processor_handle,
) -> str:
if not isinstance(processor_handle, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(
processor_handle, amdsmi_wrapper.amdsmi_processor_handle
)
length = ctypes.c_uint64()
length.value = _AMDSMI_STRING_LENGTH
vendor_name = ctypes.create_string_buffer(_AMDSMI_STRING_LENGTH)
_check_res(
amdsmi_wrapper.amdsmi_get_gpu_vendor_name(
processor_handle, vendor_name, length)
)
return vendor_name.value.decode("utf-8")
def amdsmi_get_gpu_id(processor_handle: processor_handle):
if not isinstance(processor_handle, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(
processor_handle, amdsmi_wrapper.amdsmi_processor_handle
)
id = ctypes.c_uint16()
_check_res(amdsmi_wrapper.amdsmi_get_gpu_id(
processor_handle, ctypes.byref(id)))
return id.value
def amdsmi_get_gpu_vram_vendor(processor_handle: processor_handle):
if not isinstance(processor_handle, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(
processor_handle, amdsmi_wrapper.amdsmi_processor_handle
)
length = ctypes.c_uint32()
length.value = _AMDSMI_STRING_LENGTH
vram_vendor = ctypes.create_string_buffer(_AMDSMI_STRING_LENGTH)
_check_res(
amdsmi_wrapper.amdsmi_get_gpu_vram_vendor(
processor_handle, vram_vendor, length)
)
return vram_vendor.value.decode("utf-8")
def amdsmi_get_gpu_subsystem_id(processor_handle: processor_handle):
if not isinstance(processor_handle, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(
processor_handle, amdsmi_wrapper.amdsmi_processor_handle
)
id = ctypes.c_uint16()
_check_res(
amdsmi_wrapper.amdsmi_get_gpu_subsystem_id(
processor_handle, ctypes.byref(id))
)
return _pad_hex_value(hex(id.value), 4)
def amdsmi_get_gpu_subsystem_name(processor_handle: processor_handle):
if not isinstance(processor_handle, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(
processor_handle, amdsmi_wrapper.amdsmi_processor_handle
)
length = ctypes.c_uint64()
length.value = _AMDSMI_STRING_LENGTH
name = ctypes.create_string_buffer(_AMDSMI_STRING_LENGTH)
_check_res(
amdsmi_wrapper.amdsmi_get_gpu_subsystem_name(
processor_handle, name, length)
)
return name.value.decode("utf-8")
def amdsmi_get_lib_version():
version = amdsmi_wrapper.amdsmi_version_t()
_check_res(amdsmi_wrapper.amdsmi_get_lib_version(ctypes.byref(version)))
return {
"major": version.major,
"minor": version.minor,
"release": version.release,
"build": version.build.contents.value.decode("utf-8")
}
def amdsmi_topo_get_numa_node_number(
processor_handle: processor_handle,
):
if not isinstance(processor_handle, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(
processor_handle, amdsmi_wrapper.amdsmi_processor_handle
)
numa_node_number = ctypes.c_uint32()
_check_res(
amdsmi_wrapper.amdsmi_topo_get_numa_node_number(
processor_handle, ctypes.byref(numa_node_number)
)
)
return numa_node_number.value
def amdsmi_topo_get_link_weight(
processor_handle_src: processor_handle,
processor_handle_dst: processor_handle,
):
if not isinstance(processor_handle_src, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(
processor_handle_src, amdsmi_wrapper.amdsmi_processor_handle
)
if not isinstance(processor_handle_dst, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(
processor_handle_dst, amdsmi_wrapper.amdsmi_processor_handle
)
weight = ctypes.c_uint64()
_check_res(
amdsmi_wrapper.amdsmi_topo_get_link_weight(
processor_handle_src, processor_handle_dst, ctypes.byref(weight)
)
)
return weight.value
def amdsmi_get_minmax_bandwidth_between_processors(
processor_handle_src: processor_handle,
processor_handle_dst: processor_handle,
):
if not isinstance(processor_handle_src, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(
processor_handle_src, amdsmi_wrapper.amdsmi_processor_handle
)
if not isinstance(processor_handle_dst, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(
processor_handle_dst, amdsmi_wrapper.amdsmi_processor_handle
)
min_bandwidth = ctypes.c_uint64()
max_bandwidth = ctypes.c_uint64()
_check_res(
amdsmi_wrapper.amdsmi_get_minmax_bandwidth_between_processors(
processor_handle_src,
processor_handle_dst,
ctypes.byref(min_bandwidth),
ctypes.byref(max_bandwidth),
)
)
return {"min_bandwidth": min_bandwidth.value, "max_bandwidth": max_bandwidth.value}
def amdsmi_get_link_metrics(processor_handle: processor_handle):
if not isinstance(processor_handle, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(
processor_handle, amdsmi_wrapper.amdsmi_processor_handle
)
link_metrics = amdsmi_wrapper.amdsmi_link_metrics_t()
_check_res(
amdsmi_wrapper.amdsmi_get_link_metrics(
processor_handle, ctypes.byref(link_metrics)
)
)
links = []
for i in range(AMDSMI_MAX_NUM_XGMI_LINKS):
link = link_metrics.links[i]
links.append({
"bdf": _format_bdf(link.bdf),
"bit_rate": link.bit_rate,
"max_bandwidth": link.max_bandwidth,
"link_type": link.link_type,
"read": link.read,
"write": link.write,
})
return {
"num_links": link_metrics.num_links,
"links": links
}
def amdsmi_topo_get_link_type(
processor_handle_src: processor_handle,
processor_handle_dst: processor_handle,
):
if not isinstance(processor_handle_src, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(
processor_handle_src, amdsmi_wrapper.amdsmi_processor_handle
)
if not isinstance(processor_handle_dst, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(
processor_handle_dst, amdsmi_wrapper.amdsmi_processor_handle
)
hops = ctypes.c_uint64()
type = ctypes.c_uint32()
_check_res(
amdsmi_wrapper.amdsmi_topo_get_link_type(
processor_handle_src, processor_handle_dst,
ctypes.byref(hops), ctypes.byref(type)
)
)
return {"hops": hops.value, "type": type.value}
def amdsmi_topo_get_p2p_status(
processor_handle_src: processor_handle,
processor_handle_dst: processor_handle,
):
if not isinstance(processor_handle_src, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(
processor_handle_src, amdsmi_wrapper.amdsmi_processor_handle
)
if not isinstance(processor_handle_dst, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(
processor_handle_dst, amdsmi_wrapper.amdsmi_processor_handle
)
type = ctypes.c_uint32()
cap = amdsmi_wrapper.struct_amdsmi_p2p_capability_t()
_check_res(
amdsmi_wrapper.amdsmi_topo_get_p2p_status(
processor_handle_src, processor_handle_dst, ctypes.byref(type), ctypes.byref(cap)
)
)
return {
'type' : type,
'cap': {
'is_iolink_coherent': cap.is_iolink_coherent,
'is_iolink_atomics_32bit': cap.is_iolink_atomics_32bit,
'is_iolink_atomics_64bit': cap.is_iolink_atomics_64bit,
'is_iolink_dma': cap.is_iolink_dma,
'is_iolink_bi_directional': cap.is_iolink_bi_directional
}
}
def amdsmi_is_P2P_accessible(
processor_handle_src: processor_handle,
processor_handle_dst: processor_handle,
):
if not isinstance(processor_handle_src, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(
processor_handle_src, amdsmi_wrapper.amdsmi_processor_handle
)
if not isinstance(processor_handle_dst, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(
processor_handle_dst, amdsmi_wrapper.amdsmi_processor_handle
)
accessible = ctypes.c_bool()
_check_res(
amdsmi_wrapper.amdsmi_is_P2P_accessible(
processor_handle_src, processor_handle_dst, ctypes.byref(accessible)
)
)
return accessible.value
def amdsmi_get_gpu_compute_partition(processor_handle: processor_handle):
if not isinstance(processor_handle, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(
processor_handle, amdsmi_wrapper.amdsmi_processor_handle
)
length = ctypes.c_uint32()
length.value = _AMDSMI_STRING_LENGTH
compute_partition = ctypes.create_string_buffer(_AMDSMI_STRING_LENGTH)
_check_res(
amdsmi_wrapper.amdsmi_get_gpu_compute_partition(
processor_handle, compute_partition, length
)
)
return compute_partition.value.decode("utf-8")
def amdsmi_set_gpu_compute_partition(processor_handle: processor_handle,
compute_partition: AmdSmiComputePartitionType):
if not isinstance(processor_handle, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(
processor_handle, amdsmi_wrapper.amdsmi_processor_handle
)
if not isinstance(compute_partition, AmdSmiComputePartitionType):
raise AmdSmiParameterException(compute_partition, AmdSmiComputePartitionType)
_check_res(
amdsmi_wrapper.amdsmi_set_gpu_compute_partition(
processor_handle, compute_partition
)
)
def amdsmi_set_gpu_accelerator_partition_profile(processor_handle: processor_handle,
profile_index: int):
if not isinstance(processor_handle, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(
processor_handle, amdsmi_wrapper.amdsmi_processor_handle
)
if not isinstance(profile_index, int):
raise AmdSmiParameterException(profile_index, int)
_check_res(
amdsmi_wrapper.amdsmi_set_gpu_accelerator_partition_profile(
processor_handle, profile_index
)
)
def amdsmi_get_gpu_memory_partition(processor_handle: processor_handle):
if not isinstance(processor_handle, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(
processor_handle, amdsmi_wrapper.amdsmi_processor_handle
)
length = ctypes.c_uint32()
length.value = _AMDSMI_STRING_LENGTH
memory_partition = ctypes.create_string_buffer(_AMDSMI_STRING_LENGTH)
_check_res(
amdsmi_wrapper.amdsmi_get_gpu_memory_partition(
processor_handle, memory_partition, length
)
)
return memory_partition.value.decode("utf-8")
def amdsmi_get_gpu_memory_partition_config(processor_handle: processor_handle):
if not isinstance(processor_handle, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(
processor_handle, amdsmi_wrapper.amdsmi_processor_handle
)
config = amdsmi_wrapper.amdsmi_memory_partition_config_t()
_check_res(
amdsmi_wrapper.amdsmi_get_gpu_memory_partition_config(
processor_handle, config
)
)
mem_caps_list = []
if config.partition_caps.nps_flags.nps1_cap == 1:
mem_caps_list.append("NPS1")
if config.partition_caps.nps_flags.nps2_cap == 1:
mem_caps_list.append("NPS2")
if config.partition_caps.nps_flags.nps4_cap == 1:
mem_caps_list.append("NPS4")
if config.partition_caps.nps_flags.nps8_cap == 1:
mem_caps_list.append("NPS8")
if (config.partition_caps.nps_flags.nps1_cap == 0 and
config.partition_caps.nps_flags.nps2_cap == 0 and
config.partition_caps.nps_flags.nps4_cap == 0 and
config.partition_caps.nps_flags.nps8_cap == 0):
mem_caps_list.append("N/A")
return_dict = {
"partition_caps": mem_caps_list,
"mp_mode": amdsmi_wrapper.amdsmi_memory_partition_type_t__enumvalues[
config.mp_mode].replace("AMDSMI_MEMORY_PARTITION_", "").replace("UNKNOWN", "N/A"),
"num_numa_ranges": "N/A",
"numa_range": "N/A",
}
return return_dict
def amdsmi_set_gpu_memory_partition(processor_handle: processor_handle,
memory_partition: AmdSmiMemoryPartitionType):
if not isinstance(processor_handle, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(
processor_handle, amdsmi_wrapper.amdsmi_processor_handle
)
if not isinstance(memory_partition, AmdSmiMemoryPartitionType):
raise AmdSmiParameterException(memory_partition, AmdSmiMemoryPartitionType)
_check_res(
amdsmi_wrapper.amdsmi_set_gpu_memory_partition(
processor_handle, memory_partition
)
)
def amdsmi_set_gpu_memory_partition_mode(processor_handle: processor_handle,
memory_partition: AmdSmiMemoryPartitionType):
if not isinstance(processor_handle, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(
processor_handle, amdsmi_wrapper.amdsmi_processor_handle
)
if not isinstance(memory_partition, AmdSmiMemoryPartitionType):
raise AmdSmiParameterException(memory_partition, AmdSmiMemoryPartitionType)
_check_res(
amdsmi_wrapper.amdsmi_set_gpu_memory_partition(
processor_handle, memory_partition
)
)
def amdsmi_get_gpu_accelerator_partition_profile(
processor_handle: processor_handle
) -> Dict[str, Any]:
if not isinstance(processor_handle, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(
processor_handle, amdsmi_wrapper.amdsmi_processor_handle
)
exception_caught = False
length = 8
partition_id = [0, 0, 0, 0, 0, 0, 0, 0]
partition_id_list = (ctypes.c_uint32 * length)(*partition_id)
profile = amdsmi_wrapper.amdsmi_accelerator_partition_profile_t()
partition_ids = []
kPOSITION_OF_PARTITION_ID = 0
ret = amdsmi_wrapper.amdsmi_get_gpu_accelerator_partition_profile(processor_handle,
ctypes.byref(profile), partition_id_list)
if ret == amdsmi_wrapper.AMDSMI_STATUS_NOT_SUPPORTED:
#partition_id[0] will contain the partition id of each device
#BM/Guest will include this logic. Host will only display primary partition ids.
partition_ids.append(partition_id_list[kPOSITION_OF_PARTITION_ID])
try:
_check_res(ret)
except AmdSmiException as e:
partition_profile_dict = {
"profile_type" : "N/A",
"num_partitions" : "N/A",
"profile_index" : "N/A",
"memory_caps": "N/A",
"num_resources" : "N/A",
"resources" : "N/A"
}
return_dictionary = {
"partition_id" : partition_ids,
"partition_profile" : partition_profile_dict
}
if ret == amdsmi_wrapper.AMDSMI_STATUS_NOT_SUPPORTED:
exception_caught = True
else:
_check_res(ret) # re-raise the exception if error is anything other than AMDSMI_STATUS_NOT_SUPPORTED
# this ensures we can get partition ID even if the profile is not supported.
finally:
if exception_caught:
return return_dictionary
else:
profile_type_ret = amdsmi_wrapper.amdsmi_accelerator_partition_type_t__enumvalues[profile.profile_type].replace("AMDSMI_ACCELERATOR_PARTITION_", "")
profile_type_ret = profile_type_ret.replace("INVALID", "N/A")
length = profile.num_partitions
#partition_id[0] will contain the partition id of each device
#BM/Guest will include this logic. Host will only display primary partition ids.
partition_ids.append(partition_id_list[kPOSITION_OF_PARTITION_ID])
mem_caps_list = []
if profile.memory_caps.nps_flags.nps1_cap == 1:
mem_caps_list.append("NPS1")
if profile.memory_caps.nps_flags.nps2_cap == 1:
mem_caps_list.append("NPS2")
if profile.memory_caps.nps_flags.nps4_cap == 1:
mem_caps_list.append("NPS4")
if profile.memory_caps.nps_flags.nps8_cap == 1:
mem_caps_list.append("NPS8")
if (profile.memory_caps.nps_flags.nps1_cap == 0 and
profile.memory_caps.nps_flags.nps2_cap == 0 and
profile.memory_caps.nps_flags.nps4_cap == 0 and
profile.memory_caps.nps_flags.nps8_cap == 0):
mem_caps_list.append("N/A")
partition_profile_dict = {
"profile_type" : profile_type_ret,
"num_partitions" : profile.num_partitions,
"profile_index" : profile.profile_index,
"memory_caps": mem_caps_list,
"num_resources" : profile.num_resources,
"resources" : "N/A"
}
return_dictionary = {
"partition_id" : partition_ids,
"partition_profile" : partition_profile_dict
}
return return_dictionary
def amdsmi_get_gpu_accelerator_partition_profile_config(processor_handle: processor_handle) -> Dict:
if not isinstance(processor_handle, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(
processor_handle, amdsmi_wrapper.amdsmi_processor_handle
)
config = amdsmi_wrapper.amdsmi_accelerator_partition_profile_config_t()
_check_res(amdsmi_wrapper.amdsmi_get_gpu_accelerator_partition_profile_config(processor_handle,
ctypes.byref(config)))
profiles = []
resource_idx = 0
for i in range(config.num_profiles):
profile = config.profiles[i]
profile_type_ret = amdsmi_wrapper.amdsmi_accelerator_partition_type_t__enumvalues[
config.profiles[i].profile_type].replace("AMDSMI_ACCELERATOR_PARTITION_", "")
profile_type_ret = profile_type_ret.replace("INVALID", "N/A")
resources = []
mem_caps_list = []
if profile.memory_caps.nps_flags.nps1_cap == 1:
mem_caps_list.append("NPS1")
if profile.memory_caps.nps_flags.nps2_cap == 1:
mem_caps_list.append("NPS2")
if profile.memory_caps.nps_flags.nps4_cap == 1:
mem_caps_list.append("NPS4")
if profile.memory_caps.nps_flags.nps8_cap == 1:
mem_caps_list.append("NPS8")
if (profile.memory_caps.nps_flags.nps1_cap == 0 and
profile.memory_caps.nps_flags.nps2_cap == 0 and
profile.memory_caps.nps_flags.nps4_cap == 0 and
profile.memory_caps.nps_flags.nps8_cap == 0):
mem_caps_list.append("N/A")
for r in range(config.num_resource_profiles):
res_profile = config.resource_profiles[resource_idx]
resource_profiles_ret = amdsmi_wrapper.amdsmi_accelerator_partition_resource_type_t__enumvalues[
res_profile.resource_type].replace("AMDSMI_ACCELERATOR_", "")
resource_profile_dict = {
"profile_index": res_profile.profile_index,
"resource_type": resource_profiles_ret,
"partition_resource": res_profile.partition_resource,
"num_partitions_share_resource": res_profile.num_partitions_share_resource,
}
resources.append(resource_profile_dict)
resource_idx += 1
profile_dict = {
"profile_type": profile_type_ret,
"num_partitions": profile.num_partitions,
"profile_index": profile.profile_index,
"memory_caps": mem_caps_list,
"num_resources": profile.num_resources,
"resources": resources
}
profiles.append(profile_dict)
config_dict = {
"num_profiles": config.num_profiles,
"num_resource_profiles": config.num_resource_profiles,
"resource_profiles": resources,
"default_profile_index": config.default_profile_index,
"profiles": profiles,
}
return config_dict
def amdsmi_get_xgmi_info(processor_handle: processor_handle):
if not isinstance(processor_handle, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(
processor_handle, amdsmi_wrapper.amdsmi_processor_handle
)
xgmi_info = amdsmi_wrapper.amdsmi_xgmi_info_t()
_check_res(amdsmi_wrapper.amdsmi_get_xgmi_info(processor_handle, xgmi_info))
return {
"xgmi_lanes": xgmi_info.xgmi_lanes,
"xgmi_hive_id": xgmi_info.xgmi_hive_id,
"xgmi_node_id": xgmi_info.xgmi_node_id,
"index": xgmi_info.index,
}
def amdsmi_gpu_counter_group_supported(
processor_handle: processor_handle,
event_group: AmdSmiEventGroup,
):
if not isinstance(processor_handle, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(
processor_handle, amdsmi_wrapper.amdsmi_processor_handle
)
if not isinstance(event_group, AmdSmiEventGroup):
raise AmdSmiParameterException(event_group, AmdSmiEventGroup)
_check_res(
amdsmi_wrapper.amdsmi_gpu_counter_group_supported(
processor_handle, event_group)
)
def amdsmi_gpu_create_counter(
processor_handle: processor_handle,
event_type: AmdSmiEventType,
) -> amdsmi_wrapper.amdsmi_event_handle_t:
if not isinstance(processor_handle, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(
processor_handle, amdsmi_wrapper.amdsmi_processor_handle
)
if not isinstance(event_type, AmdSmiEventType):
raise AmdSmiParameterException(event_type, AmdSmiEventType)
event_handle = amdsmi_wrapper.amdsmi_event_handle_t()
_check_res(
amdsmi_wrapper.amdsmi_gpu_create_counter(
processor_handle, event_type, ctypes.byref(event_handle)
)
)
return event_handle
def amdsmi_gpu_destroy_counter(event_handle: amdsmi_wrapper.amdsmi_event_handle_t):
if not isinstance(event_handle, amdsmi_wrapper.amdsmi_event_handle_t):
raise AmdSmiParameterException(
event_handle, amdsmi_wrapper.amdsmi_event_handle_t
)
_check_res(amdsmi_wrapper.amdsmi_gpu_destroy_counter(event_handle))
def amdsmi_gpu_control_counter(
event_handle: amdsmi_wrapper.amdsmi_event_handle_t,
counter_command: AmdSmiCounterCommand,
):
if not isinstance(event_handle, amdsmi_wrapper.amdsmi_event_handle_t):
raise AmdSmiParameterException(
event_handle, amdsmi_wrapper.amdsmi_event_handle_t
)
if not isinstance(counter_command, AmdSmiCounterCommand):
raise AmdSmiParameterException(counter_command, AmdSmiCounterCommand)
command_args = ctypes.c_void_p()
_check_res(
amdsmi_wrapper.amdsmi_gpu_control_counter(
event_handle, counter_command, command_args
)
)
def amdsmi_gpu_read_counter(
event_handle: amdsmi_wrapper.amdsmi_event_handle_t,
) -> Dict[str, Any]:
if not isinstance(event_handle, amdsmi_wrapper.amdsmi_event_handle_t):
raise AmdSmiParameterException(
event_handle, amdsmi_wrapper.amdsmi_event_handle_t
)
counter_value = amdsmi_wrapper.amdsmi_counter_value_t()
_check_res(
amdsmi_wrapper.amdsmi_gpu_read_counter(
event_handle, ctypes.byref(counter_value))
)
return {
"value": counter_value.value,
"time_enabled": counter_value.time_enabled,
"time_running": counter_value.time_running,
}
def amdsmi_get_gpu_available_counters(
processor_handle: processor_handle,
event_group: AmdSmiEventGroup,
) -> int:
if not isinstance(processor_handle, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(
processor_handle, amdsmi_wrapper.amdsmi_processor_handle
)
if not isinstance(event_group, AmdSmiEventGroup):
raise AmdSmiParameterException(event_group, AmdSmiEventGroup)
available = ctypes.c_uint32()
_check_res(
amdsmi_wrapper.amdsmi_get_gpu_available_counters(
processor_handle, event_group, ctypes.byref(available)
)
)
return available.value
def amdsmi_set_gpu_perf_level(
processor_handle: processor_handle,
perf_level: AmdSmiDevPerfLevel,
):
if not isinstance(processor_handle, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(
processor_handle, amdsmi_wrapper.amdsmi_processor_handle
)
if not isinstance(perf_level, AmdSmiDevPerfLevel):
raise AmdSmiParameterException(perf_level, AmdSmiDevPerfLevel)
_check_res(amdsmi_wrapper.amdsmi_set_gpu_perf_level(
processor_handle, perf_level))
def amdsmi_reset_gpu(processor_handle: processor_handle):
if not isinstance(processor_handle, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(
processor_handle, amdsmi_wrapper.amdsmi_processor_handle
)
_check_res(amdsmi_wrapper.amdsmi_reset_gpu(processor_handle))
def amdsmi_gpu_driver_reload():
_check_res(amdsmi_wrapper.amdsmi_gpu_driver_reload())
def amdsmi_set_gpu_fan_speed(
processor_handle: processor_handle, sensor_idx: int, fan_speed: int
):
if not isinstance(processor_handle, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(
processor_handle, amdsmi_wrapper.amdsmi_processor_handle
)
if not isinstance(sensor_idx, int):
raise AmdSmiParameterException(sensor_idx, int)
if not isinstance(fan_speed, int):
raise AmdSmiParameterException(fan_speed, int)
sensor_idx = ctypes.c_uint32(sensor_idx)
fan_speed = ctypes.c_uint64(fan_speed)
_check_res(
amdsmi_wrapper.amdsmi_set_gpu_fan_speed(
processor_handle, sensor_idx, fan_speed)
)
def amdsmi_reset_gpu_fan(
processor_handle: processor_handle, sensor_idx: int
):
if not isinstance(processor_handle, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(
processor_handle, amdsmi_wrapper.amdsmi_processor_handle
)
if not isinstance(sensor_idx, int):
raise AmdSmiParameterException(sensor_idx, int)
sensor_idx = ctypes.c_uint32(sensor_idx)
_check_res(amdsmi_wrapper.amdsmi_reset_gpu_fan(processor_handle, sensor_idx))
def amdsmi_set_clk_freq(
processor_handle: processor_handle,
clk_type: str,
freq_bitmask: int,
):
if not isinstance(processor_handle, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(
processor_handle, amdsmi_wrapper.amdsmi_processor_handle
)
if clk_type.lower() == "sclk":
clk_type_conversion = AmdSmiClkType.SYS
elif clk_type.lower() == "mclk":
clk_type_conversion = AmdSmiClkType.MEM
elif clk_type.lower() == "fclk":
clk_type_conversion = AmdSmiClkType.DF
elif clk_type.lower() == "socclk":
clk_type_conversion = AmdSmiClkType.SOC
else:
clk_type_conversion = "N/A"
if not isinstance(clk_type_conversion, AmdSmiClkType):
raise AmdSmiParameterException(clk_type_conversion, AmdSmiClkType)
if not isinstance(freq_bitmask, int):
raise AmdSmiParameterException(freq_bitmask, int)
freq_bitmask = ctypes.c_uint64(freq_bitmask)
_check_res(
amdsmi_wrapper.amdsmi_set_clk_freq(
processor_handle, clk_type_conversion, freq_bitmask
)
)
def amdsmi_set_soc_pstate(
processor_handle: processor_handle,
policy_id: int,
):
if not isinstance(processor_handle, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(
processor_handle, amdsmi_wrapper.amdsmi_processor_handle
)
_check_res(
amdsmi_wrapper.amdsmi_set_soc_pstate(
processor_handle, policy_id
)
)
def amdsmi_set_xgmi_plpd(
processor_handle: processor_handle,
policy_id: int,
):
if not isinstance(processor_handle, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(
processor_handle, amdsmi_wrapper.amdsmi_processor_handle
)
_check_res(
amdsmi_wrapper.amdsmi_set_xgmi_plpd(
processor_handle, policy_id
)
)
def amdsmi_set_gpu_process_isolation(
processor_handle: processor_handle,
pisolate: int,
):
if not isinstance(processor_handle, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(
processor_handle, amdsmi_wrapper.amdsmi_processor_handle
)
_check_res(
amdsmi_wrapper.amdsmi_set_gpu_process_isolation(
processor_handle, pisolate
)
)
def amdsmi_clean_gpu_local_data(
processor_handle: processor_handle,
):
if not isinstance(processor_handle, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(
processor_handle, amdsmi_wrapper.amdsmi_processor_handle
)
_check_res(
amdsmi_wrapper.amdsmi_clean_gpu_local_data(
processor_handle
)
)
def amdsmi_set_gpu_overdrive_level(
processor_handle: processor_handle, overdrive_value: int
):
if not isinstance(processor_handle, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(
processor_handle, amdsmi_wrapper.amdsmi_processor_handle
)
if not isinstance(overdrive_value, int):
raise AmdSmiParameterException(overdrive_value, int)
overdrive_value = ctypes.c_uint32(overdrive_value)
_check_res(
amdsmi_wrapper.amdsmi_set_gpu_overdrive_level(
processor_handle, overdrive_value)
)
def amdsmi_get_gpu_bdf_id(processor_handle: processor_handle):
if not isinstance(processor_handle, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(
processor_handle, amdsmi_wrapper.amdsmi_processor_handle
)
bdfid = ctypes.c_uint64()
_check_res(
amdsmi_wrapper.amdsmi_get_gpu_bdf_id(
processor_handle, ctypes.byref(bdfid))
)
return bdfid.value
def amdsmi_set_gpu_pci_bandwidth(
processor_handle: processor_handle, bitmask: int
) -> None:
if not isinstance(processor_handle, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(
processor_handle, amdsmi_wrapper.amdsmi_processor_handle
)
if not isinstance(bitmask, int):
raise AmdSmiParameterException(bitmask, int)
_check_res(
amdsmi_wrapper.amdsmi_set_gpu_pci_bandwidth(
processor_handle, ctypes.c_uint64(bitmask)
)
)
def _format_transfer_rate(transfer_rate):
return {
'num_supported': transfer_rate.num_supported,
'current': transfer_rate.current,
'frequency': list(transfer_rate.frequency)
}
def amdsmi_get_gpu_pci_bandwidth(processor_handle: processor_handle):
if not isinstance(processor_handle, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(
processor_handle, amdsmi_wrapper.amdsmi_processor_handle
)
bandwidth = amdsmi_wrapper.amdsmi_pcie_bandwidth_t()
_check_res(
amdsmi_wrapper.amdsmi_get_gpu_pci_bandwidth(
processor_handle, ctypes.byref(bandwidth))
)
transfer_rate = _format_transfer_rate(bandwidth.transfer_rate)
return {
'transfer_rate': transfer_rate,
'lanes': list(bandwidth.lanes)
}
def amdsmi_get_gpu_pci_throughput(processor_handle: processor_handle):
if not isinstance(processor_handle, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(
processor_handle, amdsmi_wrapper.amdsmi_processor_handle
)
sent = ctypes.c_uint64()
received = ctypes.c_uint64()
max_pkt_sz = ctypes.c_uint64()
_check_res(
amdsmi_wrapper.amdsmi_get_gpu_pci_throughput(processor_handle, ctypes.byref(
sent), ctypes.byref(received), ctypes.byref(max_pkt_sz))
)
return {
'sent': sent.value,
'received': received.value,
'max_pkt_sz': max_pkt_sz.value
}
def amdsmi_get_gpu_pci_replay_counter(processor_handle: processor_handle):
if not isinstance(processor_handle, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(
processor_handle, amdsmi_wrapper.amdsmi_processor_handle
)
counter = ctypes.c_uint64()
_check_res(
amdsmi_wrapper.amdsmi_get_gpu_pci_replay_counter(
processor_handle, ctypes.byref(counter))
)
return counter.value
def amdsmi_get_gpu_topo_numa_affinity(processor_handle: processor_handle):
if not isinstance(processor_handle, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(
processor_handle, amdsmi_wrapper.amdsmi_processor_handle
)
numa_node = ctypes.c_int32()
_check_res(
amdsmi_wrapper.amdsmi_get_gpu_topo_numa_affinity(
processor_handle, ctypes.byref(numa_node))
)
return numa_node.value
def amdsmi_set_power_cap(
processor_handle: processor_handle, sensor_ind: int, cap: int
) -> None:
if not isinstance(processor_handle, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(
processor_handle, amdsmi_wrapper.amdsmi_processor_handle
)
if not isinstance(sensor_ind, int):
raise AmdSmiParameterException(sensor_ind, int)
if not isinstance(cap, int):
raise AmdSmiParameterException(cap, int)
_check_res(
amdsmi_wrapper.amdsmi_set_power_cap(
processor_handle, ctypes.c_uint32(sensor_ind), ctypes.c_uint64(cap)
)
)
def amdsmi_set_gpu_power_profile(
processor_handle: processor_handle,
reserved: int,
profile: AmdSmiPowerProfilePresetMasks,
) -> None:
if not isinstance(processor_handle, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(
processor_handle, amdsmi_wrapper.amdsmi_processor_handle
)
if not isinstance(reserved, int):
raise AmdSmiParameterException(reserved, int)
if not isinstance(profile, AmdSmiPowerProfilePresetMasks):
raise AmdSmiParameterException(profile, AmdSmiPowerProfilePresetMasks)
_check_res(
amdsmi_wrapper.amdsmi_set_gpu_power_profile(
processor_handle, ctypes.c_uint32(reserved), profile
)
)
def amdsmi_get_energy_count(processor_handle: processor_handle):
if not isinstance(processor_handle, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(
processor_handle, amdsmi_wrapper.amdsmi_processor_handle
)
energy_accumulator= ctypes.c_uint64()
counter_resolution = ctypes.c_float()
timestamp = ctypes.c_uint64()
_check_res(
amdsmi_wrapper.amdsmi_get_energy_count(processor_handle, ctypes.byref(
energy_accumulator), ctypes.byref(counter_resolution), ctypes.byref(timestamp))
)
return {
'energy_accumulator': energy_accumulator.value,
'counter_resolution': counter_resolution.value,
'timestamp': timestamp.value,
}
def amdsmi_set_gpu_clk_range(
processor_handle: processor_handle,
min_clk_value: int,
max_clk_value: int,
clk_type: AmdSmiClkType,
) -> None:
if not isinstance(processor_handle, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(
processor_handle, amdsmi_wrapper.amdsmi_processor_handle
)
if not isinstance(min_clk_value, int):
raise AmdSmiParameterException(min_clk_value, int)
if not isinstance(max_clk_value, int):
raise AmdSmiParameterException(min_clk_value, int)
if not isinstance(clk_type, AmdSmiClkType):
raise AmdSmiParameterException(clk_type, AmdSmiClkType)
_check_res(
amdsmi_wrapper.amdsmi_set_gpu_clk_range(
processor_handle,
ctypes.c_uint64(min_clk_value),
ctypes.c_uint64(max_clk_value),
clk_type,
)
)
def amdsmi_set_gpu_clk_limit(
processor_handle: processor_handle,
clk_type: str,
limit_type: str,
value: int
) -> None:
if not isinstance(processor_handle, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(
processor_handle, amdsmi_wrapper.amdsmi_processor_handle
)
if not isinstance(value, int):
raise AmdSmiParameterException(value, int)
if clk_type.lower() == "sclk":
clk_type_conversion = amdsmi_wrapper.AMDSMI_CLK_TYPE_SYS
elif clk_type.lower() == "mclk":
clk_type_conversion = amdsmi_wrapper.AMDSMI_CLK_TYPE_MEM
if limit_type.lower() == "min":
limit_type_conversion = amdsmi_wrapper.CLK_LIMIT_MIN
elif limit_type.lower() == "max":
limit_type_conversion = amdsmi_wrapper.CLK_LIMIT_MAX
_check_res(
amdsmi_wrapper.amdsmi_set_gpu_clk_limit(
processor_handle,
amdsmi_wrapper.amdsmi_clk_type_t(clk_type_conversion),
amdsmi_wrapper.amdsmi_clk_limit_type_t(limit_type_conversion),
ctypes.c_uint64(value),
)
)
def amdsmi_get_gpu_memory_total(processor_handle: processor_handle, mem_type: AmdSmiMemoryType):
if not isinstance(processor_handle, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(
processor_handle, amdsmi_wrapper.amdsmi_processor_handle
)
if not isinstance(mem_type, AmdSmiMemoryType):
raise AmdSmiParameterException(
mem_type, AmdSmiMemoryType
)
total = ctypes.c_uint64()
_check_res(
amdsmi_wrapper.amdsmi_get_gpu_memory_total(
processor_handle, mem_type, ctypes.byref(total))
)
return total.value
def amdsmi_set_gpu_od_clk_info(
processor_handle: processor_handle,
level: AmdSmiFreqInd,
value: int,
clk_type: AmdSmiClkType,
) -> None:
if not isinstance(processor_handle, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(
processor_handle, amdsmi_wrapper.amdsmi_processor_handle
)
if not isinstance(level, AmdSmiFreqInd):
raise AmdSmiParameterException(level, AmdSmiFreqInd)
if not isinstance(value, int):
raise AmdSmiParameterException(value, int)
if not isinstance(clk_type, AmdSmiClkType):
raise AmdSmiParameterException(clk_type, AmdSmiClkType)
_check_res(
amdsmi_wrapper.amdsmi_set_gpu_od_clk_info(
processor_handle, level, ctypes.c_uint64(value), clk_type
)
)
def amdsmi_get_gpu_memory_usage(processor_handle: processor_handle, mem_type: AmdSmiMemoryType):
if not isinstance(processor_handle, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(
processor_handle, amdsmi_wrapper.amdsmi_processor_handle
)
if not isinstance(mem_type, AmdSmiMemoryType):
raise AmdSmiParameterException(
mem_type, AmdSmiMemoryType
)
used = ctypes.c_uint64()
_check_res(
amdsmi_wrapper.amdsmi_get_gpu_memory_usage(
processor_handle, mem_type, ctypes.byref(used))
)
return used.value
def amdsmi_set_gpu_od_volt_info(
processor_handle: processor_handle,
vpoint: int,
clk_value: int,
volt_value: int,
) -> None:
if not isinstance(processor_handle, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(
processor_handle, amdsmi_wrapper.amdsmi_processor_handle
)
if not isinstance(vpoint, int):
raise AmdSmiParameterException(vpoint, int)
if not isinstance(clk_value, int):
raise AmdSmiParameterException(clk_value, int)
if not isinstance(volt_value, int):
raise AmdSmiParameterException(volt_value, int)
_check_res(
amdsmi_wrapper.amdsmi_set_gpu_od_volt_info(
processor_handle,
ctypes.c_uint32(vpoint),
ctypes.c_uint64(clk_value),
ctypes.c_uint64(volt_value),
)
)
def amdsmi_get_gpu_fan_rpms(
processor_handle: processor_handle, sensor_idx: int
) -> int:
if not isinstance(processor_handle, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(
processor_handle, amdsmi_wrapper.amdsmi_processor_handle
)
if not isinstance(sensor_idx, int):
raise AmdSmiParameterException(sensor_idx, int)
fan_speed = ctypes.c_int64()
_check_res(
amdsmi_wrapper.amdsmi_get_gpu_fan_rpms(
processor_handle, sensor_idx, ctypes.byref(fan_speed)
)
)
return fan_speed.value
def amdsmi_get_gpu_fan_speed(
processor_handle: processor_handle, sensor_idx: int
) -> int:
if not isinstance(processor_handle, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(
processor_handle, amdsmi_wrapper.amdsmi_processor_handle
)
if not isinstance(sensor_idx, int):
raise AmdSmiParameterException(sensor_idx, int)
fan_speed = ctypes.c_int64()
_check_res(
amdsmi_wrapper.amdsmi_get_gpu_fan_speed(
processor_handle, sensor_idx, ctypes.byref(fan_speed)
)
)
return fan_speed.value
def amdsmi_get_gpu_fan_speed_max(
processor_handle: processor_handle, sensor_idx: int
) -> int:
if not isinstance(processor_handle, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(
processor_handle, amdsmi_wrapper.amdsmi_processor_handle
)
if not isinstance(sensor_idx, int):
raise AmdSmiParameterException(sensor_idx, int)
fan_speed = ctypes.c_uint64()
_check_res(
amdsmi_wrapper.amdsmi_get_gpu_fan_speed_max(
processor_handle, sensor_idx, ctypes.byref(fan_speed)
)
)
return fan_speed.value
def amdsmi_get_temp_metric(
processor_handle: processor_handle,
sensor_type: AmdSmiTemperatureType,
metric: AmdSmiTemperatureMetric,
) -> int:
if not isinstance(processor_handle, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(
processor_handle, amdsmi_wrapper.amdsmi_processor_handle
)
if not isinstance(sensor_type, AmdSmiTemperatureType):
raise AmdSmiParameterException(sensor_type, AmdSmiTemperatureType)
if not isinstance(metric, AmdSmiTemperatureMetric):
raise AmdSmiParameterException(metric, AmdSmiTemperatureMetric)
temp_value = ctypes.c_int64()
_check_res(
amdsmi_wrapper.amdsmi_get_temp_metric(
processor_handle, sensor_type, metric, ctypes.byref(temp_value)
)
)
return temp_value.value
def amdsmi_get_gpu_volt_metric(
processor_handle: processor_handle,
sensor_type: AmdSmiVoltageType,
metric: AmdSmiVoltageMetric,
) -> int:
if not isinstance(processor_handle, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(
processor_handle, amdsmi_wrapper.amdsmi_processor_handle
)
if not isinstance(sensor_type, AmdSmiVoltageType):
raise AmdSmiParameterException(sensor_type, AmdSmiVoltageType)
if not isinstance(metric, AmdSmiVoltageMetric):
raise AmdSmiParameterException(metric, AmdSmiVoltageMetric)
voltage = ctypes.c_int64()
_check_res(
amdsmi_wrapper.amdsmi_get_gpu_volt_metric(
processor_handle, sensor_type, metric, ctypes.byref(voltage)
)
)
return voltage.value
def amdsmi_get_utilization_count(
processor_handle: processor_handle,
counter_types: List[AmdSmiUtilizationCounterType]
) -> List[Dict[str, Any]]:
if not isinstance(processor_handle, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(
processor_handle, amdsmi_wrapper.amdsmi_processor_handle
)
# Enforce List typing
if not isinstance(counter_types, list):
counter_types = [counter_types]
counter_types = list(set(counter_types))
# Validate Inputs
if len(counter_types) == 0:
raise AmdSmiLibraryException(amdsmi_wrapper.AMDSMI_STATUS_INVAL)
counters = []
for counter_type in counter_types:
if not isinstance(counter_type, AmdSmiUtilizationCounterType):
raise AmdSmiParameterException(
counter_type, AmdSmiUtilizationCounterType)
counter = amdsmi_wrapper.amdsmi_utilization_counter_t()
counter.type = counter_type
counters.append(counter)
count = ctypes.c_uint32(len(counters))
timestamp = ctypes.c_uint64()
util_counter_list = (amdsmi_wrapper.amdsmi_utilization_counter_t * len(counters))(*counters)
_check_res(
amdsmi_wrapper.amdsmi_get_utilization_count(
processor_handle, util_counter_list, count, ctypes.byref(timestamp)
)
)
if count.value != len(counters):
raise AmdSmiLibraryException(amdsmi_wrapper.AMDSMI_STATUS_API_FAILED)
result = [{"timestamp": timestamp.value}]
for index in range(count.value):
counter_type = amdsmi_wrapper.amdsmi_utilization_counter_type_t__enumvalues[
util_counter_list[index].type
]
if counter_type == "AMDSMI_UTILIZATION_COUNTER_FIRST":
counter_type = "AMDSMI_COARSE_GRAIN_GPU_ACTIVITY"
if counter_type == "AMDSMI_UTILIZATION_COUNTER_LAST":
counter_type = "AMDSMI_FINE_DECODER_ACTIVITY"
result.append(
{"type": counter_type, "value": util_counter_list[index].value})
return result
def amdsmi_get_gpu_perf_level(
processor_handle: processor_handle,
) -> str:
if not isinstance(processor_handle, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(
processor_handle, amdsmi_wrapper.amdsmi_processor_handle
)
perf = amdsmi_wrapper.amdsmi_dev_perf_level_t()
_check_res(
amdsmi_wrapper.amdsmi_get_gpu_perf_level(
processor_handle, ctypes.byref(perf))
)
result = amdsmi_wrapper.amdsmi_dev_perf_level_t__enumvalues[perf.value]
if result == "AMDSMI_DEV_PERF_LEVEL_FIRST":
result = "AMDSMI_DEV_PERF_LEVEL_AUTO"
if result == "AMDSMI_DEV_PERF_LEVEL_LAST":
result = "AMDSMI_DEV_PERF_LEVEL_DETERMINISM"
return result
def amdsmi_set_gpu_perf_determinism_mode(
processor_handle: processor_handle, clkvalue: int
) -> None:
if not isinstance(processor_handle, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(
processor_handle, amdsmi_wrapper.amdsmi_processor_handle
)
if not isinstance(clkvalue, int):
raise AmdSmiParameterException(clkvalue, int)
_check_res(amdsmi_wrapper.amdsmi_set_gpu_perf_determinism_mode(
processor_handle, clkvalue))
def amdsmi_get_gpu_overdrive_level(
processor_handle: processor_handle,
) -> int:
if not isinstance(processor_handle, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(
processor_handle, amdsmi_wrapper.amdsmi_processor_handle
)
od_level = ctypes.c_uint32()
_check_res(
amdsmi_wrapper.amdsmi_get_gpu_overdrive_level(
processor_handle, ctypes.byref(od_level)
)
)
return od_level.value
def amdsmi_get_gpu_mem_overdrive_level(
processor_handle: processor_handle,
) -> int:
if not isinstance(processor_handle, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(
processor_handle, amdsmi_wrapper.amdsmi_processor_handle
)
mem_od_level = ctypes.c_uint32()
_check_res(
amdsmi_wrapper.amdsmi_get_gpu_mem_overdrive_level(
processor_handle, ctypes.byref(mem_od_level)
)
)
return mem_od_level.value
def amdsmi_get_clk_freq(
processor_handle: processor_handle, clk_type: AmdSmiClkType
) -> Dict[str, Any]:
if not isinstance(processor_handle, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(
processor_handle, amdsmi_wrapper.amdsmi_processor_handle
)
if not isinstance(clk_type, AmdSmiClkType):
raise AmdSmiParameterException(clk_type, AmdSmiClkType)
freq = amdsmi_wrapper.amdsmi_frequencies_t()
_check_res(
amdsmi_wrapper.amdsmi_get_clk_freq(
processor_handle, clk_type, ctypes.byref(freq)
)
)
dict_ret = {
"num_supported": freq.num_supported,
"current": freq.current,
"frequency": list(freq.frequency)[: freq.num_supported],
}
return dict_ret
def amdsmi_get_soc_pstate(
processor_handle: processor_handle,
) -> Dict[str, Any]:
if not isinstance(processor_handle, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(
processor_handle, amdsmi_wrapper.amdsmi_processor_handle
)
policy = amdsmi_wrapper.amdsmi_dpm_policy_t()
_check_res(
amdsmi_wrapper.amdsmi_get_soc_pstate(
processor_handle, ctypes.byref(policy)
)
)
polices = []
for i in range(0, policy.num_supported):
id = policy.policies[i].policy_id
desc = policy.policies[i].policy_description
polices.append({
'policy_id' : id,
'policy_description': desc.decode()
})
current_id = policy.policies[policy.current].policy_id
return {
"num_supported": policy.num_supported,
"current_id": current_id,
"policies": polices,
}
def amdsmi_get_xgmi_plpd(
processor_handle: processor_handle,
) -> Dict[str, Any]:
if not isinstance(processor_handle, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(
processor_handle, amdsmi_wrapper.amdsmi_processor_handle
)
policy = amdsmi_wrapper.amdsmi_dpm_policy_t()
_check_res(
amdsmi_wrapper.amdsmi_get_xgmi_plpd(
processor_handle, ctypes.byref(policy)
)
)
polices = []
for i in range(0, policy.num_supported):
id = policy.policies[i].policy_id
desc = policy.policies[i].policy_description
polices.append({
'policy_id' : id,
'policy_description': desc.decode()
})
current_id = policy.policies[policy.current].policy_id
return {
"num_supported": policy.num_supported,
"current_id": current_id,
"plpds": polices,
}
def amdsmi_get_gpu_process_isolation(
processor_handle: processor_handle,
) -> int:
if not isinstance(processor_handle, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(
processor_handle, amdsmi_wrapper.amdsmi_processor_handle
)
pisolate = ctypes.c_uint32()
_check_res(
amdsmi_wrapper.amdsmi_get_gpu_process_isolation(
processor_handle, ctypes.byref(pisolate)
)
)
return pisolate.value
def amdsmi_get_gpu_od_volt_info(
processor_handle: processor_handle,
) -> Dict[str, Any]:
if not isinstance(processor_handle, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(
processor_handle, amdsmi_wrapper.amdsmi_processor_handle
)
freq_data = amdsmi_wrapper.amdsmi_od_volt_freq_data_t()
_check_res(
amdsmi_wrapper.amdsmi_get_gpu_od_volt_info(
processor_handle, ctypes.byref(freq_data)
)
)
sclk_lower = freq_data.curr_sclk_range.lower_bound
sclk_upper = freq_data.curr_sclk_range.upper_bound
mclk_lower = freq_data.curr_mclk_range.lower_bound
mclk_upper = freq_data.curr_mclk_range.upper_bound
if sclk_lower == MaxUIntegerTypes.UINT64_T:
sclk_lower = "N/A"
if sclk_upper == MaxUIntegerTypes.UINT64_T:
sclk_upper = "N/A"
if mclk_lower == MaxUIntegerTypes.UINT64_T:
mclk_lower = "N/A"
if mclk_upper == MaxUIntegerTypes.UINT64_T:
mclk_upper = "N/A"
return {
"curr_sclk_range": {
"lower_bound": sclk_lower,
"upper_bound": sclk_upper,
},
"curr_mclk_range": {
"lower_bound": mclk_lower,
"upper_bound": mclk_upper,
},
"sclk_freq_limits": {
"lower_bound": freq_data.sclk_freq_limits.lower_bound,
"upper_bound": freq_data.sclk_freq_limits.upper_bound,
},
"mclk_freq_limits": {
"lower_bound": freq_data.mclk_freq_limits.lower_bound,
"upper_bound": freq_data.mclk_freq_limits.upper_bound,
},
"curve.vc_points": list(freq_data.curve.vc_points),
"num_regions": freq_data.num_regions,
}
def amdsmi_get_gpu_metrics_info(
processor_handle: processor_handle,
) -> Dict[str, Any]:
if not isinstance(processor_handle, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(
processor_handle, amdsmi_wrapper.amdsmi_processor_handle
)
gpu_metrics = amdsmi_wrapper.amdsmi_gpu_metrics_t()
_check_res(
amdsmi_wrapper.amdsmi_get_gpu_metrics_info(
processor_handle, ctypes.byref(gpu_metrics)
)
)
gpu_metrics_output = {
"common_header.structure_size": _validate_if_max_uint(gpu_metrics.common_header.structure_size, MaxUIntegerTypes.UINT16_T),
"common_header.format_revision": _validate_if_max_uint(gpu_metrics.common_header.format_revision, MaxUIntegerTypes.UINT8_T),
"common_header.content_revision": _validate_if_max_uint(gpu_metrics.common_header.content_revision, MaxUIntegerTypes.UINT8_T),
"temperature_edge": _validate_if_max_uint(gpu_metrics.temperature_edge, MaxUIntegerTypes.UINT16_T),
"temperature_hotspot": _validate_if_max_uint(gpu_metrics.temperature_hotspot, MaxUIntegerTypes.UINT16_T),
"temperature_mem": _validate_if_max_uint(gpu_metrics.temperature_mem, MaxUIntegerTypes.UINT16_T),
"temperature_vrgfx": _validate_if_max_uint(gpu_metrics.temperature_vrgfx, MaxUIntegerTypes.UINT16_T),
"temperature_vrsoc": _validate_if_max_uint(gpu_metrics.temperature_vrsoc, MaxUIntegerTypes.UINT16_T),
"temperature_vrmem": _validate_if_max_uint(gpu_metrics.temperature_vrmem, MaxUIntegerTypes.UINT16_T),
"average_gfx_activity": _validate_if_max_uint(gpu_metrics.average_gfx_activity, MaxUIntegerTypes.UINT16_T, isActivity=True),
"average_umc_activity": _validate_if_max_uint(gpu_metrics.average_umc_activity, MaxUIntegerTypes.UINT16_T, isActivity=True),
"average_mm_activity": _validate_if_max_uint(gpu_metrics.average_mm_activity, MaxUIntegerTypes.UINT16_T, isActivity=True),
"average_socket_power": _validate_if_max_uint(gpu_metrics.average_socket_power, MaxUIntegerTypes.UINT16_T),
"energy_accumulator": _validate_if_max_uint(gpu_metrics.energy_accumulator, MaxUIntegerTypes.UINT64_T),
"system_clock_counter": _validate_if_max_uint(gpu_metrics.system_clock_counter, MaxUIntegerTypes.UINT64_T),
"average_gfxclk_frequency": _validate_if_max_uint(gpu_metrics.average_gfxclk_frequency, MaxUIntegerTypes.UINT16_T),
"average_socclk_frequency": _validate_if_max_uint(gpu_metrics.average_socclk_frequency, MaxUIntegerTypes.UINT16_T),
"average_uclk_frequency": _validate_if_max_uint(gpu_metrics.average_uclk_frequency, MaxUIntegerTypes.UINT16_T),
"average_vclk0_frequency": _validate_if_max_uint(gpu_metrics.average_vclk0_frequency, MaxUIntegerTypes.UINT16_T),
"average_dclk0_frequency": _validate_if_max_uint(gpu_metrics.average_dclk0_frequency, MaxUIntegerTypes.UINT16_T),
"average_vclk1_frequency": _validate_if_max_uint(gpu_metrics.average_vclk1_frequency, MaxUIntegerTypes.UINT16_T),
"average_dclk1_frequency": _validate_if_max_uint(gpu_metrics.average_dclk1_frequency, MaxUIntegerTypes.UINT16_T),
"current_gfxclk": _validate_if_max_uint(gpu_metrics.current_gfxclk, MaxUIntegerTypes.UINT16_T),
"current_socclk": _validate_if_max_uint(gpu_metrics.current_socclk, MaxUIntegerTypes.UINT16_T),
"current_uclk": _validate_if_max_uint(gpu_metrics.current_uclk, MaxUIntegerTypes.UINT16_T),
"current_vclk0": _validate_if_max_uint(gpu_metrics.current_vclk0, MaxUIntegerTypes.UINT16_T),
"current_dclk0": _validate_if_max_uint(gpu_metrics.current_dclk0, MaxUIntegerTypes.UINT16_T),
"current_vclk1": _validate_if_max_uint(gpu_metrics.current_vclk1, MaxUIntegerTypes.UINT16_T),
"current_dclk1": _validate_if_max_uint(gpu_metrics.current_dclk1, MaxUIntegerTypes.UINT16_T),
"throttle_status": _validate_if_max_uint(gpu_metrics.throttle_status, MaxUIntegerTypes.UINT32_T, isBool=True),
"current_fan_speed": _validate_if_max_uint(gpu_metrics.current_fan_speed, MaxUIntegerTypes.UINT16_T),
"pcie_link_width": _validate_if_max_uint(gpu_metrics.pcie_link_width, MaxUIntegerTypes.UINT16_T),
"pcie_link_speed": _validate_if_max_uint(gpu_metrics.pcie_link_speed, MaxUIntegerTypes.UINT16_T),
"gfx_activity_acc": _validate_if_max_uint(gpu_metrics.gfx_activity_acc, MaxUIntegerTypes.UINT32_T),
"mem_activity_acc": _validate_if_max_uint(gpu_metrics.mem_activity_acc, MaxUIntegerTypes.UINT32_T),
"temperature_hbm": _validate_if_max_uint(list(gpu_metrics.temperature_hbm), MaxUIntegerTypes.UINT16_T),
"firmware_timestamp": _validate_if_max_uint(gpu_metrics.firmware_timestamp, MaxUIntegerTypes.UINT64_T),
"voltage_soc": _validate_if_max_uint(gpu_metrics.voltage_soc, MaxUIntegerTypes.UINT16_T),
"voltage_gfx": _validate_if_max_uint(gpu_metrics.voltage_gfx, MaxUIntegerTypes.UINT16_T),
"voltage_mem": _validate_if_max_uint(gpu_metrics.voltage_mem, MaxUIntegerTypes.UINT16_T),
"indep_throttle_status": _validate_if_max_uint(gpu_metrics.indep_throttle_status, MaxUIntegerTypes.UINT64_T, isBool=True),
"current_socket_power": _validate_if_max_uint(gpu_metrics.current_socket_power, MaxUIntegerTypes.UINT16_T),
"vcn_activity": _validate_if_max_uint(list(gpu_metrics.vcn_activity), MaxUIntegerTypes.UINT16_T, isActivity=True),
"gfxclk_lock_status": _validate_if_max_uint(gpu_metrics.gfxclk_lock_status, MaxUIntegerTypes.UINT32_T),
"xgmi_link_width": _validate_if_max_uint(gpu_metrics.xgmi_link_width, MaxUIntegerTypes.UINT16_T),
"xgmi_link_speed": _validate_if_max_uint(gpu_metrics.xgmi_link_speed, MaxUIntegerTypes.UINT16_T),
"pcie_bandwidth_acc": _validate_if_max_uint(gpu_metrics.pcie_bandwidth_acc, MaxUIntegerTypes.UINT64_T),
"pcie_bandwidth_inst": _validate_if_max_uint(gpu_metrics.pcie_bandwidth_inst, MaxUIntegerTypes.UINT64_T),
"pcie_l0_to_recov_count_acc": _validate_if_max_uint(gpu_metrics.pcie_l0_to_recov_count_acc, MaxUIntegerTypes.UINT64_T),
"pcie_replay_count_acc": _validate_if_max_uint(gpu_metrics.pcie_replay_count_acc, MaxUIntegerTypes.UINT64_T),
"pcie_replay_rover_count_acc": _validate_if_max_uint(gpu_metrics.pcie_replay_rover_count_acc, MaxUIntegerTypes.UINT64_T),
"xgmi_read_data_acc": _validate_if_max_uint(list(gpu_metrics.xgmi_read_data_acc), MaxUIntegerTypes.UINT64_T),
"xgmi_write_data_acc": _validate_if_max_uint(list(gpu_metrics.xgmi_write_data_acc), MaxUIntegerTypes.UINT64_T),
"current_gfxclks": _validate_if_max_uint(list(gpu_metrics.current_gfxclks), MaxUIntegerTypes.UINT16_T),
"current_socclks": _validate_if_max_uint(list(gpu_metrics.current_socclks), MaxUIntegerTypes.UINT16_T),
"current_vclk0s": _validate_if_max_uint(list(gpu_metrics.current_vclk0s), MaxUIntegerTypes.UINT16_T),
"current_dclk0s": _validate_if_max_uint(list(gpu_metrics.current_dclk0s), MaxUIntegerTypes.UINT16_T),
"jpeg_activity": _validate_if_max_uint(list(gpu_metrics.jpeg_activity), MaxUIntegerTypes.UINT16_T, isActivity=True),
"pcie_nak_sent_count_acc": _validate_if_max_uint(gpu_metrics.pcie_nak_sent_count_acc, MaxUIntegerTypes.UINT32_T),
"pcie_nak_rcvd_count_acc": _validate_if_max_uint(gpu_metrics.pcie_nak_rcvd_count_acc, MaxUIntegerTypes.UINT32_T),
"accumulation_counter": _validate_if_max_uint(gpu_metrics.accumulation_counter, MaxUIntegerTypes.UINT64_T),
"prochot_residency_acc": _validate_if_max_uint(gpu_metrics.prochot_residency_acc, MaxUIntegerTypes.UINT64_T),
"ppt_residency_acc": _validate_if_max_uint(gpu_metrics.ppt_residency_acc, MaxUIntegerTypes.UINT64_T),
"socket_thm_residency_acc": _validate_if_max_uint(gpu_metrics.socket_thm_residency_acc, MaxUIntegerTypes.UINT64_T),
"vr_thm_residency_acc": _validate_if_max_uint(gpu_metrics.vr_thm_residency_acc, MaxUIntegerTypes.UINT64_T),
"hbm_thm_residency_acc": _validate_if_max_uint(gpu_metrics.hbm_thm_residency_acc, MaxUIntegerTypes.UINT64_T),
"num_partition": _validate_if_max_uint(gpu_metrics.num_partition, MaxUIntegerTypes.UINT16_T),
"xcp_stats.gfx_busy_inst": list(gpu_metrics.xcp_stats),
"xcp_stats.jpeg_busy": list(gpu_metrics.xcp_stats),
"xcp_stats.vcn_busy": list(gpu_metrics.xcp_stats),
"xcp_stats.gfx_busy_acc": list(gpu_metrics.xcp_stats),
"xcp_stats.gfx_below_host_limit_acc": list(gpu_metrics.xcp_stats),
"xcp_stats.gfx_below_host_limit_ppt_acc": list(gpu_metrics.xcp_stats),
"xcp_stats.gfx_below_host_limit_thm_acc": list(gpu_metrics.xcp_stats),
"xcp_stats.gfx_low_utilization_acc": list(gpu_metrics.xcp_stats),
"xcp_stats.gfx_below_host_limit_total_acc": list(gpu_metrics.xcp_stats),
"pcie_lc_perf_other_end_recovery": _validate_if_max_uint(gpu_metrics.pcie_lc_perf_other_end_recovery, MaxUIntegerTypes.UINT32_T),
"vram_max_bandwidth": _validate_if_max_uint(gpu_metrics.vram_max_bandwidth, MaxUIntegerTypes.UINT64_T),
"xgmi_link_status": _validate_if_max_uint(list(gpu_metrics.xgmi_link_status), MaxUIntegerTypes.UINT16_T),
}
# Create 2d array with each XCD's stats
if 'xcp_stats.gfx_busy_inst' in gpu_metrics_output:
for xcp_index, xcp_metrics in enumerate(gpu_metrics_output['xcp_stats.gfx_busy_inst']):
xcp_detail = []
for val in xcp_metrics.gfx_busy_inst:
xcp_detail.append(_validate_if_max_uint(val, MaxUIntegerTypes.UINT32_T, isActivity=True))
gpu_metrics_output['xcp_stats.gfx_busy_inst'][xcp_index] = xcp_detail
if 'xcp_stats.jpeg_busy' in gpu_metrics_output:
for xcp_index, xcp_metrics in enumerate(gpu_metrics_output['xcp_stats.jpeg_busy']):
xcp_detail = []
for val in xcp_metrics.jpeg_busy:
xcp_detail.append(_validate_if_max_uint(val, MaxUIntegerTypes.UINT16_T, isActivity=True))
gpu_metrics_output['xcp_stats.jpeg_busy'][xcp_index] = xcp_detail
if 'xcp_stats.vcn_busy' in gpu_metrics_output:
for xcp_index, xcp_metrics in enumerate(gpu_metrics_output['xcp_stats.vcn_busy']):
xcp_detail = []
for val in xcp_metrics.vcn_busy:
xcp_detail.append(_validate_if_max_uint(val, MaxUIntegerTypes.UINT16_T, isActivity=True))
gpu_metrics_output["xcp_stats.vcn_busy"][xcp_index] = xcp_detail
if 'xcp_stats.gfx_busy_acc' in gpu_metrics_output:
for xcp_index, xcp_metrics in enumerate(gpu_metrics_output['xcp_stats.gfx_busy_acc']):
xcp_detail = []
for val in xcp_metrics.gfx_busy_acc:
xcp_detail.append(_validate_if_max_uint(val, MaxUIntegerTypes.UINT64_T))
gpu_metrics_output["xcp_stats.gfx_busy_acc"][xcp_index] = xcp_detail
if 'xcp_stats.gfx_below_host_limit_acc' in gpu_metrics_output:
for xcp_index, xcp_metrics in enumerate(gpu_metrics_output['xcp_stats.gfx_below_host_limit_acc']):
xcp_detail = []
for val in xcp_metrics.gfx_below_host_limit_acc:
xcp_detail.append(_validate_if_max_uint(val, MaxUIntegerTypes.UINT64_T))
gpu_metrics_output['xcp_stats.gfx_below_host_limit_acc'][xcp_index] = xcp_detail
# new for gpu metrics v1.8
if 'xcp_stats.gfx_below_host_limit_ppt_acc' in gpu_metrics_output:
for xcp_index, xcp_metrics in enumerate(gpu_metrics_output['xcp_stats.gfx_below_host_limit_ppt_acc']):
xcp_detail = []
for val in xcp_metrics.gfx_below_host_limit_ppt_acc:
xcp_detail.append(_validate_if_max_uint(val, MaxUIntegerTypes.UINT64_T))
gpu_metrics_output['xcp_stats.gfx_below_host_limit_ppt_acc'][xcp_index] = xcp_detail
if 'xcp_stats.gfx_below_host_limit_thm_acc' in gpu_metrics_output:
for xcp_index, xcp_metrics in enumerate(gpu_metrics_output['xcp_stats.gfx_below_host_limit_thm_acc']):
xcp_detail = []
for val in xcp_metrics.gfx_below_host_limit_thm_acc:
xcp_detail.append(_validate_if_max_uint(val, MaxUIntegerTypes.UINT64_T))
gpu_metrics_output['xcp_stats.gfx_below_host_limit_thm_acc'][xcp_index] = xcp_detail
if 'xcp_stats.gfx_low_utilization_acc' in gpu_metrics_output:
for xcp_index, xcp_metrics in enumerate(gpu_metrics_output['xcp_stats.gfx_low_utilization_acc']):
xcp_detail = []
for val in xcp_metrics.gfx_low_utilization_acc:
xcp_detail.append(_validate_if_max_uint(val, MaxUIntegerTypes.UINT64_T))
gpu_metrics_output['xcp_stats.gfx_low_utilization_acc'][xcp_index] = xcp_detail
if 'xcp_stats.gfx_below_host_limit_total_acc' in gpu_metrics_output:
for xcp_index, xcp_metrics in enumerate(gpu_metrics_output['xcp_stats.gfx_below_host_limit_total_acc']):
xcp_detail = []
for val in xcp_metrics.gfx_below_host_limit_total_acc:
xcp_detail.append(_validate_if_max_uint(val, MaxUIntegerTypes.UINT64_T))
gpu_metrics_output['xcp_stats.gfx_below_host_limit_total_acc'][xcp_index] = xcp_detail
return gpu_metrics_output
def amdsmi_get_gpu_partition_metrics_info(
processor_handle: processor_handle,
) -> Dict[str, Any]:
if not isinstance(processor_handle, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(
processor_handle, amdsmi_wrapper.amdsmi_processor_handle
)
gpu_metrics = amdsmi_wrapper.amdsmi_gpu_metrics_t()
_check_res(
amdsmi_wrapper.amdsmi_get_gpu_partition_metrics_info(
processor_handle, ctypes.byref(gpu_metrics)
)
)
gpu_metrics_output = {
"common_header.structure_size": _validate_if_max_uint(gpu_metrics.common_header.structure_size, MaxUIntegerTypes.UINT16_T),
"common_header.format_revision": _validate_if_max_uint(gpu_metrics.common_header.format_revision, MaxUIntegerTypes.UINT8_T),
"common_header.content_revision": _validate_if_max_uint(gpu_metrics.common_header.content_revision, MaxUIntegerTypes.UINT8_T),
"temperature_edge": _validate_if_max_uint(gpu_metrics.temperature_edge, MaxUIntegerTypes.UINT16_T),
"temperature_hotspot": _validate_if_max_uint(gpu_metrics.temperature_hotspot, MaxUIntegerTypes.UINT16_T),
"temperature_mem": _validate_if_max_uint(gpu_metrics.temperature_mem, MaxUIntegerTypes.UINT16_T),
"temperature_vrgfx": _validate_if_max_uint(gpu_metrics.temperature_vrgfx, MaxUIntegerTypes.UINT16_T),
"temperature_vrsoc": _validate_if_max_uint(gpu_metrics.temperature_vrsoc, MaxUIntegerTypes.UINT16_T),
"temperature_vrmem": _validate_if_max_uint(gpu_metrics.temperature_vrmem, MaxUIntegerTypes.UINT16_T),
"average_gfx_activity": _validate_if_max_uint(gpu_metrics.average_gfx_activity, MaxUIntegerTypes.UINT16_T, isActivity=True),
"average_umc_activity": _validate_if_max_uint(gpu_metrics.average_umc_activity, MaxUIntegerTypes.UINT16_T, isActivity=True),
"average_mm_activity": _validate_if_max_uint(gpu_metrics.average_mm_activity, MaxUIntegerTypes.UINT16_T, isActivity=True),
"average_socket_power": _validate_if_max_uint(gpu_metrics.average_socket_power, MaxUIntegerTypes.UINT16_T),
"energy_accumulator": _validate_if_max_uint(gpu_metrics.energy_accumulator, MaxUIntegerTypes.UINT64_T),
"system_clock_counter": _validate_if_max_uint(gpu_metrics.system_clock_counter, MaxUIntegerTypes.UINT64_T),
"average_gfxclk_frequency": _validate_if_max_uint(gpu_metrics.average_gfxclk_frequency, MaxUIntegerTypes.UINT16_T),
"average_socclk_frequency": _validate_if_max_uint(gpu_metrics.average_socclk_frequency, MaxUIntegerTypes.UINT16_T),
"average_uclk_frequency": _validate_if_max_uint(gpu_metrics.average_uclk_frequency, MaxUIntegerTypes.UINT16_T),
"average_vclk0_frequency": _validate_if_max_uint(gpu_metrics.average_vclk0_frequency, MaxUIntegerTypes.UINT16_T),
"average_dclk0_frequency": _validate_if_max_uint(gpu_metrics.average_dclk0_frequency, MaxUIntegerTypes.UINT16_T),
"average_vclk1_frequency": _validate_if_max_uint(gpu_metrics.average_vclk1_frequency, MaxUIntegerTypes.UINT16_T),
"average_dclk1_frequency": _validate_if_max_uint(gpu_metrics.average_dclk1_frequency, MaxUIntegerTypes.UINT16_T),
"current_gfxclk": _validate_if_max_uint(gpu_metrics.current_gfxclk, MaxUIntegerTypes.UINT16_T),
"current_socclk": _validate_if_max_uint(gpu_metrics.current_socclk, MaxUIntegerTypes.UINT16_T),
"current_uclk": _validate_if_max_uint(gpu_metrics.current_uclk, MaxUIntegerTypes.UINT16_T),
"current_vclk0": _validate_if_max_uint(gpu_metrics.current_vclk0, MaxUIntegerTypes.UINT16_T),
"current_dclk0": _validate_if_max_uint(gpu_metrics.current_dclk0, MaxUIntegerTypes.UINT16_T),
"current_vclk1": _validate_if_max_uint(gpu_metrics.current_vclk1, MaxUIntegerTypes.UINT16_T),
"current_dclk1": _validate_if_max_uint(gpu_metrics.current_dclk1, MaxUIntegerTypes.UINT16_T),
"throttle_status": _validate_if_max_uint(gpu_metrics.throttle_status, MaxUIntegerTypes.UINT32_T, isBool=True),
"current_fan_speed": _validate_if_max_uint(gpu_metrics.current_fan_speed, MaxUIntegerTypes.UINT16_T),
"pcie_link_width": _validate_if_max_uint(gpu_metrics.pcie_link_width, MaxUIntegerTypes.UINT16_T),
"pcie_link_speed": _validate_if_max_uint(gpu_metrics.pcie_link_speed, MaxUIntegerTypes.UINT16_T),
"gfx_activity_acc": _validate_if_max_uint(gpu_metrics.gfx_activity_acc, MaxUIntegerTypes.UINT32_T),
"mem_activity_acc": _validate_if_max_uint(gpu_metrics.mem_activity_acc, MaxUIntegerTypes.UINT32_T),
"temperature_hbm": _validate_if_max_uint(list(gpu_metrics.temperature_hbm), MaxUIntegerTypes.UINT16_T),
"firmware_timestamp": _validate_if_max_uint(gpu_metrics.firmware_timestamp, MaxUIntegerTypes.UINT64_T),
"voltage_soc": _validate_if_max_uint(gpu_metrics.voltage_soc, MaxUIntegerTypes.UINT16_T),
"voltage_gfx": _validate_if_max_uint(gpu_metrics.voltage_gfx, MaxUIntegerTypes.UINT16_T),
"voltage_mem": _validate_if_max_uint(gpu_metrics.voltage_mem, MaxUIntegerTypes.UINT16_T),
"indep_throttle_status": _validate_if_max_uint(gpu_metrics.indep_throttle_status, MaxUIntegerTypes.UINT64_T, isBool=True),
"current_socket_power": _validate_if_max_uint(gpu_metrics.current_socket_power, MaxUIntegerTypes.UINT16_T),
"vcn_activity": _validate_if_max_uint(list(gpu_metrics.vcn_activity), MaxUIntegerTypes.UINT16_T, isActivity=True),
"gfxclk_lock_status": _validate_if_max_uint(gpu_metrics.gfxclk_lock_status, MaxUIntegerTypes.UINT32_T),
"xgmi_link_width": _validate_if_max_uint(gpu_metrics.xgmi_link_width, MaxUIntegerTypes.UINT16_T),
"xgmi_link_speed": _validate_if_max_uint(gpu_metrics.xgmi_link_speed, MaxUIntegerTypes.UINT16_T),
"pcie_bandwidth_acc": _validate_if_max_uint(gpu_metrics.pcie_bandwidth_acc, MaxUIntegerTypes.UINT64_T),
"pcie_bandwidth_inst": _validate_if_max_uint(gpu_metrics.pcie_bandwidth_inst, MaxUIntegerTypes.UINT64_T),
"pcie_l0_to_recov_count_acc": _validate_if_max_uint(gpu_metrics.pcie_l0_to_recov_count_acc, MaxUIntegerTypes.UINT64_T),
"pcie_replay_count_acc": _validate_if_max_uint(gpu_metrics.pcie_replay_count_acc, MaxUIntegerTypes.UINT64_T),
"pcie_replay_rover_count_acc": _validate_if_max_uint(gpu_metrics.pcie_replay_rover_count_acc, MaxUIntegerTypes.UINT64_T),
"xgmi_read_data_acc": _validate_if_max_uint(list(gpu_metrics.xgmi_read_data_acc), MaxUIntegerTypes.UINT64_T),
"xgmi_write_data_acc": _validate_if_max_uint(list(gpu_metrics.xgmi_write_data_acc), MaxUIntegerTypes.UINT64_T),
"current_gfxclks": _validate_if_max_uint(list(gpu_metrics.current_gfxclks), MaxUIntegerTypes.UINT16_T),
"current_socclks": _validate_if_max_uint(list(gpu_metrics.current_socclks), MaxUIntegerTypes.UINT16_T),
"current_vclk0s": _validate_if_max_uint(list(gpu_metrics.current_vclk0s), MaxUIntegerTypes.UINT16_T),
"current_dclk0s": _validate_if_max_uint(list(gpu_metrics.current_dclk0s), MaxUIntegerTypes.UINT16_T),
"jpeg_activity": _validate_if_max_uint(list(gpu_metrics.jpeg_activity), MaxUIntegerTypes.UINT16_T, isActivity=True),
"pcie_nak_sent_count_acc": _validate_if_max_uint(gpu_metrics.pcie_nak_sent_count_acc, MaxUIntegerTypes.UINT32_T),
"pcie_nak_rcvd_count_acc": _validate_if_max_uint(gpu_metrics.pcie_nak_rcvd_count_acc, MaxUIntegerTypes.UINT32_T),
"accumulation_counter": _validate_if_max_uint(gpu_metrics.accumulation_counter, MaxUIntegerTypes.UINT64_T),
"prochot_residency_acc": _validate_if_max_uint(gpu_metrics.prochot_residency_acc, MaxUIntegerTypes.UINT64_T),
"ppt_residency_acc": _validate_if_max_uint(gpu_metrics.ppt_residency_acc, MaxUIntegerTypes.UINT64_T),
"socket_thm_residency_acc": _validate_if_max_uint(gpu_metrics.socket_thm_residency_acc, MaxUIntegerTypes.UINT64_T),
"vr_thm_residency_acc": _validate_if_max_uint(gpu_metrics.vr_thm_residency_acc, MaxUIntegerTypes.UINT64_T),
"hbm_thm_residency_acc": _validate_if_max_uint(gpu_metrics.hbm_thm_residency_acc, MaxUIntegerTypes.UINT64_T),
"num_partition": _validate_if_max_uint(gpu_metrics.num_partition, MaxUIntegerTypes.UINT16_T),
"xcp_stats.gfx_busy_inst": list(gpu_metrics.xcp_stats),
"xcp_stats.jpeg_busy": list(gpu_metrics.xcp_stats),
"xcp_stats.vcn_busy": list(gpu_metrics.xcp_stats),
"xcp_stats.gfx_busy_acc": list(gpu_metrics.xcp_stats),
"xcp_stats.gfx_below_host_limit_acc": list(gpu_metrics.xcp_stats),
"xcp_stats.gfx_below_host_limit_ppt_acc": list(gpu_metrics.xcp_stats),
"xcp_stats.gfx_below_host_limit_thm_acc": list(gpu_metrics.xcp_stats),
"xcp_stats.gfx_low_utilization_acc": list(gpu_metrics.xcp_stats),
"xcp_stats.gfx_below_host_limit_total_acc": list(gpu_metrics.xcp_stats),
"pcie_lc_perf_other_end_recovery": _validate_if_max_uint(gpu_metrics.pcie_lc_perf_other_end_recovery, MaxUIntegerTypes.UINT32_T),
"vram_max_bandwidth": _validate_if_max_uint(gpu_metrics.vram_max_bandwidth, MaxUIntegerTypes.UINT64_T),
"xgmi_link_status": _validate_if_max_uint(list(gpu_metrics.xgmi_link_status), MaxUIntegerTypes.UINT16_T),
}
# Create 2d array with each XCD's stats
if 'xcp_stats.gfx_busy_inst' in gpu_metrics_output:
for xcp_index, xcp_metrics in enumerate(gpu_metrics_output['xcp_stats.gfx_busy_inst']):
xcp_detail = []
for val in xcp_metrics.gfx_busy_inst:
xcp_detail.append(_validate_if_max_uint(val, MaxUIntegerTypes.UINT32_T, isActivity=True))
gpu_metrics_output['xcp_stats.gfx_busy_inst'][xcp_index] = xcp_detail
if 'xcp_stats.jpeg_busy' in gpu_metrics_output:
for xcp_index, xcp_metrics in enumerate(gpu_metrics_output['xcp_stats.jpeg_busy']):
xcp_detail = []
for val in xcp_metrics.jpeg_busy:
xcp_detail.append(_validate_if_max_uint(val, MaxUIntegerTypes.UINT16_T, isActivity=True))
gpu_metrics_output['xcp_stats.jpeg_busy'][xcp_index] = xcp_detail
if 'xcp_stats.vcn_busy' in gpu_metrics_output:
for xcp_index, xcp_metrics in enumerate(gpu_metrics_output['xcp_stats.vcn_busy']):
xcp_detail = []
for val in xcp_metrics.vcn_busy:
xcp_detail.append(_validate_if_max_uint(val, MaxUIntegerTypes.UINT16_T, isActivity=True))
gpu_metrics_output["xcp_stats.vcn_busy"][xcp_index] = xcp_detail
if 'xcp_stats.gfx_busy_acc' in gpu_metrics_output:
for xcp_index, xcp_metrics in enumerate(gpu_metrics_output['xcp_stats.gfx_busy_acc']):
xcp_detail = []
for val in xcp_metrics.gfx_busy_acc:
xcp_detail.append(_validate_if_max_uint(val, MaxUIntegerTypes.UINT64_T))
gpu_metrics_output["xcp_stats.gfx_busy_acc"][xcp_index] = xcp_detail
if 'xcp_stats.gfx_below_host_limit_acc' in gpu_metrics_output:
for xcp_index, xcp_metrics in enumerate(gpu_metrics_output['xcp_stats.gfx_below_host_limit_acc']):
xcp_detail = []
for val in xcp_metrics.gfx_below_host_limit_acc:
xcp_detail.append(_validate_if_max_uint(val, MaxUIntegerTypes.UINT64_T))
gpu_metrics_output['xcp_stats.gfx_below_host_limit_acc'][xcp_index] = xcp_detail
# new for gpu metrics v1.8
if 'xcp_stats.gfx_below_host_limit_ppt_acc' in gpu_metrics_output:
for xcp_index, xcp_metrics in enumerate(gpu_metrics_output['xcp_stats.gfx_below_host_limit_ppt_acc']):
xcp_detail = []
for val in xcp_metrics.gfx_below_host_limit_ppt_acc:
xcp_detail.append(_validate_if_max_uint(val, MaxUIntegerTypes.UINT64_T))
gpu_metrics_output['xcp_stats.gfx_below_host_limit_ppt_acc'][xcp_index] = xcp_detail
if 'xcp_stats.gfx_below_host_limit_thm_acc' in gpu_metrics_output:
for xcp_index, xcp_metrics in enumerate(gpu_metrics_output['xcp_stats.gfx_below_host_limit_thm_acc']):
xcp_detail = []
for val in xcp_metrics.gfx_below_host_limit_thm_acc:
xcp_detail.append(_validate_if_max_uint(val, MaxUIntegerTypes.UINT64_T))
gpu_metrics_output['xcp_stats.gfx_below_host_limit_thm_acc'][xcp_index] = xcp_detail
if 'xcp_stats.gfx_low_utilization_acc' in gpu_metrics_output:
for xcp_index, xcp_metrics in enumerate(gpu_metrics_output['xcp_stats.gfx_low_utilization_acc']):
xcp_detail = []
for val in xcp_metrics.gfx_low_utilization_acc:
xcp_detail.append(_validate_if_max_uint(val, MaxUIntegerTypes.UINT64_T))
gpu_metrics_output['xcp_stats.gfx_low_utilization_acc'][xcp_index] = xcp_detail
if 'xcp_stats.gfx_below_host_limit_total_acc' in gpu_metrics_output:
for xcp_index, xcp_metrics in enumerate(gpu_metrics_output['xcp_stats.gfx_below_host_limit_total_acc']):
xcp_detail = []
for val in xcp_metrics.gfx_below_host_limit_total_acc:
xcp_detail.append(_validate_if_max_uint(val, MaxUIntegerTypes.UINT64_T))
gpu_metrics_output['xcp_stats.gfx_below_host_limit_total_acc'][xcp_index] = xcp_detail
return gpu_metrics_output
def amdsmi_get_gpu_od_volt_curve_regions(
processor_handle: processor_handle, num_regions: int
) -> List[Dict[str, Any]]:
if not isinstance(processor_handle, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(
processor_handle, amdsmi_wrapper.amdsmi_processor_handle
)
if not isinstance(num_regions, int):
raise AmdSmiParameterException(num_regions, int)
region_count = ctypes.c_uint32(num_regions)
buffer = (amdsmi_wrapper.amdsmi_freq_volt_region_t * num_regions)()
_check_res(
amdsmi_wrapper.amdsmi_get_gpu_od_volt_curve_regions(
processor_handle, ctypes.byref(region_count), buffer
)
)
result = []
for index in range(region_count.value):
result.extend(
[
{
"freq_range": {
"lower_bound": buffer[index].freq_range.lower_bound,
"upper_bound": buffer[index].freq_range.upper_bound,
},
"volt_range": {
"lower_bound": buffer[index].volt_range.lower_bound,
"upper_bound": buffer[index].volt_range.upper_bound,
},
}
]
)
return result
def amdsmi_get_gpu_power_profile_presets(
processor_handle: processor_handle, sensor_idx: int
) -> Dict[str, Any]:
if not isinstance(processor_handle, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(
processor_handle, amdsmi_wrapper.amdsmi_processor_handle
)
if not isinstance(sensor_idx, int):
raise AmdSmiParameterException(sensor_idx, int)
status = amdsmi_wrapper.amdsmi_power_profile_status_t()
_check_res(
amdsmi_wrapper.amdsmi_get_gpu_power_profile_presets(
processor_handle, sensor_idx, ctypes.byref(status)
)
)
return {
"available_profiles": status.available_profiles,
"current": status.current,
"num_profiles": status.num_profiles,
}
def amdsmi_get_gpu_ecc_count(
processor_handle: processor_handle, block: AmdSmiGpuBlock
) -> Dict[str, int]:
if not isinstance(processor_handle, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(
processor_handle, amdsmi_wrapper.amdsmi_processor_handle
)
if not isinstance(block, AmdSmiGpuBlock):
raise AmdSmiParameterException(block, AmdSmiGpuBlock)
ec = amdsmi_wrapper.amdsmi_error_count_t()
_check_res(
amdsmi_wrapper.amdsmi_get_gpu_ecc_count(
processor_handle, block, ctypes.byref(ec))
)
return {
"correctable_count": ec.correctable_count,
"uncorrectable_count": ec.uncorrectable_count,
"deferred_count": ec.deferred_count,
}
def amdsmi_get_gpu_ecc_enabled(
processor_handle: processor_handle,
) -> int:
if not isinstance(processor_handle, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(
processor_handle, amdsmi_wrapper.amdsmi_processor_handle
)
blocks = ctypes.c_uint64(0)
_check_res(
amdsmi_wrapper.amdsmi_get_gpu_ecc_enabled(
processor_handle, ctypes.byref(blocks))
)
return blocks.value
def amdsmi_get_gpu_ecc_status(
processor_handle: processor_handle, block: AmdSmiGpuBlock
) -> AmdSmiRasErrState:
if not isinstance(processor_handle, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(
processor_handle, amdsmi_wrapper.amdsmi_processor_handle
)
if not isinstance(block, AmdSmiGpuBlock):
raise AmdSmiParameterException(block, AmdSmiGpuBlock)
state = amdsmi_wrapper.amdsmi_ras_err_state_t()
_check_res(
amdsmi_wrapper.amdsmi_get_gpu_ecc_status(
processor_handle, block, ctypes.byref(state)
)
)
return AmdSmiRasErrState(state.value)
def amdsmi_status_code_to_string(status: amdsmi_wrapper.amdsmi_status_t) -> Union[str, bytes, None]:
if not isinstance(status, amdsmi_wrapper.amdsmi_status_t):
raise AmdSmiParameterException(status, amdsmi_wrapper.amdsmi_status_t)
status_string_p_p = POINTER(POINTER(ctypes.c_char()))
_check_res(amdsmi_wrapper.amdsmi_status_code_to_string(
status, status_string_p_p))
return amdsmi_wrapper.string_cast(status_string_p_p.contents)
def amdsmi_get_gpu_compute_process_info() -> List[Dict[str, int]]:
num_items = ctypes.c_uint32(0)
nullptr = POINTER(amdsmi_wrapper.amdsmi_process_info_t)()
_check_res(
amdsmi_wrapper.amdsmi_get_gpu_compute_process_info(
nullptr, ctypes.byref(num_items))
)
procs = (amdsmi_wrapper.amdsmi_process_info_t * num_items.value)()
_check_res(
amdsmi_wrapper.amdsmi_get_gpu_compute_process_info(
procs, ctypes.byref(num_items))
)
return [
{
"process_id": proc.process_id,
"vram_usage": proc.vram_usage,
"sdma_usage": proc.sdma_usage,
"cu_occupancy": proc.cu_occupancy,
}
for proc in procs
]
def amdsmi_get_gpu_compute_process_info_by_pid(pid: int) -> Dict[str, int]:
if not isinstance(pid, int):
raise AmdSmiParameterException(pid, int)
proc = amdsmi_wrapper.amdsmi_process_info_t()
_check_res(
amdsmi_wrapper.amdsmi_get_gpu_compute_process_info_by_pid(
ctypes.c_uint32(pid), ctypes.byref(proc)
)
)
return {
"process_id": proc.process_id,
"vram_usage": proc.vram_usage,
"sdma_usage": proc.sdma_usage,
"cu_occupancy": proc.cu_occupancy,
}
def amdsmi_get_gpu_compute_process_gpus(pid: int) -> List[int]:
if not isinstance(pid, int):
raise AmdSmiParameterException(pid, int)
num_devices = ctypes.c_uint32(0)
nullptr = POINTER(ctypes.c_uint32)()
_check_res(
amdsmi_wrapper.amdsmi_get_gpu_compute_process_gpus(
pid, nullptr, ctypes.byref(num_devices)
)
)
dv_indices = (ctypes.c_uint32 * num_devices.value)()
_check_res(
amdsmi_wrapper.amdsmi_get_gpu_compute_process_gpus(
pid, dv_indices, ctypes.byref(num_devices)
)
)
return [dv_index.value for dv_index in dv_indices]
def amdsmi_gpu_xgmi_error_status(
processor_handle: processor_handle,
) -> AmdSmiXgmiStatus:
if not isinstance(processor_handle, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(
processor_handle, amdsmi_wrapper.amdsmi_processor_handle
)
status = amdsmi_wrapper.amdsmi_xgmi_status_t()
_check_res(
amdsmi_wrapper.amdsmi_gpu_xgmi_error_status(
processor_handle, ctypes.byref(status))
)
return AmdSmiXgmiStatus(status.value).value
def amdsmi_reset_gpu_xgmi_error(
processor_handle: processor_handle,
) -> None:
if not isinstance(processor_handle, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(
processor_handle, amdsmi_wrapper.amdsmi_processor_handle
)
_check_res(amdsmi_wrapper.amdsmi_reset_gpu_xgmi_error(processor_handle))
def amdsmi_get_gpu_memory_reserved_pages(
processor_handle: processor_handle,
) -> Union[list, str]:
if not isinstance(processor_handle, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(
processor_handle, amdsmi_wrapper.amdsmi_processor_handle
)
num_pages = ctypes.c_uint32()
nullptr = POINTER(amdsmi_wrapper.amdsmi_retired_page_record_t)()
_check_res(
amdsmi_wrapper.amdsmi_get_gpu_memory_reserved_pages(
processor_handle, ctypes.byref(num_pages), nullptr
)
)
if num_pages.value == 0:
return []
mem_reserved_pages = (amdsmi_wrapper.amdsmi_retired_page_record_t * num_pages)()
_check_res(
amdsmi_wrapper.amdsmi_get_gpu_memory_reserved_pages(
processor_handle, ctypes.byref(num_pages), mem_reserved_pages
)
)
return _format_bad_page_info(mem_reserved_pages, num_pages)
def amdsmi_get_gpu_metrics_header_info(
processor_handle: processor_handle,
) -> Dict[str, int]:
if not isinstance(processor_handle, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(
processor_handle, amdsmi_wrapper.amdsmi_processor_handle
)
header_info = amdsmi_wrapper.amd_metrics_table_header_t()
_check_res(
amdsmi_wrapper.amdsmi_get_gpu_metrics_header_info(
processor_handle, ctypes.byref(header_info)
)
)
return {
"structure_size": header_info.structure_size,
"format_revision": header_info.format_revision,
"content_revision": header_info.content_revision
}
def amdsmi_get_link_topology_nearest(
processor_handle: processor_handle,
link_type: AmdSmiLinkType,
)-> Dict[str, Any]:
topology_nearest_list = amdsmi_wrapper.amdsmi_topology_nearest_t()
_check_res(
amdsmi_wrapper.amdsmi_get_link_topology_nearest(
processor_handle,
link_type,
ctypes.byref(topology_nearest_list)
)
)
device_list = []
for index in range(topology_nearest_list.count):
device_list.append(topology_nearest_list.processor_list[index])
return {
'processor_list': device_list
}
def amdsmi_get_gpu_virtualization_mode(
processor_handle: processor_handle
) -> Dict[str, AmdSmiVirtualizationMode]:
# make info struct here
mode = amdsmi_wrapper.amdsmi_virtualization_mode_t()
# call lib function here
_check_res(
amdsmi_wrapper.amdsmi_get_gpu_virtualization_mode(
processor_handle,
ctypes.byref(mode)
)
)
return {
"mode": AmdSmiVirtualizationMode(mode.value)
}
### Non C-Lib APIs ###
def amdsmi_get_rocm_version()-> Tuple[bool, str]:
"""
Get the ROCm version for the rocm-core library.
This function attempts to retrieve the ROCm version by loading the `librocm-core.so` shared library
and calling its `getROCmVersion` function. The version is returned as a string in the format "major.minor.patch".
Returns:
Tuple[bool, str]: A tuple containing a boolean and a string.
- The boolean indicates whether the operation was successful.
- The string contains the ROCm version if successful, or an error message if not.
Raises:
Exception: If there is an error loading the shared library or calling the function.
Example:
rocm_lib_status, version_message = amdsmi_get_rocm_version()
if rocm_lib_status:
print(f"ROCm version: {version_message}")
else:
print(f"Error: {version_message}")
"""
# librocm-core.so can be located in found using several different methods.
# Look for it with below priority:
# 1. ROCM_HOME/ROCM_PATH environment variables
# - ROCM_HOME/lib
# - ROCM_PATH/lib (usually set to /opt/rocm/)
# 2. Decided by the linker
# - LD_LIBRARY_PATH env var
# - defined path in /etc/ld.so.conf.d/
# 3. Relative to amdsmi_wrapper.py in /opt/rocm/share/amd_smi
# - parent directory
try:
possible_locations = list()
# 1.
rocm_path = os.getenv("ROCM_HOME", os.getenv("ROCM_PATH"))
if rocm_path:
possible_locations.append(os.path.join(rocm_path, "lib/librocm-core.so"))
# Check if /opt/rocm/lib/librocm-core.so exists and add it to the list
if os.path.exists("/opt/rocm/lib/librocm-core.so"):
possible_locations.append("/opt/rocm/lib/librocm-core.so")
# 2.
possible_locations.append("librocm-core.so")
# 3.
librocm_core_parent_dir = Path(__file__).resolve().parent.parent.parent / "lib" / "librocm-core.so"
possible_locations.append(librocm_core_parent_dir)
for librocm_core_file_path in possible_locations:
try:
librocm_core = ctypes.CDLL(librocm_core_file_path)
VerErrors = ctypes.c_uint32
get_rocm_core_version = librocm_core.getROCmVersion
get_rocm_core_version.restype = VerErrors
get_rocm_core_version.argtypes = [POINTER(ctypes.c_uint32), POINTER(ctypes.c_uint32),POINTER(ctypes.c_uint32)]
# call the function
major = ctypes.c_uint32()
minor = ctypes.c_uint32()
patch = ctypes.c_uint32()
if get_rocm_core_version(ctypes.byref(major), ctypes.byref(minor),ctypes.byref(patch)) == 0:
return True, f"{major.value}.{minor.value}.{patch.value}"
else:
return False, "Failed to unpack ROCm version"
except OSError as e:
err = e
continue
# If we hit here, we were unable to find the librocm-core.so file
return False, "Could not find librocm-core.so"
except Exception as e:
return False, f"Unable to detect ROCm installation, Unknown Error: {e}"
def amdsmi_get_gpu_revision(processor_handle: processor_handle) -> str:
"""
Get the GPU revision for a given processor handle.
Parameters:
processor_handle (amdsmi_processor_handle): The processor handle for the GPU.
Returns:
str: The GPU revision as a string.
Raises:
AmdSmiParameterException: If the processor handle is invalid.
AmdSmiLibraryException: If the underlying library call fails.
"""
if not isinstance(processor_handle, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(
processor_handle, amdsmi_wrapper.amdsmi_processor_handle
)
revision = ctypes.c_uint16()
_check_res(
amdsmi_wrapper.amdsmi_get_gpu_revision(
processor_handle, ctypes.byref(revision)
)
)
return _pad_hex_value(hex(revision.value), 2)
|