Python library for monitoring and managing AMD GPUs and CPUs with programmatic hardware metrics access
Functions for retrieving static GPU device information including driver versions, ASIC details, VBIOS, firmware, board information, and device identifiers. These functions provide comprehensive hardware and software configuration data for AMD GPU devices.
Retrieve GPU driver name, version, and build date.
def amdsmi_get_gpu_driver_info(processor_handle: processor_handle) -> Dict[str, Any]:
"""
Get GPU driver information.
Retrieves the name, version, and date of the GPU driver currently loaded on the system.
This information is useful for verifying driver compatibility and troubleshooting.
Parameters:
- processor_handle (processor_handle): Handle for the GPU processor
Returns:
- Dict[str, Any]: Dictionary containing:
- "driver_name" (str): Name of the GPU driver (e.g., "amdgpu")
- "driver_version" (str): Driver version string
- "driver_date" (str): Driver build/release date
Note: Fields will contain "N/A" if information is unavailable.
Raises:
- AmdSmiParameterException: If processor_handle is not valid
- AmdSmiLibraryException: If unable to retrieve driver information
Example:
```python
import amdsmi
amdsmi.amdsmi_init()
try:
devices = amdsmi.amdsmi_get_processor_handles()
for device in devices:
driver_info = amdsmi.amdsmi_get_gpu_driver_info(device)
print(f"Driver: {driver_info['driver_name']}")
print(f"Version: {driver_info['driver_version']}")
print(f"Date: {driver_info['driver_date']}")
finally:
amdsmi.amdsmi_shut_down()
```
"""Retrieve the AMDSMI library version information.
def amdsmi_get_lib_version() -> Dict[str, Any]:
"""
Get the AMDSMI library version.
Returns version information for the AMDSMI library itself, including major, minor,
release numbers, and build identifier. This is useful for verifying library compatibility
and debugging version-specific issues.
Returns:
- Dict[str, Any]: Dictionary containing:
- "major" (int): Major version number
- "minor" (int): Minor version number
- "release" (int): Release version number
- "build" (str): Build identifier string
Raises:
- AmdSmiLibraryException: If unable to retrieve library version
Example:
```python
import amdsmi
# Can be called without initialization
version = amdsmi.amdsmi_get_lib_version()
print(f"AMDSMI Library Version: {version['major']}.{version['minor']}.{version['release']}")
print(f"Build: {version['build']}")
```
"""Retrieve the ROCm version installed on the system.
def amdsmi_get_rocm_version() -> Tuple[bool, str]:
"""
Get the ROCm version for the rocm-core library.
Attempts to retrieve the ROCm version by loading the librocm-core.so shared library
and calling its getROCmVersion function. The version is returned as a string in
the format "major.minor.patch".
The library searches for librocm-core.so in the following order:
1. ROCM_HOME/lib or ROCM_PATH/lib environment variables
2. Standard linker paths (LD_LIBRARY_PATH, /etc/ld.so.conf.d/)
Returns:
- Tuple[bool, str]: A tuple containing:
- bool: True if successful, False if an error occurred
- str: ROCm version string if successful, or error message if failed
Raises:
- Exception: If there is an error loading the shared library or calling the function
Example:
```python
import amdsmi
# Can be called without initialization
success, version_or_error = amdsmi.amdsmi_get_rocm_version()
if success:
print(f"ROCm version: {version_or_error}")
else:
print(f"Error retrieving ROCm version: {version_or_error}")
```
"""Retrieve detailed ASIC information including market name, vendor details, and hardware specifications.
def amdsmi_get_gpu_asic_info(processor_handle: processor_handle) -> Dict[str, Any]:
"""
Get GPU ASIC information.
Retrieves comprehensive ASIC (Application-Specific Integrated Circuit) information
including market name, vendor and device IDs, revision, serial number, compute units,
and graphics version. This provides detailed hardware identification data.
Parameters:
- processor_handle (processor_handle): Handle for the GPU processor
Returns:
- Dict[str, Any]: Dictionary containing:
- "market_name" (str): Marketing name of the GPU (e.g., "0x740f")
- "vendor_id" (str): Vendor ID in hex format (typically "0x1002" for AMD)
- "vendor_name" (str): Vendor name string
- "subvendor_id" (str): Subvendor ID in hex format
- "device_id" (str): Device ID in hex format
- "rev_id" (str): Revision ID in hex format
- "asic_serial" (str): ASIC serial number in hex format
- "oam_id" (int or str): OAM (OCP Accelerator Module) ID, or "N/A"
- "num_compute_units" (int or str): Number of compute units, or "N/A"
- "target_graphics_version" (str): Graphics version (e.g., "gfx90a")
- "subsystem_id" (str): Subsystem ID in hex format
Note: String fields contain "N/A" if information is unavailable.
Raises:
- AmdSmiParameterException: If processor_handle is not valid
- AmdSmiLibraryException: If unable to retrieve ASIC information
Example:
```python
import amdsmi
amdsmi.amdsmi_init()
try:
devices = amdsmi.amdsmi_get_processor_handles()
for device in devices:
asic_info = amdsmi.amdsmi_get_gpu_asic_info(device)
print(f"GPU: {asic_info['market_name']}")
print(f"Vendor: {asic_info['vendor_name']} ({asic_info['vendor_id']})")
print(f"Device ID: {asic_info['device_id']}")
print(f"Graphics Version: {asic_info['target_graphics_version']}")
print(f"Compute Units: {asic_info['num_compute_units']}")
print(f"ASIC Serial: {asic_info['asic_serial']}")
finally:
amdsmi.amdsmi_shut_down()
```
"""Retrieve Kernel Fusion Driver (KFD) information.
def amdsmi_get_gpu_kfd_info(processor_handle: processor_handle) -> Dict[str, Any]:
"""
Get KFD (Kernel Fusion Driver) information.
Retrieves KFD-related identifiers including the KFD ID, node ID, and current partition ID.
KFD is the kernel driver component that manages GPU compute operations for ROCm.
Parameters:
- processor_handle (processor_handle): Handle for the GPU processor
Returns:
- Dict[str, Any]: Dictionary containing:
- "kfd_id" (int or str): KFD device ID, or "N/A" if unavailable
- "node_id" (int or str): KFD node ID, or "N/A" if unavailable
- "current_partition_id" (int or str): Current partition ID, or "N/A" if unavailable
Raises:
- AmdSmiParameterException: If processor_handle is not valid
- AmdSmiLibraryException: If unable to retrieve KFD information
Example:
```python
import amdsmi
amdsmi.amdsmi_init()
try:
devices = amdsmi.amdsmi_get_processor_handles()
for device in devices:
kfd_info = amdsmi.amdsmi_get_gpu_kfd_info(device)
print(f"KFD ID: {kfd_info['kfd_id']}")
print(f"Node ID: {kfd_info['node_id']}")
print(f"Partition ID: {kfd_info['current_partition_id']}")
finally:
amdsmi.amdsmi_shut_down()
```
"""Retrieve GPU power cap limits and capabilities.
def amdsmi_get_power_cap_info(processor_handle: processor_handle) -> Dict[str, Any]:
"""
Get power cap information.
Retrieves current power cap settings and limits, including the current power cap,
default cap, DPM (Dynamic Power Management) cap, and minimum/maximum allowed values.
All values are in microwatts.
Parameters:
- processor_handle (processor_handle): Handle for the GPU processor
Returns:
- Dict[str, Any]: Dictionary containing:
- "power_cap" (int): Current power cap in microwatts
- "default_power_cap" (int): Default power cap in microwatts
- "dpm_cap" (int): DPM power cap in microwatts
- "min_power_cap" (int): Minimum allowed power cap in microwatts
- "max_power_cap" (int): Maximum allowed power cap in microwatts
Raises:
- AmdSmiParameterException: If processor_handle is not valid
- AmdSmiLibraryException: If unable to retrieve power cap information
Example:
```python
import amdsmi
amdsmi.amdsmi_init()
try:
devices = amdsmi.amdsmi_get_processor_handles()
for device in devices:
power_cap = amdsmi.amdsmi_get_power_cap_info(device)
print(f"Current Power Cap: {power_cap['power_cap'] / 1000000:.2f}W")
print(f"Default Power Cap: {power_cap['default_power_cap'] / 1000000:.2f}W")
print(f"Range: {power_cap['min_power_cap'] / 1000000:.2f}W - {power_cap['max_power_cap'] / 1000000:.2f}W")
finally:
amdsmi.amdsmi_shut_down()
```
"""Retrieve video memory (VRAM) configuration details.
def amdsmi_get_gpu_vram_info(processor_handle: processor_handle) -> Dict[str, Any]:
"""
Get VRAM information.
Retrieves comprehensive video memory information including type, vendor, size,
bit width, and maximum bandwidth. This provides details about the GPU's
memory subsystem configuration.
Parameters:
- processor_handle (processor_handle): Handle for the GPU processor
Returns:
- Dict[str, Any]: Dictionary containing:
- "vram_type" (int): VRAM type enumeration value (see AmdSmiVramType)
- "vram_vendor" (str): VRAM manufacturer name
- "vram_size" (int): Total VRAM size in bytes
- "vram_bit_width" (int or str): Memory bus bit width, or "N/A"
- "vram_max_bandwidth" (int or str): Maximum memory bandwidth in bytes/sec, or "N/A"
Raises:
- AmdSmiParameterException: If processor_handle is not valid
- AmdSmiLibraryException: If unable to retrieve VRAM information
Example:
```python
import amdsmi
amdsmi.amdsmi_init()
try:
devices = amdsmi.amdsmi_get_processor_handles()
for device in devices:
vram_info = amdsmi.amdsmi_get_gpu_vram_info(device)
vram_gb = vram_info['vram_size'] / (1024**3)
print(f"VRAM Size: {vram_gb:.2f} GB")
print(f"VRAM Vendor: {vram_info['vram_vendor']}")
print(f"VRAM Type: {vram_info['vram_type']}")
print(f"Memory Bus Width: {vram_info['vram_bit_width']} bits")
if vram_info['vram_max_bandwidth'] != "N/A":
bw_gbps = vram_info['vram_max_bandwidth'] / (1024**3)
print(f"Max Bandwidth: {bw_gbps:.2f} GB/s")
finally:
amdsmi.amdsmi_shut_down()
```
"""Retrieve GPU cache hierarchy information.
def amdsmi_get_gpu_cache_info(processor_handle: processor_handle) -> Dict[str, List]:
"""
Get GPU cache information.
Retrieves detailed information about the GPU's cache hierarchy, including cache
properties, sizes, levels, and sharing configuration. Returns information for
all cache levels present on the GPU.
Parameters:
- processor_handle (processor_handle): Handle for the GPU processor
Returns:
- Dict[str, List]: Dictionary containing:
- "cache" (List[Dict]): List of cache information dictionaries, each containing:
- "cache_properties" (List[str]): List of cache property strings
(e.g., "DATA_CACHE", "INST_CACHE", "CPU_CACHE", "SIMD_CACHE")
- "cache_size" (int): Cache size in bytes
- "cache_level" (int): Cache level (1, 2, 3, etc.)
- "max_num_cu_shared" (int): Maximum number of compute units sharing this cache
- "num_cache_instance" (int): Number of cache instances
Raises:
- AmdSmiParameterException: If processor_handle is not valid
- AmdSmiLibraryException: If unable to retrieve cache information or no data available
Example:
```python
import amdsmi
amdsmi.amdsmi_init()
try:
devices = amdsmi.amdsmi_get_processor_handles()
for device in devices:
cache_info = amdsmi.amdsmi_get_gpu_cache_info(device)
print(f"Cache hierarchy for GPU:")
for cache in cache_info['cache']:
size_kb = cache['cache_size'] / 1024
print(f" L{cache['cache_level']} Cache:")
print(f" Size: {size_kb:.2f} KB")
print(f" Properties: {', '.join(cache['cache_properties'])}")
print(f" Shared by {cache['max_num_cu_shared']} CUs")
print(f" Instances: {cache['num_cache_instance']}")
finally:
amdsmi.amdsmi_shut_down()
```
"""Retrieve the number of XCD (accelerator compute dies) for a GPU.
def amdsmi_get_gpu_xcd_counter(processor_handle: processor_handle) -> int:
"""
Get GPU XCD counter.
Returns the number of XCD (eXtended Compute Dies) present in the GPU. XCDs are
chiplet-based compute dies used in multi-die GPU architectures. This count is
relevant for newer AMD GPU architectures that use chiplet designs.
Parameters:
- processor_handle (processor_handle): Handle for the GPU processor
Returns:
- int: Number of XCD dies in the GPU
Raises:
- AmdSmiParameterException: If processor_handle is not valid
- AmdSmiLibraryException: If unable to retrieve XCD counter
Example:
```python
import amdsmi
amdsmi.amdsmi_init()
try:
devices = amdsmi.amdsmi_get_processor_handles()
for device in devices:
xcd_count = amdsmi.amdsmi_get_gpu_xcd_counter(device)
print(f"XCD Count: {xcd_count}")
finally:
amdsmi.amdsmi_shut_down()
```
"""Retrieve GPU VBIOS (Video BIOS) version and build information.
def amdsmi_get_gpu_vbios_info(processor_handle: processor_handle) -> Dict[str, Any]:
"""
Get GPU VBIOS information.
Retrieves VBIOS (Video BIOS) information including the VBIOS name, build date,
part number, and version string. VBIOS is the firmware that initializes the GPU
hardware during system boot.
Parameters:
- processor_handle (processor_handle): Handle for the GPU processor
Returns:
- Dict[str, Any]: Dictionary containing:
- "name" (str): VBIOS name
- "build_date" (str): VBIOS build date
- "part_number" (str): VBIOS part number
- "version" (str): VBIOS version string
Raises:
- AmdSmiParameterException: If processor_handle is not valid
- AmdSmiLibraryException: If unable to retrieve VBIOS information
Example:
```python
import amdsmi
amdsmi.amdsmi_init()
try:
devices = amdsmi.amdsmi_get_processor_handles()
for device in devices:
vbios = amdsmi.amdsmi_get_gpu_vbios_info(device)
print(f"VBIOS Name: {vbios['name']}")
print(f"VBIOS Version: {vbios['version']}")
print(f"VBIOS Build Date: {vbios['build_date']}")
print(f"VBIOS Part Number: {vbios['part_number']}")
finally:
amdsmi.amdsmi_shut_down()
```
"""Retrieve firmware version information for all GPU firmware blocks.
def amdsmi_get_fw_info(processor_handle: processor_handle) -> Dict[str, List[Dict[str, str]]]:
"""
Get firmware information for all firmware blocks.
Retrieves version information for all firmware blocks present on the GPU, including
various security processors, microcode, and subsystem firmware. Different firmware
blocks use different version formats (hex or decimal dotted notation).
Parameters:
- processor_handle (processor_handle): Handle for the GPU processor
Returns:
- Dict[str, List[Dict[str, str]]]: Dictionary containing:
- "fw_list" (List[Dict]): List of firmware information dictionaries, each containing:
- "fw_name" (str): Firmware block name (e.g., "AMDSMI_FW_ID_SMC", "AMDSMI_FW_ID_CP_ME")
- "fw_version" (str): Firmware version string (format varies by firmware type)
Raises:
- AmdSmiParameterException: If processor_handle is not valid
- AmdSmiLibraryException: If unable to retrieve firmware information
Example:
```python
import amdsmi
amdsmi.amdsmi_init()
try:
devices = amdsmi.amdsmi_get_processor_handles()
for device in devices:
fw_info = amdsmi.amdsmi_get_fw_info(device)
print("Firmware versions:")
for fw in fw_info['fw_list']:
fw_name = fw['fw_name'].replace('AMDSMI_FW_ID_', '')
print(f" {fw_name}: {fw['fw_version']}")
finally:
amdsmi.amdsmi_shut_down()
```
"""Retrieve GPU board manufacturing and identification information.
def amdsmi_get_gpu_board_info(processor_handle: processor_handle) -> Dict[str, Any]:
"""
Get GPU board information.
Retrieves board-level information including model number, product serial number,
FRU (Field Replaceable Unit) ID, product name, and manufacturer name. This
information identifies the physical board and its manufacturer.
Parameters:
- processor_handle (processor_handle): Handle for the GPU processor
Returns:
- Dict[str, Any]: Dictionary containing:
- "model_number" (str): Board model number in hex format
- "product_serial" (str): Product serial number
- "fru_id" (str): Field Replaceable Unit ID
- "product_name" (str): Product name in hex format
- "manufacturer_name" (str): Board manufacturer name
Note: Fields contain "N/A" if information is unavailable.
Raises:
- AmdSmiParameterException: If processor_handle is not valid
- AmdSmiLibraryException: If unable to retrieve board information
Example:
```python
import amdsmi
amdsmi.amdsmi_init()
try:
devices = amdsmi.amdsmi_get_processor_handles()
for device in devices:
board_info = amdsmi.amdsmi_get_gpu_board_info(device)
print(f"Board Model: {board_info['model_number']}")
print(f"Product Name: {board_info['product_name']}")
print(f"Serial Number: {board_info['product_serial']}")
print(f"Manufacturer: {board_info['manufacturer_name']}")
print(f"FRU ID: {board_info['fru_id']}")
finally:
amdsmi.amdsmi_shut_down()
```
"""Retrieve the GPU vendor name string.
def amdsmi_get_gpu_vendor_name(processor_handle: processor_handle) -> str:
"""
Get GPU vendor name.
Retrieves the vendor name string for the GPU. For AMD GPUs, this typically
returns "Advanced Micro Devices, Inc. [AMD/ATI]" or similar.
Parameters:
- processor_handle (processor_handle): Handle for the GPU processor
Returns:
- str: Vendor name string
Raises:
- AmdSmiParameterException: If processor_handle is not valid
- AmdSmiLibraryException: If unable to retrieve vendor name
Example:
```python
import amdsmi
amdsmi.amdsmi_init()
try:
devices = amdsmi.amdsmi_get_processor_handles()
for device in devices:
vendor = amdsmi.amdsmi_get_gpu_vendor_name(device)
print(f"GPU Vendor: {vendor}")
finally:
amdsmi.amdsmi_shut_down()
```
"""Retrieve the GPU device ID.
def amdsmi_get_gpu_id(processor_handle: processor_handle) -> int:
"""
Get GPU device ID.
Retrieves the PCI device ID for the GPU. This is a 16-bit identifier that
specifies the GPU model within the vendor's product line.
Parameters:
- processor_handle (processor_handle): Handle for the GPU processor
Returns:
- int: GPU device ID (16-bit unsigned integer)
Raises:
- AmdSmiParameterException: If processor_handle is not valid
- AmdSmiLibraryException: If unable to retrieve device ID
Example:
```python
import amdsmi
amdsmi.amdsmi_init()
try:
devices = amdsmi.amdsmi_get_processor_handles()
for device in devices:
device_id = amdsmi.amdsmi_get_gpu_id(device)
print(f"GPU Device ID: 0x{device_id:04x}")
finally:
amdsmi.amdsmi_shut_down()
```
"""Retrieve the VRAM vendor name.
def amdsmi_get_gpu_vram_vendor(processor_handle: processor_handle) -> str:
"""
Get VRAM vendor name.
Retrieves the name of the VRAM manufacturer (e.g., "Samsung", "SK hynix", "Micron").
This identifies which company manufactured the memory modules on the GPU.
Parameters:
- processor_handle (processor_handle): Handle for the GPU processor
Returns:
- str: VRAM vendor name string
Raises:
- AmdSmiParameterException: If processor_handle is not valid
- AmdSmiLibraryException: If unable to retrieve VRAM vendor
Example:
```python
import amdsmi
amdsmi.amdsmi_init()
try:
devices = amdsmi.amdsmi_get_processor_handles()
for device in devices:
vram_vendor = amdsmi.amdsmi_get_gpu_vram_vendor(device)
print(f"VRAM Vendor: {vram_vendor}")
finally:
amdsmi.amdsmi_shut_down()
```
"""Retrieve the GPU subsystem ID.
def amdsmi_get_gpu_subsystem_id(processor_handle: processor_handle) -> str:
"""
Get GPU subsystem ID.
Retrieves the PCI subsystem ID for the GPU. The subsystem ID is assigned by the
board manufacturer and helps identify the specific board variant. Returns as a
4-character hex string with leading zeros.
Parameters:
- processor_handle (processor_handle): Handle for the GPU processor
Returns:
- str: Subsystem ID in hex format (e.g., "0x1234")
Raises:
- AmdSmiParameterException: If processor_handle is not valid
- AmdSmiLibraryException: If unable to retrieve subsystem ID
Example:
```python
import amdsmi
amdsmi.amdsmi_init()
try:
devices = amdsmi.amdsmi_get_processor_handles()
for device in devices:
subsystem_id = amdsmi.amdsmi_get_gpu_subsystem_id(device)
print(f"Subsystem ID: {subsystem_id}")
finally:
amdsmi.amdsmi_shut_down()
```
"""Retrieve the GPU subsystem name.
def amdsmi_get_gpu_subsystem_name(processor_handle: processor_handle) -> str:
"""
Get GPU subsystem name.
Retrieves the subsystem name string for the GPU board. This is typically the
board manufacturer's product name for this specific GPU variant.
Parameters:
- processor_handle (processor_handle): Handle for the GPU processor
Returns:
- str: Subsystem name string
Raises:
- AmdSmiParameterException: If processor_handle is not valid
- AmdSmiLibraryException: If unable to retrieve subsystem name
Example:
```python
import amdsmi
amdsmi.amdsmi_init()
try:
devices = amdsmi.amdsmi_get_processor_handles()
for device in devices:
subsystem_name = amdsmi.amdsmi_get_gpu_subsystem_name(device)
print(f"Subsystem Name: {subsystem_name}")
finally:
amdsmi.amdsmi_shut_down()
```
"""Generate a comprehensive report of all GPU device information:
import amdsmi
def print_gpu_device_info(device):
"""Print comprehensive device information for a GPU."""
print("=" * 80)
# Driver and version information
driver_info = amdsmi.amdsmi_get_gpu_driver_info(device)
print(f"Driver: {driver_info['driver_name']} v{driver_info['driver_version']}")
print(f"Driver Date: {driver_info['driver_date']}")
# ASIC information
asic_info = amdsmi.amdsmi_get_gpu_asic_info(device)
print(f"\nASIC Information:")
print(f" Market Name: {asic_info['market_name']}")
print(f" Vendor: {asic_info['vendor_name']} ({asic_info['vendor_id']})")
print(f" Device ID: {asic_info['device_id']}")
print(f" Subsystem ID: {asic_info['subsystem_id']}")
print(f" Graphics Version: {asic_info['target_graphics_version']}")
print(f" Compute Units: {asic_info['num_compute_units']}")
print(f" ASIC Serial: {asic_info['asic_serial']}")
# VRAM information
vram_info = amdsmi.amdsmi_get_gpu_vram_info(device)
vram_gb = vram_info['vram_size'] / (1024**3)
print(f"\nVRAM Information:")
print(f" Size: {vram_gb:.2f} GB")
print(f" Vendor: {vram_info['vram_vendor']}")
print(f" Bit Width: {vram_info['vram_bit_width']} bits")
if vram_info['vram_max_bandwidth'] != "N/A":
bw_gbps = vram_info['vram_max_bandwidth'] / (1024**3)
print(f" Max Bandwidth: {bw_gbps:.2f} GB/s")
# Cache hierarchy
try:
cache_info = amdsmi.amdsmi_get_gpu_cache_info(device)
print(f"\nCache Hierarchy:")
for cache in cache_info['cache']:
size_kb = cache['cache_size'] / 1024
props = ', '.join(cache['cache_properties'])
print(f" L{cache['cache_level']}: {size_kb:.0f} KB ({props})")
except amdsmi.AmdSmiLibraryException:
print("\nCache information not available")
# VBIOS information
vbios = amdsmi.amdsmi_get_gpu_vbios_info(device)
print(f"\nVBIOS:")
print(f" Name: {vbios['name']}")
print(f" Version: {vbios['version']}")
print(f" Build Date: {vbios['build_date']}")
# Board information
board_info = amdsmi.amdsmi_get_gpu_board_info(device)
print(f"\nBoard Information:")
print(f" Manufacturer: {board_info['manufacturer_name']}")
print(f" Product Name: {board_info['product_name']}")
print(f" Model Number: {board_info['model_number']}")
print(f" Serial Number: {board_info['product_serial']}")
# Power cap information
power_cap = amdsmi.amdsmi_get_power_cap_info(device)
print(f"\nPower Cap:")
print(f" Current: {power_cap['power_cap'] / 1000000:.2f}W")
print(f" Default: {power_cap['default_power_cap'] / 1000000:.2f}W")
print(f" Range: {power_cap['min_power_cap'] / 1000000:.2f}W - {power_cap['max_power_cap'] / 1000000:.2f}W")
# KFD information
kfd_info = amdsmi.amdsmi_get_gpu_kfd_info(device)
print(f"\nKFD Information:")
print(f" KFD ID: {kfd_info['kfd_id']}")
print(f" Node ID: {kfd_info['node_id']}")
# Usage
amdsmi.amdsmi_init()
try:
# Print library version
lib_version = amdsmi.amdsmi_get_lib_version()
print(f"AMDSMI Library: {lib_version['major']}.{lib_version['minor']}.{lib_version['release']}")
print(f"Build: {lib_version['build']}")
# Print ROCm version
success, rocm_version = amdsmi.amdsmi_get_rocm_version()
if success:
print(f"ROCm Version: {rocm_version}")
print()
# Print information for each GPU
devices = amdsmi.amdsmi_get_processor_handles()
for i, device in enumerate(devices):
print(f"\nGPU {i}:")
print_gpu_device_info(device)
finally:
amdsmi.amdsmi_shut_down()Check and display all firmware versions:
import amdsmi
amdsmi.amdsmi_init()
try:
devices = amdsmi.amdsmi_get_processor_handles()
for i, device in enumerate(devices):
print(f"\nGPU {i} Firmware Versions:")
print("-" * 60)
fw_info = amdsmi.amdsmi_get_fw_info(device)
for fw in fw_info['fw_list']:
fw_name = fw['fw_name'].replace('AMDSMI_FW_ID_', '')
# Format name for readability
fw_name = fw_name.replace('_', ' ').title()
print(f" {fw_name:30s}: {fw['fw_version']}")
finally:
amdsmi.amdsmi_shut_down()Get essential identification information:
import amdsmi
def get_gpu_identity(device):
"""Get essential GPU identification information."""
asic_info = amdsmi.amdsmi_get_gpu_asic_info(device)
vbios = amdsmi.amdsmi_get_gpu_vbios_info(device)
vendor_name = amdsmi.amdsmi_get_gpu_vendor_name(device)
return {
'vendor': vendor_name,
'model': asic_info['market_name'],
'device_id': asic_info['device_id'],
'subsystem_id': asic_info['subsystem_id'],
'graphics_version': asic_info['target_graphics_version'],
'vbios_version': vbios['version'],
'serial': asic_info['asic_serial']
}
# Usage
amdsmi.amdsmi_init()
try:
devices = amdsmi.amdsmi_get_processor_handles()
for i, device in enumerate(devices):
identity = get_gpu_identity(device)
print(f"\nGPU {i}:")
print(f" Vendor: {identity['vendor']}")
print(f" Model: {identity['model']}")
print(f" Device ID: {identity['device_id']}")
print(f" Graphics: {identity['graphics_version']}")
print(f" VBIOS: {identity['vbios_version']}")
print(f" Serial: {identity['serial']}")
finally:
amdsmi.amdsmi_shut_down()Generate a detailed memory configuration report:
import amdsmi
amdsmi.amdsmi_init()
try:
devices = amdsmi.amdsmi_get_processor_handles()
for i, device in enumerate(devices):
print(f"\nGPU {i} Memory Configuration:")
print("-" * 60)
# VRAM details
vram_info = amdsmi.amdsmi_get_gpu_vram_info(device)
vram_gb = vram_info['vram_size'] / (1024**3)
print(f"Total VRAM: {vram_gb:.2f} GB")
print(f"VRAM Vendor: {vram_info['vram_vendor']}")
print(f"Memory Type: {vram_info['vram_type']}")
print(f"Bus Width: {vram_info['vram_bit_width']} bits")
if vram_info['vram_max_bandwidth'] != "N/A":
bw_gbps = vram_info['vram_max_bandwidth'] / (1024**3)
print(f"Max Bandwidth: {bw_gbps:.2f} GB/s")
# Cache hierarchy
try:
cache_info = amdsmi.amdsmi_get_gpu_cache_info(device)
print("\nCache Hierarchy:")
for cache in cache_info['cache']:
size_kb = cache['cache_size'] / 1024
print(f" L{cache['cache_level']} Cache:")
print(f" Size: {size_kb:.0f} KB")
print(f" Type: {', '.join(cache['cache_properties'])}")
print(f" CU Sharing: {cache['max_num_cu_shared']}")
print(f" Instances: {cache['num_cache_instance']}")
except amdsmi.AmdSmiLibraryException:
print("\nCache information not available")
finally:
amdsmi.amdsmi_shut_down()Get all version information in one place:
import amdsmi
def print_version_info():
"""Print all version information for the system and GPUs."""
# Library version (no init needed)
lib_version = amdsmi.amdsmi_get_lib_version()
print("System Version Information:")
print("=" * 60)
print(f"AMDSMI Library: {lib_version['major']}.{lib_version['minor']}.{lib_version['release']}")
print(f"Build: {lib_version['build']}")
# ROCm version (no init needed)
success, rocm_version = amdsmi.amdsmi_get_rocm_version()
if success:
print(f"ROCm Version: {rocm_version}")
else:
print(f"ROCm Version: Not available ({rocm_version})")
# Initialize for GPU queries
amdsmi.amdsmi_init()
try:
devices = amdsmi.amdsmi_get_processor_handles()
for i, device in enumerate(devices):
print(f"\nGPU {i} Version Information:")
print("-" * 60)
# Driver version
driver_info = amdsmi.amdsmi_get_gpu_driver_info(device)
print(f"Driver: {driver_info['driver_name']} {driver_info['driver_version']}")
print(f"Driver Date: {driver_info['driver_date']}")
# VBIOS version
vbios = amdsmi.amdsmi_get_gpu_vbios_info(device)
print(f"VBIOS: {vbios['version']} ({vbios['build_date']})")
# ASIC info
asic_info = amdsmi.amdsmi_get_gpu_asic_info(device)
print(f"Graphics: {asic_info['target_graphics_version']}")
print(f"Revision: {asic_info['rev_id']}")
finally:
amdsmi.amdsmi_shut_down()
# Usage
print_version_info()class AmdSmiVramType(IntEnum):
"""
VRAM memory types.
"""
VRAM_TYPE_UNKNOWN = ... # Unknown VRAM type
VRAM_TYPE_HBM = ... # High Bandwidth Memory
VRAM_TYPE_HBM2 = ... # High Bandwidth Memory 2
VRAM_TYPE_HBM2E = ... # High Bandwidth Memory 2E
VRAM_TYPE_HBM3 = ... # High Bandwidth Memory 3
VRAM_TYPE_DDR2 = ... # DDR2 SDRAM
VRAM_TYPE_DDR3 = ... # DDR3 SDRAM
VRAM_TYPE_DDR4 = ... # DDR4 SDRAM
VRAM_TYPE_DDR5 = ... # DDR5 SDRAM
VRAM_TYPE_GDDR1 = ... # GDDR1 SDRAM
VRAM_TYPE_GDDR3 = ... # GDDR3 SDRAM
VRAM_TYPE_GDDR4 = ... # GDDR4 SDRAM
VRAM_TYPE_GDDR5 = ... # GDDR5 SDRAM
VRAM_TYPE_GDDR6 = ... # GDDR6 SDRAMclass AmdSmiFwBlock(IntEnum):
"""
Firmware block identifiers.
Represents different firmware components on the GPU including security processors,
microcode, and subsystem firmware. Each block has its own version numbering.
"""
AMDSMI_FW_ID_SMC = ... # System Management Controller
AMDSMI_FW_ID_SDMA0 = ... # SDMA engine 0
AMDSMI_FW_ID_SDMA1 = ... # SDMA engine 1
AMDSMI_FW_ID_CP_CE = ... # Command Processor - Constant Engine
AMDSMI_FW_ID_CP_PFP = ... # Command Processor - Pre-Fetch Parser
AMDSMI_FW_ID_CP_ME = ... # Command Processor - Micro Engine
AMDSMI_FW_ID_CP_MEC1 = ... # Command Processor - Micro Engine Compute 1
AMDSMI_FW_ID_CP_MEC2 = ... # Command Processor - Micro Engine Compute 2
AMDSMI_FW_ID_RLC = ... # RunList Controller
AMDSMI_FW_ID_MEC = ... # Micro Engine Compute
AMDSMI_FW_ID_PSP_SOSDRV = ... # Platform Security Processor - SOS Driver
AMDSMI_FW_ID_TA_RAS = ... # Trusted Application - RAS
AMDSMI_FW_ID_TA_XGMI = ... # Trusted Application - XGMI
AMDSMI_FW_ID_UVD = ... # Unified Video Decoder
AMDSMI_FW_ID_VCE = ... # Video Compression Engine
AMDSMI_FW_ID_VCN = ... # Video Core Next
AMDSMI_FW_ID_PM = ... # Power Management (SMC)
# ... and many more firmware blocksRetrieve the GPU virtualization mode to determine if running in bare metal, host, guest, or passthrough mode.
def amdsmi_get_gpu_virtualization_mode(processor_handle: processor_handle) -> Dict[str, AmdSmiVirtualizationMode]:
"""
Get GPU virtualization mode.
Retrieves the current virtualization mode of the GPU, indicating whether it is running
on bare metal, acting as a virtualization host, running in a guest VM, or in GPU passthrough mode.
This is useful for understanding the virtualization environment and adjusting monitoring strategies accordingly.
Parameters:
- processor_handle (processor_handle): Handle for the GPU processor
Returns:
- Dict[str, AmdSmiVirtualizationMode]: Dictionary containing:
- "mode" (AmdSmiVirtualizationMode): Virtualization mode enum value
- UNKNOWN (0): Unknown virtualization mode
- BAREMETAL (1): Running on bare metal (no virtualization)
- HOST (2): Running as hypervisor host
- GUEST (3): Running in guest VM
- PASSTHROUGH (4): GPU passthrough mode
Raises:
- AmdSmiParameterException: If processor_handle is not valid
- AmdSmiLibraryException: If unable to retrieve virtualization mode
Example:
```python
import amdsmi
amdsmi.amdsmi_init()
try:
devices = amdsmi.amdsmi_get_processor_handles()
for device in devices:
virt_mode = amdsmi.amdsmi_get_gpu_virtualization_mode(device)
mode = virt_mode['mode']
if mode == amdsmi.AmdSmiVirtualizationMode.BAREMETAL:
print("Running on bare metal")
elif mode == amdsmi.AmdSmiVirtualizationMode.HOST:
print("Running as hypervisor host")
elif mode == amdsmi.AmdSmiVirtualizationMode.GUEST:
print("Running in guest VM")
elif mode == amdsmi.AmdSmiVirtualizationMode.PASSTHROUGH:
print("GPU in passthrough mode")
else:
print("Unknown virtualization mode")
finally:
amdsmi.amdsmi_shut_down()
```
"""amdsmi_init()amdsmi_get_processor_handles()amdsmi_get_lib_version, amdsmi_get_rocm_version) can be called before initialization