Update amdsmi_wrapper.py and name fields

When updating the wrapper I ran into an issue with anonymous structs.
Generated wrapper would contain a string split into multiple lines,
which is invalid python.

e.g.
    'struct_struct anonymous
    (struct.... amdsmi.h:355)'

After naming the structs - the issue is gone. BDF union now has to be
addressed with .fields

e.g.
    OLD: bdf.function_number
    NEW: bdf.fields.function_number

Change-Id: Ib3c640c088ad0cc67893d636827356902051f17f
Signed-off-by: Galantsev, Dmitrii <dmitrii.galantsev@amd.com>
This commit is contained in:
Galantsev, Dmitrii
2023-08-28 18:42:12 -05:00
parent 1d24dd93a6
commit 03cfdeefd5
9 changed files with 449 additions and 543 deletions
+5 -5
View File
@@ -1,7 +1,6 @@
# Generate py-interface and package targets
# match this version to your clang
# too new won't work, too old won't work either
# CLANG installed must be 14.0 or above
set(clang_ver 14.0)
set(ctypeslib_ver 2.3.2)
@@ -12,7 +11,6 @@ set(PY_PACKAGE_DIR "${PY_BUILD_DIR}/amdsmi")
set(PY_WRAPPER_INSTALL_DIR "${SHARE_INSTALL_PREFIX}" CACHE STRING "Wrapper installation directory")
# TODO: Figure out how python-clang and clang are related
# Currently only a very specific combination works
# try to find clang of the right version
set(GOOD_CLANG_FOUND FALSE)
@@ -22,7 +20,7 @@ if(BUILD_WRAPPER)
# extract clang version manually because find_package(clang) doesn't work
execute_process(COMMAND ${clang} --version OUTPUT_VARIABLE clang_full_version_string)
string (REGEX REPLACE ".*clang version ([0-9]+\\.[0-9]+).*" "\\1" CLANG_VERSION_STRING ${clang_full_version_string})
if(CLANG_VERSION_STRING VERSION_EQUAL clang_ver)
if((CLANG_VERSION_STRING VERSION_GREATER clang_ver) OR (CLANG_VERSION_STRING VERSION_EQUAL clang_ver))
message("GOOD CLANG VERSION: ${CLANG_VERSION_STRING}")
set(GOOD_CLANG_FOUND TRUE)
else()
@@ -47,9 +45,11 @@ if(NOT GOOD_CLANG_FOUND)
COMMAND ln -Pf ${CMAKE_CURRENT_BINARY_DIR}/amdsmi_wrapper.py ${PY_PACKAGE_DIR}/)
else()
find_package(Python3 3.7 COMPONENTS Interpreter Development REQUIRED)
# --break-system-packages is needed for python 3.11
# see: https://peps.python.org/pep-0668/
add_custom_target(
python_pre_reqs
COMMAND ${Python3_EXECUTABLE} -m pip install clang==${clang_ver} ctypeslib2==${ctypeslib_ver})
COMMAND ${Python3_EXECUTABLE} -m pip install --break-system-packages clang==${clang_ver} ctypeslib2==${ctypeslib_ver})
# generate new wrapper
configure_file(${PROJECT_SOURCE_DIR}/tools/generator.py generator.py @ONLY COPYONLY)
add_custom_command(
+10 -53
View File
@@ -445,10 +445,10 @@ def _format_bdf(amdsmi_bdf: amdsmi_wrapper.amdsmi_bdf_t) -> str:
Returns:
`str`: String containing BDF data in a readable format.
"""
domain = hex(amdsmi_bdf.c__UA_amdsmi_bdf_t_0.domain_number)[2:].zfill(4)
bus = hex(amdsmi_bdf.c__UA_amdsmi_bdf_t_0.bus_number)[2:].zfill(2)
device = hex(amdsmi_bdf.c__UA_amdsmi_bdf_t_0.device_number)[2:].zfill(2)
function = hex(amdsmi_bdf.c__UA_amdsmi_bdf_t_0.function_number)[2:]
domain = hex(amdsmi_bdf.fields.domain_number)[2:].zfill(4)
bus = hex(amdsmi_bdf.fields.bus_number)[2:].zfill(2)
device = hex(amdsmi_bdf.fields.device_number)[2:].zfill(2)
function = hex(amdsmi_bdf.fields.function_number)[2:]
return domain + ":" + bus + ":" + device + "." + function
@@ -495,10 +495,10 @@ def _make_amdsmi_bdf_from_list(bdf):
if len(bdf) != 4:
return None
amdsmi_bdf = amdsmi_wrapper.amdsmi_bdf_t()
amdsmi_bdf.c__UA_amdsmi_bdf_t_0.function_number = bdf[3]
amdsmi_bdf.c__UA_amdsmi_bdf_t_0.device_number = bdf[2]
amdsmi_bdf.c__UA_amdsmi_bdf_t_0.bus_number = bdf[1]
amdsmi_bdf.c__UA_amdsmi_bdf_t_0.domain_number = bdf[0]
amdsmi_bdf.fields.function_number = bdf[3]
amdsmi_bdf.fields.device_number = bdf[2]
amdsmi_bdf.fields.bus_number = bdf[1]
amdsmi_bdf.fields.domain_number = bdf[0]
return amdsmi_bdf
@@ -1422,32 +1422,6 @@ def amdsmi_set_gpu_perf_level(
processor_handle, perf_level))
def amdsmi_get_gpu_power_profile_presets(
processor_handle: amdsmi_wrapper.amdsmi_processor_handle, sensor_idx: int
) -> Dict[str, Any]:
if not isinstance(processor_handle, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(
processor_handle, amdsmi_wrapper.amdsmi_processor_handle
)
if not isinstance(sensor_idx, int):
raise AmdSmiParameterException(sensor_idx, int)
sensor_idx = ctypes.c_uint32(sensor_idx)
status = amdsmi_wrapper.amdsmi_power_profile_status_t()
_check_res(
amdsmi_wrapper.amdsmi_get_gpu_power_profile_presets(
processor_handle, sensor_idx, ctypes.byref(status)
)
)
return {
"available_profiles": status.available_profiles,
"current": status.current,
"num_profiles": status.num_profiles,
}
def amdsmi_reset_gpu(processor_handle: amdsmi_wrapper.amdsmi_processor_handle):
if not isinstance(processor_handle, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(
@@ -1457,23 +1431,6 @@ def amdsmi_reset_gpu(processor_handle: amdsmi_wrapper.amdsmi_processor_handle):
_check_res(amdsmi_wrapper.amdsmi_reset_gpu(processor_handle))
def amdsmi_set_gpu_perf_determinism_mode(
processor_handle: amdsmi_wrapper.amdsmi_processor_handle, clock_value: int
):
if not isinstance(processor_handle, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(
processor_handle, amdsmi_wrapper.amdsmi_processor_handle
)
if not isinstance(clock_value, int):
raise AmdSmiParameterException(clock_value, int)
clock_value = ctypes.c_uint64(clock_value)
_check_res(
amdsmi_wrapper.amdsmi_set_gpu_perf_determinism_mode(
processor_handle, clock_value)
)
def amdsmi_set_gpu_fan_speed(
processor_handle: amdsmi_wrapper.amdsmi_processor_handle, sensor_idx: int, fan_speed: int
):
@@ -1998,7 +1955,7 @@ def amdsmi_get_utilization_count(
result = [{"timestamp": timestamp.value}]
for idx in range(count.value):
counter_type = amdsmi_wrapper.c__EA_AMDSMI_UTILIZATION_COUNTER_TYPE__enumvalues[
counter_type = amdsmi_wrapper.AMDSMI_UTILIZATION_COUNTER_TYPE__enumvalues[
util_counter_list[idx].type
]
if counter_type == "AMDSMI_UTILIZATION_COUNTER_LAST":
@@ -2024,7 +1981,7 @@ def amdsmi_get_gpu_perf_level(
processor_handle, ctypes.byref(perf))
)
result = amdsmi_wrapper.c__EA_amdsmi_dev_perf_level_t__enumvalues[perf.value]
result = amdsmi_wrapper.amdsmi_dev_perf_level_t__enumvalues[perf.value]
if result == "AMDSMI_DEV_PERF_LEVEL_FIRST":
result = "AMDSMI_DEV_PERF_LEVEL_AUTO"
if result == "AMDSMI_DEV_PERF_LEVEL_LAST":
File diff suppressed because it is too large Load Diff