41 use mpi_f08,
only : mpi_allreduce, mpi_alltoall, mpi_integer, mpi_max
43 use,
intrinsic :: iso_c_binding, only : c_sizeof, c_int32_t, c_int64_t, &
44 c_ptr, c_null_ptr, c_size_t, c_associated
50 integer,
allocatable :: ndofs(:)
51 integer,
allocatable :: offset(:)
52 integer,
allocatable :: remote_offset(:)
54 type(c_ptr) :: buf_d = c_null_ptr
55 type(c_ptr) :: buf_v_d = c_null_ptr
56 type(c_ptr) :: dof_d = c_null_ptr
67 type(c_ptr),
allocatable :: stream(:)
68 type(c_ptr),
allocatable :: event(:)
80 type(c_ptr) :: done_sig_d = c_null_ptr
81 type(c_ptr) :: ready_sig_d = c_null_ptr
94#if defined (HAVE_CUDA) && defined(HAVE_NVSHMEM)
98 bind(c, name =
'cudamalloc_nvshmem')
99 use,
intrinsic :: iso_c_binding
102 integer(c_size_t),
value :: size
108 bind(c, name =
'cudafree_nvshmem')
109 use,
intrinsic :: iso_c_binding
117 dest_rank, rbuf_d, roffset, iter, done_d, ready_d, mype) &
118 bind(c, name =
'cuda_gs_pack_and_push')
119 use,
intrinsic :: iso_c_binding
121 integer(c_int),
value :: n, offset, dest_rank, roffset, iter, mype
122 type(c_ptr),
value :: u_d, buf_d, dof_d, stream, rbuf_d, done_d, &
129 bind(c, name =
'cuda_gs_pack_and_push_wait')
130 use,
intrinsic :: iso_c_binding
132 integer(c_int),
value :: iter, src_rank
133 type(c_ptr),
value :: stream, done_d
139 bind(c, name =
'cuda_gs_post_ready')
140 use,
intrinsic :: iso_c_binding
142 integer(c_int),
value :: iter, mype, src_rank
143 type(c_ptr),
value :: stream, ready_d
149 bind(c, name =
'cuda_gs_unpack')
150 use,
intrinsic :: iso_c_binding
152 integer(c_int),
value :: op, offset, n
153 type(c_ptr),
value :: u_d, buf_d, dof_d, stream
159 ns, stream, dest_rank, rbuf_d, roffset, iter, done_d, ready_d, &
160 mype) bind(c, name = 'cuda_gs_pack_and_push_vec')
161 use,
intrinsic :: iso_c_binding
163 integer(c_int),
value :: n, nc, ns, offset, dest_rank, roffset, iter
164 integer(c_int),
value :: mype
165 type(c_ptr),
value :: u_d, buf_d, dof_d, stream, rbuf_d, done_d, &
172 stream) bind(c, name = 'cuda_gs_unpack_vec')
173 use,
intrinsic :: iso_c_binding
175 integer(c_int),
value :: op, offset, n, nc, ns
176 type(c_ptr),
value :: u_d, buf_d, dof_d, stream
185 integer,
allocatable,
intent(inout) :: pe_order(:)
186 type(
stack_i4_t),
allocatable,
intent(inout) :: dof_stack(:)
187 logical,
intent(in) :: mark_dupes
188 integer,
allocatable :: dofs(:)
189 integer :: i, j, total, max_total
190 integer(c_size_t) :: sz
192 integer :: dupe, marked, k
193 real(c_rp) :: rp_dummy
194 integer(c_int32_t) :: i4_dummy
196 allocate(this%ndofs(
size(pe_order)))
197 allocate(this%offset(
size(pe_order)))
198 allocate(this%remote_offset(
size(pe_order)))
200 do i = 1,
size(pe_order)
201 this%remote_offset(i) = -1
205 do i = 1,
size(pe_order)
206 this%ndofs(i) = dof_stack(pe_order(i))%size()
207 this%offset(i) = total
208 total = total + this%ndofs(i)
211 call mpi_allreduce(total, max_total, 1, mpi_integer, mpi_max,
neko_comm)
215 sz = c_sizeof(rp_dummy) * max_total
219 sz = c_sizeof(rp_dummy) *
gs_vec_nc * max_total
223 sz = c_sizeof(i4_dummy) * total
226 if (mark_dupes)
call doftable%init(2*total)
227 allocate(dofs(total))
231 do i = 1,
size(pe_order)
233 select type (arr => dof_stack(pe_order(i))%data)
235 do j = 1, this%ndofs(i)
236 k = this%offset(i) + j
238 if (doftable%get(arr(j), dupe) .eq. 0)
then
239 if (dofs(dupe) .gt. 0)
then
240 dofs(dupe) = -dofs(dupe)
246 call doftable%set(arr(j), k)
267 if (
allocated(this%ndofs))
deallocate(this%ndofs)
268 if (
allocated(this%offset))
deallocate(this%offset)
274 if (c_associated(this%dof_d))
call device_free(this%dof_d)
283 integer :: i, nstrm, ierr
284 integer,
allocatable :: local_offsets(:), remote_offsets(:)
285 integer(c_size_t) :: sz
286 integer(c_int64_t) :: i64_dummy
288 call this%init_order(send_pe, recv_pe)
290 call this%send_buf%init(this%send_pe, this%send_dof, .false.)
291 call this%recv_buf%init(this%recv_pe, this%recv_dof, .true.)
299 allocate(local_offsets(0:
pe_size - 1))
300 allocate(remote_offsets(0:
pe_size - 1))
302 do i = 1,
size(this%recv_pe)
303 local_offsets(this%recv_pe(i)) = this%recv_buf%offset(i)
305 call mpi_alltoall(local_offsets, 1, mpi_integer, &
306 remote_offsets, 1, mpi_integer,
neko_comm, ierr)
307 do i = 1,
size(this%send_pe)
308 this%send_buf%remote_offset(i) = remote_offsets(this%send_pe(i))
310 deallocate(local_offsets)
311 deallocate(remote_offsets)
313#if defined(HAVE_HIP) || defined(HAVE_CUDA)
318 nstrm =
max(
size(this%send_pe),
size(this%recv_pe))
319 allocate(this%stream(nstrm))
325 allocate(this%event(nstrm))
334 sz = c_sizeof(i64_dummy) *
pe_size
341 this%vec_supported = .true.
350 call this%send_buf%free()
351 call this%recv_buf%free()
355 if (c_associated(this%done_sig_d))
then
357 this%done_sig_d = c_null_ptr
359 if (c_associated(this%ready_sig_d))
then
361 this%ready_sig_d = c_null_ptr
365 call this%free_order()
366 call this%free_dofs()
368#if defined(HAVE_HIP) || defined(HAVE_CUDA)
369 if (
allocated(this%stream))
then
370 do i = 1,
size(this%stream)
373 deallocate(this%stream)
382 integer,
intent(in) :: n
383 real(kind=
rp),
dimension(n),
intent(inout) :: u
384 integer,
intent(in) :: tag
385 type(c_ptr),
intent(inout) :: deps
386 type(c_ptr),
intent(inout) :: strm
400 do i = 1,
size(this%send_pe)
411 integer,
intent(in) :: tag
421 integer,
intent(in) :: n
422 real(kind=
rp),
dimension(n),
intent(inout) :: u
423 type(c_ptr),
intent(inout) :: strm
424 integer :: op, done_req, i
431 this%iter = this%iter + 1
436 do i = 1,
size(this%send_pe)
438 this%send_buf%buf_d, &
439 this%send_buf%dof_d, &
440 this%send_buf%offset(i), &
441 this%send_buf%ndofs(i), &
444 this%recv_buf%buf_d, &
445 this%send_buf%remote_offset(i), &
446 this%iter, this%done_sig_d, this%ready_sig_d,
pe_rank)
451 do done_req = 1,
size(this%recv_pe)
453 this%done_sig_d, this%recv_pe(done_req))
455 this%recv_buf%buf_d, &
456 this%recv_buf%dof_d, &
457 this%recv_buf%offset(done_req), &
458 this%recv_buf%ndofs(done_req), &
459 this%stream(done_req))
461 this%ready_sig_d,
pe_rank, this%recv_pe(done_req))
466 do done_req = 1,
size(this%recv_pe)
468 this%event(done_req), 0)
478 integer,
intent(in) :: n, nc
479 real(kind=
rp),
dimension(nc*n),
intent(inout) :: u
480 integer,
intent(in) :: tag
481 type(c_ptr),
intent(inout) :: deps
482 type(c_ptr),
intent(inout) :: strm
487 do i = 1,
size(this%send_pe)
496 integer,
intent(in) :: tag, nc
502 integer,
intent(in) :: n, nc
503 real(kind=
rp),
dimension(nc*n),
intent(inout) :: u
504 type(c_ptr),
intent(inout) :: strm
505 integer :: op, done_req, i
512 this%iter = this%iter + 1
515 do i = 1,
size(this%send_pe)
517 this%send_buf%buf_v_d, &
518 this%send_buf%dof_d, &
519 this%send_buf%offset(i), &
520 this%send_buf%ndofs(i), &
524 this%recv_buf%buf_v_d, &
525 this%send_buf%remote_offset(i), &
526 this%iter, this%done_sig_d, this%ready_sig_d,
pe_rank)
531 do done_req = 1,
size(this%recv_pe)
533 this%done_sig_d, this%recv_pe(done_req))
535 this%recv_buf%buf_v_d, &
536 this%recv_buf%dof_d, &
537 this%recv_buf%offset(done_req), &
538 this%recv_buf%ndofs(done_req), &
540 this%stream(done_req))
542 this%ready_sig_d,
pe_rank, this%recv_pe(done_req))
547 do done_req = 1,
size(this%recv_pe)
549 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_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_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 pack-and-push + unpack.
subroutine gs_device_shmem_buf_init(this, pe_order, dof_stack, mark_dupes)
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.