Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions projects/amdsmi/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ Full documentation for amd_smi_lib is available at [https://rocm.docs.amd.com/pr
- The per-process KFD lookup rebuilt the entire KFD node topology (an expensive sysfs walk) on every call just to translate the device BDF into its KFD GPU id.
- The caller already knows this value, so it is now passed through to `gpuvsmi_get_pid_info()`, eliminating one full topology discovery per process per refresh. Falls back to the original discovery path when the id is unavailable.

### Removed

- **Removed the `amdsmi_gpu_driver_reload()` API and its Python binding** (breaking).
- Reload the amdgpu driver out of band with `sudo modprobe -r amdgpu && sudo modprobe amdgpu` to apply memory partition changes instead.

### Resolved Issues

- **Fixed `amd-smi set --ptl-status` silently failing to change PTL state**.
Expand Down
11 changes: 5 additions & 6 deletions projects/amdsmi/docs/conceptual/partition.md
Original file line number Diff line number Diff line change
Expand Up @@ -460,8 +460,6 @@ Changing partition settings has strict requirements:
sudo modprobe -r amdgpu && sudo modprobe amdgpu
```

Alternatively, call `amdsmi_gpu_driver_reload()` from the library.

- A driver reload affects **all GPUs in the hive** -- every GPU in the system is reconfigured
to the new memory partition configuration at once.

Expand All @@ -475,7 +473,7 @@ set API automatically triggered an immediate driver reload on invocation; the CL
reloaded after the user explicitly requested the partition change. The API-level reload was
separated to give applications control over when the disruptive reload occurs. Additionally,
as of [**ROCm 7.13.0**](https://github.com/ROCm/rocm-systems/blob/develop/projects/amdsmi/CHANGELOG.md#amd_smi_lib-for-rocm-7130), `amd-smi reset -r` is no longer available for driver reloading — use
`sudo modprobe -r amdgpu && sudo modprobe amdgpu` or `amdsmi_gpu_driver_reload()` instead.
`sudo modprobe -r amdgpu && sudo modprobe amdgpu` instead.
```

## Workload isolation and assignment
Expand Down Expand Up @@ -695,7 +693,8 @@ int main() {

// Step 4: Reload the driver -- required to apply the memory partition change.
// Stop all GPU workloads first. The reload may reset the accelerator partition.
amdsmi_gpu_driver_reload();
// The reload needs to occur out of band via calls to `modprobe -r amdgpu` and
// then `modprobe amdgpu`

Comment thread
gabrpham marked this conversation as resolved.
Resolved
// Step 5: Re-initialize to pull in the updated topology (new device count/handles)
amdsmi_shut_down();
Expand Down Expand Up @@ -731,7 +730,6 @@ APIs, see
index (obtained from {c:func}`amdsmi_get_gpu_accelerator_partition_profile_config`).
- {c:func}`amdsmi_get_gpu_memory_partition_config` -- Query the current NPS mode and supported NPS modes.
- {c:func}`amdsmi_set_gpu_memory_partition_mode` -- Set the NPS memory partition mode.
- {c:func}`amdsmi_gpu_driver_reload` -- Reload the amdgpu driver to apply memory partition changes.

**Bare metal only:**
- {c:func}`amdsmi_get_gpu_compute_partition` -- Query the current compute partition setting as a string.
Expand Down Expand Up @@ -769,7 +767,8 @@ amdsmi.amdsmi_set_gpu_memory_partition_mode(gpu, amdsmi.AmdSmiMemoryPartitionTyp

# Step 4: Reload the driver -- required to apply the memory partition change.
# Stop all GPU workloads first. The reload may reset the accelerator partition.
amdsmi.amdsmi_gpu_driver_reload()
# The reload needs to occur out of band via calls to `modprobe -r amdgpu` and
# then `modprobe amdgpu`

Comment thread
gabrpham marked this conversation as resolved.
Resolved
# Step 5: Re-initialize to pull in the updated topology (new device count/handles)
amdsmi.amdsmi_shut_down()
Expand Down
26 changes: 4 additions & 22 deletions projects/amdsmi/example/amd_smi_drm_example.cc
Original file line number Diff line number Diff line change
Expand Up @@ -742,18 +742,9 @@ int main() {
std::cout << "\tamdsmi_set_gpu_memory_partition(" << gpu_number << ", "
<< memoryPartitionString(updatePartition) << "): " << err_str << "\n\n";

// Reload only if the memory partition was set successfully
if (ret_set == AMDSMI_STATUS_SUCCESS) {
std::cout << "\t**Reloading GPU driver to apply memory "
<< "partition change, this may take some time... **\n";
amdsmi_status_t reload_status = amdsmi_gpu_driver_reload();
amdsmi_status_code_to_string(reload_status, &err_str);
if (reload_status == AMDSMI_STATUS_SUCCESS) {
PRINT_AMDSMI_RET(reload_status)
std::cout << "\tamdsmi_gpu_driver_reload(): " << err_str << "\n\n";
} else {
std::cout << "\tamdsmi_gpu_driver_reload(): " << err_str << "\n\n";
}
std::cout << "\t** Memory partition staged. Run to apply:\n"
<< "\t sudo modprobe -r amdgpu && sudo modprobe amdgpu\n\n";
}

// Get the current memory partition
Expand Down Expand Up @@ -841,18 +832,9 @@ int main() {
}
std::cout << "\tamdsmi_set_gpu_memory_partition(" << gpu_number << ", "
<< memoryPartitionString(orig_partition) << "): " << err_str << "\n\n";
// Reload only if the memory partition was set successfully
if (ret_set == AMDSMI_STATUS_SUCCESS) {
std::cout << "\t**Reloading GPU driver to apply memory "
<< "partition change, this may take some time... **\n";
amdsmi_status_t reload_status = amdsmi_gpu_driver_reload();
amdsmi_status_code_to_string(reload_status, &err_str);
if (reload_status == AMDSMI_STATUS_SUCCESS) {
PRINT_AMDSMI_RET(reload_status)
std::cout << "\tamdsmi_gpu_driver_reload(): " << err_str << "\n\n";
} else {
std::cout << "\tamdsmi_gpu_driver_reload(): " << err_str << "\n\n";
}
std::cout << "\t** Memory partition staged. Run to apply:\n"
<< "\t sudo modprobe -r amdgpu && sudo modprobe amdgpu\n\n";
}
// Get the current memory partition
char current_memory_partition[AMDSMI_MAX_STRING_LENGTH];
Expand Down
19 changes: 3 additions & 16 deletions projects/amdsmi/example/amd_smi_partition_example.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
// invalid and must not be used.
//
// Memory partition (NPS mode):
// Requires amdsmi_gpu_driver_reload() to take effect. The driver reload
// Requires driver reload to take effect. The driver reload
// tears down and rebuilds all kernel device objects, which also destroys
// any existing handles. amdsmi_shut_down() + amdsmi_init() is therefore
// mandatory before querying or changing anything further.
Expand Down Expand Up @@ -363,18 +363,6 @@ static void print_available_partition_modes(const std::vector<amdsmi_processor_h
return ret == AMDSMI_STATUS_SUCCESS;
}

// Returns true if the driver was reloaded successfully.
[[nodiscard]] static bool reload_driver() {
print_separator("Reload driver");
// Mandatory to apply memory partition change. All GPU activity must be
// stopped first. The reload may reset the accelerator partition to default.
// Root privileges (sudo) are required for driver reload.
std::cout << " Reloading driver, this may take some time...\n";
auto ret = amdsmi_gpu_driver_reload();
std::cout << " amdsmi_gpu_driver_reload: " << status_str(ret) << '\n';
return ret == AMDSMI_STATUS_SUCCESS;
}

// For each GPU: build the NPS→profiles map, print every entry, then demonstrate
// iterating over only the profiles compatible with the currently active NPS mode.
static void print_profiles_by_nps(const std::vector<amdsmi_processor_handle>& gpus) {
Expand Down Expand Up @@ -514,9 +502,8 @@ int main() {
} else {
mem_changed = set_memory_partition(gpus.front(), target_memory_partition);
if (mem_changed) {
if (!reload_driver())
std::cout << "[warn] Driver reload failed; memory partition change may not have "
"taken effect.\n";
std::cout << " Memory partition staged. Run to apply:\n"
<< " sudo modprobe -r amdgpu && sudo modprobe amdgpu\n";
} else {
std::cout << "\n[info] Memory partition unchanged; skipping driver reload.\n";
}
Expand Down
27 changes: 5 additions & 22 deletions projects/amdsmi/example/amd_smi_partition_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
# invalid and must not be used.
#
# Memory partition (NPS mode):
# Requires amdsmi_gpu_driver_reload() to take effect. The driver reload
# Requires driver reload to take effect. The driver reload
# tears down and rebuilds all kernel device objects, which also destroys
# any existing handles. amdsmi_shut_down() + amdsmi_init() is therefore
# mandatory before querying or changing anything further.
Expand Down Expand Up @@ -244,22 +244,6 @@ def set_memory_partition(gpu0: Any, target: amdsmi.AmdSmiMemoryPartitionType) ->
return False


# Returns True if the driver was reloaded successfully.
def reload_driver() -> bool:
print_separator("Reload driver")
# Mandatory to apply memory partition change. All GPU activity must be
# stopped first. The reload may reset the accelerator partition to default.
# Root privileges (sudo) are required for driver reload.
print(" Reloading driver, this may take some time...")
try:
amdsmi.amdsmi_gpu_driver_reload()
print(" amdsmi_gpu_driver_reload: success")
return True
except amdsmi.AmdSmiException as e:
print(f" amdsmi_gpu_driver_reload: {e}")
return False


# For each GPU: build the NPS->profiles map, print every entry, then demonstrate
# iterating over only the profiles compatible with the currently active NPS mode.
def print_profiles_by_nps(gpus: List) -> None:
Expand Down Expand Up @@ -388,11 +372,10 @@ def main() -> None:
else:
mem_changed = set_memory_partition(gpus[0], target_memory_partition)
if mem_changed:
if not reload_driver():
print(
"[warn] Driver reload failed; memory partition change "
"may not have taken effect."
)
print(
" Memory partition staged. Run to apply:\n"
" sudo modprobe -r amdgpu && sudo modprobe amdgpu"
)
else:
print("\n[info] Memory partition unchanged; skipping driver reload.")

Expand Down
62 changes: 3 additions & 59 deletions projects/amdsmi/include/amd_smi/amdsmi.h
Original file line number Diff line number Diff line change
Expand Up @@ -7112,7 +7112,7 @@ amdsmi_status_t amdsmi_get_gpu_memory_partition(amdsmi_processor_handle processo
* Device must be idle and have no workloads when performing set partition operations.
*
* On @platform{gpu_bm_linux} AMDGPU driver restart is REQUIRED to complete updating to
* the new memory partition setting. Refer to `amdsmi_gpu_driver_reload()` for more details.
* the new memory partition setting.
*
* @param[in] processor_handle Device which to query
*
Expand Down Expand Up @@ -7163,10 +7163,10 @@ amdsmi_status_t amdsmi_get_gpu_memory_partition_config(amdsmi_processor_handle p
* Device must be idle and have no workloads when performing set partition operations.
*
* @details On @platform{gpu_bm_linux} AMDGPU driver restart is REQUIRED to complete updating
* to the new memory partition setting. Refer to `amdsmi_gpu_driver_reload()` for more details.
* to the new memory partition setting.
*
* On @platform{gpu_bm_linux} AMDGPU driver restart is REQUIRED to complete updating to
* the new memory partition setting. Refer to `amdsmi_gpu_driver_reload()` for more details.
* the new memory partition setting.
*
* @param[in] processor_handle A processor handle
*
Expand Down Expand Up @@ -7859,62 +7859,6 @@ amdsmi_status_t amdsmi_get_gpu_process_list_by_pid(amdsmi_processor_handle* proc

/** @} End tagProcessInfo */

/*****************************************************************************/
/** @defgroup tagDriverControl Driver control mechanisms
* These functions provide control over the driver. Users should use with
* caution as they may cause the driver to become unstable.
* @{
*/
/**
* @brief Restart the device driver (kmod module) for all AMD GPUs on the
* system.
*
* @ingroup tagDriverControl
*
* @platform{gpu_bm_linux} @platform{guest_1vf} @platform{guest_mvf}
*
* @details This function will reload the AMD GPU driver as described in
* the Linux kernel documentation -
* https://docs.kernel.org/admin-guide/sysctl/kernel.html#modprobe
* with no extra parameters as specified in
* https://docs.kernel.org/gpu/amdgpu/module-parameters.html.
*
* Use this function with caution, as it will unload and reload the AMD GPU
* driver: `modprobe -r amdgpu && modprobe amdgpu`.
*
* Any process or workload using the AMD GPU driver is REQUIRED to be
* stopped before calling this function. Otherwise, function will return
* ::AMDSMI_STATUS_AMDGPU_RESTART_ERR could not successfully restart
* the amdgpu driver.
*
* User is REQUIRED to have root/admin privileges to call this function.
* Otherwise, this function will return ::AMDSMI_STATUS_NO_PERM.
*
* This API will take time to complete, as we are checking the driver's
* loading status to confirm it reloaded properly. If
* ::AMDSMI_STATUS_AMDGPU_RESTART_ERR is returned, it means the driver
* did not reload properly and the user should check dmesg logs.
*
* This function has been created in order to conveniently reload the
* AMD GPU driver once `amdsmi_set_gpu_memory_partition()` or
* `amdsmi_set_gpu_memory_partition_mode()` successfully has been changed
* on Baremetal systems. Now users can control the reload once all GPU
* processes/workloads have been stopped on the AMD GPU driver.
* A (AMD GPU) driver reload is REQUIRED to complete changing
* to the new memory partition configuration
* (`amdsmi_set_gpu_memory_partition()`/`amdsmi_set_gpu_memory_partition_mode()`)
* operation MUST be successful. This function WILL EFFECT all GPUs in the
* hive to be reconfigured with the specified memory partition configuration.
*
* @return ::amdsmi_status_t | ::AMDSMI_STATUS_SUCCESS on success
* @return | ::AMDSMI_STATUS_NO_PERM function requires admin/sudo privileges
* @return | ::AMDSMI_STATUS_AMDGPU_RESTART_ERR could not successfully restart
* the amdgpu driver.
*/
amdsmi_status_t amdsmi_gpu_driver_reload(void);

/** @} End tagDriverControl */

/*****************************************************************************/
/** @defgroup tagPTL Peak Tops Limiter
Comment thread
gabrpham marked this conversation as resolved.
Resolved
* @{
Expand Down
1 change: 0 additions & 1 deletion projects/amdsmi/py-interface/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,6 @@
from .amdsmi_interface import amdsmi_set_gpu_perf_level
from .amdsmi_interface import amdsmi_get_gpu_power_profile_presets
from .amdsmi_interface import amdsmi_reset_gpu
from .amdsmi_interface import amdsmi_gpu_driver_reload
from .amdsmi_interface import amdsmi_set_gpu_perf_determinism_mode
from .amdsmi_interface import amdsmi_set_gpu_fan_speed
from .amdsmi_interface import amdsmi_reset_gpu_fan
Expand Down
4 changes: 0 additions & 4 deletions projects/amdsmi/py-interface/amdsmi_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -4774,10 +4774,6 @@ def amdsmi_reset_gpu(processor_handle: processor_handle_t):
_check_res(amdsmi_wrapper.amdsmi_reset_gpu(processor_handle))


def amdsmi_gpu_driver_reload():
_check_res(amdsmi_wrapper.amdsmi_gpu_driver_reload())


def amdsmi_set_gpu_fan_speed(processor_handle: processor_handle_t, sensor_idx: int, fan_speed: int):
if not isinstance(processor_handle, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(processor_handle, amdsmi_wrapper.amdsmi_processor_handle)
Expand Down
23 changes: 8 additions & 15 deletions projects/amdsmi/py-interface/amdsmi_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -4252,12 +4252,6 @@ class struct_amdsmi_cper_hdr_t(Structure):
amdsmi_get_gpu_process_list_by_pid.argtypes = [ctypes.POINTER(ctypes.POINTER(None)), uint32_t, ctypes.POINTER(struct_amdsmi_proc_info_by_pid_t), ctypes.POINTER(ctypes.c_uint32)]
except AttributeError:
pass
try:
amdsmi_gpu_driver_reload = _libraries['libamd_smi.so'].amdsmi_gpu_driver_reload
amdsmi_gpu_driver_reload.restype = amdsmi_status_t
amdsmi_gpu_driver_reload.argtypes = []
except AttributeError:
pass
try:
amdsmi_get_gpu_ptl_state = _libraries['libamd_smi.so'].amdsmi_get_gpu_ptl_state
amdsmi_get_gpu_ptl_state.restype = amdsmi_status_t
Expand Down Expand Up @@ -5309,15 +5303,14 @@ class struct_amdsmi_ttm_info_t(Structure):
'amdsmi_gpu_block_t', 'amdsmi_gpu_cache_info_t',
'amdsmi_gpu_control_counter',
'amdsmi_gpu_counter_group_supported', 'amdsmi_gpu_create_counter',
'amdsmi_gpu_destroy_counter', 'amdsmi_gpu_driver_reload',
'amdsmi_gpu_metrics_t', 'amdsmi_gpu_ras_policy_info_t',
'amdsmi_gpu_ras_policy_v4_0_t', 'amdsmi_gpu_read_counter',
'amdsmi_gpu_validate_ras_eeprom', 'amdsmi_gpu_xcp_metrics_t',
'amdsmi_gpu_xgmi_error_status', 'amdsmi_hsmp_driver_version_t',
'amdsmi_hsmp_freqlimit_src_names', 'amdsmi_hsmp_metrics_table_t',
'amdsmi_init', 'amdsmi_init_flags_t',
'amdsmi_init_gpu_event_notification', 'amdsmi_io_bw_encoding_t',
'amdsmi_is_P2P_accessible',
'amdsmi_gpu_destroy_counter', 'amdsmi_gpu_metrics_t',
'amdsmi_gpu_ras_policy_info_t', 'amdsmi_gpu_ras_policy_v4_0_t',
'amdsmi_gpu_read_counter', 'amdsmi_gpu_validate_ras_eeprom',
'amdsmi_gpu_xcp_metrics_t', 'amdsmi_gpu_xgmi_error_status',
'amdsmi_hsmp_driver_version_t', 'amdsmi_hsmp_freqlimit_src_names',
'amdsmi_hsmp_metrics_table_t', 'amdsmi_init',
'amdsmi_init_flags_t', 'amdsmi_init_gpu_event_notification',
'amdsmi_io_bw_encoding_t', 'amdsmi_is_P2P_accessible',
'amdsmi_is_gpu_power_management_enabled', 'amdsmi_kfd_info_t',
'amdsmi_link_id_bw_type_t', 'amdsmi_link_metrics_t',
'amdsmi_link_status_t', 'amdsmi_link_type_t',
Expand Down
50 changes: 0 additions & 50 deletions projects/amdsmi/rocm_smi/include/rocm_smi/rocm_smi.h
Original file line number Diff line number Diff line change
Expand Up @@ -5929,56 +5929,6 @@ rsmi_status_t rsmi_dev_metrics_log_get(uint32_t dv_ind);

/** @} */ // end of DevMetricsHeaderInfoGet

/*****************************************************************************/
/** @defgroup DriverControl Driver control mechanisms
* These functions provide control over the driver. Users should use with
* caution as they may cause the driver to become unstable.
* @{
*/
/**
* @brief Restart the device driver (kmod module) for all AMD GPUs on the
* system.
*
* @details This function will reload the AMD GPU driver as described in
* the Linux kernel documentation -
* https://docs.kernel.org/admin-guide/sysctl/kernel.html#modprobe
* with no extra parameters as specified in
* https://docs.kernel.org/gpu/amdgpu/module-parameters.html.
*
* Use this function with caution, as it will unload and reload the AMD GPU
* driver: `modprobe -r amdgpu && modprobe amdgpu`.
*
* Any process or workload using the AMD GPU driver is REQUIRED to be
* stopped before calling this function. Otherwise, function will return
* ::RSMI_STATUS_AMDGPU_RESTART_ERR could not successfully restart
* the amdgpu driver.
*
* User is REQUIRED to have root/admin privileges to call this function.
* Otherwise, this function will return ::RSMI_STATUS_PERMISSION.
*
* This API will take time to complete, as we are checking the driver's
* loading status to confirm it reloaded properly. If
* ::RSMI_STATUS_AMDGPU_RESTART_ERR is returned, it means the driver
* did not reload properly and the user should check dmesg logs.
*
* This function has been created in order to conveniently reload the
* AMD GPU driver once `rsmi_dev_memory_partition_set()`
* successfully has been changed on Baremetal systems.
* Now users can control the reload once all GPU processes/workloads
* have been stopped on the AMD GPU driver. A (AMD GPU) driver reload
* is REQUIRED to complete changing to the new memory partition
* configuration (`rsmi_dev_memory_partition_set()`) operation MUST
* be successful. This function WILL EFFECT all GPUs in the hive to
* be reconfigured with the specified memory partition configuration.
*
* @retval ::RSMI_STATUS_SUCCESS call was successful
* @retval ::RSMI_STATUS_PERMISSION function requires root access
* @retval ::RSMI_STATUS_AMDGPU_RESTART_ERR could not successfully restart
* the amdgpu driver.
*/
rsmi_status_t rsmi_dev_amdgpu_driver_reload(void);
/** @} */ // end of DriverControl

#ifdef __cplusplus
}
#endif // __cplusplus
Expand Down
2 changes: 0 additions & 2 deletions projects/amdsmi/rocm_smi/include/rocm_smi/rocm_smi_device.h
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,6 @@ class Device {
void fillSupportedFuncs(void);
void DumpSupportedFunctions(void);
bool DeviceAPISupported(std::string name, uint64_t variant, uint64_t sub_variant);
rsmi_status_t restartAMDGpuDriver(void);
rsmi_status_t isRestartInProgress(bool* isRestartInProgress, bool* isAMDGPUModuleLive);
rsmi_status_t storeDevicePartitions(uint32_t dv_ind);
template <typename T>
std::string readBootPartitionState(uint32_t dv_ind);
Expand Down
Loading
Loading