Skip to content

Conversation

@ahendriksen
Copy link
Contributor

Take a mutable reference instead.

Moving the token into try_wait makes no sense. The caller has to be able to retry the try_wait with the same token.

For more details and C++ spec, see:

https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2023/p2643r1.html

Take a mutable reference instead.

Moving the token into try_wait makes no sense. The caller has to be able
to retry the try wait with the same token.

For more details and C++ spec, see:

https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2023/p2643r1.html
@ahendriksen ahendriksen requested review from a team as code owners July 28, 2023 07:35
@ahendriksen ahendriksen requested review from ericniebler and griwes and removed request for a team July 28, 2023 07:35
@rapids-bot
Copy link

rapids-bot bot commented Jul 28, 2023

Pull requests from external contributors require approval from a NVIDIA organization member with write permissions or greater before CI can begin.

@ahendriksen
Copy link
Contributor Author

This PR is a redo of NVIDIA/libcudacxx#499

Related issue: #280

Also: I changed the signature of try_wait_for and try_wait_until, but I could not find a signature of try_wait. Is this intentional?

bool try_wait_for(arrival_token & __token, const _CUDA_VSTD::chrono::duration<_Rep, _Period>& __dur) {
auto __nanosec = _CUDA_VSTD::chrono::duration_cast<_CUDA_VSTD::chrono::nanoseconds>(__dur);

return __try_wait(_CUDA_VSTD::move(__token), __nanosec);
Copy link
Contributor

Choose a reason for hiding this comment

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

You are still moving here, is that intentional?

Applies below

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is intentional in the sense that I tried to make as few changes as possible. I did not change the internal APIs from && to &. One thing I had not considered is that arrival_token might actually invalidate the original location on move. Does it?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think this needs to update the internal APIs as well.

@gonzalobg gonzalobg self-requested a review September 7, 2023 11:03
template<class _Rep, class _Period>
_LIBCUDACXX_NODISCARD_ATTRIBUTE _LIBCUDACXX_INLINE_VISIBILITY
bool try_wait_for(arrival_token && __token, const _CUDA_VSTD::chrono::duration<_Rep, _Period>& __dur) {
bool try_wait_for(arrival_token & __token, const _CUDA_VSTD::chrono::duration<_Rep, _Period>& __dur) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we add a test that would have caught this? e.g., a try_wait_for that fails and retries.

Copy link
Collaborator

Choose a reason for hiding this comment

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

The current tests for this are a little janky:

while(b->try_wait_for(cuda::std::move(*tok), delay) == false) {}

It's moving from a moved-from object in a loop.

Copy link
Collaborator

Choose a reason for hiding this comment

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

This may not actually be possible to do without adding some runtime state tracking to track a moved-from token. So it may not be worth it.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Main thing is to just remove the std::move which would catch not needing to pass an r-value ref.

@miscco
Copy link
Contributor

miscco commented Sep 13, 2023

/ok to test

Copy link
Contributor

@miscco miscco left a comment

Choose a reason for hiding this comment

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

This needs to update the internal APIs we should not require arrival_token to be a trivial type

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

4 participants