Repository navigation
Add IO layer - #10
Merged
Merged
Add IO layer#10
Conversation
There was a problem hiding this comment.
Pull request overview
Adds a new distributed IO layer (IOContext) on top of ProcessGroupUCX, plus a dedicated shared library target (commux_io) to ship this functionality separately from the core backend.
Changes:
- Introduces
commux::IOContextwith barrier, p2p byte send/recv, broadcast/gather helpers, and coordinated file ops (open/close/fsync/write_at). - Adds
make_tcp_io_context()helper to bootstrap an IO context viac10d::TCPStore. - Updates CMake to build and install
libcommux_io.so.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 14 comments.
| File | Description |
|---|---|
| src/io.cpp | Implements the IOContext IO/collective helpers and TCPStore bootstrap function. |
| include/commux/io.hpp | Declares the IOContext API and make_tcp_io_context() factory. |
| CMakeLists.txt | Adds the commux_io shared library target and installs it into the wheel/lib layout. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+3
to
+6
| #include <c10/util/intrusive_ptr.h> | ||
|
|
||
| #include <cstdint> | ||
| #include <memory> |
Comment on lines
+129
to
+132
| auto size_t = i64_tensor(nbytes); | ||
| std::vector<at::Tensor> size_vec{size_t}; | ||
| pg_->send(size_vec, r, kBroadcastSizeTag)->wait(); | ||
| send_bytes(bytes.data(), bytes.size(), r, kBroadcastDataTag); |
Comment on lines
+135
to
+138
| auto size_t = torch::zeros({1}, torch::kInt64); | ||
| std::vector<at::Tensor> size_vec{size_t}; | ||
| pg_->recv(size_vec, root, kBroadcastSizeTag)->wait(); | ||
| nbytes = tensor_i64(size_t); |
Comment on lines
+158
to
+161
| auto size_t = torch::zeros({1}, torch::kInt64); | ||
| std::vector<at::Tensor> size_vec{size_t}; | ||
| pg_->recv(size_vec, r, kGatherSizeTag)->wait(); | ||
| auto nbytes = tensor_i64(size_t); |
Comment on lines
+173
to
+176
| auto size_t = i64_tensor(static_cast<std::int64_t>(bytes.size())); | ||
| std::vector<at::Tensor> size_vec{size_t}; | ||
| pg_->send(size_vec, root, kGatherSizeTag)->wait(); | ||
| send_bytes(bytes.data(), bytes.size(), root, kGatherDataTag); |
| opts.reduceOp = c10d::ReduceOp::SUM; | ||
| pg_->allreduce(tensors, opts)->wait(); | ||
| if (tensor_i64(status) != 0) | ||
| throw std::runtime_error("commux::IOContext sync_file failed"); |
Comment on lines
+50
to
+54
| void IOContext::send_bytes(const void* data, std::size_t nbytes, int dst, | ||
| int tag) { | ||
| auto t = byte_tensor_from_copy(data, nbytes); | ||
| std::vector<at::Tensor> tensors{t}; | ||
| pg_->send(tensors, dst, tag)->wait(); |
Comment on lines
+57
to
+61
| void IOContext::recv_bytes(void* data, std::size_t nbytes, int src, int tag) { | ||
| auto t = byte_tensor(nbytes); | ||
| std::vector<at::Tensor> tensors{t}; | ||
| pg_->recv(tensors, src, tag)->wait(); | ||
| if (nbytes != 0) std::memcpy(data, t.data_ptr(), nbytes); |
Comment on lines
+120
to
+125
| void IOContext::broadcast_bytes(std::vector<std::uint8_t>& bytes, int root) { | ||
| if (root < 0 || root >= size_) | ||
| throw std::invalid_argument( | ||
| "commux::IOContext broadcast root out of range"); | ||
|
|
||
| std::int64_t nbytes = static_cast<std::int64_t>(bytes.size()); |
Comment on lines
+120
to
+145
| void IOContext::broadcast_bytes(std::vector<std::uint8_t>& bytes, int root) { | ||
| if (root < 0 || root >= size_) | ||
| throw std::invalid_argument( | ||
| "commux::IOContext broadcast root out of range"); | ||
|
|
||
| std::int64_t nbytes = static_cast<std::int64_t>(bytes.size()); | ||
| if (rank_ == root) { | ||
| for (int r = 0; r < size_; ++r) { | ||
| if (r == root) continue; | ||
| auto size_t = i64_tensor(nbytes); | ||
| std::vector<at::Tensor> size_vec{size_t}; | ||
| pg_->send(size_vec, r, kBroadcastSizeTag)->wait(); | ||
| send_bytes(bytes.data(), bytes.size(), r, kBroadcastDataTag); | ||
| } | ||
| } else { | ||
| auto size_t = torch::zeros({1}, torch::kInt64); | ||
| std::vector<at::Tensor> size_vec{size_t}; | ||
| pg_->recv(size_vec, root, kBroadcastSizeTag)->wait(); | ||
| nbytes = tensor_i64(size_t); | ||
| if (nbytes < 0) | ||
| throw std::runtime_error("commux::IOContext negative broadcast size"); | ||
| bytes.resize(static_cast<std::size_t>(nbytes)); | ||
| recv_bytes(bytes.data(), bytes.size(), root, kBroadcastDataTag); | ||
| } | ||
| barrier(); | ||
| } |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
No description provided.