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
Этот коммит содержится в:
Bill(Shuzhou) Liu
2020-03-04 15:51:16 -05:00
коммит произвёл Chris Freehill
родитель 1ff1c7b617
Коммит 020f6939f7
21 изменённых файлов: 1296 добавлений и 11 удалений
+7 -5
Просмотреть файл
@@ -1,15 +1,15 @@
# Copyright (c) 2019 - 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
@@ -46,7 +46,7 @@ set(SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}
# CACHE STRING "Default installation directory.")
# set(CPACK_PACKAGING_INSTALL_PREFIX "/"
# CACHE STRING "Default packaging prefix.")
#
#
## Compiler flags
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -m64")
@@ -68,10 +68,12 @@ file(GLOB PROTOBUF_GENERATED_INCLUDES "${PROTOB_OUT_DIR}/*.h")
file(GLOB PROTOBUF_GENERATED_SRCS "${PROTOB_OUT_DIR}/*.cc")
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include
"${PROJECT_SOURCE_DIR}/include"
"${PROTOB_OUT_DIR}" "${RSMI_INC_DIR}")
set(SERVER_SRC_LIST "${SRC_DIR}/rdc_rsmi_service.cc")
set(SERVER_SRC_LIST ${SERVER_SRC_LIST} "${SRC_DIR}/rdc_admin_service.cc")
set(SERVER_SRC_LIST ${SERVER_SRC_LIST} "${SRC_DIR}/rdc_api_service.cc")
set(SERVER_SRC_LIST ${SERVER_SRC_LIST} "${SRC_DIR}/rdc_server_main.cc")
set(SERVER_SRC_LIST ${SERVER_SRC_LIST} "${SRC_DIR}/rdc_server_utils.cc")
set(SERVER_SRC_LIST ${SERVER_SRC_LIST} "${PROTOBUF_GENERATED_SRCS}")
@@ -86,7 +88,7 @@ add_executable(${SERVER_DAEMON_EXE} "${SERVER_SRC_LIST}")
# target_include_directories(${SERVER_DAEMON_EXE} PUBLIC ${RSMI_INC_DIR})
target_link_libraries(${SERVER_DAEMON_EXE} pthread rt grpc grpc++
cap grpc++_reflection dl protobuf rocm_smi64)
cap grpc++_reflection dl protobuf rocm_smi64 rdc_bootstrap)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${SERVER_DAEMON_EXE}
PERMISSIONS OWNER_EXECUTE OWNER_READ OWNER_WRITE GROUP_READ
Исполняемый файл
+53
Просмотреть файл
@@ -0,0 +1,53 @@
/*
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.
*/
#ifndef SERVER_INCLUDE_RDC_RDC_API_SERVICE_H_
#define SERVER_INCLUDE_RDC_RDC_API_SERVICE_H_
#include "rdc.grpc.pb.h" // NOLINT
#include "rdc/rdc.h"
namespace amd {
namespace rdc {
class RdcAPIServiceImpl final : public ::rdc::RdcAPI::Service {
public:
RdcAPIServiceImpl();
~RdcAPIServiceImpl();
rdc_status_t Initialize(uint64_t rdcd_init_flags = 0);
::grpc::Status GetAllDevices(::grpc::ServerContext* context,
const ::rdc::Empty* request,
::rdc::GetAllDevicesResponse* reply) override;
::grpc::Status GetDeviceAttributes(::grpc::ServerContext* context,
const ::rdc::GetDeviceAttributesRequest* request,
::rdc::GetDeviceAttributesResponse* reply) override;
private:
rdc_handle_t rdc_handle_;
};
} // namespace rdc
} // namespace amd
#endif // SERVER_INCLUDE_RDC_RDC_API_SERVICE_H_
+7
Просмотреть файл
@@ -29,6 +29,7 @@ THE SOFTWARE.
#include "rdc/rdc_rsmi_service.h"
#include "rdc/rdc_admin_service.h"
#include "rdc/rdc_api_service.h"
class RDCServer {
public:
@@ -45,6 +46,9 @@ class RDCServer {
bool start_rdc_admin_service(void) const {return start_rdc_admin_service_;}
void set_start_rdc_admin_service(bool s) {start_rdc_admin_service_ = s;}
bool start_api_service(void) const {return start_api_service_;}
void set_start_api_service(bool s) {start_api_service_ = s;}
void ShutDown(void);
private:
@@ -57,6 +61,9 @@ class RDCServer {
bool start_rdc_admin_service_;
amd::rdc::RDCAdminServiceImpl *rdc_admin_service_;
bool start_api_service_;
amd::rdc::RdcAPIServiceImpl *api_service_;
};
#endif // SERVER_INCLUDE_RDC_RDC_SERVER_MAIN_H_
Исполняемый файл
+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
+16 -1
Просмотреть файл
@@ -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();