docs: Remove redundant/stale docs
bump rocm-docs-core to 1.8.2 rm unused files rm stale docs fix sphinx conf reorg docs SWDEV-482203 -- add note to usage guides update readmes Change-Id: I9e0111ac8fe2a691ac964b27436ba47747c27904 Signed-off-by: Peter Park <Peter.Park@amd.com>
This commit is contained in:
1 parent
6e843436f5
commit
e196f98dba
26 files changed
+2871
-7034
No files matched your search
@@ -1,10 +1,37 @@
|
||||
# Using AMD SMI Command Line Interface tool
|
||||
---
|
||||
myst:
|
||||
html_meta:
|
||||
"description lang=en": "Learn how to use the AMD SMI command line tool."
|
||||
"keywords": "api, smi, lib, system, management, interface, example"
|
||||
---
|
||||
|
||||
**Disclaimer: CLI Tool is provided as an example code to aid the development of telemetry tools. Python or C++ Library is recommended as a reliable data source.**
|
||||
# AMD SMI CLI tool usage
|
||||
|
||||
AMD-SMI reports the version and current platform detected when running the command line interface (CLI) without arguments:
|
||||
This tool is a command line interface (CLI) for manipulating and monitoring the
|
||||
`amdgpu` kernel; it is intended to replace and deprecate the existing `rocm_smi`
|
||||
CLI tool and `gpuv-smi` tool. The AMD SMI CLI tool uses Ctypes to call the
|
||||
`amd_smi_lib` API.
|
||||
|
||||
``` bash
|
||||
When using the CLI tool, you should have at least one AMD GPU and the driver
|
||||
installed.
|
||||
|
||||
```{admonition} Disclaimer
|
||||
The AMD SMI CLI tool is provided as an example code to aid the development of
|
||||
telemetry tools. The [Python](./amdsmi-py-lib) or [C++
|
||||
library](./amdsmi-cpp-lib) is recommended as a robust data source.
|
||||
```
|
||||
|
||||
## Install the CLI Tool and Python library
|
||||
|
||||
Refer to the [installation instructions](../install/install.md).
|
||||
|
||||
## Get started
|
||||
|
||||
The amd-smi command provides system management and monitoring capabilities for
|
||||
AMD hardware. When run without arguments, it reports the version and platform
|
||||
detected:
|
||||
|
||||
```shell-session
|
||||
~$ amd-smi
|
||||
usage: amd-smi [-h] ...
|
||||
|
||||
@@ -26,28 +53,38 @@ AMD-SMI Commands:
|
||||
topology Displays topology information of the devices
|
||||
set Set options for devices
|
||||
reset Reset options for devices
|
||||
monitor Monitor metrics for target devices
|
||||
monitor (dmon) Monitor metrics for target devices
|
||||
xgmi Displays xgmi information of the devices
|
||||
```
|
||||
|
||||
Example commands:
|
||||
|
||||
``` bash
|
||||
```shell-session
|
||||
amd-smi static --gpu 0
|
||||
amd-smi metric
|
||||
amd-smi process --gpu 0 1
|
||||
amd-smi reset --gpureset --gpu all
|
||||
```
|
||||
|
||||
More detailed verison information is available from `amd-smi version`
|
||||
```{note}
|
||||
For command-specific help, use `amd-smi [command] --help` for see more detailed
|
||||
usage information. See [Commands](#cmds).
|
||||
|
||||
Each command will have detailed information via `amd-smi [command] --help`
|
||||
For more detailed version information, use `amd-smi version`.
|
||||
```
|
||||
|
||||
(cmds)=
|
||||
## Commands
|
||||
|
||||
For convenience, here is the help output for each command
|
||||
The following are the help output for each command, providing quick reference
|
||||
details for usage.
|
||||
|
||||
```bash
|
||||
(cmd-list)=
|
||||
### amd-smi list
|
||||
|
||||
Lists GPU information.
|
||||
|
||||
```shell-session
|
||||
~$ amd-smi list --help
|
||||
usage: amd-smi list [-h] [--json | --csv] [--file FILE] [--loglevel LEVEL]
|
||||
[-g GPU [GPU ...] | -U CPU [CPU ...] | -O CORE [CORE ...]]
|
||||
@@ -84,7 +121,13 @@ Command Modifiers:
|
||||
DEBUG, INFO, WARNING, ERROR, CRITICAL
|
||||
```
|
||||
|
||||
```bash
|
||||
(cmd-static)=
|
||||
### amd-smi static
|
||||
|
||||
Gets static information about the specified GPU. See the [sample
|
||||
output](#cli-ex-static) for `amd-smi static`.
|
||||
|
||||
```shell-session
|
||||
~$ amd-smi static --help
|
||||
usage: amd-smi static [-h] [-g GPU [GPU ...] | -U CPU [CPU ...]] [-a] [-b] [-V] [-d] [-v]
|
||||
[-c] [-B] [-R] [-r] [-p] [-l] [-P] [-x] [-u] [-s] [-i]
|
||||
@@ -134,7 +177,12 @@ Command Modifiers:
|
||||
DEBUG, INFO, WARNING, ERROR, CRITICAL
|
||||
```
|
||||
|
||||
```bash
|
||||
(cmd-firmware)=
|
||||
### amd-smi firmware
|
||||
|
||||
Gets firmware information about the specified GPU.
|
||||
|
||||
```shell-session
|
||||
~$ amd-smi firmware --help
|
||||
usage: amd-smi firmware [-h] [--json | --csv] [--file FILE] [--loglevel LEVEL]
|
||||
[-g GPU [GPU ...] | -U CPU [CPU ...] | -O CORE [CORE ...]] [-f]
|
||||
@@ -168,7 +216,12 @@ Command Modifiers:
|
||||
DEBUG, INFO, WARNING, ERROR, CRITICAL
|
||||
```
|
||||
|
||||
```bash
|
||||
(cmd-bad-pages)=
|
||||
### amd-smi bad-pages
|
||||
|
||||
Gets bad page information about the specified GPU.
|
||||
|
||||
```shell-session
|
||||
~$ amd-smi bad-pages --help
|
||||
usage: amd-smi bad-pages [-h] [--json | --csv] [--file FILE] [--loglevel LEVEL]
|
||||
[-g GPU [GPU ...] | -U CPU [CPU ...] | -O CORE [CORE ...]] [-p]
|
||||
@@ -205,7 +258,12 @@ Command Modifiers:
|
||||
DEBUG, INFO, WARNING, ERROR, CRITICAL
|
||||
```
|
||||
|
||||
```bash
|
||||
(cmd-metric)=
|
||||
### amd-smi metric
|
||||
|
||||
Gets metrics and performance information about the specified GPU.
|
||||
|
||||
```shell-session
|
||||
~$ amd-smi metric --help
|
||||
usage: amd-smi metric [-h] [-g GPU [GPU ...] | -U CPU [CPU ...] | -O CORE [CORE ...]]
|
||||
[-w INTERVAL] [-W TIME] [-i ITERATIONS] [-m] [-u] [-p] [-c] [-t]
|
||||
@@ -295,7 +353,12 @@ Command Modifiers:
|
||||
DEBUG, INFO, WARNING, ERROR, CRITICAL
|
||||
```
|
||||
|
||||
```bash
|
||||
(cmd-process)=
|
||||
### amd-smi process
|
||||
|
||||
Lists general process information running on the specified GPU.
|
||||
|
||||
```shell-session
|
||||
~$ amd-smi process --help
|
||||
usage: amd-smi process [-h] [--json | --csv] [--file FILE] [--loglevel LEVEL]
|
||||
[-g GPU [GPU ...] | -U CPU [CPU ...] | -O CORE [CORE ...]]
|
||||
@@ -339,7 +402,12 @@ Command Modifiers:
|
||||
DEBUG, INFO, WARNING, ERROR, CRITICAL
|
||||
```
|
||||
|
||||
```bash
|
||||
(cmd-event)=
|
||||
### amd-smi event
|
||||
|
||||
Displays event information for the given GPU.
|
||||
|
||||
```shell-session
|
||||
~$ amd-smi event --help
|
||||
usage: amd-smi event [-h] [--json | --csv] [--file FILE] [--loglevel LEVEL]
|
||||
[-g GPU [GPU ...] | -U CPU [CPU ...] | -O CORE [CORE ...]]
|
||||
@@ -372,7 +440,12 @@ Command Modifiers:
|
||||
DEBUG, INFO, WARNING, ERROR, CRITICAL
|
||||
```
|
||||
|
||||
```bash
|
||||
(cmd-topology)=
|
||||
### amd-smi topology
|
||||
|
||||
Displays topology information of the specified devices.
|
||||
|
||||
```shell-session
|
||||
~$ amd-smi topology --help
|
||||
usage: amd-smi topology [-h] [--json | --csv] [--file FILE] [--loglevel LEVEL]
|
||||
[-g GPU [GPU ...] | -U CPU [CPU ...] | -O CORE [CORE ...]] [-a]
|
||||
@@ -412,7 +485,12 @@ Command Modifiers:
|
||||
DEBUG, INFO, WARNING, ERROR, CRITICAL
|
||||
```
|
||||
|
||||
```bash
|
||||
(cmd-set)=
|
||||
### amd-smi set
|
||||
|
||||
Set options for specified devices.
|
||||
|
||||
```shell-session
|
||||
~$ amd-smi set --help
|
||||
usage: amd-smi set [-h] (-g GPU [GPU ...] | -U CPU [CPU ...] | -O CORE [CORE ...]) [-f %]
|
||||
[-l LEVEL] [-P SETPROFILE] [-d SCLKMAX] [-C PARTITION] [-M PARTITION]
|
||||
@@ -482,7 +560,12 @@ Command Modifiers:
|
||||
DEBUG, INFO, WARNING, ERROR, CRITICAL
|
||||
```
|
||||
|
||||
```bash
|
||||
(cmd-reset)=
|
||||
### amd-smi reset
|
||||
|
||||
Reset options for specified devices.
|
||||
|
||||
```shell-session
|
||||
~$ amd-smi reset --help
|
||||
usage: amd-smi reset [-h] [--json | --csv] [--file FILE] [--loglevel LEVEL]
|
||||
(-g GPU [GPU ...] | -U CPU [CPU ...] | -O CORE [CORE ...]) [-G] [-c]
|
||||
@@ -527,7 +610,12 @@ Command Modifiers:
|
||||
DEBUG, INFO, WARNING, ERROR, CRITICAL
|
||||
```
|
||||
|
||||
```bash
|
||||
(cmd-monitor)=
|
||||
### amd-smi monitor
|
||||
|
||||
Monitor metrics for target devices.
|
||||
|
||||
```shell-session
|
||||
~$ amd-smi monitor --help
|
||||
usage: amd-smi monitor [-h] [--json | --csv] [--file FILE] [--loglevel LEVEL]
|
||||
[-g GPU [GPU ...] | -U CPU [CPU ...] | -O CORE [CORE ...]]
|
||||
@@ -577,7 +665,12 @@ Command Modifiers:
|
||||
DEBUG, INFO, WARNING, ERROR, CRITICAL
|
||||
```
|
||||
|
||||
```bash
|
||||
(cmd-xgmi)=
|
||||
### amd-smi xgmi
|
||||
|
||||
Displays XGMI information of specified devices.
|
||||
|
||||
```shell-session
|
||||
~$ amd-smi xgmi --help
|
||||
usage: amd-smi xgmi [-h] [--json | --csv] [--file FILE] [--loglevel LEVEL]
|
||||
[-g GPU [GPU ...] | -U CPU [CPU ...] | -O CORE [CORE ...]] [-m]
|
||||
@@ -612,9 +705,11 @@ Command Modifiers:
|
||||
DEBUG, INFO, WARNING, ERROR, CRITICAL
|
||||
```
|
||||
|
||||
(cli-ex-static)=
|
||||
### Example output from amd-smi static
|
||||
|
||||
Here is some example output from the tool:
|
||||
To gain a sense of the AMD SMI CLI's output, the following block is sample
|
||||
output from the CLI tool:
|
||||
|
||||
```bash
|
||||
~$ amd-smi static
|
||||
@@ -0,0 +1,198 @@
|
||||
---
|
||||
myst:
|
||||
html_meta:
|
||||
"description lang=en": "Get started with the AMD SMI C++ library. Basic usage and examples."
|
||||
"keywords": "api, smi, lib, c++, system, management, interface, ROCm"
|
||||
---
|
||||
|
||||
# AMD SMI C++ library usage and examples
|
||||
|
||||
This section presents a brief overview and some basic examples on the AMD SMI
|
||||
library's usage. Whether you are developing applications for performance
|
||||
monitoring, system diagnostics, or resource allocation, the AMD SMI C++ library
|
||||
serves as a valuable tool for leveraging the full potential of AMD hardware in
|
||||
your projects.
|
||||
|
||||
```{note}
|
||||
``hipcc`` and other compilers will not automatically link in the ``libamd_smi``
|
||||
dynamic library. To compile code that uses the AMD SMI library API, ensure the
|
||||
``libamd_smi.so`` can be located by setting the ``LD_LIBRARY_PATH`` environment
|
||||
variable to the directory containing ``librocm_smi64.so`` (usually
|
||||
``/opt/rocm/lib``) or by passing the ``-lamd_smi`` flag to the compiler.
|
||||
```
|
||||
|
||||
```{seealso}
|
||||
Refer to the [C++ library API reference](../reference/amdsmi-cpp-api.md).
|
||||
```
|
||||
|
||||
(device_socket_handle)=
|
||||
## Device and socket handles
|
||||
|
||||
Many functions in the library take a _socket handle_ or _device handle_. A
|
||||
_socket_ refers to a physical hardware socket, abstracted by the library to
|
||||
represent the hardware more effectively to the user. While there is always one
|
||||
unique GPU per socket, an APU may house both a GPU and CPU on the same socket.
|
||||
For MI200 GPUs, multiple GCDs may reside within a single socket
|
||||
|
||||
To identify the sockets in a system, use the `amdsmi_get_socket_handles()`
|
||||
function, which returns a list of socket handles. These handles can then be used
|
||||
with `amdsmi_get_processor_handles()` to query devices within each socket. The
|
||||
device handle is used to differentiate between detected devices; however, it's
|
||||
important to note that a device handle may change after restarting the
|
||||
application, so it should not be considered a persistent identifier across
|
||||
processes.
|
||||
|
||||
The list of socket handles obtained from `amdsmi_get_socket_handles()` can
|
||||
also be used to query the CPUs in each socket by calling
|
||||
`amdsmi_get_processor_handles_by_type()`. This function can then be called again
|
||||
to query the cores within each CPU.
|
||||
|
||||
(cpp_hello_amdsmi)=
|
||||
## Hello AMD SMI
|
||||
|
||||
An application using AMD SMI must call `amdsmi_init()` to initialize the AMI SMI
|
||||
library before all other calls. This call initializes the internal data
|
||||
structures required for subsequent AMD SMI operations. In the call, a flag can
|
||||
be passed to indicate if the application is interested in a specific device
|
||||
type.
|
||||
|
||||
`amdsmi_shut_down()` must be the last call to properly close connection to
|
||||
driver and make sure that any resources held by AMD SMI are released.
|
||||
|
||||
1. A simple "Hello World" type program that displays the temperature of detected
|
||||
devices looks like this:
|
||||
|
||||
```cpp
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include "amd_smi/amdsmi.h"
|
||||
|
||||
int main() {
|
||||
amdsmi_status_t ret;
|
||||
|
||||
// Init amdsmi for sockets and devices. Here we are only interested in AMD_GPUS.
|
||||
ret = amdsmi_init(AMDSMI_INIT_AMD_GPUS);
|
||||
|
||||
// Get all sockets
|
||||
uint32_t socket_count = 0;
|
||||
|
||||
// Get the socket count available in the system.
|
||||
ret = amdsmi_get_socket_handles(&socket_count, nullptr);
|
||||
|
||||
// Allocate the memory for the sockets
|
||||
std::vector<amdsmi_socket_handle> sockets(socket_count);
|
||||
// Get the socket handles in the system
|
||||
ret = amdsmi_get_socket_handles(&socket_count, &sockets[0]);
|
||||
|
||||
std::cout << "Total Socket: " << socket_count << std::endl;
|
||||
|
||||
// For each socket, get identifier and devices
|
||||
for (uint32_t i=0; i < socket_count; i++) {
|
||||
// Get Socket info
|
||||
char socket_info[128];
|
||||
ret = amdsmi_get_socket_info(sockets[i], 128, socket_info);
|
||||
std::cout << "Socket " << socket_info<< std::endl;
|
||||
|
||||
// Get the device count for the socket.
|
||||
uint32_t device_count = 0;
|
||||
ret = amdsmi_get_processor_handles(sockets[i], &device_count, nullptr);
|
||||
|
||||
// Allocate the memory for the device handlers on the socket
|
||||
std::vector<amdsmi_processor_handle> processor_handles(device_count);
|
||||
// Get all devices of the socket
|
||||
ret = amdsmi_get_processor_handles(sockets[i],
|
||||
&device_count, &processor_handles[0]);
|
||||
|
||||
// For each device of the socket, get name and temperature.
|
||||
for (uint32_t j=0; j < device_count; j++) {
|
||||
// Get device type. Since the amdsmi is initialized with
|
||||
// AMD_SMI_INIT_AMD_GPUS, the processor_type must be AMDSMI_PROCESSOR_TYPE_AMD_GPU.
|
||||
processor_type_t processor_type;
|
||||
ret = amdsmi_get_processor_type(processor_handles[j], &processor_type);
|
||||
if (processor_type != AMDSMI_PROCESSOR_TYPE_AMD_GPU) {
|
||||
std::cout << "Expect AMDSMI_PROCESSOR_TYPE_AMD_GPU device type!\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Get device name
|
||||
amdsmi_board_info_t board_info;
|
||||
ret = amdsmi_get_gpu_board_info(processor_handles[j], &board_info);
|
||||
std::cout << "\tdevice "
|
||||
<< j <<"\n\t\tName:" << board_info.product_name << std::endl;
|
||||
|
||||
// Get temperature
|
||||
int64_t val_i64 = 0;
|
||||
ret = amdsmi_get_temp_metric(processor_handles[j], AMDSMI_TEMPERATURE_TYPE_EDGE,
|
||||
AMDSMI_TEMP_CURRENT, &val_i64);
|
||||
std::cout << "\t\tTemperature: " << val_i64 << "C" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
// Clean up resources allocated at amdsmi_init. It will invalidate sockets
|
||||
// and devices pointers
|
||||
ret = amdsmi_shut_down();
|
||||
|
||||
return 0;
|
||||
}
|
||||
```
|
||||
|
||||
2. A sample program that displays the power of detected CPUs looks like this:
|
||||
|
||||
```cpp
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include "amd_smi/amdsmi.h"
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
amdsmi_status_t ret;
|
||||
uint32_t socket_count = 0;
|
||||
|
||||
// Initialize amdsmi for AMD CPUs
|
||||
ret = amdsmi_init(AMDSMI_INIT_AMD_CPUS);
|
||||
|
||||
ret = amdsmi_get_socket_handles(&socket_count, nullptr);
|
||||
|
||||
// Allocate the memory for the sockets
|
||||
std::vector<amdsmi_socket_handle> sockets(socket_count);
|
||||
|
||||
// Get the sockets of the system
|
||||
ret = amdsmi_get_socket_handles(&socket_count, &sockets[0]);
|
||||
|
||||
std::cout << "Total Socket: " << socket_count << std::endl;
|
||||
|
||||
// For each socket, get cpus
|
||||
for (uint32_t i = 0; i < socket_count; i++) {
|
||||
uint32_t cpu_count = 0;
|
||||
|
||||
// Set processor type as AMDSMI_PROCESSOR_TYPE_AMD_CPU
|
||||
processor_type_t processor_type = AMDSMI_PROCESSOR_TYPE_AMD_CPU;
|
||||
ret = amdsmi_get_processor_handles_by_type(sockets[i], processor_type, nullptr, &cpu_count);
|
||||
|
||||
// Allocate the memory for the cpus
|
||||
std::vector<amdsmi_processor_handle> plist(cpu_count);
|
||||
|
||||
// Get the cpus for each socket
|
||||
ret = amdsmi_get_processor_handles_by_type(sockets[i], processor_type, &plist[0], &cpu_count);
|
||||
|
||||
for (uint32_t index = 0; index < plist.size(); index++) {
|
||||
uint32_t socket_power;
|
||||
std::cout<<"CPU "<<index<<"\t"<< std::endl;
|
||||
std::cout<<"Power (Watts): ";
|
||||
|
||||
ret = amdsmi_get_cpu_socket_power(plist[index], &socket_power);
|
||||
if(ret != AMDSMI_STATUS_SUCCESS)
|
||||
std::cout<<"Failed to get cpu socket power"<<"["<<index<<"] , Err["<<ret<<"] "<< std::endl;
|
||||
|
||||
if (!ret) {
|
||||
std::cout<<static_cast<double>(socket_power)/1000<<std::endl;
|
||||
}
|
||||
std::cout<<std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
// Clean up resources allocated at amdsmi_init
|
||||
ret = amdsmi_shut_down();
|
||||
|
||||
return 0;
|
||||
}
|
||||
```
|
||||
@@ -0,0 +1,105 @@
|
||||
---
|
||||
myst:
|
||||
html_meta:
|
||||
"description lang=en": "Get started with the AMD SMI Python interface."
|
||||
"keywords": "api, smi, lib, py, system, management, interface, ROCm"
|
||||
---
|
||||
|
||||
# AMD SMI Python interface overview
|
||||
|
||||
The AMD SMI Python interface provides a convenient way to interact with AMD
|
||||
hardware through a simple and accessible [API](../reference/amdsmi-py-api.md).
|
||||
Compatible with Python 3.6 and higher, this library requires the AMD driver to
|
||||
be loaded for initialization -- review the [prerequisites](#install_reqs).
|
||||
|
||||
## Get started
|
||||
|
||||
To get started, the `amdsmi` folder should be copied and placed next to
|
||||
the importing script. Import it as follows:
|
||||
|
||||
```python
|
||||
from amdsmi import *
|
||||
|
||||
try:
|
||||
amdsmi_init()
|
||||
|
||||
# amdsmi calls ...
|
||||
|
||||
except AmdSmiException as e:
|
||||
print(e)
|
||||
finally:
|
||||
try:
|
||||
amdsmi_shut_down()
|
||||
except AmdSmiException as e:
|
||||
print(e)
|
||||
```
|
||||
|
||||
(py_lib_fs)=
|
||||
### Folder structure
|
||||
|
||||
File name | Description
|
||||
----------------------|-------------------------------------------------
|
||||
`__init__.py` | Python package initialization file
|
||||
`amdsmi_interface.py` | Amdsmi library Python interface
|
||||
`amdsmi_wrapper.py` | Python wrapper around amdsmi binary
|
||||
`amdsmi_exception.py` | Amdsmi [exceptions](#py_exceptions) Python file
|
||||
|
||||
(py_usage)=
|
||||
## Usage
|
||||
|
||||
```{note}
|
||||
``hipcc`` and other compilers will not automatically link in the ``libamd_smi``
|
||||
dynamic library. To compile code that uses the AMD SMI library API, ensure the
|
||||
``libamd_smi.so`` can be located by setting the ``LD_LIBRARY_PATH`` environment
|
||||
variable to the directory containing ``librocm_smi64.so`` (usually
|
||||
``/opt/rocm/lib``) or by passing the ``-lamd_smi`` flag to the compiler.
|
||||
```
|
||||
|
||||
```{seealso}
|
||||
Refer to the [Python library API reference](../reference/amdsmi-py-api.md).
|
||||
```
|
||||
|
||||
An application using AMD SMI must call `amdsmi_init()` to initialize the AMI SMI
|
||||
library before all other calls. This call initializes the internal data
|
||||
structures required for subsequent AMD SMI operations. In the call, a flag can
|
||||
be passed to indicate if the application is interested in a specific device
|
||||
type.
|
||||
|
||||
`amdsmi_shut_down()` must be the last call to properly close connection to
|
||||
driver and make sure that any resources held by AMD SMI are released.
|
||||
|
||||
(py_exceptions)=
|
||||
## Exceptions
|
||||
|
||||
All exceptions are in `amdsmi_exception.py` file.
|
||||
|
||||
Exceptions that can be thrown by AMD SMI are:
|
||||
|
||||
* `AmdSmiException`: base amdsmi exception class
|
||||
* `AmdSmiLibraryException`: derives base `AmdSmiException` class and represents errors that can occur in amdsmi-lib.
|
||||
When this exception is thrown, `err_code` and `err_info` are set. `err_code` is an integer that corresponds to errors that can occur
|
||||
in amdsmi-lib and `err_info` is a string that explains the error that occurred.
|
||||
|
||||
For example:
|
||||
|
||||
```python
|
||||
try:
|
||||
num_of_GPUs = len(amdsmi_get_processor_handles())
|
||||
if num_of_GPUs == 0:
|
||||
print("No GPUs on machine")
|
||||
except AmdSmiException as e:
|
||||
print("Error code: {}".format(e.err_code))
|
||||
if e.err_code == amdsmi_wrapper.AMDSMI_STATUS_RETRY:
|
||||
print("Error info: {}".format(e.err_info))
|
||||
```
|
||||
|
||||
* `AmdSmiRetryException` : Derives `AmdSmiLibraryException` class and signals
|
||||
device is busy and call should be retried.
|
||||
* `AmdSmiTimeoutException` : Derives `AmdSmiLibraryException` class and
|
||||
represents that call had timed out.
|
||||
* `AmdSmiParameterException`: Derives base `AmdSmiException` class and
|
||||
represents errors related to invaild parameters passed to functions. When this
|
||||
exception is thrown, `err_msg` is set and it explains what is the actual and
|
||||
expected type of the parameters.
|
||||
* `AmdSmiBdfFormatException`: Derives base `AmdSmiException` class and
|
||||
represents invalid bdf format.
|
||||
@@ -1,254 +0,0 @@
|
||||
.. meta::
|
||||
:description: Using AMD SMI
|
||||
:keywords: AMD, SMI, system, management, interface, ROCm
|
||||
|
||||
********************************
|
||||
Usage Basics for the C Library
|
||||
********************************
|
||||
|
||||
Device/Socket handles
|
||||
----------------------
|
||||
|
||||
Many of the AMD SMI library's functions take a "socket handle" or "device handle." The socket is an abstraction of the hardware's physical socket. This will enable AMD SMI to provide a better representation of the hardware to the user. Although there is always one distinct GPU for a socket, the APU may have both GPU and CPU devices on the same socket. Moreover, for the MI200 series, it may have multiple GCDs.
|
||||
|
||||
To discover the sockets in the system, `amdsmi_get_socket_handles()` is called to get a list of socket handles, which, in turn, can be used to query the devices in that socket using `amdsmi_get_processor_handles().` The device handler is used to distinguish the detected devices from one another. It is important to note that a device may end up with a different device handle after restarting the application, so a device handle should not be relied upon to be constant over the process.
|
||||
|
||||
The list of socket handles discovered using `amdsmi_get_socket_handles()`, can also be used to query the CPUs in that socket using amdsmi_get_processor_handles_by_type(), which in turn can then be used to query the cores in that CPU using amdsmi_get_processor_handles_by_type() again.
|
||||
|
||||
|
||||
Hello AMD SMI
|
||||
--------------
|
||||
|
||||
The only required AMD SMI call for any program that wants to use AMD SMI is the `amdsmi_init()` call. This call initializes some internal data structures that subsequent AMD-SMI calls will use. A flag can be passed in the call if the application is only interested in a specific device type.
|
||||
|
||||
When AMD SMI is no longer used, `amdsmi_shut_down()` should be called. This provides a way to release resources that AMD-SMI may have held.
|
||||
|
||||
1) A simple "Hello World" type program that displays the temperature of detected devices would look like this:
|
||||
|
||||
.. code-block::
|
||||
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include "amd_smi/amdsmi.h"
|
||||
|
||||
int main() {
|
||||
amdsmi_status_t ret;
|
||||
|
||||
// Init amdsmi for sockets and devices. Here we are only interested in AMD_GPUS.
|
||||
ret = amdsmi_init(AMDSMI_INIT_AMD_GPUS);
|
||||
|
||||
// Get all sockets
|
||||
uint32_t socket_count = 0;
|
||||
|
||||
// Get the socket count available in the system.
|
||||
ret = amdsmi_get_socket_handles(&socket_count, nullptr);
|
||||
|
||||
// Allocate the memory for the sockets
|
||||
std::vector<amdsmi_socket_handle> sockets(socket_count);
|
||||
// Get the socket handles in the system
|
||||
ret = amdsmi_get_socket_handles(&socket_count, &sockets[0]);
|
||||
|
||||
std::cout << "Total Socket: " << socket_count << std::endl;
|
||||
|
||||
// For each socket, get identifier and devices
|
||||
for (uint32_t i=0; i < socket_count; i++) {
|
||||
// Get Socket info
|
||||
char socket_info[128];
|
||||
ret = amdsmi_get_socket_info(sockets[i], 128, socket_info);
|
||||
std::cout << "Socket " << socket_info<< std::endl;
|
||||
|
||||
// Get the device count for the socket.
|
||||
uint32_t device_count = 0;
|
||||
ret = amdsmi_get_processor_handles(sockets[i], &device_count, nullptr);
|
||||
|
||||
// Allocate the memory for the device handlers on the socket
|
||||
std::vector<amdsmi_processor_handle> processor_handles(device_count);
|
||||
// Get all devices of the socket
|
||||
ret = amdsmi_get_processor_handles(sockets[i],
|
||||
&device_count, &processor_handles[0]);
|
||||
|
||||
// For each device of the socket, get name and temperature.
|
||||
for (uint32_t j=0; j < device_count; j++) {
|
||||
// Get device type. Since the amdsmi is initialized with
|
||||
// AMD_SMI_INIT_AMD_GPUS, the processor_type must be AMD_GPU.
|
||||
processor_type_t processor_type;
|
||||
ret = amdsmi_get_processor_type(processor_handles[j], &processor_type);
|
||||
if (processor_type != AMD_GPU) {
|
||||
std::cout << "Expect AMD_GPU device type!\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Get device name
|
||||
amdsmi_board_info_t board_info;
|
||||
ret = amdsmi_get_gpu_board_info(processor_handles[j], &board_info);
|
||||
std::cout << "\tdevice "
|
||||
<< j <<"\n\t\tName:" << board_info.product_name << std::endl;
|
||||
|
||||
// Get temperature
|
||||
int64_t val_i64 = 0;
|
||||
ret = amdsmi_get_temp_metric(processor_handles[j], AMDSMI_TEMPERATURE_TYPE_EDGE,
|
||||
AMDSMI_TEMP_CURRENT, &val_i64);
|
||||
std::cout << "\t\tTemperature: " << val_i64 << "C" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
// Clean up resources allocated at amdsmi_init. It will invalidate sockets
|
||||
// and devices pointers
|
||||
ret = amdsmi_shut_down();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
2) A sample program that displays the power of detected cpus would look like this:
|
||||
|
||||
.. code-block::
|
||||
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include "amd_smi/amdsmi.h"
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
amdsmi_status_t ret;
|
||||
uint32_t socket_count = 0;
|
||||
|
||||
// Initialize amdsmi for AMD CPUs
|
||||
ret = amdsmi_init(AMDSMI_INIT_AMD_CPUS);
|
||||
|
||||
ret = amdsmi_get_socket_handles(&socket_count, nullptr);
|
||||
|
||||
// Allocate the memory for the sockets
|
||||
std::vector<amdsmi_socket_handle> sockets(socket_count);
|
||||
|
||||
// Get the sockets of the system
|
||||
ret = amdsmi_get_socket_handles(&socket_count, &sockets[0]);
|
||||
|
||||
std::cout << "Total Socket: " << socket_count << std::endl;
|
||||
|
||||
// For each socket, get cpus
|
||||
for (uint32_t i = 0; i < socket_count; i++) {
|
||||
uint32_t cpu_count = 0;
|
||||
|
||||
// Set processor type as AMD_CPU
|
||||
processor_type_t processor_type = AMD_CPU;
|
||||
ret = amdsmi_get_processor_handles_by_type(sockets[i], processor_type, nullptr, &cpu_count);
|
||||
|
||||
// Allocate the memory for the cpus
|
||||
std::vector<amdsmi_processor_handle> plist(cpu_count);
|
||||
|
||||
// Get the cpus for each socket
|
||||
ret = amdsmi_get_processor_handles_by_type(sockets[i], processor_type, &plist[0], &cpu_count);
|
||||
|
||||
for (uint32_t index = 0; index < plist.size(); index++) {
|
||||
uint32_t socket_power;
|
||||
std::cout<<"CPU "<<index<<"\t"<< std::endl;
|
||||
std::cout<<"Power (Watts): ";
|
||||
|
||||
ret = amdsmi_get_cpu_socket_power(plist[index], &socket_power);
|
||||
if(ret != AMDSMI_STATUS_SUCCESS)
|
||||
std::cout<<"Failed to get cpu socket power"<<"["<<index<<"] , Err["<<ret<<"] "<< std::endl;
|
||||
|
||||
if (!ret) {
|
||||
std::cout<<static_cast<double>(socket_power)/1000<<std::endl;
|
||||
}
|
||||
std::cout<<std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
// Clean up resources allocated at amdsmi_init
|
||||
ret = amdsmi_shut_down();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Building AMD SMI
|
||||
-----------------
|
||||
|
||||
Rebuilding Python wrapper
|
||||
==========================
|
||||
|
||||
Python wrapper (binding) is an auto-generated file `py-interface/amdsmi_wrapper.py`
|
||||
|
||||
The wrapper should be re-generated on each C++ API change by doing the following:
|
||||
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
./update_wrapper.sh
|
||||
|
||||
|
||||
After this command, the file in `py-interface/amdsmi_wrapper.py` will be automatically updated on each compile.
|
||||
|
||||
Note: To re-generate the Python wrapper, you must have **Docker** installed.
|
||||
|
||||
Note: Python_wrapper is NOT automatically re-generated. You must run `./update_wrapper.sh`.
|
||||
|
||||
|
||||
Additional software required for building AMD SMI
|
||||
--------------------------------------------------
|
||||
|
||||
The following components are required to build the library.
|
||||
|
||||
.. Note:: The software versions listed are what was used in development. Earlier versions are not guaranteed to work.
|
||||
|
||||
* CMake (v3.14.0) - `python3 -m pip install cmake`
|
||||
* g++ (5.4.0)
|
||||
|
||||
The following components are required to build the AMD SMI Python package:
|
||||
|
||||
* Python (3.6.8 or above)
|
||||
* virtualenv - `python3 -m pip install virtualenv`
|
||||
|
||||
The following tools are required to build the latest documentation:
|
||||
|
||||
* Doxygen (1.8.11)
|
||||
* Latex (pdfTeX 3.14159265-2.6-1.40.16)
|
||||
|
||||
The source code for AMD SMI is available on Github.
|
||||
|
||||
After the AMD SMI library git repository is cloned to a local Linux machine, the default location for the library and headers is /opt/rocm.
|
||||
|
||||
.. Note:: Before installation, the old ROCm directories must be deleted:
|
||||
|
||||
* /opt/rocm
|
||||
* /opt/rocm-{number}
|
||||
|
||||
Building the library is achieved by following the typical CMake build sequence (run as root user or use 'sudo' before the 'make install' command), specifically:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
mkdir -p build
|
||||
cd build
|
||||
cmake ..
|
||||
make -j $(nproc)
|
||||
make install
|
||||
|
||||
|
||||
The built library will appear in the `build` folder.
|
||||
|
||||
In addition to the preceding steps, use the following instructions to build the rpm and deb packages:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
make package
|
||||
|
||||
Building tests
|
||||
-------------------
|
||||
|
||||
To verify the build and capability of AMD SMI on your system and see an example of how AMD SMI can be used, you may build and run the tests available in the repo. To build the tests, follow these steps:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
mkdir -p build
|
||||
cd build
|
||||
cmake -DBUILD_TESTS=ON ..
|
||||
make -j $(nproc)
|
||||
|
||||
|
||||
Running tests
|
||||
--------------
|
||||
|
||||
Execute the program `amdsmitst` that is built from the steps above to run the test.
|
||||
|
||||
Path to the program `amdsmitst`: `build/tests/amd_smi_test/`
|
||||
File diff suppressed because it is too large.
Load diff
Reference in new issue
Block a user