45 use,
intrinsic :: iso_c_binding, only : c_sizeof, c_int32_t, &
46 c_ptr, c_null_ptr, c_size_t, c_associated, c_int
52 integer,
allocatable :: ndofs(:)
53 integer,
allocatable :: offset(:)
55 type(c_ptr) :: buf_d = c_null_ptr
56 type(c_ptr) :: buf_v_d = c_null_ptr
57 type(c_ptr) :: dof_d = c_null_ptr
68 type(c_ptr),
allocatable :: stream(:)
69 type(c_ptr),
allocatable :: event(:)
71 type(c_ptr) :: send_event = c_null_ptr
85 subroutine hip_gs_pack(u_d, buf_d, dof_d, offset, n, stream) &
86 bind(c, name =
'hip_gs_pack')
87 use,
intrinsic :: iso_c_binding
89 integer(c_int),
value :: n, offset
90 type(c_ptr),
value :: u_d, buf_d, dof_d, stream
96 bind(c, name =
'hip_gs_unpack')
97 use,
intrinsic :: iso_c_binding
99 integer(c_int),
value :: op, offset, n
100 type(c_ptr),
value :: u_d, buf_d, dof_d, stream
106 bind(c, name =
'hip_gs_pack_vec')
107 use,
intrinsic :: iso_c_binding
109 integer(c_int),
value :: offset, n, nc, ns
110 type(c_ptr),
value :: u_d, buf_d, dof_d, stream
116 stream) bind(c, name = 'hip_gs_unpack_vec')
117 use,
intrinsic :: iso_c_binding
119 integer(c_int),
value :: op, offset, n, nc, ns
120 type(c_ptr),
value :: u_d, buf_d, dof_d, stream
125 subroutine cuda_gs_pack(u_d, buf_d, dof_d, offset, n, stream) &
126 bind(c, name =
'cuda_gs_pack')
127 use,
intrinsic :: iso_c_binding
129 integer(c_int),
value :: n, offset
130 type(c_ptr),
value :: u_d, buf_d, dof_d, stream
135 subroutine cuda_gs_unpack(u_d, op, buf_d, dof_d, offset, n, stream) &
136 bind(c, name =
'cuda_gs_unpack')
137 use,
intrinsic :: iso_c_binding
139 integer(c_int),
value :: op, offset, n
140 type(c_ptr),
value :: u_d, buf_d, dof_d, stream
146 bind(c, name =
'cuda_gs_pack_vec')
147 use,
intrinsic :: iso_c_binding
149 integer(c_int),
value :: offset, n, nc, ns
150 type(c_ptr),
value :: u_d, buf_d, dof_d, stream
156 stream) bind(c, name = 'cuda_gs_unpack_vec')
157 use,
intrinsic :: iso_c_binding
159 integer(c_int),
value :: op, offset, n, nc, ns
160 type(c_ptr),
value :: u_d, buf_d, dof_d, stream
167 rbuf_d, roffset, rcount, rrank, nbytes, stream) &
168 bind(c, name =
'device_nccl_sendrecv')
169 use,
intrinsic :: iso_c_binding
171 integer(c_int),
value :: soffset, scount, roffset, rcount
172 integer(c_int),
value :: srank, rrank, nbytes
173 type(c_ptr),
value :: sbuf_d, rbuf_d, stream
181 integer,
allocatable,
intent(inout) :: pe_order(:)
182 type(
stack_i4_t),
allocatable,
intent(inout) :: dof_stack(:)
183 logical,
intent(in) :: mark_dupes
184 integer,
allocatable :: dofs(:)
185 integer :: i, j, total
186 integer(c_size_t) :: sz
188 integer :: dupe, marked, k
189 real(c_rp) :: rp_dummy
190 integer(c_int32_t) :: i4_dummy
193 allocate(this%ndofs(
size(pe_order)))
194 allocate(this%offset(
size(pe_order)))
197 do i = 1,
size(pe_order)
198 this%ndofs(i) = dof_stack(pe_order(i))%size()
199 this%offset(i) = total
200 total = total + this%ndofs(i)
205 sz = c_sizeof(rp_dummy) * total
209 sz = c_sizeof(rp_dummy) *
gs_vec_nc * total
212 sz = c_sizeof(i4_dummy) * total
215 if (mark_dupes)
call doftable%init(2*total)
216 allocate(dofs(total))
220 do i = 1,
size(pe_order)
222 select type (arr => dof_stack(pe_order(i))%data)
224 do j = 1, this%ndofs(i)
225 k = this%offset(i) + j
227 if (doftable%get(arr(j), dupe) .eq. 0)
then
228 if (dofs(dupe) .gt. 0)
then
229 dofs(dupe) = -dofs(dupe)
235 call doftable%set(arr(j), k)
255 if (
allocated(this%ndofs))
deallocate(this%ndofs)
256 if (
allocated(this%offset))
deallocate(this%offset)
258 if (c_associated(this%buf_d))
call device_free(this%buf_d)
259 if (c_associated(this%buf_v_d))
call device_free(this%buf_v_d)
260 if (c_associated(this%dof_d))
call device_free(this%dof_d)
270#if !defined(HAVE_NCCL) && !defined(HAVE_RCCL)
271 call neko_error(
'Neko was not built with NCCL support')
274 call this%init_order(send_pe, recv_pe)
276 call this%send_buf%init(this%send_pe, this%send_dof, .false.)
277 call this%recv_buf%init(this%recv_pe, this%recv_dof, .true.)
279#if defined(HAVE_HIP) || defined(HAVE_CUDA)
283 nstrm =
max(
size(this%send_pe),
size(this%recv_pe))
284 allocate(this%stream(nstrm))
290 allocate(this%event(nstrm))
296 this%vec_supported = .true.
305 call this%send_buf%free()
306 call this%recv_buf%free()
308 call this%free_order()
309 call this%free_dofs()
311#if defined(HAVE_HIP) || defined(HAVE_CUDA)
312 if (
allocated(this%stream))
then
313 do i = 1,
size(this%stream)
316 deallocate(this%stream)
319 if (
allocated(this%event))
then
320 do i = 1,
size(this%event)
323 deallocate(this%event)
332 integer,
intent(in) :: n
333 real(kind=
rp),
dimension(n),
intent(inout) :: u
334 integer,
intent(in) :: tag
335 type(c_ptr),
intent(inout) :: deps
336 type(c_ptr),
intent(inout) :: strm
342 do i = 1,
size(this%send_pe)
346 this%send_buf%buf_d, &
347 this%send_buf%dof_d, &
348 this%send_buf%offset(i), &
349 this%send_buf%ndofs(i), &
353 this%send_buf%buf_d, &
354 this%send_buf%dof_d, &
355 this%send_buf%offset(i), &
356 this%send_buf%ndofs(i), &
371 integer,
intent(in) :: tag
381 integer,
intent(in) :: n
382 real(kind=
rp),
dimension(n),
intent(inout) :: u
383 type(c_ptr),
intent(inout) :: strm
384 integer :: op, done_req, i
386 real(c_rp) :: rp_dummy
387 integer(c_int) :: nbytes
390 nbytes = c_sizeof(rp_dummy)
392 do i = 1,
size(this%send_pe)
395 nbytes*this%send_buf%offset(i), &
396 this%send_buf%ndofs(i), &
398 this%recv_buf%buf_d, &
399 nbytes*this%recv_buf%offset(i), &
400 this%recv_buf%ndofs(i), &
407 this%recv_buf%buf_d, &
408 this%recv_buf%dof_d, &
409 this%recv_buf%offset(i), &
410 this%recv_buf%ndofs(i), &
414 this%recv_buf%buf_d, &
415 this%recv_buf%dof_d, &
416 this%recv_buf%offset(i), &
417 this%recv_buf%ndofs(i), &
426 do done_req = 1,
size(this%recv_pe)
428 this%event(done_req), 0)
438 integer,
intent(in) :: n, nc
439 real(kind=
rp),
dimension(nc*n),
intent(inout) :: u
440 integer,
intent(in) :: tag
441 type(c_ptr),
intent(inout) :: deps
442 type(c_ptr),
intent(inout) :: strm
448 do i = 1,
size(this%send_pe)
451 call hip_gs_pack_vec(u_d, this%send_buf%buf_v_d, this%send_buf%dof_d, &
452 this%send_buf%offset(i), this%send_buf%ndofs(i), nc, n, &
456 this%send_buf%offset(i), this%send_buf%ndofs(i), nc, n, &
468 integer,
intent(in) :: tag, nc
474 integer,
intent(in) :: n, nc
475 real(kind=
rp),
dimension(nc*n),
intent(inout) :: u
476 type(c_ptr),
intent(inout) :: strm
477 integer :: op, done_req, i
479 real(c_rp) :: rp_dummy
480 integer(c_int) :: nbytes
483 nbytes = c_sizeof(rp_dummy)
485 do i = 1,
size(this%send_pe)
488 nbytes*nc*this%send_buf%offset(i), &
489 nc*this%send_buf%ndofs(i), &
491 this%recv_buf%buf_v_d, &
492 nbytes*nc*this%recv_buf%offset(i), &
493 nc*this%recv_buf%ndofs(i), &
500 this%recv_buf%dof_d, this%recv_buf%offset(i), &
501 this%recv_buf%ndofs(i), nc, n, this%stream(i))
504 this%recv_buf%dof_d, this%recv_buf%offset(i), &
505 this%recv_buf%ndofs(i), nc, n, this%stream(i))
513 do done_req = 1,
size(this%recv_pe)
515 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_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 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.