Implement CPU discovery support (#77)
* Implement CPU discovery support SWDEV-482949: enable the CPU model name info support to the RDC, rdci command can detect GPU and CPU modules at the same time. It will query the CPU info through the amdsmi interface like below: 1 GPUs found. ----------------------------------------------------------------- GPU Index Device Information 0 AMD Radeon PRO W7800 ================================================================= 1 CPUs found. ----------------------------------------------------------------- CPU Index Device Information 0 AMD Ryzen Threadripper PRO 7995WX 96-Cores ----------------------------------------------------------------- Change-Id: Ibc6533c9a61000cd86c45b1bae14c3eb6788c119 Signed-off-by: Perry Yuan <perry.yuan@amd.com> * CMAKE - Add required version for amdsmi Change-Id: I341a89351d196ec66cce215a5d1d3953302fcc66 Signed-off-by: Galantsev, Dmitrii <dmitrii.galantsev@amd.com> --------- Signed-off-by: Perry Yuan <perry.yuan@amd.com> Signed-off-by: Galantsev, Dmitrii <dmitrii.galantsev@amd.com> Co-authored-by: Galantsev, Dmitrii <dmitrii.galantsev@amd.com>
This commit is contained in:
@@ -49,7 +49,11 @@ class smi_initializer {
|
||||
smi_initializer() {
|
||||
// Make sure smi will not be initialized multiple times
|
||||
amdsmi_shut_down();
|
||||
amdsmi_status_t ret = amdsmi_init(AMDSMI_INIT_AMD_GPUS);
|
||||
amdsmi_status_t ret;
|
||||
uint64_t init_flag_;
|
||||
//initialize CPU and GPU instances
|
||||
init_flag_ = AMDSMI_INIT_AMD_GPUS | AMDSMI_INIT_AMD_CPUS;
|
||||
ret = amdsmi_init(init_flag_);
|
||||
if (ret != AMDSMI_STATUS_SUCCESS) {
|
||||
throw amd::rdc::RdcException(RDC_ST_FAIL_LOAD_MODULE, "SMI initialize fail");
|
||||
}
|
||||
@@ -193,6 +197,28 @@ rdc_status_t RdcEmbeddedHandler::rdc_device_get_all(uint32_t gpu_index_list[RDC_
|
||||
return RDC_ST_OK;
|
||||
}
|
||||
|
||||
// Discovery API
|
||||
rdc_status_t RdcEmbeddedHandler::rdc_device_get_all_cpu(uint32_t cpu_index_list[RDC_MAX_NUM_DEVICES],
|
||||
uint32_t* count) {
|
||||
if (!count) {
|
||||
return RDC_ST_BAD_PARAMETER;
|
||||
}
|
||||
|
||||
rdc_field_value device_count;
|
||||
rdc_status_t status = metric_fetcher_->fetch_smi_cpu_field(0, RDC_FI_DEV_CPU_COUNT, &device_count);
|
||||
if (status != RDC_ST_OK) {
|
||||
std::cout << "rdc_device_get_all_cpu failed to get cpu count";
|
||||
return status;
|
||||
}
|
||||
|
||||
// Assign the index to the index list
|
||||
*count = device_count.value.l_int;
|
||||
for (uint32_t i = 0; i < *count; i++) {
|
||||
cpu_index_list[i] = i;
|
||||
}
|
||||
|
||||
return RDC_ST_OK;
|
||||
}
|
||||
rdc_status_t RdcEmbeddedHandler::rdc_device_get_attributes(uint32_t gpu_index,
|
||||
rdc_device_attributes_t* p_rdc_attr) {
|
||||
if (!p_rdc_attr) {
|
||||
@@ -204,6 +230,19 @@ rdc_status_t RdcEmbeddedHandler::rdc_device_get_attributes(uint32_t gpu_index,
|
||||
return status;
|
||||
}
|
||||
|
||||
rdc_status_t RdcEmbeddedHandler::rdc_device_get_cpu_attributes(uint32_t cpu_index,
|
||||
rdc_device_attributes_t* p_rdc_attr) {
|
||||
if (!p_rdc_attr) {
|
||||
return RDC_ST_BAD_PARAMETER;
|
||||
}
|
||||
rdc_field_value device_name;
|
||||
|
||||
rdc_status_t status = metric_fetcher_->fetch_smi_cpu_field(cpu_index, RDC_FI_DEV_CPU_MODEL, &device_name);
|
||||
strncpy_with_null(p_rdc_attr->device_name, device_name.value.str, RDC_MAX_STR_LENGTH);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
rdc_status_t RdcEmbeddedHandler::rdc_device_get_component_version(
|
||||
rdc_component_t component, rdc_component_version_t* p_rdc_compv) {
|
||||
if (!p_rdc_compv) {
|
||||
|
||||
@@ -1295,5 +1295,66 @@ rdc_status_t RdcMetricFetcherImpl::acquire_smi_handle(RdcFieldKey fk) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
rdc_status_t RdcMetricFetcherImpl::fetch_smi_cpu_field(uint32_t cpu_index, rdc_field_t field_id,
|
||||
rdc_field_value* value) {
|
||||
amdsmi_status_t ret;
|
||||
amdsmi_processor_handle processor_handle = {};
|
||||
|
||||
ret = amdsmi_init(AMDSMI_INIT_AMD_CPUS);
|
||||
if (ret != AMDSMI_STATUS_SUCCESS) {
|
||||
RDC_LOG(RDC_ERROR, "Fail to init amdsmi for CPU");
|
||||
return Smi2RdcError(ret);
|
||||
}
|
||||
|
||||
if (!value) {
|
||||
return RDC_ST_BAD_PARAMETER;
|
||||
}
|
||||
|
||||
if (!is_field_valid(field_id)) {
|
||||
RDC_LOG(RDC_ERROR, "Fail to fetch CPU field " << field_id << " which is not supported");
|
||||
return RDC_ST_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
ret = get_processor_handle_from_id(cpu_index, &processor_handle);
|
||||
if (ret != AMDSMI_STATUS_SUCCESS) {
|
||||
RDC_LOG(RDC_ERROR, "Failed to get processor handle for GPU " << cpu_index << " error: " << ret);
|
||||
return Smi2RdcError(ret);
|
||||
}
|
||||
|
||||
value->ts = now();
|
||||
value->field_id = field_id;
|
||||
value->status = AMDSMI_STATUS_NOT_SUPPORTED;
|
||||
|
||||
switch (field_id) {
|
||||
case RDC_FI_DEV_CPU_COUNT: {
|
||||
uint32_t processor_count = 0;
|
||||
value->status = get_processor_count(processor_count);
|
||||
value->type = INTEGER;
|
||||
if (value->status == AMDSMI_STATUS_SUCCESS) {
|
||||
value->value.l_int = static_cast<int64_t>(processor_count);
|
||||
}
|
||||
|
||||
value->type = INTEGER;
|
||||
value->status = Smi2RdcError(ret);
|
||||
break;
|
||||
}
|
||||
case RDC_FI_DEV_CPU_MODEL: {
|
||||
amdsmi_cpu_info_t cpu_info;
|
||||
value->status = amdsmi_get_cpu_model_name(processor_handle, &cpu_info);
|
||||
value->type = STRING;
|
||||
if (value->status == AMDSMI_STATUS_SUCCESS) {
|
||||
memcpy(value->value.str, cpu_info.model_name, sizeof(cpu_info.model_name));
|
||||
}
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
RDC_LOG(RDC_ERROR, "field_id is not supported: " << field_id);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return RDC_ST_OK;
|
||||
}
|
||||
|
||||
} // namespace rdc
|
||||
} // namespace amd
|
||||
|
||||
Reference in New Issue
Block a user