Stage the pre-regrid solution on the DEVICE (Stage 6a), replacing the base implementation's device-to-host copy of the whole field. Regrid subsequently releases solution%interior_gpu, so the field is copied device-to-device into a buffer this model owns; ApplyTransferPlan then reads it from there.
The staging buffer is grown monotonically and reused, so an adapting run allocates here only when the element count exceeds every previous epoch's.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(DGModel2D), | intent(inout) | :: | this |
subroutine StageSolutionForTransfer_DGModel2D(this)
!! Stage the pre-regrid solution on the DEVICE (Stage 6a), replacing the base
!! implementation's device-to-host copy of the whole field. Regrid subsequently releases
!! solution%interior_gpu, so the field is copied device-to-device into a buffer this model
!! owns; ApplyTransferPlan then reads it from there.
!!
!! The staging buffer is grown monotonically and reused, so an adapting run allocates here
!! only when the element count exceeds every previous epoch's.
implicit none
class(DGModel2D),intent(inout) :: this
! Local
integer(c_size_t) :: nbytes
nbytes = int(this%solution%interp%N+1,c_size_t)*(this%solution%interp%N+1)* &
this%solution%nElem*this%nvar*prec
if(nbytes > this%xferAllocBytes) then
if(c_associated(this%xferOld_gpu)) call gpuCheck(hipFree(this%xferOld_gpu))
call gpuCheck(hipMalloc(this%xferOld_gpu,nbytes))
this%xferAllocBytes = nbytes
endif
call gpuCheck(hipMemcpy(this%xferOld_gpu,this%solution%interior_gpu,nbytes, &
hipMemcpyDeviceToDevice))
! Remember the staged field's element count: it is the stride the transfer kernel must use
! to index the staged buffer, and it is no longer recoverable from the model after Regrid.
this%xferNOld = this%solution%nElem
endsubroutine StageSolutionForTransfer_DGModel2D