From a33cdd7da67875b01c8f63bdf57396daf193542d Mon Sep 17 00:00:00 2001 From: adapryor Date: Mon, 28 Oct 2024 08:59:03 -0500 Subject: [PATCH 1/8] [SWDEV-446215] Update cmake to put test libs in proper lib dir Change-Id: I2e91b904b3f869cdba717d872c10d799d0260c30 Signed-off-by: adapryor [ROCm/amdsmi commit: 6e01df00ca3b6cb1f4bc156529dfd9ecd0d078de] --- projects/amdsmi/tests/amd_smi_test/CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/projects/amdsmi/tests/amd_smi_test/CMakeLists.txt b/projects/amdsmi/tests/amd_smi_test/CMakeLists.txt index 6433986a9a..c80b7648dc 100644 --- a/projects/amdsmi/tests/amd_smi_test/CMakeLists.txt +++ b/projects/amdsmi/tests/amd_smi_test/CMakeLists.txt @@ -4,7 +4,7 @@ option(INSTALL_GTEST "Install GTest (only useful if GTest is not already install # Help tests find libraries at runtime set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--enable-new-dtags") set(CMAKE_INSTALL_RPATH - "\$ORIGIN:\$ORIGIN/../../../lib" + "\$ORIGIN:\$ORIGIN/../../../lib:CPACK_PACKAGING_INSTALL_PREFIX/lib" CACHE STRING "RUNPATH for tests. Helps find libgtest.so and libamd_smi.so") # Download and compile googletest @@ -76,6 +76,6 @@ install( # Install googletest libraries with tests install(TARGETS gtest gtest_main - DESTINATION ${SHARE_INSTALL_PREFIX}/tests + DESTINATION ${CPACK_PACKAGING_INSTALL_PREFIX}/lib COMPONENT ${TESTS_COMPONENT}) From 73f909cd8bb15da8cbceff4f731e87f38da03b8b Mon Sep 17 00:00:00 2001 From: Joe Narlo Date: Wed, 30 Oct 2024 09:55:52 -0500 Subject: [PATCH 2/8] SWDEV-495316 [AMDSMI] In amdsmi.h, change typedef amdsmi_accelerator_partition_profile_t to match definition in Confluence Move memory_caps defintion and correct the number in reserved to match Confluence Signed-off-by: Joe Narlo Change-Id: Id94144f4b3d2d3d7b4d7327211ffc1957ffd0a93 [ROCm/amdsmi commit: 54462ab447d309e09639613196203a9f3b43084b] --- projects/amdsmi/include/amd_smi/amdsmi.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/projects/amdsmi/include/amd_smi/amdsmi.h b/projects/amdsmi/include/amd_smi/amdsmi.h index 21ef4b077e..fb4875632f 100644 --- a/projects/amdsmi/include/amd_smi/amdsmi.h +++ b/projects/amdsmi/include/amd_smi/amdsmi.h @@ -691,11 +691,11 @@ typedef union { typedef struct { amdsmi_accelerator_partition_type_t profile_type; // SPX, DPX, QPX, CPX and so on uint32_t num_partitions; // On MI300X, SPX: 1, DPX: 2, QPX: 4, CPX: 8, length of resources array - uint32_t profile_index; amdsmi_nps_caps_t memory_caps; // Possible memory partition capabilities + uint32_t profile_index; uint32_t num_resources; // length of index_of_resources_profile uint32_t resources[AMDSMI_MAX_ACCELERATOR_PARTITIONS][AMDSMI_MAX_CP_PROFILE_RESOURCES]; - uint64_t reserved[6]; + uint64_t reserved[13]; } amdsmi_accelerator_partition_profile_t; typedef enum { From bfbb2f9de78a98c51071c8987c7500f00d6e4f22 Mon Sep 17 00:00:00 2001 From: adapryor Date: Thu, 24 Oct 2024 08:13:18 -0500 Subject: [PATCH 3/8] [SWDEV-412505] Handle mclk permission errors as not supported Change-Id: Idb3eeed76ff55c507f28b5e692f8704704c3e46e Signed-off-by: adapryor [ROCm/amdsmi commit: 02cbffb42a7bf3fb8654d5a0e30b0b2b6e394bcc] --- .../rocm_smi/include/rocm_smi/rocm_smi_utils.h | 1 + projects/amdsmi/rocm_smi/src/rocm_smi.cc | 17 ++++++++++++++--- projects/amdsmi/rocm_smi/src/rocm_smi_utils.cc | 18 ++++++++++++++++++ 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/projects/amdsmi/rocm_smi/include/rocm_smi/rocm_smi_utils.h b/projects/amdsmi/rocm_smi/include/rocm_smi/rocm_smi_utils.h index 6dc4588cd7..901eb96954 100644 --- a/projects/amdsmi/rocm_smi/include/rocm_smi/rocm_smi_utils.h +++ b/projects/amdsmi/rocm_smi/include/rocm_smi/rocm_smi_utils.h @@ -82,6 +82,7 @@ int SameFile(const std::string fileA, const std::string fileB); bool FileExists(char const *filename); std::vector globFilesExist(const std::string& filePattern); int isRegularFile(std::string fname, bool *is_reg); +int isReadOnlyForAll(const std::string& fname, bool *is_read_only); int ReadSysfsStr(std::string path, std::string *retStr); int WriteSysfsStr(std::string path, std::string val); bool IsInteger(const std::string & n_str); diff --git a/projects/amdsmi/rocm_smi/src/rocm_smi.cc b/projects/amdsmi/rocm_smi/src/rocm_smi.cc index 90593b0523..b0c3ea1ead 100644 --- a/projects/amdsmi/rocm_smi/src/rocm_smi.cc +++ b/projects/amdsmi/rocm_smi/src/rocm_smi.cc @@ -2054,7 +2054,7 @@ rsmi_dev_gpu_clk_freq_set(uint32_t dv_ind, return ret; } - int ret_i; + rsmi_status_t status; amd::smi::DevInfoTypes dev_type; const auto & clk_type_it = kClkTypeMap.find(clk_type); @@ -2064,9 +2064,20 @@ rsmi_dev_gpu_clk_freq_set(uint32_t dv_ind, return RSMI_STATUS_INVALID_ARGS; } - ret_i = dev->writeDevInfo(dev_type, freq_enable_str); - return amd::smi::ErrnoToRsmiStatus(ret_i); + status = amd::smi::ErrnoToRsmiStatus(dev->writeDevInfo(dev_type, freq_enable_str)); + // If an operation is not supported, the dev file, ie /sys/class/drm/card1/device/pp_dpm_pcie + // will have read-only perms, and the OS will deny access, before the request hits the driver level + if (status == RSMI_STATUS_PERMISSION){ + bool read_only = false; + int perms = amd::smi::isReadOnlyForAll(dev->path(), &read_only); + if(read_only){ + return RSMI_STATUS_NOT_SUPPORTED; + } + } + + return status; + CATCH } diff --git a/projects/amdsmi/rocm_smi/src/rocm_smi_utils.cc b/projects/amdsmi/rocm_smi/src/rocm_smi_utils.cc index 7c9ece9be1..332228baf1 100644 --- a/projects/amdsmi/rocm_smi/src/rocm_smi_utils.cc +++ b/projects/amdsmi/rocm_smi/src/rocm_smi_utils.cc @@ -173,6 +173,24 @@ int isRegularFile(std::string fname, bool *is_reg) { return 0; } +int isReadOnlyForAll(const std::string& fname, bool *is_read_only){ + struct stat file_stat; + int ret; + + ret = stat(fname.c_str(), &file_stat); + if (ret) { + return errno; + } + + if (is_read_only != nullptr) { + *is_read_only = (file_stat.st_mode & (S_IRUSR | S_IRGRP | S_IROTH)) && !(file_stat.st_mode & (S_IWUSR | S_IWGRP | S_IWOTH)); + } else { + ret = 1; + } + + return ret; +} + int WriteSysfsStr(std::string path, std::string val) { // On success, zero is returned. On error, -1 is returned, and // errno is set to indicate the error. From 5dfc8836e83d2bcfeb22e3138f501684e660c3a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20L=C3=B3pez?= Date: Mon, 5 Aug 2024 13:28:29 +0200 Subject: [PATCH 4/8] Updates driverInitialized() to support amdgpu built as module as well as kernel built-in. Fixes ROCm/rocm_smi_lib#102 and is an updated version of ROCm/rocm_smi_lib#104 Change-Id: Icb3abe820bc67035b822358a1c04bd09a7c22b6b Signed-off-by: Galantsev, Dmitrii Reviewed-by: Galantsev, Dmitrii [ROCm/amdsmi commit: 172a3e233b612a1f9c03c4504ecafa8755171eb9] --- .../rocm_smi/python_smi_tools/rocm_smi.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/projects/amdsmi/rocm_smi/python_smi_tools/rocm_smi.py b/projects/amdsmi/rocm_smi/python_smi_tools/rocm_smi.py index 9ebf07167b..b660d4050e 100755 --- a/projects/amdsmi/rocm_smi/python_smi_tools/rocm_smi.py +++ b/projects/amdsmi/rocm_smi/python_smi_tools/rocm_smi.py @@ -71,14 +71,17 @@ validClockNames.sort() def driverInitialized(): """ Returns true if amdgpu is found in the list of initialized modules """ - driverInitialized = '' - try: - driverInitialized = str(subprocess.check_output("cat /sys/module/amdgpu/initstate |grep live", shell=True)) - except subprocess.CalledProcessError: - pass - if len(driverInitialized) > 0: - return True - return False + driverInitialized = False + if os.path.exists("/sys/module/amdgpu") : + if os.path.exists("/sys/module/amdgpu/initstate"): + # amdgpu is loadable module + with open("/sys/module/amdgpu/initstate") as initstate: + if 'live' in initstate.read(): + driverInitialized = True + else: + # amdgpu is built into the kernel + driverInitialized = True + return driverInitialized def formatJson(device, log): From 2d760697b3b48287890ccb6f19737ab83d42231a Mon Sep 17 00:00:00 2001 From: Maisam Arif Date: Tue, 5 Nov 2024 15:51:10 -0600 Subject: [PATCH 5/8] [SWDEV-492031] Update Market Names Signed-off-by: Maisam Arif Change-Id: I13c2047fd8c7af0dc566f88a3cac8b365697a092 [ROCm/amdsmi commit: 2678e1f3f7472e45e6480c791145ef2120a4a72e] --- projects/amdsmi/src/amd_smi/amd_smi_utils.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/amdsmi/src/amd_smi/amd_smi_utils.cc b/projects/amdsmi/src/amd_smi/amd_smi_utils.cc index 80af991bda..86198625cb 100644 --- a/projects/amdsmi/src/amd_smi/amd_smi_utils.cc +++ b/projects/amdsmi/src/amd_smi/amd_smi_utils.cc @@ -576,7 +576,7 @@ amdsmi_status_t smi_amdgpu_get_market_name_from_dev_id(uint32_t device_id, char break; case 0x74a1: case 0x74b5: - strcpy(market_name, "MI300X-O"); + strcpy(market_name, "AMD Instinct MI300X"); break; case 0x74a2: case 0x74b6: From d221ca528e6d732c69734bacd85aa8c3a0c0204b Mon Sep 17 00:00:00 2001 From: Charis Poag Date: Thu, 31 Oct 2024 11:51:07 -0500 Subject: [PATCH 6/8] [SWDEV-495305] Fix AttributeError: 'Namespace' object has no attribute 'compute_partition' Changes: - [CLI] Earlier we removed compute & memory partition resets, this fix changes back to the correct spacing for reset commands Change-Id: I707ff197baf7a32bfb7ef20f2b26a63acd13f08a Signed-off-by: Charis Poag [ROCm/amdsmi commit: 7fc4b853d43cedbba0fde00b4dea0473f91d57b5] --- projects/amdsmi/CHANGELOG.md | 2 + projects/amdsmi/amdsmi_cli/amdsmi_commands.py | 88 +++++++++---------- 2 files changed, 46 insertions(+), 44 deletions(-) diff --git a/projects/amdsmi/CHANGELOG.md b/projects/amdsmi/CHANGELOG.md index 45c7470b2b..41ba4dc8d9 100644 --- a/projects/amdsmi/CHANGELOG.md +++ b/projects/amdsmi/CHANGELOG.md @@ -591,6 +591,8 @@ GPU: 0 ### Resolved issues +- **Fixed `amd-smi reset` commands showing an AttributeError**. + - **Improved Offline install process & lowered dependency for PyYAML**. - **Fixed CPX not showing total number of logical GPUs**. diff --git a/projects/amdsmi/amdsmi_cli/amdsmi_commands.py b/projects/amdsmi/amdsmi_cli/amdsmi_commands.py index 74735cb5e8..57c23ddf04 100644 --- a/projects/amdsmi/amdsmi_cli/amdsmi_commands.py +++ b/projects/amdsmi/amdsmi_cli/amdsmi_commands.py @@ -4270,7 +4270,7 @@ class AMDSMICommands(): # Error if no subcommand args are passed if self.helpers.is_baremetal(): if not any([args.gpureset, args.clocks, args.fans, args.profile, args.xgmierr, \ - args.perf_determinism, args.compute_partition, args.memory_partition, \ + args.perf_determinism, \ args.power_cap, args.clean_local_data]): command = " ".join(sys.argv[1:]) raise AmdSmiRequiredCommandException(command, self.logger.format) @@ -4337,8 +4337,8 @@ class AMDSMICommands(): logging.debug("Failed to reset fans on gpu %s | %s", gpu_id, e.get_error_info()) self.logger.store_output(args.gpu, 'reset_fans', result) if args.profile: - reset_profile_results = {'power_profile' : '', - 'performance_level': ''} + reset_profile_results = {'power_profile' : 'N/A', + 'performance_level': 'N/A'} try: power_profile_mask = amdsmi_interface.AmdSmiPowerProfilePresetMasks.BOOTUP_DEFAULT amdsmi_interface.amdsmi_set_gpu_power_profile(args.gpu, 0, power_profile_mask) @@ -4349,48 +4349,48 @@ class AMDSMICommands(): reset_profile_results['power_profile'] = "N/A" logging.debug("Failed to reset power profile on gpu %s | %s", gpu_id, e.get_error_info()) - try: - level_auto = amdsmi_interface.AmdSmiDevPerfLevel.AUTO - amdsmi_interface.amdsmi_set_gpu_perf_level(args.gpu, level_auto) - reset_profile_results['performance_level'] = 'Successfully reset Performance Level' - except amdsmi_exception.AmdSmiLibraryException as e: - if e.get_error_code() == amdsmi_interface.amdsmi_wrapper.AMDSMI_STATUS_NO_PERM: - raise PermissionError('Command requires elevation') from e - reset_profile_results['performance_level'] = "N/A" - logging.debug("Failed to reset perf level on gpu %s | %s", gpu_id, e.get_error_info()) + try: + level_auto = amdsmi_interface.AmdSmiDevPerfLevel.AUTO + amdsmi_interface.amdsmi_set_gpu_perf_level(args.gpu, level_auto) + reset_profile_results['performance_level'] = 'Successfully reset Performance Level' + except amdsmi_exception.AmdSmiLibraryException as e: + if e.get_error_code() == amdsmi_interface.amdsmi_wrapper.AMDSMI_STATUS_NO_PERM: + raise PermissionError('Command requires elevation') from e + reset_profile_results['performance_level'] = "N/A" + logging.debug("Failed to reset perf level on gpu %s | %s", gpu_id, e.get_error_info()) - self.logger.store_output(args.gpu, 'reset_profile', reset_profile_results) - if args.xgmierr: - try: - amdsmi_interface.amdsmi_reset_gpu_xgmi_error(args.gpu) - result = 'Successfully reset XGMI Error count' - except amdsmi_exception.AmdSmiLibraryException as e: - if e.get_error_code() == amdsmi_interface.amdsmi_wrapper.AMDSMI_STATUS_NO_PERM: - raise PermissionError('Command requires elevation') from e - result = "N/A" - logging.debug("Failed to reset xgmi error count on gpu %s | %s", gpu_id, e.get_error_info()) - self.logger.store_output(args.gpu, 'reset_xgmi_err', result) - if args.perf_determinism: - try: - level_auto = amdsmi_interface.AmdSmiDevPerfLevel.AUTO - amdsmi_interface.amdsmi_set_gpu_perf_level(args.gpu, level_auto) - result = 'Successfully disabled performance determinism' - except amdsmi_exception.AmdSmiLibraryException as e: - if e.get_error_code() == amdsmi_interface.amdsmi_wrapper.AMDSMI_STATUS_NO_PERM: - raise PermissionError('Command requires elevation') from e - result = "N/A" - logging.debug("Failed to set perf level on gpu %s | %s", gpu_id, e.get_error_info()) - self.logger.store_output(args.gpu, 'reset_perf_determinism', result) - if args.power_cap: - try: - power_cap_info = amdsmi_interface.amdsmi_get_power_cap_info(args.gpu) - logging.debug(f"Power cap info for gpu {gpu_id} | {power_cap_info}") - default_power_cap_in_w = power_cap_info["default_power_cap"] - default_power_cap_in_w = self.helpers.convert_SI_unit(default_power_cap_in_w, AMDSMIHelpers.SI_Unit.MICRO) - current_power_cap_in_w = power_cap_info["power_cap"] - current_power_cap_in_w = self.helpers.convert_SI_unit(current_power_cap_in_w, AMDSMIHelpers.SI_Unit.MICRO) - except amdsmi_exception.AmdSmiLibraryException as e: - raise ValueError(f"Unable to get power cap info from {gpu_id}") from e + self.logger.store_output(args.gpu, 'reset_profile', reset_profile_results) + if args.xgmierr: + try: + amdsmi_interface.amdsmi_reset_gpu_xgmi_error(args.gpu) + result = 'Successfully reset XGMI Error count' + except amdsmi_exception.AmdSmiLibraryException as e: + if e.get_error_code() == amdsmi_interface.amdsmi_wrapper.AMDSMI_STATUS_NO_PERM: + raise PermissionError('Command requires elevation') from e + result = "N/A" + logging.debug("Failed to reset xgmi error count on gpu %s | %s", gpu_id, e.get_error_info()) + self.logger.store_output(args.gpu, 'reset_xgmi_err', result) + if args.perf_determinism: + try: + level_auto = amdsmi_interface.AmdSmiDevPerfLevel.AUTO + amdsmi_interface.amdsmi_set_gpu_perf_level(args.gpu, level_auto) + result = 'Successfully disabled performance determinism' + except amdsmi_exception.AmdSmiLibraryException as e: + if e.get_error_code() == amdsmi_interface.amdsmi_wrapper.AMDSMI_STATUS_NO_PERM: + raise PermissionError('Command requires elevation') from e + result = "N/A" + logging.debug("Failed to set perf level on gpu %s | %s", gpu_id, e.get_error_info()) + self.logger.store_output(args.gpu, 'reset_perf_determinism', result) + if args.power_cap: + try: + power_cap_info = amdsmi_interface.amdsmi_get_power_cap_info(args.gpu) + logging.debug(f"Power cap info for gpu {gpu_id} | {power_cap_info}") + default_power_cap_in_w = power_cap_info["default_power_cap"] + default_power_cap_in_w = self.helpers.convert_SI_unit(default_power_cap_in_w, AMDSMIHelpers.SI_Unit.MICRO) + current_power_cap_in_w = power_cap_info["power_cap"] + current_power_cap_in_w = self.helpers.convert_SI_unit(current_power_cap_in_w, AMDSMIHelpers.SI_Unit.MICRO) + except amdsmi_exception.AmdSmiLibraryException as e: + raise ValueError(f"Unable to get power cap info from {gpu_id}") from e if current_power_cap_in_w == default_power_cap_in_w: self.logger.store_output(args.gpu, 'powercap', f"Power cap is already set to {default_power_cap_in_w}") From 17f7c7c2e857efe62c39f378e557800a7c12fcb9 Mon Sep 17 00:00:00 2001 From: gabrpham Date: Wed, 6 Nov 2024 15:29:17 -0600 Subject: [PATCH 7/8] [SWDEV-489060] Added python3-setuptools and wheel as prereqs in README. Signed-off-by: gabrpham Change-Id: I51cf938033d746bd6c255d518d7e0d3a87296be4 [ROCm/amdsmi commit: 4effd48fe2906b19e8a8a67f541ceb5d4281acc7] --- projects/amdsmi/README.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/projects/amdsmi/README.md b/projects/amdsmi/README.md index df5d18518b..0cc125e01f 100644 --- a/projects/amdsmi/README.md +++ b/projects/amdsmi/README.md @@ -24,6 +24,9 @@ installed to query firmware information and hardware IPs. ### Requirements * python 3.6.8+ 64-bit + - prerequisite modules: + - python3-wheel + - python3-setuptools * amdgpu driver must be loaded for amdsmi_init() to pass ### Installation @@ -91,6 +94,14 @@ Type "help", "copyright", "credits" or "license" for more information. >>> ``` +### Installing the Python Prerequisite Modules + +Python3-setuptools and python3-wheel can both be installed through the pip installer as shown below: + +```bash +python3 -m pip install setuptools wheel +``` + ## Usage Basics for the C Library ### Device/Socket handles From f162de9efdd0ed4897098230733957335f5eada4 Mon Sep 17 00:00:00 2001 From: gabrpham Date: Wed, 6 Nov 2024 10:33:14 -0600 Subject: [PATCH 8/8] [SWDEV-495985] Changed ACCELERATOR_TYPE default value. Default value changed from 0 to "N/A". Actual values for all fields will be filled out in later API update. Signed-off-by: gabrpham Change-Id: I69b08fff894a032ef79301754807ed4b5c85257f [ROCm/amdsmi commit: 27996aef18e9ece594915e5c1261a38085ce3c6c] --- projects/amdsmi/amdsmi_cli/amdsmi_commands.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/projects/amdsmi/amdsmi_cli/amdsmi_commands.py b/projects/amdsmi/amdsmi_cli/amdsmi_commands.py index 57c23ddf04..03538c1f84 100644 --- a/projects/amdsmi/amdsmi_cli/amdsmi_commands.py +++ b/projects/amdsmi/amdsmi_cli/amdsmi_commands.py @@ -5239,6 +5239,9 @@ class AMDSMICommands(): current_mem_cap = "N/A" logging.debug("Failed to get current memory partition capabilties for GPU %s | %s", gpu_id, e.get_error_info()) + if profile_type == 0: + profile_type = "N/A" + tabular_output_dict = {"gpu_id": gpu_id, "memory": current_mem_cap, "accelerator_type": profile_type, @@ -5298,6 +5301,7 @@ class AMDSMICommands(): self.logger.store_multiple_device_output() self.logger.print_output(multiple_device_enabled=True) self.logger.clear_multiple_devices_ouput() + if args.accelerator: self.logger.table_header = ''.rjust(7) current_header = "GPU_ID".ljust(13) + \ @@ -5361,6 +5365,9 @@ class AMDSMICommands(): mem_caps_str = "N/A" logging.debug("Failed to get accelerator partition profile for GPU %s | %s", gpu_id, e.get_error_info()) + if profile_type == 0: + profile_type = "N/A" + tabular_output_dict = {"gpu_id": gpu_id, "profile_index": profile_index, "memory_partition_caps": mem_caps_str,