17#include <ucp/api/ucp.h>
19#include <ucxx/address_builder.h>
20#include <ucxx/buffer.h>
21#include <ucxx/component.h>
22#include <ucxx/context.h>
23#include <ucxx/delayed_submission.h>
24#include <ucxx/endpoint_builder.h>
25#include <ucxx/future.h>
26#include <ucxx/inflight_requests.h>
27#include <ucxx/listener_builder.h>
28#include <ucxx/notifier.h>
29#include <ucxx/request_flush_builder.h>
30#include <ucxx/request_tag_builder.h>
31#include <ucxx/typedefs.h>
32#include <ucxx/worker_builder.h>
33#include <ucxx/worker_progress_thread.h>
43void registerInflightRequest(std::shared_ptr<Component> component, std::shared_ptr<Request> req);
64 ucp_worker_h _handle{
nullptr};
65 int _epollFileDescriptor{-1};
66 int _workerFileDescriptor{-1};
67 std::mutex _inflightRequestsMutex{};
68 std::unique_ptr<InflightRequests> _inflightRequests{
69 std::make_unique<InflightRequests>()};
71 _inflightRequestsToCancelMutex{};
72 std::unique_ptr<InflightRequests> _inflightRequestsToCancel{
73 std::make_unique<InflightRequests>()};
75 std::atomic<bool> _progressThreadRunning{
false};
76 std::atomic<bool> _progressThreadPollingMode{
false};
77 std::atomic<std::thread::id> _progressThreadId{std::thread::id()};
78 std::function<void(
void*)> _progressThreadStartCallback{
80 void* _progressThreadStartCallbackArg{
82 std::shared_ptr<DelayedSubmissionCollection> _delayedSubmissionCollection{
85 friend class detail::ConstructorFactory;
93 std::queue<std::shared_ptr<Future>>
96 std::shared_ptr<internal::AmData>
107 void drainWorkerTagRecv();
123 [[nodiscard]] std::shared_ptr<RequestAm> getAmRecv(
124 ucp_ep_h ep, std::function<std::shared_ptr<RequestAm>()> createAmRecvRequestFunction);
132 void stopProgressThreadNoWarn();
144 [[nodiscard]] std::shared_ptr<Request> registerInflightRequest(std::shared_ptr<Request> request);
153 bool progressPending();
166 void setCudaBufferType(
BufferType bufferType);
189 explicit Worker(std::shared_ptr<Context> context,
190 const bool enableDelayedSubmission =
false,
191 const bool enableFuture =
false);
208 friend void detail::registerInflightRequest(std::shared_ptr<Component> component,
209 std::shared_ptr<Request> req);
470 uint64_t period = 0);
499 uint64_t period = 0);
763 const
TagMask tagMask = TagMaskFull,
764 const
bool remove = false) const;
862 ucp_listener_conn_callback_t callback,
951 [[nodiscard]]
bool amProbe(const ucp_ep_h endpointHandle) const;
Builder class for constructing std::shared_ptr<ucxx::Address> objects.
Definition address_builder.h:23
Component encapsulating the address of a UCP worker.
Definition address.h:26
Information of an Active Message receiver callback.
Definition typedefs.h:224
A simple object to simplify managing buffers.
Definition buffer.h:31
A UCXX component class to prevent early destruction of parent object.
Definition component.h:21
Builder class for constructing std::shared_ptr<ucxx::Endpoint> objects.
Definition endpoint_builder.h:28
Component encapsulating a UCP endpoint.
Definition endpoint.h:69
Represent a future that may be notified by a specialized notifier.
Definition future.h:21
Builder class for constructing std::shared_ptr<ucxx::Listener> objects.
Definition listener_builder.h:26
Component encapsulating a UCP listener.
Definition listener.h:26
Send or receive a message with the UCX Active Message API.
Definition request_am.h:33
Builder class for constructing std::shared_ptr<ucxx::RequestFlush> objects.
Definition request_flush_builder.h:39
Builder class for constructing std::shared_ptr<ucxx::RequestTag> objects.
Definition request_tag_builder.h:40
Base type for a UCXX transfer request.
Definition request.h:39
Information about probed tag message.
Definition tag_probe.h:65
Builder class for constructing std::shared_ptr<ucxx::Worker> objects.
Definition worker_builder.h:45
A thread to progress a ucxx::Worker.
Definition worker_progress_thread.h:50
bool amProbe(const ucp_ep_h endpointHandle) const
Check for uncaught active messages.
int getEpollFileDescriptor()
Get the epoll file descriptor associated with the worker.
bool progress()
Progress the worker until all communication events are completed.
void registerAmReceiverCallback(AmReceiverCallbackInfo info, AmReceiverCallbackType callback)
Register receiver callback for active messages.
ListenerBuilder listenerBuilder(uint16_t port, ucp_listener_conn_callback_t callback, void *callbackArgs)
Create a builder for a listener on this worker.
AddressBuilder addressBuilder()
Create a builder for this worker's address.
bool isRequestAttributesEnabled() const noexcept
Inquire if worker has been created with request attributes querying enabled.
bool _enableRequestAttributes
Whether request attributes (e.g. UCP debug info) are queried for each request.
Definition worker.h:90
void signal()
Signal the worker that an event happened.
virtual void populateFuturesPool()
Populate the futures pool.
bool registerGenericPre(DelayedSubmissionCallbackType callback, uint64_t period=0)
Register callback to be executed in progress thread before progressing.
std::shared_ptr< TagProbeInfo > tagProbe(const Tag tag, const TagMask tagMask=TagMaskFull, const bool remove=false) const
Check for uncaught tag messages.
void setProgressThreadStartCallback(std::function< void(void *)> callback, void *callbackArg)
Set callback to be executed at the progress thread start.
bool progressOnce()
Progress the worker only once.
void startProgressThread(const bool pollingMode=false, const int epollTimeout=1)
Start the progress thread.
bool isProgressThreadRunning()
Inquire if worker has a progress thread running.
RequestTagBuilder tagRecvWithHandleBuilder(void *buffer, std::shared_ptr< TagProbeInfo > probeInfo)
Create a builder for a tag receive operation using a message handle.
friend class WorkerBuilder
Allow WorkerBuilder to access protected/private constructor.
Definition worker.h:203
void registerAmAllocator(ucs_memory_type_t memoryType, AmAllocatorType allocator)
Register allocator for active messages.
void stopProgressThread()
Stop the progress thread.
Worker(std::shared_ptr< Context > context, const bool enableDelayedSubmission=false, const bool enableFuture=false)
Protected constructor of ucxx::Worker.
virtual std::shared_ptr< Future > getFuture()
Get a future from the pool.
std::queue< std::shared_ptr< Future > > _futuresPool
Futures pool to prevent running out of fresh futures.
Definition worker.h:94
EndpointBuilder endpointBuilder(std::string ipAddress, uint16_t port)
Create a builder for an endpoint to a worker listening on an IP and port.
BufferType _cudaBufferType
Preferred buffer type for CUDA allocations.
Definition worker.h:98
bool isDelayedRequestSubmissionEnabled() const
Inquire if worker has been created with delayed submission enabled.
virtual ~Worker()
ucxx::Worker destructor.
virtual void clearFuturesPool()
Clear the futures pool.
ucp_worker_h getHandle()
Get the underlying ucp_worker_h handle.
std::mutex _futuresPoolMutex
Mutex to access the futures pool.
Definition worker.h:92
virtual RequestNotifierWaitState waitRequestNotifier(uint64_t periodNs)
Block until a request event.
bool arm()
Arm the UCP worker.
bool waitProgress()
Block until an event has happened, then progresses.
virtual void runRequestNotifier()
Notify futures of each completed communication request.
bool registerGenericPost(DelayedSubmissionCallbackType callback, uint64_t period=0)
Register callback to be executed in progress thread before progressing.
std::shared_ptr< Notifier > _notifier
Notifier object.
Definition worker.h:95
RequestTagBuilder tagRecvBuilder(void *buffer, size_t length, Tag tag, TagMask tagMask)
Create a builder for a tag receive operation.
void registerDelayedSubmission(std::shared_ptr< Request > request, DelayedSubmissionCallbackType callback)
Register delayed request submission.
std::thread::id getProgressThreadId()
Get the progress thread ID.
size_t cancelInflightRequests(uint64_t period=0, uint64_t maxAttempts=1)
Cancel inflight requests.
bool _enableFuture
Boolean identifying whether the worker was created with future capability.
Definition worker.h:88
bool isFutureEnabled() const
Inquire if worker has been created with future support.
RequestFlushBuilder flushBuilder()
Create a builder for a flush operation.
Attributes queryAttributes() const
Get the worker's attributes.
virtual void stopRequestNotifierThread()
Signal the notifier to terminate.
void removeInflightRequest(std::shared_ptr< Request > request)
Remove reference to request from internal container.
bool progressWorkerEvent(const int epollTimeout=-1)
Progress worker event while in blocking progress mode.
BufferType getCudaBufferType() const
Get the preferred buffer type for CUDA allocations.
std::shared_ptr< internal::AmData > _amData
Worker data made available to Active Messages callback.
Definition worker.h:97
void scheduleRequestCancel(TrackedRequests trackedRequests)
Schedule cancelation of inflight requests.
void initBlockingProgressMode()
Initialize blocking progress mode.
std::string getInfo()
Get information about the underlying ucp_worker_h object.
Active Message data owned by a ucxx::Worker.
Definition request_am.h:102
std::function< void()> DelayedSubmissionCallbackType
A user-defined function to execute as part of delayed submission callback.
Definition delayed_submission.h:32
std::function< std::shared_ptr< Buffer >(size_t)> AmAllocatorType
Custom Active Message allocator type.
Definition typedefs.h:129
RequestNotifierWaitState
The state with which a wait operation completed.
Definition notifier.h:26
TagMask
Strong type for a UCP tag mask.
Definition typedefs.h:74
Tag
Strong type for a UCP tag.
Definition typedefs.h:66
std::function< void(std::shared_ptr< Request >, ucp_ep_h)> AmReceiverCallbackType
Active Message receiver callback.
Definition typedefs.h:138
BufferType
The type of a buffer.
Definition buffer.h:17
Container for transferring tracked requests between InflightRequests instances.
Definition inflight_requests.h:23
Worker attributes reported by ucp_worker_query.
Definition worker.h:966
size_t maxDebugString
Maximum debug-string buffer size accepted by ucp_request_query.
Definition worker.h:974
std::string name
Worker name used by tracing and analysis tools.
Definition worker.h:972
size_t maxAmHeader
Maximum allowed header size for ucp_am_send_nbx.
Definition worker.h:970
ucs_thread_mode_t threadMode
Thread safety level the worker was created with.
Definition worker.h:968