SWDEV-429037 - Automatically install amdsmi python lib with package

Signed-off-by: Maisam Arif <maisarif@amd.com>
Change-Id: I9c8c1335982ebd61a29da6f66c635f0a97d95f6e


[ROCm/amdsmi commit: c2e12feb6a]
This commit is contained in:
Maisam Arif
2023-10-25 18:52:46 -05:00
committed by Maisam Arif
parent cf0098c16f
commit 0a90c7cfc8
12 changed files with 213 additions and 133 deletions
+8 -5
View File
@@ -241,12 +241,12 @@ install(
#Debian package specific variables
set(CPACK_DEBIAN_PACKAGE_PROVIDES "amd-smi")
set(CPACK_DEBIAN_PACKAGE_RECOMMENDS "sudo, libdrm-dev, python3-yaml")
set(CPACK_DEBIAN_PACKAGE_RECOMMENDS "sudo, libdrm-dev, python3-yaml, python3-argcomplete")
set(CPACK_DEBIAN_ASAN_PACKAGE_RECOMMENDS ${CPACK_DEBIAN_PACKAGE_RECOMMENDS})
set(CPACK_DEBIAN_DEV_PACKAGE_RECOMMENDS ${CPACK_DEBIAN_PACKAGE_RECOMMENDS})
set(CPACK_DEBIAN_ASAN_PACKAGE_PROVIDES "${AMD_SMI_PACKAGE}-asan")
set(CPACK_DEBIAN_DEV_PACKAGE_PROVIDES "${AMD_SMI_PACKAGE}")
set(CPACK_DEBIAN_PACKAGE_DEPENDS "python3 (>= 3.7.9)")
set(CPACK_DEBIAN_PACKAGE_DEPENDS "python3 (>= 3.6.8), python3-pip")
set(CPACK_DEBIAN_ASAN_PACKAGE_DEPENDS ${CPACK_DEBIAN_PACKAGE_DEPENDS})
set(CPACK_DEBIAN_DEV_PACKAGE_DEPENDS ${CPACK_DEBIAN_PACKAGE_DEPENDS})
@@ -265,10 +265,13 @@ endif()
set(CPACK_RPM_PACKAGE_PROVIDES "amd-smi")
set(CPACK_RPM_DEV_PACKAGE_PROVIDES "${AMD_SMI_PACKAGE}")
set(CPACK_RPM_ASAN_PACKAGE_PROVIDES "${AMD_SMI_PACKAGE}-asan")
# python version gated by rhel8 :(
set(CPACK_RPM_PACKAGE_SUGGESTS "python3 >= 3.6.8")
set(CPACK_RPM_PACKAGE_SUGGESTS "python3-argcomplete")
set(CPACK_RPM_DEV_PACKAGE_SUGGESTS ${CPACK_RPM_PACKAGE_SUGGESTS})
set(CPACK_RPM_ASAN_PACKAGE_SUGGESTS ${CPACK_RPM_PACKAGE_SUGGESTS})
# python version gated by rhel8 :(
set(CPACK_RPM_PACKAGE_REQUIRES "python3 >= 3.6.8, python3-pip")
set(CPACK_RPM_DEV_PACKAGE_REQUIRES ${CPACK_RPM_PACKAGE_REQUIRES})
set(CPACK_RPM_ASAN_PACKAGE_REQUIRES ${CPACK_RPM_PACKAGE_REQUIRES})
# don't terminate if bytecompile of python files fails
set(CPACK_RPM_SPEC_MORE_DEFINE "%define _python_bytecompile_errors_terminate_build 0")
@@ -306,7 +309,7 @@ configure_file("${CMAKE_CURRENT_SOURCE_DIR}/RPM/post.in" RPM/post @ONLY)
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/RPM/preun.in" RPM/preun @ONLY)
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/RPM/postun.in" RPM/postun @ONLY)
set(CPACK_RPM_POST_INSTALL_SCRIPT_FILE "${CMAKE_CURRENT_BINARY_DIR}/RPM/post")
set ( CPACK_RPM_PRE_UNINSTALL_SCRIPT_FILE "${CMAKE_CURRENT_BINARY_DIR}/RPM/preun" )
set(CPACK_RPM_PRE_UNINSTALL_SCRIPT_FILE "${CMAKE_CURRENT_BINARY_DIR}/RPM/preun")
set(CPACK_RPM_POST_UNINSTALL_SCRIPT_FILE "${CMAKE_CURRENT_BINARY_DIR}/RPM/postun")
#Set the names now using CPACK utility
+30
View File
@@ -104,8 +104,38 @@ do_ldconfig() {
fi
}
do_install_amdsmi_python_lib() {
# get python version
local python3_minor_version=$(python3 -c 'import sys;print(sys.version_info.minor)')
if [ $? -ne 0 ]; then
echo "[WARNING] Could not determine python version. "\
"AMD-SMI python library will not be installed."
return
fi
# check if python version is supported
if [ "$python3_minor_version" -lt 6 ]; then
echo "[WARNING] AMD-SMI python library is not "\
"supported on python version 3.$python3_minor_version. "\
"AMD-SMI python library will not be installed."
return
fi
# Remove old python library
python3 -m pip uninstall amdsmi --yes --quiet
# 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"
python3 -m pip show argcomplete
if [ $? -ne 1 ]; then
activate-global-python-argcomplete
fi
}
case "$1" in
( configure )
do_install_amdsmi_python_lib
do_ldconfig
do_configureLogrotate || return 0
;;
+25
View File
@@ -33,11 +33,36 @@ return_logrotateToOrigConfig() {
fi
}
rm_python_lib() {
# get python version
local python3_minor_version=$(python3 -c 'import sys;print(sys.version_info.minor)')
if [ $? -ne 0 ]; then
echo "[WARNING] Could not determine python version. "\
"AMD-SMI python library will not be uninstalled."
return
fi
# check if python version is supported
if [ "$python3_minor_version" -lt 6 ]; then
echo "[INFO] AMD-SMI python library is not supported on python version 3.$python3_minor_version. "\
"AMD-SMI python library will not be uninstalled."
return
fi
python3 -m pip uninstall amdsmi --yes
python3 -m pip show amdsmi
if [ $? -ne 1 ]; then
echo "[WARNING] AMD-SMI python library (amdsmi) is still installed. "\
"Check post install to ensure version is correct"
return
fi
}
case "$1" in
( remove | upgrade)
# remove old gpuv-smi symlink
rm -f @CPACK_PACKAGING_INSTALL_PREFIX@/bin/gpuv-smi &> /dev/null
rm_python_lib
rm_ldconfig
rm_pyc
rm_logFolder
+67 -90
View File
@@ -17,7 +17,71 @@ AMD SMI library can run on AMD ROCm supported platforms, please refer to [List o
To run the AMD SMI library, the amdgpu driver and the hsmp driver needs to be installed. Optionally, the libdrm can be
installed to query firmware information and hardware IPs.
## Usage Basics
## Install CLI Tool and Libraries
### Requirements
* python 3.6.8+ 64-bit
* amdgpu driver must be loaded for amdsmi_init() to pass
### Installation
* Install amdgpu driver
* Install amd-smi-lib package through package manager
* amd-smi --help
### Install Example for Ubuntu 22.04
``` bash
apt install amd-smi-lib
amd-smi --help
```
### Optional autocompletion
`amd-smi` cli application supports autocompletion. The package should attempt to install it, if argcomplete is not installed you can enable it by using the following commands:
```bash
python3 -m pip install argcomplete
activate-global-python-argcomplete
# restart shell to enable
```
### Manual/Multiple Rocm Instance Python Library Install
In the event there are multiple rocm installations and pyenv is not being used, to use the correct amdsmi version you must uninstall previous versions of amd-smi and install the version you want directly from your rocm instance.
#### Python Library Install Example for Ubuntu 22.04
Remove previous amdsmi installation:
```bash
python3 -m pip list | grep amd
python3 -m pip uninstall amdsmi
```
Then install Python library from your target rocm instance:
``` bash
apt install amd-smi-lib
amd-smi --help
cd /opt/rocm/share/amd_smi
python3 -m pip install --upgrade pip
python3 -m pip install --user .
```
Now you have the amdsmi python library in your python path:
``` bash
~$ python3
Python 3.8.10 (default, May 26 2023, 14:05:08)
[GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import amdsmi
>>>
```
## Usage Basics for the C Library
### Device/Socket handles
@@ -133,92 +197,7 @@ The output will be in `docs/_build/html`.
For additional details, see the [ROCm Contributing Guide](https://rocm.docs.amd.com/en/latest/contributing.html#building-documentation)
## Install CLI Tool and Python Library
### Requirements
* python 3.7+ 64-bit
* amdgpu driver and hsmp driver must be loaded for amdsmi_init() to pass
### Optional autocompletion
`amd-smi` cli application supports autocompletion. It is enabled by using the
following commands:
```bash
python3 -m pip install argcomplete
activate-global-python-argcomplete
# restart shell to enable
```
### CLI Installation
Before amd-smi install, ensure previous versions of amdsmi library are uninstalled using pip:
```bash
python3 -m pip list | grep amd
python3 -m pip uninstall amdsmi
```
* Install amdgpu driver
* Install amd-smi-lib package through package manager
* amd-smi --help
### Install Example for Ubuntu 22.04
``` bash
python3 -m pip list | grep amd
python3 -m pip uninstall amdsmi
apt install amd-smi-lib
amd-smi --help
```
### Python Development Library Installation
This option is for users who want to develop their own scripts using amd-smi's python library
Verify that your python version is 3.7+ to install the python library
* Install amdgpu driver
* Install amd-smi-lib package through package manager
* cd /opt/rocm/share/amd_smi
* python3 -m pip install --upgrade pip
* python3 -m pip install --user .
* import amdsmi in python to start development
Warning: this will take precedence over the cli tool's library install, to avoid issues run these steps after every amd-smi-lib update.
#### Older RPM Packaged OS's
The default python versions in older RPM based OS's are not gauranteed to have the minium version.
For example RHEL 8 and SLES 15 are 3.6.8 and 3.6.15 . You will need to ensure the latest yaml package is installed ( pyyaml >= 5.1) pyyaml is installed to your pip instance:
``` bash
python3 -m pip install pyyaml
amd-smi list
```
While the CLI will work with these older python versions, to install the python development library you need to upgrade to python 3.7+
#### Python Library Install Example for Ubuntu 22.04
``` bash
apt install amd-smi-lib
amd-smi --help
cd /opt/rocm/share/amd_smi
python3 -m pip install --upgrade pip
python3 -m pip install --user .
```
``` bash
python3
Python 3.8.10 (default, May 26 2023, 14:05:08)
[GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import amdsmi
>>>
```
## Building AMD SMI
### Rebuilding Python wrapper
@@ -236,8 +215,6 @@ Note: To be able to re-generate python wrapper you need **docker** installed.
Note: python_wrapper is NOT automatically re-generated. You must run `./update_wrapper.sh`.
## Building AMD SMI
### Additional Required software for building
In order to build the AMD SMI library, the following components are required. Note that the software versions listed are what was used in development. Earlier versions are not guaranteed to work:
@@ -248,7 +225,7 @@ In order to build the AMD SMI library, the following components are required. No
In order to build the AMD SMI python package, the following components are required:
* clang (14.0 or above)
* python (3.7 or above)
* python (3.6.8 or above)
* virtualenv - `python3 -m pip install virtualenv`
In order to build the latest documentation, the following are required:
+30
View File
@@ -104,8 +104,38 @@ do_ldconfig() {
fi
}
do_install_amdsmi_python_lib() {
# get python version
local python3_minor_version=$(python3 -c 'import sys;print(sys.version_info.minor)')
if [ $? -ne 0 ]; then
echo "[WARNING] Could not determine python version. "\
"AMD-SMI python library will not be installed."
return
fi
# check if python version is supported
if [ "$python3_minor_version" -lt 6 ]; then
echo "[WARNING] AMD-SMI python library is not "\
"supported on python version 3.$python3_minor_version. "\
"AMD-SMI python library will not be installed."
return
fi
# Remove old python library
python3 -m pip uninstall amdsmi --yes --quiet
# 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"
python3 -m pip show argcomplete
if [ $? -ne 1 ]; then
activate-global-python-argcomplete
fi
}
# post install or upgrade, $i is 1 or 2 -> do these actions
if [ "$1" -ge 1 ]; then
do_install_amdsmi_python_lib
do_ldconfig
do_configureLogrotate || return 0
fi
+26
View File
@@ -25,10 +25,36 @@ return_logrotateToOrigConfig() {
fi
}
rm_python_lib() {
# get python version
local python3_minor_version=$(python3 -c 'import sys;print(sys.version_info.minor)')
if [ $? -ne 0 ]; then
echo "[WARNING] Could not determine python version. "\
"AMD-SMI python library will not be uninstalled."
return
fi
# check if python version is supported
if [ "$python3_minor_version" -lt 6 ]; then
echo "[INFO] AMD-SMI python library is not supported on python version 3.$python3_minor_version. "\
"AMD-SMI python library will not be uninstalled."
return
fi
python3 -m pip uninstall amdsmi --yes
python3 -m pip show amdsmi
if [ $? -ne 1 ]; then
echo "[WARNING] AMD-SMI python library (amdsmi) is still installed. "\
"Check post install to ensure version is correct"
return
fi
}
if [ "$1" -le 1 ]; then
# perform the below actions for rpm remove($1=0) or upgrade($1=1) operations
# remove old gpuv-smi symlink
rm -f @CPACK_PACKAGING_INSTALL_PREFIX@/bin/gpuv-smi &> /dev/null
rm_python_lib
rm_pyc
rm_logFolder
return_logrotateToOrigConfig
+22 -34
View File
@@ -10,17 +10,10 @@ Recommended: At least one AMD GPU with AMD driver installed
### Requirements
* python 3.7+ 64-bit
* python 3.6.8+ 64-bit
* amdgpu driver must be loaded for amdsmi_init() to pass
### CLI Installation
Before amd-smi install, ensure previous versions of amdsmi library are uninstalled using pip:
```bash
python3 -m pip list | grep amd
python3 -m pip uninstall amdsmi
```
### Installation
* Install amdgpu driver
* Install amd-smi-lib package through package manager
@@ -29,42 +22,35 @@ python3 -m pip uninstall amdsmi
### Install Example for Ubuntu 22.04
``` bash
python3 -m pip list | grep amd
python3 -m pip uninstall amdsmi
apt install amd-smi-lib
amd-smi --help
```
### Python Development Library Installation
### Optional autocompletion
This option is for users who want to develop their own scripts using amd-smi's python library
`amd-smi` cli application supports autocompletion. The package should attempt to install it, if argcomplete is not installed you can enable it by using the following commands:
Verify that your python version is 3.7+ to install the python library
* Install amdgpu driver
* Install amd-smi-lib package through package manager
* cd /opt/rocm/share/amd_smi
* python3 -m pip install --upgrade pip
* python3 -m pip install --user .
* import amdsmi in python to start development
Warning: this will take precedence over the cli tool's library install, to avoid issues run these steps after every amd-smi-lib update.
#### Older RPM Packaged OS's
The default python versions in older RPM based OS's are not gauranteed to have the minium version.
For example RHEL 8 and SLES 15 are 3.6.8 and 3.6.15 . You will need to ensure the latest yaml package is installed ( pyyaml >= 5.1) pyyaml is installed to your pip instance:
``` bash
python3 -m pip install pyyaml
amd-smi list
```bash
python3 -m pip install argcomplete
activate-global-python-argcomplete
# restart shell to enable
```
While the CLI will work with these older python versions, to install the python development library you need to upgrade to python 3.7+
### Manual/Multiple Rocm Instance Python Library Install
In the event there are multiple rocm installations and pyenv is not being used, to use the correct amdsmi version you must uninstall previous versions of amd-smi and install the version you want directly from your rocm instance.
#### Python Library Install Example for Ubuntu 22.04
Remove previous amdsmi installation:
```bash
python3 -m pip list | grep amd
python3 -m pip uninstall amdsmi
```
Then install Python library from your target rocm instance:
``` bash
apt install amd-smi-lib
amd-smi --help
@@ -73,6 +59,8 @@ python3 -m pip install --upgrade pip
python3 -m pip install --user .
```
Now you have the amdsmi python library in your python path:
``` bash
~$ python3
Python 3.8.10 (default, May 26 2023, 14:05:08)
+1 -1
View File
@@ -30,8 +30,8 @@ import sys
from pathlib import Path
sys.path.append(f"{Path(__file__).resolve().parent}/../../share/amd_smi")
sys.path.append("/opt/rocm/share/amd_smi")
# If the python library is installed, it will overwrite the path above
from amdsmi import amdsmi_interface
from amdsmi import amdsmi_exception
+1 -1
View File
@@ -46,7 +46,7 @@ if(NOT GOOD_CLANG_FOUND)
COMMAND mkdir -p ${PY_PACKAGE_DIR}
COMMAND ln -Pf ${CMAKE_CURRENT_BINARY_DIR}/amdsmi_wrapper.py ${PY_PACKAGE_DIR}/)
else()
find_package(Python3 3.7 COMPONENTS Interpreter Development REQUIRED)
find_package(Python3 3.6 COMPONENTS Interpreter Development REQUIRED)
# --break-system-packages is needed for python 3.11
# see: https://peps.python.org/pep-0668/
if (NOT Python3_VERSION VERSION_LESS "3.11")
+1 -1
View File
@@ -2,7 +2,7 @@
## Requirements
* python 3.7+ 64-bit
* python 3.6+ 64-bit
* driver must be loaded for amdsmi_init() to pass
## Overview
@@ -168,6 +168,7 @@ def char_pointer_cast(string, encoding='utf-8'):
_libraries = {}
from pathlib import Path
### TODO: Add lib build folder cmake variable or dynamic
libamd_smi_cpack = Path("@CPACK_PACKAGING_INSTALL_PREFIX@/@CMAKE_INSTALL_LIBDIR@/libamd_smi.so")
libamd_smi_optrocm = Path("/opt/rocm/lib/libamd_smi.so")
libamd_smi_parent_dir = Path(__file__).resolve().parent / "libamd_smi.so"
+1 -1
View File
@@ -3,7 +3,7 @@
#
message("&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&")
message(" CMake AMD SMI (Library) ")
message(" CMake AMD SMI C/C++ Library ")
message("&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&")
message("")