Break srvs. into rsmi & admin srvs. Add VerifyConnection api.

Change-Id: I67567264c37e31f3409062a14e56eba4801cd944


[ROCm/rdc commit: dc6f6f3e9a]
此提交包含在:
Chris Freehill
2019-12-22 20:30:58 -06:00
父節點 bc7f01e992
當前提交 ba14edbb4d
共有 19 個檔案被更改,包括 316 行新增87 行删除
+14 -11
查看文件
@@ -67,7 +67,7 @@ set(CLIENT_LIB "rdc_client")
set(RDC "rdc")
set(CLIENT_LIB_COMPONENT "lib${CLIENT_LIB}")
set(SRC_DIR "${PROJECT_SOURCE_DIR}/client/src")
set(INC_DIR "${PROJECT_SOURCE_DIR}/client/include/rdc")
set(RDC_CLIENT_INC_DIR "${PROJECT_SOURCE_DIR}/client/include/rdc")
################# Determine the library version #########################
## Setup the SO version based on git tags.
@@ -119,27 +119,30 @@ set(CMAKE_VERBOSE_MAKEFILE on)
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}"
"${PROTOB_OUT_DIR}" "${RSMI_INC_DIR}")
set(CLIENT_LIB_SRC_LIST "${SRC_DIR}/rdc_client.cc")
set(CLIENT_LIB_SRC_LIST ${CLIENT_LIB_SRC_LIST} "${SRC_DIR}/rdc_main.cc")
set(CLIENT_LIB_SRC_LIST ${CLIENT_LIB_SRC_LIST} "${SRC_DIR}/rdc_client_main.cc")
set(CLIENT_LIB_SRC_LIST ${CLIENT_LIB_SRC_LIST} "${PROTOBUF_GENERATED_SRCS}")
set(CLIENT_LIB_SRC_LIST ${CLIENT_LIB_SRC_LIST}
"${PROJECT_SOURCE_DIR}/common/rdc_utils.cc")
message("CLIENT_LIB_SRC_LIST=${CLIENT_LIB_SRC_LIST}")
set(CLIENT_LIB_INC_LIST "${INC_DIR}/rdc_client.h")
set(CLIENT_LIB_INC_LIST ${CLIENT_LIB_INC_LIST} "${INC_DIR}/rdc_exception.h")
set(CLIENT_LIB_INC_LIST ${CLIENT_LIB_INC_LIST} "${INC_DIR}/rdc_main.h")
set(CLIENT_LIB_INC_LIST "${RDC_CLIENT_INC_DIR}/rdc_client.h")
set(CLIENT_LIB_INC_LIST ${CLIENT_LIB_INC_LIST}
"${PROJECT_SOURCE_DIR}/common/rdc_utils.h")
"${RDC_CLIENT_INC_DIR}/rdc_exception.h")
set(CLIENT_LIB_INC_LIST ${CLIENT_LIB_INC_LIST}
"${RDC_CLIENT_INC_DIR}/rdc_client_main.h")
set(CLIENT_LIB_INC_LIST ${CLIENT_LIB_INC_LIST}
"${PROJECT_SOURCE_DIR}/common/rdc_utils.h")
add_library(${CLIENT_LIB} SHARED ${CLIENT_LIB_SRC_LIST} ${CLIENT_LIB_INC_LIST})
target_link_libraries(${CLIENT_LIB} pthread rt grpc grpc++ grpc++_reflection
dl protobuf)
target_include_directories(${CLIENT_LIB} PUBLIC ${INC_DIR})
target_include_directories(${CLIENT_LIB} PRIVATE
"${PROJECT_SOURCE_DIR}"
"${PROJECT_SOURCE_DIR}/include"
"${CMAKE_CURRENT_SOURCE_DIR}/include"
"${PROTOB_OUT_DIR}"
"${RSMI_INC_DIR}")
# TODO: set the properties for the library once we have one
## Set the VERSION and SOVERSION values
set_property(TARGET ${CLIENT_LIB} PROPERTY
+61 -1
查看文件
@@ -24,6 +24,8 @@ THE SOFTWARE.
#ifndef CLIENT_INCLUDE_RDC_RDC_CLIENT_H_
#define CLIENT_INCLUDE_RDC_RDC_CLIENT_H_
#include <grpcpp/grpcpp.h>
#include <memory>
#include <string>
#include "rocm_smi/rocm_smi.h"
@@ -192,6 +194,64 @@ typedef uintptr_t rdc_channel_t;
#define RDC_DEFAULT_SERVER_PORT 50051
#define RDC_DEFAULT_SERVER_IP "localhost"
/*****************************************************************************/
/** @defgroup RDCAdmin RDC Administration Functions
* These administrative functions are used to monitor and control, for
* example RDC connectivity.
* @{
*/
/**
* @brief Check the connection status of a channel
*
* @details Given an ::rdc_channel_t @p channel and a boolean @p
* try_to_connect, this function will return the grpc_connectivity_state for
* that channel
*
* @p channel[in] The channel for which the status will be given
*
* @param[in] try_to_connect If the channel is currently IDLE, if the argument
* is true, transition to CONNECTING.
*
* @param[inout] state A pointer to caller provided memory to which an
* the grpc_connectivity_state will be written. grpc_connectivity_state has
* the following possible values:
* GRPC_CHANNEL_IDLE channel is idle
* GRPC_CHANNEL_CONNECTING channel is connecting
* GRPC_CHANNEL_READY channel is ready for work
* GRPC_CHANNEL_TRANSIENT_FAILURE channel has seen a failure but expects to
* recover
* GRPC_CHANNEL_SHUTDOWN channel has seen a failure that it cannot
* recover from
*
* @retval ::RDC_STATUS_SUCCESS is returned upon successful call.
*
*/
rdc_status_t
rdc_channel_state_get(rdc_channel_t channel, bool try_to_connect,
grpc_connectivity_state *state);
/**
* @brief Verify a channel's connection to the server
*
* @details Given an ::rdc_channel_t @p channel, this function will send a
* random number to the server associated with @p channel. The server will send
* the number back. Upon receiving the returned message from the server, the
* number sent to the server is compared to the number received from the
* server. If the 2 numbers are the same, the connection is verified.
* Otherwise, an appropriate error code is returned.
*
* @p channel[in] The channel for which the connection will be verified
*
* @retval ::RDC_STATUS_SUCCESS is returned upon successful call.
*
*/
rdc_status_t
rdc_channel_connection_verify(rdc_channel_t channel);
/** @} */ // end of RDCAdmin
/*****************************************************************************/
/** @defgroup InitShutAdmin Initialization and Shutdown
* These functions are used for initialization of RDC and clean up when
@@ -216,7 +276,7 @@ typedef uintptr_t rdc_channel_t;
*
* @param[in] port A pointer to string containing the port on which the
* RDC server is listening
*
*
* @param[in] secure A bool indicating whether SSL should be used for
* communications (not currently supported)
*
@@ -21,8 +21,8 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#ifndef CLIENT_INCLUDE_RDC_RDC_MAIN_H_
#define CLIENT_INCLUDE_RDC_RDC_MAIN_H_
#ifndef CLIENT_INCLUDE_RDC_RDC_CLIENT_MAIN_H_
#define CLIENT_INCLUDE_RDC_RDC_CLIENT_MAIN_H_
#include <string>
#include <memory>
@@ -48,15 +48,21 @@ class RDCChannel {
std::string server_ip(void) const {return server_ip_;}
std::string server_port(void) const {return server_port_;}
bool secure_channel(void) const {return secure_channel_;}
std::shared_ptr<::rdc::Rsmi::Stub> stub(void) const {return stub_;}
std::shared_ptr<::rdc::Rsmi::Stub> rsmi_stub(void) const {return rsmi_stub_;}
std::shared_ptr<::rdc::RdcAdmin::Stub> rdc_admin_stub(void) const {
return rdc_admin_stub_;}
std::shared_ptr<grpc::Channel> const channel(void) {return channel_;}
private:
std::string server_ip_;
std::string server_port_;
bool secure_channel_;
std::shared_ptr<::rdc::Rsmi::Stub> stub_;
std::shared_ptr<::rdc::Rsmi::Stub> rsmi_stub_;
std::shared_ptr<::rdc::RdcAdmin::Stub> rdc_admin_stub_;
std::shared_ptr<grpc::Channel> channel_;
};
} // namespace rdc
} // namespace amd
#endif // CLIENT_INCLUDE_RDC_RDC_MAIN_H_
#endif // CLIENT_INCLUDE_RDC_RDC_CLIENT_MAIN_H_
+46 -4
查看文件
@@ -1,5 +1,5 @@
/*
Copyright (c) 2019 - present Advanced Micro Devices, Inc. All rights reserved.
Copyright (c) 2019 - 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
@@ -22,10 +22,11 @@ THE SOFTWARE.
#include <grpcpp/grpcpp.h>
#include <time.h>
#include <unistd.h>
#include <iostream>
#include "rdc/rdc_main.h"
#include "rdc/rdc_client_main.h"
#include "rdc/rdc_client.h"
#include "common/rdc_utils.h"
#include "rdc/rdc_exception.h"
@@ -113,6 +114,45 @@ rdc_channel_create(rdc_channel_t *channel, const char *ip,
CATCH
}
rdc_status_t
rdc_channel_state_get(rdc_channel_t channel, bool try_to_connect,
grpc_connectivity_state *state) {
TRY
CHK_PTR_ARG(state)
UINTPTR_TO_RDC_CHAN(channel)
*state = ch->channel()->GetState(try_to_connect);
return RDC_STATUS_SUCCESS;
CATCH
}
rdc_status_t
rdc_channel_connection_verify(rdc_channel_t channel) {
TRY
UINTPTR_TO_RDC_CHAN(channel)
::rdc::VerifyConnectionResponse resp;
::rdc::VerifyConnectionRequest req;
::grpc::ClientContext context;
unsigned int seed = time(NULL);
req.set_magic_num(static_cast<uint64_t>(rand_r(&seed)));
::grpc::Status status =
ch->rdc_admin_stub()->VerifyConnection(&context, req, &resp);
if (!status.ok()) {
return amd::rdc::GrpcErrorToRdcError(status.error_code());
}
if (resp.echo_magic_num() != req.magic_num()) {
return RDC_STATUS_GRPC_DATA_LOSS;
}
return RDC_STATUS_SUCCESS;
CATCH
}
rdc_status_t
rdc_channel_destroy(rdc_channel_t channel) {
@@ -135,7 +175,8 @@ rdc_num_gpus_get(rdc_channel_t channel, uint64_t *num_gpu) {
::rdc::GetNumDevicesResponse resp;
::rdc::GetNumDevicesRequest empty;
::grpc::ClientContext context;
::grpc::Status status = ch->stub()->GetNumDevices(&context, empty, &resp);
::grpc::Status status =
ch->rsmi_stub()->GetNumDevices(&context, empty, &resp);
if (!status.ok()) {
return amd::rdc::GrpcErrorToRdcError(status.error_code());
@@ -171,7 +212,8 @@ rdc_dev_temp_metric_get(rdc_channel_t channel, uint32_t dv_ind,
in_args.set_dv_ind(dv_ind);
in_args.set_sensor_type(sensor_type);
::grpc::Status status = ch->stub()->GetTemperature(&context, in_args, &resp);
::grpc::Status status =
ch->rsmi_stub()->GetTemperature(&context, in_args, &resp);
if (!status.ok()) {
return ::amd::rdc::GrpcErrorToRdcError(status.error_code());
+11 -7
查看文件
@@ -27,7 +27,7 @@ THE SOFTWARE.
#include <string>
#include "rdc.grpc.pb.h" // NOLINT
#include "rdc/rdc_main.h"
#include "rdc/rdc_client_main.h"
#include "rdc/rdc_client.h"
namespace amd {
@@ -48,21 +48,25 @@ RDCChannel::Initialize(void) {
std::string addr_str = server_ip() + ":";
addr_str += server_port();
std::shared_ptr<grpc::Channel> channel;
if (secure_channel_) {
// Not yet supported
return RDC_STATUS_GRPC_UNIMPLEMENTED;
} else {
channel = ::grpc::CreateChannel(addr_str,
channel_ = ::grpc::CreateChannel(addr_str,
grpc::InsecureChannelCredentials());
}
stub_ = ::rdc::Rsmi::NewStub(channel);
if (stub_ == nullptr) {
rsmi_stub_ = ::rdc::Rsmi::NewStub(channel_);
if (rsmi_stub_ == nullptr) {
return RDC_STATUS_GRPC_RESOURCE_EXHAUSTED;
}
rdc_admin_stub_ = ::rdc::RdcAdmin::NewStub(channel_);
if (rdc_admin_stub_ == nullptr) {
return RDC_STATUS_GRPC_RESOURCE_EXHAUSTED;
}
// Test to see if we can connect to server; if not, return err.
return RDC_STATUS_SUCCESS;
}