Use primary context in CUDA GPU code. #3432
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This patch changes the CUDA context creation inside LAMMPS to instead use
the "primary" context for the requested device; this then makes LAMMPS
compatible with other libraries that also use CUDA via its runtime API.
It's not a complete fix, in that other libraries that use their own context
via the driver API could still break LAMMPS (e.g. if they switch to their
own context after LAMMPS has initialised its and don't switch it back before
returning), but it at least covers packages that use the CUDA runtime
library.
Unfortunately, to make all driver calls in LAMMPS "context aware" might
require more significant changes to the interfaces as the current context
may not be available at the calls (for example, the
_device_alloc
functionsin
nvd_memory.h
that don't take aUCL_Device
argument).Related Issue(s)
Fixes: #3431
Author(s)
Ben Menadue, National Computational Infrastructure, Australian National University
Licensing
By submitting this pull request, I agree, that my contribution will be included in LAMMPS and redistributed under either the GNU General Public License version 2 (GPL v2) or the GNU Lesser General Public License version 2.1 (LGPL v2.1).
Backward Compatibility
These changes should not have any impact on backwards compatibility.
Implementation Notes
As recommended in the CUDA documentation, switches it to use
cuDevicePrimaryCtxRetain
andcuDevicePrimaryCtxRelease
instead ofcuCtxCreate
andcuCtxDestroy
.Post Submission Checklist