From af4f954ae8ef38099439fc7efb6cf08f63ea00ac Mon Sep 17 00:00:00 2001 From: Maisam Arif Date: Tue, 26 Sep 2023 19:13:31 -0500 Subject: [PATCH 01/16] Made driver N/A population consistent Signed-off-by: Maisam Arif Change-Id: I4bd6d6f9729e62447ad765acc4908f124046e861 --- amdsmi_cli/amdsmi_commands.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/amdsmi_cli/amdsmi_commands.py b/amdsmi_cli/amdsmi_commands.py index 8e7d901789..fa3cfbe14a 100644 --- a/amdsmi_cli/amdsmi_commands.py +++ b/amdsmi_cli/amdsmi_commands.py @@ -390,14 +390,15 @@ class AMDSMICommands(): static_dict['limit'] = limit_info if args.driver: + driver_info = {"driver_version" : "N/A", + "driver_date" : "N/A"} + try: - driver_info = {} driver_info = amdsmi_interface.amdsmi_get_gpu_driver_info(args.gpu) - static_dict['driver'] = driver_info except amdsmi_exception.AmdSmiLibraryException as e: - static_dict['driver'] = "N/A" logging.debug("Failed to get driver info for gpu %s | %s", gpu_id, e.get_error_info()) + static_dict['driver'] = driver_info if self.helpers.is_hypervisor() or self.helpers.is_baremetal(): if args.ras: try: From 016dbf8aa3cc61af4efe55b13cfb674a828d9e04 Mon Sep 17 00:00:00 2001 From: "Bill(Shuzhou) Liu" Date: Tue, 26 Sep 2023 10:26:06 -0500 Subject: [PATCH 02/16] Do not print the library name if in default folder The rocm-smi python tool will not print the library name on default folder. Change-Id: I203a872ebe2fc994766a2628049ca50c8bfa7120 --- python_smi_tools/rsmiBindings.py.in | 2 -- 1 file changed, 2 deletions(-) diff --git a/python_smi_tools/rsmiBindings.py.in b/python_smi_tools/rsmiBindings.py.in index 36dbb6e5ff..87c32a8fc9 100644 --- a/python_smi_tools/rsmiBindings.py.in +++ b/python_smi_tools/rsmiBindings.py.in @@ -37,8 +37,6 @@ def initRsmiBindings(silent=False): print_silent('Using lib from %s' % path_librocm) else: print('Unable to find librocm_smi64.so.@VERSION_MAJOR@') - else: - print_silent('Library loaded from: %s ' % path_librocm) # ----------> TODO: Support static libs as well as SO try: From 3fa96a9e022844a842ad3afdef576e6c872b1aa9 Mon Sep 17 00:00:00 2001 From: Maisam Arif Date: Wed, 27 Sep 2023 02:37:46 -0500 Subject: [PATCH 03/16] Updated Driver Error Logging & Exceptions Change-Id: Idd14904b33e82e4cb5d9f84c75978fe686a9b603 Signed-off-by: Maisam Arif --- amdsmi_cli/amdsmi_cli.py | 10 +++++++++- amdsmi_cli/amdsmi_commands.py | 8 +++++++- amdsmi_cli/amdsmi_helpers.py | 13 +++++++++++-- amdsmi_cli/amdsmi_init.py | 32 ++++++++++++++++++-------------- py-interface/amdsmi_exception.py | 2 +- 5 files changed, 46 insertions(+), 19 deletions(-) diff --git a/amdsmi_cli/amdsmi_cli.py b/amdsmi_cli/amdsmi_cli.py index d1232b2b26..3a88ae5acc 100755 --- a/amdsmi_cli/amdsmi_cli.py +++ b/amdsmi_cli/amdsmi_cli.py @@ -42,6 +42,12 @@ def _print_error(e, destination): if __name__ == "__main__": + # Disable traceback before possible init errors in AMDSMICommands and AMDSMIParser + if "DEBUG" in sys.argv: + sys.tracebacklimit = 10 + else: + sys.tracebacklimit = -1 + amd_smi_commands = AMDSMICommands() amd_smi_parser = AMDSMIParser(amd_smi_commands.version, amd_smi_commands.list, @@ -80,7 +86,9 @@ if __name__ == "__main__": logging.basicConfig(format='%(levelname)s: %(message)s', level=logging_dict[args.loglevel]) # Disable traceback for non-debug log levels - if args.loglevel != "DEBUG": + if args.loglevel == "DEBUG": + sys.tracebacklimit = 10 + else: sys.tracebacklimit = -1 # Execute subcommands diff --git a/amdsmi_cli/amdsmi_commands.py b/amdsmi_cli/amdsmi_commands.py index fa3cfbe14a..a4f2aee64c 100644 --- a/amdsmi_cli/amdsmi_commands.py +++ b/amdsmi_cli/amdsmi_commands.py @@ -21,6 +21,7 @@ # import logging +import sys import threading import time @@ -42,7 +43,12 @@ class AMDSMICommands(): try: self.device_handles = amdsmi_interface.amdsmi_get_processor_handles() except amdsmi_exception.AmdSmiLibraryException as e: - raise e + if e.err_code in (amdsmi_interface.amdsmi_wrapper.AMDSMI_STATUS_NOT_INIT, + amdsmi_interface.amdsmi_wrapper.AMDSMI_STATUS_DRIVER_NOT_LOADED): + logging.error('Unable to get devices, driver not initialized (amdgpu not found in modules)') + sys.exit(-1) + else: + raise e self.stop = '' self.all_arguments = False diff --git a/amdsmi_cli/amdsmi_helpers.py b/amdsmi_cli/amdsmi_helpers.py index 8b88c10c05..f4914e01a4 100644 --- a/amdsmi_cli/amdsmi_helpers.py +++ b/amdsmi_cli/amdsmi_helpers.py @@ -141,8 +141,17 @@ class AMDSMIHelpers(): gpu_choices = {} gpu_choices_str = "" - # amdsmi_get_processor_handles returns the device_handles storted for gpu_id - device_handles = amdsmi_interface.amdsmi_get_processor_handles() + try: + # amdsmi_get_processor_handles returns the device_handles storted for gpu_id + device_handles = amdsmi_interface.amdsmi_get_processor_handles() + except amdsmi_interface.AmdSmiLibraryException as e: + if e.err_code in (amdsmi_interface.amdsmi_wrapper.AMDSMI_STATUS_NOT_INIT, + amdsmi_interface.amdsmi_wrapper.AMDSMI_STATUS_DRIVER_NOT_LOADED): + logging.error('Unable to get device choices, driver not initialized (amdgpu not found in modules)') + sys.exit(-1) + else: + raise e + for gpu_id, device_handle in enumerate(device_handles): bdf = amdsmi_interface.amdsmi_get_gpu_device_bdf(device_handle) uuid = amdsmi_interface.amdsmi_get_gpu_device_uuid(device_handle) diff --git a/amdsmi_cli/amdsmi_init.py b/amdsmi_cli/amdsmi_init.py index 7e837026cc..a1cb955d02 100644 --- a/amdsmi_cli/amdsmi_init.py +++ b/amdsmi_cli/amdsmi_init.py @@ -36,9 +36,9 @@ from amdsmi import amdsmi_interface from amdsmi import amdsmi_exception # Using basic python logging for user errors and development -logging.basicConfig(format='%(levelname)s: %(message)s', level=logging.ERROR) # User level logging +logging.basicConfig(format="%(levelname)s: %(message)s", level=logging.ERROR) # User level logging # This traceback limit only affects this file, once the code hit's the cli portion it get's reset to the user's preference -sys.tracebacklimit = -1 # Disable traceback for user errors +sys.tracebacklimit = -1 # Disable traceback when raising errors # On initial import set initialized variable AMDSMI_INITIALIZED = False @@ -47,11 +47,9 @@ AMD_VENDOR_ID = 4098 def check_amdgpu_driver(): """ Returns true if amdgpu is found in the list of initialized modules """ amd_gpu_status_file = Path("/sys/module/amdgpu/initstate") - if amd_gpu_status_file.exists(): - if amd_gpu_status_file.read_text(encoding='ascii').strip() == 'live': + if amd_gpu_status_file.read_text(encoding="ascii").strip() == "live": return True - return False @@ -61,17 +59,22 @@ def init_amdsmi(flag=amdsmi_interface.AmdSmiInitFlags.INIT_AMD_GPUS): Raises: err: AmdSmiLibraryException if not successful """ - # Check if amdgpu driver is up & Handle error gracefully + # # Check if amdgpu driver is up & Handle error gracefully if check_amdgpu_driver(): # Only init AMD GPUs for now, waiting for future support for AMD CPUs try: amdsmi_interface.amdsmi_init(flag) - except (amdsmi_interface.AmdSmiLibraryException, amdsmi_interface.AmdSmiParameterException) as err: - raise err - logging.debug('AMDSMI initialized successfully') + except (amdsmi_interface.AmdSmiLibraryException, amdsmi_interface.AmdSmiParameterException) as e: + if e.err_code in (amdsmi_interface.amdsmi_wrapper.AMDSMI_STATUS_NOT_INIT, + amdsmi_interface.amdsmi_wrapper.AMDSMI_STATUS_DRIVER_NOT_LOADED): + logging.error("Driver not loaded (amdgpu not found in modules)") + sys.exit(-1) + else: + raise e + logging.debug("AMDSMI initialized successfully, but initstate was not live") else: - logging.error('Driver not initialized (amdgpu not found in modules)') - exit(-1) + logging.error("Driver not found (amdgpu not found in modules)") + sys.exit(-1) def shut_down_amdsmi(): @@ -82,12 +85,13 @@ def shut_down_amdsmi(): """ try: amdsmi_interface.amdsmi_shut_down() - except amdsmi_exception.AmdSmiLibraryException as err: - raise err + except amdsmi_exception.AmdSmiLibraryException as e: + logging.error("Unable to cleanly shut down amd-smi-lib") + raise e def signal_handler(sig, frame): - logging.debug(f'Handling signal: {sig}') + logging.debug(f"Handling signal: {sig}") sys.exit(0) diff --git a/py-interface/amdsmi_exception.py b/py-interface/amdsmi_exception.py index 162e4f7a00..309831101b 100644 --- a/py-interface/amdsmi_exception.py +++ b/py-interface/amdsmi_exception.py @@ -72,7 +72,7 @@ class AmdSmiLibraryException(AmdSmiException): amdsmi_wrapper.AMDSMI_STATUS_NOT_FOUND : "AMDSMI_STATUS_NOT_FOUND - Device Not found", amdsmi_wrapper.AMDSMI_STATUS_NOT_INIT : "AMDSMI_STATUS_NOT_INIT - Device not initialized", amdsmi_wrapper.AMDSMI_STATUS_NO_SLOT : "AMDSMI_STATUS_NO_SLOT - No more free slot", - amdsmi_wrapper.AMDSMI_STATUS_DRIVER_NOT_LOADED : "AMDSMI_STATUS_DRIVER_NOT_LOADED - Processor driver not loaded", + amdsmi_wrapper.AMDSMI_STATUS_DRIVER_NOT_LOADED : "AMDSMI_STATUS_DRIVER_NOT_LOADED - Driver not loaded", amdsmi_wrapper.AMDSMI_STATUS_NO_DATA : "AMDSMI_STATUS_NO_DATA - No data was found for given input", amdsmi_wrapper.AMDSMI_STATUS_INSUFFICIENT_SIZE : "AMDSMI_STATUS_INSUFFICIENT_SIZE - Insufficient size for operation", amdsmi_wrapper.AMDSMI_STATUS_UNEXPECTED_SIZE : "AMDSMI_STATUS_UNEXPECTED_SIZE - unexpected size of data was read", From 9eccf20f0cea9b828a5777573d9bd206fcba50ab Mon Sep 17 00:00:00 2001 From: "Bill(Shuzhou) Liu" Date: Wed, 27 Sep 2023 12:40:53 -0500 Subject: [PATCH 04/16] Get PCIe slot type Add API to get the PCIe slot type. Change-Id: If6894af53894c524d61c7586c59768541bbf0ac6 --- example/amd_smi_drm_example.cc | 7 ++++--- include/amd_smi/amdsmi.h | 1 + py-interface/amdsmi_interface.py | 6 ++++-- py-interface/amdsmi_wrapper.py | 1 + src/amd_smi/amd_smi.cc | 30 ++++++++++++++++++++++++++++++ 5 files changed, 40 insertions(+), 5 deletions(-) diff --git a/example/amd_smi_drm_example.cc b/example/amd_smi_drm_example.cc index 09ae1144ee..1ac45844b6 100644 --- a/example/amd_smi_drm_example.cc +++ b/example/amd_smi_drm_example.cc @@ -380,8 +380,9 @@ int main() { CHK_AMDSMI_RET(ret) printf(" Output of amdsmi_get_pcie_link_status:\n"); printf("\tPCIe lanes: %d\n", pcie_info.pcie_lanes); - printf("\tPCIe speed: %d\n\n", pcie_info.pcie_speed); - printf("\tPCIe Interface Version: %d\n\n", pcie_info.pcie_interface_version); + printf("\tPCIe speed: %d\n", pcie_info.pcie_speed); + printf("\tPCIe Interface Version: %d\n", pcie_info.pcie_interface_version); + printf("\tPCIe slot type: %d\n\n", pcie_info.pcie_slot_type); // Get PCIe caps amdsmi_pcie_info_t pcie_caps_info = {}; @@ -389,7 +390,7 @@ int main() { CHK_AMDSMI_RET(ret) printf(" Output of amdsmi_get_pcie_link_caps:\n"); printf("\tPCIe max lanes: %d\n", pcie_caps_info.pcie_lanes); - printf("\tPCIe max speed: %d\n\n", pcie_caps_info.pcie_speed); + printf("\tPCIe max speed: %d\n", pcie_caps_info.pcie_speed); printf("\tPCIe Interface Version: %d\n\n", pcie_caps_info.pcie_interface_version); // Get VRAM temperature limit diff --git a/include/amd_smi/amdsmi.h b/include/amd_smi/amdsmi.h index 4f8f2536f1..66ec6dae2d 100644 --- a/include/amd_smi/amdsmi.h +++ b/include/amd_smi/amdsmi.h @@ -1157,6 +1157,7 @@ typedef struct { uint16_t pcie_lanes; uint32_t pcie_speed; uint32_t pcie_interface_version; + uint32_t pcie_slot_type; // 0: PCIE, 1: CEM, 2: OAM, 3: Reserved uint32_t reserved[5]; } amdsmi_pcie_info_t; /** diff --git a/py-interface/amdsmi_interface.py b/py-interface/amdsmi_interface.py index 9731bf6c65..74a8e23aeb 100644 --- a/py-interface/amdsmi_interface.py +++ b/py-interface/amdsmi_interface.py @@ -1061,7 +1061,8 @@ def amdsmi_get_pcie_link_status( return {"pcie_speed": pcie_info.pcie_speed, "pcie_lanes": pcie_info.pcie_lanes, - "pcie_interface_version": pcie_info.pcie_interface_version} + "pcie_interface_version": pcie_info.pcie_interface_version, + "pcie_slot_type": pcie_info.pcie_slot_type} def amdsmi_get_pcie_link_caps( processor_handle: amdsmi_wrapper.amdsmi_processor_handle, @@ -1079,7 +1080,8 @@ def amdsmi_get_pcie_link_caps( return {"max_pcie_speed": pcie_info.pcie_speed, "max_pcie_lanes": pcie_info.pcie_lanes, - "pcie_interface_version": pcie_info.pcie_interface_version} + "pcie_interface_version": pcie_info.pcie_interface_version, + "pcie_slot_type": pcie_info.pcie_slot_type} def amdsmi_get_processor_handle_from_bdf(bdf): diff --git a/py-interface/amdsmi_wrapper.py b/py-interface/amdsmi_wrapper.py index 2c0fcfe1ab..a948f31c3d 100644 --- a/py-interface/amdsmi_wrapper.py +++ b/py-interface/amdsmi_wrapper.py @@ -1433,6 +1433,7 @@ struct_amdsmi_pcie_info_t._fields_ = [ ('PADDING_0', ctypes.c_ubyte * 2), ('pcie_speed', ctypes.c_uint32), ('pcie_interface_version', ctypes.c_uint32), + ('pcie_slot_type', ctypes.c_uint32), ('reserved', ctypes.c_uint32 * 5), ] diff --git a/src/amd_smi/amd_smi.cc b/src/amd_smi/amd_smi.cc index f6a3fbef4c..66daf32be0 100644 --- a/src/amd_smi/amd_smi.cc +++ b/src/amd_smi/amd_smi.cc @@ -1813,6 +1813,23 @@ amdsmi_get_pcie_link_status(amdsmi_processor_handle processor_handle, amdsmi_pci info->pcie_interface_version = 0; } + // default to PCIe + info->pcie_slot_type = 0; + amd::smi::AMDSmiGPUDevice* gpu_device = nullptr; + status = get_gpu_device_from_handle( + processor_handle, &gpu_device); + if (status == AMDSMI_STATUS_SUCCESS + && gpu_device->check_if_drm_is_supported()) { + struct drm_amdgpu_info_device dev_info = {}; + status = gpu_device->amdgpu_query_info(AMDGPU_INFO_DEV_INFO, + sizeof(struct drm_amdgpu_memory_info), &dev_info); + // bits [16:17] in ids_flags field as slot type + if (status == AMDSMI_STATUS_SUCCESS) { + // two bits starts with index 16 + info->pcie_slot_type = (dev_info.ids_flags >> 16) & 0x03; + } + } + return status; } @@ -1887,6 +1904,19 @@ amdsmi_status_t amdsmi_get_pcie_link_caps(amdsmi_processor_handle processor_hand info->pcie_interface_version = 0; } + // default to PCIe + info->pcie_slot_type = 0; + if (gpu_device->check_if_drm_is_supported()) { + struct drm_amdgpu_info_device dev_info = {}; + status = gpu_device->amdgpu_query_info(AMDGPU_INFO_DEV_INFO, + sizeof(struct drm_amdgpu_memory_info), &dev_info); + // bits [16:17] in ids_flags field as slot type + if (status == AMDSMI_STATUS_SUCCESS) { + // two bits starts with index 16 + info->pcie_slot_type = (dev_info.ids_flags >> 16) & 0x03; + } + } + return status; } From cf6bcbbb275f652796228f8213e80b9bd02e9218 Mon Sep 17 00:00:00 2001 From: "Galantsev, Dmitrii" Date: Wed, 27 Sep 2023 17:47:59 -0500 Subject: [PATCH 05/16] Upgrade to CXX-17 gtest-1.14 and cmake-3.14 Also change the TARGET from amd_smi_libraries to rocm_smi_libraries This helps reduce confusion between rocm-smi and amd-smi Change-Id: Ie54cedd831ba24bd9afc341ad15b7e8e20732059 Signed-off-by: Galantsev, Dmitrii --- CMakeLists.txt | 24 ++++++++++---------- tests/rocm_smi_test/CMakeLists.txt | 35 +++++++++++++----------------- 2 files changed, 28 insertions(+), 31 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index dd4c5d53f2..a16e48ba7f 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,11 +1,11 @@ # -# Minimum version of cmake required +# Minimum version of cmake and C++ required # -cmake_minimum_required(VERSION 3.6.3) +cmake_minimum_required(VERSION 3.14) -set(AMD_SMI_LIBS_TARGET "amd_smi_libraries") +set(ROCM_SMI_LIBS_TARGET "rocm_smi_libraries") -set ( BUILD_SHARED_LIBS ON CACHE BOOL "Build shared library (.so) or not.") +set(BUILD_SHARED_LIBS ON CACHE BOOL "Build shared library (.so) or not.") ## Set default module path if not already set if(NOT DEFINED CMAKE_MODULE_PATH) @@ -37,10 +37,10 @@ find_program (GIT NAMES git) set(PKG_VERSION_GIT_TAG_PREFIX "rsmi_pkg_ver") get_package_version_number("5.0.0" ${PKG_VERSION_GIT_TAG_PREFIX} GIT) message("Package version: ${PKG_VERSION_STR}") -set(${AMD_SMI_LIBS_TARGET}_VERSION_MAJOR "${VERSION_MAJOR}") -set(${AMD_SMI_LIBS_TARGET}_VERSION_MINOR "${VERSION_MINOR}") -set(${AMD_SMI_LIBS_TARGET}_VERSION_PATCH "0") -set(${AMD_SMI_LIBS_TARGET}_VERSION_BUILD "0") +set(${ROCM_SMI_LIBS_TARGET}_VERSION_MAJOR "${VERSION_MAJOR}") +set(${ROCM_SMI_LIBS_TARGET}_VERSION_MINOR "${VERSION_MINOR}") +set(${ROCM_SMI_LIBS_TARGET}_VERSION_PATCH "0") +set(${ROCM_SMI_LIBS_TARGET}_VERSION_BUILD "0") # The following default version values should be updated as appropriate for # ABI breaks (update MAJOR and MINOR), and ABI/API additions (update MINOR). @@ -57,7 +57,9 @@ set(CMAKE_INSTALL_PREFIX "/opt/rocm" CACHE STRING "Default installation director set(COMMON_SRC_ROOT ${CMAKE_CURRENT_SOURCE_DIR} CACHE STRING "Location source code common root.") set(ROCM_SMI_PACKAGE rocm-smi-lib) -project(${AMD_SMI_LIBS_TARGET}) +project(${ROCM_SMI_LIBS_TARGET}) +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) include(GNUInstallDirs) set(COMMON_PROJ_ROOT ${PROJECT_SOURCE_DIR}) @@ -70,7 +72,7 @@ endif() ## Compiler flags set(CMAKE_CXX_FLAGS - "${CMAKE_CXX_FLAGS} -Wall -Wextra -fno-rtti -m64 -msse -msse2 -std=c++11 ") + "${CMAKE_CXX_FLAGS} -Wall -Wextra -fno-rtti -m64 -msse -msse2 ") # Security options set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wconversion -Wcast-align ") @@ -78,7 +80,7 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wformat=2 -fno-common -Wstrict-overflow ") # Intentionally leave out -Wsign-promo. It causes spurious warnings. set(CMAKE_CXX_FLAGS - "${CMAKE_CXX_FLAGS} -Woverloaded-virtual -Wreorder ") + "${CMAKE_CXX_FLAGS} -Woverloaded-virtual -Wreorder ") # Clang does not set the build-id if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang") diff --git a/tests/rocm_smi_test/CMakeLists.txt b/tests/rocm_smi_test/CMakeLists.txt index efdbe96469..2253327813 100755 --- a/tests/rocm_smi_test/CMakeLists.txt +++ b/tests/rocm_smi_test/CMakeLists.txt @@ -36,24 +36,13 @@ set(CMAKE_INSTALL_RPATH ${CMAKE_INSTALL_RPATH} ${RSMITST_RPATH}) -# TODO: Try to find googletest -# DISABLED because we want to install gtest with rocm_smi_lib ourselves -#find_package(GTest 1.12.0) - -# GTest_FOUND is set to TRUE if ANY version is found -# GTest_VERSION is set if 1.12.0 or newer version is found -if(NOT GTest_FOUND STREQUAL "TRUE" OR NOT DEFINED GTest_VERSION) - # Google Test wasn't found. Download and compile ourselves - include(FetchContent) - FetchContent_Declare( - googletest - GIT_REPOSITORY https://github.com/google/googletest.git - GIT_TAG release-1.12.0) - FetchContent_MakeAvailable(googletest) - install(TARGETS gtest gtest_main - DESTINATION ${SHARE_INSTALL_PREFIX}/rsmitst_tests - COMPONENT ${TESTS_COMPONENT}) -endif() +# Download and compile googletest +include(FetchContent) +FetchContent_Declare( + googletest + GIT_REPOSITORY https://github.com/google/googletest.git + GIT_TAG v1.14.0) +FetchContent_MakeAvailable(googletest) # Other source directories aux_source_directory(${SRC_DIR}/functional functionalSources) @@ -70,13 +59,13 @@ target_include_directories(${RSMITST} PUBLIC ${SRC_DIR}/..) target_link_libraries( ${RSMITST} PUBLIC ${ROCM_SMI_TARGET} - PUBLIC gtest - PUBLIC gtest_main + PUBLIC GTest::gtest_main PUBLIC c PUBLIC stdc++ PUBLIC pthread PUBLIC dl) +# install tests install(TARGETS ${RSMITST} DESTINATION ${SHARE_INSTALL_PREFIX}/rsmitst_tests COMPONENT ${TESTS_COMPONENT}) @@ -84,3 +73,9 @@ install(TARGETS ${RSMITST} install(FILES rsmitst.exclude DESTINATION ${SHARE_INSTALL_PREFIX}/rsmitst_tests COMPONENT ${TESTS_COMPONENT}) + +# install googletest libraries with tests +install(TARGETS gtest gtest_main + DESTINATION ${SHARE_INSTALL_PREFIX}/rsmitst_tests + COMPONENT ${TESTS_COMPONENT}) + From 871fae8b2504de345f476b39e07826a581db95ab Mon Sep 17 00:00:00 2001 From: "Galantsev, Dmitrii" Date: Wed, 27 Sep 2023 17:58:50 -0500 Subject: [PATCH 06/16] Upgrade to CXX-17 gtest-1.14 and cmake-3.14 Change-Id: I3bceb90f79235a9c0616c5d7ef9e37e458ffdce6 Signed-off-by: Galantsev, Dmitrii --- CMakeLists.txt | 6 ++++-- example/CMakeLists.txt.in | 8 +++----- tests/amd_smi_test/CMakeLists.txt | 32 +++++++++++++++---------------- 3 files changed, 22 insertions(+), 24 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 97fa12d871..ef5b8756d2 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,7 @@ # # Minimum version of cmake required # -cmake_minimum_required(VERSION 3.11) +cmake_minimum_required(VERSION 3.14) set(AMD_SMI "amd_smi") set(AMD_SMI_COMPONENT "lib${AMD_SMI}") @@ -49,6 +49,8 @@ set(AMD_SMI_PACKAGE CACHE STRING "") project(${AMD_SMI_LIBS_TARGET}) +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) include(GNUInstallDirs) @@ -78,7 +80,7 @@ set(CPACK_PACKAGE_DESCRIPTION_SUMMARY generic_package() ## Compiler flags -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -fno-rtti -m64 -msse -msse2 -std=c++11") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -fno-rtti -m64 -msse -msse2") # Security options set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wconversion -Wcast-align") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wformat=2 -fno-common -Wstrict-overflow") diff --git a/example/CMakeLists.txt.in b/example/CMakeLists.txt.in index c4c4c6a854..589fcd6c3e 100644 --- a/example/CMakeLists.txt.in +++ b/example/CMakeLists.txt.in @@ -1,13 +1,11 @@ -cmake_minimum_required(VERSION 3.11) +cmake_minimum_required(VERSION 3.14) option(CMAKE_VERBOSE_MAKEFILE "Enable verbose output" ON) option(CMAKE_EXPORT_COMPILE_COMMANDS "Export compile commands for linters and autocompleters" ON) project(main LANGUAGES CXX) - -set(CMAKE_CXX_STANDARD - 11 - CACHE STRING "The C++ standard to use") +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) find_package(amd_smi HINTS diff --git a/tests/amd_smi_test/CMakeLists.txt b/tests/amd_smi_test/CMakeLists.txt index d87bdec4c2..865042b89b 100644 --- a/tests/amd_smi_test/CMakeLists.txt +++ b/tests/amd_smi_test/CMakeLists.txt @@ -7,20 +7,13 @@ set(CMAKE_INSTALL_RPATH "\$ORIGIN:\$ORIGIN/../../../lib" CACHE STRING "RUNPATH for tests. Helps find libgtest.so and libamd_smi.so") -# Try to find googletest -find_package(GTest 1.12.0) - -# GTest_FOUND is set to TRUE if ANY version is found -# GTest_VERSION is set if 1.11.0 or newer version is found -if(NOT GTest_FOUND STREQUAL "TRUE" OR NOT DEFINED GTest_VERSION) - # Google Test wasn't found. Download and compile ourselves - include(FetchContent) - FetchContent_Declare( - googletest - GIT_REPOSITORY https://github.com/google/googletest.git - GIT_TAG release-1.12.0) - FetchContent_MakeAvailable(googletest) -endif() +# Download and compile googletest +include(FetchContent) +FetchContent_Declare( + googletest + GIT_REPOSITORY https://github.com/google/googletest.git + GIT_TAG v1.14.0) +FetchContent_MakeAvailable(googletest) enable_testing() @@ -70,10 +63,9 @@ target_link_libraries(${TEST} stdc++ pthread) -# Install tests and gtest -# TODO: Remove GTest from here in the future and rely on INSTALL_GTEST? +# Install tests install( - TARGETS ${TEST} gtest gtest_main + TARGETS ${TEST} DESTINATION ${SHARE_INSTALL_PREFIX}/tests COMPONENT ${TESTS_COMPONENT}) @@ -81,3 +73,9 @@ install( FILES amdsmitst.exclude DESTINATION ${SHARE_INSTALL_PREFIX}/tests COMPONENT ${TESTS_COMPONENT}) + +# Install googletest libraries with tests +install(TARGETS gtest gtest_main + DESTINATION ${SHARE_INSTALL_PREFIX}/tests + COMPONENT ${TESTS_COMPONENT}) + From aa89f2e125c80af5cdd35b58fe5f47cfdf120ada Mon Sep 17 00:00:00 2001 From: Ori Messinger Date: Wed, 27 Sep 2023 12:38:15 -0400 Subject: [PATCH 07/16] ROCm SMI CLI: Add Missing Firmware Blocks The purpose of this patch is to add the following missing firmware blocks to the SMI CLI: -RSMI_FW_BLOCK_MES -RSMI_FW_BLOCK_MES_KIQ Signed-off-by: Ori Messinger Change-Id: If9cabdc60ffcf08f27c9e6bdc20e8a26b192a738 --- python_smi_tools/rocm_smi.py | 2 +- python_smi_tools/rsmiBindings.py.in | 32 +++++++++++++++-------------- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/python_smi_tools/rocm_smi.py b/python_smi_tools/rocm_smi.py index 6f7ba1a8e0..ddead08f83 100755 --- a/python_smi_tools/rocm_smi.py +++ b/python_smi_tools/rocm_smi.py @@ -2052,7 +2052,7 @@ def showFwInfo(deviceList, fwType): ret = rocmsmi.rsmi_dev_firmware_version_get(device, fw_block_names_l.index(fw_name), byref(fw_ver)) if rsmi_ret_ok(ret, device, 'get_firmware_version_' + str(fw_name)): # The VCN, VCE, UVD, SOS and ASD firmware's value needs to be in hexadecimal - if fw_name in ['VCN', 'VCE', 'UVD', 'SOS', 'ASD']: + if fw_name in ['VCN', 'VCE', 'UVD', 'SOS', 'ASD', 'MES', 'MES KIQ']: printLog(device, '%s firmware version' % (fw_name), '\t0x%s' % (str(hex(fw_ver.value))[2:].zfill(8))) # The TA XGMI, TA RAS, and SMC firmware's hex value looks like 0x12345678 diff --git a/python_smi_tools/rsmiBindings.py.in b/python_smi_tools/rsmiBindings.py.in index 87c32a8fc9..f913d99936 100644 --- a/python_smi_tools/rsmiBindings.py.in +++ b/python_smi_tools/rsmiBindings.py.in @@ -417,25 +417,27 @@ class rsmi_fw_block_t(c_int): RSMI_FW_BLOCK_ME = 4 RSMI_FW_BLOCK_MEC = 5 RSMI_FW_BLOCK_MEC2 = 6 - RSMI_FW_BLOCK_PFP = 7 - RSMI_FW_BLOCK_RLC = 8 - RSMI_FW_BLOCK_RLC_SRLC = 9 - RSMI_FW_BLOCK_RLC_SRLG = 10 - RSMI_FW_BLOCK_RLC_SRLS = 11 - RSMI_FW_BLOCK_SDMA = 12 - RSMI_FW_BLOCK_SDMA2 = 13 - RSMI_FW_BLOCK_SMC = 14 - RSMI_FW_BLOCK_SOS = 15 - RSMI_FW_BLOCK_TA_RAS = 16 - RSMI_FW_BLOCK_TA_XGMI = 17 - RSMI_FW_BLOCK_UVD = 18 - RSMI_FW_BLOCK_VCE = 19 - RSMI_FW_BLOCK_VCN = 20 + RSMI_FW_BLOCK_MES = 7 + RSMI_FW_BLOCK_MES_KIQ = 8 + RSMI_FW_BLOCK_PFP = 9 + RSMI_FW_BLOCK_RLC = 10 + RSMI_FW_BLOCK_RLC_SRLC = 11 + RSMI_FW_BLOCK_RLC_SRLG = 12 + RSMI_FW_BLOCK_RLC_SRLS = 13 + RSMI_FW_BLOCK_SDMA = 14 + RSMI_FW_BLOCK_SDMA2 = 15 + RSMI_FW_BLOCK_SMC = 16 + RSMI_FW_BLOCK_SOS = 17 + RSMI_FW_BLOCK_TA_RAS = 18 + RSMI_FW_BLOCK_TA_XGMI = 19 + RSMI_FW_BLOCK_UVD = 20 + RSMI_FW_BLOCK_VCE = 21 + RSMI_FW_BLOCK_VCN = 22 RSMI_FW_BLOCK_LAST = RSMI_FW_BLOCK_VCN # The following list correlated to the rsmi_fw_block_t -fw_block_names_l = ['ASD', 'CE', 'DMCU', 'MC', 'ME', 'MEC', 'MEC2', 'PFP',\ +fw_block_names_l = ['ASD', 'CE', 'DMCU', 'MC', 'ME', 'MEC', 'MEC2', 'MES', 'MES KIQ', 'PFP',\ 'RLC', 'RLC SRLC', 'RLC SRLG', 'RLC SRLS', 'SDMA', 'SDMA2',\ 'SMC', 'SOS', 'TA RAS', 'TA XGMI', 'UVD', 'VCE', 'VCN'] From f7d631b9cd5b9bdd396759d487396cc95b532b85 Mon Sep 17 00:00:00 2001 From: Maisam Arif Date: Thu, 28 Sep 2023 19:08:37 -0500 Subject: [PATCH 08/16] Sync commands w/ Host Added ucode as alias to firmware Changed pcie_width to pcie_lanes Signed-off-by: Maisam Arif Change-Id: Ia95a13d937c8e1b7bf092b5001de38ea9c008606 --- amdsmi_cli/amdsmi_commands.py | 4 ++-- amdsmi_cli/amdsmi_parser.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/amdsmi_cli/amdsmi_commands.py b/amdsmi_cli/amdsmi_commands.py index a4f2aee64c..f9f74cbf5c 100644 --- a/amdsmi_cli/amdsmi_commands.py +++ b/amdsmi_cli/amdsmi_commands.py @@ -1013,7 +1013,7 @@ class AMDSMICommands(): values_dict['ecc_block'] = "N/A" logging.debug("Failed to get ecc block features for gpu %s | %s", gpu_id, e.get_error_info()) if args.pcie: - pcie_dict = {'current_width': "N/A", + pcie_dict = {'current_lanes': "N/A", 'current_speed': "N/A", 'replay_count' : "N/A", 'current_bandwith_sent': "N/A", @@ -1029,7 +1029,7 @@ class AMDSMICommands(): pcie_speed_GTs_value = round(pcie_link_status['pcie_speed'] / 1000) pcie_dict['current_speed'] = pcie_speed_GTs_value - pcie_dict['current_width'] = pcie_link_status['pcie_lanes'] + pcie_dict['current_lanes'] = pcie_link_status['pcie_lanes'] if self.logger.is_human_readable_format(): unit = 'GT/s' diff --git a/amdsmi_cli/amdsmi_parser.py b/amdsmi_cli/amdsmi_parser.py index 54cba3081e..af95a8641f 100644 --- a/amdsmi_cli/amdsmi_parser.py +++ b/amdsmi_cli/amdsmi_parser.py @@ -348,7 +348,7 @@ class AMDSMIParser(argparse.ArgumentParser): err_records_help = "All error records information" # Create firmware subparser - firmware_parser = subparsers.add_parser('firmware', help=firmware_help, description=firmware_subcommand_help) + firmware_parser = subparsers.add_parser('firmware', help=firmware_help, description=firmware_subcommand_help, aliases=['ucode']) firmware_parser._optionals.title = firmware_optionals_title firmware_parser.formatter_class=lambda prog: argparse.RawTextHelpFormatter(prog, max_help_position=80, width=90) firmware_parser.set_defaults(func=func) From b58665e77b594cd05bebbabbcde34cabc7d4a838 Mon Sep 17 00:00:00 2001 From: Maisam Arif Date: Thu, 28 Sep 2023 21:56:09 -0500 Subject: [PATCH 09/16] Adjust static --board output to be inline with Host Change-Id: Ia6dcca5be077ef9e04533b632628a62633b63556 Signed-off-by: Maisam Arif --- amdsmi_cli/amdsmi_commands.py | 17 +++++++++-------- py-interface/amdsmi_interface.py | 10 +++++----- src/amd_smi/amd_smi.cc | 5 ++++- src/amd_smi/amd_smi_utils.cc | 2 +- 4 files changed, 19 insertions(+), 15 deletions(-) diff --git a/amdsmi_cli/amdsmi_commands.py b/amdsmi_cli/amdsmi_commands.py index f9f74cbf5c..9d973c688b 100644 --- a/amdsmi_cli/amdsmi_commands.py +++ b/amdsmi_cli/amdsmi_commands.py @@ -269,18 +269,19 @@ class AMDSMICommands(): if self.helpers.is_linux() and self.helpers.is_baremetal(): if args.board: + static_dict['board'] = {"model_number": "N/A", + "product_serial": "N/A", + "fru_id": "N/A", + "manufacturer_name": "N/A", + "product_name": "N/A"} try: board_info = amdsmi_interface.amdsmi_get_gpu_board_info(args.gpu) - board_info['serial_number'] = hex(board_info['serial_number']) - board_info['model_number'] = board_info['model_number'].strip() - board_info['product_name'] = board_info['product_name'].strip() - board_info['manufacturer_name'] = board_info['manufacturer_name'].strip() - board_info.pop('product_serial') - board_info.pop('manufacturer_name') - + for key, value in board_info.items(): + if isinstance(value, str): + if value.strip() == '': + board_info[key] = "N/A" static_dict['board'] = board_info except amdsmi_exception.AmdSmiLibraryException as e: - static_dict['board'] = "N/A" logging.debug("Failed to get board info for gpu %s | %s", gpu_id, e.get_error_info()) if args.limit: # Power limits diff --git a/py-interface/amdsmi_interface.py b/py-interface/amdsmi_interface.py index 74a8e23aeb..41cd01af8e 100644 --- a/py-interface/amdsmi_interface.py +++ b/py-interface/amdsmi_interface.py @@ -823,11 +823,11 @@ def amdsmi_get_gpu_board_info( ) return { - "serial_number": board_info.serial_number, - "model_number": board_info.model_number.decode("utf-8"), - "product_serial": board_info.product_serial.decode("utf-8"), - "product_name": board_info.product_name.decode("utf-8"), - "manufacturer_name" : board_info.product_name.decode("utf-8") + "model_number": board_info.model_number.decode("utf-8").strip(), + "product_serial": board_info.serial_number, + "fru_id": board_info.fru_id.decode("utf-8").strip(), + "manufacturer_name" : board_info.manufacturer_name.decode("utf-8").strip(), + "product_name": board_info.product_name.decode("utf-8").strip() } diff --git a/src/amd_smi/amd_smi.cc b/src/amd_smi/amd_smi.cc index 66daf32be0..0a94835a09 100644 --- a/src/amd_smi/amd_smi.cc +++ b/src/amd_smi/amd_smi.cc @@ -457,7 +457,7 @@ amdsmi_status_t amdsmi_get_gpu_board_info(amdsmi_processor_handle processor_hand return r; if (gpu_device->check_if_drm_is_supported()) { - // Get from sys file + // Populate product_serial, product_name, & product_number from sysfs status = smi_amdgpu_get_board_info(gpu_device, board_info); } else { @@ -472,6 +472,9 @@ amdsmi_status_t amdsmi_get_gpu_board_info(amdsmi_processor_handle processor_hand } } + // Get FRU ID + // Get manufacturer name + return AMDSMI_STATUS_SUCCESS; } diff --git a/src/amd_smi/amd_smi_utils.cc b/src/amd_smi/amd_smi_utils.cc index fbf8d8efb6..8aef5c8dc1 100644 --- a/src/amd_smi/amd_smi_utils.cc +++ b/src/amd_smi/amd_smi_utils.cc @@ -138,7 +138,7 @@ amdsmi_status_t smi_amdgpu_get_board_info(amd::smi::AMDSmiGPUDevice* device, amd fp = fopen(serial_number_path.c_str(), "rb"); if (fp) { - fscanf(fp, "%lx", &info->serial_number); + fscanf(fp, "%lx", &info->product_serial); fclose(fp); } From fadf1b6cc91515925c0f060fe790332f4d72fdfb Mon Sep 17 00:00:00 2001 From: Maisam Arif Date: Wed, 27 Sep 2023 22:19:19 -0500 Subject: [PATCH 10/16] SWDEV-410230 - Added slot_type to amd-smi static --bus Signed-off-by: Maisam Arif Change-Id: I2006a3525a8aa9091bf54501461d364f7237f00f --- amdsmi_cli/amdsmi_commands.py | 24 +++++++++--------------- example/amd_smi_drm_example.cc | 6 +++--- include/amd_smi/amdsmi.h | 15 +++++++++++++-- py-interface/amdsmi_wrapper.py | 25 ++++++++++++++++++++----- src/amd_smi/amd_smi.cc | 8 ++++---- 5 files changed, 49 insertions(+), 29 deletions(-) diff --git a/amdsmi_cli/amdsmi_commands.py b/amdsmi_cli/amdsmi_commands.py index 9d973c688b..1296e03268 100644 --- a/amdsmi_cli/amdsmi_commands.py +++ b/amdsmi_cli/amdsmi_commands.py @@ -226,27 +226,21 @@ class AMDSMICommands(): bus_info['max_pcie_speed'] = pcie_speed_GTs_value - try: - slot_type = amdsmi_interface.amdsmi_topo_get_link_type(args.gpu, args.gpu)['type'] - except amdsmi_exception.AmdSmiLibraryException as e: - slot_type = e.get_error_info() + slot_type = bus_info.pop('pcie_slot_type') + if isinstance(slot_type, int): + slot_types = amdsmi_interface.amdsmi_wrapper.amdsmi_pcie_slot_type_t__enumvalues + if slot_type in slot_types: + bus_info['slot_type'] = slot_types[slot_type].replace("AMDSMI_SLOT_TYPE__", "") + else: + bus_info['slot_type'] = "Unknown" + else: + bus_info['slot_type'] = "N/A" if self.logger.is_human_readable_format(): unit ='GT/s' bus_info['max_pcie_speed'] = f"{bus_info['max_pcie_speed']} {unit}" - if bus_info['pcie_interface_version'] > 0: bus_info['pcie_interface_version'] = f"Gen {bus_info['pcie_interface_version']}" - - bus_info['slot_type'] = 'XXXX' - if isinstance(slot_type, int): - if slot_type == amdsmi_interface.amdsmi_wrapper.AMDSMI_IOLINK_TYPE_UNDEFINED: - bus_info['slot_type'] = "UNKNOWN" - elif slot_type == amdsmi_interface.amdsmi_wrapper.AMDSMI_IOLINK_TYPE_PCIEXPRESS: - bus_info['slot_type'] = "PCIE" - elif slot_type == amdsmi_interface.amdsmi_wrapper.AMDSMI_IOLINK_TYPE_XGMI: - bus_info['slot_type'] = "XGMI" - except amdsmi_exception.AmdSmiLibraryException as e: bus_info = "N/A" logging.debug("Failed to get bus info for gpu %s | %s", gpu_id, e.get_error_info()) diff --git a/example/amd_smi_drm_example.cc b/example/amd_smi_drm_example.cc index 1ac45844b6..542866b74a 100644 --- a/example/amd_smi_drm_example.cc +++ b/example/amd_smi_drm_example.cc @@ -379,9 +379,9 @@ int main() { ret = amdsmi_get_pcie_link_status(processor_handles[j], &pcie_info); CHK_AMDSMI_RET(ret) printf(" Output of amdsmi_get_pcie_link_status:\n"); - printf("\tPCIe lanes: %d\n", pcie_info.pcie_lanes); - printf("\tPCIe speed: %d\n", pcie_info.pcie_speed); - printf("\tPCIe Interface Version: %d\n", pcie_info.pcie_interface_version); + printf("\tCurrent PCIe lanes: %d\n", pcie_info.pcie_lanes); + printf("\tCurrent PCIe speed: %d\n", pcie_info.pcie_speed); + printf("\tCurrent PCIe Interface Version: %d\n", pcie_info.pcie_interface_version); printf("\tPCIe slot type: %d\n\n", pcie_info.pcie_slot_type); // Get PCIe caps diff --git a/include/amd_smi/amdsmi.h b/include/amd_smi/amdsmi.h index 66ec6dae2d..d7cf774345 100644 --- a/include/amd_smi/amdsmi.h +++ b/include/amd_smi/amdsmi.h @@ -1150,6 +1150,16 @@ typedef struct { uint64_t reserved[2]; } amdsmi_error_count_t; +/** + * @brief This is a enum translation for pcie_slot_type + */ +typedef enum { + AMDSMI_SLOT_TYPE__PCIE = 0, + AMDSMI_SLOT_TYPE__CEM = 1, + AMDSMI_SLOT_TYPE__OAM = 2, + AMDSMI_SLOT_TYPE__RESERVED = 3, +} amdsmi_pcie_slot_type_t; + /** * @brief This structure holds pcie info. */ @@ -1157,9 +1167,10 @@ typedef struct { uint16_t pcie_lanes; uint32_t pcie_speed; uint32_t pcie_interface_version; - uint32_t pcie_slot_type; // 0: PCIE, 1: CEM, 2: OAM, 3: Reserved - uint32_t reserved[5]; + amdsmi_pcie_slot_type_t pcie_slot_type; // 0: PCIE, 1: CEM, 2: OAM, 3: Reserved + uint32_t reserved[4]; } amdsmi_pcie_info_t; + /** * @brief This structure contains information specific to a process. */ diff --git a/py-interface/amdsmi_wrapper.py b/py-interface/amdsmi_wrapper.py index a948f31c3d..89bf709402 100644 --- a/py-interface/amdsmi_wrapper.py +++ b/py-interface/amdsmi_wrapper.py @@ -1424,6 +1424,19 @@ struct_amdsmi_error_count_t._fields_ = [ ] amdsmi_error_count_t = struct_amdsmi_error_count_t + +# values for enumeration 'amdsmi_pcie_slot_type_t' +amdsmi_pcie_slot_type_t__enumvalues = { + 0: 'AMDSMI_SLOT_TYPE__PCIE', + 1: 'AMDSMI_SLOT_TYPE__CEM', + 2: 'AMDSMI_SLOT_TYPE__OAM', + 3: 'AMDSMI_SLOT_TYPE__RESERVED', +} +AMDSMI_SLOT_TYPE__PCIE = 0 +AMDSMI_SLOT_TYPE__CEM = 1 +AMDSMI_SLOT_TYPE__OAM = 2 +AMDSMI_SLOT_TYPE__RESERVED = 3 +amdsmi_pcie_slot_type_t = ctypes.c_uint32 # enum class struct_amdsmi_pcie_info_t(Structure): pass @@ -1433,8 +1446,8 @@ struct_amdsmi_pcie_info_t._fields_ = [ ('PADDING_0', ctypes.c_ubyte * 2), ('pcie_speed', ctypes.c_uint32), ('pcie_interface_version', ctypes.c_uint32), - ('pcie_slot_type', ctypes.c_uint32), - ('reserved', ctypes.c_uint32 * 5), + ('pcie_slot_type', amdsmi_pcie_slot_type_t), + ('reserved', ctypes.c_uint32 * 4), ] amdsmi_pcie_info_t = struct_amdsmi_pcie_info_t @@ -1805,7 +1818,9 @@ __all__ = \ 'AMDSMI_RAS_ERR_STATE_INVALID', 'AMDSMI_RAS_ERR_STATE_LAST', 'AMDSMI_RAS_ERR_STATE_MULT_UC', 'AMDSMI_RAS_ERR_STATE_NONE', 'AMDSMI_RAS_ERR_STATE_PARITY', 'AMDSMI_RAS_ERR_STATE_POISON', - 'AMDSMI_RAS_ERR_STATE_SING_C', 'AMDSMI_STATUS_ADDRESS_FAULT', + 'AMDSMI_RAS_ERR_STATE_SING_C', 'AMDSMI_SLOT_TYPE__CEM', + 'AMDSMI_SLOT_TYPE__OAM', 'AMDSMI_SLOT_TYPE__PCIE', + 'AMDSMI_SLOT_TYPE__RESERVED', 'AMDSMI_STATUS_ADDRESS_FAULT', 'AMDSMI_STATUS_API_FAILED', 'AMDSMI_STATUS_BUSY', 'AMDSMI_STATUS_DRIVER_NOT_LOADED', 'AMDSMI_STATUS_DRM_ERROR', 'AMDSMI_STATUS_FAIL_LOAD_MODULE', @@ -1955,8 +1970,8 @@ __all__ = \ 'amdsmi_mm_ip_t', 'amdsmi_od_vddc_point_t', 'amdsmi_od_volt_curve_t', 'amdsmi_od_volt_freq_data_t', 'amdsmi_pcie_bandwidth_t', 'amdsmi_pcie_info_t', - 'amdsmi_power_cap_info_t', 'amdsmi_power_info_t', - 'amdsmi_power_profile_preset_masks_t', + 'amdsmi_pcie_slot_type_t', 'amdsmi_power_cap_info_t', + 'amdsmi_power_info_t', 'amdsmi_power_profile_preset_masks_t', 'amdsmi_power_profile_status_t', 'amdsmi_proc_info_t', 'amdsmi_process_handle_t', 'amdsmi_process_info_t', 'amdsmi_processor_handle', 'amdsmi_range_t', diff --git a/src/amd_smi/amd_smi.cc b/src/amd_smi/amd_smi.cc index 0a94835a09..667ec666c6 100644 --- a/src/amd_smi/amd_smi.cc +++ b/src/amd_smi/amd_smi.cc @@ -1817,7 +1817,7 @@ amdsmi_get_pcie_link_status(amdsmi_processor_handle processor_handle, amdsmi_pci } // default to PCIe - info->pcie_slot_type = 0; + info->pcie_slot_type = AMDSMI_SLOT_TYPE__PCIE; amd::smi::AMDSmiGPUDevice* gpu_device = nullptr; status = get_gpu_device_from_handle( processor_handle, &gpu_device); @@ -1829,7 +1829,7 @@ amdsmi_get_pcie_link_status(amdsmi_processor_handle processor_handle, amdsmi_pci // bits [16:17] in ids_flags field as slot type if (status == AMDSMI_STATUS_SUCCESS) { // two bits starts with index 16 - info->pcie_slot_type = (dev_info.ids_flags >> 16) & 0x03; + info->pcie_slot_type = static_cast((dev_info.ids_flags >> 16) & 0x03); } } @@ -1908,7 +1908,7 @@ amdsmi_status_t amdsmi_get_pcie_link_caps(amdsmi_processor_handle processor_hand } // default to PCIe - info->pcie_slot_type = 0; + info->pcie_slot_type = AMDSMI_SLOT_TYPE__PCIE; if (gpu_device->check_if_drm_is_supported()) { struct drm_amdgpu_info_device dev_info = {}; status = gpu_device->amdgpu_query_info(AMDGPU_INFO_DEV_INFO, @@ -1916,7 +1916,7 @@ amdsmi_status_t amdsmi_get_pcie_link_caps(amdsmi_processor_handle processor_hand // bits [16:17] in ids_flags field as slot type if (status == AMDSMI_STATUS_SUCCESS) { // two bits starts with index 16 - info->pcie_slot_type = (dev_info.ids_flags >> 16) & 0x03; + info->pcie_slot_type = static_cast((dev_info.ids_flags >> 16) & 0x03); } } From d665157cd17dcb82a8787dbf179b0c3a5b2ddfbb Mon Sep 17 00:00:00 2001 From: "Bill(Shuzhou) Liu" Date: Mon, 2 Oct 2023 09:19:12 -0500 Subject: [PATCH 11/16] rocm-smi shows wrong fwinfo Add new fw block into the rocm-smi tool. Change-Id: Id5c7ccc2fc491f7e5d0390aeb4c6f81fd12fa644 From d862bee754ad23d65ac1405ae3a40e5dceef80d2 Mon Sep 17 00:00:00 2001 From: "Galantsev, Dmitrii" Date: Mon, 2 Oct 2023 17:57:02 -0500 Subject: [PATCH 12/16] Add --version to CLI Change-Id: Id2a8f10f544ed04e874db773820534eddd73f55d Signed-off-by: Galantsev, Dmitrii --- cmake_modules/utils.cmake | 2 +- python_smi_tools/rocm_smi.py | 41 ++++++++++++++++++++++++++++++++---- 2 files changed, 38 insertions(+), 5 deletions(-) diff --git a/cmake_modules/utils.cmake b/cmake_modules/utils.cmake index 76f910a20b..afaa442e59 100755 --- a/cmake_modules/utils.cmake +++ b/cmake_modules/utils.cmake @@ -52,7 +52,7 @@ function( parse_version VERSION_STRING ) string ( SUBSTRING ${VERSION_STRING} ${STRING_INDEX} -1 VERSION_BUILD ) endif () - string ( REGEX MATCHALL "[0123456789]+" VERSIONS ${VERSION_STRING} ) + string ( REGEX MATCHALL "[0-9]+" VERSIONS ${VERSION_STRING} ) list ( LENGTH VERSIONS VERSION_COUNT ) if ( ${VERSION_COUNT} GREATER 0) diff --git a/python_smi_tools/rocm_smi.py b/python_smi_tools/rocm_smi.py index ddead08f83..8db2d7eeea 100755 --- a/python_smi_tools/rocm_smi.py +++ b/python_smi_tools/rocm_smi.py @@ -30,8 +30,8 @@ from rsmiBindings import * # Minor version - Increment when adding a new feature, set to 0 when major is incremented # Patch version - Increment when adding a fix, set to 0 when minor is incremented SMI_MAJ = 1 -SMI_MIN = 4 -SMI_PAT = 1 +SMI_MIN = 5 +SMI_PAT = 0 __version__ = '%s.%s.%s' % (SMI_MAJ, SMI_MIN, SMI_PAT) # Set to 1 if an error occurs @@ -1675,6 +1675,32 @@ def setNPSMode(deviceList, npsMode): printErrLog(device, 'Failed to retrieve NPS mode, even though device supports it.') printLogSpacer() +def showVersion(isCSV=False): + values = { 'ROCM-SMI version': __version__ } + + version = rsmi_version_t() + status = rocmsmi.rsmi_version_get(byref(version)) + if status == 0: + version_string = "%u.%u.%u" % (version.major, version.minor, version.patch) + values['ROCM-SMI-LIB version'] = version_string + + if isCSV: + print('name, value') + for k in values.keys(): + print('%s, %s' % (k, values[k])) + return + if PRINT_JSON: + temp_str = '{\n' + for k in values.keys(): + temp_str += ' "%s": "%s",\n' % (k, values[k]) + if len(values.keys()) > 1: + # replace ',\n' with '\n}' + temp_str = temp_str[:-2] + temp_str += '\n}' + print(temp_str) + return + for k in values.keys(): + print('%s: %s' % (k, values[k])) def showAllConcise(deviceList): """ Display critical info for all devices in a concise format @@ -2955,7 +2981,7 @@ def showTempGraph(deviceList): printLogSpacer() -def showVersion(deviceList, component): +def showDriverVersion(deviceList, component): """ Display the software version for the specified component @param deviceList: List of DRM devices (can be a single-item list) @@ -3614,6 +3640,7 @@ if __name__ == '__main__': parser = argparse.ArgumentParser( description='AMD ROCm System Management Interface | ROCM-SMI version: %s' % __version__, formatter_class=lambda prog: argparse.HelpFormatter(prog, max_help_position=90, width=120)) + groupVersion = parser.add_argument_group() groupDev = parser.add_argument_group() groupDisplayOpt = parser.add_argument_group('Display Options') groupDisplayTop = parser.add_argument_group('Topology') @@ -3627,6 +3654,7 @@ if __name__ == '__main__': groupResponse = parser.add_argument_group('Auto-response options') groupActionOutput = parser.add_argument_group('Output options') + groupVersion.add_argument('-V', '--version', help='Show version information', action='store_true') groupDev.add_argument('-d', '--device', help='Execute command on specified device', type=int, nargs='+') groupDisplayOpt.add_argument('--alldevices', action='store_true') # ------------- function deprecated, no help menu groupDisplayOpt.add_argument('--showhw', help='Show Hardware details', action='store_true') @@ -3775,11 +3803,16 @@ if __name__ == '__main__': # Must set PRINT_JSON early so the prints can be silenced if args.json or args.csv: PRINT_JSON = True + # Initialize rsmiBindings rocmsmi = initRsmiBindings(silent=PRINT_JSON) # Initialize the rocm SMI library initializeRsmi() + if args.version: + showVersion(isCSV=args.csv) + sys.exit() + logging.basicConfig(format='%(levelname)s: %(message)s', level=logging.WARNING) if args.loglevel is not None: numericLogLevel = getattr(logging, args.loglevel.upper(), logging.WARNING) @@ -3878,7 +3911,7 @@ if __name__ == '__main__': if args.showhw: showAllConciseHw(deviceList) if args.showdriverversion: - showVersion(deviceList, rsmi_sw_component_t.RSMI_SW_COMP_DRIVER) + showDriverVersion(deviceList, rsmi_sw_component_t.RSMI_SW_COMP_DRIVER) if args.showtempgraph: showTempGraph(deviceList) if args.showid: From 6c8767a69a7556cc23258d0e0ba577e279aadeaa Mon Sep 17 00:00:00 2001 From: "Galantsev, Dmitrii" Date: Thu, 28 Sep 2023 17:33:23 -0500 Subject: [PATCH 13/16] TESTS - Disable same tests as in rocm-smi Change-Id: I2587baf8a76e4e3a54880e73941b1d973440e7d3 Signed-off-by: Galantsev, Dmitrii --- tests/amd_smi_test/amdsmitst.exclude | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/tests/amd_smi_test/amdsmitst.exclude b/tests/amd_smi_test/amdsmitst.exclude index f498de400f..5a49f0dc0a 100644 --- a/tests/amd_smi_test/amdsmitst.exclude +++ b/tests/amd_smi_test/amdsmitst.exclude @@ -14,12 +14,13 @@ PERMANENT_BLACKLIST_ALL_ASICS= # is failing consistently TEMPORARY_BLACKLIST_ALL_ASICS= -if [ -z $PERMANENT_BLACKLIST_ALL_ASICS -a -z $TEMPORARY_BLACKLIST_ALL_ASICS ]; then + +if [ -z "$PERMANENT_BLACKLIST_ALL_ASICS" -a -z "$TEMPORARY_BLACKLIST_ALL_ASICS" ]; then BLACKLIST_ALL_ASICS= else BLACKLIST_ALL_ASICS=\ - "$PERMANENT_BLACKLIST_ALL_ASICS:"\ - "$TEMPORARY_BLACKLIST_ALL_ASICS" +"$PERMANENT_BLACKLIST_ALL_ASICS:"\ +"$TEMPORARY_BLACKLIST_ALL_ASICS:" fi # Device specific blacklists @@ -55,6 +56,18 @@ FILTER[sienna_cichlid]=\ $BLACKLIST_ALL_ASICS\ "amdsmitstReadWrite.TestPerfLevelReadWrite" +# SWDEV-391407 +# aqua_vanjaram and later systems show 'ip discovery' in +# /sys/class/kfd/kfd/topology/nodes/*/name +# +# For those systems gfx_target_version must be used. It can be found in +# /sys/class/kfd/kfd/topology/nodes/*/properties +FILTER[90400]=\ +$BLACKLIST_ALL_ASICS\ +"amdsmitstReadOnly.TestVoltCurvRead" +FILTER[90401]=${FILTER[90400]} +FILTER[90402]=${FILTER[90400]} + # SWDEV-321166 FILTER[virtualization]=\ $BLACKLIST_ALL_ASICS\ @@ -63,4 +76,4 @@ $BLACKLIST_ALL_ASICS\ "amdsmitstReadWrite.FanReadWrite:"\ "amdsmitstReadWrite.TestOverdriveReadWrite:"\ "amdsmitstReadWrite.TestPowerReadWrite:"\ -"amdsmitstReadWrite.TestPowerCapReadWrite" \ No newline at end of file +"amdsmitstReadWrite.TestPowerCapReadWrite" From 572bf563d1db9bbc94d38ce4d4c3b605eed0039c Mon Sep 17 00:00:00 2001 From: Maisam Arif Date: Fri, 29 Sep 2023 13:46:46 -0500 Subject: [PATCH 14/16] Added driver_name to amdsmi_cli tool Signed-off-by: Maisam Arif Change-Id: I8f3d52e0b23298443b2b16afec418cbbbc5f77e0 --- amdsmi_cli/amdsmi_commands.py | 3 ++- example/amd_smi_drm_example.cc | 1 + include/amd_smi/amdsmi.h | 1 + include/amd_smi/impl/amd_smi_drm.h | 1 + include/amd_smi/impl/amd_smi_gpu_device.h | 1 + py-interface/README.md | 8 +++++++- py-interface/amdsmi_interface.py | 1 + py-interface/amdsmi_wrapper.py | 1 + src/amd_smi/amd_smi.cc | 16 ++++++++++++++-- src/amd_smi/amd_smi_drm.cc | 12 ++++++++++++ src/amd_smi/amd_smi_gpu_device.cc | 9 +++++++++ 11 files changed, 50 insertions(+), 4 deletions(-) diff --git a/amdsmi_cli/amdsmi_commands.py b/amdsmi_cli/amdsmi_commands.py index 1296e03268..78b7435ac1 100644 --- a/amdsmi_cli/amdsmi_commands.py +++ b/amdsmi_cli/amdsmi_commands.py @@ -391,7 +391,8 @@ class AMDSMICommands(): static_dict['limit'] = limit_info if args.driver: - driver_info = {"driver_version" : "N/A", + driver_info = {"driver_name" : "N/A", + "driver_version" : "N/A", "driver_date" : "N/A"} try: diff --git a/example/amd_smi_drm_example.cc b/example/amd_smi_drm_example.cc index 542866b74a..2ee0bb3127 100644 --- a/example/amd_smi_drm_example.cc +++ b/example/amd_smi_drm_example.cc @@ -322,6 +322,7 @@ int main() { ret = amdsmi_get_gpu_driver_info(processor_handles[j], &driver_info); CHK_AMDSMI_RET(ret) printf(" Output of amdsmi_get_gpu_driver_info:\n"); + printf("\tDriver name: %s\n", driver_info.driver_name); printf("\tDriver version: %s\n", driver_info.driver_version); printf("\tDriver date: %s\n\n", driver_info.driver_date); diff --git a/include/amd_smi/amdsmi.h b/include/amd_smi/amdsmi.h index d7cf774345..ce70d58f30 100644 --- a/include/amd_smi/amdsmi.h +++ b/include/amd_smi/amdsmi.h @@ -444,6 +444,7 @@ typedef struct{ typedef struct { + char driver_name[AMDSMI_MAX_STRING_LENGTH]; char driver_version[AMDSMI_MAX_STRING_LENGTH]; char driver_date[AMDSMI_MAX_STRING_LENGTH]; } amdsmi_driver_info_t; diff --git a/include/amd_smi/impl/amd_smi_drm.h b/include/amd_smi/impl/amd_smi_drm.h index cb9fde0c42..88da83e82a 100644 --- a/include/amd_smi/impl/amd_smi_drm.h +++ b/include/amd_smi/impl/amd_smi_drm.h @@ -75,6 +75,7 @@ class AMDSmiDrm { amdsmi_status_t amdgpu_query_hw_ip(int fd, unsigned info_id, unsigned hw_ip_type, unsigned size, void *value); amdsmi_status_t amdgpu_query_vbios(int fd, void *info); + amdsmi_status_t amdgpu_query_driver_name(int fd, std::string& driver_name); amdsmi_status_t amdgpu_query_driver_date(int fd, std::string& driver_date); private: diff --git a/include/amd_smi/impl/amd_smi_gpu_device.h b/include/amd_smi/impl/amd_smi_gpu_device.h index fdd97d8cfd..c191b29421 100644 --- a/include/amd_smi/impl/amd_smi_gpu_device.h +++ b/include/amd_smi/impl/amd_smi_gpu_device.h @@ -81,6 +81,7 @@ class AMDSmiGPUDevice: public AMDSmiProcessor { amdsmi_status_t amdgpu_query_fw(unsigned info_id, unsigned fw_type, unsigned size, void *value) const; amdsmi_status_t amdgpu_query_vbios(void *info) const; + amdsmi_status_t amdgpu_query_driver_name(std::string& name) const; amdsmi_status_t amdgpu_query_driver_date(std::string& date) const; private: uint32_t gpu_id_; diff --git a/py-interface/README.md b/py-interface/README.md index 6efba3b16d..72f9f843fd 100644 --- a/py-interface/README.md +++ b/py-interface/README.md @@ -310,7 +310,13 @@ Input parameters: * `processor_handle` dev for which to query -Output: Driver info that is handling the device +Output: Dictionary with fields + +Field | Content +---|--- +`driver_name` | driver name +`driver_version` | driver_version +`driver_date` | driver_date Exceptions that can be thrown by `amdsmi_get_gpu_driver_info` function: diff --git a/py-interface/amdsmi_interface.py b/py-interface/amdsmi_interface.py index 41cd01af8e..9c439e3104 100644 --- a/py-interface/amdsmi_interface.py +++ b/py-interface/amdsmi_interface.py @@ -962,6 +962,7 @@ def amdsmi_get_gpu_driver_info( ) return { + "driver_name": info.driver_name.decode("utf-8"), "driver_version": info.driver_version.decode("utf-8"), "driver_date": info.driver_date.decode("utf-8") } diff --git a/py-interface/amdsmi_wrapper.py b/py-interface/amdsmi_wrapper.py index 89bf709402..74240ad597 100644 --- a/py-interface/amdsmi_wrapper.py +++ b/py-interface/amdsmi_wrapper.py @@ -774,6 +774,7 @@ class struct_amdsmi_driver_info_t(Structure): struct_amdsmi_driver_info_t._pack_ = 1 # source:False struct_amdsmi_driver_info_t._fields_ = [ + ('driver_name', ctypes.c_char * 64), ('driver_version', ctypes.c_char * 64), ('driver_date', ctypes.c_char * 64), ] diff --git a/src/amd_smi/amd_smi.cc b/src/amd_smi/amd_smi.cc index 667ec666c6..20306ebf51 100644 --- a/src/amd_smi/amd_smi.cc +++ b/src/amd_smi/amd_smi.cc @@ -1721,18 +1721,30 @@ amdsmi_status_t amdsmi_get_gpu_driver_info(amdsmi_processor_handle processor_han return r; int length = AMDSMI_MAX_STRING_LENGTH; + + // Get the driver version status = smi_amdgpu_get_driver_version(gpu_device, &length, info->driver_version); + + // Get the driver date std::string driver_date; status = gpu_device->amdgpu_query_driver_date(driver_date); - if (status != AMDSMI_STATUS_SUCCESS) return r; - + if (status != AMDSMI_STATUS_SUCCESS) + return r; // Reformat the driver date from 20150101 to 2015/01/01 00:00 if (driver_date.length() == 8) { driver_date = driver_date.substr(0, 4) + "/" + driver_date.substr(4, 2) + "/" + driver_date.substr(6, 2) + " 00:00"; } strncpy(info->driver_date, driver_date.c_str(), AMDSMI_MAX_STRING_LENGTH-1); + + // Get the driver name + std::string driver_name; + status = gpu_device->amdgpu_query_driver_name(driver_name); + if (status != AMDSMI_STATUS_SUCCESS) + return r; + strncpy(info->driver_name, driver_name.c_str(), AMDSMI_MAX_STRING_LENGTH-1); + return status; } diff --git a/src/amd_smi/amd_smi_drm.cc b/src/amd_smi/amd_smi_drm.cc index 49677e77e8..f3c6d8e090 100644 --- a/src/amd_smi/amd_smi_drm.cc +++ b/src/amd_smi/amd_smi_drm.cc @@ -197,6 +197,18 @@ amdsmi_status_t AMDSmiDrm::cleanup() { return AMDSMI_STATUS_SUCCESS; } +amdsmi_status_t AMDSmiDrm::amdgpu_query_driver_name(int fd, std::string& driver_name) { + // RAII handler + using drm_version_ptr = std::unique_ptr; + std::lock_guard guard(drm_mutex_); + auto version = drm_version_ptr( + drm_get_version_(fd), drm_free_version_); + if (version == nullptr) return AMDSMI_STATUS_DRM_ERROR; + driver_name = version->name; + return AMDSMI_STATUS_SUCCESS; +} + amdsmi_status_t AMDSmiDrm::amdgpu_query_driver_date(int fd, std::string& driver_date) { // RAII handler using drm_version_ptr = std::unique_ptr Date: Wed, 4 Oct 2023 13:47:36 -0500 Subject: [PATCH 15/16] TESTS - Don't fail on TestFrequenciesRead - Return from freq_output function early if clock is unsupported - Right-align frequencies Change-Id: I799c9351dac8a5be161bc9243cd3816539728357 Signed-off-by: Galantsev, Dmitrii --- .../functional/frequencies_read.cc | 40 +++++++++++-------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/tests/rocm_smi_test/functional/frequencies_read.cc b/tests/rocm_smi_test/functional/frequencies_read.cc index 37bb9ec0b2..5b956e9951 100755 --- a/tests/rocm_smi_test/functional/frequencies_read.cc +++ b/tests/rocm_smi_test/functional/frequencies_read.cc @@ -43,9 +43,7 @@ * */ -#include -#include - +#include #include #include @@ -87,15 +85,23 @@ void TestFrequenciesRead::Close() { static void print_frequencies(rsmi_frequencies_t *f, uint32_t *l = nullptr) { assert(f != nullptr); - for (uint32_t j = 0; j < f->num_supported; ++j) { - std::cout << "\t** " << j << ": " << f->frequency[j]; + for (uint32_t clk_i = 0; clk_i < f->num_supported; ++clk_i) { + std::string clk_i_str; + if (f->has_deep_sleep) { + clk_i_str = (clk_i == 0) ? "S" : std::to_string(clk_i-1); + } else { + clk_i_str = std::to_string(clk_i); + } + std::cout << "\t** " << + std::setw(2) << std::right << clk_i_str << ": " << + std::setw(11) << std::right << f->frequency[clk_i]; if (l != nullptr) { - std::cout << "T/s; x" << l[j]; + std::cout << "T/s; x" << l[clk_i]; } else { std::cout << "Hz"; } - if (j == f->current) { + if (clk_i == f->current) { std::cout << " *"; } std::cout << std::endl; @@ -123,12 +129,14 @@ void TestFrequenciesRead::Run(void) { // Verify api support checking functionality is working err = rsmi_dev_gpu_clk_freq_get(i, t, nullptr); ASSERT_EQ(err, RSMI_STATUS_NOT_SUPPORTED); + return; } // special driver issue, shouldn't normally occur if (err == RSMI_STATUS_UNEXPECTED_DATA) { std::cerr << "WARN: Clock file [" << FreqEnumToStr(t) << "] exists on device [" << i << "] but empty!" << std::endl; std::cerr << " Likely a driver issue!" << std::endl; + return; } CHK_ERR_ASRT(err) @@ -158,15 +166,15 @@ void TestFrequenciesRead::Run(void) { err = rsmi_dev_pci_bandwidth_get(i, nullptr); ASSERT_EQ(err, RSMI_STATUS_NOT_SUPPORTED); } else { - CHK_ERR_ASRT(err) - IF_VERB(STANDARD) { - std::cout << "\t**Supported PCIe bandwidths: "; - std::cout << b.transfer_rate.num_supported << std::endl; - print_frequencies(&b.transfer_rate, b.lanes); - // Verify api support checking functionality is working - err = rsmi_dev_pci_bandwidth_get(i, nullptr); - ASSERT_EQ(err, RSMI_STATUS_INVALID_ARGS); - } + CHK_ERR_ASRT(err) + IF_VERB(STANDARD) { + std::cout << "\t**Supported PCIe bandwidths: "; + std::cout << b.transfer_rate.num_supported << std::endl; + print_frequencies(&b.transfer_rate, b.lanes); + // Verify api support checking functionality is working + err = rsmi_dev_pci_bandwidth_get(i, nullptr); + ASSERT_EQ(err, RSMI_STATUS_INVALID_ARGS); + } } } } From 656f12e0f3905b9c79a16c6de5033a4d7ae724eb Mon Sep 17 00:00:00 2001 From: "Bill(Shuzhou) Liu" Date: Tue, 3 Oct 2023 11:11:56 -0500 Subject: [PATCH 16/16] Read PCIe slot type from sysfs Read the PCIe slot type from sysfs instead of libdrm. Change-Id: I9392b9e18a209ac7332f6902bcafb3b6062c86c1 --- rocm_smi/include/rocm_smi/rocm_smi.h | 33 +++++++++++++++++++ rocm_smi/include/rocm_smi/rocm_smi_device.h | 4 +++ rocm_smi/include/rocm_smi/rocm_smi_utils.h | 3 ++ rocm_smi/src/rocm_smi.cc | 23 +++++++++++++ rocm_smi/src/rocm_smi_device.cc | 31 ++++++++++++++++++ rocm_smi/src/rocm_smi_main.cc | 1 + src/amd_smi/amd_smi.cc | 36 +++++++-------------- 7 files changed, 107 insertions(+), 24 deletions(-) diff --git a/rocm_smi/include/rocm_smi/rocm_smi.h b/rocm_smi/include/rocm_smi/rocm_smi.h index 6f8cb475ac..31064f3cc9 100755 --- a/rocm_smi/include/rocm_smi/rocm_smi.h +++ b/rocm_smi/include/rocm_smi/rocm_smi.h @@ -625,6 +625,19 @@ typedef enum { typedef rsmi_freq_ind_t rsmi_freq_ind; /// \endcond +/** + * @brief The values of this enum are used as PCIe slot type. + */ +typedef enum { + RSMI_PCIE_SLOT_PCIE = 0, + RSMI_PCIE_SLOT_CEM = 1, + RSMI_PCIE_SLOT_OAM = 2, + RSMI_PCIE_SLOT_UNKNOWN = 3 //!< An unknown +} rsmi_pcie_slot_type_t; +/// \cond Ignore in docs. +typedef rsmi_pcie_slot_type_t rsmi_pcie_slot_type; +/// \endcond + /** * @brief The values of this enum are used to identify the various firmware @@ -1391,6 +1404,26 @@ rsmi_status_t rsmi_dev_vendor_name_get(uint32_t dv_ind, char *name, rsmi_status_t rsmi_dev_vram_vendor_get(uint32_t dv_ind, char *brand, uint32_t len); + +/** + * @brief Get the PCIe slot type of a gpu device. + * + * @details Given a device index @p dv_ind, a pointer to a caller provided + * char buffer @p type, this function will write the PCIe slot type of the + * device to @p type. + * + * + * @param[in] dv_ind a device index + * + * @param[inout] type a pointer to a caller provided buffer to which the + * type info will be written + * + * @retval ::RSMI_STATUS_SUCCESS is returned upon successful call. + * + */ +rsmi_status_t rsmi_dev_pcie_slot_type_get(uint32_t dv_ind, + rsmi_pcie_slot_type_t* type); + /** * @brief Get the serial number string for a device * diff --git a/rocm_smi/include/rocm_smi/rocm_smi_device.h b/rocm_smi/include/rocm_smi/rocm_smi_device.h index e9a61af972..8640bae9c1 100755 --- a/rocm_smi/include/rocm_smi/rocm_smi_device.h +++ b/rocm_smi/include/rocm_smi/rocm_smi_device.h @@ -105,6 +105,7 @@ enum DevInfoTypes { kDevDevRevID, kDevDevProdName, kDevDevProdNum, + kDevBoardInfo, kDevVendorID, kDevSubSysDevID, kDevSubSysVendorID, @@ -200,6 +201,9 @@ class Device { int readDevInfo(DevInfoTypes type, std::vector *retVec); int readDevInfo(DevInfoTypes type, std::size_t b_size, void *p_binary_data); + // Get the property from a file which may contain multiple properties. + int readDevInfo(DevInfoTypes type, const std::string& property, + std::string& value); int writeDevInfo(DevInfoTypes type, uint64_t val); int writeDevInfo(DevInfoTypes type, std::string val); diff --git a/rocm_smi/include/rocm_smi/rocm_smi_utils.h b/rocm_smi/include/rocm_smi/rocm_smi_utils.h index f66eedf314..174ae3e988 100755 --- a/rocm_smi/include/rocm_smi/rocm_smi_utils.h +++ b/rocm_smi/include/rocm_smi/rocm_smi_utils.h @@ -269,6 +269,9 @@ class ScopedAcquire { // In VM environment, the /proc/cpuinfo set hypervisor flag by default bool is_vm_guest(); +// trim a string +std::string trim(const std::string &s); + } // namespace smi } // namespace amd diff --git a/rocm_smi/src/rocm_smi.cc b/rocm_smi/src/rocm_smi.cc index 79c703bc31..10cca04b8d 100755 --- a/rocm_smi/src/rocm_smi.cc +++ b/rocm_smi/src/rocm_smi.cc @@ -910,6 +910,29 @@ rsmi_dev_vendor_id_get(uint32_t dv_ind, uint16_t *id) { return get_id(dv_ind, amd::smi::kDevVendorID, id); } +rsmi_status_t +rsmi_dev_pcie_slot_type_get(uint32_t dv_ind, rsmi_pcie_slot_type_t* type) { + TRY + + std::ostringstream ss; + ss << __PRETTY_FUNCTION__ << "| ======= start ======="; + LOG_TRACE(ss); + CHK_SUPPORT_NAME_ONLY(type) + DEVICE_MUTEX + + std::string value; + int ret = dev->readDevInfo(amd::smi::kDevBoardInfo, "type", value); + if (ret != 0) return RSMI_STATUS_NOT_SUPPORTED; + + *type = RSMI_PCIE_SLOT_PCIE; + if (value.compare("oam") == 0) *type=RSMI_PCIE_SLOT_OAM; + else if (value.compare("cem") == 0 ) *type=RSMI_PCIE_SLOT_CEM; + else if (value.compare("unknown") == 0 ) *type=RSMI_PCIE_SLOT_UNKNOWN; + return RSMI_STATUS_SUCCESS; + + CATCH +} + rsmi_status_t rsmi_dev_subsystem_vendor_id_get(uint32_t dv_ind, uint16_t *id) { std::ostringstream ss; diff --git a/rocm_smi/src/rocm_smi_device.cc b/rocm_smi/src/rocm_smi_device.cc index 1310b27956..a1a45795e2 100755 --- a/rocm_smi/src/rocm_smi_device.cc +++ b/rocm_smi/src/rocm_smi_device.cc @@ -87,6 +87,7 @@ static const char *kDevDevProdNumFName = "product_number"; static const char *kDevDevIDFName = "device"; static const char *kDevDevRevIDFName = "revision"; static const char *kDevVendorIDFName = "vendor"; +static const char *kDevBoardInfoFName = "board_info"; static const char *kDevSubSysDevIDFName = "subsystem_device"; static const char *kDevSubSysVendorIDFName = "subsystem_vendor"; static const char *kDevOverDriveLevelFName = "pp_sclk_od"; @@ -238,6 +239,7 @@ static const std::map kDevAttribNameMap = { {kDevPerfLevel, kDevPerfLevelFName}, {kDevOverDriveLevel, kDevOverDriveLevelFName}, {kDevMemOverDriveLevel, kDevMemOverDriveLevelFName}, + {kDevBoardInfo, kDevBoardInfoFName}, {kDevDevProdName, kDevDevProdNameFName}, {kDevDevProdNum, kDevDevProdNumFName}, {kDevDevID, kDevDevIDFName}, @@ -388,6 +390,7 @@ static const std::map kDevFuncDependsMap = { {"rsmi_dev_name_get", {{kDevVendorIDFName, kDevDevIDFName}, {}}}, {"rsmi_dev_sku_get", {{kDevDevProdNumFName}, {}}}, + {"rsmi_dev_pcie_slot_type_get", {{kDevBoardInfoFName}, {}}}, {"rsmi_dev_brand_get", {{kDevVendorIDFName, kDevVBiosVerFName}, {}}}, {"rsmi_dev_vendor_name_get", {{kDevVendorIDFName}, {}}}, @@ -1003,6 +1006,34 @@ int Device::readDevInfo(DevInfoTypes type, uint64_t *val) { return 0; } +// Read a property from a file which may contain multiple properties +int Device::readDevInfo(DevInfoTypes type, const std::string& property, + std::string& value) { + std::vector val; + int ret = 0; + switch (type) { + case kDevBoardInfo: + ret = readDevInfoMultiLineStr(type, &val); + break; + default: + return EINVAL; + } + if (ret != 0) return ret; + + // Find the property from the file + for (unsigned int i = 0; i < val.size(); i++) { + auto pos = val[i].find(":"); // delimiter + if (pos == std::string::npos) continue; + auto name = trim(val[i].substr(0, pos)); + if (name != property) continue; + value = trim(val[i].substr(pos+1)); + return 0; + } + + + return EINVAL; +} + int Device::readDevInfo(DevInfoTypes type, std::vector *val) { assert(val != nullptr); diff --git a/rocm_smi/src/rocm_smi_main.cc b/rocm_smi/src/rocm_smi_main.cc index 9089e9093d..2e5b322f28 100755 --- a/rocm_smi/src/rocm_smi_main.cc +++ b/rocm_smi/src/rocm_smi_main.cc @@ -86,6 +86,7 @@ amd::smi::RocmSMI::devInfoTypesStrings = { {amd::smi::kDevDevID, amdSMI + "kDevDevID"}, {amd::smi::kDevDevRevID, amdSMI + "kDevDevRevID"}, {amd::smi::kDevDevProdName, amdSMI + "kDevDevProdName"}, + {amd::smi::kDevBoardInfo, amdSMI + "kDevBoardInfo"}, {amd::smi::kDevDevProdNum, amdSMI + "kDevDevProdNum"}, {amd::smi::kDevVendorID, amdSMI + "kDevVendorID"}, {amd::smi::kDevSubSysDevID, amdSMI + "kDevSubSysDevID"}, diff --git a/src/amd_smi/amd_smi.cc b/src/amd_smi/amd_smi.cc index 20306ebf51..7040860e06 100644 --- a/src/amd_smi/amd_smi.cc +++ b/src/amd_smi/amd_smi.cc @@ -1830,22 +1830,14 @@ amdsmi_get_pcie_link_status(amdsmi_processor_handle processor_handle, amdsmi_pci // default to PCIe info->pcie_slot_type = AMDSMI_SLOT_TYPE__PCIE; - amd::smi::AMDSmiGPUDevice* gpu_device = nullptr; - status = get_gpu_device_from_handle( - processor_handle, &gpu_device); - if (status == AMDSMI_STATUS_SUCCESS - && gpu_device->check_if_drm_is_supported()) { - struct drm_amdgpu_info_device dev_info = {}; - status = gpu_device->amdgpu_query_info(AMDGPU_INFO_DEV_INFO, - sizeof(struct drm_amdgpu_memory_info), &dev_info); - // bits [16:17] in ids_flags field as slot type - if (status == AMDSMI_STATUS_SUCCESS) { - // two bits starts with index 16 - info->pcie_slot_type = static_cast((dev_info.ids_flags >> 16) & 0x03); - } + rsmi_pcie_slot_type_t slot_type; + status = rsmi_wrapper(rsmi_dev_pcie_slot_type_get, + processor_handle, &slot_type); + if (status == AMDSMI_STATUS_SUCCESS) { + info->pcie_slot_type = static_cast(slot_type); } - return status; + return AMDSMI_STATUS_SUCCESS; } amdsmi_status_t amdsmi_get_pcie_link_caps(amdsmi_processor_handle processor_handle, amdsmi_pcie_info_t *info) { @@ -1921,18 +1913,14 @@ amdsmi_status_t amdsmi_get_pcie_link_caps(amdsmi_processor_handle processor_hand // default to PCIe info->pcie_slot_type = AMDSMI_SLOT_TYPE__PCIE; - if (gpu_device->check_if_drm_is_supported()) { - struct drm_amdgpu_info_device dev_info = {}; - status = gpu_device->amdgpu_query_info(AMDGPU_INFO_DEV_INFO, - sizeof(struct drm_amdgpu_memory_info), &dev_info); - // bits [16:17] in ids_flags field as slot type - if (status == AMDSMI_STATUS_SUCCESS) { - // two bits starts with index 16 - info->pcie_slot_type = static_cast((dev_info.ids_flags >> 16) & 0x03); - } + rsmi_pcie_slot_type_t slot_type; + status = rsmi_wrapper(rsmi_dev_pcie_slot_type_get, + processor_handle, &slot_type); + if (status == AMDSMI_STATUS_SUCCESS) { + info->pcie_slot_type = static_cast(slot_type); } - return status; + return AMDSMI_STATUS_SUCCESS; } amdsmi_status_t amdsmi_get_processor_handle_from_bdf(amdsmi_bdf_t bdf,