remote_key.h
1 
5 #pragma once
6 #include <memory>
7 #include <string>
8 #include <utility>
9 #include <vector>
10 
11 #include <ucp/api/ucp.h>
12 
13 #include <ucxx/component.h>
14 #include <ucxx/endpoint.h>
15 #include <ucxx/memory_handle.h>
16 
17 namespace ucxx {
18 
25 typedef size_t SerializedRemoteKeyHash;
26 
36 class RemoteKey : public Component {
37  private:
38  ucp_rkey_h _remoteKey{nullptr};
39  void* _packedRemoteKey{
40  nullptr};
41  size_t _packedRemoteKeySize{0};
42  std::vector<char> _packedRemoteKeyVector{};
43  uint64_t _memoryBaseAddress{0};
44  size_t _memorySize{0};
45 
61  explicit RemoteKey(std::shared_ptr<MemoryHandle> memoryHandle);
62 
80  RemoteKey(std::shared_ptr<Endpoint> endpoint, SerializedRemoteKey serializedRemoteKey);
81 
97  void deserialize(const SerializedRemoteKey& serializedHeader);
98 
99  public:
121  friend std::shared_ptr<RemoteKey> createRemoteKeyFromMemoryHandle(
122  std::shared_ptr<MemoryHandle> memoryHandle);
123 
149  friend std::shared_ptr<RemoteKey> createRemoteKeyFromSerialized(
150  std::shared_ptr<Endpoint> endpoint, SerializedRemoteKey serializedRemoteKey);
151 
152  ~RemoteKey();
153 
169  [[nodiscard]] ucp_rkey_h getHandle();
170 
184  [[nodiscard]] size_t getSize() const;
185 
200  [[nodiscard]] uint64_t getBaseAddress();
201 
215  [[nodiscard]] SerializedRemoteKey serialize() const;
216 };
217 
218 } // namespace ucxx
A UCXX component class to prevent early destruction of parent object.
Definition: component.h:17
Component holding a UCP rkey (remote key).
Definition: remote_key.h:36
friend std::shared_ptr< RemoteKey > createRemoteKeyFromMemoryHandle(std::shared_ptr< MemoryHandle > memoryHandle)
Constructor for std::shared_ptr<ucxx::RemoteKey> from local memory handle.
ucp_rkey_h getHandle()
Get the underlying ucp_rkey_h handle.
size_t getSize() const
Get the size of the memory allocation.
friend std::shared_ptr< RemoteKey > createRemoteKeyFromSerialized(std::shared_ptr< Endpoint > endpoint, SerializedRemoteKey serializedRemoteKey)
Constructor for std::shared_ptr<ucxx::RemoteKey> from remote.
uint64_t getBaseAddress()
Get the base address of the memory allocation.
SerializedRemoteKey serialize() const
Serialize the remote key.
Definition: address.h:15
const std::string SerializedRemoteKey
Serialized form of a remote key.
Definition: typedefs.h:203
size_t SerializedRemoteKeyHash
Type for hashing serialized remote keys.
Definition: remote_key.h:25