Skip to content

Commit 64c7be9

Browse files
committed
Add OpenACC directives to enable executing mpas_atm_get_bdy_tend on GPUs.
Note this commit adds "mpas_atm_get_bdy_tend [ACC_data_xfer]" timers to time the data transfers done in mpas_atm_get_bdy_tend, but there is no timer for the actual computation done in mpas_atm_get_bdy_tend.
1 parent 37aa961 commit 64c7be9

File tree

1 file changed

+46
-5
lines changed

1 file changed

+46
-5
lines changed

src/core_atmosphere/dynamics/mpas_atm_boundaries.F

+46-5
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,15 @@
77
!
88
module mpas_atm_boundaries
99

10+
#ifdef MPAS_OPENACC
11+
use mpas_timer
12+
#define MPAS_ACC_TIMER_START(X) call mpas_timer_start(X)
13+
#define MPAS_ACC_TIMER_STOP(X) call mpas_timer_stop(X)
14+
#else
15+
#define MPAS_ACC_TIMER_START(X)
16+
#define MPAS_ACC_TIMER_STOP(X)
17+
#endif
18+
1019
use mpas_derived_types, only : mpas_pool_type, mpas_clock_type, block_type, mpas_time_type, mpas_timeInterval_type, MPAS_NOW, &
1120
MPAS_STREAM_LATEST_BEFORE, MPAS_STREAM_EARLIEST_STRICTLY_AFTER, &
1221
MPAS_streamManager_type
@@ -291,25 +300,57 @@ function mpas_atm_get_bdy_tend(clock, block, vertDim, horizDim, field, delta_t)
291300
real (kind=RKIND), dimension(vertDim,horizDim+1) :: return_tend
292301

293302
type (mpas_pool_type), pointer :: lbc
294-
integer, pointer :: idx
303+
integer, pointer :: idx_ptr
295304
real (kind=RKIND), dimension(:,:), pointer :: tend
296305
real (kind=RKIND), dimension(:,:,:), pointer :: tend_scalars
297-
integer :: ierr
306+
integer :: idx, i, j
298307

299308

300309
call mpas_pool_get_subpool(block % structs, 'lbc', lbc)
301310

302311
nullify(tend)
303312
call mpas_pool_get_array(lbc, 'lbc_'//trim(field), tend, 1)
304313

314+
MPAS_ACC_TIMER_START('mpas_atm_get_bdy_tend [ACC_data_xfer]')
315+
!$acc enter data create(return_tend)
305316
if (associated(tend)) then
306-
return_tend(:,:) = tend(:,:)
317+
!$acc enter data copyin(tend)
307318
else
308319
call mpas_pool_get_array(lbc, 'lbc_scalars', tend_scalars, 1)
309-
call mpas_pool_get_dimension(lbc, 'index_'//trim(field), idx)
320+
!$acc enter data copyin(tend_scalars)
321+
322+
! Ensure the integer pointed to by idx_ptr is copied to the gpu device
323+
call mpas_pool_get_dimension(lbc, 'index_'//trim(field), idx_ptr)
324+
idx = idx_ptr
325+
end if
326+
MPAS_ACC_TIMER_STOP('mpas_atm_get_bdy_tend [ACC_data_xfer]')
310327

311-
return_tend(:,:) = tend_scalars(idx,:,:)
328+
!$acc parallel default(present)
329+
if (associated(tend)) then
330+
!$acc loop gang vector collapse(2)
331+
do j=1,horizDim+1
332+
do i=1,vertDim
333+
return_tend(i,j) = tend(i,j)
334+
end do
335+
end do
336+
else
337+
!$acc loop vector collapse(2)
338+
do j=1,horizDim+1
339+
do i=1,vertDim
340+
return_tend(i,j) = tend_scalars(idx,i,j)
341+
end do
342+
end do
343+
end if
344+
!$acc end parallel
345+
346+
MPAS_ACC_TIMER_START('mpas_atm_get_bdy_tend [ACC_data_xfer]')
347+
!$acc exit data copyout(return_tend)
348+
if (associated(tend)) then
349+
!$acc exit data delete(tend)
350+
else
351+
!$acc exit data delete(tend_scalars)
312352
end if
353+
MPAS_ACC_TIMER_STOP('mpas_atm_get_bdy_tend [ACC_data_xfer]')
313354

314355
end function mpas_atm_get_bdy_tend
315356

0 commit comments

Comments
 (0)