• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright 2023 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 
17 #ifndef MINDSPORE_CCSRC_DISTRIBUTED_RPC_RDMA_RDMA_SERVER_H_
18 #define MINDSPORE_CCSRC_DISTRIBUTED_RPC_RDMA_RDMA_SERVER_H_
19 
20 #include <string>
21 #include <memory>
22 
23 #include "include/backend/distributed/rpc/rdma/constants.h"
24 #include "include/backend/distributed/rpc/rpc_server_base.h"
25 
26 namespace mindspore {
27 namespace distributed {
28 namespace rpc {
29 class BACKEND_EXPORT RDMAServer : public RPCServerBase {
30  public:
31   explicit RDMAServer(bool enable_ssl = false, const ServerPortRange &port_range = {})
RPCServerBase(enable_ssl,port_range)32       : RPCServerBase(enable_ssl, port_range),
33         urpc_allocator_(urpc_get_default_allocator_func()),
34         dev_name_(kDefaultIfName),
35         ip_addr_(kDefaultIP),
36         port_(kDefaultPort),
37         func_id_(0) {}
38   ~RDMAServer() override = default;
39 
40   bool Initialize(const std::string &url, const MemAllocateCallback &allocate_cb = {}) override;
41   void Finalize() override;
42   void SetMessageHandler(const MessageHandler &handler, uint32_t func_id = 0) override;
43 
44   std::string GetIP() const override;
45   uint32_t GetPort() const override;
46 
urpc_allocator()47   struct urpc_buffer_allocator *urpc_allocator() const {
48     return urpc_allocator_;
49   }
50 
func_id()51   uint32_t func_id() const { return func_id_; }
52 
53  private:
54   // The message callback for urpc. This method will call user-set message handler.
55   static void urpc_req_handler(struct urpc_sgl *req, void *arg, struct urpc_sgl *rsp);
56   // The callback after this server responding.
57   static void urpc_rsp_handler(struct urpc_sgl *rsp, void *arg);
58 
59   MessageHandler message_handler_;
60   struct urpc_buffer_allocator *urpc_allocator_;
61 
62   std::string dev_name_;
63   std::string ip_addr_;
64   uint16_t port_;
65   uint32_t func_id_;
66 };
67 }  // namespace rpc
68 }  // namespace distributed
69 }  // namespace mindspore
70 
71 #endif  // MINDSPORE_CCSRC_DISTRIBUTED_RPC_RDMA_RDMA_SERVER_H_
72