ps/rdma/control_plane.h
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #pragma once | ||
| 2 | |||
| 3 | #include <atomic> | ||
| 4 | #include <condition_variable> | ||
| 5 | #include <cstdint> | ||
| 6 | #include <memory> | ||
| 7 | #include <mutex> | ||
| 8 | #include <string> | ||
| 9 | #include <thread> | ||
| 10 | #include <unordered_map> | ||
| 11 | #include <unordered_set> | ||
| 12 | #include <vector> | ||
| 13 | |||
| 14 | #include "ps/rdma/raw_verbs_transport.h" | ||
| 15 | |||
| 16 | namespace grpc { | ||
| 17 | class Server; | ||
| 18 | } | ||
| 19 | |||
| 20 | namespace petps { | ||
| 21 | |||
| 22 | class RdmaControlPlaneService; | ||
| 23 | |||
| 24 | struct RdmaControlPlaneEndpoint { | ||
| 25 | std::string host = "127.0.0.1"; | ||
| 26 | int port = 25100; | ||
| 27 | int timeout_ms = 30000; | ||
| 28 | }; | ||
| 29 | |||
| 30 | class RdmaControlPlaneClient { | ||
| 31 | public: | ||
| 32 | explicit RdmaControlPlaneClient(RdmaControlPlaneEndpoint endpoint); | ||
| 33 | |||
| 34 | void PublishMeta(int publisher_node_id, | ||
| 35 | int publisher_lane, | ||
| 36 | int receiver_node_id, | ||
| 37 | int receiver_lane, | ||
| 38 | const RawVerbsNodeMeta& meta) const; | ||
| 39 | RawVerbsNodeMeta | ||
| 40 | GetMeta(int publisher_node_id, | ||
| 41 | int publisher_lane, | ||
| 42 | int receiver_node_id, | ||
| 43 | int receiver_lane, | ||
| 44 | int timeout_ms = -1) const; | ||
| 45 | void PublishServerReady(int server_id) const; | ||
| 46 | void WaitServer(int server_id, int timeout_ms = -1) const; | ||
| 47 | void WaitServerReady(int num_servers, int timeout_ms = -1) const; | ||
| 48 | |||
| 49 | private: | ||
| 50 | RdmaControlPlaneEndpoint endpoint_; | ||
| 51 | }; | ||
| 52 | |||
| 53 | class RdmaControlPlaneServer { | ||
| 54 | public: | ||
| 55 | explicit RdmaControlPlaneServer(RdmaControlPlaneEndpoint endpoint); | ||
| 56 | ~RdmaControlPlaneServer(); | ||
| 57 | |||
| 58 | void Start(); | ||
| 59 | void Stop(); | ||
| 60 | |||
| 61 | private: | ||
| 62 | friend class RdmaControlPlaneService; | ||
| 63 | |||
| 64 | struct MetaKey { | ||
| 65 | int publisher_node_id = 0; | ||
| 66 | int publisher_lane = 0; | ||
| 67 | int receiver_node_id = 0; | ||
| 68 | int receiver_lane = 0; | ||
| 69 | |||
| 70 | 4 | bool operator==(const MetaKey& other) const { | |
| 71 | 8 | return publisher_node_id == other.publisher_node_id && | |
| 72 |
1/2✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
|
4 | publisher_lane == other.publisher_lane && |
| 73 |
2/4✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
|
12 | receiver_node_id == other.receiver_node_id && |
| 74 |
1/2✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
|
8 | receiver_lane == other.receiver_lane; |
| 75 | } | ||
| 76 | }; | ||
| 77 | |||
| 78 | struct MetaKeyHash { | ||
| 79 | std::size_t operator()(const MetaKey& key) const; | ||
| 80 | }; | ||
| 81 | |||
| 82 | RdmaControlPlaneEndpoint endpoint_; | ||
| 83 | std::mutex mu_; | ||
| 84 | std::condition_variable cv_; | ||
| 85 | std::unordered_map<MetaKey, RawVerbsNodeMeta, MetaKeyHash> metadata_; | ||
| 86 | std::unordered_set<int> ready_servers_; | ||
| 87 | std::atomic<bool> stop_requested_{false}; | ||
| 88 | std::unique_ptr<RdmaControlPlaneService> service_; | ||
| 89 | std::unique_ptr<grpc::Server> server_; | ||
| 90 | }; | ||
| 91 | |||
| 92 | } // namespace petps | ||
| 93 |