diff --git a/projects/amdsmi/CHANGELOG.md b/projects/amdsmi/CHANGELOG.md index 817b77109a..5f1e04f8ff 100644 --- a/projects/amdsmi/CHANGELOG.md +++ b/projects/amdsmi/CHANGELOG.md @@ -289,6 +289,8 @@ With this change additional padding was added to PCIE_BW `amd-smi monitor --pcie ### Resolved issues +- **Improved Offline install process & lowered dependency for PyYAML**. + - **Fixed CPX not showing total number of logical GPUs**. Updates were made to `amdsmi_init()` and `amdsmi_get_gpu_bdf_id(..)`. In order to display all logical devices, we needed a way to provide order to GPU's enumerated. This was done by adding a partition_id within the BDF optional pci_id bits. diff --git a/projects/amdsmi/DEBIAN/postinst.in b/projects/amdsmi/DEBIAN/postinst.in index 97ea7a7518..8ecd91db0c 100755 --- a/projects/amdsmi/DEBIAN/postinst.in +++ b/projects/amdsmi/DEBIAN/postinst.in @@ -159,6 +159,24 @@ do_install_amdsmi_python_lib() { fi unset pip_version + # Install setuptools wheel (offline install) + echo "Checking for amdsmi_offline.tar.gz..." + offline_packages_tar_path=@CPACK_PACKAGING_INSTALL_PREFIX@/@CMAKE_INSTALL_LIBEXECDIR@/amdsmi_cli/amdsmi_offline.tar.gz + + if [ -z "$offline_packages_tar_path" ]; then + echo "Error: amdsmi_offline.tar.gz not found. Not installing amdsmi offline packages..." + else + echo "Extracting amdsmi_offline.tar.gz..." + offline_packages_target_path=@CPACK_PACKAGING_INSTALL_PREFIX@/@CMAKE_INSTALL_LIBEXECDIR@/amdsmi_cli/ + tar -xzvf $offline_packages_tar_path -C $offline_packages_target_path + offline_packages_path=@CPACK_PACKAGING_INSTALL_PREFIX@/@CMAKE_INSTALL_LIBEXECDIR@/amdsmi_cli/offline_packages + echo "Installing/Upgrading amdsmi offline packages..." + python3 -m pip install --upgrade --upgrade-strategy only-if-needed --no-index --find-links="$offline_packages_path" setuptools + unset offline_packages_path + unset offline_packages_target_path + fi + unset offline_packages_tar_path + # Check PyYAML dependency, typically should not execute pyyaml_version=$(pip show pyyaml | grep -Po '(?<=Version: )[0-9]') if [[ "$pyyaml_version" -lt 3 ]]; then @@ -167,33 +185,6 @@ do_install_amdsmi_python_lib() { fi unset pyyaml_version -# Install setuptools wheel (offline install) -# Function to find the tarball - find_tarball() { - find / -name "amdsmi_offline.tar.gz" 2>/dev/null | head -n 1 - } - - # Locate the tarball - tarball_path=$(find_tarball) - - if [ -z "$tarball_path" ]; then - echo "Error: amdsmi_offline.tar.gz not found." - exit 1 - fi - - # Extract directory from tarball path - base_dir=$(dirname "$tarball_path") - - # Navigate to the directory containing the tarball - cd "$base_dir" || exit - - # Unpack the tarball - tar -xzvf amdsmi_offline.tar.gz - - # Install setuptools offline (if needed) - cd offline_packages || exit - python3 -m pip install --upgrade --upgrade-strategy only-if-needed --no-index --find-links=. setuptools - # install python library at @CPACK_PACKAGING_INSTALL_PREFIX@/@SHARE_INSTALL_PREFIX@/amdsmi local python_lib_path=@CPACK_PACKAGING_INSTALL_PREFIX@/@SHARE_INSTALL_PREFIX@ python3 -m pip install "$python_lib_path" --quiet --disable-pip-version-check --no-build-isolation diff --git a/projects/amdsmi/DEBIAN/prerm.in b/projects/amdsmi/DEBIAN/prerm.in index 3decc72093..88573f33d3 100755 --- a/projects/amdsmi/DEBIAN/prerm.in +++ b/projects/amdsmi/DEBIAN/prerm.in @@ -13,9 +13,13 @@ rm_ldconfig() { rm_leftovers() { # remove pyc files generated by python - rm -rf "@CPACK_PACKAGING_INSTALL_PREFIX@/@CMAKE_INSTALL_LIBEXECDIR@/amdsmi_cli/__pycache__" rm -rf "@CPACK_PACKAGING_INSTALL_PREFIX@/@SHARE_INSTALL_PREFIX@/amdsmi/__pycache__" + # remove CLI folder packages folder + if test -e "@CPACK_PACKAGING_INSTALL_PREFIX@/@CMAKE_INSTALL_LIBEXECDIR@/amdsmi_cli*"; then + rm -rf "@CPACK_PACKAGING_INSTALL_PREFIX@/@CMAKE_INSTALL_LIBEXECDIR@/amdsmi_cli*" + fi + # remove build and egg files rm -rf "@CPACK_PACKAGING_INSTALL_PREFIX@/@SHARE_INSTALL_PREFIX@/amdsmi.egg-info" rm -rf "@CPACK_PACKAGING_INSTALL_PREFIX@/@SHARE_INSTALL_PREFIX@/build" diff --git a/projects/amdsmi/RPM/post.in b/projects/amdsmi/RPM/post.in index d98316b4b8..94d3921481 100755 --- a/projects/amdsmi/RPM/post.in +++ b/projects/amdsmi/RPM/post.in @@ -158,7 +158,25 @@ do_install_amdsmi_python_lib() { fi unset pip_version - # Check PyYAML dependency + # Install setuptools wheel (offline install) + echo "Checking for amdsmi_offline.tar.gz..." + offline_packages_tar_path=@CPACK_PACKAGING_INSTALL_PREFIX@/@CMAKE_INSTALL_LIBEXECDIR@/amdsmi_cli/amdsmi_offline.tar.gz + + if [ -z "$offline_packages_tar_path" ]; then + echo "Error: amdsmi_offline.tar.gz not found. Not installing amdsmi offline packages..." + else + echo "Extracting amdsmi_offline.tar.gz..." + offline_packages_target_path=@CPACK_PACKAGING_INSTALL_PREFIX@/@CMAKE_INSTALL_LIBEXECDIR@/amdsmi_cli/ + tar -xzvf $offline_packages_tar_path -C $offline_packages_target_path + offline_packages_path=@CPACK_PACKAGING_INSTALL_PREFIX@/@CMAKE_INSTALL_LIBEXECDIR@/amdsmi_cli/offline_packages + echo "Installing/Upgrading amdsmi offline packages..." + python3 -m pip install --upgrade --upgrade-strategy only-if-needed --no-index --find-links="$offline_packages_path" setuptools + unset offline_packages_path + unset offline_packages_target_path + fi + unset offline_packages_tar_path + + # Check PyYAML dependency, typically should not execute local pyyaml_version pyyaml_version=$(pip show pyyaml | grep -Po '(?<=Version: )[0-9]') if [[ "$pyyaml_version" -lt 3 ]]; then @@ -167,33 +185,6 @@ do_install_amdsmi_python_lib() { fi unset pyyaml_version -# Install setuptools wheel (offline install) -# Function to find the tarball - find_tarball() { - find / -name "amdsmi_offline.tar.gz" 2>/dev/null | head -n 1 - } - - # Locate the tarball - tarball_path=$(find_tarball) - - if [ -z "$tarball_path" ]; then - echo "Error: amdsmi_offline.tar.gz not found." - exit 1 - fi - - # Extract directory from tarball path - base_dir=$(dirname "$tarball_path") - - # Navigate to the directory containing the tarball - cd "$base_dir" || exit - - # Unpack the tarball - tar -xzvf amdsmi_offline.tar.gz - - # Install setuptools offline (if needed) - cd offline_packages || exit - python3 -m pip install --upgrade --upgrade-strategy only-if-needed --no-index --find-links=. setuptools - # install python library at @CPACK_PACKAGING_INSTALL_PREFIX@/@SHARE_INSTALL_PREFIX@/amdsmi local python_lib_path=@CPACK_PACKAGING_INSTALL_PREFIX@/@SHARE_INSTALL_PREFIX@ python3 -m pip install "$python_lib_path" --quiet --disable-pip-version-check --no-build-isolation diff --git a/projects/amdsmi/RPM/preun.in b/projects/amdsmi/RPM/preun.in index 43e58c93f3..fbfde6b5af 100755 --- a/projects/amdsmi/RPM/preun.in +++ b/projects/amdsmi/RPM/preun.in @@ -2,9 +2,13 @@ rm_leftovers() { # remove pyc files generated by python - rm -rf "@CPACK_PACKAGING_INSTALL_PREFIX@/@CMAKE_INSTALL_LIBEXECDIR@/amdsmi_cli/__pycache__" rm -rf "@CPACK_PACKAGING_INSTALL_PREFIX@/@SHARE_INSTALL_PREFIX@/amdsmi/__pycache__" + # remove CLI folder packages folder + if test -e "@CPACK_PACKAGING_INSTALL_PREFIX@/@CMAKE_INSTALL_LIBEXECDIR@/amdsmi_cli*"; then + rm -rf "@CPACK_PACKAGING_INSTALL_PREFIX@/@CMAKE_INSTALL_LIBEXECDIR@/amdsmi_cli*" + fi + # remove build and egg files rm -rf "@CPACK_PACKAGING_INSTALL_PREFIX@/@SHARE_INSTALL_PREFIX@/amdsmi.egg-info" rm -rf "@CPACK_PACKAGING_INSTALL_PREFIX@/@SHARE_INSTALL_PREFIX@/build" diff --git a/projects/amdsmi/amdsmi_cli/CMakeLists.txt b/projects/amdsmi/amdsmi_cli/CMakeLists.txt index d0cba22c50..6fdd442321 100644 --- a/projects/amdsmi/amdsmi_cli/CMakeLists.txt +++ b/projects/amdsmi/amdsmi_cli/CMakeLists.txt @@ -24,6 +24,7 @@ add_custom_command( ${PY_PACKAGE_DIR}/amdsmi_cli_exceptions.py ${PY_PACKAGE_DIR}/rocm_version.py ${PY_PACKAGE_DIR}/BDF.py + ${PY_PACKAGE_DIR}/amdsmi_offline.tar.gz ${PY_PACKAGE_DIR}/README.md ${PY_PACKAGE_DIR}/Release_Notes.md DEPENDS amdsmi_cli @@ -38,6 +39,7 @@ add_custom_command( COMMAND ln -Pf ${CMAKE_CURRENT_SOURCE_DIR}/amdsmi_cli_exceptions.py ${PY_PACKAGE_DIR}/ COMMAND ln -Pf ${CMAKE_CURRENT_SOURCE_DIR}/rocm_version.py ${PY_PACKAGE_DIR}/ COMMAND ln -Pf ${CMAKE_CURRENT_SOURCE_DIR}/BDF.py ${PY_PACKAGE_DIR}/ + COMMAND ln -Pf ${CMAKE_CURRENT_SOURCE_DIR}/amdsmi_offline.tar.gz ${PY_PACKAGE_DIR}/ COMMAND ln -Pf ${CMAKE_CURRENT_SOURCE_DIR}/README.md ${PY_PACKAGE_DIR}/ COMMAND ln -Pf ${CMAKE_CURRENT_SOURCE_DIR}/Release_Notes.md ${PY_PACKAGE_DIR}/) @@ -56,6 +58,7 @@ add_custom_target( ${PY_PACKAGE_DIR}/amdsmi_cli_exceptions.py ${PY_PACKAGE_DIR}/rocm_version.py ${PY_PACKAGE_DIR}/BDF.py + ${PY_PACKAGE_DIR}/amdsmi_offline.tar.gz ${PY_PACKAGE_DIR}/README.md ${PY_PACKAGE_DIR}/Release_Notes.md) diff --git a/projects/amdsmi/amdsmi_cli/amdsmi_logger.py b/projects/amdsmi/amdsmi_cli/amdsmi_logger.py index 6fb6e5a327..8234f99eac 100644 --- a/projects/amdsmi/amdsmi_cli/amdsmi_logger.py +++ b/projects/amdsmi/amdsmi_cli/amdsmi_logger.py @@ -37,7 +37,7 @@ import amdsmi_cli_exceptions class CustomDumper(yaml.Dumper): def represent_dict_preserve_order(self, data): return self.represent_dict(data.items()) -def has_sort_keys_option(): # to check if sort_keys is available +def has_sort_keys_option(): # to check if sort_keys is available return 'sort_keys' in inspect.signature(yaml.dump).parameters class AMDSMILogger(): @@ -212,14 +212,14 @@ class AMDSMILogger(): json_string = json.dumps(capitalized_json, indent=4) - if has_sort_keys_option(): + if has_sort_keys_option(): yaml_data = yaml.safe_load(json_string) - yaml_output = yaml.dump(yaml_data, sort_keys=False, allow_unicode=True) - else: + yaml_output = yaml.dump(yaml_data, sort_keys=False, allow_unicode=True) + else: CustomDumper.add_representer(dict, CustomDumper.represent_dict_preserve_order) yaml_data = yaml.safe_load(json_string) yaml_output = yaml.dump(yaml_data, Dumper=CustomDumper, allow_unicode=True, default_flow_style=False) - + # Remove a key line if it is a spacer yaml_output = yaml_output.replace("AMDSMI_SPACING_REMOVAL:\n", "") yaml_output = yaml_output.replace("'", "") # Remove '' diff --git a/projects/amdsmi/amdsmi_cli/amdsmi_offline.tar.gz b/projects/amdsmi/amdsmi_cli/amdsmi_offline.tar.gz new file mode 100644 index 0000000000..9484090fd4 Binary files /dev/null and b/projects/amdsmi/amdsmi_cli/amdsmi_offline.tar.gz differ