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
|
#!/usr/bin/env python3
""" gpu-pac - A utility program and control compatible GPUs.
Part of the rickslab-gpu-utils package which includes gpu-ls, gpu-mon,
gpu-pac, and gpu-plot.
Program and Control compatible GPUs with this utility. By default, the
commands to be written to a GPU are written to a bash file for the user to
inspect and run. If you have confidence, the *--execute_pac* option can
be used to execute and then delete the saved bash file. Since the GPU
device files are writable only by root, sudo is used to execute commands in
the bash file, as a result, you will be prompted for credentials in the
terminal where you executed *gpu-pac*. The *--no_fan* option can be used to
eliminate fan details from the utility. The *--force_write* option can be
used to force all configuration parameters to be written to the GPU. The
default behavior is to only write changes. The *--verbose* option will
display progress and informational messages generated by the utilities.
Copyright (C) 2019 RicksLab
This program is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the Free
Software Foundation, either version 3 of the License, or (at your option)
any later version.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
more details.
You should have received a copy of the GNU General Public License along with
this program. If not, see <https://www.gnu.org/licenses/>.
"""
__author__ = 'RicksLab'
__copyright__ = 'Copyright (C) 2019 RicksLab'
__license__ = 'GNU General Public License'
__program_name__ = 'gpu-pac'
__maintainer__ = 'RicksLab'
__docformat__ = 'reStructuredText'
# pylint: disable=multiple-statements
# pylint: disable=line-too-long
# pylint: disable=consider-using-f-string
import argparse
import re
import subprocess
import os
import logging
import sys
from time import sleep
from uuid import uuid4
try:
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
except ModuleNotFoundError as error:
print('gi import error: {}'.format(error))
print('gi is required for {}'.format(__program_name__))
print(' In a venv, first install vext: pip install --no-cache-dir vext')
print(' Then install vext.gi: pip install --no-cache-dir vext.gi')
sys.exit(0)
except ImportError as error:
print('gi import error: {}'.format(error))
print('If not using system python version, you may get a circular import error.')
sys.exit(0)
from GPUmodules import __version__, __status__, __credits__
from GPUmodules import GPUgui
from GPUmodules import GPUmodule as Gpu
from GPUmodules.env import GUT_CONST
from GPUmodules.GPUKeys import GpuType, GpuCompatibility, SensorSet
from GPUmodules.RegexPatterns import PatternKeys as PK
MAX_CHAR = 54
CHAR_WIDTH = 8
set_gtk_prop = GPUgui.GuiProps.set_gtk_prop
LOGGER = logging.getLogger('gpu-utils')
PATTERNS = GUT_CONST.PATTERNS
class PACWindow(Gtk.Window):
"""
PAC Window class.
"""
def __init__(self, gpu_list, devices):
init_chk_value = Gtk.init_check(sys.argv)
LOGGER.debug('init_check: %s', init_chk_value)
if not init_chk_value[0]:
print('Gtk Error, Exiting')
sys.exit(-1)
Gtk.Window.__init__(self, title=GUT_CONST.gui_window_title)
grid = Gtk.Grid()
scrolled_window = Gtk.ScrolledWindow(hexpand=True, vexpand=True)
scrolled_window.set_border_width(0)
scrolled_window.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
scrolled_window.add(grid)
self.add(scrolled_window)
GPUgui.GuiProps.set_style()
if GUT_CONST.icon_file:
LOGGER.debug('Icon file: [%s]', GUT_CONST.icon_file)
if os.path.isfile(GUT_CONST.icon_file):
self.set_icon_from_file(GUT_CONST.icon_file)
num_com_gpus = gpu_list.num_gpus()['total']
max_rows = 0
row = col = 0
for gpu in gpu_list.gpus():
row = 0
# Card Number in top center of box
devices[gpu.prm.uuid] = {'card_num': Gtk.Label(name='white_label', halign=Gtk.Align.CENTER, valign=Gtk.Align.CENTER)}
devices[gpu.prm.uuid]['card_num'].set_markup('<big><b>Card {}: </b>{}</big>'.format(
gpu.get_params_value(str('card_num')), gpu.get_params_value('model_display')[:40]))
set_gtk_prop(devices[gpu.prm.uuid]['card_num'], top=1, bottom=1, right=4, left=4)
lbox = Gtk.Box(spacing=6, name='head_box')
set_gtk_prop(lbox, top=1, bottom=1, right=1, left=1)
lbox.pack_start(devices[gpu.prm.uuid]['card_num'], True, True, 0)
grid.attach(lbox, col, row, 1, 1)
row += 1
# Card Path
devices[gpu.prm.uuid]['card_path'] = Gtk.Label(name='white_label')
devices[gpu.prm.uuid]['card_path'].set_markup('<b>Device: </b>{}'.format(gpu.get_params_value('card_path')))
set_gtk_prop(devices[gpu.prm.uuid]['card_path'], align=(0.0, 0.5), top=1, bottom=1,
right=4, left=4, width=MAX_CHAR*CHAR_WIDTH)
lbox = Gtk.Box(spacing=6, name='dark_box')
set_gtk_prop(lbox, top=1, bottom=1, right=1, left=1)
lbox.pack_start(devices[gpu.prm.uuid]['card_path'], True, True, 0)
#devices[gpu.prm.uuid]['card_path'].set_halign(Gtk.Align.END)
grid.attach(lbox, col, row, 1, 1)
row += 1
# Card Power Cap
power_cap_range = gpu.get_params_value('power_cap_range')
if 'power_cap' not in gpu.read_disabled and (power_cap_range and None not in power_cap_range):
devices[gpu.prm.uuid]['power_cap'] = Gtk.Label(name='white_label')
devices[gpu.prm.uuid]['power_cap'].set_markup('<b>Power Cap: </b> Range ({} - {} W)'.format(
power_cap_range[0], power_cap_range[1]))
set_gtk_prop(devices[gpu.prm.uuid]['power_cap'], align=(0.0, 0.5), top=1, bottom=1, right=4, left=4)
lbox = Gtk.Box(spacing=6, name='dark_box')
set_gtk_prop(lbox, top=1, bottom=1, right=1, left=1)
lbox.pack_start(devices[gpu.prm.uuid]['power_cap'], True, True, 0)
grid.attach(lbox, col, row, 1, 1)
row += 1
# Card Power Cap Value and Entry
devices[gpu.prm.uuid]['power_cap_cur'] = Gtk.Label(name='white_label')
set_gtk_prop(devices[gpu.prm.uuid]['power_cap_cur'], top=1, bottom=1, right=2, left=2)
devices[gpu.prm.uuid]['power_cap_ent'] = Gtk.Entry()
set_gtk_prop(devices[gpu.prm.uuid]['power_cap_ent'], top=1, bottom=1, right=0, left=2, xalign=1,
width_chars=5, max_length=5)
devices[gpu.prm.uuid]['power_cap_ent_unit'] = Gtk.Label(name='white_label')
devices[gpu.prm.uuid]['power_cap_ent_unit'].set_text('W (value or \'reset\')')
set_gtk_prop(devices[gpu.prm.uuid]['power_cap_ent_unit'], top=1, bottom=1, right=0, left=0,
align=(0.0, 0.5))
lbox = Gtk.Box(spacing=2, name='med_box')
set_gtk_prop(lbox, top=1, bottom=1, right=1, left=1)
lbox.pack_start(devices[gpu.prm.uuid]['power_cap_cur'], False, False, 0)
lbox.pack_start(devices[gpu.prm.uuid]['power_cap_ent'], False, False, 0)
lbox.pack_start(devices[gpu.prm.uuid]['power_cap_ent_unit'], False, False, 0)
grid.attach(lbox, col, row, 1, 1)
row += 1
fan_pwm_range = gpu.get_params_value('fan_pwm_range')
if GUT_CONST.show_fans and fan_pwm_range and None not in fan_pwm_range:
# Fan PWM Value
devices[gpu.prm.uuid]['fan_pwm_range'] = Gtk.Label(name='white_label')
devices[gpu.prm.uuid]['fan_pwm_range'].set_markup(
'<b>Fan PWM: </b> Range ({} - {} %)'.format(fan_pwm_range[0], fan_pwm_range[1]))
set_gtk_prop(devices[gpu.prm.uuid]['fan_pwm_range'], top=1, bottom=1, right=4, left=4, align=(0.0, 0.5))
lbox = Gtk.Box(spacing=6, name='dark_box')
set_gtk_prop(lbox, top=1, bottom=1, right=1, left=1)
lbox.pack_start(devices[gpu.prm.uuid]['fan_pwm_range'], True, True, 0)
grid.attach(lbox, col, row, 1, 1)
row += 1
# Card Fan PWM Value and Entry
devices[gpu.prm.uuid]['fan_pwm_cur'] = Gtk.Label(name='white_label')
set_gtk_prop(devices[gpu.prm.uuid]['fan_pwm_cur'], top=1, bottom=1, right=2, left=2)
devices[gpu.prm.uuid]['fan_pwm_ent'] = Gtk.Entry()
set_gtk_prop(devices[gpu.prm.uuid]['fan_pwm_ent'], top=1, bottom=1, right=0, left=2,
width_chars=5, max_length=5, xalign=1)
devices[gpu.prm.uuid]['fan_pwm_ent_unit'] = Gtk.Label(name='white_label')
devices[gpu.prm.uuid]['fan_pwm_ent_unit'].set_text('% (value, \'reset\', or \'max\')')
set_gtk_prop(devices[gpu.prm.uuid]['fan_pwm_ent_unit'], top=1, bottom=1,
right=0, left=0, align=(0.0, 0.5))
lbox = Gtk.Box(spacing=2, name='med_box')
set_gtk_prop(lbox, top=1, bottom=1, right=1, left=1)
lbox.pack_start(devices[gpu.prm.uuid]['fan_pwm_cur'], False, False, 0)
lbox.pack_start(devices[gpu.prm.uuid]['fan_pwm_ent'], False, False, 0)
lbox.pack_start(devices[gpu.prm.uuid]['fan_pwm_ent_unit'], False, False, 0)
grid.attach(lbox, col, row, 1, 1)
row += 1
if gpu.get_params_value('gpu_type') in (GpuType.PStatesNE, GpuType.PStates):
# Sclk P-States
devices[gpu.prm.uuid]['sclk_range'] = Gtk.Label(name='white_label')
devices[gpu.prm.uuid]['sclk_range'].set_markup('<b>Sclk P-States: </b> Ranges {}-{}, {}-{} '.format(
gpu.get_params_value('sclk_f_range')[0],
gpu.get_params_value('sclk_f_range')[1],
gpu.get_params_value('vddc_range')[0],
gpu.get_params_value('vddc_range')[1]))
set_gtk_prop(devices[gpu.prm.uuid]['sclk_range'],
top=1, bottom=1, right=4, left=4, align=(0.0, 0.5))
lbox = Gtk.Box(spacing=6, name='dark_box')
set_gtk_prop(lbox, top=1, bottom=1, right=1, left=1)
lbox.pack_start(devices[gpu.prm.uuid]['sclk_range'], False, False, 0)
grid.attach(lbox, col, row, 1, 1)
row += 1
# Sclk P-State Values and Entry
devices[gpu.prm.uuid]['sclk_pstate'] = {}
for ps in gpu.sclk_state.keys():
devices[gpu.prm.uuid]['sclk_pstate'][ps] = {}
devices[gpu.prm.uuid]['sclk_pstate'][ps]['gtk_cur_obj'] = Gtk.Label(name='white_label')
set_gtk_prop(devices[gpu.prm.uuid]['sclk_pstate'][ps]['gtk_cur_obj'], width_chars=20,
top=1, bottom=1, right=2, left=2, align=(0.0, 0.5))
devices[gpu.prm.uuid]['sclk_pstate'][ps]['gtk_ent_f_obj'] = Gtk.Entry()
set_gtk_prop(devices[gpu.prm.uuid]['sclk_pstate'][ps]['gtk_ent_f_obj'], width_chars=5, max_length=5,
xalign=1, top=1, bottom=1, right=0, left=0)
devices[gpu.prm.uuid]['sclk_pstate'][ps]['gtk_ent_f_obj_unit'] = Gtk.Label(name='white_label')
set_gtk_prop(devices[gpu.prm.uuid]['sclk_pstate'][ps]['gtk_ent_f_obj_unit'],
top=1, bottom=1, right=4, left=0, align=(0.0, 0.5))
devices[gpu.prm.uuid]['sclk_pstate'][ps]['gtk_ent_v_obj'] = Gtk.Entry()
set_gtk_prop(devices[gpu.prm.uuid]['sclk_pstate'][ps]['gtk_ent_v_obj'], width_chars=5, max_length=5,
xalign=1, top=1, bottom=1, right=0, left=0)
devices[gpu.prm.uuid]['sclk_pstate'][ps]['gtk_ent_v_obj_unit'] = Gtk.Label(name='white_label')
set_gtk_prop(devices[gpu.prm.uuid]['sclk_pstate'][ps]['gtk_ent_v_obj_unit'],
top=1, bottom=1, right=4, left=0, align=(0.0, 0.5))
lbox = Gtk.Box(spacing=6, name='med_box')
set_gtk_prop(lbox, top=1, bottom=1, right=1, left=1)
lbox.pack_start(devices[gpu.prm.uuid]['sclk_pstate'][ps]['gtk_cur_obj'], False, False, 0)
lbox.pack_start(devices[gpu.prm.uuid]['sclk_pstate'][ps]['gtk_ent_f_obj'], False, False, 0)
lbox.pack_start(devices[gpu.prm.uuid]['sclk_pstate'][ps]['gtk_ent_f_obj_unit'], False, False, 0)
lbox.pack_start(devices[gpu.prm.uuid]['sclk_pstate'][ps]['gtk_ent_v_obj'], False, False, 0)
lbox.pack_start(devices[gpu.prm.uuid]['sclk_pstate'][ps]['gtk_ent_v_obj_unit'], False, False, 0)
grid.attach(lbox, col, row, 1, 1)
row += 1
elif gpu.get_params_value('gpu_type') in (GpuType.CurvePts, GpuType.Offset):
# Sclk Curve End Points
devices[gpu.prm.uuid]['sclk_range'] = Gtk.Label(name='white_label')
devices[gpu.prm.uuid]['sclk_range'].set_markup('<b>Sclk Curve End Points: </b> Ranges {}-{} '.format(
gpu.get_params_value('sclk_f_range')[0], gpu.get_params_value('sclk_f_range')[1]))
set_gtk_prop(devices[gpu.prm.uuid]['sclk_range'], top=1, bottom=1, right=4, left=4, align=(0.0, 0.5))
lbox = Gtk.Box(spacing=6, name='dark_box')
set_gtk_prop(lbox, top=1, bottom=1, right=1, left=1)
lbox.pack_start(devices[gpu.prm.uuid]['sclk_range'], False, False, 0)
grid.attach(lbox, col, row, 1, 1)
row += 1
# Sclk Curve End Points Values and Entry
devices[gpu.prm.uuid]['sclk_pstate'] = {}
for ps in gpu.sclk_state.keys():
devices[gpu.prm.uuid]['sclk_pstate'][ps] = {}
devices[gpu.prm.uuid]['sclk_pstate'][ps]['gtk_cur_obj'] = Gtk.Label(name='white_label')
set_gtk_prop(devices[gpu.prm.uuid]['sclk_pstate'][ps]['gtk_cur_obj'], width_chars=20,
top=1, bottom=1, right=2, left=2, align=(0.0, 0.5))
devices[gpu.prm.uuid]['sclk_pstate'][ps]['gtk_ent_f_obj'] = Gtk.Entry()
set_gtk_prop(devices[gpu.prm.uuid]['sclk_pstate'][ps]['gtk_ent_f_obj'], width_chars=5, max_length=5,
xalign=1, top=1, bottom=1, right=0, left=0)
devices[gpu.prm.uuid]['sclk_pstate'][ps]['gtk_ent_f_obj_unit'] = Gtk.Label(name='white_label')
set_gtk_prop(devices[gpu.prm.uuid]['sclk_pstate'][ps]['gtk_ent_f_obj_unit'],
top=1, bottom=1, right=4, left=0, align=(0.0, 0.5))
lbox = Gtk.Box(spacing=6, name='med_box')
set_gtk_prop(lbox, top=1, bottom=1, right=1, left=1)
lbox.pack_start(devices[gpu.prm.uuid]['sclk_pstate'][ps]['gtk_cur_obj'], False, False, 0)
lbox.pack_start(devices[gpu.prm.uuid]['sclk_pstate'][ps]['gtk_ent_f_obj'], False, False, 0)
lbox.pack_start(devices[gpu.prm.uuid]['sclk_pstate'][ps]['gtk_ent_f_obj_unit'], False, False, 0)
grid.attach(lbox, col, row, 1, 1)
row += 1
if gpu.get_params_value('gpu_type') in (GpuType.CurvePts, GpuType.Offset, GpuType.PStates):
# SCLK P-State Mask
devices[gpu.prm.uuid]['sclk_pst_mask_cur'] = Gtk.Label(name='white_label')
set_gtk_prop(devices[gpu.prm.uuid]['sclk_pst_mask_cur'], top=1, bottom=1, right=2, left=2)
devices[gpu.prm.uuid]['sclk_pst_mask_ent'] = Gtk.Entry()
set_gtk_prop(devices[gpu.prm.uuid]['sclk_pst_mask_ent'], width_chars=17, max_length=17,
xalign=0, top=1, bottom=1, right=0, left=1)
lbox = Gtk.Box(spacing=2, name='med_box')
set_gtk_prop(lbox, top=1, bottom=1, right=1, left=1)
lbox.pack_start(devices[gpu.prm.uuid]['sclk_pst_mask_cur'], False, False, 0)
lbox.pack_start(devices[gpu.prm.uuid]['sclk_pst_mask_ent'], False, False, 0)
grid.attach(lbox, col, row, 1, 1)
row += 1
if gpu.get_params_value('gpu_type') == GpuType.PStates:
# Mclk P-States
devices[gpu.prm.uuid]['mclk_range'] = Gtk.Label(name='white_label')
devices[gpu.prm.uuid]['mclk_range'].set_markup('<b>Mclk P-States: </b> Ranges {}-{}, {}-{} '.format(
gpu.get_params_value('mclk_f_range')[0],
gpu.get_params_value('mclk_f_range')[1],
gpu.get_params_value('vddc_range')[0],
gpu.get_params_value('vddc_range')[1]))
set_gtk_prop(devices[gpu.prm.uuid]['mclk_range'], top=1, bottom=1, right=4, left=4, align=(0.0, 0.5))
lbox = Gtk.Box(spacing=6, name='dark_box')
set_gtk_prop(lbox, top=1, bottom=1, right=1, left=1)
lbox.pack_start(devices[gpu.prm.uuid]['mclk_range'], True, True, 0)
grid.attach(lbox, col, row, 1, 1)
row += 1
# Mclk P-State Values and Entry
devices[gpu.prm.uuid]['mclk_pstate'] = {}
for ps in gpu.mclk_state.keys():
devices[gpu.prm.uuid]['mclk_pstate'][ps] = {}
devices[gpu.prm.uuid]['mclk_pstate'][ps]['gtk_cur_obj'] = Gtk.Label(name='white_label')
set_gtk_prop(devices[gpu.prm.uuid]['mclk_pstate'][ps]['gtk_cur_obj'], width_chars=20,
top=1, bottom=1, right=2, left=2, align=(0.0, 0.5))
devices[gpu.prm.uuid]['mclk_pstate'][ps]['gtk_ent_f_obj'] = Gtk.Entry()
set_gtk_prop(devices[gpu.prm.uuid]['mclk_pstate'][ps]['gtk_ent_f_obj'], width_chars=5, max_length=5,
xalign=1, top=1, bottom=1, right=0, left=0)
devices[gpu.prm.uuid]['mclk_pstate'][ps]['gtk_ent_f_obj_unit'] = Gtk.Label(name='white_label')
set_gtk_prop(devices[gpu.prm.uuid]['mclk_pstate'][ps]['gtk_ent_f_obj_unit'],
top=1, bottom=1, right=4, left=0, align=(0.0, 0.5))
devices[gpu.prm.uuid]['mclk_pstate'][ps]['gtk_ent_v_obj'] = Gtk.Entry()
set_gtk_prop(devices[gpu.prm.uuid]['mclk_pstate'][ps]['gtk_ent_v_obj'], width_chars=5, max_length=5,
xalign=1, top=1, bottom=1, right=0, left=0)
devices[gpu.prm.uuid]['mclk_pstate'][ps]['gtk_ent_v_obj_unit'] = Gtk.Label(name='white_label')
set_gtk_prop(devices[gpu.prm.uuid]['mclk_pstate'][ps]['gtk_ent_v_obj_unit'],
top=1, bottom=1, right=4, left=0, align=(0.0, 0.5))
lbox = Gtk.Box(spacing=6, name='med_box')
set_gtk_prop(lbox, top=1, bottom=1, right=1, left=1)
lbox.pack_start(devices[gpu.prm.uuid]['mclk_pstate'][ps]['gtk_cur_obj'], False, False, 0)
lbox.pack_start(devices[gpu.prm.uuid]['mclk_pstate'][ps]['gtk_ent_f_obj'], False, False, 0)
lbox.pack_start(devices[gpu.prm.uuid]['mclk_pstate'][ps]['gtk_ent_f_obj_unit'], False, False, 0)
lbox.pack_start(devices[gpu.prm.uuid]['mclk_pstate'][ps]['gtk_ent_v_obj'], False, False, 0)
lbox.pack_start(devices[gpu.prm.uuid]['mclk_pstate'][ps]['gtk_ent_v_obj_unit'], False, False, 0)
grid.attach(lbox, col, row, 1, 1)
row += 1
elif gpu.get_params_value('gpu_type') in (GpuType.CurvePts, GpuType.Offset):
# Mclk Curve End points
devices[gpu.prm.uuid]['mclk_range'] = Gtk.Label(name='white_label')
devices[gpu.prm.uuid]['mclk_range'].set_markup('<b>Mclk Curve End Points: </b> Ranges {}-{} '.format(
gpu.get_params_value('mclk_f_range')[0],
gpu.get_params_value('mclk_f_range')[1]))
set_gtk_prop(devices[gpu.prm.uuid]['mclk_range'], top=1, bottom=1, right=4, left=4, align=(0.0, 0.5))
lbox = Gtk.Box(spacing=6, name='dark_box')
set_gtk_prop(lbox, top=1, bottom=1, right=1, left=1)
lbox.pack_start(devices[gpu.prm.uuid]['mclk_range'], True, True, 0)
grid.attach(lbox, col, row, 1, 1)
row += 1
# Mclk Curve End Points Values and Entry
devices[gpu.prm.uuid]['mclk_pstate'] = {}
for ps in gpu.mclk_state.keys():
devices[gpu.prm.uuid]['mclk_pstate'][ps] = {}
devices[gpu.prm.uuid]['mclk_pstate'][ps]['gtk_cur_obj'] = Gtk.Label(name='white_label')
set_gtk_prop(devices[gpu.prm.uuid]['mclk_pstate'][ps]['gtk_cur_obj'], width_chars=20,
top=1, bottom=1, right=2, left=2, align=(0.0, 0.5))
devices[gpu.prm.uuid]['mclk_pstate'][ps]['gtk_ent_f_obj'] = Gtk.Entry()
set_gtk_prop(devices[gpu.prm.uuid]['mclk_pstate'][ps]['gtk_ent_f_obj'], width_chars=5, max_length=5,
xalign=1, top=1, bottom=1, right=0, left=0)
devices[gpu.prm.uuid]['mclk_pstate'][ps]['gtk_ent_f_obj_unit'] = Gtk.Label(name='white_label')
set_gtk_prop(devices[gpu.prm.uuid]['mclk_pstate'][ps]['gtk_ent_f_obj_unit'],
top=1, bottom=1, right=4, left=0, align=(0.0, 0.5))
lbox = Gtk.Box(spacing=6, name='med_box')
set_gtk_prop(lbox, top=1, bottom=1, right=1, left=1)
lbox.pack_start(devices[gpu.prm.uuid]['mclk_pstate'][ps]['gtk_cur_obj'], False, False, 0)
lbox.pack_start(devices[gpu.prm.uuid]['mclk_pstate'][ps]['gtk_ent_f_obj'], False, False, 0)
lbox.pack_start(devices[gpu.prm.uuid]['mclk_pstate'][ps]['gtk_ent_f_obj_unit'], False, False, 0)
grid.attach(lbox, col, row, 1, 1)
row += 1
if gpu.get_params_value('gpu_type') in (GpuType.CurvePts, GpuType.Offset, GpuType.PStates):
# MCLK P-State Mask
devices[gpu.prm.uuid]['mclk_pst_mask_cur'] = Gtk.Label(name='white_label')
set_gtk_prop(devices[gpu.prm.uuid]['mclk_pst_mask_cur'], top=1, bottom=1, right=2, left=2)
devices[gpu.prm.uuid]['mclk_pst_mask_ent'] = Gtk.Entry()
set_gtk_prop(devices[gpu.prm.uuid]['mclk_pst_mask_ent'], width_chars=17, max_length=17,
xalign=0, top=1, bottom=1, right=0, left=1)
lbox = Gtk.Box(spacing=2, name='med_box')
set_gtk_prop(lbox, top=1, bottom=1, right=1, left=1)
lbox.pack_start(devices[gpu.prm.uuid]['mclk_pst_mask_cur'], False, False, 0)
lbox.pack_start(devices[gpu.prm.uuid]['mclk_pst_mask_ent'], False, False, 0)
grid.attach(lbox, col, row, 1, 1)
row += 1
if gpu.get_params_value('gpu_type') == GpuType.Offset:
# VDDGFX OFFSET
devices[gpu.prm.uuid]['vddgfx_offset'] = Gtk.Label(name='white_label')
devices[gpu.prm.uuid]['vddgfx_offset'].set_markup('<b>VddGFX Offset: </b> Range ({} to {} mv)'.format(
gpu.prm.vddgfx_offset_range[0], gpu.prm.vddgfx_offset_range[1]))
set_gtk_prop(devices[gpu.prm.uuid]['vddgfx_offset'], align=(0.0, 0.5), top=1, bottom=1, right=4, left=4)
lbox = Gtk.Box(spacing=6, name='dark_box')
set_gtk_prop(lbox, top=1, bottom=1, right=1, left=1)
lbox.pack_start(devices[gpu.prm.uuid]['vddgfx_offset'], True, True, 0)
grid.attach(lbox, col, row, 1, 1)
row += 1
# VDDGFX Offset Value and Entry
devices[gpu.prm.uuid]['vddgfx_offset_cur'] = Gtk.Label(name='white_label')
set_gtk_prop(devices[gpu.prm.uuid]['vddgfx_offset_cur'], top=1, bottom=1, right=2, left=2)
devices[gpu.prm.uuid]['vddgfx_offset_ent'] = Gtk.Entry()
set_gtk_prop(devices[gpu.prm.uuid]['vddgfx_offset_ent'], top=1, bottom=1, right=0, left=2, xalign=1,
width_chars=5, max_length=5)
devices[gpu.prm.uuid]['vddgfx_offset_ent_unit'] = Gtk.Label(name='white_label')
devices[gpu.prm.uuid]['vddgfx_offset_ent_unit'].set_text('mV (value)')
set_gtk_prop(devices[gpu.prm.uuid]['vddgfx_offset_ent_unit'], top=1, bottom=1, right=0, left=0,
align=(0.0, 0.5))
lbox = Gtk.Box(spacing=2, name='med_box')
set_gtk_prop(lbox, top=1, bottom=1, right=1, left=1)
lbox.pack_start(devices[gpu.prm.uuid]['vddgfx_offset_cur'], False, False, 0)
lbox.pack_start(devices[gpu.prm.uuid]['vddgfx_offset_ent'], False, False, 0)
lbox.pack_start(devices[gpu.prm.uuid]['vddgfx_offset_ent_unit'], False, False, 0)
grid.attach(lbox, col, row, 1, 1)
row += 1
if gpu.get_params_value('gpu_type') == GpuType.CurvePts:
# VDDC Curve Points
devices[gpu.prm.uuid]['vddc_curve_range'] = Gtk.Label(name='white_label')
devices[gpu.prm.uuid]['vddc_curve_range'].set_markup(
'<b>VDDC Curve Points: </b> Ranges {}-{}, {}-{} '.format(gpu.vddc_curve_range[0]['SCLK'][0],
gpu.vddc_curve_range[0]['SCLK'][1],
gpu.prm.vddc_range[0],
gpu.prm.vddc_range[1]))
set_gtk_prop(devices[gpu.prm.uuid]['vddc_curve_range'], top=1, bottom=1,
right=4, left=4, align=(0.0, 0.5))
lbox = Gtk.Box(spacing=6, name='dark_box')
set_gtk_prop(lbox, top=1, bottom=1, right=1, left=1)
lbox.pack_start(devices[gpu.prm.uuid]['vddc_curve_range'], False, False, 0)
grid.attach(lbox, col, row, 1, 1)
row += 1
# VDDC CURVE Points Values and Entry
devices[gpu.prm.uuid]['vddc_curve_pt'] = {}
for ps in gpu.vddc_curve.keys():
devices[gpu.prm.uuid]['vddc_curve_pt'][ps] = {}
devices[gpu.prm.uuid]['vddc_curve_pt'][ps]['gtk_cur_obj'] = Gtk.Label(name='white_label')
set_gtk_prop(devices[gpu.prm.uuid]['vddc_curve_pt'][ps]['gtk_cur_obj'], width_chars=20,
top=1, bottom=1, right=2, left=2, align=(0.0, 0.5))
devices[gpu.prm.uuid]['vddc_curve_pt'][ps]['gtk_ent_f_obj'] = Gtk.Entry()
set_gtk_prop(devices[gpu.prm.uuid]['vddc_curve_pt'][ps]['gtk_ent_f_obj'], width_chars=5,
max_length=5, xalign=1, top=1, bottom=1, right=0, left=0)
devices[gpu.prm.uuid]['vddc_curve_pt'][ps]['gtk_ent_f_obj_unit'] = Gtk.Label(name='white_label')
set_gtk_prop(devices[gpu.prm.uuid]['vddc_curve_pt'][ps]['gtk_ent_f_obj_unit'],
top=1, bottom=1, right=4, left=0, align=(0.0, 0.5))
devices[gpu.prm.uuid]['vddc_curve_pt'][ps]['gtk_ent_v_obj'] = Gtk.Entry()
set_gtk_prop(devices[gpu.prm.uuid]['vddc_curve_pt'][ps]['gtk_ent_v_obj'], width_chars=5,
max_length=5, xalign=1, top=1, bottom=1, right=0, left=0)
devices[gpu.prm.uuid]['vddc_curve_pt'][ps]['gtk_ent_v_obj_unit'] = Gtk.Label(name='white_label')
set_gtk_prop(devices[gpu.prm.uuid]['vddc_curve_pt'][ps]['gtk_ent_v_obj_unit'],
top=1, bottom=1, right=4, left=0, align=(0.0, 0.5))
lbox = Gtk.Box(spacing=6, name='med_box')
set_gtk_prop(lbox, top=1, bottom=1, right=1, left=1)
lbox.pack_start(devices[gpu.prm.uuid]['vddc_curve_pt'][ps]['gtk_cur_obj'], False, False, 0)
lbox.pack_start(devices[gpu.prm.uuid]['vddc_curve_pt'][ps]['gtk_ent_f_obj'], False, False, 0)
lbox.pack_start(devices[gpu.prm.uuid]['vddc_curve_pt'][ps]['gtk_ent_f_obj_unit'], False, False, 0)
lbox.pack_start(devices[gpu.prm.uuid]['vddc_curve_pt'][ps]['gtk_ent_v_obj'], False, False, 0)
lbox.pack_start(devices[gpu.prm.uuid]['vddc_curve_pt'][ps]['gtk_ent_v_obj_unit'], False, False, 0)
grid.attach(lbox, col, row, 1, 1)
row += 1
# Power Performance Mode Selection
devices[gpu.prm.uuid]['ppm'] = Gtk.Label(name='white_label')
devices[gpu.prm.uuid]['ppm'].set_markup('<b>Power Performance Modes:</b>')
set_gtk_prop(devices[gpu.prm.uuid]['ppm'], top=1, bottom=1, right=4, left=4, align=(0.0, 0.5))
lbox = Gtk.Box(spacing=6, name='dark_box')
set_gtk_prop(lbox, top=1, bottom=1, right=1, left=1)
lbox.pack_start(devices[gpu.prm.uuid]['ppm'], True, True, 0)
grid.attach(lbox, col, row, 1, 1)
row += 1
devices[gpu.prm.uuid]['ppm_modes'] = Gtk.ListStore(int, str)
devices[gpu.prm.uuid]['ppm_mode_items'] = {}
item_num = 0
for mode_num, mode in gpu.ppm_modes.items():
if mode_num == 'NUM':
continue
if mode[0] == 'CUSTOM':
continue
devices[gpu.prm.uuid]['ppm_modes'].append([int(mode_num), mode[0]])
devices[gpu.prm.uuid]['ppm_mode_items'][int(mode_num)] = item_num
item_num += 1
lbox = Gtk.Box(spacing=6, name='med_box')
set_gtk_prop(lbox, top=1, bottom=1, right=1, left=1)
devices[gpu.prm.uuid]['ppm_selection'] = Gtk.Label(name='white_label')
devices[gpu.prm.uuid]['ppm_selection'].set_markup(' PPM Selection: ')
set_gtk_prop(devices[gpu.prm.uuid]['ppm_selection'], top=1, bottom=1, right=4, left=4, align=(0.0, 0.5))
devices[gpu.prm.uuid]['ppm_modes_combo'] = Gtk.ComboBox.new_with_model_and_entry(
devices[gpu.prm.uuid]['ppm_modes'])
devices[gpu.prm.uuid]['ppm_modes_combo'].get_child().set_name('ppm_combo')
devices[gpu.prm.uuid]['ppm_modes_combo'].connect('changed', ppm_select, devices[gpu.prm.uuid])
devices[gpu.prm.uuid]['ppm_modes_combo'].set_entry_text_column(1)
lbox.pack_start(devices[gpu.prm.uuid]['ppm_selection'], False, False, 0)
lbox.pack_start(devices[gpu.prm.uuid]['ppm_modes_combo'], False, False, 0)
grid.attach(lbox, col, row, 1, 1)
row += 1
# Save/Reset Card Buttons
devices[gpu.prm.uuid]['save_button'] = Gtk.Button(label='')
for child in devices[gpu.prm.uuid]['save_button'].get_children():
child.set_label('<big><b>Save</b></big>')
child.set_use_markup(True)
devices[gpu.prm.uuid]['save_button'].connect('clicked', self.save_card, gpu_list, devices, gpu.prm.uuid)
set_gtk_prop(devices[gpu.prm.uuid]['save_button'], width=90)
devices[gpu.prm.uuid]['reset_button'] = Gtk.Button(label='')
for child in devices[gpu.prm.uuid]['reset_button'].get_children():
child.set_label('<big><b>Reset</b></big>')
child.set_use_markup(True)
devices[gpu.prm.uuid]['reset_button'].connect('clicked', self.reset_card, gpu_list, devices, gpu.prm.uuid)
set_gtk_prop(devices[gpu.prm.uuid]['reset_button'], width=90)
lbox = Gtk.Box(spacing=6)
lbox.set_name('button_box')
set_gtk_prop(lbox, top=1, bottom=1, right=1, left=1)
lbox.pack_start(devices[gpu.prm.uuid]['save_button'], True, False, 0)
lbox.pack_start(devices[gpu.prm.uuid]['reset_button'], True, False, 0)
grid.attach(lbox, col, row, 1, 1)
row += 1
# Increment column before going to next Device
max_rows = max(max_rows, row)
col += 1
# End of for v in values
# Setup the Save_ALL and Reset_ALL buttons
if num_com_gpus > 1:
# Save/Reset/Update ALL Card Buttons
devices['all_buttons'] = {}
devices['all_buttons']['save_all_button'] = Gtk.Button(label='')
for child in devices['all_buttons']['save_all_button'].get_children():
child.set_label('<big><b>Save All</b></big>')
child.set_use_markup(True)
devices['all_buttons']['save_all_button'].connect('clicked', self.save_all_cards, gpu_list, devices)
set_gtk_prop(devices['all_buttons']['save_all_button'], width=100)
devices['all_buttons']['reset_all_button'] = Gtk.Button(label='')
for child in devices['all_buttons']['reset_all_button'].get_children():
child.set_label('<big><b>Reset All</b></big>')
child.set_use_markup(True)
devices['all_buttons']['reset_all_button'].connect('clicked', self.reset_all_cards, gpu_list, devices)
set_gtk_prop(devices['all_buttons']['reset_all_button'], width=100)
devices['all_buttons']['refresh_all_button'] = Gtk.Button(label='')
for child in devices['all_buttons']['refresh_all_button'].get_children():
child.set_label('<big><b>Refresh All</b></big>')
child.set_use_markup(True)
devices['all_buttons']['refresh_all_button'].connect('clicked', self.refresh_all_cards, gpu_list,
devices, True)
set_gtk_prop(devices['all_buttons']['refresh_all_button'], width=100)
lbox = Gtk.Box(spacing=6)
lbox.set_name('button_box')
set_gtk_prop(lbox, top=1, bottom=1, right=1, left=1)
lbox.pack_start(devices['all_buttons']['save_all_button'], True, False, 0)
lbox.pack_start(devices['all_buttons']['reset_all_button'], True, False, 0)
lbox.pack_start(devices['all_buttons']['refresh_all_button'], True, False, 0)
grid.attach(lbox, 0, max_rows, col, 1)
row += 1
max_rows += 1
# Initialize message box
devices['message_label'] = Gtk.Label(name='message_label')
devices['message_label'].set_line_wrap(True)
set_gtk_prop(devices['message_label'], width_max=num_com_gpus * MAX_CHAR,
align=(0.0, 0.5), width=num_com_gpus * MAX_CHAR * CHAR_WIDTH)
devices['message_label'].set_line_wrap(True)
devices['message_box'] = Gtk.Box(spacing=6)
devices['message_box'].set_name('message_box')
set_gtk_prop(devices['message_box'], top=1, bottom=1, right=1, left=1)
devices['message_box'].pack_start(devices['message_label'], True, True, 1)
grid.attach(devices['message_box'], 0, max_rows, col, 1)
row += 1
self.update_message(devices, '', 'gray')
self.refresh_pac(gpu_list, devices)
self.show_all()
grid_rectangle = grid.get_allocation()
LOGGER.debug('Grid alloc: x: %s, y: %s, width: %s, height: %s',
grid_rectangle.x, grid_rectangle.y, grid_rectangle.width, grid_rectangle.height)
self.resize(grid_rectangle.width + 8, grid_rectangle.height + 8)
@staticmethod
def update_message(devices: dict, message: str, color: str = 'gray') -> None:
"""
Set PAC message using default message if no message specified.
:param devices: Dictionary of GUI items and GPU data.
:param message: Message as a string.
:param color: Valid color strings: gray, yellow, white, red
"""
if message == '':
if GUT_CONST.execute_pac:
message = ('Using the --execute_pac option. Changes will be written to the GPU without '
'confirmation.\nSudo will be used, so you may be prompted for credentials in '
'the window where gpu-pac was executed from.')
else:
message = ('Using gpu-pac without --execute_pac option.\nYou must manually run bash '
'file with sudo to execute changes.')
if color == 'red':
GPUgui.GuiProps.set_style(css_str="#message_label { color: %s; }" %
GPUgui.GuiProps.color_name_to_hex('white_off'))
GPUgui.GuiProps.set_style(css_str="#message_box { background-image: image(%s); }" %
GPUgui.GuiProps.color_name_to_hex('red'))
elif color == 'yellow':
GPUgui.GuiProps.set_style(css_str="#message_label { color: %s; }" %
GPUgui.GuiProps.color_name_to_hex('white_off'))
GPUgui.GuiProps.set_style(css_str="#message_box { background-image: image(%s); }" %
GPUgui.GuiProps.color_name_to_hex('yellow'))
elif color == 'white':
GPUgui.GuiProps.set_style(css_str="#message_label { color: %s; }" %
GPUgui.GuiProps.color_name_to_hex('gray95'))
GPUgui.GuiProps.set_style(css_str="#message_box { background-image: image(%s); }" %
GPUgui.GuiProps.color_name_to_hex('gray20'))
else:
GPUgui.GuiProps.set_style(css_str="#message_label { color: %s; }" %
GPUgui.GuiProps.color_name_to_hex('white_off'))
GPUgui.GuiProps.set_style(css_str="#message_box { background-image: image(%s); }" %
GPUgui.GuiProps.color_name_to_hex('gray50'))
devices['message_label'].set_text(message)
while Gtk.events_pending():
Gtk.main_iteration_do(True)
def refresh_all_cards(self, _, gpu_list: Gpu.GpuList, devices: dict, reset_message: bool = False) -> None:
"""
Refresh all cards by calling card level refresh.
:param _: parent not used
:param gpu_list:
:param devices: Dictionary of GUI items and GPU data.
:param reset_message:
"""
self.refresh_pac(gpu_list, devices, reset_message)
def refresh_pac(self, gpu_list: Gpu.GpuList, devices: dict, refresh_message: bool = False) -> None:
"""
Update device data from gpuList data.
:param gpu_list: gpuList of all gpuItems
:param devices: Dictionary of GUI items and GPU data.
:param refresh_message:
"""
# Read sensor and state data from GPUs
gpu_list.read_gpu_sensor_set(data_type=SensorSet.All)
# Read pstate and ppm table data
gpu_list.read_gpu_pstates()
gpu_list.read_gpu_ppm_table()
for gpu in gpu_list.gpus():
devices[gpu.prm.uuid]['power_cap_cur'].set_text(' Current: {:3d}W Set: '.format(
gpu.get_params_value('power_cap', num_as_int=True)))
devices[gpu.prm.uuid]['power_cap_ent'].set_text(str(gpu.get_params_value('power_cap', num_as_int=True)))
if gpu.get_params_value('gpu_type') == GpuType.Offset:
devices[gpu.prm.uuid]['vddgfx_offset_cur'].set_text(' Current: {:3d}mV Set: '.format(
gpu.get_params_value('vddgfx_offset', num_as_int=True)))
devices[gpu.prm.uuid]['vddgfx_offset_ent'].set_text(
str(gpu.get_params_value('vddgfx_offset', num_as_int=True)))
if GUT_CONST.show_fans:
devices[gpu.prm.uuid]['fan_pwm_cur'].set_text(' Current: {:3d}% Set: '.format(
gpu.get_params_value('fan_pwm', num_as_int=True)))
devices[gpu.prm.uuid]['fan_pwm_ent'].set_text(str(gpu.get_params_value('fan_pwm', num_as_int=True)))
LOGGER.debug('Refresh got current pwm speed: %s', devices[gpu.prm.uuid]['fan_pwm_ent'].get_text())
# SCLK
if gpu.get_params_value('gpu_type') in (GpuType.PStates, ):
for ps, psd in gpu.sclk_state.items():
devices[gpu.prm.uuid]['sclk_pstate'][ps]['gtk_cur_obj'].set_text(' {}: {}, {}'.format(ps, *psd))
item_value = re.sub(PATTERNS[PK.END_IN_ALPHA], '', str(psd[0]))
item_unit = re.sub(PATTERNS[PK.IS_FLOAT], '', str(psd[0]))
devices[gpu.prm.uuid]['sclk_pstate'][ps]['gtk_ent_f_obj'].set_text(item_value)
devices[gpu.prm.uuid]['sclk_pstate'][ps]['gtk_ent_f_obj_unit'].set_text(item_unit + ' ')
item_value = re.sub(PATTERNS[PK.END_IN_ALPHA], '', str(psd[1]))
item_unit = re.sub(PATTERNS[PK.IS_FLOAT], '', str(psd[1]))
devices[gpu.prm.uuid]['sclk_pstate'][ps]['gtk_ent_v_obj'].set_text(str(item_value))
devices[gpu.prm.uuid]['sclk_pstate'][ps]['gtk_ent_v_obj_unit'].set_text(item_unit)
devices[gpu.prm.uuid]['sclk_pst_mask_cur'].set_text(
' SCLK Default: {} Set Mask: '.format(gpu.prm.sclk_mask))
devices[gpu.prm.uuid]['sclk_pst_mask_ent'].set_text(gpu.prm.sclk_mask)
elif gpu.get_params_value('gpu_type') in (GpuType.CurvePts, GpuType.Offset):
for ps, psd in gpu.sclk_state.items():
devices[gpu.prm.uuid]['sclk_pstate'][ps]['gtk_cur_obj'].set_text(' {}: {}'.format(ps, psd[0]))
item_value = re.sub(PATTERNS[PK.END_IN_ALPHA], '', str(psd[0]))
item_unit = re.sub(PATTERNS[PK.IS_FLOAT], '', str(psd[0]))
devices[gpu.prm.uuid]['sclk_pstate'][ps]['gtk_ent_f_obj'].set_text(item_value)
devices[gpu.prm.uuid]['sclk_pstate'][ps]['gtk_ent_f_obj_unit'].set_text(item_unit + ' ')
devices[gpu.prm.uuid]['sclk_pst_mask_cur'].set_text(
' SCLK Default: {} Set Mask: '.format(gpu.prm.sclk_mask))
devices[gpu.prm.uuid]['sclk_pst_mask_ent'].set_text(gpu.prm.sclk_mask)
# MCLK
if gpu.get_params_value('gpu_type') in (GpuType.PStates, ):
for ps, psd in gpu.mclk_state.items():
devices[gpu.prm.uuid]['mclk_pstate'][ps]['gtk_cur_obj'].set_text(' {}: {}, {}'.format(ps, *psd))
item_value = re.sub(PATTERNS[PK.END_IN_ALPHA], '', str(psd[0]))
item_unit = re.sub(PATTERNS[PK.IS_FLOAT], '', str(psd[0]))
devices[gpu.prm.uuid]['mclk_pstate'][ps]['gtk_ent_f_obj'].set_text(item_value)
devices[gpu.prm.uuid]['mclk_pstate'][ps]['gtk_ent_f_obj_unit'].set_text(item_unit + ' ')
item_value = re.sub(PATTERNS[PK.END_IN_ALPHA], '', str(psd[1]))
item_unit = re.sub(PATTERNS[PK.IS_FLOAT], '', str(psd[1]))
devices[gpu.prm.uuid]['mclk_pstate'][ps]['gtk_ent_v_obj'].set_text(str(item_value))
devices[gpu.prm.uuid]['mclk_pstate'][ps]['gtk_ent_v_obj_unit'].set_text(item_unit)
devices[gpu.prm.uuid]['mclk_pst_mask_cur'].set_text(
' MCLK Default: {} Set Mask: '.format(gpu.prm.mclk_mask))
devices[gpu.prm.uuid]['mclk_pst_mask_ent'].set_text(gpu.prm.mclk_mask)
elif gpu.get_params_value('gpu_type') in (GpuType.CurvePts, GpuType.Offset):
for ps, psd in gpu.mclk_state.items():
devices[gpu.prm.uuid]['mclk_pstate'][ps]['gtk_cur_obj'].set_text(' {}: {}'.format(ps, psd[0]))
item_value = re.sub(PATTERNS[PK.END_IN_ALPHA], '', str(psd[0]))
item_unit = re.sub(PATTERNS[PK.IS_FLOAT], '', str(psd[0]))
devices[gpu.prm.uuid]['mclk_pstate'][ps]['gtk_ent_f_obj'].set_text(item_value)
devices[gpu.prm.uuid]['mclk_pstate'][ps]['gtk_ent_f_obj_unit'].set_text(item_unit + ' ')
devices[gpu.prm.uuid]['mclk_pst_mask_cur'].set_text(
' MCLK Default: {} Set Mask: '.format(gpu.prm.mclk_mask))
devices[gpu.prm.uuid]['mclk_pst_mask_ent'].set_text(gpu.prm.mclk_mask)
# VDDC CURVE
if gpu.get_params_value('gpu_type') == GpuType.CurvePts:
for ps, psd in gpu.vddc_curve.items():
devices[gpu.prm.uuid]['vddc_curve_pt'][ps]['gtk_cur_obj'].set_text(' {}: {}, {}'.format(ps, *psd))
item_value = re.sub(PATTERNS[PK.END_IN_ALPHA], '', str(psd[0]))
item_unit = re.sub(PATTERNS[PK.IS_FLOAT], '', str(psd[0]))
devices[gpu.prm.uuid]['vddc_curve_pt'][ps]['gtk_ent_f_obj'].set_text(item_value)
devices[gpu.prm.uuid]['vddc_curve_pt'][ps]['gtk_ent_f_obj_unit'].set_text(item_unit + ' ')
item_value = re.sub(PATTERNS[PK.END_IN_ALPHA], '', str(psd[1]))
item_unit = re.sub(PATTERNS[PK.IS_FLOAT], '', str(psd[1]))
devices[gpu.prm.uuid]['vddc_curve_pt'][ps]['gtk_ent_v_obj'].set_text(str(item_value))
devices[gpu.prm.uuid]['vddc_curve_pt'][ps]['gtk_ent_v_obj_unit'].set_text(item_unit)
# refresh active mode item
devices[gpu.prm.uuid]['ppm_modes_combo'].set_active(
devices[gpu.prm.uuid]['ppm_mode_items'][gpu.get_current_ppm_mode()[0]])
if refresh_message:
self.update_message(devices, 'Refresh complete.\n', 'gray')
while Gtk.events_pending():
Gtk.main_iteration_do(True)
def save_all_cards(self, parent, gpu_list: Gpu.GpuList, devices: dict) -> None:
"""
Save modified data for all GPUs.
:param parent: parent
:param gpu_list:
:param devices: Dictionary of GUI items and GPU data.
"""
changed = 0
# Write start message
if GUT_CONST.execute_pac:
message = ('Using the --execute_pac option. Changes will be written to the GPU without '
'confirmation.\nSudo will be used, so you may be prompted for credentials in '
'the window where gpu-pac was executed from.')
else:
message = 'Writing PAC command bash file.\n'
self.update_message(devices, message, 'red')
# save each card
for uuid in gpu_list.uuids():
changed += self.save_card(parent, gpu_list, devices, uuid, refresh=False)
# Write finish message
sleep(1.0)
if GUT_CONST.execute_pac:
if changed:
message = ('Write {} PAC commands to card complete.\n'
'Confirm changes with gpu-mon.').format(changed)
else:
message = 'No PAC commands to write to card.\nNo changes specified.'
else:
if changed:
message = ('Writing {} PAC commands to bash file complete.\n'
'Run bash file with sudo to execute changes.').format(changed)
else:
message = 'No PAC commands to write to bash file.\nNo changes specified.'
self.update_message(devices, message, 'yellow')
self.refresh_all_cards(parent, gpu_list, devices)
def save_card(self, _, gpu_list: Gpu.GpuList, devices: dict, uuid: str, refresh: bool = True) -> None:
"""
Save modified data for specified GPU.
:param _: parent not used
:param gpu_list:
:param devices: Dictionary of GUI items and GPU data.
:param uuid: GPU device ID
:param refresh: Flag to indicate if refresh should be done
"""
if refresh:
# Write message
if GUT_CONST.execute_pac:
message = ('Using the --execute_pac option. Changes will be written to the GPU '
'without confirmation.\nSudo will be used, so you may be prompted for '
'credentials in the window where gpu-pac was executed from.')
else:
message = 'Writing PAC commands to bash file.\n'
self.update_message(devices, message, 'red')
# Specify output batch file name
out_filename = os.path.join(os.getcwd(), 'pac_writer_{}.sh'.format(uuid4().hex))
fileptr = open(out_filename, mode='x', encoding='utf-8')
# Output header
print('#!/bin/sh', file=fileptr)
print('###########################################################################', file=fileptr)
print('## rickslab-gpu-pac generated script to modify GPU configuration/settings', file=fileptr)
print('###########################################################################', file=fileptr)
print('', file=fileptr)
print('###########################################################################', file=fileptr)
print('## WARNING - Do not execute this script without completely', file=fileptr)
print('## understanding appropriate values to write to your specific GPUs', file=fileptr)
print('###########################################################################', file=fileptr)
print('#', file=fileptr)
print('# Copyright (C) 2019 RueiKe', file=fileptr)
print('#', file=fileptr)
print('# This program is free software: you can redistribute it and/or modify', file=fileptr)
print('# it under the terms of the GNU General Public License as published by', file=fileptr)
print('# the Free Software Foundation, either version 3 of the License, or', file=fileptr)
print('# (at your option) any later version.', file=fileptr)
print('#', file=fileptr)
print('# This program is distributed in the hope that it will be useful,', file=fileptr)
print('# but WITHOUT ANY WARRANTY; without even the implied warranty of', file=fileptr)
print('# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the', file=fileptr)
print('# GNU General Public License for more details.', file=fileptr)
print('#', file=fileptr)
print('# You should have received a copy of the GNU General Public License', file=fileptr)
print('# along with this program. If not, see <https://www.gnu.org/licenses/>.', file=fileptr)
print('###########################################################################', file=fileptr)
changed = 0
gpu = gpu_list[uuid]
print('# ', file=fileptr)
print('# Card{} Model: {}'.format(gpu.prm.card_num, gpu.get_params_value('model')), file=fileptr)
print('# Type: {}'.format(gpu.prm.gpu_type), file=fileptr)
print('# Path: {}'.format(gpu.prm.card_path), file=fileptr)
if not GUT_CONST.write_delta_only:
print('# Force Write mode.')
else:
print('# Write Delta mode.')
print('# ', file=fileptr)
print('set -x', file=fileptr)
# Check/set power_dpm_force_performance_level
# Mode of manual required to change ppm or clock masks
curr_power_dpm_force = gpu.get_params_value('power_dpm_force').lower()
if curr_power_dpm_force == 'manual' and GUT_CONST.write_delta_only:
print('# Power DPM Force Performance Level: already [{}], skipping.'.format(curr_power_dpm_force),
file=fileptr)
else:
power_dpm_force_file = os.path.join(gpu.prm.card_path, 'power_dpm_force_performance_level')
print('# Power DPM Force Performance Level: [{}] change to [manual]'.format(curr_power_dpm_force),
file=fileptr)
print("sudo sh -c \"echo \'manual\' > {}\"".format(power_dpm_force_file), file=fileptr)
# Power Cap
power_cap_file = os.path.join(gpu.prm.hwmon_path, 'power1_cap')
old_power_cap = gpu.get_params_value('power_cap', num_as_int=True)
new_power_cap_str = devices[uuid]['power_cap_ent'].get_text()
if new_power_cap_str.lower() == 'reset':
changed += 1
print('# Powercap entry: {}, Resetting to default'.format(new_power_cap_str), file=fileptr)
print("sudo sh -c \"echo \'0\' > {}\"".format(power_cap_file), file=fileptr)
elif re.fullmatch(PATTERNS[PK.DIGITS], new_power_cap_str):
new_power_cap = int(new_power_cap_str)
power_cap_range = gpu.get_params_value('power_cap_range')
print('# Powercap Old: {}'.format(old_power_cap), end='', file=fileptr)
print(' New: {}'.format(new_power_cap), end='', file=fileptr)
print(' Min: {}'.format(power_cap_range[0]), end='', file=fileptr)
print(' Max: {}\n'.format(power_cap_range[1]), end='', file=fileptr)
if new_power_cap == old_power_cap and GUT_CONST.write_delta_only:
print('# No Powercap changes, skipped', file=fileptr)
else:
if gpu.is_valid_power_cap(new_power_cap):
changed += 1
print("sudo sh -c \"echo \'{}\' > {}\"".format((int(1000000 * new_power_cap)), power_cap_file),
file=fileptr)
else:
print('# Invalid power_cap parameter values', file=fileptr)
print('Invalid power_cap parameter values')
else:
print('# Powercap New: {}, invalid input, ignoring'.format(new_power_cap_str), file=fileptr)
new_power_cap = old_power_cap
if GUT_CONST.show_fans:
# Fan PWM
pwm_enable_file = os.path.join(gpu.prm.hwmon_path, 'pwm1_enable')
pwm_file = os.path.join(gpu.prm.hwmon_path, 'pwm1')
old_pwm = gpu.get_params_value('fan_pwm', num_as_int=True)
LOGGER.debug('Current pwm value: %s', old_pwm)
new_pwm_str = devices[uuid]['fan_pwm_ent'].get_text()
LOGGER.debug('Original pwm value %s, entered value %s', old_pwm, new_pwm_str)
if new_pwm_str.lower() == 'reset':
changed += 1
print('# PWM entry: {}, Resetting to default mode of dynamic'.format(new_pwm_str), file=fileptr)
print("sudo sh -c \"echo \'0\' > {}\"".format(pwm_enable_file), file=fileptr)
print("sudo sh -c \"echo \'2\' > {}\"".format(pwm_enable_file), file=fileptr)
elif new_pwm_str.lower() == 'max':
changed += 1
print('# PWM entry: {}, Disabling fan control'.format(new_pwm_str), file=fileptr)
print("sudo sh -c \"echo \'0\' > {}\"".format(pwm_enable_file), file=fileptr)
elif re.fullmatch(PATTERNS[PK.DIGITS], new_pwm_str):
new_pwm = int(new_pwm_str)
print('# Fan PWM Old: {}'.format(old_pwm), end='', file=fileptr)
print(' New: {}'.format(new_pwm), end='', file=fileptr)
pwm_range = gpu.get_params_value('fan_pwm_range')
print(' Min: {}'.format(pwm_range[0]), end='', file=fileptr)
print(' Max: {}\n'.format(pwm_range[1]), end='', file=fileptr)
if new_pwm == old_pwm and GUT_CONST.write_delta_only:
print('# No PWM changes, skipped', file=fileptr)
elif new_pwm == 0 and old_pwm is None:
print('# No PWM changes, None to Zero skipped', file=fileptr)
elif new_pwm < 20:
print('# Specified PWM value below min safe limit of 20%, skipped', file=fileptr)
LOGGER.debug('Unsafe PWM value skipped: %s', new_pwm_str)
else:
if gpu.is_valid_fan_pwm(new_pwm):
changed += 1
new_pwm_value = int(255 * new_pwm / 100)
print("sudo sh -c \"echo \'1\' > {}\"".format(pwm_enable_file), file=fileptr)
print("sudo sh -c \"echo \'{}\' > {}\"".format(new_pwm_value, pwm_file), file=fileptr)
else:
print('# Invalid pwm parameter values', file=fileptr)
print('Invalid pwm parameter values')
else:
print('# PWM entry: {}, invalid input, ignoring'.format(new_pwm_str), file=fileptr)
new_pwm = old_pwm
device_file = os.path.join(gpu.prm.card_path, 'pp_od_clk_voltage')
commit_needed = False
if gpu.get_params_value('gpu_type') == GpuType.PStates:
# Sclk P-states
for comp_name, comp_item in devices[uuid]['sclk_pstate'].items():
if not comp_item['gtk_ent_f_obj'].get_text().isnumeric():
print('# Invalid sclk pstate entry: {}'.format(comp_item['gtk_ent_f_obj'].get_text()),
file=fileptr)
print('# Invalid sclk pstate entry: {}'.format(comp_item['gtk_ent_f_obj'].get_text()))
continue
if not comp_item['gtk_ent_v_obj'].get_text().isnumeric():
print('# Invalid sclk pstate entry: {}'.format(comp_item['gtk_ent_v_obj'].get_text()),
file=fileptr)
print('# Invalid sclk pstate entry: {}'.format(comp_item['gtk_ent_v_obj'].get_text()))
pstate = [comp_name,
int(comp_item['gtk_ent_f_obj'].get_text()),
int(comp_item['gtk_ent_v_obj'].get_text())]
print('#sclk p-state: {} : {} MHz, {} mV'.format(pstate[0], pstate[1], pstate[2]), file=fileptr)
if gpu.is_valid_sclk_pstate(pstate):
if gpu.is_changed_sclk_pstate(pstate) or not GUT_CONST.write_delta_only:
changed += 1
commit_needed = True
print("sudo sh -c \"echo \'s {} {} {}\' > {}\"".format(pstate[0], pstate[1],
pstate[2], device_file), file=fileptr)
else:
print('# Sclk pstate {} unchanged, skipping'.format(comp_name), file=fileptr)
else:
print('# Invalid sclk pstate values', file=fileptr)
print('Invalid sclk pstate values')
# Mclk P-states
for comp_name, comp_item in devices[uuid]['mclk_pstate'].items():
if not comp_item['gtk_ent_f_obj'].get_text().isnumeric():
print('# Invalid mclk pstate entry: {}'.format(comp_item['gtk_ent_f_obj'].get_text()),
file=fileptr)
print('# Invalid mclk pstate entry: {}'.format(comp_item['gtk_ent_f_obj'].get_text()))
continue
if not comp_item['gtk_ent_v_obj'].get_text().isnumeric():
print('# Invalid mclk pstate entry: {}'.format(comp_item['gtk_ent_v_obj'].get_text()),
file=fileptr)
print('# Invalid mclk pstate entry: {}'.format(comp_item['gtk_ent_v_obj'].get_text()))
continue
pstate = [comp_name,
int(comp_item['gtk_ent_f_obj'].get_text()),
int(comp_item['gtk_ent_v_obj'].get_text())]
print('#mclk p-state: {} : {} MHz, {} mV'.format(pstate[0], pstate[1], pstate[2]), file=fileptr)
if gpu.is_valid_mclk_pstate(pstate):
if gpu.is_changed_mclk_pstate(pstate) or not GUT_CONST.write_delta_only:
changed += 1
commit_needed = True
print("sudo sh -c \"echo \'m {} {} {}\' > {}\"".format(pstate[0], pstate[1],
pstate[2], device_file), file=fileptr)
else:
print('# Mclk pstate {} unchanged, skipping'.format(comp_name), file=fileptr)
else:
print('# Invalid mclk pstate values', file=fileptr)
print('Invalid mclk pstate values')
elif gpu.get_params_value('gpu_type') in (GpuType.CurvePts, GpuType.Offset):
# Sclk Curve End Points
for comp_name, comp_item in devices[uuid]['sclk_pstate'].items():
if not comp_item['gtk_ent_f_obj'].get_text().isnumeric():
print('# Invalid sclk curve end point entry: {}'.format(comp_item['gtk_ent_f_obj'].get_text()),
file=fileptr)
print('# Invalid sclk curve end point entry: {}'.format(comp_item['gtk_ent_f_obj'].get_text()))
continue
pstate = [comp_name, int(comp_item['gtk_ent_f_obj'].get_text()), '-']
print('# Sclk curve end point: {} : {} MHz'.format(pstate[0], pstate[1]), file=fileptr)
if gpu.is_valid_sclk_pstate(pstate):
if gpu.is_changed_sclk_pstate(pstate) or not GUT_CONST.write_delta_only:
changed += 1
commit_needed = True
print("sudo sh -c \"echo \'s {} {}\' > {}\"".format(pstate[0], pstate[1], device_file),
file=fileptr)
else:
print('# Sclk curve point {} unchanged, skipping'.format(comp_name), file=fileptr)
else:
print('# Invalid sclk curve end point values', file=fileptr)
print('Invalid sclk curve end point values')
# Mclk Curve End Points
for comp_name, comp_item in devices[uuid]['mclk_pstate'].items():
if not comp_item['gtk_ent_f_obj'].get_text().isnumeric():
print('# Invalid mclk curve end point entry: {}'.format(comp_item['gtk_ent_f_obj'].get_text()),
file=fileptr)
print('# Invalid mclk curve end point entry: {}'.format(comp_item['gtk_ent_f_obj'].get_text()))
continue
pstate = [comp_name, int(comp_item['gtk_ent_f_obj'].get_text()), '-']
print('# Mclk curve end point: {} : {} MHz'.format(pstate[0], pstate[1]), file=fileptr)
if gpu.is_valid_mclk_pstate(pstate):
if gpu.is_changed_mclk_pstate(pstate) or not GUT_CONST.write_delta_only:
changed += 1
commit_needed = True
print("sudo sh -c \"echo \'m {} {}\' > {}\"".format(pstate[0], pstate[1], device_file),
file=fileptr)
else:
print('# Mclk curve point {} unchanged, skipping'.format(comp_name), file=fileptr)
else:
print('# Invalid mclk curve end point values', file=fileptr)
print('Invalid mclk curve end point values')
if gpu.get_params_value('gpu_type') in (GpuType.CurvePts, ):
# VDDC Curve Points
for comp_name, comp_item in devices[uuid]['vddc_curve_pt'].items():
if not comp_item['gtk_ent_f_obj'].get_text().isnumeric():
print('# Invalid vddc curve point entry: {}'.format(comp_item['gtk_ent_f_obj'].get_text()),
file=fileptr)
print('# Invalid vddc curve point entry: {}'.format(comp_item['gtk_ent_f_obj'].get_text()))
continue
if not comp_item['gtk_ent_v_obj'].get_text().isnumeric():
print('# Invalid vddc curve point entry: {}'.format(comp_item['gtk_ent_v_obj'].get_text()),
file=fileptr)
print('# Invalid vddc curve point entry: {}'.format(comp_item['gtk_ent_v_obj'].get_text()))
continue
curve_pts = [comp_name,
int(comp_item['gtk_ent_f_obj'].get_text()),
int(comp_item['gtk_ent_v_obj'].get_text())]
print('# Vddc curve point: {} : {} MHz, {} mV'.format(curve_pts[0], curve_pts[1], curve_pts[2]),
file=fileptr)
if gpu.is_valid_vddc_curve_pts(curve_pts):
if gpu.is_changed_vddc_curve_pt(curve_pts) or not GUT_CONST.write_delta_only:
changed += 1
commit_needed = True
print("sudo sh -c \"echo \'vc {} {} {}\' > {}\"".format(curve_pts[0], curve_pts[1],
curve_pts[2], device_file), file=fileptr)
else:
print('# Vddc curve point {} unchanged, skipping'.format(comp_name), file=fileptr)
else:
print('# Invalid Vddc curve point values', file=fileptr)
print('Invalid Vddc curve point values')
elif gpu.get_params_value('gpu_type') in (GpuType.Offset, ):
# VDDCGFX OFFSET
if not devices[uuid]['vddgfx_offset_ent'].get_text().lstrip('-+').isnumeric():
print('# Invalid vddgfx offset entry: [{}]'.format(devices[uuid]['vddgfx_offset_ent'].get_text()),
file=fileptr)
print('# Invalid vddgfx offset entry: [{}]'.format(devices[uuid]['vddgfx_offset_ent'].get_text()))
else:
vddgfx_offset_val = int(devices[uuid]['vddgfx_offset_ent'].get_text())
print('# Vddgfx offset: {} mV'.format(vddgfx_offset_val), file=fileptr)
if gpu.is_valid_vddgfx_offset(vddgfx_offset_val):
if gpu.is_changed_vddgfx_offset(vddgfx_offset_val) or not GUT_CONST.write_delta_only:
changed += 1
commit_needed = True
print("sudo sh -c \"echo \'vo {}\' > {}\"".format(
vddgfx_offset_val, device_file), file=fileptr)
else:
print('# Vddgfx offset {} unchanged, skipping'.format(vddgfx_offset_val), file=fileptr)
else:
print('# Invalid Vddgfx offset value, out of range.', file=fileptr)
print('Invalid Vddgfx offset value, out of range.')
# PPM
ppm_mode_file = os.path.join(gpu.prm.card_path, 'pp_power_profile_mode')
tree_iter = devices[uuid]['ppm_modes_combo'].get_active_iter()
if tree_iter is not None:
# model = devices[uuid]['ppm_modes_combo'].get_model()
# row_id, name = model[tree_iter][:2]
# selected_mode = devices[uuid]['new_ppm'][0]
print('# Selected: ID={}, name={}'.format(devices[uuid]['new_ppm'][0], devices[uuid]['new_ppm'][1]),
file=fileptr)
if gpu.get_current_ppm_mode()[0] != devices[uuid]['new_ppm'][0] or not GUT_CONST.write_delta_only:
changed += 1
print("sudo sh -c \"echo \'{}\' > {}\"".format(devices[uuid]['new_ppm'][0], ppm_mode_file),
file=fileptr)
else:
print('# PPM mode {} unchanged, skipping'.format(devices[uuid]['new_ppm'][1]), file=fileptr)
# Commit changes
device_file = os.path.join(gpu.prm.card_path, 'pp_od_clk_voltage')
if commit_needed:
changed += 1
print("sudo sh -c \"echo \'c\' > {}\"".format(device_file), file=fileptr)
else:
print('# No clock changes made, commit skipped', file=fileptr)
if gpu.get_params_value('gpu_type') in (GpuType.PStates, GpuType.CurvePts):
# Writes of pstate Masks must come after commit of pstate changes
# Sclk Mask
sclk_mask_file = os.path.join(gpu.prm.card_path, 'pp_dpm_sclk')
old_sclk_mask = gpu.prm.sclk_mask.replace(',', ' ')
new_sclk_mask = devices[uuid]['sclk_pst_mask_ent'].get_text().replace(' ', '').strip()
new_sclk_mask = new_sclk_mask.replace(',', ' ').strip()
print('# Sclk P-State Mask Default: {}'.format(old_sclk_mask), end='', file=fileptr)
print(' New: {}'.format(new_sclk_mask), file=fileptr)
if new_sclk_mask == old_sclk_mask and GUT_CONST.write_delta_only:
print('# No changes, skipped', file=fileptr)
else:
if gpu.is_valid_pstate_list_str(new_sclk_mask, 'SCLK'):
changed += 1
if new_sclk_mask == '':
# reset
print('# Resetting SCLK Mask to default', file=fileptr)
print("sudo sh -c \"echo \'{}\' > {}\"".format(old_sclk_mask, sclk_mask_file), file=fileptr)
else:
print("sudo sh -c \"echo \'{}\' > {}\"".format(new_sclk_mask, sclk_mask_file), file=fileptr)
else:
print('# Invalid sclk mask parameter values', file=fileptr)
print('Invalid sclk mask parameter values: {}'.format(new_sclk_mask))
# Mclk Mask
mclk_mask_file = os.path.join(gpu.prm.card_path, 'pp_dpm_mclk')
old_mclk_mask = gpu.prm.mclk_mask.replace(',', ' ')
new_mclk_mask = devices[uuid]['mclk_pst_mask_ent'].get_text().replace(' ', '').strip()
new_mclk_mask = new_mclk_mask.replace(',', ' ').strip()
print('# Mclk P-State Mask Default: {}'.format(old_mclk_mask), end='', file=fileptr)
print(' New: {}'.format(new_mclk_mask), file=fileptr)
if new_mclk_mask == old_mclk_mask and GUT_CONST.write_delta_only:
print('# No changes, skipped', file=fileptr)
else:
if gpu.is_valid_pstate_list_str(new_mclk_mask, 'MCLK'):
changed += 1
if new_mclk_mask == '':
# reset
print('# Resetting MCLK Mask to default', file=fileptr)
print("sudo sh -c \"echo \'{}\' > {}\"".format(old_mclk_mask, mclk_mask_file), file=fileptr)
else:
print("sudo sh -c \"echo \'{}\' > {}\"".format(new_mclk_mask, mclk_mask_file), file=fileptr)
else:
print('# Invalid mclk mask parameter values', file=fileptr)
print('Invalid mclk mask parameter values: {}'.format(new_mclk_mask))
# Close file and Set permissions and Execute it --execute_pac
fileptr.close()
os.chmod(out_filename, 0o744)
print('Batch file completed: {}'.format(out_filename))
if GUT_CONST.execute_pac:
# Execute bash file
print('Writing {} changes to GPU {}'.format(changed, gpu.prm.card_path))
with subprocess.Popen(out_filename, shell=True) as cmd:
cmd.wait()
print('PAC execution complete.')
if refresh:
# dismiss execute_pac message
sleep(0.5)
if changed:
message = ('Write of {} PAC commands to card complete.\n'
'Confirm changes with gpu-monitor.').format(changed)
else:
message = 'No PAC commands to write to card.\nNo changes specified.'
self.update_message(devices, message, 'yellow')
if refresh:
self.refresh_pac(gpu_list, devices)
os.remove(out_filename)
else:
if refresh:
# dismiss execute_pac message
if changed:
message = ('Write of {} PAC commands to bash file complete.\n'
'Manually run bash file with sudo to execute changes.').format(changed)
else:
message = 'No PAC commands to write bash file.\nNo changes specified.'
self.update_message(devices, message, 'yellow')
print('Execute to write changes to GPU {}'.format(gpu.prm.card_path))
print('')
return changed
def reset_all_cards(self, parent, gpu_list: Gpu.GpuList, devices: dict) -> None:
"""
Reset data for all GPUs.
:param parent: parent
:param gpu_list:
:param devices: Dictionary of GUI items and GPU data.
"""
# Write start message
if GUT_CONST.execute_pac:
message = ('Using the --execute_pac option Reset commands will be written to the GPU '
'without confirmation.\nSudo will be used, so you may be prompted for '
'credentials in the window where gpu-pac was executed from.')
else:
message = 'Writing reset commands to bash file.\n'
self.update_message(devices, message, 'red')
# reset each card
for uuid in gpu_list.uuids():
self.reset_card(parent, gpu_list, devices, uuid, refresh=False)
# Write finish message
if GUT_CONST.execute_pac:
message = 'Write reset commands to card complete.\nConfirm changes with gpu-mon.'
else:
message = 'Write reset commands to bash file complete.\nRun bash file with sudo to execute changes.'
self.update_message(devices, message, 'yellow')
self.refresh_all_cards(parent, gpu_list, devices)
def reset_card(self, _, gpu_list: Gpu.GpuList, devices: dict, uuid: str, refresh: bool = True) -> None:
"""
Reset data for specified GPU.
:param _: parent not used
:param gpu_list:
:param devices: Dictionary of GUI items and GPU data.
:param uuid: GPU device ID
:param refresh: Flag to indicate if refresh should be done
"""
if refresh:
# Write message
if GUT_CONST.execute_pac:
message = ('Using the --execute_pac option Reset commands will be written to the GPU '
'without confirmation.\nSudo will be used, so you may be prompted for '
'credentials in the window where gpu-pac was executed from.')
else:
message = 'Writing reset commands to bash file.\n'
self.update_message(devices, message, 'red')
# specify output batch file name
out_filename = os.path.join(os.getcwd(), 'pac_resetter_{}.sh'.format(uuid4().hex))
fileptr = open(out_filename, mode='x', encoding='utf-8')
# Output header
print('#!/bin/sh', file=fileptr)
print('###########################################################################', file=fileptr)
print('## rickslab-gpu-pac generated script to modify GPU configuration/settings', file=fileptr)
print('###########################################################################', file=fileptr)
print('', file=fileptr)
print('###########################################################################', file=fileptr)
print('## WARNING - Do not execute this script without completely', file=fileptr)
print('## understanding appropriate value to write to your specific GPUs', file=fileptr)
print('###########################################################################', file=fileptr)
print('#', file=fileptr)
print('# Copyright (C) 2019 RueiKe', file=fileptr)
print('#', file=fileptr)
print('# This program is free software: you can redistribute it and/or modify', file=fileptr)
print('# it under the terms of the GNU General Public License as published by', file=fileptr)
print('# the Free Software Foundation, either version 3 of the License, or', file=fileptr)
print('# (at your option) any later version.', file=fileptr)
print('#', file=fileptr)
print('# This program is distributed in the hope that it will be useful,', file=fileptr)
print('# but WITHOUT ANY WARRANTY; without even the implied warranty of', file=fileptr)
print('# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the', file=fileptr)
print('# GNU General Public License for more details.', file=fileptr)
print('#', file=fileptr)
print('# You should have received a copy of the GNU General Public License', file=fileptr)
print('# along with this program. If not, see <https://www.gnu.org/licenses/>.', file=fileptr)
print('###########################################################################', file=fileptr)
gpu = gpu_list[uuid]
print('# ', file=fileptr)
print('# Card{} Model: {}'.format(gpu.prm.card_num, gpu.get_params_value('model')), file=fileptr)
print('# Type: {}'.format(gpu.prm.gpu_type), file=fileptr)
print('# Path: {}'.format(gpu.prm.card_path), file=fileptr)
print('# Reset mode.')
print('# ', file=fileptr)
print('set -x', file=fileptr)
# Commit changes
power_cap_file = os.path.join(gpu.prm.hwmon_path, 'power1_cap')
pwm_enable_file = os.path.join(gpu.prm.hwmon_path, 'pwm1_enable')
device_file = os.path.join(gpu.prm.card_path, 'pp_od_clk_voltage')
power_dpm_force_file = os.path.join(gpu.prm.card_path, 'power_dpm_force_performance_level')
print("sudo sh -c \"echo \'0\' > {}\"".format(power_cap_file), file=fileptr)
if GUT_CONST.show_fans:
print("sudo sh -c \"echo \'2\' > {}\"".format(pwm_enable_file), file=fileptr)
print("sudo sh -c \"echo \'auto\' > {}\"".format(power_dpm_force_file), file=fileptr)
print("sudo sh -c \"echo \'r\' > {}\"".format(device_file), file=fileptr)
print("sudo sh -c \"echo \'c\' > {}\"".format(device_file), file=fileptr)
# No need to reset clk pstate masks as commit to pp_od_clk_voltage will reset
# Close file and Set permissions and Execute it --execute_pac
fileptr.close()
os.chmod(out_filename, 0o744)
print('Batch file completed: {}'.format(out_filename))
if GUT_CONST.execute_pac:
print('Writing changes to GPU {}'.format(gpu.prm.card_path))
with subprocess.Popen(out_filename, shell=True) as cmd:
cmd.wait()
print('')
if refresh:
# Dismiss execute_pac message
message = 'Write reset commands to card complete.\nConfirm changes with gpu-mon.'
self.update_message(devices, message, 'yellow')
self.refresh_pac(gpu_list, devices)
os.remove(out_filename)
else:
print('Execute to write changes to GPU {}.\n'.format(gpu.prm.card_path))
if refresh:
# Dismiss execute_pac message
message = 'Write reset commands to bash file complete.\nRun bash file with sudo to execute changes.'
self.update_message(devices, message, 'yellow')
def ppm_select(_, device: dict) -> None:
"""
Update device data for ppm selection and update active selected item in Gui.
:param _: self
:param device: Dictionary of GUI items and GPU data.
"""
tree_iter = device['ppm_modes_combo'].get_active_iter()
if tree_iter is not None:
model = device['ppm_modes_combo'].get_model()
row_id, name = model[tree_iter][:2]
device['new_ppm'] = [row_id, name]
def main() -> None:
"""
Main PAC flow.
"""
parser = argparse.ArgumentParser()
parser.add_argument('--about', help='README', action='store_true', default=False)
parser.add_argument('--execute_pac', help='execute pac bash script without review',
action='store_true', default=False)
parser.add_argument('--no_fan', help='do not include fan setting options', action='store_true', default=False)
parser.add_argument('--force_write', help='write all parameters, even if unchanged',
action='store_true', default=False)
parser.add_argument('--verbose', help='Display informational message of GPU util progress',
action='store_true', default=False)
parser.add_argument('-d', '--debug', help='Debug output', action='store_true', default=False)
args = parser.parse_args()
# About me
if args.about:
print(__doc__)
print('Author: ', __author__)
print('Copyright: ', __copyright__)
print('Credits: ', *['\n {}'.format(item) for item in __credits__])
print('License: ', __license__)
print('Version: ', __version__)
print('Install Type: ', GUT_CONST.install_type)
print('Maintainer: ', __maintainer__)
print('Status: ', __status__)
sys.exit(0)
GUT_CONST.set_args(args, __program_name__)
LOGGER.debug('########## %s %s', __program_name__, __version__)
if GUT_CONST.check_env() < 0:
print('Error in environment. Exiting...')
sys.exit(-1)
# Get list of GPUs
gpu_list = Gpu.GpuList()
gpu_list.set_gpu_list()
num_gpus = gpu_list.num_gpus()
if num_gpus['total'] == 0:
print('No GPUs detected, exiting...')
sys.exit(-1)
# Check list of GPUs and display vendor and driver details
Gpu.print_driver_vendor_summary(gpu_list)
# Read data static/dynamic/info/state driver information for GPUs
gpu_list.read_gpu_sensor_set(data_type=SensorSet.All)
# Check number of readable/writable GPUs again
print('All GPUs:')
print(gpu_list)
# Select GPU's appropriate for pac
com_gpu_list = gpu_list.list_gpus(compatibility=GpuCompatibility.Writable)
com_gpu_list = com_gpu_list.list_gpus(gpu_type=GpuType.Unsupported, reverse=True)
com_gpu_list = com_gpu_list.list_gpus(gpu_type=GpuType.Undefined, reverse=True)
com_gpu_list = com_gpu_list.list_gpus(gpu_type=GpuType.LegacyAPU, reverse=True)
com_gpu_list = com_gpu_list.list_gpus(gpu_type=GpuType.APU, reverse=True)
# Check number of compatible GPUs again
writable_gpus = com_gpu_list.num_gpus()['total']
print('Compatible GPUs:')
if not writable_gpus:
print('None are writable, exiting...')
sys.exit(-1)
# Check writable and compatible
print(com_gpu_list)
com_gpu_list.read_gpu_pstates()
com_gpu_list.read_gpu_ppm_table()
# Display Gtk style Monitor
devices = {}
gmonitor = PACWindow(com_gpu_list, devices)
gmonitor.connect('delete-event', Gtk.main_quit)
gmonitor.show_all()
Gtk.main()
if __name__ == '__main__':
main()
|