46 use,
intrinsic :: iso_c_binding, only : c_sizeof, c_int32_t, &
47 c_ptr, c_null_ptr, c_size_t, c_associated
53 integer,
allocatable :: ndofs(:)
54 integer,
allocatable :: offset(:)
56 type(c_ptr) :: reqs = c_null_ptr
57 type(c_ptr) :: buf_d = c_null_ptr
58 type(c_ptr) :: buf_v_d = c_null_ptr
59 type(c_ptr) :: dof_d = c_null_ptr
70 type(c_ptr),
allocatable :: stream(:)
71 type(c_ptr),
allocatable :: event(:)
73 type(c_ptr) :: send_event = c_null_ptr
87 subroutine hip_gs_pack(u_d, buf_d, dof_d, offset, n, stream) &
88 bind(c, name =
'hip_gs_pack')
89 use,
intrinsic :: iso_c_binding
91 integer(c_int),
value :: n, offset
92 type(c_ptr),
value :: u_d, buf_d, dof_d, stream
98 bind(c, name =
'hip_gs_unpack')
99 use,
intrinsic :: iso_c_binding
101 integer(c_int),
value :: op, offset, n
102 type(c_ptr),
value :: u_d, buf_d, dof_d, stream
108 bind(c, name =
'hip_gs_pack_vec')
109 use,
intrinsic :: iso_c_binding
111 integer(c_int),
value :: offset, n, nc, ns
112 type(c_ptr),
value :: u_d, buf_d, dof_d, stream
118 stream) bind(c, name = 'hip_gs_unpack_vec')
119 use,
intrinsic :: iso_c_binding
121 integer(c_int),
value :: op, offset, n, nc, ns
122 type(c_ptr),
value :: u_d, buf_d, dof_d, stream
127 subroutine cuda_gs_pack(u_d, buf_d, dof_d, offset, n, stream) &
128 bind(c, name =
'cuda_gs_pack')
129 use,
intrinsic :: iso_c_binding
131 integer(c_int),
value :: n, offset
132 type(c_ptr),
value :: u_d, buf_d, dof_d, stream
137 subroutine cuda_gs_unpack(u_d, op, buf_d, dof_d, offset, n, stream) &
138 bind(c, name =
'cuda_gs_unpack')
139 use,
intrinsic :: iso_c_binding
141 integer(c_int),
value :: op, offset, n
142 type(c_ptr),
value :: u_d, buf_d, dof_d, stream
148 bind(c, name =
'cuda_gs_pack_vec')
149 use,
intrinsic :: iso_c_binding
151 integer(c_int),
value :: offset, n, nc, ns
152 type(c_ptr),
value :: u_d, buf_d, dof_d, stream
158 stream) bind(c, name = 'cuda_gs_unpack_vec')
159 use,
intrinsic :: iso_c_binding
161 integer(c_int),
value :: op, offset, n, nc, ns
162 type(c_ptr),
value :: u_d, buf_d, dof_d, stream
169 bind(c, name =
'device_mpi_init_reqs')
170 use,
intrinsic :: iso_c_binding
172 integer(c_int),
value :: n
179 bind(c, name =
'device_mpi_free_reqs')
180 use,
intrinsic :: iso_c_binding
188 bind(c, name =
'device_mpi_isend')
189 use,
intrinsic :: iso_c_binding
191 integer(c_int),
value :: offset, nbytes, rank, tag, i
192 type(c_ptr),
value :: buf_d, reqs
198 bind(c, name =
'device_mpi_irecv')
199 use,
intrinsic :: iso_c_binding
201 integer(c_int),
value :: offset, nbytes, rank, tag, i
202 type(c_ptr),
value :: buf_d, reqs
208 bind(c, name =
'device_mpi_test')
209 use,
intrinsic :: iso_c_binding
211 integer(c_int),
value :: i
212 type(c_ptr),
value :: reqs
218 bind(c, name =
'device_mpi_waitall')
219 use,
intrinsic :: iso_c_binding
221 integer(c_int),
value :: n
222 type(c_ptr),
value :: reqs
228 bind(c, name =
'device_mpi_waitany')
229 use,
intrinsic :: iso_c_binding
231 integer(c_int),
value :: n
233 type(c_ptr),
value :: reqs
241 integer,
allocatable,
intent(inout) :: pe_order(:)
242 type(
stack_i4_t),
allocatable,
intent(inout) :: dof_stack(:)
243 logical,
intent(in) :: mark_dupes
244 integer,
allocatable :: dofs(:)
245 integer :: i, j, total
246 integer(c_size_t) :: sz
248 integer :: dupe, marked, k
249 real(c_rp) :: rp_dummy
250 integer(c_int32_t) :: i4_dummy
254 allocate(this%ndofs(
size(pe_order)))
255 allocate(this%offset(
size(pe_order)))
258 do i = 1,
size(pe_order)
259 this%ndofs(i) = dof_stack(pe_order(i))%size()
260 this%offset(i) = total
261 total = total + this%ndofs(i)
266 sz = c_sizeof(rp_dummy) * total
271 sz = c_sizeof(rp_dummy) *
gs_vec_nc * total
275 sz = c_sizeof(i4_dummy) * total
278 if (mark_dupes)
call doftable%init(2*total)
279 allocate(dofs(total))
283 do i = 1,
size(pe_order)
285 select type (arr => dof_stack(pe_order(i))%data)
287 do j = 1, this%ndofs(i)
288 k = this%offset(i) + j
290 if (doftable%get(arr(j), dupe) .eq. 0)
then
291 if (dofs(dupe) .gt. 0)
then
292 dofs(dupe) = -dofs(dupe)
298 call doftable%set(arr(j), k)
323 if (
allocated(this%ndofs))
deallocate(this%ndofs)
324 if (
allocated(this%offset))
deallocate(this%offset)
326 if (c_associated(this%buf_d))
call device_free(this%buf_d)
327 if (c_associated(this%buf_v_d))
call device_free(this%buf_v_d)
328 if (c_associated(this%dof_d))
call device_free(this%dof_d)
338 call this%init_order(send_pe, recv_pe)
340 call this%send_buf%init(this%send_pe, this%send_dof, .false.)
341 call this%recv_buf%init(this%recv_pe, this%recv_dof, .true.)
343#if defined(HAVE_HIP) || defined(HAVE_CUDA)
347 nstrm =
max(
size(this%send_pe),
size(this%recv_pe))
348 allocate(this%stream(nstrm))
354 allocate(this%event(nstrm))
363 this%vec_supported = .true.
372 call this%send_buf%free()
373 call this%recv_buf%free()
375 call this%free_order()
376 call this%free_dofs()
378#if defined(HAVE_HIP) || defined(HAVE_CUDA)
379 if (
allocated(this%stream))
then
380 do i = 1,
size(this%stream)
383 deallocate(this%stream)
392 integer,
intent(in) :: n
393 real(kind=
rp),
dimension(n),
intent(inout) :: u
394 integer,
intent(in) :: tag
395 type(c_ptr),
intent(inout) :: deps
396 type(c_ptr),
intent(inout) :: strm
402 if (iand(this%nb_strtgy, 1) .eq. 0)
then
406 this%send_buf%buf_d, &
407 this%send_buf%dof_d, &
408 0, this%send_buf%total, &
412 this%send_buf%buf_d, &
413 this%send_buf%dof_d, &
414 0, this%send_buf%total, &
422 do i = 1,
size(this%send_pe)
424 rp*this%send_buf%offset(i), &
425 rp*this%send_buf%ndofs(i), this%send_pe(i), tag, &
426 this%send_buf%reqs, i)
431 do i = 1,
size(this%send_pe)
435 this%send_buf%buf_d, &
436 this%send_buf%dof_d, &
437 this%send_buf%offset(i), &
438 this%send_buf%ndofs(i), &
442 this%send_buf%buf_d, &
443 this%send_buf%dof_d, &
444 this%send_buf%offset(i), &
445 this%send_buf%ndofs(i), &
453 do i = 1,
size(this%send_pe)
456 rp*this%send_buf%offset(i), &
457 rp*this%send_buf%ndofs(i), this%send_pe(i), tag, &
458 this%send_buf%reqs, i)
467 integer,
intent(in) :: tag
470 do i = 1,
size(this%recv_pe)
472 rp*this%recv_buf%ndofs(i), this%recv_pe(i), tag, &
473 this%recv_buf%reqs, i)
481 integer,
intent(in) :: n
482 real(kind=
rp),
dimension(n),
intent(inout) :: u
483 type(c_ptr),
intent(inout) :: strm
484 integer :: op, done_req, i
489 if (iand(this%nb_strtgy, 2) .eq. 0)
then
494 this%recv_buf%buf_d, &
495 this%recv_buf%dof_d, &
496 0, this%recv_buf%total, &
500 this%recv_buf%buf_d, &
501 this%recv_buf%dof_d, &
502 0, this%recv_buf%total, &
516 this%recv_buf%reqs, done_req) .ne. 0)
520 this%recv_buf%buf_d, &
521 this%recv_buf%dof_d, &
522 this%recv_buf%offset(done_req), &
523 this%recv_buf%ndofs(done_req), &
524 this%stream(done_req))
527 this%recv_buf%buf_d, &
528 this%recv_buf%dof_d, &
529 this%recv_buf%offset(done_req), &
530 this%recv_buf%ndofs(done_req), &
531 this%stream(done_req))
541 do done_req = 1,
size(this%recv_pe)
543 this%event(done_req), 0)
555 integer,
intent(in) :: n, nc
556 real(kind=
rp),
dimension(nc*n),
intent(inout) :: u
557 integer,
intent(in) :: tag
558 type(c_ptr),
intent(inout) :: deps
559 type(c_ptr),
intent(inout) :: strm
566 call hip_gs_pack_vec(u_d, this%send_buf%buf_v_d, this%send_buf%dof_d, &
567 0, this%send_buf%total, nc, n, strm)
570 0, this%send_buf%total, nc, n, strm)
577 do i = 1,
size(this%send_pe)
579 rp*nc*this%send_buf%offset(i), &
580 rp*nc*this%send_buf%ndofs(i), this%send_pe(i), tag, &
581 this%send_buf%reqs, i)
589 integer,
intent(in) :: tag, nc
592 do i = 1,
size(this%recv_pe)
594 rp*nc*this%recv_buf%offset(i), &
595 rp*nc*this%recv_buf%ndofs(i), this%recv_pe(i), tag, &
596 this%recv_buf%reqs, i)
604 integer,
intent(in) :: n, nc
605 real(kind=
rp),
dimension(nc*n),
intent(inout) :: u
606 type(c_ptr),
intent(inout) :: strm
616 this%recv_buf%dof_d, 0, this%recv_buf%total, nc, n, strm)
619 this%recv_buf%dof_d, 0, this%recv_buf%total, nc, n, strm)
void cuda_gs_unpack(real *u_d, int op, real *buf_d, int *dof_d, int offset, int n, cudaStream_t stream)
void cuda_gs_pack(void *u_d, void *buf_d, void *dof_d, int offset, int n, cudaStream_t stream)
void cuda_gs_pack_vec(void *u_d, void *buf_d, void *dof_d, int offset, int n, int nc, int ns, cudaStream_t stream)
void cuda_gs_unpack_vec(real *u_d, int op, real *buf_d, int *dof_d, int offset, int n, int nc, int ns, cudaStream_t stream)
Return the device pointer for an associated Fortran array.
Copy data between host and device (or device and device)
Synchronize a device or stream.
integer, public pe_size
MPI size of communicator.
integer, public pe_rank
MPI rank.
Device abstraction, common interface for various accelerators.
subroutine, public device_event_record(event, stream)
Record a device event.
integer, parameter, public host_to_device
subroutine, public device_free(x_d)
Deallocate memory on the device.
subroutine, public device_event_destroy(event)
Destroy a device event.
subroutine, public device_alloc(x_d, s)
Allocate memory on the device.
subroutine, public device_stream_create_with_priority(stream, flags, prio)
Create a device stream/command queue with priority.
subroutine, public device_stream_wait_event(stream, event, flags)
Synchronize a device stream with an event.
subroutine, public device_event_create(event, flags)
Create a device event queue.
integer, public strm_high_prio
High priority stream setting.
subroutine, public device_memset(x_d, v, s, sync, strm)
Set memory on the device to a value.
subroutine, public device_stream_destroy(stream)
Destroy a device stream/command queue.
Defines a gather-scatter communication method.
integer, parameter, public gs_vec_nc
Maximum number of components handled by the fused vector (multi-component) halo exchange used by gs_o...
Defines GPU aware MPI gather-scatter communication.
subroutine gs_device_mpi_nbsend_vec(this, u, n, nc, tag, deps, strm)
Fused nc-component send. u is the compact shared device buffer (component-outer, per-component stride...
subroutine gs_device_mpi_buf_init(this, pe_order, dof_stack, mark_dupes)
subroutine gs_device_mpi_nbwait(this, u, n, op, strm)
Wait for non-blocking operations.
subroutine gs_device_mpi_free(this)
Deallocate MPI based communication method.
subroutine gs_device_mpi_nbrecv_vec(this, tag, nc)
Post non-blocking receives for a fused nc-component exchange.
subroutine gs_device_mpi_nbwait_vec(this, u, n, nc, op, strm)
Wait for a fused nc-component exchange and unpack/reduce into u.
subroutine gs_device_mpi_buf_free(this)
subroutine gs_device_mpi_nbsend(this, u, n, tag, deps, strm)
Post non-blocking send operations.
subroutine gs_device_mpi_init(this, send_pe, recv_pe)
Initialise MPI based communication method.
subroutine gs_device_mpi_nbrecv(this, tag)
Post non-blocking receive operations.
Implements a hash table ADT.
integer, parameter, public c_rp
integer, parameter, public rp
Global precision used in computations.
Implements a dynamic stack ADT.
Gather-scatter communication method.
Buffers for non-blocking communication and packing/unpacking.
Gather-scatter communication using device MPI. The arrays are indexed per PE like send_pe and @ recv_...
Integer based hash table.