Active Message Request#
2026-03-31
6 min read time
The ucxx::RequestAm class implements non-blocking active message (AM) send and
receive operations. Active messages allow user-defined callbacks to be invoked on the
receiver side when a message arrives, enabling RPC-style communication patterns.
#include <ucxx/request_am.h>
namespace ucxx
-
class RequestAm : public ucxx::Request#
Send or receive a message with the UCX Active Message API.
Send or receive a message with the UCX Active Message API, using non-blocking UCP calls
ucp_am_send_nbxorucp_am_recv_data_nbx.Public Functions
- virtual void cancel(
Cancel the request.
Cancel the request. Often called by the error handler or parent’s object destructor but may be called by the user to cancel the request as well.
- virtual void populateDelayedSubmission(
Populate the internal submission dispatcher.
The
ucxx::Requestutilizesucxx::DelayedSubmissionto manage when the request will be dispatched. This method is registered as a callback in the worker, that may choose to either execute (submit) it immediately or delay for the next iteration of its progress loop, depending on the progress mode in use by the worker.See
ucxx::DelayedSubmission::DelayedSubmission()for more details.
- void request(
Create and submit an active message send request.
This is the method that should be called to actually submit an active message send request. It is meant to be called from
populateDelayedSubmission(), which is decided at the discretion ofstd::shared_ptr<ucxx::Worker>. SeepopulateDelayedSubmission()for more details.
- virtual std::shared_ptr<Buffer> getRecvBuffer(
Get the received buffer.
This method is used to get the received buffer for applicable derived classes (e.g.,
RequestAmreceive operations), in all other cases this will returnnullptr. Before getting the received buffer it’s necessary to check that the request completed successfully either by validatinggetStatus() == UCS_OKor by checking the request completed withisCompleted() == trueand that it did not error withcheckError(), if any of those is unsuccessful this call returnsnullptr.- Returns:
The received buffer (if applicable) or
nullptr.
Public Static Functions
- static ucs_status_t recvCallback(
- void *arg,
- const void *header,
- size_t header_length,
- void *data,
- size_t length,
- const ucp_am_recv_param_t *param
Receive callback registered by
ucxx::Worker.This is the receive callback registered by the
ucxx::Workerto handle incoming active messages. For each incoming active message, a proper buffer will be allocated based on the header sent by the remote endpoint using the default allocator or one registered by the user viaucxx::Worker::registerAmAllocator(). Following that, the message is immediately received onto the buffer and aUCS_OKor the proper error status is set onto theRequestAmthat is returned to the user, or will be later handled by another callback when the message is ready. If the callback is executed when a user has already requested received of the active message, the buffer and status will be set on the earliest request, otherwise a new request is created and saved in a pool that will be already populated and ready for consumption or waiting for the internal callback when requested.This is always called by
ucp_worker_progress(), and thus will happen in the same thread that is called from, when using the worker progress thread, this is called from the progress thread.param[in,out] arg pointer to the
AmDataobject held by theucxx::Workerwho registered this callback. param[in] header pointer to the header containing the sender buffer’s memory type. param[in] header_length length in bytes of the receive header. param[in] data pointer to the buffer containing the remote endpoint’s send data. param[in] length the length in bytes of the message to be received. param[in] param UCP parameters of the active message being received.
Friends
- std::shared_ptr<Endpoint> endpoint,
- const std::variant<data::AmSend, data::AmReceive> requestData,
- const bool enablePythonFuture,
- RequestCallbackUserFunction callbackFunction,
- RequestCallbackUserData callbackData
Constructor for
std::shared_ptr<ucxx::RequestAm>.The constructor for a
std::shared_ptr<ucxx::RequestAm>object, creating an active message request, returning a pointer to a request object that can be later awaited and checked for errors. This is a non-blocking operation, and the status of the transfer must be verified from the resulting request object before the data can be released if this is a send operation, or consumed if this is a receive operation. Received data is available via thegetRecvBuffer()method if the receive transfer request completed successfully.Note
If a
callbackFunctionis specified, the lifetime ofcallbackDataand of any other objects used in the scope ofcallbackFunctionmust be guaranteed by the caller until it executes orisCompleted()becomes true. ThecallbackFunctionexecutes in the thread progressing theucxx::Worker, unless the request completes immediately, in which case the callback will also execute immediately within the calling thread and before the method returns.- Throws:
ucxx::Error – if
endpointis not a validstd::shared_ptr<ucxx::Endpoint>.- Parameters:
endpoint – [in] the parent endpoint.
requestData – [in] container of the specified message type, including all type-specific data.
enablePythonFuture – [in] whether a python future should be created and subsequently notified.
callbackFunction – [in] user-defined callback function to call upon completion.
callbackData – [in] user-defined data to pass to the
callbackFunction.
- Returns:
The
shared_ptr<ucxx::RequestAm>object
Factory Functions#
#include <ucxx/constructors.h>
- std::shared_ptr<Endpoint> endpoint,
- const std::variant<data::AmSend, data::AmReceive> requestData,
- const bool enablePythonFuture,
- RequestCallbackUserFunction callbackFunction,
- RequestCallbackUserData callbackData
The constructor for a
std::shared_ptr<ucxx::RequestAm>object, creating an active message request, returning a pointer to a request object that can be later awaited and checked for errors. This is a non-blocking operation, and the status of the transfer must be verified from the resulting request object before the data can be released if this is a send operation, or consumed if this is a receive operation. Received data is available via thegetRecvBuffer()method if the receive transfer request completed successfully.Note
If a
callbackFunctionis specified, the lifetime ofcallbackDataand of any other objects used in the scope ofcallbackFunctionmust be guaranteed by the caller until it executes orisCompleted()becomes true. ThecallbackFunctionexecutes in the thread progressing theucxx::Worker, unless the request completes immediately, in which case the callback will also execute immediately within the calling thread and before the method returns.- Throws:
ucxx::Error – if
endpointis not a validstd::shared_ptr<ucxx::Endpoint>.- Parameters:
endpoint – [in] the parent endpoint.
requestData – [in] container of the specified message type, including all type-specific data.
enablePythonFuture – [in] whether a python future should be created and subsequently notified.
callbackFunction – [in] user-defined callback function to call upon completion.
callbackData – [in] user-defined data to pass to the
callbackFunction.
- Returns:
The
shared_ptr<ucxx::RequestAm>object