[SWDEV-482949] Add CPU model name querying support (#33)
- Add support to check CPU vendor info which will be called by RDC to
discovery CPU information
- Move esmi headers declaration to impl/amd_smi_common.h
- remove duplicated amdsmi_cpu_util_t
---------
Signed-off-by: Perry Yuan <perry.yuan@amd.com>
Signed-off-by: Deepak Mewar <deepak.mewar@amd.com>
Signed-off-by: Maisam Arif <Maisam.Arif@amd.com>
Co-authored-by: Deepak Mewar <deepak.mewar@amd.com>
[ROCm/amdsmi commit: 68e44c7f66]
This commit is contained in:
@@ -1520,6 +1520,7 @@ amdsmi_status_t amdsmi_get_gpu_vendor_name(
|
||||
name, len);
|
||||
}
|
||||
|
||||
|
||||
amdsmi_status_t amdsmi_get_gpu_vram_vendor(amdsmi_processor_handle processor_handle,
|
||||
char *brand, uint32_t len) {
|
||||
return rsmi_wrapper(rsmi_dev_vram_vendor_get, processor_handle, 0,
|
||||
@@ -5224,6 +5225,30 @@ amdsmi_status_t amdsmi_get_cpu_model(uint32_t *cpu_model)
|
||||
return AMDSMI_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
amdsmi_status_t amdsmi_get_cpu_model_name(amdsmi_processor_handle processor_handle, amdsmi_cpu_info_t *cpu_info)
|
||||
{
|
||||
amdsmi_status_t status;
|
||||
uint32_t sock_ind;
|
||||
std::string model_name;
|
||||
|
||||
if (processor_handle == nullptr)
|
||||
return AMDSMI_STATUS_INVAL;
|
||||
|
||||
amdsmi_status_t r = amdsmi_get_processor_info(processor_handle, SIZE, proc_id);
|
||||
if (r != AMDSMI_STATUS_SUCCESS)
|
||||
return r;
|
||||
|
||||
sock_ind = (uint8_t)std::stoi(proc_id, NULL, 0);
|
||||
|
||||
status = amd::smi::AMDSmiSystem::getInstance().get_cpu_model_name(sock_ind, &model_name);
|
||||
if (status != AMDSMI_STATUS_SUCCESS)
|
||||
return amdsmi_errno_to_esmi_status(status);
|
||||
|
||||
strncpy(cpu_info->model_name, model_name.c_str(), AMDSMI_MAX_STRING_LENGTH -1);
|
||||
|
||||
return AMDSMI_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
amdsmi_status_t amdsmi_get_cpu_handles(uint32_t *cpu_count,
|
||||
amdsmi_processor_handle *processor_handles)
|
||||
{
|
||||
@@ -5349,4 +5374,5 @@ amdsmi_status_t amdsmi_get_esmi_err_msg(amdsmi_status_t status, const char **sta
|
||||
}
|
||||
return AMDSMI_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -29,6 +29,9 @@
|
||||
#include "amd_smi/impl/amd_smi_utils.h"
|
||||
#include "rocm_smi/rocm_smi.h"
|
||||
#include "rocm_smi/rocm_smi_main.h"
|
||||
#include <fstream>
|
||||
#include <cerrno>
|
||||
#include <cstring>
|
||||
|
||||
namespace amd {
|
||||
namespace smi {
|
||||
@@ -92,24 +95,59 @@ static amdsmi_status_t get_nr_cpu_sockets(uint32_t *num_socks) {
|
||||
}
|
||||
return AMDSMI_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
amdsmi_status_t AMDSmiSystem::get_cpu_model_name(uint32_t socket_id, std::string *model_name) {
|
||||
std::ifstream cpu_info("/proc/cpuinfo");
|
||||
std::string info;
|
||||
std::map<uint32_t, std::string> socket_model_map;
|
||||
|
||||
if (!cpu_info.is_open()) {
|
||||
std::cerr << "Failed to open /proc/cpuinfo:" << strerror(errno) << std::endl;
|
||||
return AMDSMI_STATUS_FILE_ERROR;
|
||||
} else {
|
||||
uint32_t current_socket_id = -1;
|
||||
while (std::getline(cpu_info, info)) {
|
||||
if (info.find("processor") != std::string::npos) {
|
||||
current_socket_id = std::stoi(info.substr(info.find(':') + 1));
|
||||
}
|
||||
if (info.find("model name") != std::string::npos) {
|
||||
*model_name = info.substr(info.find(':') + 2);
|
||||
if (current_socket_id != -1) {
|
||||
socket_model_map[current_socket_id] = *model_name;
|
||||
}
|
||||
}
|
||||
}
|
||||
cpu_info.close();
|
||||
}
|
||||
|
||||
if (socket_model_map.find(socket_id) != socket_model_map.end()) {
|
||||
*model_name = socket_model_map[socket_id];
|
||||
} else {
|
||||
return AMDSMI_STATUS_NO_DATA;
|
||||
}
|
||||
return AMDSMI_STATUS_SUCCESS;
|
||||
}
|
||||
#endif
|
||||
|
||||
amdsmi_status_t AMDSmiSystem::init(uint64_t flags) {
|
||||
init_flag_ = flags;
|
||||
amdsmi_status_t amd_smi_status;
|
||||
// populate sockets and processors
|
||||
|
||||
// populate GPU sockets and processors
|
||||
if (flags & AMDSMI_INIT_AMD_GPUS) {
|
||||
amd_smi_status = populate_amd_gpu_devices();
|
||||
if (amd_smi_status != AMDSMI_STATUS_SUCCESS)
|
||||
return amd_smi_status;
|
||||
}
|
||||
#ifdef ENABLE_ESMI_LIB
|
||||
// populate CPU sockets and processors
|
||||
if (flags & AMDSMI_INIT_AMD_CPUS) {
|
||||
amd_smi_status = populate_amd_cpus();
|
||||
if (amd_smi_status != AMDSMI_STATUS_SUCCESS)
|
||||
return amd_smi_status;
|
||||
}
|
||||
#endif
|
||||
|
||||
return AMDSMI_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
Fai riferimento in un nuovo problema
Block a user