SWDEV-209060 - Create the Skeleton RDC CLI and daemon
Create the skeleton implementation of rdc_client.so and rdci. Modify current rdcd to integrate the RDC API service: rdc.proto is changed to add a new RdcAPI service which defined the interfaces for the RDC API. RdcStandaloneHandler.cpp is added to send the request using gRPC to the rdcd. It is built into the rdc_client.so rdci.cc, RdciDisCoverySubSystem.cc and RdciSubSystem.cc are added to implement skeleton rdci. Currently, the discovery subsystem is supported. rdc_api_service.cc is added to the server as a skeleton to implement the RdcAPI service. Currently, only discovery API is implemented. Note: we disabled the rdc_rsmi_service, which will be removed in the future. The original rdc_client.so is renamed to rdc_client_smi.so which should also be removed in the future. Add the instruction how to run the rdcd and rdci in the build folder in the README.md. Change-Id: Id232f9f83787e5812d4a295dc8cf0daa7728b06c
Dieser Commit ist enthalten in:
committet von
Chris Freehill
Ursprung
1ff1c7b617
Commit
020f6939f7
Ausführbare Datei
+110
@@ -0,0 +1,110 @@
|
||||
/*
|
||||
Copyright (c) 2020 - present Advanced Micro Devices, Inc. All rights reserved.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
#include <assert.h>
|
||||
#include <grpcpp/grpcpp.h>
|
||||
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <csignal>
|
||||
|
||||
#include "rdc.grpc.pb.h" // NOLINT
|
||||
#include "rdc/rdc_api_service.h"
|
||||
#include "rdc/rdc.h"
|
||||
|
||||
namespace amd {
|
||||
namespace rdc {
|
||||
|
||||
RdcAPIServiceImpl::RdcAPIServiceImpl():rdc_handle_(nullptr) {
|
||||
}
|
||||
|
||||
rdc_status_t RdcAPIServiceImpl::Initialize(uint64_t rdcd_init_flags) {
|
||||
rdc_status_t result = rdc_init(rdcd_init_flags);
|
||||
if (result != RDC_ST_OK) {
|
||||
std::cout << "RDC API initialize fail\n";
|
||||
return result;
|
||||
}
|
||||
|
||||
result = rdc_start_embedded(RDC_OPERATION_MODE_AUTO, &rdc_handle_);
|
||||
if (result != RDC_ST_OK) {
|
||||
std::cout << "RDC API start embedded fail\n";
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
RdcAPIServiceImpl::~RdcAPIServiceImpl() {
|
||||
if (rdc_handle_) {
|
||||
rdc_stop_embedded(rdc_handle_);
|
||||
rdc_handle_ = nullptr;
|
||||
}
|
||||
rdc_shutdown();
|
||||
}
|
||||
|
||||
::grpc::Status RdcAPIServiceImpl::GetAllDevices(::grpc::ServerContext* context,
|
||||
const ::rdc::Empty* request,
|
||||
::rdc::GetAllDevicesResponse* reply) {
|
||||
(void)(context);
|
||||
(void)(request);
|
||||
if (!reply) {
|
||||
return ::grpc::Status(::grpc::StatusCode::INTERNAL, "Empty reply");
|
||||
}
|
||||
uint32_t gpu_index_list[RDC_MAX_NUM_DEVICES];
|
||||
uint32_t count = 0;
|
||||
rdc_status_t result = rdc_get_all_devices(rdc_handle_,
|
||||
gpu_index_list, &count);
|
||||
reply->set_status(result);
|
||||
if (result != RDC_ST_OK) {
|
||||
return ::grpc::Status::OK;
|
||||
}
|
||||
for (uint32_t i = 0; i < count; i++) {
|
||||
reply->add_gpus(gpu_index_list[i]);
|
||||
}
|
||||
|
||||
return ::grpc::Status::OK;
|
||||
}
|
||||
|
||||
::grpc::Status RdcAPIServiceImpl::GetDeviceAttributes(
|
||||
::grpc::ServerContext* context,
|
||||
const ::rdc::GetDeviceAttributesRequest* request,
|
||||
::rdc::GetDeviceAttributesResponse* reply) {
|
||||
(void)(context);
|
||||
if (!reply || !request) {
|
||||
return ::grpc::Status(::grpc::StatusCode::INTERNAL, "Empty contents");
|
||||
}
|
||||
uint32_t gpu_index = request->gpu_index();
|
||||
rdc_device_attributes_t attribute;
|
||||
rdc_status_t result = rdc_get_device_attributes(rdc_handle_,
|
||||
gpu_index, &attribute);
|
||||
|
||||
::rdc::DeviceAttributes* attr = reply->mutable_attributes();
|
||||
attr->set_device_name(attribute.device_name);
|
||||
|
||||
reply->set_status(result);
|
||||
|
||||
return ::grpc::Status::OK;
|
||||
}
|
||||
|
||||
} // namespace rdc
|
||||
} // namespace amd
|
||||
|
||||
|
||||
@@ -39,6 +39,7 @@ THE SOFTWARE.
|
||||
#include "rocm_smi/rocm_smi.h"
|
||||
#include "rdc/rdc_server_main.h"
|
||||
#include "rdc/rdc_rsmi_service.h"
|
||||
#include "rdc/rdc_api_service.h"
|
||||
#include "rdc/rdc_server_utils.h"
|
||||
|
||||
static bool sShutDownServer = false;
|
||||
@@ -86,6 +87,19 @@ RDCServer::Run() {
|
||||
}
|
||||
}
|
||||
|
||||
if (start_api_service()) {
|
||||
api_service_ = new amd::rdc::RdcAPIServiceImpl();
|
||||
builder.RegisterService(api_service_);
|
||||
|
||||
// TODO(bill_liu): pass flags from cnfg file
|
||||
rdc_status_t ret = api_service_->Initialize(0);
|
||||
|
||||
if (ret != RDC_ST_OK) {
|
||||
std::cerr << "Failed to start API service" << std::endl;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Finally assemble the server.
|
||||
// std::unique_ptr<::grpc::Server> server(builder.BuildAndStart());
|
||||
server_ = builder.BuildAndStart();
|
||||
@@ -316,8 +330,9 @@ int main(int argc, char** argv) {
|
||||
}
|
||||
|
||||
// TODO(cfreehil): Eventually, set these by reading a config file
|
||||
rdc_server.set_start_rsmi_service(true);
|
||||
rdc_server.set_start_rsmi_service(false);
|
||||
rdc_server.set_start_rdc_admin_service(true);
|
||||
rdc_server.set_start_api_service(true);
|
||||
|
||||
rdc_server.Run();
|
||||
|
||||
|
||||
In neuem Issue referenzieren
Einen Benutzer sperren