Add SSL mutual authentication support for rdci
The RDC API is changed to pass the certificates to the gRPC. Add the support to add all GPUs in the host to a group. Also before add a GPU to a group, the RDC API will verify that GPU exists or not. Add the support to fetch the temperature metrics. Change-Id: I5857ef03fede233d16e8b2836be120f33172da93
This commit is contained in:
committed by
Chris Freehill
parent
023de40df7
commit
66e4e790c3
@@ -41,8 +41,11 @@ rdc_status_t rdc_shutdown() {
|
||||
}
|
||||
|
||||
rdc_status_t rdc_connect(const char* ipAddress,
|
||||
rdc_handle_t* p_rdc_handle ) {
|
||||
amd::rdc::RdcHandler* (*func_make_handler)(const char*);
|
||||
rdc_handle_t* p_rdc_handle,
|
||||
const char* root_ca, const char* client_cert,
|
||||
const char* client_key ) {
|
||||
amd::rdc::RdcHandler* (*func_make_handler)(const char*,
|
||||
const char*, const char*, const char*);
|
||||
|
||||
if (!ipAddress || !p_rdc_handle) {
|
||||
return RDC_ST_FAIL_LOAD_MODULE;
|
||||
@@ -63,7 +66,8 @@ rdc_status_t rdc_connect(const char* ipAddress,
|
||||
}
|
||||
|
||||
*p_rdc_handle = static_cast<rdc_handle_t>
|
||||
(func_make_handler(ipAddress));
|
||||
(func_make_handler(ipAddress,
|
||||
root_ca, client_cert, client_key));
|
||||
return RDC_ST_OK;
|
||||
}
|
||||
|
||||
|
||||
@@ -27,13 +27,22 @@ THE SOFTWARE.
|
||||
#include "rdc_lib/impl/RdcCacheManagerImpl.h"
|
||||
#include "rdc_lib/impl/RdcWatchTableImpl.h"
|
||||
#include "rdc_lib/rdc_common.h"
|
||||
#include "rdc_lib/RdcException.h"
|
||||
#include "rocm_smi/rocm_smi.h"
|
||||
|
||||
namespace {
|
||||
// call the rsmi_init when load library
|
||||
// and rsmi_shutdown when unload the library.
|
||||
class rsmi_initializer {
|
||||
rsmi_initializer() { rsmi_init(0);}
|
||||
rsmi_initializer() {
|
||||
// Make sure rsmi will not be initialized multiple times
|
||||
rsmi_shut_down();
|
||||
rsmi_status_t rsmi_ret = rsmi_init(0);
|
||||
if (rsmi_ret != RSMI_STATUS_SUCCESS) {
|
||||
throw amd::rdc::RdcException(
|
||||
RDC_ST_FAIL_LOAD_MODULE, "RSMI initialize fail");
|
||||
}
|
||||
}
|
||||
~rsmi_initializer() { rsmi_shut_down();}
|
||||
public:
|
||||
static rsmi_initializer& getInstance() {
|
||||
@@ -144,12 +153,50 @@ rdc_status_t RdcEmbeddedHandler::rdc_group_gpu_create(rdc_group_type_t type,
|
||||
if (!group_name || !p_rdc_group_id) {
|
||||
return RDC_ST_BAD_PARAMETER;
|
||||
}
|
||||
return group_settings_->
|
||||
rdc_group_gpu_create(type, group_name, p_rdc_group_id);
|
||||
|
||||
rdc_status_t status = group_settings_->
|
||||
rdc_group_gpu_create(group_name, p_rdc_group_id);
|
||||
|
||||
if (status != RDC_ST_OK || type == RDC_GROUP_EMPTY) {
|
||||
return status;
|
||||
}
|
||||
|
||||
// Add All GPUs to the group
|
||||
uint32_t count = 0;
|
||||
uint32_t gpu_index_list[RDC_MAX_NUM_DEVICES];
|
||||
status = rdc_get_all_devices(
|
||||
gpu_index_list, &count);
|
||||
if (status != RDC_ST_OK) {
|
||||
return status;
|
||||
}
|
||||
for (uint32_t i=0; i < count; i++) {
|
||||
status = rdc_group_gpu_add(*p_rdc_group_id, gpu_index_list[i]);
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
rdc_status_t RdcEmbeddedHandler::rdc_group_gpu_add(rdc_gpu_group_t group_id,
|
||||
uint32_t gpu_index) {
|
||||
uint32_t count = 0;
|
||||
uint32_t gpu_index_list[RDC_MAX_NUM_DEVICES];
|
||||
rdc_status_t status = rdc_get_all_devices(
|
||||
gpu_index_list, &count);
|
||||
if (status != RDC_ST_OK) {
|
||||
return status;
|
||||
}
|
||||
bool is_gpu_exist = false;
|
||||
for (uint32_t i=0; i < count; i++) {
|
||||
if (gpu_index_list[i] == gpu_index) {
|
||||
is_gpu_exist = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!is_gpu_exist) {
|
||||
return RDC_ST_NOT_FOUND;
|
||||
}
|
||||
|
||||
return group_settings_->rdc_group_gpu_add(group_id, gpu_index);
|
||||
}
|
||||
|
||||
|
||||
@@ -29,15 +29,11 @@ namespace rdc {
|
||||
RdcGroupSettingsImpl::RdcGroupSettingsImpl() {
|
||||
}
|
||||
|
||||
rdc_status_t RdcGroupSettingsImpl::rdc_group_gpu_create(rdc_group_type_t type,
|
||||
rdc_status_t RdcGroupSettingsImpl::rdc_group_gpu_create(
|
||||
const char* group_name, rdc_gpu_group_t* p_rdc_group_id) {
|
||||
// TODO(bill_liu): handle type to create default group for all GPUs
|
||||
if (type == RDC_GROUP_DEFAULT) {
|
||||
return RDC_ST_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
rdc_group_info_t ginfo;
|
||||
strncpy_with_null(ginfo.group_name, group_name, RDC_MAX_STR_LENGTH);
|
||||
ginfo.count = 0;
|
||||
|
||||
std::lock_guard<std::mutex> guard(group_mutex_);
|
||||
gpu_group_.emplace(cur_group_id_, ginfo);
|
||||
@@ -72,6 +68,8 @@ rdc_status_t RdcGroupSettingsImpl::rdc_group_gpu_add(
|
||||
} else {
|
||||
return RDC_ST_MAX_LIMIT;
|
||||
}
|
||||
} else {
|
||||
return RDC_ST_NOT_FOUND;
|
||||
}
|
||||
|
||||
return RDC_ST_OK;
|
||||
|
||||
@@ -34,11 +34,10 @@ namespace rdc {
|
||||
bool RdcMetricFetcherImpl::is_field_valid(uint32_t field_id) const {
|
||||
const std::vector<uint32_t> all_fields = {RDC_FI_GPU_MEMORY_USAGE,
|
||||
RDC_FI_GPU_MEMORY_TOTAL, RDC_FI_GPU_COUNT, RDC_FI_POWER_USAGE,
|
||||
RDC_FI_GPU_SM_CLOCK, RDC_FI_GPU_UTIL, RDC_FI_DEV_NAME};
|
||||
RDC_FI_GPU_SM_CLOCK, RDC_FI_GPU_UTIL, RDC_FI_DEV_NAME, RDC_FI_GPU_TEMP};
|
||||
|
||||
return std::find(all_fields.begin(), all_fields.end(), field_id)
|
||||
!= all_fields.end();
|
||||
|
||||
}
|
||||
|
||||
rdc_status_t RdcMetricFetcherImpl::fetch_smi_field(uint32_t gpu_index,
|
||||
@@ -113,6 +112,15 @@ rdc_status_t RdcMetricFetcherImpl::fetch_smi_field(uint32_t gpu_index,
|
||||
value->value.str, RDC_MAX_STR_LENGTH);
|
||||
value->type = STRING;
|
||||
break;
|
||||
case RDC_FI_GPU_TEMP:
|
||||
int64_t val_i64;
|
||||
value->status = rsmi_dev_temp_metric_get(gpu_index,
|
||||
0, RSMI_TEMP_CURRENT, &val_i64);
|
||||
value->type = INTEGER;
|
||||
if (value->status == RSMI_STATUS_SUCCESS) {
|
||||
value->value.l_int = val_i64;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -44,7 +44,8 @@ void RdcMetricsUpdaterImpl::start() {
|
||||
updater_ = std::async(std::launch::async, [this](){
|
||||
while (started_) {
|
||||
watch_table_->rdc_update_all_fields();
|
||||
std::this_thread::sleep_for(std::chrono::microseconds(100));
|
||||
std::this_thread::sleep_for(
|
||||
std::chrono::microseconds(_check_frequency));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -23,18 +23,31 @@ THE SOFTWARE.
|
||||
#include <grpcpp/grpcpp.h>
|
||||
#include "rdc.grpc.pb.h" // NOLINT
|
||||
|
||||
|
||||
amd::rdc::RdcHandler *make_handler(const char* ip_and_port) {
|
||||
return new amd::rdc::RdcStandaloneHandler(ip_and_port);
|
||||
amd::rdc::RdcHandler *make_handler(const char* ip_and_port,
|
||||
const char* root_ca, const char* client_cert, const char* client_key) {
|
||||
return new amd::rdc::RdcStandaloneHandler(ip_and_port,
|
||||
root_ca, client_cert, client_key);
|
||||
}
|
||||
|
||||
namespace amd {
|
||||
namespace rdc {
|
||||
|
||||
RdcStandaloneHandler::RdcStandaloneHandler(const char* ip_and_port):
|
||||
stub_(::rdc::RdcAPI::NewStub(grpc::CreateChannel(ip_and_port,
|
||||
grpc::InsecureChannelCredentials()))) {
|
||||
}
|
||||
RdcStandaloneHandler::RdcStandaloneHandler(const char* ip_and_port,
|
||||
const char* root_ca, const char* client_cert, const char* client_key) {
|
||||
std::shared_ptr<grpc::ChannelCredentials> cred(nullptr);
|
||||
if (root_ca == nullptr || client_cert == nullptr
|
||||
|| client_key == nullptr) {
|
||||
cred = grpc::InsecureChannelCredentials();
|
||||
} else {
|
||||
grpc::SslCredentialsOptions sslOpts{};
|
||||
sslOpts.pem_root_certs = root_ca;
|
||||
sslOpts.pem_private_key = client_key;
|
||||
sslOpts.pem_cert_chain = client_cert;
|
||||
cred = grpc::SslCredentials(sslOpts);
|
||||
}
|
||||
stub_ = ::rdc::RdcAPI::NewStub(grpc::CreateChannel(ip_and_port, cred));
|
||||
}
|
||||
|
||||
|
||||
rdc_status_t RdcStandaloneHandler::error_handle(::grpc::Status status,
|
||||
uint32_t rdc_status) {
|
||||
@@ -44,10 +57,7 @@ rdc_status_t RdcStandaloneHandler::error_handle(::grpc::Status status,
|
||||
return RDC_ST_CLIENT_ERROR;
|
||||
}
|
||||
|
||||
if (rdc_status != RDC_ST_OK) {
|
||||
return static_cast<rdc_status_t>(rdc_status);
|
||||
}
|
||||
return RDC_ST_OK;
|
||||
return static_cast<rdc_status_t>(rdc_status);
|
||||
}
|
||||
|
||||
// JOB RdcAPI
|
||||
|
||||
Reference in New Issue
Block a user