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

Release OpenMP resources in blas_thread_shutdown #4080

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

aitap
Copy link

@aitap aitap commented Jun 10, 2023

OpenMP 5.0 gained an omp_pause_resource_all function designed to release the locks before forking the process. The parameters are described in the omp_pause_resource function. Using this function makes it possible for OpenMP builds of OpenBLAS to pass fork safety tests.

An important detail is that there exist OpenMP implementations that only claim OpenMP 4.5 compatibility (i.e. they #define _OPENMP 201511) while they do have the omp_pause_resource_all. We currently don't have a way to use omp_pause_resource_all with such implementations (e.g. GCC 10 on Debian 11).

The first commit adds the omp_pause_resource_all call to blas_thread_shutdown. You may want not to merge this if you'd like blas_thread_shutdown to be safe to call while other OpenMP operations are in progress.

The second commit adds a convoluted way to test fork safety of the resulting build on OpenMP ≥ 5.0 in addition to non-OpenMP builds. I'd be glad to see a better way of testing for OpenMP ≥ 5.0 in a Makefile.

@martin-frbg
Copy link
Collaborator

Thanks - I have not had time to review in detail, but perhaps it might be better to put the OpenMP version test in the c_check script rather than getarch

OpenMP 5.0 introduced the function omp_pause_resource_all that instructs
the runtime to "relinquish resources used by OpenMP on all devices". In
practice, these resources include the locks that would otherwise trip up
the runtime after a fork(). Releasing these resources in a function
called by pthread_atfork() makes it possible for the child process to
continue functioning after the runtime automatically re-acquires its
resources.

Thread safety: blas_thread_shutdown doesn't check whether there are
other BLAS operations running in parallel, so this isn't any less safe
than before with respect to OpenBLAS function calls. On the other hand,
if there are other OpenMP operations in progress, asking the runtime to
pause may result in unspecified behaviour. A hard pause is allowed to
deallocate threadprivate variables too.
In addition to testing fork safety on non-OpenMP builds, test it on
OpenMP >= 5.0, where we get the ability to release the locks at fork()
time.
@aitap
Copy link
Author

aitap commented Jun 11, 2023 via email

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.

2 participants