single.hpp
1 
5 #pragma once
6 
7 #include <cstdlib>
8 #include <memory>
9 #include <string>
10 #include <unordered_map>
11 #include <vector>
12 
13 #include <rapidsmpf/buffer/buffer.hpp>
14 #include <rapidsmpf/buffer/resource.hpp>
15 #include <rapidsmpf/communicator/communicator.hpp>
16 #include <rapidsmpf/config.hpp>
17 
18 namespace rapidsmpf {
19 
27 class Single final : public Communicator {
28  public:
35  class Future : public Communicator::Future {
36  friend class Single;
37 
38  public:
39  ~Future() noexcept override = default;
40  };
41 
48 
49  ~Single() noexcept override = default;
50 
54  [[nodiscard]] constexpr Rank rank() const override {
55  return 0;
56  }
57 
61  [[nodiscard]] constexpr Rank nranks() const override {
62  return 1;
63  }
64 
68  [[nodiscard]] std::unique_ptr<Communicator::Future> send(
69  std::unique_ptr<std::vector<uint8_t>> msg, Rank rank, Tag tag
70  ) override;
71 
72  // clang-format off
78  // clang-format on
79  [[nodiscard]] std::unique_ptr<Communicator::Future> send(
80  std::unique_ptr<Buffer> msg, Rank rank, Tag tag
81  ) override;
82 
89  [[nodiscard]] std::unique_ptr<Communicator::Future> recv(
90  Rank rank, Tag tag, std::unique_ptr<Buffer> recv_buffer
91  ) override;
92 
93  // clang-format off
100  // clang-format on
101  [[nodiscard]] std::unique_ptr<Communicator::Future> recv_sync_host_data(
102  Rank rank, Tag tag, std::unique_ptr<std::vector<uint8_t>> synced_buffer
103  ) override;
104 
111  [[nodiscard]] std::pair<std::unique_ptr<std::vector<uint8_t>>, Rank> recv_any(
112  Tag tag
113  ) override;
114 
121  [[nodiscard]] std::unique_ptr<std::vector<uint8_t>> recv_from(
122  Rank src, Tag tag
123  ) override;
124 
131  std::pair<
132  std::vector<std::unique_ptr<Communicator::Future>>,
133  std::vector<std::size_t>>
134  test_some(std::vector<std::unique_ptr<Communicator::Future>>& future_vector) override;
135 
136  // clang-format off
142  // clang-format on
143  std::vector<std::size_t> test_some(
144  std::unordered_map<std::size_t, std::unique_ptr<Communicator::Future>> const&
145  future_map
146  ) override;
147 
154  [[nodiscard]] std::unique_ptr<Buffer> wait(
155  std::unique_ptr<Communicator::Future> future
156  ) override;
157 
164  [[nodiscard]] std::unique_ptr<Buffer> release_data(
165  std::unique_ptr<Communicator::Future> future
166  ) override;
167 
174  [[nodiscard]] std::unique_ptr<std::vector<uint8_t>> release_sync_host_data(
175  std::unique_ptr<Communicator::Future> future
176  ) override;
177 
181  [[nodiscard]] Logger& logger() override {
182  return logger_;
183  }
184 
188  [[nodiscard]] std::string str() const override;
189 
190  private:
191  Logger logger_;
192 };
193 
194 
195 } // namespace rapidsmpf
Abstract base class for asynchronous operation within the communicator.
A logger base class for handling different levels of log messages.
Abstract base class for a communication mechanism between nodes.
Represents the future result of an operation.
Definition: single.hpp:35
Single process communicator class that implements the Communicator interface.
Definition: single.hpp:27
std::string str() const override
Provides a string representation of the communicator.
Single(config::Options options)
Construct a single process communicator.
constexpr Rank rank() const override
Retrieves the rank of the current node.
Definition: single.hpp:54
std::unique_ptr< Communicator::Future > recv(Rank rank, Tag tag, std::unique_ptr< Buffer > recv_buffer) override
Receives a message from a specific rank to a buffer. Use release_data to extract the data out of the ...
std::unique_ptr< std::vector< uint8_t > > release_sync_host_data(std::unique_ptr< Communicator::Future > future) override
Retrieves synchronized host data associated with a completed future. When the future is completed,...
constexpr Rank nranks() const override
Retrieves the total number of ranks.
Definition: single.hpp:61
std::pair< std::vector< std::unique_ptr< Communicator::Future > >, std::vector< std::size_t > > test_some(std::vector< std::unique_ptr< Communicator::Future >> &future_vector) override
Tests for completion of multiple futures.
std::unique_ptr< Communicator::Future > recv_sync_host_data(Rank rank, Tag tag, std::unique_ptr< std::vector< uint8_t >> synced_buffer) override
Receives a message from a specific rank to an allocated (synchronized) host buffer....
std::unique_ptr< Buffer > wait(std::unique_ptr< Communicator::Future > future) override
Wait for a future to complete and return the data buffer.
std::vector< std::size_t > test_some(std::unordered_map< std::size_t, std::unique_ptr< Communicator::Future >> const &future_map) override
Tests for completion of multiple futures in a map.
std::unique_ptr< Buffer > release_data(std::unique_ptr< Communicator::Future > future) override
Retrieves data associated with a completed future.
std::unique_ptr< Communicator::Future > send(std::unique_ptr< Buffer > msg, Rank rank, Tag tag) override
Sends a message (device or host) to a specific rank.
std::unique_ptr< Communicator::Future > send(std::unique_ptr< std::vector< uint8_t >> msg, Rank rank, Tag tag) override
Sends a host message to a specific rank.
std::pair< std::unique_ptr< std::vector< uint8_t > >, Rank > recv_any(Tag tag) override
Receives a message from any rank (blocking).
Logger & logger() override
Retrieves the logger associated with this communicator.
Definition: single.hpp:181
std::unique_ptr< std::vector< uint8_t > > recv_from(Rank src, Tag tag) override
Receives a message from a specific rank (blocking).
A tag used for identifying messages in a communication operation.
Manages configuration options for RapidsMPF operations.
Definition: config.hpp:124