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>


[ROCm/amdsmi commit: 03cfdeefd5]
Этот коммит содержится в:
Galantsev, Dmitrii
2023-08-28 18:42:12 -05:00
родитель 8d98bfe46d
Коммит 5ac201fe42
9 изменённых файлов: 449 добавлений и 543 удалений
+9 -4
Просмотреть файл
@@ -272,8 +272,10 @@ int main() {
CHK_AMDSMI_RET(ret)
printf(" Output of amdsmi_get_gpu_device_bdf:\n");
printf("\tDevice[%d] BDF %04lx:%02x:%02x.%d\n\n", i,
bdf.domain_number, bdf.bus_number, bdf.device_number,
bdf.function_number);
bdf.fields.domain_number,
bdf.fields.bus_number,
bdf.fields.device_number,
bdf.fields.function_number);
// Get handle from BDF
amdsmi_processor_handle dev_handle;
@@ -507,8 +509,11 @@ int main() {
uint64_t mem = 0, gtt_mem = 0, cpu_mem = 0, vram_mem = 0;
uint64_t gfx = 0, enc = 0;
char bdf_str[20];
sprintf(bdf_str, "%04lx:%02x:%02x.%d", bdf.domain_number,
bdf.bus_number, bdf.device_number, bdf.function_number);
sprintf(bdf_str, "%04lx:%02x:%02x.%d",
bdf.fields.domain_number,
bdf.fields.bus_number,
bdf.fields.device_number,
bdf.fields.function_number);
int num = 0;
ret = amdsmi_get_gpu_process_list(processor_handles[j], &num_process,
process_list);
+4 -2
Просмотреть файл
@@ -123,8 +123,10 @@ int main() {
CHK_AMDSMI_RET(ret)
printf(" Output of amdsmi_get_gpu_device_bdf:\n");
printf("\tDevice[%d] BDF %04lx:%02x:%02x.%d\n\n", i,
bdf.domain_number, bdf.bus_number, bdf.device_number,
bdf.function_number);
bdf.fields.domain_number,
bdf.fields.bus_number,
bdf.fields.device_number,
bdf.fields.function_number);
amdsmi_asic_info_t asic_info = {};
ret = amdsmi_get_gpu_asic_info(processor_handles[j], &asic_info);
+11 -11
Просмотреть файл
@@ -352,12 +352,12 @@ typedef struct {
} amdsmi_frequency_range_t;
typedef union {
struct {
struct fields_ {
uint64_t function_number : 3;
uint64_t device_number : 5;
uint64_t bus_number : 8;
uint64_t domain_number : 48;
};
} fields;
uint64_t as_uint;
} amdsmi_bdf_t;
@@ -380,7 +380,7 @@ typedef struct {
typedef struct {
uint8_t num_fw_info;
struct {
struct fw_info_list_ {
amdsmi_fw_block_t fw_id;
uint64_t fw_version;
uint64_t reserved[2];
@@ -439,15 +439,15 @@ typedef struct {
typedef uint32_t amdsmi_process_handle_t;
typedef struct {
char name[AMDSMI_NORMAL_STRING_LENGTH];
amdsmi_process_handle_t pid;
uint64_t mem; /** in bytes */
struct {
uint64_t gfx;
uint64_t enc;
char name[AMDSMI_NORMAL_STRING_LENGTH];
amdsmi_process_handle_t pid;
uint64_t mem; /** in bytes */
struct engine_usage_ {
uint64_t gfx;
uint64_t enc;
uint32_t reserved[12];
} engine_usage; /** How much time the process spend using these engines in ns */
struct {
} engine_usage; /** How much time the process spend using these engines in ns */
struct memory_usage_ {
uint64_t gtt_mem;
uint64_t cpu_mem;
uint64_t vram_mem;
+5 -5
Просмотреть файл
@@ -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
Просмотреть файл
@@ -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":
Разница между файлами не показана из-за своего большого размера Загрузить разницу
+4 -4
Просмотреть файл
@@ -1847,10 +1847,10 @@ amdsmi_status_t amdsmi_get_processor_handle_from_bdf(amdsmi_bdf_t bdf,
return status;
}
amdsmi_bdf_t found_bdf = gpu_device->get_bdf();
if (bdf.bus_number == found_bdf.bus_number &&
bdf.device_number == found_bdf.device_number &&
bdf.domain_number == found_bdf.domain_number &&
bdf.function_number == found_bdf.function_number) {
if ((bdf.fields.bus_number == found_bdf.fields.bus_number) &&
(bdf.fields.device_number == found_bdf.fields.device_number) &&
(bdf.fields.domain_number == found_bdf.fields.domain_number) &&
(bdf.fields.function_number == found_bdf.fields.function_number)) {
*processor_handle = devs[idx];
return AMDSMI_STATUS_SUCCESS;
}
+4 -4
Просмотреть файл
@@ -171,10 +171,10 @@ amdsmi_status_t AMDSmiDrm::init() {
continue;
}
bdf.function_number = device->businfo.pci->func;
bdf.device_number = device->businfo.pci->dev;
bdf.bus_number = device->businfo.pci->bus;
bdf.domain_number = device->businfo.pci->domain;
bdf.fields.function_number = device->businfo.pci->func;
bdf.fields.device_number = device->businfo.pci->dev;
bdf.fields.bus_number = device->businfo.pci->bus;
bdf.fields.domain_number = device->businfo.pci->domain;
vendor_id = device->deviceinfo.pci->vendor_id;
+10 -8
Просмотреть файл
@@ -73,10 +73,11 @@ amdsmi_status_t gpuvsmi_get_pids(const amdsmi_bdf_t &bdf, std::vector<long int>
struct dirent *dir;
/* 0000:00:00.0 */
snprintf(bdf_str, 13, "%04x:%02x:%02x.%d", bdf.domain_number & 0xffff,
bdf.bus_number & 0xff,
bdf.device_number & 0x1f,
bdf.function_number & 0x7);
snprintf(bdf_str, 13, "%04x:%02x:%02x.%d",
bdf.fields.domain_number & 0xffff,
bdf.fields.bus_number & 0xff,
bdf.fields.device_number & 0x1f,
bdf.fields.function_number & 0x7);
d = opendir("/proc");
if (!d)
@@ -121,10 +122,11 @@ amdsmi_status_t gpuvsmi_get_pid_info(const amdsmi_bdf_t &bdf, long int pid,
struct dirent *dir;
/* 0000:00:00.0 */
snprintf(bdf_str, 13, "%04x:%02x:%02x.%d", bdf.domain_number & 0xffff,
bdf.bus_number & 0xff,
bdf.device_number & 0x1f,
bdf.function_number & 0x7);
snprintf(bdf_str, 13, "%04x:%02x:%02x.%d",
bdf.fields.domain_number & 0xffff,
bdf.fields.bus_number & 0xff,
bdf.fields.device_number & 0x1f,
bdf.fields.function_number & 0x7);
std::string path = "/proc/" + std::to_string(pid) + "/fdinfo/";