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)
386 if (
allocated(this%event))
then
387 do i = 1,
size(this%event)
390 deallocate(this%event)
399 integer,
intent(in) :: n
400 real(kind=
rp),
dimension(n),
intent(inout) :: u
401 integer,
intent(in) :: tag
402 type(c_ptr),
intent(inout) :: deps
403 type(c_ptr),
intent(inout) :: strm
409 if (iand(this%nb_strtgy, 1) .eq. 0)
then
413 this%send_buf%buf_d, &
414 this%send_buf%dof_d, &
415 0, this%send_buf%total, &
419 this%send_buf%buf_d, &
420 this%send_buf%dof_d, &
421 0, this%send_buf%total, &
429 do i = 1,
size(this%send_pe)
431 rp*this%send_buf%offset(i), &
432 rp*this%send_buf%ndofs(i), this%send_pe(i), tag, &
433 this%send_buf%reqs, i)
438 do i = 1,
size(this%send_pe)
442 this%send_buf%buf_d, &
443 this%send_buf%dof_d, &
444 this%send_buf%offset(i), &
445 this%send_buf%ndofs(i), &
449 this%send_buf%buf_d, &
450 this%send_buf%dof_d, &
451 this%send_buf%offset(i), &
452 this%send_buf%ndofs(i), &
460 do i = 1,
size(this%send_pe)
463 rp*this%send_buf%offset(i), &
464 rp*this%send_buf%ndofs(i), this%send_pe(i), tag, &
465 this%send_buf%reqs, i)
474 integer,
intent(in) :: tag
477 do i = 1,
size(this%recv_pe)
479 rp*this%recv_buf%ndofs(i), this%recv_pe(i), tag, &
480 this%recv_buf%reqs, i)
488 integer,
intent(in) :: n
489 real(kind=
rp),
dimension(n),
intent(inout) :: u
490 type(c_ptr),
intent(inout) :: strm
491 integer :: op, done_req, i
496 if (iand(this%nb_strtgy, 2) .eq. 0)
then
501 this%recv_buf%buf_d, &
502 this%recv_buf%dof_d, &
503 0, this%recv_buf%total, &
507 this%recv_buf%buf_d, &
508 this%recv_buf%dof_d, &
509 0, this%recv_buf%total, &
523 this%recv_buf%reqs, done_req) .ne. 0)
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))
534 this%recv_buf%buf_d, &
535 this%recv_buf%dof_d, &
536 this%recv_buf%offset(done_req), &
537 this%recv_buf%ndofs(done_req), &
538 this%stream(done_req))
548 do done_req = 1,
size(this%recv_pe)
550 this%event(done_req), 0)
562 integer,
intent(in) :: n, nc
563 real(kind=
rp),
dimension(nc*n),
intent(inout) :: u
564 integer,
intent(in) :: tag
565 type(c_ptr),
intent(inout) :: deps
566 type(c_ptr),
intent(inout) :: strm
573 call hip_gs_pack_vec(u_d, this%send_buf%buf_v_d, this%send_buf%dof_d, &
574 0, this%send_buf%total, nc, n, strm)
577 0, this%send_buf%total, nc, n, strm)
584 do i = 1,
size(this%send_pe)
586 rp*nc*this%send_buf%offset(i), &
587 rp*nc*this%send_buf%ndofs(i), this%send_pe(i), tag, &
588 this%send_buf%reqs, i)
596 integer,
intent(in) :: tag, nc
599 do i = 1,
size(this%recv_pe)
601 rp*nc*this%recv_buf%offset(i), &
602 rp*nc*this%recv_buf%ndofs(i), this%recv_pe(i), tag, &
603 this%recv_buf%reqs, i)
611 integer,
intent(in) :: n, nc
612 real(kind=
rp),
dimension(nc*n),
intent(inout) :: u
613 type(c_ptr),
intent(inout) :: strm
623 this%recv_buf%dof_d, 0, this%recv_buf%total, nc, n, strm)
626 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.