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
53#if defined(HAVE_NCCL) || defined(HAVE_RCCL)
54 logical,
parameter,
public :: GS_DEVICE_NCCL_AVAIL = .true.
56 logical,
parameter,
public :: gs_device_nccl_avail = .false.
61 integer,
allocatable :: ndofs(:)
62 integer,
allocatable :: offset(:)
64 type(c_ptr) :: buf_d = c_null_ptr
65 type(c_ptr) :: buf_v_d = c_null_ptr
66 type(c_ptr) :: dof_d = c_null_ptr
77 type(c_ptr),
allocatable :: stream(:)
78 type(c_ptr),
allocatable :: event(:)
80 type(c_ptr) :: send_event = c_null_ptr
94 subroutine hip_gs_pack(u_d, buf_d, dof_d, offset, n, stream) &
95 bind(c, name =
'hip_gs_pack')
96 use,
intrinsic :: iso_c_binding
98 integer(c_int),
value :: n, offset
99 type(c_ptr),
value :: u_d, buf_d, dof_d, stream
105 bind(c, name =
'hip_gs_unpack')
106 use,
intrinsic :: iso_c_binding
108 integer(c_int),
value :: op, offset, n
109 type(c_ptr),
value :: u_d, buf_d, dof_d, stream
115 bind(c, name =
'hip_gs_pack_vec')
116 use,
intrinsic :: iso_c_binding
118 integer(c_int),
value :: offset, n, nc, ns
119 type(c_ptr),
value :: u_d, buf_d, dof_d, stream
125 stream) bind(c, name = 'hip_gs_unpack_vec')
126 use,
intrinsic :: iso_c_binding
128 integer(c_int),
value :: op, offset, n, nc, ns
129 type(c_ptr),
value :: u_d, buf_d, dof_d, stream
134 subroutine cuda_gs_pack(u_d, buf_d, dof_d, offset, n, stream) &
135 bind(c, name =
'cuda_gs_pack')
136 use,
intrinsic :: iso_c_binding
138 integer(c_int),
value :: n, offset
139 type(c_ptr),
value :: u_d, buf_d, dof_d, stream
144 subroutine cuda_gs_unpack(u_d, op, buf_d, dof_d, offset, n, stream) &
145 bind(c, name =
'cuda_gs_unpack')
146 use,
intrinsic :: iso_c_binding
148 integer(c_int),
value :: op, offset, n
149 type(c_ptr),
value :: u_d, buf_d, dof_d, stream
155 bind(c, name =
'cuda_gs_pack_vec')
156 use,
intrinsic :: iso_c_binding
158 integer(c_int),
value :: offset, n, nc, ns
159 type(c_ptr),
value :: u_d, buf_d, dof_d, stream
165 stream) bind(c, name = 'cuda_gs_unpack_vec')
166 use,
intrinsic :: iso_c_binding
168 integer(c_int),
value :: op, offset, n, nc, ns
169 type(c_ptr),
value :: u_d, buf_d, dof_d, stream
176 rbuf_d, roffset, rcount, rrank, nbytes, stream) &
177 bind(c, name =
'device_nccl_sendrecv')
178 use,
intrinsic :: iso_c_binding
180 integer(c_int),
value :: soffset, scount, roffset, rcount
181 integer(c_int),
value :: srank, rrank, nbytes
182 type(c_ptr),
value :: sbuf_d, rbuf_d, stream
190 integer,
allocatable,
intent(inout) :: pe_order(:)
191 type(
stack_i4_t),
allocatable,
intent(inout) :: dof_stack(:)
192 logical,
intent(in) :: mark_dupes
193 integer,
allocatable :: dofs(:)
194 integer :: i, j, total
195 integer(c_size_t) :: sz
197 integer :: dupe, marked, k
198 real(c_rp) :: rp_dummy
199 integer(c_int32_t) :: i4_dummy
202 allocate(this%ndofs(
size(pe_order)))
203 allocate(this%offset(
size(pe_order)))
206 do i = 1,
size(pe_order)
207 this%ndofs(i) = dof_stack(pe_order(i))%size()
208 this%offset(i) = total
209 total = total + this%ndofs(i)
214 sz = c_sizeof(rp_dummy) * total
218 sz = c_sizeof(rp_dummy) *
gs_vec_nc * total
221 sz = c_sizeof(i4_dummy) * total
224 if (mark_dupes)
call doftable%init(2*total)
225 allocate(dofs(total))
229 do i = 1,
size(pe_order)
231 select type (arr => dof_stack(pe_order(i))%data)
233 do j = 1, this%ndofs(i)
234 k = this%offset(i) + j
236 if (doftable%get(arr(j), dupe) .eq. 0)
then
237 if (dofs(dupe) .gt. 0)
then
238 dofs(dupe) = -dofs(dupe)
244 call doftable%set(arr(j), k)
264 if (
allocated(this%ndofs))
deallocate(this%ndofs)
265 if (
allocated(this%offset))
deallocate(this%offset)
267 if (c_associated(this%buf_d))
call device_free(this%buf_d)
268 if (c_associated(this%buf_v_d))
call device_free(this%buf_v_d)
269 if (c_associated(this%dof_d))
call device_free(this%dof_d)
279#if !defined(HAVE_NCCL) && !defined(HAVE_RCCL)
280 call neko_error(
'Neko was not built with NCCL support')
283 call this%init_order(send_pe, recv_pe)
285 call this%send_buf%init(this%send_pe, this%send_dof, .false.)
286 call this%recv_buf%init(this%recv_pe, this%recv_dof, .true.)
288#if defined(HAVE_HIP) || defined(HAVE_CUDA)
292 nstrm =
max(
size(this%send_pe),
size(this%recv_pe))
293 allocate(this%stream(nstrm))
299 allocate(this%event(nstrm))
305 this%vec_supported = .true.
314 call this%send_buf%free()
315 call this%recv_buf%free()
317 call this%free_order()
318 call this%free_dofs()
320#if defined(HAVE_HIP) || defined(HAVE_CUDA)
321 if (
allocated(this%stream))
then
322 do i = 1,
size(this%stream)
325 deallocate(this%stream)
328 if (
allocated(this%event))
then
329 do i = 1,
size(this%event)
332 deallocate(this%event)
341 integer,
intent(in) :: n
342 real(kind=
rp),
dimension(n),
intent(inout) :: u
343 integer,
intent(in) :: tag
344 type(c_ptr),
intent(inout) :: deps
345 type(c_ptr),
intent(inout) :: strm
351 do i = 1,
size(this%send_pe)
355 this%send_buf%buf_d, &
356 this%send_buf%dof_d, &
357 this%send_buf%offset(i), &
358 this%send_buf%ndofs(i), &
362 this%send_buf%buf_d, &
363 this%send_buf%dof_d, &
364 this%send_buf%offset(i), &
365 this%send_buf%ndofs(i), &
380 integer,
intent(in) :: tag
390 integer,
intent(in) :: n
391 real(kind=
rp),
dimension(n),
intent(inout) :: u
392 type(c_ptr),
intent(inout) :: strm
393 integer :: op, done_req, i
395 real(c_rp) :: rp_dummy
396 integer(c_int) :: nbytes
399 nbytes = c_sizeof(rp_dummy)
401 do i = 1,
size(this%send_pe)
404 nbytes*this%send_buf%offset(i), &
405 this%send_buf%ndofs(i), &
407 this%recv_buf%buf_d, &
408 nbytes*this%recv_buf%offset(i), &
409 this%recv_buf%ndofs(i), &
416 this%recv_buf%buf_d, &
417 this%recv_buf%dof_d, &
418 this%recv_buf%offset(i), &
419 this%recv_buf%ndofs(i), &
423 this%recv_buf%buf_d, &
424 this%recv_buf%dof_d, &
425 this%recv_buf%offset(i), &
426 this%recv_buf%ndofs(i), &
435 do done_req = 1,
size(this%recv_pe)
437 this%event(done_req), 0)
447 integer,
intent(in) :: n, nc
448 real(kind=
rp),
dimension(nc*n),
intent(inout) :: u
449 integer,
intent(in) :: tag
450 type(c_ptr),
intent(inout) :: deps
451 type(c_ptr),
intent(inout) :: strm
457 do i = 1,
size(this%send_pe)
460 call hip_gs_pack_vec(u_d, this%send_buf%buf_v_d, this%send_buf%dof_d, &
461 this%send_buf%offset(i), this%send_buf%ndofs(i), nc, n, &
465 this%send_buf%offset(i), this%send_buf%ndofs(i), nc, n, &
477 integer,
intent(in) :: tag, nc
483 integer,
intent(in) :: n, nc
484 real(kind=
rp),
dimension(nc*n),
intent(inout) :: u
485 type(c_ptr),
intent(inout) :: strm
486 integer :: op, done_req, i
488 real(c_rp) :: rp_dummy
489 integer(c_int) :: nbytes
492 nbytes = c_sizeof(rp_dummy)
494 do i = 1,
size(this%send_pe)
497 nbytes*nc*this%send_buf%offset(i), &
498 nc*this%send_buf%ndofs(i), &
500 this%recv_buf%buf_v_d, &
501 nbytes*nc*this%recv_buf%offset(i), &
502 nc*this%recv_buf%ndofs(i), &
509 this%recv_buf%dof_d, this%recv_buf%offset(i), &
510 this%recv_buf%ndofs(i), nc, n, this%stream(i))
513 this%recv_buf%dof_d, this%recv_buf%offset(i), &
514 this%recv_buf%ndofs(i), nc, n, this%stream(i))
522 do done_req = 1,
size(this%recv_pe)
524 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.