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

Fix thread-safety for the Serial backend #7080

Merged
merged 3 commits into from
Jun 20, 2024

Conversation

masterleinad
Copy link
Contributor

Splits the changes for the Serial backend from #6151.
This pull request ensures that kernels submitted to the same execution space instance from multiple threads don't run concurrently.

core/src/Serial/Kokkos_Serial.hpp Outdated Show resolved Hide resolved
core/src/Serial/Kokkos_Serial.cpp Outdated Show resolved Hide resolved
Co-authored-by: Nevin ":-)" Liber <nliber+github@gmail.com>
@masterleinad masterleinad requested a review from nliber June 19, 2024 18:06
if (it == all_instances.end())
Kokkos::abort(
"Execution space instance to be removed couldn't be found!");
std::swap(*it, all_instances.back());
Copy link
Contributor

Choose a reason for hiding this comment

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

Giving it more thought: you don't even need swap, as assignment will do:

Suggested change
std::swap(*it, all_instances.back());
*it = all_instances.back();

Sorry about that. The usual reason to prefer swap is when it is non-throwing, but pointer assignment doesn't throw either.

@@ -147,7 +170,9 @@ Serial::Serial(NewInstance)
: m_space_instance(new Impl::SerialInternal, [](Impl::SerialInternal* ptr) {
ptr->finalize();
delete ptr;
}) {}
}) {
m_space_instance->initialize();
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it necessary to initialize this explicitly here? Is this space not initialized along with other spaces during Kokkos::initialize() (by Kokkos::initialize_backends())?

Copy link
Member

@dalg24 dalg24 Jun 20, 2024

Choose a reason for hiding this comment

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

Kokkos::initialize only initializes default instances.

@@ -147,7 +170,9 @@ Serial::Serial(NewInstance)
: m_space_instance(new Impl::SerialInternal, [](Impl::SerialInternal* ptr) {
ptr->finalize();
delete ptr;
}) {}
}) {
m_space_instance->initialize();
Copy link
Member

Choose a reason for hiding this comment

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

So this was an oversight right? It means that the m_is_initialized member was never set to true but that somehow didn't cause an error :/

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right, before this pull request that only affected SerialInternal::is_initialized().

@masterleinad
Copy link
Contributor Author

Only the OpenACC CI fails with

3: [ RUN      ] openacc.mdspan_minimal_functional
3: Failing in Thread:1
3: Accelerator Fatal Error: call to cuStreamSynchronize returned error 700: Illegal address during kernel execution
3:  File: (OpenACC API)
3:  Function: acc_copyout:1
3:  Line: 1
3: 

which we also see in other pull requests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants