Skip to content

Commit

Permalink
Add get_npu_device_id() to device_info.py
Browse files Browse the repository at this point in the history
  • Loading branch information
jleveque committed Aug 10, 2020
1 parent 863520d commit 46e6ed4
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions src/sonic-py-common/sonic_py_common/device_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,42 @@ def get_npu_id_from_name(npu_name):
return None


def get_npu_device_id(npu_id):
platform = get_platform_info(get_machine_info())
if not platform:
return None

asic_conf_file_path = os.path.join(SONIC_DEVICE_PATH, platform, ASIC_CONF_FILENAME)
if not os.path.isfile(asic_conf_file_path):
return None

# In a multi-npu device we need to have the file "asic.conf" updated with the asic instance
# and the corresponding device id which could be pci_id. Below is an eg: for a 2 ASIC platform/sku.
# DEV_ID_ASIC_0=03:00.0
# DEV_ID_ASIC_1=04:00.0
device_str = "DEV_ID_ASIC_{}".format(npu_id)

with open(asic_conf_file_path) as asic_conf_file:
for line in asic_conf_file:
tokens = line.split('=')
if len(tokens) < 2:
continue
if tokens[0] == device_str:
device_id = tokens[1].strip()
return device_id


def get_asic_conf_file_path(platform):
asic_conf_path_candidates = []
asic_conf_path_candidates.append(os.path.join('/usr/share/sonic/platform', ASIC_CONF_FILENAME))
if platform is not None:
asic_conf_path_candidates.append(os.path.join(SONIC_DEVICE_PATH, platform, ASIC_CONF_FILENAME))
for asic_conf_file_path in asic_conf_path_candidates:
if os.path.isfile(asic_conf_file_path):
return asic_conf_file_path
return None


def get_namespaces():
"""
In a multi NPU platform, each NPU is in a Linux Namespace.
Expand Down

0 comments on commit 46e6ed4

Please sign in to comment.