Skip to content
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

Merged
merged 10 commits into from
Sep 21, 2023

Conversation

madsbk
Copy link
Member

@madsbk madsbk commented Sep 4, 2023

Implements a version of read_async and write_async that takes by-value arguments and returns a StreamFuture.

This is to make the common case easy where the user knows the file and buffer size.

cc. @tell-rebanta

@madsbk madsbk added improvement Improves an existing functionality non-breaking Introduces a non-breaking change labels Sep 4, 2023
@madsbk madsbk marked this pull request as ready for review September 4, 2023 13:46
@madsbk madsbk requested a review from a team as a code owner September 4, 2023 13:46
@madsbk madsbk requested a review from tell-rebanta September 11, 2023 07:01
Copy link
Contributor

@wence- wence- left a 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).

* `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!
Copy link
Contributor

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?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, done

Comment on lines 52 to 63
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;
};
Copy link
Contributor

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?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

Comment on lines 68 to 69
ArgByVal* _val{nullptr};
ArgByRef _ref{nullptr};
Copy link
Contributor

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?

Copy link
Member Author

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

@madsbk madsbk requested a review from wence- September 13, 2023 08:16
@madsbk
Copy link
Member Author

madsbk commented Sep 21, 2023

@wence- I think I have addressed all your comments.

Copy link
Contributor

@wence- wence- left a 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

@wence-
Copy link
Contributor

wence- commented Sep 21, 2023

/merge

@rapids-bot rapids-bot bot merged commit 71c2858 into rapidsai:branch-23.10 Sep 21, 2023
@madsbk madsbk deleted the async_future branch September 21, 2023 11:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
improvement Improves an existing functionality non-breaking Introduces a non-breaking change
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants