### Install Rust Interface Examples Source: https://github.com/rocm/amdsmi/blob/amd-mainline/rust-interface/CMakeLists.txt Conditionally installs example binaries for the Rust interface if the BUILD_RUST_EXAMPLES option is enabled. This includes executable files for specific examples. ```cmake if(BUILD_RUST_EXAMPLES) install(DIRECTORY DESTINATION ${RUST_WRAPPER_INSTALL_DIR}/examples COMPONENT dev) install( FILES ${RUST_OUTPUT_DIR}/examples/amdsmi_get_gpu_info ${RUST_OUTPUT_DIR}/examples/amdsmi_exporter DESTINATION ${RUST_WRAPPER_INSTALL_DIR}/examples PERMISSIONS OWNER_EXECUTE OWNER_READ GROUP_EXECUTE GROUP_READ WORLD_EXECUTE WORLD_READ COMPONENT dev) endif() ``` -------------------------------- ### Get CPU Power Information Source: https://github.com/rocm/amdsmi/blob/amd-mainline/docs/how-to/amdsmi-cpp-lib.md This example shows how to initialize AMD SMI for CPUs and retrieve power information. Note the use of -DENABLE_ESMI during compilation. ```cpp #include #include #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 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; ``` -------------------------------- ### Run amdsmi_get_gpu_info Example Source: https://github.com/rocm/amdsmi/blob/amd-mainline/rust-interface/README.md Example command to run the 'amdsmi_get_gpu_info' example. ```sh cargo run --example amdsmi_get_gpu_info ``` -------------------------------- ### Run a Specific Example Source: https://github.com/rocm/amdsmi/blob/amd-mainline/rust-interface/README.md Execute a specific example by replacing 'example_name' with the desired example's name. ```sh cargo run --example example_name ``` -------------------------------- ### Build Example Executables Source: https://github.com/rocm/amdsmi/blob/amd-mainline/example/CMakeLists.txt Defines and links executables for different AMD SMI examples. This includes DRM and non-DRM examples, and an optional ESMI integration example if enabled. ```cmake message("&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&") message(" Finished Cmake Example ") message("&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&") # compile example files but do not install # this is only useful if running from build directory set(SMI_DRM_EXAMPLE_EXE "amd_smi_drm_ex") add_executable(${SMI_DRM_EXAMPLE_EXE} "amd_smi_drm_example.cc") target_link_libraries(${SMI_DRM_EXAMPLE_EXE} amd_smi) set(SMI_NODRM_EXAMPLE_EXE "amd_smi_nodrm_ex") add_executable(${SMI_NODRM_EXAMPLE_EXE} "amd_smi_nodrm_example.cc") target_link_libraries(${SMI_NODRM_EXAMPLE_EXE} amd_smi) if(ENABLE_ESMI_LIB) set(ESMI_SAMPLE_EXE "amd_smi_esmi_ex") add_executable(${ESMI_SAMPLE_EXE} "amdsmi_esmi_intg_example.cc") target_link_libraries(${ESMI_SAMPLE_EXE} amd_smi) target_compile_definitions(${ESMI_SAMPLE_EXE} PUBLIC ENABLE_ESMI_LIB) endif() ``` -------------------------------- ### Install Go using update-golang Source: https://github.com/rocm/amdsmi/blob/amd-mainline/docs/how-to/amdsmi-go-lib.md Install Go version 1.20+ using the update-golang script. This includes cloning the repository, running the script, and sourcing the Go path. ```bash git clone https://github.com/udhos/update-golang cd update-golang sudo ./update-golang.sh source /etc/profile.d/golang_path.sh go version ``` -------------------------------- ### Install Python Package Configuration Files Source: https://github.com/rocm/amdsmi/blob/amd-mainline/py-interface/CMakeLists.txt Installs Python package configuration files like pyproject.toml and setup.py to the development component directory. ```cmake install( FILES ${CMAKE_CURRENT_BINARY_DIR}/${PY_BUILD_DIR}/pyproject.toml ${CMAKE_CURRENT_BINARY_DIR}/${PY_BUILD_DIR}/setup.py ${CMAKE_CURRENT_BINARY_DIR}/${PY_PACKAGE_DIR}/_version.py DESTINATION ${PY_WRAPPER_INSTALL_DIR} COMPONENT dev) ``` -------------------------------- ### Example Test Output (Not Verbose) Source: https://github.com/rocm/amdsmi/blob/amd-mainline/tests/python_unittest/README.md An example of the output when running unit tests without verbose mode, showing test results and summary. ```shell /opt/rocm/share/amd_smi/tests/python_unittest/unit_tests.py -b -v test_check_res (__main__.TestAmdSmiPythonBDF) ... ok test_format_bdf (__main__.TestAmdSmiPythonBDF) ... ok test_parse_bdf (__main__.TestAmdSmiPythonBDF) ... ok ---------------------------------------------------------------------- Ran 3 tests in 0.001s OK ``` -------------------------------- ### Install Rust Interface Source Source: https://github.com/rocm/amdsmi/blob/amd-mainline/rust-interface/CMakeLists.txt Installs the source archive of the Rust interface to the specified installation directory. This method is recommended by the Rust ecosystem over using pre-compiled binaries. ```cmake install( FILES ${CMAKE_CURRENT_BINARY_DIR}/source.tar.gz DESTINATION ${RUST_WRAPPER_INSTALL_DIR} COMPONENT dev) ``` -------------------------------- ### Install AMD SMI Header File Source: https://github.com/rocm/amdsmi/blob/amd-mainline/src/CMakeLists.txt Installs the main AMD SMI header file to the include directory. This is typically done for the 'dev' component. ```cmake install( FILES ${PROJECT_SOURCE_DIR}/include/amd_smi/amdsmi.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/amd_smi COMPONENT dev) ``` -------------------------------- ### Verify AMD SMI CLI installation manually Source: https://github.com/rocm/amdsmi/blob/amd-mainline/docs/install/install.md Check the AMD SMI CLI installation by running the help command. This is useful after a manual installation. ```shell amd-smi --help ``` -------------------------------- ### Install AMD SMI Python Library Source: https://github.com/rocm/amdsmi/blob/amd-mainline/docs/install/install.md Install the AMD SMI Python library from your ROCm instance. Ensure pip is up-to-date and install the library using the user flag. ```shell apt install amd-smi-lib cd /opt/rocm/share/amd_smi python3 -m pip install --upgrade pip python3 -m pip install --user . ``` -------------------------------- ### Install Python Package Directory Source: https://github.com/rocm/amdsmi/blob/amd-mainline/py-interface/CMakeLists.txt Installs the entire Python package directory, including source files and the copied library, to the development component directory. ```cmake install( DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${PY_PACKAGE_DIR} DESTINATION ${PY_WRAPPER_INSTALL_DIR} COMPONENT dev) ``` -------------------------------- ### Install AMD SMI Test Executable and Exclude File Source: https://github.com/rocm/amdsmi/blob/amd-mainline/tests/amd_smi_test/CMakeLists.txt Configures the installation of the built test executable and an associated exclude file. These are placed in the share directory under the tests subdirectory, associated with a specific component. ```cmake # Install tests install( TARGETS ${TEST} DESTINATION ${SHARE_INSTALL_PREFIX}/tests COMPONENT ${TESTS_COMPONENT}) install( FILES amdsmitst.exclude DESTINATION ${SHARE_INSTALL_PREFIX}/tests COMPONENT ${TESTS_COMPONENT}) ``` -------------------------------- ### Get GPU Firmware Information using amdsmi_get_fw_info Source: https://github.com/rocm/amdsmi/blob/amd-mainline/docs/reference/amdsmi-py-api.md Fetches and prints firmware details for each GPU, including firmware name and version. ```python try: devices = amdsmi_get_processor_handles() if len(devices) == 0: print("No GPUs on machine") else: for device in devices: firmware_list = amdsmi_get_fw_info(device)['fw_list'] for firmware_block in firmware_list: print(firmware_block['fw_name']) # String formated hex or decimal value ie: 21.00.00.AC or 130 print(firmware_block['fw_version']) except AmdSmiException as e: print(e) ``` -------------------------------- ### Get AMD SMI RAS help information Source: https://github.com/rocm/amdsmi/blob/amd-mainline/docs/conceptual/ras.md Use this command to view help information and available options for the amd-smi ras CLI. ```shell amd-smi ras --help ``` -------------------------------- ### Get GPU Temperature Metrics (C++) Source: https://context7.com/rocm/amdsmi/llms.txt Example of how to query GPU edge temperature using the C++ API. The temperature is returned in millidegrees Celsius. ```cpp #include #include "amdsmi.h" int main() { int64_t val = 0; // Assuming processor_handle is already obtained amdsmi_get_temp_metric(processor_handle, AMDSMI_TEMPERATURE_TYPE_EDGE, AMDSMI_TEMP_CURRENT, &val); std::cout << "Edge temperature: " << val << " C" << std::endl; return 0; } ``` -------------------------------- ### Get CPU Prochot Status Source: https://github.com/rocm/amdsmi/blob/amd-mainline/docs/reference/amdsmi-py-api.md Fetches the Prochot status for a CPU socket. The example iterates through all available CPU sockets and prints their Prochot status, with exception handling. ```python try: processor_handles = amdsmi_get_cpusocket_handles() if len(processor_handles) == 0: print("No CPU sockets on machine") else: for processor in processor_handles: prochot = amdsmi_get_cpu_prochot_status(processor) print(prochot) except AmdSmiException as e: print(e) ``` -------------------------------- ### Get CPU Socket Frequency Range Source: https://github.com/rocm/amdsmi/blob/amd-mainline/docs/reference/amdsmi-py-api.md Fetches the maximum and minimum frequency range for each CPU socket. The example iterates through the returned dictionary and prints both the maximum and minimum frequencies. ```python try: processor_handles = amdsmi_get_cpusocket_handles() if len(processor_handles) == 0: print("No CPU sockets on machine") else: for processor in processor_handles: freq_range = amdsmi_get_cpu_socket_freq_range(processor) for fmax, fmin in freq_range.items(): print(fmax) print(fmin) except AmdSmiException as e: print(e) ``` -------------------------------- ### Get CPU Core Clock Limit Source: https://github.com/rocm/amdsmi/blob/amd-mainline/docs/reference/amdsmi-py-api.md Fetches the core clock limit in MHz for each CPU socket. The example includes a check for the existence of CPU sockets and prints the limit if available. ```python try: processor_handles = amdsmi_get_cpusocket_handles() if len(processor_handles) == 0: print("No CPU sockets on machine") else: for processor in processor_handles: cclk_limit = amdsmi_get_cpu_cclk_limit(processor) print(cclk_limit) except AmdSmiException as e: print(e) ``` -------------------------------- ### General Usage: Get AFIDs from CPER File Source: https://github.com/rocm/amdsmi/blob/amd-mainline/docs/reference/amdsmi-py-api.md Reads CPER data from a file and extracts AFIDs. This example demonstrates file handling and exception management for potential AMDSMI errors. ```python try: with open(cper_file.path, "rb") as file: afids, num_afids = amdsmi_interface.amdsmi_get_afids_from_cper(file.read()) print(f"AFIDs: {afids}\nTotal count: {num_afids}") except AmdSmiException as e: print(e) ``` -------------------------------- ### Execute Example AMD SMI CLI Commands Source: https://github.com/rocm/amdsmi/blob/amd-mainline/docs/how-to/amdsmi-cli-tool.md Demonstrates common usage patterns for the AMD SMI CLI tool, including fetching static GPU information, general metrics, process details for specific GPUs, and resetting all GPUs. ```shell amd-smi static --gpu 0 ``` ```shell amd-smi metric ``` ```shell amd-smi process --gpu 0 1 ``` ```shell amd-smi reset --gpureset --gpu all ``` -------------------------------- ### Generate Project Documentation Source: https://github.com/rocm/amdsmi/blob/amd-mainline/rust-interface/README.md Generate the project's documentation and automatically open it in the default web browser. ```sh cargo doc --open ``` -------------------------------- ### Initialize and Shut Down AMD SMI Library (C++) Source: https://context7.com/rocm/amdsmi/llms.txt Basic C++ example demonstrating initialization and shutdown of the AMD SMI library. Compilation requires linking against the amd_smi library. ```cpp // C++ equivalent #include "amd_smi/amdsmi.h" // Build: g++ -I/opt/rocm/include file.cc -L/opt/rocm/lib -lamd_smi -o app int main() { amdsmi_status_t ret = amdsmi_init(AMDSMI_INIT_AMD_GPUS); // ... use the library ... ret = amdsmi_shut_down(); return 0; } ``` -------------------------------- ### List Supported GPUs and Metrics Source: https://github.com/rocm/amdsmi/blob/amd-mainline/rust-interface/examples/amdsmi_exporter/README.md Use the 'list' subcommand to view available GPUs and their associated metrics. ```sh amdsmi_exporter list ``` -------------------------------- ### Uninstall Previous AMD SMI Installation Source: https://github.com/rocm/amdsmi/blob/amd-mainline/docs/install/install.md Before installing, remove any existing AMD SMI installations using pip. ```shell python3 -m pip list | grep amd python3 -m pip uninstall amdsmi ``` -------------------------------- ### Display amd-smi static help information Source: https://github.com/rocm/amdsmi/blob/amd-mainline/docs/how-to/amdsmi-cli-tool.md Shows the available options and arguments for the `amd-smi static` command. Use this to understand all possible static information queries. ```shell ~$ amd-smi static --help ``` -------------------------------- ### Enable CPU DF P-State Performance Boost Source: https://github.com/rocm/amdsmi/blob/amd-mainline/docs/how-to/amdsmi-cli-tool.md Enable the DF P-state performance boost algorithm for the CPU. Requires 'sudo' privileges. ```shell sudo amd-smi set --cpu-enable-apb ``` -------------------------------- ### Verify AMD SMI installation with ROCm Source: https://github.com/rocm/amdsmi/blob/amd-mainline/docs/install/install.md After installing ROCm and the amdgpu driver, run this command to verify that the AMD SMI installation is successful. ```shell amd-smi ``` -------------------------------- ### Get Firmware Information Help Source: https://github.com/rocm/amdsmi/blob/amd-mainline/docs/how-to/amdsmi-cli-tool.md Displays help information for the `amd-smi firmware` command. Use this to understand available options for querying firmware details. ```shell ~$ amd-smi firmware --help ``` -------------------------------- ### Install AMD SMI Runtime Library Source: https://github.com/rocm/amdsmi/blob/amd-mainline/src/CMakeLists.txt Installs the AMD SMI runtime library and exports its targets. The library is installed to the CMAKE_INSTALL_LIBDIR and is associated with 'dev' and 'asan' components. ```cmake install( TARGETS ${AMD_SMI} EXPORT amd_smiTargets LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT dev) install( TARGETS ${AMD_SMI} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT asan) ``` -------------------------------- ### Run AMDSMI Exporter with HTTP Server Source: https://github.com/rocm/amdsmi/blob/amd-mainline/rust-interface/examples/amdsmi_exporter/README.md Execute the 'metric' subcommand to start the exporter and serve metrics over HTTP. Options allow specifying the port and filtering by GPU. ```sh amdsmi_exporter metric [OPTIONS] ``` -------------------------------- ### Display amd-smi set Help Information Source: https://github.com/rocm/amdsmi/blob/amd-mainline/docs/how-to/amdsmi-cli-tool.md Use the --help flag to display detailed usage information for the 'amd-smi set' command, including available arguments and their descriptions. ```shell ~$ amd-smi set --help ``` -------------------------------- ### Project and Dependency Setup Source: https://github.com/rocm/amdsmi/blob/amd-mainline/example/CMakeLists.txt Defines the project name and sets up the ROCm directory path, falling back to a default if the environment variable is not set. It also adds necessary search paths for packages. ```cmake project(amd_smi_example) # required variables if(DEFINED ENV{ROCM_PATH}) set(ROCM_DIR "$ENV{ROCM_PATH}" CACHE STRING "ROCm directory.") else() set(ROCM_DIR "/opt/rocm" CACHE STRING "ROCm directory.") endif() include(GNUInstallDirs) # add package search paths # ../../../ should resolve to /opt/rocm or another rocm install path # fall back to ROCM_DIR list(APPEND CMAKE_PREFIX_PATH ../../../ ${ROCM_DIR}) list(APPEND CMAKE_LIBRARY_PATH ${ROCM_DIR}/${CMAKE_INSTALL_LIBDIR}) find_package(amd_smi CONFIG REQUIRED) ``` -------------------------------- ### Install AMD SMI library manually Source: https://github.com/rocm/amdsmi/blob/amd-mainline/docs/install/install.md Install the AMD SMI library package using apt on Ubuntu 22.04. This is for manual installation without the full ROCm stack. ```shell sudo apt install amd-smi-lib ``` -------------------------------- ### Verify AMD SMI Python Library Installation Source: https://github.com/rocm/amdsmi/blob/amd-mainline/docs/install/install.md After installation, verify that the amdsmi module can be imported in the Python interpreter. ```python import amdsmi ``` -------------------------------- ### Display Help for amd-smi process Source: https://github.com/rocm/amdsmi/blob/amd-mainline/docs/how-to/amdsmi-cli-tool.md Shows the available options and arguments for the `amd-smi process` command. Use this to understand how to filter and format process information. ```shell ~$ amd-smi process --help ``` -------------------------------- ### Print Build Configuration Details Source: https://github.com/rocm/amdsmi/blob/amd-mainline/tests/amd_smi_test/CMakeLists.txt Outputs detailed information about the current build configuration, including the build type, compiler, compiler version, and project source, binary, library, and executable directories. This is useful for debugging and understanding the build environment. ```cmake message("") message("Build Configuration:") message("-----------BuildType: " ${CMAKE_BUILD_TYPE}) message("------------Compiler: " ${CMAKE_CXX_COMPILER}) message("-------------Version: " ${CMAKE_CXX_COMPILER_VERSION}) message("--------Proj Src Dir: " ${PROJECT_SOURCE_DIR}) message("--------Proj Bld Dir: " ${PROJECT_BINARY_DIR}) message("--------Proj Lib Dir: " ${PROJECT_BINARY_DIR}/lib) message("--------Proj Exe Dir: " ${PROJECT_BINARY_DIR}/bin) message("") ``` -------------------------------- ### Add AMD SMI Go Library to Project Source: https://github.com/rocm/amdsmi/blob/amd-mainline/docs/how-to/amdsmi-go-lib.md Include the AMD SMI Go API in your project by fetching the appropriate version of the library using the go get command. ```shell go get github.com/ROCm/amdsmi@amd-staging ``` -------------------------------- ### Initialize AMD GPUs and CPUs Source: https://github.com/rocm/amdsmi/blob/amd-mainline/docs/reference/amdsmi-py-api.md Initializes the amdsmi library to include both AMD GPUs and CPUs. Includes error handling for the initialization process. ```python try: ret = amdsmi_init(AmdSmiInitFlags.INIT_AMD_APUS) # continue with amdsmi except AmdSmiException as e: print("Init both GPUs & CPUs failed") print(e) ``` -------------------------------- ### Get GPU Temperature and Board Info Source: https://github.com/rocm/amdsmi/blob/amd-mainline/docs/how-to/amdsmi-cpp-lib.md This snippet demonstrates how to get the name and current edge temperature of AMD GPUs. Ensure amdsmi is initialized with AMDSMI_INIT_AMD_GPUS. ```cpp #include #include #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 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 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; } ``` -------------------------------- ### Show amd-smi reset Help Source: https://github.com/rocm/amdsmi/blob/amd-mainline/docs/how-to/amdsmi-cli-tool.md Displays the help message for the `amd-smi reset` command, outlining available options and arguments. Requires 'sudo' privileges. ```shell ~$ amd-smi reset --help ``` -------------------------------- ### Monitor All CPUs Source: https://github.com/rocm/amdsmi/blob/amd-mainline/docs/how-to/amdsmi-cli-tool.md Selects all available CPUs for monitoring. Use 'all' with the -U argument. ```shell amd-smi monitor -U all ``` -------------------------------- ### Populate Python Package Configuration Files Source: https://github.com/rocm/amdsmi/blob/amd-mainline/py-interface/CMakeLists.txt Configures version information and setup files for the Python package by copying and processing template files. ```cmake # populate version string configure_file(pyproject.toml.in ${PY_BUILD_DIR}/pyproject.toml @ONLY) configure_file(_version.py.in ${PY_PACKAGE_DIR}/_version.py @ONLY) configure_file(setup.py.in ${PY_BUILD_DIR}/setup.py @ONLY) ``` -------------------------------- ### Get Socket Information Source: https://github.com/rocm/amdsmi/blob/amd-mainline/docs/reference/amdsmi-py-api.md Retrieves and prints the name of each socket on the machine. It first gets the socket handles and then iterates through them. Note: This function is currently hardcoded to return empty values. ```python try: socket_handles = amdsmi_get_socket_handles() if len(socket_handles) == 0: print("No sockets on machine") else: for socket in socket_handles: print(amdsmi_get_socket_info(socket)) except AmdSmiException as e: print(e) ``` -------------------------------- ### Basic CMake Configuration Source: https://github.com/rocm/amdsmi/blob/amd-mainline/example/CMakeLists.txt Sets the minimum CMake version, enables verbose output, and configures compile commands export. Use this to set up the basic build environment. ```cmake cmake_minimum_required(VERSION 3.20) option(ENABLE_ESMI_LIB "Build ESMI Library" ON) option(CMAKE_VERBOSE_MAKEFILE "Enable verbose output" ON) option(CMAKE_EXPORT_COMPILE_COMMANDS "Export compile commands for linters and autocompleters" ON) ``` -------------------------------- ### Install more_itertools for Python build workaround Source: https://github.com/rocm/amdsmi/blob/amd-mainline/docs/install/install.md Use this command to install the 'more_itertools' Python package as a workaround for a potential 'ModuleNotFoundError' during AMD SMI's CMake build process on Azure Linux 3. ```python sudo python3 -m pip install more_itertools ``` -------------------------------- ### Example Output of amd-smi static Source: https://github.com/rocm/amdsmi/blob/amd-mainline/docs/how-to/amdsmi-cli-tool.md This snippet shows the typical static output from the amd-smi tool, detailing frequency levels for various GPU components. ```text FREQUENCY_LEVELS: LEVEL 0: 54 MHz VCLK1: CURRENT LEVEL: 0 FREQUENCY_LEVELS: LEVEL 0: 54 MHz DCLK0: CURRENT LEVEL: 0 FREQUENCY_LEVELS: LEVEL 0: 45 MHz DCLK1: CURRENT LEVEL: 0 FREQUENCY_LEVELS: LEVEL 0: 45 MHz ``` -------------------------------- ### Get CPU temperature Source: https://github.com/rocm/amdsmi/blob/amd-mainline/docs/how-to/amdsmi-cli-tool.md Displays the CPU socket temperature. ```shell amd-smi --cpu-temp ``` -------------------------------- ### Display Partition Help Source: https://github.com/rocm/amdsmi/blob/amd-mainline/docs/how-to/amdsmi-cli-tool.md Shows the help message for the amd-smi partition command, detailing available arguments and options for querying partition information. ```shell ~$ amd-smi partition --help ``` -------------------------------- ### Export LD_LIBRARY_PATH Source: https://github.com/rocm/amdsmi/blob/amd-mainline/docs/how-to/amdsmi-py-lib.md Export the LD_LIBRARY_PATH to the amdsmi installation directory. This is required for initialization. ```bash export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/rocm/lib:/opt/rocm/lib64: ``` -------------------------------- ### Watch GPU metrics in real-time Source: https://github.com/rocm/amdsmi/blob/amd-mainline/docs/how-to/amdsmi-cli-tool.md Continuously monitors and displays GPU metrics every 5 seconds. Adjust the interval as needed. ```shell amd-smi metric -w 5 ``` -------------------------------- ### amdsmi_status_code_to_string Source: https://github.com/rocm/amdsmi/blob/amd-mainline/docs/reference/amdsmi-py-api.md Get a textual description of a provided AMDSMI error status code. ```APIDOC ## amdsmi_status_code_to_string ### Description Get a description of a provided AMDSMI error status. ### Parameters #### Path Parameters * `status` (uint32) - The error status for which a description is desired ### Output String description of the provided error code ### Exceptions * `AmdSmiParameterException` ### Example ```python try: status_str = amdsmi_status_code_to_string(ctypes.c_uint32(0)) print(status_str) except AmdSmiException as e: print(e) ``` ``` -------------------------------- ### List Processes with General Information Source: https://github.com/rocm/amdsmi/blob/amd-mainline/docs/how-to/amdsmi-cli-tool.md Displays PID, process name, and memory usage for processes on the specified GPU(s). ```shell amd-smi process -G -g 0 ``` -------------------------------- ### Get CPU core energy Source: https://github.com/rocm/amdsmi/blob/amd-mainline/docs/how-to/amdsmi-cli-tool.md Displays the energy consumption for the selected CPU core. ```shell amd-smi --core-energy ``` -------------------------------- ### Export Metrics for a Specific GPU on a Custom Port Source: https://github.com/rocm/amdsmi/blob/amd-mainline/rust-interface/examples/amdsmi_exporter/README.md This example demonstrates running the exporter to collect metrics for a specific GPU (identified by its BDF) and serve them on port 8080. ```sh amdsmi_exporter metric --port 8080 --gpu 0000:03:00.0 ``` -------------------------------- ### Get DIMM power consumption Source: https://github.com/rocm/amdsmi/blob/amd-mainline/docs/how-to/amdsmi-cli-tool.md Displays the power consumption for a specified DIMM address. ```shell amd-smi --cpu-dimm-pow-consumption DIMM_ADDR ``` -------------------------------- ### Get CPU socket energy Source: https://github.com/rocm/amdsmi/blob/amd-mainline/docs/how-to/amdsmi-cli-tool.md Displays the energy consumption for the selected CPU socket. ```shell amd-smi --cpu-socket-energy ``` -------------------------------- ### amdsmi_get_gpu_memory_partition / amdsmi_set_gpu_memory_partition Source: https://context7.com/rocm/amdsmi/llms.txt Get or set the memory partition mode for supported AMD GPUs. ```APIDOC ## amdsmi_get_gpu_memory_partition / amdsmi_set_gpu_memory_partition ### Description Gets or sets the memory partition mode for supported AMD GPUs. Devices must be idle when setting partitions. ### Method ```python amdsmi_get_gpu_memory_partition(handle) amdsmi_set_gpu_memory_partition(handle, partition_type) ``` ### Parameters - **handle**: Handle to the GPU processor. - **partition_type**: The desired memory partition type (e.g., `AmdSmiMemoryPartitionType.NPS1`). ### Response - **amdsmi_get_gpu_memory_partition**: String representing the current memory partition mode. - **amdsmi_set_gpu_memory_partition**: None (operation is performed for its side effect). ``` -------------------------------- ### Display CPU metrics table Source: https://github.com/rocm/amdsmi/blob/amd-mainline/docs/how-to/amdsmi-cli-tool.md Shows the complete metrics table for CPU performance monitoring. ```shell amd-smi --cpu-metrics-table ``` -------------------------------- ### List CPER Entries with JSON Output Source: https://github.com/rocm/amdsmi/blob/amd-mainline/docs/how-to/amdsmi-cli-tool.md Lists CPER entries for a specific GPU and outputs the data in JSON format to files. Also shows how to list directory contents and view a JSON file. Requires root privileges. ```bash ~$ sudo amd-smi ras --cper --severity all --folder /tmp/cper_dump/ --gpu 1 --json ``` ```bash ~$ ls -alh /tmp/cper_dump/ ``` ```json { "error_severity": "fatal", "notify_type": "MCE", "timestamp": "2000/06/27 10:45:13", "signature": "CPER", "revision": 256, "signature_end": "0xffffffff", "sec_cnt": 1, "record_length": 376, "platform_id": "111102-G40307-0C", "creator_id": "136c692517001839", "record_id": "f0000031", "flags": 0, "persistence_info": 0 } ``` -------------------------------- ### amdsmi_get_gpu_compute_partition / amdsmi_set_gpu_compute_partition Source: https://context7.com/rocm/amdsmi/llms.txt Get or set the compute partition mode for supported AMD GPUs. ```APIDOC ## amdsmi_get_gpu_compute_partition / amdsmi_set_gpu_compute_partition ### Description Gets or sets the compute partition mode (SPX, DPX, TPX, QPX, CPX) for Mi300 and newer GPUs that support Accelerated Compute Processor (XCP) partitioning. Devices must be idle when setting partitions. ### Method ```python amdsmi_get_gpu_compute_partition(handle) amdsmi_set_gpu_compute_partition(handle, partition_type) ``` ### Parameters - **handle**: Handle to the GPU processor. - **partition_type**: The desired compute partition type (e.g., `AmdSmiComputePartitionType.SPX`). ### Response - **amdsmi_get_gpu_compute_partition**: String representing the current compute partition mode. - **amdsmi_set_gpu_compute_partition**: None (operation is performed for its side effect). ``` -------------------------------- ### Monitor All GPUs Source: https://github.com/rocm/amdsmi/blob/amd-mainline/docs/how-to/amdsmi-cli-tool.md Selects all available GPUs for monitoring. Use 'all' with the -g argument. ```shell amd-smi monitor -g all ``` -------------------------------- ### amdsmi_get_gpu_activity Source: https://context7.com/rocm/amdsmi/llms.txt Gets the current utilization percentages for the graphics, memory, and multimedia engines of the GPU. ```APIDOC ## amdsmi_get_gpu_activity — Get GPU engine utilization percentages ### Description Returns current graphics engine, memory engine, and multimedia engine utilization as percentages (0–100). Not supported on virtual machine guests. ### Usage Example ```python from amdsmi import * try: amdsmi_init() for device in amdsmi_get_processor_handles(): activity = amdsmi_get_gpu_activity(device) print(f"GFX Activity : {activity['gfx_activity']}%") print(f"UMC Activity : {activity['umc_activity']}%") print(f"MM Activity : {activity['mm_activity']}%") except AmdSmiException as e: print(e) finally: amdsmi_shut_down() ``` ### Returns - **gfx_activity** (int): Graphics engine utilization percentage. - **umc_activity** (int): Memory engine utilization percentage. - **mm_activity** (int): Multimedia engine utilization percentage. ``` -------------------------------- ### amdsmi_get_lib_version Source: https://github.com/rocm/amdsmi/blob/amd-mainline/docs/reference/amdsmi-py-api.md Gets the build version of the AMDSMI library. This function does not require the AMDSMI library to be initialized. ```APIDOC ## amdsmi_get_lib_version ### Description Get the build version information for the currently running build of AMDSMI. This function doesn't require amdsmi library init. ### Output amdsmi build version ### Exceptions * `AmdSmiLibraryException` * `AmdSmiRetryException` * `AmdSmiParameterException` ### Example ```python try: version = amdsmi_get_lib_version() print(version) except AmdSmiException as e: print(e) ``` ``` -------------------------------- ### Get and Set GPU Compute and Memory Partitions Source: https://context7.com/rocm/amdsmi/llms.txt This snippet shows how to retrieve the current compute and memory partition modes for Mi300 and newer GPUs. It also demonstrates setting new partitions, which requires the device to be idle and root privileges. ```python from amdsmi import * try: amdsmi_init() for device in amdsmi_get_processor_handles(): current = amdsmi_get_gpu_compute_partition(device) print(f"Compute partition : {current}") mem_partition = amdsmi_get_gpu_memory_partition(device) print(f"Memory partition : {mem_partition}") # Change compute partition (device must be idle; requires root) amdsmi_set_gpu_compute_partition(device, AmdSmiComputePartitionType.SPX) print("Compute partition set to SPX") # Change memory partition amdsmi_set_gpu_memory_partition(device, AmdSmiMemoryPartitionType.NPS1) print("Memory partition set to NPS1") except AmdSmiException as e: print(e) finally: amdsmi_shut_down() ``` -------------------------------- ### Get CPU core boost limit Source: https://github.com/rocm/amdsmi/blob/amd-mainline/docs/how-to/amdsmi-cli-tool.md Retrieves the boost limit for the selected CPU cores. ```shell amd-smi --core-boost-limit ``` -------------------------------- ### List CPER Entries for All GPUs Source: https://github.com/rocm/amdsmi/blob/amd-mainline/docs/how-to/amdsmi-cli-tool.md Lists all CPER entries for all GPUs and saves them to files in the specified directory. Requires root privileges. ```bash ~$ sudo amd-smi ras --cper --severity all --folder /tmp/cper_dump/ ``` -------------------------------- ### Show Help for amd-smi list Source: https://github.com/rocm/amdsmi/blob/amd-mainline/docs/how-to/amdsmi-cli-tool.md Displays the help message for the 'amd-smi list' command, outlining its usage, arguments, and available options. ```shell ~$ amd-smi list --help ``` -------------------------------- ### Get DIMM thermal sensor data Source: https://github.com/rocm/amdsmi/blob/amd-mainline/docs/how-to/amdsmi-cli-tool.md Displays thermal sensor data for a specified DIMM address. ```shell amd-smi --cpu-dimm-thermal-sensor DIMM_ADDR ``` -------------------------------- ### amdsmi_get_gpu_fan_speed Source: https://github.com/rocm/amdsmi/blob/amd-mainline/docs/reference/amdsmi-py-api.md Gets the fan speed for a specified GPU device relative to AMDSMI_MAX_FAN_SPEED. Not supported on virtual machine guests. ```APIDOC ## amdsmi_get_gpu_fan_speed ### Description Get the fan speed for the specified device as a value relative to AMDSMI_MAX_FAN_SPEED. It is not supported on virtual machine guests. ### Parameters * `processor_handle` (handle) - Handle for the given device. * `sensor_idx` (int) - A 0-based sensor index. Normally, this will be 0. If a device has more than one sensor, it could be greater than 0. ### Output Fan speed in relative to MAX. ### Exceptions * `AmdSmiLibraryException` * `AmdSmiRetryException` * `AmdSmiParameterException` ### Example ```python try: devices = amdsmi_get_processor_handles() if len(devices) == 0: print("No GPUs on machine") else: for device in devices: fan_speed = amdsmi_get_gpu_fan_speed(device, 0) print(fan_speed) except AmdSmiException as e: print(e) ``` ``` -------------------------------- ### Enable CLI autocompletion for amd-smi Source: https://github.com/rocm/amdsmi/blob/amd-mainline/docs/install/install.md Install the 'argcomplete' Python package and activate global autocompletion for the 'amd-smi' CLI. Restart your shell for changes to take effect. ```shell python3 -m pip install argcomplete activate-global-python-argcomplete --user # restart shell to enable ``` -------------------------------- ### Display Help for amd-smi event Source: https://github.com/rocm/amdsmi/blob/amd-mainline/docs/how-to/amdsmi-cli-tool.md Shows the available options and arguments for the `amd-smi event` command. Use this to understand how to retrieve event information for GPUs. ```shell ~$ amd-smi event --help ``` -------------------------------- ### Get DIMM temperature range and rate Source: https://github.com/rocm/amdsmi/blob/amd-mainline/docs/how-to/amdsmi-cli-tool.md Displays the temperature range and refresh rate for a specified DIMM address. ```shell amd-smi --cpu-dimm-temp-range-rate DIMM_ADDR ``` -------------------------------- ### Get GPU Board Product Information (Python) Source: https://context7.com/rocm/amdsmi/llms.txt Fetches board-level product information for a GPU, such as serial number, product serial, FRU ID, product name, and manufacturer name. Ensure the SMI library is initialized and shut down properly. ```python from amdsmi import * try: amdsmi_init() for device in amdsmi_get_processor_handles(): board = amdsmi_get_gpu_board_info(device) print(f"Product : {board['product_name']}") print(f"Manufacturer : {board['manufacturer_name']}") print(f"Model Number : {board['model_number']}") print(f"Serial : {board['product_serial']}") print(f"FRU ID : {board['fru_id']}") except AmdSmiException as e: print(e) finally: amdsmi_shut_down() ``` -------------------------------- ### Get CPU frequency metrics Source: https://github.com/rocm/amdsmi/blob/amd-mainline/docs/how-to/amdsmi-cli-tool.md Displays current FCLK, MemClk frequencies and CCLK frequency limit for the CPU. ```shell amd-smi --cpu-freq-metrics ``` -------------------------------- ### Get Bad Pages Information Help Source: https://github.com/rocm/amdsmi/blob/amd-mainline/docs/how-to/amdsmi-cli-tool.md Displays help information for the `amd-smi bad-pages` command. Use this to understand options for retrieving bad page information for GPUs. ```shell ~$ amd-smi bad-pages --help ``` -------------------------------- ### Get GPU energy consumption Source: https://github.com/rocm/amdsmi/blob/amd-mainline/docs/how-to/amdsmi-cli-tool.md Shows the amount of energy consumed by all GPUs. Use -g to specify a GPU. ```shell amd-smi metric -E ``` -------------------------------- ### Get GPU voltage Source: https://github.com/rocm/amdsmi/blob/amd-mainline/docs/how-to/amdsmi-cli-tool.md Displays the current GPU voltage for all GPUs. Use -g to select a specific GPU. ```shell amd-smi metric -V ``` -------------------------------- ### amd-smi CLI - Show GPU Processes Source: https://context7.com/rocm/amdsmi/llms.txt Lists the processes currently utilizing specified GPUs. Provide the GPU indices as arguments. ```shell # Show processes using GPU 0 and GPU 1 ``` ```shell amd-smi process --gpu 0 1 ```