typedefs.h
1 
5 #pragma once
6 
7 #include <atomic>
8 #include <cstddef>
9 #include <cstring>
10 #include <functional>
11 #include <limits>
12 #include <memory>
13 #include <optional>
14 #include <stdexcept>
15 #include <string>
16 #include <string_view>
17 #include <unordered_map>
18 #include <vector>
19 
20 #include <ucp/api/ucp.h>
21 
22 namespace ucxx {
23 
24 class Buffer;
25 class Request;
26 class RequestAm;
27 
35 typedef enum {
36  UCXX_LOG_LEVEL_FATAL, /* Immediate termination */
37  UCXX_LOG_LEVEL_ERROR, /* Error is returned to the user */
38  UCXX_LOG_LEVEL_WARN, /* Something's wrong, but we continue */
39  UCXX_LOG_LEVEL_DIAG, /* Diagnostics, silent adjustments or internal error handling */
40  UCXX_LOG_LEVEL_INFO, /* Information */
41  UCXX_LOG_LEVEL_DEBUG, /* Low-volume debugging */
42  UCXX_LOG_LEVEL_TRACE, /* High-volume debugging */
43  UCXX_LOG_LEVEL_TRACE_REQ, /* Every send/receive request */
44  UCXX_LOG_LEVEL_TRACE_DATA, /* Data sent/received on the transport */
45  UCXX_LOG_LEVEL_TRACE_ASYNC, /* Asynchronous progress engine */
46  UCXX_LOG_LEVEL_TRACE_FUNC, /* Function calls */
47  UCXX_LOG_LEVEL_TRACE_POLL, /* Polling functions */
48  UCXX_LOG_LEVEL_LAST, /* Last level barrier, not an actual level */
49  UCXX_LOG_LEVEL_PRINT /* Temporary output */
51 
57 enum class TransferDirection { Send = 0, Receive };
58 
65 enum Tag : ucp_tag_t {};
66 
73 enum TagMask : ucp_tag_t {};
74 
80 static constexpr TagMask TagMaskFull{std::numeric_limits<std::underlying_type_t<TagMask>>::max()};
81 
88 typedef std::unordered_map<std::string, std::string> ConfigMap;
89 
96 typedef std::function<void(ucs_status_t, std::shared_ptr<void>)> RequestCallbackUserFunction;
97 
104 typedef std::shared_ptr<void> RequestCallbackUserData;
105 
113 
121 
128 typedef std::function<std::shared_ptr<Buffer>(size_t)> AmAllocatorType;
129 
137 typedef std::function<void(std::shared_ptr<Request>, ucp_ep_h)> AmReceiverCallbackType;
138 
146 typedef std::string AmReceiverCallbackOwnerType;
147 
153 typedef uint64_t AmReceiverCallbackIdType;
154 
161  public:
164 
165  AmReceiverCallbackInfo() = delete;
166 
174 };
175 
183  FallbackToHost = 0,
185 };
186 
193 struct AmSendParams {
194  uint32_t flags{UCP_AM_SEND_FLAG_REPLY};
195  ucp_datatype_t datatype{ucp_dt_make_contig(1)};
196  ucs_memory_type_t memoryType{UCS_MEMORY_TYPE_HOST};
199  std::optional<AmReceiverCallbackInfo> receiverCallbackInfo{
200  std::nullopt};
201  std::vector<std::byte> userHeader{};
210 
217  void setUserHeader(const void* data, size_t size)
218  {
219  if (size > 0 && data == nullptr)
220  throw std::invalid_argument(
221  "AmSendParams::setUserHeader received null data with non-zero size");
222  userHeader.resize(size);
223  if (size > 0) memcpy(userHeader.data(), data, size);
224  }
225 
231  void setUserHeader(std::string_view data) { setUserHeader(data.data(), data.size()); }
232 };
233 
240 typedef const std::string SerializedRemoteKey;
241 
242 } // namespace ucxx
Information of an Active Message receiver callback.
Definition: typedefs.h:160
AmReceiverCallbackOwnerType owner
The owner name of the callback.
Definition: typedefs.h:162
AmReceiverCallbackInfo(const AmReceiverCallbackOwnerType owner, AmReceiverCallbackIdType id)
Construct an AmReceiverCallbackInfo object.
AmReceiverCallbackIdType id
The unique identifier of the callback.
Definition: typedefs.h:163
Definition: address.h:15
std::function< void(ucs_status_t, std::shared_ptr< void >)> RequestCallbackUserFunction
A user-defined function to execute as part of a ucxx::Request callback.
Definition: typedefs.h:96
std::shared_ptr< void > RequestCallbackUserData
Data for the user-defined function provided to the ucxx::Request callback.
Definition: typedefs.h:104
std::unordered_map< std::string, std::string > ConfigMap
A UCP configuration map.
Definition: typedefs.h:88
RequestCallbackUserData EndpointCloseCallbackUserData
Data for the user-defined function provided to endpoint close callback.
Definition: typedefs.h:120
TransferDirection
The direction of a UCXX transfer.
Definition: typedefs.h:57
std::function< std::shared_ptr< Buffer >size_t)> AmAllocatorType
Custom Active Message allocator type.
Definition: typedefs.h:128
AmSendMemoryTypePolicy
Policy used to allocate receive buffers for Active Messages.
Definition: typedefs.h:182
@ FallbackToHost
If no allocator exists for memory type, fallback to host memory.
@ ErrorOnUnsupported
If no allocator exists for memory type, fail with unsupported error.
const std::string SerializedRemoteKey
Serialized form of a remote key.
Definition: typedefs.h:240
ucxx_log_level_t
Available logging levels.
Definition: typedefs.h:35
uint64_t AmReceiverCallbackIdType
Active Message receiver callback identifier.
Definition: typedefs.h:153
RequestCallbackUserFunction EndpointCloseCallbackUserFunction
A user-defined function to execute after an endpoint closes.
Definition: typedefs.h:112
std::string AmReceiverCallbackOwnerType
Active Message receiver callback owner name.
Definition: typedefs.h:146
TagMask
Strong type for a UCP tag mask.
Definition: typedefs.h:73
Tag
Strong type for a UCP tag.
Definition: typedefs.h:65
std::function< void(std::shared_ptr< Request >, ucp_ep_h)> AmReceiverCallbackType
Active Message receiver callback.
Definition: typedefs.h:137
Parameters controlling Active Message send behavior.
Definition: typedefs.h:193
std::optional< AmReceiverCallbackInfo > receiverCallbackInfo
Optional receiver callback metadata.
Definition: typedefs.h:199
ucp_datatype_t datatype
Datatype used by ucp_am_send_nbx.
Definition: typedefs.h:195
AmSendMemoryTypePolicy memoryTypePolicy
Receiver allocation policy.
Definition: typedefs.h:197
void setUserHeader(std::string_view data)
Convenience overload to set user header from string-like views.
Definition: typedefs.h:231
std::vector< std::byte > userHeader
Definition: typedefs.h:201
void setUserHeader(const void *data, size_t size)
Set opaque user header bytes from raw pointer.
Definition: typedefs.h:217
ucs_memory_type_t memoryType
Sender memory type hint.
Definition: typedefs.h:196
uint32_t flags
UCP AM send flags.
Definition: typedefs.h:194