SWDEV-495057 Check video and render groups (#121)

Change-Id: I0a96dfbd84ae84fa29f41e1fe5ea89c05c5e5e7e

Signed-off-by: adapryor <Adam.pryor@amd.com>
This commit is contained in:
Pryor, Adam
2025-02-26 17:16:41 -06:00
committato da GitHub
parent b4c05ccb16
commit 7745f4f6c9
2 ha cambiato i file con 45 aggiunte e 0 eliminazioni
+23
Vedi File
@@ -49,6 +49,7 @@ class AMDSMICommands():
self.cpu_handles = []
self.core_handles = []
self.stop = ''
self.group_check_printed = False
amdsmi_init_flag = self.helpers.get_amdsmi_init_flag()
logging.debug(f"AMDSMI Init Flag: {amdsmi_init_flag}")
@@ -199,6 +200,8 @@ class AMDSMICommands():
if args.gpu == None:
args.gpu = self.device_handles
self.helpers.check_required_groups()
# Handle multiple GPUs
handled_multiple_gpus, device_handle = self.helpers.handle_gpus(args, self.logger, self.list)
if handled_multiple_gpus:
@@ -382,6 +385,8 @@ class AMDSMICommands():
args.vram, args.cache, args.board, args.process_isolation,
args.clock]
self.helpers.check_required_groups()
if self.helpers.is_linux() and self.helpers.is_baremetal():
if partition:
args.partition = partition
@@ -1445,6 +1450,10 @@ class AMDSMICommands():
if args.gpu == None:
args.gpu = self.device_handles
if not self.group_check_printed:
self.helpers.check_required_groups()
self.group_check_printed = True
# Handle watch logic, will only enter this block once
if args.watch:
self.helpers.handle_watch(args=args, subcommand=self.metric_gpu, logger=self.logger)
@@ -3297,6 +3306,8 @@ class AMDSMICommands():
# Clear the table header
self.logger.table_header = ''.rjust(12)
self.helpers.check_required_groups()
# Populate the possible gpus
topo_values = []
for src_gpu_index, src_gpu in enumerate(args.gpu):
@@ -4571,6 +4582,8 @@ class AMDSMICommands():
if core:
args.core = core
self.helpers.check_required_groups()
# Check if a GPU argument has been set
gpu_args_enabled = False
gpu_attributes = ["fan", "perf_level", "profile", "perf_determinism", "compute_partition",
@@ -4715,6 +4728,8 @@ class AMDSMICommands():
if args.gpu == None:
args.gpu = self.device_handles
self.helpers.check_required_groups()
# Handle multiple GPUs
handled_multiple_gpus, device_handle = self.helpers.handle_gpus(args, self.logger, self.reset)
if handled_multiple_gpus:
@@ -4951,6 +4966,10 @@ class AMDSMICommands():
if args.gpu == None:
args.gpu = self.device_handles
if not self.group_check_printed:
self.helpers.check_required_groups()
self.group_check_printed = True
# If all arguments are False, the print all values
# Don't include process in this logic as it's an optional edge case
if not any([args.power_usage, args.temperature, args.gfx, args.mem,
@@ -5507,6 +5526,8 @@ class AMDSMICommands():
# Clear the table header
self.logger.table_header = ''.rjust(7)
self.helpers.check_required_groups()
# Populate the possible gpus and their bdfs
xgmi_values = []
for gpu in args.gpu:
@@ -5751,6 +5772,8 @@ class AMDSMICommands():
if accelerator:
args.accelerator = accelerator
self.helpers.check_required_groups()
###########################################
# amd-smi partition (no args) #
###########################################
+22
Vedi File
@@ -22,6 +22,7 @@
import logging
import math
import os
import grp
import platform
import sys
import time
@@ -985,3 +986,24 @@ class AMDSMIHelpers():
title += ": "
for i in self.progressbar(range(timeInSeconds), title, 40):
time.sleep(1)
def check_required_groups(self):
"""
Check if the current user is a member of the required groups.
If not, log a warning.
"""
required_groups = {'video', 'render'}
try:
user_groups = {grp.getgrgid(gid).gr_name for gid in os.getgroups()}
except Exception as e:
logging.warning("Unable to determine group memberships: %s", e)
return
missing_groups = required_groups - user_groups
if missing_groups:
msg = (
"WARNING: User is missing the following required groups: %s. "
"Please add user to these groups."
) % ", ".join(sorted(missing_groups))
print(msg)
logging.warning(msg)