Moved KFD information to separate structure and API

Signed-off-by: Maisam Arif <Maisam.Arif@amd.com>
Change-Id: If6eaea589edc704cf408d6391b5f2154134035e7
This commit is contained in:
Maisam Arif
2024-09-17 04:54:41 -05:00
parent 2cfae06560
commit 3b7f661e71
15 changed files with 328 additions and 175 deletions
+40 -7
View File
@@ -377,6 +377,8 @@ Field | Content
`rev_id` | revision id
`asic_serial` | asic serial
`oam_id` | oam id
`num_of_compute_units` | number of compute units on asic
`target_graphics_version` | hardware graphics version
Exceptions that can be thrown by `amdsmi_get_gpu_asic_info` function:
@@ -394,13 +396,44 @@ try:
else:
for device in devices:
asic_info = amdsmi_get_gpu_asic_info(device)
print(asic_info['market_name'])
print(hex(asic_info['vendor_id']))
print(asic_info['vendor_name'])
print(hex(asic_info['device_id']))
print(hex(asic_info['rev_id']))
print(asic_info['asic_serial'])
print(asic_info['oam_id'])
print(asic_info)
except AmdSmiException as e:
print(e)
```
### amdsmi_get_gpu_kfd_info
Description: Returns KFD(kernel fusion driver) information for the given GPU
This correlates to GUID in rocm-smi
Input parameters:
* `processor_handle` device which to query
Output: Dictionary with fields
Field | Content
---|---
`kfd_id` | KFD's unique GPU identifier
`node_id` | KFD's internal GPU index
Exceptions that can be thrown by `amdsmi_get_gpu_kfd_info` function:
* `AmdSmiLibraryException`
* `AmdSmiRetryException`
* `AmdSmiParameterException`
Example:
```python
try:
devices = amdsmi_get_processor_handles()
if len(devices) == 0:
print("No GPUs on machine")
else:
for device in devices:
kfd_info = amdsmi_get_gpu_kfd_info(device)
print(kfd_info)
except AmdSmiException as e:
print(e)
```
+1
View File
@@ -89,6 +89,7 @@ from .amdsmi_interface import amdsmi_get_gpu_driver_info
# # ASIC and Bus Static Information
from .amdsmi_interface import amdsmi_get_gpu_asic_info
from .amdsmi_interface import amdsmi_get_gpu_kfd_info
from .amdsmi_interface import amdsmi_get_power_cap_info
from .amdsmi_interface import amdsmi_get_gpu_vram_info
from .amdsmi_interface import amdsmi_get_gpu_cache_info
+47 -27
View File
@@ -575,7 +575,7 @@ def _make_amdsmi_bdf_from_list(bdf):
amdsmi_bdf.struct_amdsmi_bdf_t.domain_number = bdf[0]
return amdsmi_bdf
def _padHexValue(value, length):
def _pad_hex_value(value, length):
""" Pad a hexadecimal value with a given length of zeros
:param value: A hexadecimal value to be padded with zeros
@@ -590,23 +590,23 @@ def _padHexValue(value, length):
return '0x' + value[2:].zfill(length)
return value
class UIntegerTypes(IntEnum):
class MaxUIntegerTypes(IntEnum):
UINT8_T = 0xFF
UINT16_T = 0xFFFF
UINT32_T = 0xFFFFFFFF
UINT64_T = 0xFFFFFFFFFFFFFFFF
def _validateIfMaxUint(valToCheck, uintType: UIntegerTypes):
def _validate_if_max_uint(value, uint_type: MaxUIntegerTypes):
return_val = "N/A"
if not isinstance(valToCheck, list):
if valToCheck == uintType:
if not isinstance(value, list):
if value == uint_type:
return return_val
else:
return valToCheck
return value
else:
return_val = valToCheck
for idx, v in enumerate(valToCheck):
if v == uintType:
return_val = value
for idx, v in enumerate(value):
if v == uint_type:
return_val[idx] = "N/A"
return return_val
@@ -1656,18 +1656,16 @@ def amdsmi_get_gpu_asic_info(
)
asic_info = {
"market_name": _padHexValue(asic_info_struct.market_name.decode("utf-8"), 4),
"market_name": _pad_hex_value(asic_info_struct.market_name.decode("utf-8"), 4),
"vendor_id": asic_info_struct.vendor_id,
"vendor_name": asic_info_struct.vendor_name.decode("utf-8"),
"subvendor_id": asic_info_struct.subvendor_id,
"device_id": asic_info_struct.device_id,
"rev_id": _padHexValue(hex(asic_info_struct.rev_id), 2),
"rev_id": _pad_hex_value(hex(asic_info_struct.rev_id), 2),
"asic_serial": asic_info_struct.asic_serial.decode("utf-8"),
"oam_id": asic_info_struct.oam_id,
"num_compute_units": asic_info_struct.num_of_compute_units,
"target_graphics_version": "gfx" + str(asic_info_struct.target_graphics_version),
"kfd_id": asic_info_struct.kfd_id,
"node_id": asic_info_struct.node_id,
"partition_id": asic_info_struct.partition_id
}
@@ -1705,6 +1703,28 @@ def amdsmi_get_gpu_asic_info(
return asic_info
def amdsmi_get_gpu_kfd_info(
processor_handle: amdsmi_wrapper.amdsmi_processor_handle,
) -> Dict[str, Any]:
if not isinstance(processor_handle, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(
processor_handle, amdsmi_wrapper.amdsmi_processor_handle
)
kfd_info_struct = amdsmi_wrapper.amdsmi_kfd_info_t()
_check_res(
amdsmi_wrapper.amdsmi_get_gpu_kfd_info(
processor_handle, ctypes.byref(kfd_info_struct))
)
kfd_info = {
"kfd_id": _validate_if_max_uint(kfd_info_struct.kfd_id, MaxUIntegerTypes.UINT32_T),
"node_id": _validate_if_max_uint(kfd_info_struct.node_id, MaxUIntegerTypes.UINT64_T)
}
return kfd_info
def amdsmi_get_power_cap_info(
processor_handle: amdsmi_wrapper.amdsmi_processor_handle,
) -> Dict[str, Any]:
@@ -1999,10 +2019,10 @@ def amdsmi_get_gpu_board_info(
)
board_info_dict = {
"model_number": _padHexValue(board_info.model_number.decode("utf-8").strip(), 4),
"model_number": _pad_hex_value(board_info.model_number.decode("utf-8").strip(), 4),
"product_serial": board_info.product_serial.decode("utf-8").strip(),
"fru_id": board_info.fru_id.decode("utf-8").strip(),
"product_name": _padHexValue(board_info.product_name.decode("utf-8").strip(), 4),
"product_name": _pad_hex_value(board_info.product_name.decode("utf-8").strip(), 4),
"manufacturer_name": board_info.manufacturer_name.decode("utf-8").strip()
}
@@ -2301,20 +2321,20 @@ def amdsmi_get_pcie_info(
pcie_info_dict = {
"pcie_static": {
"max_pcie_width": _validateIfMaxUint(pcie_info.pcie_static.max_pcie_width, UIntegerTypes.UINT16_T),
"max_pcie_speed": _validateIfMaxUint(pcie_info.pcie_static.max_pcie_speed, UIntegerTypes.UINT32_T),
"pcie_interface_version": _validateIfMaxUint(pcie_info.pcie_static.pcie_interface_version, UIntegerTypes.UINT32_T),
"max_pcie_width": _validate_if_max_uint(pcie_info.pcie_static.max_pcie_width, MaxUIntegerTypes.UINT16_T),
"max_pcie_speed": _validate_if_max_uint(pcie_info.pcie_static.max_pcie_speed, MaxUIntegerTypes.UINT32_T),
"pcie_interface_version": _validate_if_max_uint(pcie_info.pcie_static.pcie_interface_version, MaxUIntegerTypes.UINT32_T),
"slot_type": pcie_info.pcie_static.slot_type,
},
"pcie_metric": {
"pcie_width": _validateIfMaxUint(pcie_info.pcie_metric.pcie_width, UIntegerTypes.UINT16_T),
"pcie_speed": _validateIfMaxUint(pcie_info.pcie_metric.pcie_speed, UIntegerTypes.UINT32_T),
"pcie_bandwidth": _validateIfMaxUint(pcie_info.pcie_metric.pcie_bandwidth, UIntegerTypes.UINT32_T),
"pcie_replay_count": _validateIfMaxUint(pcie_info.pcie_metric.pcie_replay_count, UIntegerTypes.UINT64_T),
"pcie_l0_to_recovery_count": _validateIfMaxUint(pcie_info.pcie_metric.pcie_l0_to_recovery_count, UIntegerTypes.UINT64_T),
"pcie_replay_roll_over_count": _validateIfMaxUint(pcie_info.pcie_metric.pcie_replay_roll_over_count, UIntegerTypes.UINT64_T),
"pcie_nak_sent_count": _validateIfMaxUint(pcie_info.pcie_metric.pcie_nak_sent_count, UIntegerTypes.UINT64_T),
"pcie_nak_received_count": _validateIfMaxUint(pcie_info.pcie_metric.pcie_nak_received_count, UIntegerTypes.UINT64_T),
"pcie_width": _validate_if_max_uint(pcie_info.pcie_metric.pcie_width, MaxUIntegerTypes.UINT16_T),
"pcie_speed": _validate_if_max_uint(pcie_info.pcie_metric.pcie_speed, MaxUIntegerTypes.UINT32_T),
"pcie_bandwidth": _validate_if_max_uint(pcie_info.pcie_metric.pcie_bandwidth, MaxUIntegerTypes.UINT32_T),
"pcie_replay_count": _validate_if_max_uint(pcie_info.pcie_metric.pcie_replay_count, MaxUIntegerTypes.UINT64_T),
"pcie_l0_to_recovery_count": _validate_if_max_uint(pcie_info.pcie_metric.pcie_l0_to_recovery_count, MaxUIntegerTypes.UINT64_T),
"pcie_replay_roll_over_count": _validate_if_max_uint(pcie_info.pcie_metric.pcie_replay_roll_over_count, MaxUIntegerTypes.UINT64_T),
"pcie_nak_sent_count": _validate_if_max_uint(pcie_info.pcie_metric.pcie_nak_sent_count, MaxUIntegerTypes.UINT64_T),
"pcie_nak_received_count": _validate_if_max_uint(pcie_info.pcie_metric.pcie_nak_received_count, MaxUIntegerTypes.UINT64_T),
}
}
@@ -2407,7 +2427,7 @@ def amdsmi_get_gpu_subsystem_id(processor_handle: amdsmi_wrapper.amdsmi_processo
processor_handle, ctypes.byref(id))
)
return _padHexValue(hex(id.value), 4)
return _pad_hex_value(hex(id.value), 4)
def amdsmi_get_gpu_subsystem_name(processor_handle: amdsmi_wrapper.amdsmi_processor_handle):
+19 -6
View File
@@ -904,14 +904,23 @@ struct_amdsmi_asic_info_t._fields_ = [
('num_of_compute_units', ctypes.c_uint32),
('PADDING_0', ctypes.c_ubyte * 4),
('target_graphics_version', ctypes.c_uint64),
('kfd_id', ctypes.c_uint64),
('node_id', ctypes.c_uint32),
('partition_id', ctypes.c_uint32),
('reserved', ctypes.c_uint32 * 17),
('reserved', ctypes.c_uint32 * 14),
('PADDING_1', ctypes.c_ubyte * 4),
]
amdsmi_asic_info_t = struct_amdsmi_asic_info_t
class struct_amdsmi_kfd_info_t(Structure):
pass
struct_amdsmi_kfd_info_t._pack_ = 1 # source:False
struct_amdsmi_kfd_info_t._fields_ = [
('kfd_id', ctypes.c_uint64),
('node_id', ctypes.c_uint32),
('reserved', ctypes.c_uint32 * 13),
]
amdsmi_kfd_info_t = struct_amdsmi_kfd_info_t
# values for enumeration 'amdsmi_link_type_t'
amdsmi_link_type_t__enumvalues = {
@@ -2265,6 +2274,9 @@ amdsmi_get_gpu_driver_info.argtypes = [amdsmi_processor_handle, ctypes.POINTER(s
amdsmi_get_gpu_asic_info = _libraries['libamd_smi.so'].amdsmi_get_gpu_asic_info
amdsmi_get_gpu_asic_info.restype = amdsmi_status_t
amdsmi_get_gpu_asic_info.argtypes = [amdsmi_processor_handle, ctypes.POINTER(struct_amdsmi_asic_info_t)]
amdsmi_get_gpu_kfd_info = _libraries['libamd_smi.so'].amdsmi_get_gpu_kfd_info
amdsmi_get_gpu_kfd_info.restype = amdsmi_status_t
amdsmi_get_gpu_kfd_info.argtypes = [amdsmi_processor_handle, ctypes.POINTER(struct_amdsmi_kfd_info_t)]
amdsmi_get_gpu_vram_info = _libraries['libamd_smi.so'].amdsmi_get_gpu_vram_info
amdsmi_get_gpu_vram_info.restype = amdsmi_status_t
amdsmi_get_gpu_vram_info.argtypes = [amdsmi_processor_handle, ctypes.POINTER(struct_amdsmi_vram_info_t)]
@@ -2696,7 +2708,8 @@ __all__ = \
'amdsmi_get_gpu_ecc_enabled', 'amdsmi_get_gpu_ecc_status',
'amdsmi_get_gpu_event_notification', 'amdsmi_get_gpu_fan_rpms',
'amdsmi_get_gpu_fan_speed', 'amdsmi_get_gpu_fan_speed_max',
'amdsmi_get_gpu_id', 'amdsmi_get_gpu_mem_overdrive_level',
'amdsmi_get_gpu_id', 'amdsmi_get_gpu_kfd_info',
'amdsmi_get_gpu_mem_overdrive_level',
'amdsmi_get_gpu_memory_partition',
'amdsmi_get_gpu_memory_reserved_pages',
'amdsmi_get_gpu_memory_total', 'amdsmi_get_gpu_memory_usage',
@@ -2742,7 +2755,7 @@ __all__ = \
'amdsmi_init', 'amdsmi_init_flags_t',
'amdsmi_init_gpu_event_notification', 'amdsmi_io_bw_encoding_t',
'amdsmi_io_link_type_t', 'amdsmi_is_P2P_accessible',
'amdsmi_is_gpu_power_management_enabled',
'amdsmi_is_gpu_power_management_enabled', 'amdsmi_kfd_info_t',
'amdsmi_link_id_bw_type_t', 'amdsmi_link_metrics_t',
'amdsmi_link_type_t', 'amdsmi_memory_page_status_t',
'amdsmi_memory_partition_type_t', 'amdsmi_memory_type_t',
@@ -2802,7 +2815,7 @@ __all__ = \
'struct_amdsmi_freq_volt_region_t', 'struct_amdsmi_frequencies_t',
'struct_amdsmi_frequency_range_t', 'struct_amdsmi_fw_info_t',
'struct_amdsmi_gpu_cache_info_t', 'struct_amdsmi_gpu_metrics_t',
'struct_amdsmi_hsmp_metrics_table_t',
'struct_amdsmi_hsmp_metrics_table_t', 'struct_amdsmi_kfd_info_t',
'struct_amdsmi_link_id_bw_type_t', 'struct_amdsmi_link_metrics_t',
'struct_amdsmi_name_value_t', 'struct_amdsmi_od_vddc_point_t',
'struct_amdsmi_od_volt_curve_t',