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

Make sure that CUDA instances are destroyed prior to destroying streams #1050

Merged
merged 2 commits into from
Apr 2, 2024

Conversation

aprokop
Copy link
Contributor

@aprokop aprokop commented Apr 1, 2024

Fix #1049. Should fix nightly failures.

@aprokop aprokop added bug Something isn't working testing Anything to do with tests and CI labels Apr 1, 2024
@aprokop aprokop force-pushed the fix_stream_instance_destroy_order branch from 47759bf to 52f352d Compare April 1, 2024 19:55
@aprokop aprokop added examples Anything to do with examples benchmarks labels Apr 1, 2024
@aprokop aprokop force-pushed the fix_stream_instance_destroy_order branch from 52f352d to b19cb1c Compare April 1, 2024 20:03
Copy link
Contributor

@dalg24 dalg24 left a comment

Choose a reason for hiding this comment

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

How was it not failing in the regular CI ?!

Comment on lines 81 to 82
// Place the code using CUDA instance in a block to make sure the instance
// is destroyed prior to destroying the stream.
Copy link
Contributor

Choose a reason for hiding this comment

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

What about

Kokkos::push_finalize_hook([&stream](){ cudaStreamDestroy(stream); });

instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Would it guarantee the destroy order with the instance, though?

Copy link
Contributor

Choose a reason for hiding this comment

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

The instance would get out of scope and destroyed first, then the kokkos execution environment scope guard destructor kicks in, calls Kokkos::finalize which invokes all registered callbacks before releasing resources.

Copy link
Contributor

Choose a reason for hiding this comment

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

That is "yes it would do the right thing".
I prefer that solution but I am not blocking.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Alternatively, you could just move Kokkos::ScopeGuard guard(argc, argv); inside this block so that the stream is created/destroyed before/after Kokkos is initialized/finalized.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think it matters whether the stream is destroyed before/after Kokkos is finalized. As long as the instance is destroyed before, that's the only thing that matters, if I understand it right. So, I would prefer to keep the current code.

Copy link
Contributor

@dalg24 dalg24 Apr 2, 2024

Choose a reason for hiding this comment

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

The change I suggested is more explicit about what needs to happen, hence more readable IMO.

Copy link
Contributor

@dalg24 dalg24 left a comment

Choose a reason for hiding this comment

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

Sorry my suggestion was buggy

examples/access_traits/example_cuda_access_traits.cpp Outdated Show resolved Hide resolved
Co-authored-by: Damien L-G <dalg24@gmail.com>
@aprokop aprokop force-pushed the fix_stream_instance_destroy_order branch from 2cd4715 to d236452 Compare April 2, 2024 15:53
@aprokop
Copy link
Contributor Author

aprokop commented Apr 2, 2024

HIP failed, but this PR does not include #1048.

@aprokop aprokop merged commit a850ae8 into arborx:master Apr 2, 2024
1 of 2 checks passed
@aprokop aprokop deleted the fix_stream_instance_destroy_order branch April 2, 2024 18:07
@aprokop aprokop mentioned this pull request Apr 2, 2024
@aprokop
Copy link
Contributor Author

aprokop commented Apr 3, 2024

This indeed fixed CUDA nightlies.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
benchmarks bug Something isn't working examples Anything to do with examples testing Anything to do with tests and CI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fix nightly tests
3 participants