From e2e63055a615172327c17928b71e37823aaf9a67 Mon Sep 17 00:00:00 2001 From: "Oliveira, Daniel" Date: Mon, 5 Aug 2024 17:15:42 -0500 Subject: [PATCH] SWDEV-463399: amdsmi_get_gpu_vram_info() adds bit-width Driver info `amdgpu_gpu_info.vram_bit_width` is exposed through amdsmi_get_gpu_vram_info(). Code changes related to the following: * API * CLI * Unit tests * Examples Change-Id: I8abd8db7a603078b2b1c008b2685cecf35caf3d2 Signed-off-by: Oliveira, Daniel [ROCm/amdsmi commit: 893f13ab988c7907365f7f1f165c3d4e99b56f96] --- projects/amdsmi/amdsmi_cli/amdsmi_commands.py | 6 +++++- projects/amdsmi/example/amd_smi_drm_example.cc | 14 ++++++++++++++ projects/amdsmi/include/amd_smi/amdsmi.h | 3 ++- projects/amdsmi/py-interface/amdsmi_interface.py | 1 + projects/amdsmi/py-interface/amdsmi_wrapper.py | 4 +++- projects/amdsmi/src/amd_smi/amd_smi.cc | 3 +++ .../tests/amd_smi_test/functional/id_info_read.cc | 10 ++++++++-- 7 files changed, 36 insertions(+), 5 deletions(-) diff --git a/projects/amdsmi/amdsmi_cli/amdsmi_commands.py b/projects/amdsmi/amdsmi_cli/amdsmi_commands.py index 80dbeac7f1..63e4298f9b 100644 --- a/projects/amdsmi/amdsmi_cli/amdsmi_commands.py +++ b/projects/amdsmi/amdsmi_cli/amdsmi_commands.py @@ -693,7 +693,8 @@ class AMDSMICommands(): if args.vram: vram_info_dict = {"type" : "N/A", "vendor" : "N/A", - "size" : "N/A"} + "size" : "N/A", + "bit_width" : "N/A"} try: vram_info = amdsmi_interface.amdsmi_get_gpu_vram_info(args.gpu) @@ -729,6 +730,9 @@ class AMDSMICommands(): vram_info_dict['size'] = {"value" : vram_info['vram_size'], "unit" : vram_size_unit} + # Populate bit width + vram_info_dict['bit_width'] = vram_info['vram_bit_width'] + except amdsmi_exception.AmdSmiLibraryException as e: logging.debug("Failed to get vram info for gpu %s | %s", gpu_id, e.get_error_info()) diff --git a/projects/amdsmi/example/amd_smi_drm_example.cc b/projects/amdsmi/example/amd_smi_drm_example.cc index 94179c47bc..9f3de13957 100644 --- a/projects/amdsmi/example/amd_smi_drm_example.cc +++ b/projects/amdsmi/example/amd_smi_drm_example.cc @@ -303,6 +303,20 @@ int main() { printf("\tRevisionID: 0x%x\n", asic_info.rev_id); printf("\tAsic serial: 0x%s\n\n", asic_info.asic_serial); + // Get VRAM info + amdsmi_vram_info_t vram_info = {}; + ret = amdsmi_get_gpu_vram_info(processor_handles[j], &vram_info); + if (ret != amdsmi_status_t::AMDSMI_STATUS_NOT_SUPPORTED) { + CHK_AMDSMI_RET(ret) + printf(" Output of amdsmi_get_gpu_vram_info:\n"); + printf("\tVRAM Size: 0x%lx (%ld) \n", vram_info.vram_size, vram_info.vram_size); + printf("\tBIT Width: 0x%x (%d) \n\n", vram_info.vram_bit_width, vram_info.vram_bit_width); + } + else { + printf("\t**amdsmi_get_gpu_vram_info() not supported on this system.\n"); + } + + // Get VBIOS info amdsmi_vbios_info_t vbios_info = {}; ret = amdsmi_get_gpu_vbios_info(processor_handles[j], &vbios_info); diff --git a/projects/amdsmi/include/amd_smi/amdsmi.h b/projects/amdsmi/include/amd_smi/amdsmi.h index 75afb7289c..f49636e675 100644 --- a/projects/amdsmi/include/amd_smi/amdsmi.h +++ b/projects/amdsmi/include/amd_smi/amdsmi.h @@ -616,7 +616,8 @@ typedef struct { amdsmi_vram_type_t vram_type; amdsmi_vram_vendor_type_t vram_vendor; uint64_t vram_size; - uint64_t reserved[6]; + uint32_t vram_bit_width; + uint64_t reserved[5]; } amdsmi_vram_info_t; diff --git a/projects/amdsmi/py-interface/amdsmi_interface.py b/projects/amdsmi/py-interface/amdsmi_interface.py index a7360b66fd..7ddb94d2ee 100644 --- a/projects/amdsmi/py-interface/amdsmi_interface.py +++ b/projects/amdsmi/py-interface/amdsmi_interface.py @@ -1770,6 +1770,7 @@ def amdsmi_get_gpu_vram_info( "vram_type": vram_info.vram_type, "vram_vendor": vram_info.vram_vendor, "vram_size": vram_info.vram_size, + "vram_bit_width": vram_info.vram_bit_width } diff --git a/projects/amdsmi/py-interface/amdsmi_wrapper.py b/projects/amdsmi/py-interface/amdsmi_wrapper.py index 77138d266a..1c7a4377d4 100644 --- a/projects/amdsmi/py-interface/amdsmi_wrapper.py +++ b/projects/amdsmi/py-interface/amdsmi_wrapper.py @@ -953,7 +953,9 @@ struct_amdsmi_vram_info_t._fields_ = [ ('vram_type', amdsmi_vram_type_t), ('vram_vendor', amdsmi_vram_vendor_type_t), ('vram_size', ctypes.c_uint64), - ('reserved', ctypes.c_uint64 * 6), + ('vram_bit_width', ctypes.c_uint32), + ('PADDING_0', ctypes.c_ubyte * 4), + ('reserved', ctypes.c_uint64 * 5), ] amdsmi_vram_info_t = struct_amdsmi_vram_info_t diff --git a/projects/amdsmi/src/amd_smi/amd_smi.cc b/projects/amdsmi/src/amd_smi/amd_smi.cc index 8e0905b5b2..9f4d3aa74a 100644 --- a/projects/amdsmi/src/amd_smi/amd_smi.cc +++ b/projects/amdsmi/src/amd_smi/amd_smi.cc @@ -55,6 +55,7 @@ #include #include #include +#include #include #include "amd_smi/amdsmi.h" #include "amd_smi/impl/fdinfo.h" @@ -799,6 +800,7 @@ amdsmi_status_t amdsmi_get_gpu_vram_info( info->vram_type = AMDSMI_VRAM_TYPE_UNKNOWN; info->vram_size = 0; info->vram_vendor = AMDSMI_VRAM_VENDOR__PLACEHOLDER0; + info->vram_bit_width = std::numeric_limitsvram_bit_width)>::max(); // Only can read vram type from libdrm if (gpu_device->check_if_drm_is_supported()) { @@ -808,6 +810,7 @@ amdsmi_status_t amdsmi_get_gpu_vram_info( sizeof(struct drm_amdgpu_info_device), &dev_info); if (r == AMDSMI_STATUS_SUCCESS) { info->vram_type = amd::smi::vram_type_value(dev_info.vram_type); + info->vram_bit_width = dev_info.vram_bit_width; } } diff --git a/projects/amdsmi/tests/amd_smi_test/functional/id_info_read.cc b/projects/amdsmi/tests/amd_smi_test/functional/id_info_read.cc index d6e208fbdd..322da175c3 100755 --- a/projects/amdsmi/tests/amd_smi_test/functional/id_info_read.cc +++ b/projects/amdsmi/tests/amd_smi_test/functional/id_info_read.cc @@ -154,8 +154,14 @@ void TestIdInfoRead::Run(void) { << vram_info.vram_type << std::endl; std::cout << "\t**Device Vram vendor id: " << vram_info.vram_vendor << std::endl; - std::cout << "\t**Device Vram size: " - << vram_info.vram_size << std::endl; + std::cout << "\t**Device Vram size: 0x" + << std::hex << vram_info.vram_size + << " (" << std::dec << vram_info.vram_size << ")" + << std::endl; + std::cout << "\t**Device Bit Width: 0x" + << std::hex << vram_info.vram_bit_width + << " (" << std::dec << vram_info.vram_bit_width << ")" + << std::endl; } err = amdsmi_get_gpu_vendor_name(processor_handles_[i], buffer, kBufferLen);