42 use,
intrinsic :: iso_c_binding, only : c_sizeof, c_int32_t, &
43 c_ptr, c_null_ptr, c_size_t, c_associated, c_int
49 integer,
allocatable :: ndofs(:)
50 integer,
allocatable :: offset(:)
52 type(c_ptr) :: buf_d = c_null_ptr
53 type(c_ptr) :: buf_v_d = c_null_ptr
54 type(c_ptr) :: dof_d = c_null_ptr
65 type(c_ptr),
allocatable :: stream(:)
66 type(c_ptr),
allocatable :: event(:)
68 type(c_ptr) :: send_event = c_null_ptr
82 subroutine hip_gs_pack(u_d, buf_d, dof_d, offset, n, stream) &
83 bind(c, name =
'hip_gs_pack')
84 use,
intrinsic :: iso_c_binding
86 integer(c_int),
value :: n, offset
87 type(c_ptr),
value :: u_d, buf_d, dof_d, stream
93 bind(c, name =
'hip_gs_unpack')
94 use,
intrinsic :: iso_c_binding
96 integer(c_int),
value :: op, offset, n
97 type(c_ptr),
value :: u_d, buf_d, dof_d, stream
103 bind(c, name =
'hip_gs_pack_vec')
104 use,
intrinsic :: iso_c_binding
106 integer(c_int),
value :: offset, n, nc, ns
107 type(c_ptr),
value :: u_d, buf_d, dof_d, stream
113 stream) bind(c, name = 'hip_gs_unpack_vec')
114 use,
intrinsic :: iso_c_binding
116 integer(c_int),
value :: op, offset, n, nc, ns
117 type(c_ptr),
value :: u_d, buf_d, dof_d, stream
122 subroutine cuda_gs_pack(u_d, buf_d, dof_d, offset, n, stream) &
123 bind(c, name =
'cuda_gs_pack')
124 use,
intrinsic :: iso_c_binding
126 integer(c_int),
value :: n, offset
127 type(c_ptr),
value :: u_d, buf_d, dof_d, stream
132 subroutine cuda_gs_unpack(u_d, op, buf_d, dof_d, offset, n, stream) &
133 bind(c, name =
'cuda_gs_unpack')
134 use,
intrinsic :: iso_c_binding
136 integer(c_int),
value :: op, offset, n
137 type(c_ptr),
value :: u_d, buf_d, dof_d, stream
143 bind(c, name =
'cuda_gs_pack_vec')
144 use,
intrinsic :: iso_c_binding
146 integer(c_int),
value :: offset, n, nc, ns
147 type(c_ptr),
value :: u_d, buf_d, dof_d, stream
153 stream) bind(c, name = 'cuda_gs_unpack_vec')
154 use,
intrinsic :: iso_c_binding
156 integer(c_int),
value :: op, offset, n, nc, ns
157 type(c_ptr),
value :: u_d, buf_d, dof_d, stream
164 rbuf_d, roffset, rcount, rrank, nbytes, stream) &
165 bind(c, name =
'device_nccl_sendrecv')
166 use,
intrinsic :: iso_c_binding
168 integer(c_int),
value :: soffset, scount, roffset, rcount
169 integer(c_int),
value :: srank, rrank, nbytes
170 type(c_ptr),
value :: sbuf_d, rbuf_d, stream
178 integer,
allocatable,
intent(inout) :: pe_order(:)
179 type(
stack_i4_t),
allocatable,
intent(inout) :: dof_stack(:)
180 logical,
intent(in) :: mark_dupes
181 integer,
allocatable :: dofs(:)
182 integer :: i, j, total
183 integer(c_size_t) :: sz
185 integer :: dupe, marked, k
186 real(c_rp) :: rp_dummy
187 integer(c_int32_t) :: i4_dummy
190 allocate(this%ndofs(
size(pe_order)))
191 allocate(this%offset(
size(pe_order)))
194 do i = 1,
size(pe_order)
195 this%ndofs(i) = dof_stack(pe_order(i))%size()
196 this%offset(i) = total
197 total = total + this%ndofs(i)
202 sz = c_sizeof(rp_dummy) * total
206 sz = c_sizeof(rp_dummy) *
gs_vec_nc * total
209 sz = c_sizeof(i4_dummy) * total
212 if (mark_dupes)
call doftable%init(2*total)
213 allocate(dofs(total))
217 do i = 1,
size(pe_order)
219 select type (arr => dof_stack(pe_order(i))%data)
221 do j = 1, this%ndofs(i)
222 k = this%offset(i) + j
224 if (doftable%get(arr(j), dupe) .eq. 0)
then
225 if (dofs(dupe) .gt. 0)
then
226 dofs(dupe) = -dofs(dupe)
232 call doftable%set(arr(j), k)
252 if (
allocated(this%ndofs))
deallocate(this%ndofs)
253 if (
allocated(this%offset))
deallocate(this%offset)
255 if (c_associated(this%buf_d))
call device_free(this%buf_d)
256 if (c_associated(this%buf_v_d))
call device_free(this%buf_v_d)
257 if (c_associated(this%dof_d))
call device_free(this%dof_d)
267 call this%init_order(send_pe, recv_pe)
269 call this%send_buf%init(this%send_pe, this%send_dof, .false.)
270 call this%recv_buf%init(this%recv_pe, this%recv_dof, .true.)
272#if defined(HAVE_HIP) || defined(HAVE_CUDA)
276 nstrm =
max(
size(this%send_pe),
size(this%recv_pe))
277 allocate(this%stream(nstrm))
283 allocate(this%event(nstrm))
289 this%vec_supported = .true.
298 call this%send_buf%free()
299 call this%recv_buf%free()
301 call this%free_order()
302 call this%free_dofs()
304#if defined(HAVE_HIP) || defined(HAVE_CUDA)
305 if (
allocated(this%stream))
then
306 do i = 1,
size(this%stream)
309 deallocate(this%stream)
318 integer,
intent(in) :: n
319 real(kind=
rp),
dimension(n),
intent(inout) :: u
320 integer,
intent(in) :: tag
321 type(c_ptr),
intent(inout) :: deps
322 type(c_ptr),
intent(inout) :: strm
328 do i = 1,
size(this%send_pe)
332 this%send_buf%buf_d, &
333 this%send_buf%dof_d, &
334 this%send_buf%offset(i), &
335 this%send_buf%ndofs(i), &
339 this%send_buf%buf_d, &
340 this%send_buf%dof_d, &
341 this%send_buf%offset(i), &
342 this%send_buf%ndofs(i), &
357 integer,
intent(in) :: tag
367 integer,
intent(in) :: n
368 real(kind=
rp),
dimension(n),
intent(inout) :: u
369 type(c_ptr),
intent(inout) :: strm
370 integer :: op, done_req, i
372 real(c_rp) :: rp_dummy
373 integer(c_int) :: nbytes
376 nbytes = c_sizeof(rp_dummy)
378 do i = 1,
size(this%send_pe)
381 nbytes*this%send_buf%offset(i), &
382 this%send_buf%ndofs(i), &
384 this%recv_buf%buf_d, &
385 nbytes*this%recv_buf%offset(i), &
386 this%recv_buf%ndofs(i), &
393 this%recv_buf%buf_d, &
394 this%recv_buf%dof_d, &
395 this%recv_buf%offset(i), &
396 this%recv_buf%ndofs(i), &
400 this%recv_buf%buf_d, &
401 this%recv_buf%dof_d, &
402 this%recv_buf%offset(i), &
403 this%recv_buf%ndofs(i), &
412 do done_req = 1,
size(this%recv_pe)
414 this%event(done_req), 0)
424 integer,
intent(in) :: n, nc
425 real(kind=
rp),
dimension(nc*n),
intent(inout) :: u
426 integer,
intent(in) :: tag
427 type(c_ptr),
intent(inout) :: deps
428 type(c_ptr),
intent(inout) :: strm
434 do i = 1,
size(this%send_pe)
437 call hip_gs_pack_vec(u_d, this%send_buf%buf_v_d, this%send_buf%dof_d, &
438 this%send_buf%offset(i), this%send_buf%ndofs(i), nc, n, &
442 this%send_buf%offset(i), this%send_buf%ndofs(i), nc, n, &
454 integer,
intent(in) :: tag, nc
460 integer,
intent(in) :: n, nc
461 real(kind=
rp),
dimension(nc*n),
intent(inout) :: u
462 type(c_ptr),
intent(inout) :: strm
463 integer :: op, done_req, i
465 real(c_rp) :: rp_dummy
466 integer(c_int) :: nbytes
469 nbytes = c_sizeof(rp_dummy)
471 do i = 1,
size(this%send_pe)
474 nbytes*nc*this%send_buf%offset(i), &
475 nc*this%send_buf%ndofs(i), &
477 this%recv_buf%buf_v_d, &
478 nbytes*nc*this%recv_buf%offset(i), &
479 nc*this%recv_buf%ndofs(i), &
486 this%recv_buf%dof_d, this%recv_buf%offset(i), &
487 this%recv_buf%ndofs(i), nc, n, this%stream(i))
490 this%recv_buf%dof_d, this%recv_buf%offset(i), &
491 this%recv_buf%ndofs(i), nc, n, this%stream(i))
499 do done_req = 1,
size(this%recv_pe)
501 this%event(done_req), 0)
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)
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_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 NCCL based gather-scatter communication.
subroutine gs_device_nccl_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_nccl_nbrecv(this, tag)
Post non-blocking receive operations.
subroutine gs_device_nccl_init(this, send_pe, recv_pe)
Initialise NCCL based communication method.
subroutine gs_device_nccl_nbsend(this, u, n, tag, deps, strm)
Post non-blocking send operations.
subroutine gs_device_nccl_nbwait(this, u, n, op, strm)
Wait for non-blocking operations.
subroutine gs_device_nccl_buf_init(this, pe_order, dof_stack, mark_dupes)
subroutine gs_device_nccl_nbrecv_vec(this, tag, nc)
No-op: send/recv and unpack happen in nbwait_vec.
subroutine gs_device_nccl_nbwait_vec(this, u, n, nc, op, strm)
Fused nc-component send/recv + unpack.
subroutine gs_device_nccl_free(this)
Deallocate MPI based communication method.
subroutine gs_device_nccl_buf_free(this)
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 NCCL The arrays are indexed per PE like send_pe and @ recv_pe.
Integer based hash table.