From d8f236cd8180ee0f1fc1da497d0f576a446b86ab Mon Sep 17 00:00:00 2001 From: David Salinas Date: Wed, 1 Jun 2022 19:06:12 +0000 Subject: [PATCH] Handle case with no GPUs Change-Id: I35b8d4d0c0b6e63d9851d56163686794c7bb8c1e --- rocm_agent_enumerator | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/rocm_agent_enumerator b/rocm_agent_enumerator index 7bc0dc4..6264a5f 100755 --- a/rocm_agent_enumerator +++ b/rocm_agent_enumerator @@ -190,24 +190,25 @@ def readFromKFD(): target_list = [] topology_dir = '/sys/class/kfd/kfd/topology/nodes/' - for node in sorted(os.listdir(topology_dir)): - node_path = os.path.join(topology_dir, node) - if os.path.isdir(node_path): - prop_path = node_path + '/properties' - if os.path.isfile(prop_path): - target_search_term = re.compile("gfx_target_version.+") - with open(prop_path) as f: - line = f.readline() - while line != '' : - search_result = target_search_term.search(line) - if search_result is not None: - device_id = int(search_result.group(0).split(' ')[1], 10) - if device_id != 0: - major_ver = int((device_id / 10000) % 100) - minor_ver = int((device_id / 100) % 100) - stepping_ver = int(device_id % 100) - target_list.append("gfx" + format(major_ver, 'd') + format(minor_ver, 'x') + format(stepping_ver, 'x')) + if os.path.isdir(topology_dir): + for node in sorted(os.listdir(topology_dir)): + node_path = os.path.join(topology_dir, node) + if os.path.isdir(node_path): + prop_path = node_path + '/properties' + if os.path.isfile(prop_path): + target_search_term = re.compile("gfx_target_version.+") + with open(prop_path) as f: line = f.readline() + while line != '' : + search_result = target_search_term.search(line) + if search_result is not None: + device_id = int(search_result.group(0).split(' ')[1], 10) + if device_id != 0: + major_ver = int((device_id / 10000) % 100) + minor_ver = int((device_id / 100) % 100) + stepping_ver = int(device_id % 100) + target_list.append("gfx" + format(major_ver, 'd') + format(minor_ver, 'x') + format(stepping_ver, 'x')) + line = f.readline() return target_list