Allow AM receive callback to control data allocation/copy#479
Allow AM receive callback to control data allocation/copy#479pentschev wants to merge 15 commits intorapidsai:branch-0.46from
Conversation
This reverts commit d9a04ee.
wence-
left a comment
There was a problem hiding this comment.
I think this looks broadly good though I am slightly worried about the reinterpret_cast usage.
| * @param[in] receiverCallbackInfo receiver callback info to execute when request completes, | ||
| * including user header. |
There was a problem hiding this comment.
I don't understand this docstring addition. AFAICT the receiverCallbackInfo is not a function, so how can it be executed?
| : _data(reinterpret_cast<const uint8_t*>(&value), | ||
| reinterpret_cast<const uint8_t*>(&value) + sizeof(T)) |
There was a problem hiding this comment.
This is UB due to aliasing I think, you need to std::memcpy. The compiler will turn it in to the obvious thing.
| reinterpret_cast<const uint8_t*>(&value) + sizeof(T)) | ||
| { | ||
| static_assert(std::is_trivially_copyable_v<T>, "Type must be trivially copyable"); | ||
| static_assert(sizeof(T) > 0, "Type size must be greater than zero"); |
There was a problem hiding this comment.
nit: No C++ type has zero size (using Empty = T[0] for some T is UB)
| * @returns String representation of the data. | ||
| */ | ||
| AmData(void* data, size_t length) : data(data), length(length) {} | ||
| [[nodiscard]] std::string asString() const { return std::string(_data.begin(), _data.end()); } |
There was a problem hiding this comment.
This copies the values, is that what you want or would a std::string_view do?
| throw std::runtime_error("AmUserHeader size mismatch: expected " + std::to_string(sizeof(T)) + | ||
| " bytes, got " + std::to_string(_data.size())); | ||
| } | ||
| return *reinterpret_cast<const T*>(_data.data()); |
There was a problem hiding this comment.
This needs to be std::memcpy as well, I think, due to aliasing issues.
| * This method is used for delayed receive operations where `delayReceive`` was enabled. | ||
| * It takes a user-provided buffer and internally calls `ucp_am_recv_data_nbx`` to receive | ||
| * the AM data that was stored when the message first arrived. Returns a `Request`` object |
There was a problem hiding this comment.
| * This method is used for delayed receive operations where `delayReceive`` was enabled. | |
| * It takes a user-provided buffer and internally calls `ucp_am_recv_data_nbx`` to receive | |
| * the AM data that was stored when the message first arrived. Returns a `Request`` object | |
| * This method is used for delayed receive operations where `delayReceive` was enabled. | |
| * It takes a user-provided buffer and internally calls `ucp_am_recv_data_nbx` to receive | |
| * the AM data that was stored when the message first arrived. Returns a `Request` object |
Start in markdown, finish in rst :)
| /** | ||
| * @brief Receive delayed Active Message data into a user-provided buffer pointer. | ||
| * | ||
| * This method is used for delayed receive operations where `delayReceive`` was enabled. |
There was a problem hiding this comment.
| * This method is used for delayed receive operations where `delayReceive`` was enabled. | |
| * This method is used for delayed receive operations where `delayReceive` was enabled. |
| */ | ||
| class AmUserHeader { | ||
| private: | ||
| std::vector<uint8_t> _data; |
There was a problem hiding this comment.
suggestion: use std::byte (these aren't characters...).
Also, do you need this to be a resizeable thing, or is it sufficient for this object to manage a std::byte *?
WIP