-
Notifications
You must be signed in to change notification settings - Fork 0
Memory pool add #15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
EthanLavi
wants to merge
5
commits into
main
Choose a base branch
from
memory_pool_add
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Memory pool add #15
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
f590cf1
Adding Jacob's remaining rdma modules
EthanLavi affee1f
Removing unnecessary using
EthanLavi f7fefa8
Adding dockerfile for development and testing build
EthanLavi eb6b00f
Removing ethan's experimental stuff
EthanLavi 539794c
Fixing based on feedback
EthanLavi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,3 +28,4 @@ third-party | |
|
|
||
| # Build | ||
| /*build* | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| FROM ubuntu:22.04 | ||
| RUN apt-get update | ||
| RUN apt-get install libprotobuf-dev protobuf-compiler -y | ||
| RUN apt-get install cmake -y | ||
| RUN apt-get install clang-15 libabsl-dev librdmacm-dev libibverbs-dev libgtest-dev libbenchmark-dev libfmt-dev libspdlog-dev libgmock-dev -y | ||
| RUN apt-get install libc6-dev-i386 -y |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| add_executable(coroutines coroutines/main.cc) | ||
| target_link_libraries(coroutines PRIVATE rome::rome) | ||
| add_executable(coroutines_out coroutines/main.cc) | ||
| target_link_libraries(coroutines_out PRIVATE rome::rome) | ||
|
|
||
| add_executable(hello_world hello_world/main.cc) | ||
| target_link_libraries(hello_world PRIVATE rome::rome) | ||
| target_link_libraries(hello_world PRIVATE absl::flags absl::flags_parse) | ||
| add_executable(hello_world_out hello_world/main.cc) | ||
| target_link_libraries(hello_world_out PRIVATE rome::rome) | ||
| target_link_libraries(hello_world_out PRIVATE absl::flags absl::flags_parse) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| #pragma once | ||
|
|
||
| #include <rdma/rdma_cma.h> | ||
|
|
||
| #include <cstdint> | ||
| #include <memory> | ||
|
|
||
| #include "rome/rdma/channel/rdma_accessor.h" | ||
| #include "rome/rdma/channel/rdma_channel.h" | ||
| #include "rome/rdma/channel/twosided_messenger.h" | ||
|
|
||
| namespace rome::rdma { | ||
|
|
||
| // Contains the necessary information for communicating between nodes. This | ||
| // class wraps a unique pointer to the `rdma_cm_id` that holds the QP used for | ||
| // communication, along with the `RdmaChannel` that represents the memory used | ||
| // for 2-sided message-passing. | ||
| template <typename Channel = RdmaChannel<EmptyRdmaMessenger, EmptyRdmaAccessor>> | ||
| class Connection { | ||
| public: | ||
| typedef Channel channel_type; | ||
|
|
||
| Connection() | ||
| : terminated_(false), | ||
| src_id_(std::numeric_limits<uint32_t>::max()), | ||
| dst_id_(std::numeric_limits<uint32_t>::max()), | ||
| channel_(nullptr) {} | ||
| Connection(uint32_t src_id, uint32_t dst_id, | ||
| std::unique_ptr<channel_type> channel) | ||
| : terminated_(false), | ||
| src_id_(src_id), | ||
| dst_id_(dst_id), | ||
| channel_(std::move(channel)) {} | ||
|
|
||
| Connection(const Connection&) = delete; | ||
| Connection(Connection&& c) | ||
| : terminated_(c.terminated_), | ||
| src_id_(c.src_id_), | ||
| dst_id_(c.dst_id_), | ||
| channel_(std::move(c.channel_)) {} | ||
|
|
||
| // Getters. | ||
| inline bool terminated() const { return terminated_; } | ||
| uint32_t src_id() const { return src_id_; } | ||
| uint32_t dst_id() const { return dst_id_; } | ||
| rdma_cm_id* id() const { return channel_->id(); } | ||
| channel_type* channel() const { return channel_.get(); } | ||
|
|
||
| void Terminate() { terminated_ = true; } | ||
|
|
||
| private: | ||
| volatile bool terminated_; | ||
|
|
||
| uint32_t src_id_; | ||
| uint32_t dst_id_; | ||
|
|
||
| // Remotely accessible memory that is used for 2-sided message-passing. | ||
| std::unique_ptr<channel_type> channel_; | ||
| }; | ||
|
|
||
| } // namespace rome::rdma |
169 changes: 169 additions & 0 deletions
169
include/rome/rdma/connection_manager/connection_manager.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,169 @@ | ||
| #pragma once | ||
|
|
||
| #include <infiniband/verbs.h> | ||
| #include <rdma/rdma_cma.h> | ||
|
|
||
| #include <chrono> | ||
| #include <limits> | ||
| #include <memory> | ||
| #include <optional> | ||
| #include <string_view> | ||
| #include <thread> | ||
| #include <unordered_set> | ||
|
|
||
| #include "absl/status/status.h" | ||
| #include "absl/status/statusor.h" | ||
| #include "connection.h" | ||
| #include "rome/rdma/channel/rdma_accessor.h" | ||
| #include "rome/rdma/channel/rdma_channel.h" | ||
| #include "rome/rdma/channel/twosided_messenger.h" | ||
| #include "rome/rdma/rdma_broker.h" | ||
| #include "rome/rdma/rdma_device.h" | ||
| #include "rome/rdma/rdma_memory.h" | ||
| #include "rome/rdma/rdma_receiver.h" | ||
| #include "rome/util/coroutine.h" | ||
|
|
||
| namespace rome::rdma { | ||
|
|
||
| template <typename ChannelType> | ||
| class ConnectionManager : public RdmaReceiverInterface { | ||
| public: | ||
| typedef Connection<ChannelType> conn_type; | ||
|
|
||
| ~ConnectionManager(); | ||
| explicit ConnectionManager(uint32_t my_id); | ||
|
|
||
| absl::Status Start(std::string_view addr, std::optional<uint16_t> port); | ||
|
|
||
| // Getters. | ||
| std::string address() const { return broker_->address(); } | ||
| uint16_t port() const { return broker_->port(); } | ||
| ibv_pd* pd() const { return broker_->pd(); } | ||
|
|
||
| int GetNumConnections() { | ||
| Acquire(my_id_); | ||
| int size = established_.size(); | ||
| Release(); | ||
| return size; | ||
| } | ||
|
|
||
| // `RdmaReceiverInterface` implementaiton | ||
| void OnConnectRequest(rdma_cm_id* id, rdma_cm_event* event) override; | ||
| void OnEstablished(rdma_cm_id* id, rdma_cm_event* event) override; | ||
| void OnDisconnect(rdma_cm_id* id) override; | ||
|
|
||
| // `RdmaClientInterface` implementation | ||
| absl::StatusOr<conn_type*> Connect(uint32_t node_id, std::string_view server, | ||
| uint16_t port); | ||
|
|
||
| absl::StatusOr<conn_type*> GetConnection(uint32_t node_id); | ||
|
|
||
| void Shutdown(); | ||
|
|
||
| private: | ||
| // The size of each memory region dedicated to a single connection. | ||
| static constexpr int kCapacity = 1 << 12; // 4 KiB | ||
| static constexpr int kMaxRecvBytes = 64; | ||
|
|
||
| static constexpr int kMaxWr = kCapacity / kMaxRecvBytes; | ||
| static constexpr int kMaxSge = 1; | ||
| static constexpr int kMaxInlineData = 0; | ||
|
|
||
| static constexpr char kPdId[] = "ConnectionManager"; | ||
|
|
||
| static constexpr int kUnlocked = -1; | ||
|
|
||
| static constexpr uint32_t kMinBackoffUs = 100; | ||
| static constexpr uint32_t kMaxBackoffUs = 5000000; | ||
|
|
||
| // Each `rdma_cm_id` can be associated with some context, which is represented | ||
| // by `IdContext`. `node_id` is the numerical identifier for the peer node of | ||
| // the connection and `conn_param` is used to provide private data during the | ||
| // connection set up to send the local node identifier upon connection setup. | ||
| struct IdContext { | ||
| uint32_t node_id; | ||
| rdma_conn_param conn_param; | ||
| ChannelType* channel; | ||
|
|
||
| static inline uint32_t GetNodeId(void* ctx) { | ||
| return reinterpret_cast<IdContext*>(ctx)->node_id; | ||
| } | ||
|
|
||
| static inline ChannelType* GetRdmaChannel(void* ctx) { | ||
| return reinterpret_cast<IdContext*>(ctx)->channel; | ||
| } | ||
| }; | ||
|
|
||
| // Lock acquisition will spin until either the lock is acquired successfully | ||
| // or the locker is an outgoing connection request from this node. | ||
| inline bool Acquire(int peer_id) { | ||
| for (int expected = kUnlocked; | ||
| !mu_.compare_exchange_weak(expected, peer_id); expected = kUnlocked) { | ||
| if (expected == my_id_) { | ||
| ROME_DEBUG( | ||
| "[Acquire] (Node {}) Giving up lock acquisition: actual={}, " | ||
| "swap={}", | ||
| my_id_, expected, peer_id); | ||
| return false; | ||
| } | ||
| } | ||
| return true; | ||
| } | ||
|
|
||
| inline void Release() { mu_ = kUnlocked; } | ||
|
|
||
| constexpr ibv_qp_init_attr DefaultQpInitAttr() { | ||
| ibv_qp_init_attr init_attr; | ||
| std::memset(&init_attr, 0, sizeof(init_attr)); | ||
| init_attr.cap.max_send_wr = init_attr.cap.max_recv_wr = kMaxWr; | ||
| init_attr.cap.max_send_sge = init_attr.cap.max_recv_sge = kMaxSge; | ||
| init_attr.cap.max_inline_data = kMaxInlineData; | ||
| init_attr.sq_sig_all = 0; // Must request completions. | ||
| init_attr.qp_type = IBV_QPT_RC; | ||
| return init_attr; | ||
| } | ||
|
|
||
| constexpr ibv_qp_attr DefaultQpAttr() { | ||
| ibv_qp_attr attr; | ||
| std::memset(&attr, 0, sizeof(attr)); | ||
| attr.qp_access_flags = IBV_ACCESS_LOCAL_WRITE | IBV_ACCESS_REMOTE_READ | | ||
| IBV_ACCESS_REMOTE_WRITE | IBV_ACCESS_REMOTE_ATOMIC; | ||
| attr.max_dest_rd_atomic = 8; | ||
| attr.path_mtu = IBV_MTU_4096; | ||
| attr.min_rnr_timer = 12; | ||
| attr.rq_psn = 0; | ||
| attr.sq_psn = 0; | ||
| attr.timeout = 12; | ||
| attr.retry_cnt = 7; | ||
| attr.rnr_retry = 1; | ||
| attr.max_rd_atomic = 8; | ||
| return attr; | ||
| } | ||
|
|
||
| absl::StatusOr<conn_type*> ConnectLoopback(rdma_cm_id* id); | ||
|
|
||
| // Whether or not to stop handling requests. | ||
| volatile bool accepting_; | ||
|
|
||
| // Current status | ||
| absl::Status status_; | ||
|
|
||
| uint32_t my_id_; | ||
| std::unique_ptr<RdmaBroker> broker_; | ||
| ibv_pd* pd_; // Convenience ptr to protection domain of `broker_` | ||
|
|
||
| // Maintains connection information for a given Internet address. A connection | ||
| // manager only maintains a single connection per node. Nodes are identified | ||
| // by a string representing their IP address. | ||
| std::atomic<int> mu_; | ||
| std::unordered_map<uint32_t, std::unique_ptr<conn_type>> requested_; | ||
| std::unordered_map<uint32_t, std::unique_ptr<conn_type>> established_; | ||
|
|
||
| uint32_t backoff_us_{0}; | ||
|
|
||
| rdma_cm_id* loopback_id_ = nullptr; | ||
| }; | ||
|
|
||
| } // namespace rome::rdma | ||
|
|
||
| #include "connection_manager_impl.h" |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.