44 use mpi_f08,
only : mpi_allreduce, mpi_alltoall, mpi_integer, mpi_max
46 use,
intrinsic :: iso_c_binding, only : c_sizeof, c_int32_t, c_int64_t, &
47 c_ptr, c_null_ptr, c_size_t, c_associated
53 integer,
allocatable :: ndofs(:)
54 integer,
allocatable :: offset(:)
55 integer,
allocatable :: remote_offset(:)
60 integer :: slab_stride
61 type(c_ptr) :: buf_d = c_null_ptr
62 type(c_ptr) :: buf_v_d = c_null_ptr
63 type(c_ptr) :: dof_d = c_null_ptr
74 type(c_ptr),
allocatable :: stream(:)
75 type(c_ptr),
allocatable :: event(:)
87 type(c_ptr) :: done_sig_d = c_null_ptr
88 type(c_ptr) :: ready_sig_d = c_null_ptr
92 type(c_ptr) :: pack_event = c_null_ptr
105#if defined (HAVE_CUDA) && defined(HAVE_NVSHMEM)
109 bind(c, name =
'cudamalloc_nvshmem')
110 use,
intrinsic :: iso_c_binding
113 integer(c_size_t),
value :: size
119 bind(c, name =
'cudafree_nvshmem')
120 use,
intrinsic :: iso_c_binding
128 bind(c, name =
'cuda_gs_nvshmem_pack')
129 use,
intrinsic :: iso_c_binding
131 integer(c_int),
value :: boffset, n
132 type(c_ptr),
value :: u_d, buf_d, dof_d, stream
138 ns, stream) bind(c, name = 'cuda_gs_nvshmem_pack_vec')
139 use,
intrinsic :: iso_c_binding
141 integer(c_int),
value :: boffset, n, nc, ns
142 type(c_ptr),
value :: u_d, buf_d, dof_d, stream
148 roffset, iter, done_d, ready_d, mype) &
149 bind(c, name =
'cuda_gs_push')
150 use,
intrinsic :: iso_c_binding
152 integer(c_int),
value :: n, offset, dest_rank, roffset, iter, mype
153 type(c_ptr),
value :: buf_d, stream, rbuf_d, done_d, ready_d
159 bind(c, name =
'cuda_gs_push_wait')
160 use,
intrinsic :: iso_c_binding
162 integer(c_int),
value :: iter, src_rank
163 type(c_ptr),
value :: stream, done_d
169 bind(c, name =
'cuda_gs_post_ready')
170 use,
intrinsic :: iso_c_binding
172 integer(c_int),
value :: iter, mype, src_rank
173 type(c_ptr),
value :: stream, ready_d
179 bind(c, name =
'cuda_gs_unpack')
180 use,
intrinsic :: iso_c_binding
182 integer(c_int),
value :: op, offset, n
183 type(c_ptr),
value :: u_d, buf_d, dof_d, stream
189 stream) bind(c, name = 'cuda_gs_unpack_vec')
190 use,
intrinsic :: iso_c_binding
192 integer(c_int),
value :: op, offset, n, nc, ns
193 type(c_ptr),
value :: u_d, buf_d, dof_d, stream
207 integer,
allocatable,
intent(inout) :: pe_order(:)
208 type(
stack_i4_t),
allocatable,
intent(inout) :: dof_stack(:)
209 logical,
intent(in) :: mark_dupes
210 integer,
intent(in) :: nslabs
211 integer,
allocatable :: dofs(:)
212 integer :: i, j, total, max_total
213 integer(c_size_t) :: sz
215 integer :: dupe, marked, k
216 real(c_rp) :: rp_dummy
217 integer(c_int32_t) :: i4_dummy
219 allocate(this%ndofs(
size(pe_order)))
220 allocate(this%offset(
size(pe_order)))
221 allocate(this%remote_offset(
size(pe_order)))
223 do i = 1,
size(pe_order)
224 this%remote_offset(i) = -1
228 do i = 1,
size(pe_order)
229 this%ndofs(i) = dof_stack(pe_order(i))%size()
230 this%offset(i) = total
231 total = total + this%ndofs(i)
234 call mpi_allreduce(total, max_total, 1, mpi_integer, mpi_max,
neko_comm)
237 this%slab_stride = max_total
239 sz = c_sizeof(rp_dummy) * nslabs * max_total
243 sz = c_sizeof(rp_dummy) * nslabs *
gs_vec_nc * max_total
247 sz = c_sizeof(i4_dummy) * total
250 if (mark_dupes)
call doftable%init(2*total)
251 allocate(dofs(total))
255 do i = 1,
size(pe_order)
257 select type (arr => dof_stack(pe_order(i))%data)
259 do j = 1, this%ndofs(i)
260 k = this%offset(i) + j
262 if (doftable%get(arr(j), dupe) .eq. 0)
then
263 if (dofs(dupe) .gt. 0)
then
264 dofs(dupe) = -dofs(dupe)
270 call doftable%set(arr(j), k)
291 if (
allocated(this%ndofs))
deallocate(this%ndofs)
292 if (
allocated(this%offset))
deallocate(this%offset)
293 if (
allocated(this%remote_offset))
deallocate(this%remote_offset)
299 if (c_associated(this%dof_d))
call device_free(this%dof_d)
308 integer :: i, nstrm, ierr
309 integer,
allocatable :: local_offsets(:), remote_offsets(:)
310 integer(c_size_t) :: sz
311 integer(c_int64_t) :: i64_dummy
313 call this%init_order(send_pe, recv_pe)
320 if (
size(this%send_pe) .ne.
size(this%recv_pe))
then
321 call neko_error(
'gs_device_shmem requires symmetric peer lists')
323 do i = 1,
size(this%send_pe)
324 if (this%send_pe(i) .ne. this%recv_pe(i))
then
325 call neko_error(
'gs_device_shmem requires aligned peer lists')
331 call this%send_buf%init(this%send_pe, this%send_dof, .false., 2)
332 call this%recv_buf%init(this%recv_pe, this%recv_dof, .true., 1)
340 allocate(local_offsets(0:
pe_size - 1))
341 allocate(remote_offsets(0:
pe_size - 1))
343 do i = 1,
size(this%recv_pe)
344 local_offsets(this%recv_pe(i)) = this%recv_buf%offset(i)
346 call mpi_alltoall(local_offsets, 1, mpi_integer, &
347 remote_offsets, 1, mpi_integer,
neko_comm, ierr)
348 do i = 1,
size(this%send_pe)
349 this%send_buf%remote_offset(i) = remote_offsets(this%send_pe(i))
351 deallocate(local_offsets)
352 deallocate(remote_offsets)
354#if defined(HAVE_HIP) || defined(HAVE_CUDA)
359 nstrm =
max(
size(this%send_pe),
size(this%recv_pe))
360 allocate(this%stream(nstrm))
366 allocate(this%event(nstrm))
377 sz = c_sizeof(i64_dummy) *
pe_size
384 this%vec_supported = .true.
393 call this%send_buf%free()
394 call this%recv_buf%free()
398 if (c_associated(this%done_sig_d))
then
400 this%done_sig_d = c_null_ptr
402 if (c_associated(this%ready_sig_d))
then
404 this%ready_sig_d = c_null_ptr
408 call this%free_order()
409 call this%free_dofs()
411#if defined(HAVE_HIP) || defined(HAVE_CUDA)
412 if (
allocated(this%stream))
then
413 do i = 1,
size(this%stream)
416 deallocate(this%stream)
419 if (
allocated(this%event))
then
420 do i = 1,
size(this%event)
423 deallocate(this%event)
426 if (c_associated(this%pack_event))
then
428 this%pack_event = c_null_ptr
437 integer,
intent(in) :: n
438 real(kind=
rp),
dimension(n),
intent(inout) :: u
439 integer,
intent(in) :: tag
440 type(c_ptr),
intent(inout) :: deps
441 type(c_ptr),
intent(inout) :: strm
451 this%iter = this%iter + 1
452 parity = mod(this%iter, 2)
473 this%send_buf%dof_d, parity * this%send_buf%slab_stride, &
474 this%send_buf%total, strm)
479 do i = 1,
size(this%send_pe)
491 integer,
intent(in) :: tag
501 integer,
intent(in) :: n
502 real(kind=
rp),
dimension(n),
intent(inout) :: u
503 type(c_ptr),
intent(inout) :: strm
504 integer :: op, done_req, i, parity
509 parity = mod(this%iter, 2)
514 do i = 1,
size(this%send_pe)
516 parity * this%send_buf%slab_stride + this%send_buf%offset(i), &
517 this%send_buf%ndofs(i), &
520 this%recv_buf%buf_d, &
521 this%send_buf%remote_offset(i), &
522 this%iter, this%done_sig_d, this%ready_sig_d,
pe_rank)
527 do done_req = 1,
size(this%recv_pe)
529 this%done_sig_d, this%recv_pe(done_req))
531 this%recv_buf%buf_d, &
532 this%recv_buf%dof_d, &
533 this%recv_buf%offset(done_req), &
534 this%recv_buf%ndofs(done_req), &
535 this%stream(done_req))
537 this%ready_sig_d,
pe_rank, this%recv_pe(done_req))
542 do done_req = 1,
size(this%recv_pe)
544 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
568 this%iter = this%iter + 1
569 parity = mod(this%iter, 2)
573 this%send_buf%dof_d, &
574 parity *
gs_vec_nc * this%send_buf%slab_stride, &
575 this%send_buf%total, nc, n, strm)
580 do i = 1,
size(this%send_pe)
590 integer,
intent(in) :: tag, nc
596 integer,
intent(in) :: n, nc
597 real(kind=
rp),
dimension(nc*n),
intent(inout) :: u
598 type(c_ptr),
intent(inout) :: strm
599 integer :: op, done_req, i, parity
604 parity = mod(this%iter, 2)
609 do i = 1,
size(this%send_pe)
611 parity *
gs_vec_nc * this%send_buf%slab_stride &
612 + nc * this%send_buf%offset(i), &
613 nc * this%send_buf%ndofs(i), &
616 this%recv_buf%buf_v_d, &
617 nc * this%send_buf%remote_offset(i), &
618 this%iter, this%done_sig_d, this%ready_sig_d,
pe_rank)
623 do done_req = 1,
size(this%recv_pe)
625 this%done_sig_d, this%recv_pe(done_req))
627 this%recv_buf%buf_v_d, &
628 this%recv_buf%dof_d, &
629 this%recv_buf%offset(done_req), &
630 this%recv_buf%ndofs(done_req), &
632 this%stream(done_req))
634 this%ready_sig_d,
pe_rank, this%recv_pe(done_req))
639 do done_req = 1,
size(this%recv_pe)
641 this%event(done_req), 0)
Return the device pointer for an associated Fortran array.
Copy data between host and device (or device and device)
integer, public pe_size
MPI size of communicator.
integer, public pe_rank
MPI rank.
type(mpi_comm), public neko_comm
MPI communicator.
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_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_shmem_nbrecv_vec(this, tag, nc)
No-op: everything happens in nbwait_vec.
subroutine gs_device_shmem_buf_init(this, pe_order, dof_stack, mark_dupes, nslabs)
subroutine gs_device_shmem_nbwait(this, u, n, op, strm)
Wait for non-blocking operations.
subroutine gs_device_shmem_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_shmem_nbsend(this, u, n, tag, deps, strm)
Post non-blocking send operations.
subroutine gs_device_shmem_nbrecv(this, tag)
Post non-blocking receive operations.
subroutine gs_device_shmem_nbwait_vec(this, u, n, nc, op, strm)
Fused nc-component push + unpack (the pack happens in nbsend_vec).
subroutine gs_device_shmem_free(this)
Deallocate MPI based communication method.
subroutine gs_device_shmem_buf_free(this)
subroutine gs_device_shmem_init(this, send_pe, recv_pe)
Initialise MPI based communication method.
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 SHMEM. The arrays are indexed per PE like send_pe and @ rec...
Integer based hash table.