diff --git a/projects/amdsmi/amdsmi_cli/amdsmi_commands.py b/projects/amdsmi/amdsmi_cli/amdsmi_commands.py index 1296e03268..78b7435ac1 100644 --- a/projects/amdsmi/amdsmi_cli/amdsmi_commands.py +++ b/projects/amdsmi/amdsmi_cli/amdsmi_commands.py @@ -391,7 +391,8 @@ class AMDSMICommands(): static_dict['limit'] = limit_info if args.driver: - driver_info = {"driver_version" : "N/A", + driver_info = {"driver_name" : "N/A", + "driver_version" : "N/A", "driver_date" : "N/A"} try: diff --git a/projects/amdsmi/example/amd_smi_drm_example.cc b/projects/amdsmi/example/amd_smi_drm_example.cc index 542866b74a..2ee0bb3127 100644 --- a/projects/amdsmi/example/amd_smi_drm_example.cc +++ b/projects/amdsmi/example/amd_smi_drm_example.cc @@ -322,6 +322,7 @@ int main() { ret = amdsmi_get_gpu_driver_info(processor_handles[j], &driver_info); CHK_AMDSMI_RET(ret) printf(" Output of amdsmi_get_gpu_driver_info:\n"); + printf("\tDriver name: %s\n", driver_info.driver_name); printf("\tDriver version: %s\n", driver_info.driver_version); printf("\tDriver date: %s\n\n", driver_info.driver_date); diff --git a/projects/amdsmi/include/amd_smi/amdsmi.h b/projects/amdsmi/include/amd_smi/amdsmi.h index d7cf774345..ce70d58f30 100644 --- a/projects/amdsmi/include/amd_smi/amdsmi.h +++ b/projects/amdsmi/include/amd_smi/amdsmi.h @@ -444,6 +444,7 @@ typedef struct{ typedef struct { + char driver_name[AMDSMI_MAX_STRING_LENGTH]; char driver_version[AMDSMI_MAX_STRING_LENGTH]; char driver_date[AMDSMI_MAX_STRING_LENGTH]; } amdsmi_driver_info_t; diff --git a/projects/amdsmi/include/amd_smi/impl/amd_smi_drm.h b/projects/amdsmi/include/amd_smi/impl/amd_smi_drm.h index cb9fde0c42..88da83e82a 100644 --- a/projects/amdsmi/include/amd_smi/impl/amd_smi_drm.h +++ b/projects/amdsmi/include/amd_smi/impl/amd_smi_drm.h @@ -75,6 +75,7 @@ class AMDSmiDrm { amdsmi_status_t amdgpu_query_hw_ip(int fd, unsigned info_id, unsigned hw_ip_type, unsigned size, void *value); amdsmi_status_t amdgpu_query_vbios(int fd, void *info); + amdsmi_status_t amdgpu_query_driver_name(int fd, std::string& driver_name); amdsmi_status_t amdgpu_query_driver_date(int fd, std::string& driver_date); private: diff --git a/projects/amdsmi/include/amd_smi/impl/amd_smi_gpu_device.h b/projects/amdsmi/include/amd_smi/impl/amd_smi_gpu_device.h index fdd97d8cfd..c191b29421 100644 --- a/projects/amdsmi/include/amd_smi/impl/amd_smi_gpu_device.h +++ b/projects/amdsmi/include/amd_smi/impl/amd_smi_gpu_device.h @@ -81,6 +81,7 @@ class AMDSmiGPUDevice: public AMDSmiProcessor { amdsmi_status_t amdgpu_query_fw(unsigned info_id, unsigned fw_type, unsigned size, void *value) const; amdsmi_status_t amdgpu_query_vbios(void *info) const; + amdsmi_status_t amdgpu_query_driver_name(std::string& name) const; amdsmi_status_t amdgpu_query_driver_date(std::string& date) const; private: uint32_t gpu_id_; diff --git a/projects/amdsmi/py-interface/README.md b/projects/amdsmi/py-interface/README.md index 6efba3b16d..72f9f843fd 100644 --- a/projects/amdsmi/py-interface/README.md +++ b/projects/amdsmi/py-interface/README.md @@ -310,7 +310,13 @@ Input parameters: * `processor_handle` dev for which to query -Output: Driver info that is handling the device +Output: Dictionary with fields + +Field | Content +---|--- +`driver_name` | driver name +`driver_version` | driver_version +`driver_date` | driver_date Exceptions that can be thrown by `amdsmi_get_gpu_driver_info` function: diff --git a/projects/amdsmi/py-interface/amdsmi_interface.py b/projects/amdsmi/py-interface/amdsmi_interface.py index 41cd01af8e..9c439e3104 100644 --- a/projects/amdsmi/py-interface/amdsmi_interface.py +++ b/projects/amdsmi/py-interface/amdsmi_interface.py @@ -962,6 +962,7 @@ def amdsmi_get_gpu_driver_info( ) return { + "driver_name": info.driver_name.decode("utf-8"), "driver_version": info.driver_version.decode("utf-8"), "driver_date": info.driver_date.decode("utf-8") } diff --git a/projects/amdsmi/py-interface/amdsmi_wrapper.py b/projects/amdsmi/py-interface/amdsmi_wrapper.py index 89bf709402..74240ad597 100644 --- a/projects/amdsmi/py-interface/amdsmi_wrapper.py +++ b/projects/amdsmi/py-interface/amdsmi_wrapper.py @@ -774,6 +774,7 @@ class struct_amdsmi_driver_info_t(Structure): struct_amdsmi_driver_info_t._pack_ = 1 # source:False struct_amdsmi_driver_info_t._fields_ = [ + ('driver_name', ctypes.c_char * 64), ('driver_version', ctypes.c_char * 64), ('driver_date', ctypes.c_char * 64), ] diff --git a/projects/amdsmi/src/amd_smi/amd_smi.cc b/projects/amdsmi/src/amd_smi/amd_smi.cc index 667ec666c6..20306ebf51 100644 --- a/projects/amdsmi/src/amd_smi/amd_smi.cc +++ b/projects/amdsmi/src/amd_smi/amd_smi.cc @@ -1721,18 +1721,30 @@ amdsmi_status_t amdsmi_get_gpu_driver_info(amdsmi_processor_handle processor_han return r; int length = AMDSMI_MAX_STRING_LENGTH; + + // Get the driver version status = smi_amdgpu_get_driver_version(gpu_device, &length, info->driver_version); + + // Get the driver date std::string driver_date; status = gpu_device->amdgpu_query_driver_date(driver_date); - if (status != AMDSMI_STATUS_SUCCESS) return r; - + if (status != AMDSMI_STATUS_SUCCESS) + return r; // Reformat the driver date from 20150101 to 2015/01/01 00:00 if (driver_date.length() == 8) { driver_date = driver_date.substr(0, 4) + "/" + driver_date.substr(4, 2) + "/" + driver_date.substr(6, 2) + " 00:00"; } strncpy(info->driver_date, driver_date.c_str(), AMDSMI_MAX_STRING_LENGTH-1); + + // Get the driver name + std::string driver_name; + status = gpu_device->amdgpu_query_driver_name(driver_name); + if (status != AMDSMI_STATUS_SUCCESS) + return r; + strncpy(info->driver_name, driver_name.c_str(), AMDSMI_MAX_STRING_LENGTH-1); + return status; } diff --git a/projects/amdsmi/src/amd_smi/amd_smi_drm.cc b/projects/amdsmi/src/amd_smi/amd_smi_drm.cc index 49677e77e8..f3c6d8e090 100644 --- a/projects/amdsmi/src/amd_smi/amd_smi_drm.cc +++ b/projects/amdsmi/src/amd_smi/amd_smi_drm.cc @@ -197,6 +197,18 @@ amdsmi_status_t AMDSmiDrm::cleanup() { return AMDSMI_STATUS_SUCCESS; } +amdsmi_status_t AMDSmiDrm::amdgpu_query_driver_name(int fd, std::string& driver_name) { + // RAII handler + using drm_version_ptr = std::unique_ptr; + std::lock_guard guard(drm_mutex_); + auto version = drm_version_ptr( + drm_get_version_(fd), drm_free_version_); + if (version == nullptr) return AMDSMI_STATUS_DRM_ERROR; + driver_name = version->name; + return AMDSMI_STATUS_SUCCESS; +} + amdsmi_status_t AMDSmiDrm::amdgpu_query_driver_date(int fd, std::string& driver_date) { // RAII handler using drm_version_ptr = std::unique_ptr