ROCm SMI Python CLI: Check for amdgpu Driver Initialization

The purpose of this patch is to check for amdgpu driver initialization
before attempting to initialize rocmsmi in the CLI.

Additionally, since the '--help' functionality does not rely on anything
external to the CLI, it can now be called without the driver initialized.

Change-Id: I2fcce60ca6d9f77835549e3558c4bb1747499c5c
Signed-off-by: Ori Messinger <Ori.Messinger@amd.com>


[ROCm/amdsmi commit: e3c9aec714]
Этот коммит содержится в:
Ori Messinger
2020-09-23 16:33:01 -04:00
родитель 137e33a1e6
Коммит 6ea0c8b524
+29 -5
Просмотреть файл
@@ -57,11 +57,18 @@ validClockNames = clk_type_names[1:-2]
validClockNames.append('pcie')
validClockNames.sort()
# Check for correct initialization value
ret_init = rocmsmi.rsmi_init(0)
if ret_init != 0:
logging.error('ROCm SMI returned %s (the expected value is 0)', ret_init)
exit(ret_init)
def driverInitialized():
""" Returns true if amdgpu is found in the list of initialized modules
"""
driverInitialized = ''
try:
driverInitialized = str(subprocess.check_output("cat /proc/modules|grep amdgpu", shell=True))
except subprocess.CalledProcessError:
pass
if len(driverInitialized) > 0:
return True
return False
def formatJson(device, log):
""" Print out in JSON format
@@ -2132,6 +2139,20 @@ def doesDeviceExist(device):
return False
def initializeRsmi():
""" initializes rocmsmi if the amdgpu driver is initialized
"""
# Check if amdgpu is initialized before initializing rsmi
if driverInitialized() is True:
ret_init = rocmsmi.rsmi_init(0)
if ret_init != 0:
logging.error('ROCm SMI returned %s (the expected value is 0)', ret_init)
exit(ret_init)
else:
logging.error('Driver not initialized (amdgpu not found in modules)')
exit(0)
def isAmdDevice(device):
""" Return whether the specified device is an AMD device or not
@@ -2444,6 +2465,9 @@ if __name__ == '__main__':
args = parser.parse_args()
# Initialize the rocm SMI library
initializeRsmi()
logging.basicConfig(format='%(levelname)s: %(message)s', level=logging.WARNING)
if args.loglevel is not None:
numericLogLevel = getattr(logging, args.loglevel.upper(), logging.WARNING)