-
Notifications
You must be signed in to change notification settings - Fork 67
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Async I/O using by-value arguments #275
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @madsbk, wondering if we can simplify things a little, and make the interface slightly safer to use (and avoid use-after-free footguns one normally has with raw pointers).
cpp/include/kvikio/stream.hpp
Outdated
* `write_async` can call `.get_args()` to get the by-reference arguments required by cuFile's | ||
* stream API. However, this also means that the caller of `read_async` and `write_async` MUST keep | ||
* the returned `StreamFuture` alive until the operations is done otherwise `StreamFuture` will free | ||
* `ArgByVal` before cuFile had a change to use them! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 suggestion: Could we make this safer by having ~StreamFuture
sync the stored stream?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, done
cpp/include/kvikio/stream.hpp
Outdated
struct ArgByVal { | ||
std::size_t size; | ||
off_t file_offset; | ||
off_t devPtr_offset; | ||
ssize_t bytes_done; | ||
}; | ||
struct ArgByRef { | ||
std::size_t* size_p; | ||
off_t* file_offset_p; | ||
off_t* devPtr_offset_p; | ||
ssize_t* bytes_done_p; | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❓ question: Since these are not exposed to the outside world (I think/hope), should they rather be private
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
cpp/include/kvikio/stream.hpp
Outdated
ArgByVal* _val{nullptr}; | ||
ArgByRef _ref{nullptr}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❓ question: Do we actually need both of these stored in the class, does it suffice instead to do something like:
class StreamFuture {
private:
struct data {
std::size_t size;
off_t file_offset;
off_t devptr_offset;
ssize_t bytes_done;
}
data* _values{};
public:
StreamFuture(...args)
{
_values = static_cast<data *>(...);
_values->size = size;
_values->...;
}
std::tuple<...> get_args() {
return {&_values->size, &_values->file_offset, ...};
}
}
Or is there some subtlety I am missing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, my initially idea was to support mixing of by-value and by-ref arguments, which would use ArgByRef
to tell which arguments were which. Fixed
@wence- I think I have addressed all your comments. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @madsbk, apologies for the delay
…o async_future
Co-authored-by: Lawrence Mitchell <[email protected]>
/merge |
Implements a version of
read_async
andwrite_async
that takes by-value arguments and returns aStreamFuture
.This is to make the common case easy where the user knows the file and buffer size.
cc. @tell-rebanta