1 /** 2 * Copyright 2020-2021 Huawei Technologies Co., Ltd 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 #ifndef MINDSPORE_CCSRC_DEBUG_DEBUGGER_GRPC_CLIENT_H_ 17 #define MINDSPORE_CCSRC_DEBUG_DEBUGGER_GRPC_CLIENT_H_ 18 19 #include <grpcpp/grpcpp.h> 20 #include <string> 21 #include <list> 22 #include <vector> 23 #include <memory> 24 #include "proto/debug_grpc.grpc.pb.h" 25 26 using debugger::Chunk; 27 using debugger::EventListener; 28 using debugger::EventReply; 29 using debugger::GraphProto; 30 using debugger::Heartbeat; 31 using debugger::Metadata; 32 using debugger::TensorBase; 33 using debugger::TensorProto; 34 using debugger::TensorSummary; 35 using debugger::WatchpointHit; 36 37 namespace mindspore { 38 class GrpcClient { 39 public: 40 GrpcClient(const std::string &host, const std::string &port); 41 42 ~GrpcClient() = default; 43 44 void Init(const std::string &host, const std::string &port); 45 46 void Reset(); 47 48 EventReply WaitForCommand(const Metadata &metadata); 49 50 EventReply SendMetadata(const Metadata &metadata); 51 52 EventReply SendGraph(const GraphProto &graph); 53 54 EventReply SendTensors(const std::list<TensorProto> &tensors); 55 56 EventReply SendTensorBase(const std::list<TensorBase> &tensor_base); 57 58 EventReply SendTensorStats(const std::list<TensorSummary> &tensor_summary); 59 60 EventReply SendMultiGraphs(const std::list<Chunk> &chunks); 61 62 EventReply SendWatchpointHits(const std::list<WatchpointHit> &watchpoints); 63 64 std::vector<std::string> ChunkString(std::string str, int graph_size) const; 65 66 EventReply SendHeartbeat(const Heartbeat &heartbeat); 67 68 private: 69 std::unique_ptr<EventListener::Stub> stub_; 70 }; 71 } // namespace mindspore 72 #endif // MINDSPORE_CCSRC_DEBUG_DEBUGGER_GRPC_CLIENT_H_ 73