Draft
Conversation
fixed const Kokkos view to eigen map
updated CCSMIceAlbedo removed obsolete code restored old interface of FiniteElementSpecHum
streamlined DeviceModelArray
restricted num threads to speed up ThermoIntegration test
Reworked the model core and physics to use Kokkos for all expensive computations.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Full GPU support
related Issues: #671, #672
Remaining Issues
Reviewers: Since there is a lot of code to cover, it probably does not hurt to have a look already.
Change Description
Ported all major parts of neXtSIM-DG to Kokkos, enabling fast execution on a GPU. This involves major changes to the dynamics and physics (thermodynamics) but also the core infrastructure related to data exchange between
ModelComponents.Core
The most invasive change is the introduction of
ModelArrayAccessor. This handle replacesModelArrayRefas a mechanism to share fields betweenModelComponents but also takes care of host/device data transfers in a transparent manner. To achieve the latter, the new handle as different ergonomics. In order to a access field, one has to explicitly request read or write access for either host or device each time. The resultingModelArray(orModelArrayDevice) reference should only be used within the current scope to ensure that host and device buffers can be synced in between uses as needed.Portable kernels
In order to write code just once that runs with and without Kokkos, a thin wrapper is provided in
KernelAlternatives.hpp. These utilities are meant to be used in combination with theAutovariants that map to the chosen backend, e.g.ModelArrayAccessor::getAutoRW()/ModelArrayAccessor::getAutoRO()to get the bufferoverElementsAutoto run the computations,OVER_ELEMENTS_LAMBDAto define an appropriate lambda.Additionally, device code has a number of restrictions which have to be kept in mind in order to make a computation kernel portable. These are:
ModelArrayDeviceobjects, acquired through aModelArrayAccessorwhich are pointers to already existing buffers. Static class variables on the other hand need to be assigned to a local variable first in order to capture them.Utilswhich maps to eitherstdorKokkos.min,max). In the latter case, just assign the constant to a local variable first.Physics
The major thermodynamics modules where rewritten as portable kernels. To get around the kernel restrictions, two modules had to be converted into proper
ModelComponents since their implementation as virtual function that operates on a single element does not work anymore.IIceAlbedointroduces new fields which are updated internally. The albedo parameteri0(previously alsoI_0in some cases) now also resides with the concreteIIceAlbedoimplementation instead of the calling module. The other module with a changed interface isIFreezingPoint. Since the update was already done on existing fields fewer changes where needed andFreezingPointImplprovides a convenient mechanism to generate the needed implementation and the old interface while only requiring the definition of a single element function, as before.With disciplined use of accessors it is still easily possible to mix host and device code. Adding new modules in the old style is therefore not an issue. However, switching the execution space within a single module is discouraged since this incurs a significant cost from memory transfers and it is easier to introduce synchronization bugs.
Dynamics
Kokkos variants of the dynamics are built on top of the old ones. The interface was kept mostly the same with some additions to minimize needed host/device data transfers when interacting with the other parts of neXtSIM-DG. To port the computations additional tools where needed compared to the thermodynamics. Most important is the Kokkos / Eigen interface provided in
KokkosUtils.hppthat makes switching between Kokkos views and Eigen matrices effortless while preserving compile-time information.In principle, it would be possible to roll the remaining parts that are used from the old variants into the Kokkos dynamics and keep only the latter to ease future maintenance. However, this is out of scope for the current PR as their are some remaining roadblocks:
Test Description
Many existing tests had to be updated to work with the new
ModelArrayAccessorinfrastructure. When Kokkos is enabled, tests automatically use the selected backend. For full code coverage, it is therefore best to run the whole suite with and without Kokkos enabled.Documentation Impact
Build instructions need to be provided. Otherwise there should be little difference for users.