Neko 1.99.11
A portable framework for high-order spectral element flow simulations
Loading...
Searching...
No Matches
gs_nvshmem.cu
Go to the documentation of this file.
1/*
2 Copyright (c) 2024-2026, The Neko Authors
3 All rights reserved.
4
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions
7 are met:
8
9 * Redistributions of source code must retain the above copyright
10 notice, this list of conditions and the following disclaimer.
11
12 * Redistributions in binary form must reproduce the above
13 copyright notice, this list of conditions and the following
14 disclaimer in the documentation and/or other materials provided
15 with the distribution.
16
17 * Neither the name of the authors nor the names of its
18 contributors may be used to endorse or promote products derived
19 from this software without specific prior written permission.
20
21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31 ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 POSSIBILITY OF SUCH DAMAGE.
33*/
34
36#include <device/cuda/check.h>
37#ifdef HAVE_NVSHMEM
38#include <nvshmem.h>
39#include "gs_kernels.h"
40#include "gs_nvshmem_kernels.h"
41#endif
42
43extern "C" {
44
45#ifdef HAVE_NVSHMEM
46 void cudamalloc_nvshmem(void** ptr, size_t size)
47 {
48 *ptr = nvshmem_malloc(size);
49 CUDA_CHECK(cudaGetLastError());
50 cudaMemset(*ptr, 0, size);
51 CUDA_CHECK(cudaGetLastError());
52 }
53
54 void cudafree_nvshmem(void** ptr, size_t size)
55 {
56 nvshmem_free(*ptr);
57 CUDA_CHECK(cudaGetLastError());
58 }
59
67 void cuda_gs_nvshmem_pack(void *u_d, void *buf_d, void *dof_d,
68 int boffset, int n, cudaStream_t stream)
69 {
70 if (n == 0) return;
71
72 const int nthrds = 1024;
73 const int nblcks = (n + nthrds - 1) / nthrds;
74
76 <<<nblcks, nthrds, 0, stream>>>((real *) u_d, (real *) buf_d + boffset,
77 (int *) dof_d, n);
78 CUDA_CHECK(cudaGetLastError());
79 }
80
86 void cuda_gs_nvshmem_pack_vec(void *u_d, void *buf_d, void *dof_d,
87 int boffset, int n, int nc, int ns,
88 cudaStream_t stream)
89 {
90 if (n == 0) return;
91
92 const int nthrds = 1024;
93 const int nblcks = (n + nthrds - 1) / nthrds;
94
96 <<<nblcks, nthrds, 0, stream>>>((real *) u_d, (real *) buf_d + boffset,
97 (int *) dof_d, n, nc, ns);
98 CUDA_CHECK(cudaGetLastError());
99 }
100
108 void cuda_gs_push(void *sbuf_d, int soffset, int n, cudaStream_t stream,
109 int destRank, void *rbuf_d, int roffset, int iter,
110 void *done_d, void *ready_d, int mype)
111 {
112 const int nthrds = 1024;
113
115 <<<1,nthrds,0,stream>>>((real *) rbuf_d + roffset,
116 (real *) sbuf_d + soffset,
117 (size_t) n, destRank, (uint64_t) iter,
118 (uint64_t *) done_d + mype,
119 (uint64_t *) ready_d + destRank);
120 CUDA_CHECK(cudaGetLastError());
121 }
122
127 void cuda_gs_push_wait(cudaStream_t stream, int iter,
128 void *done_d, int srcRank)
129 {
130 pushShmemKernelWait<<<1,1,0,stream>>>((uint64_t) iter,
131 (uint64_t *) done_d + srcRank);
132 CUDA_CHECK(cudaGetLastError());
133 }
134
140 void cuda_gs_post_ready(cudaStream_t stream, int iter, void *ready_d,
141 int mype, int srcRank)
142 {
143 postReadyShmemKernel<<<1,1,0,stream>>>((uint64_t *) ready_d + mype,
144 (uint64_t) iter, srcRank);
145 CUDA_CHECK(cudaGetLastError());
146 }
147#endif
148}
#define CUDA_CHECK(err)
Definition check.h:6
__global__ void gs_pack_kernel(const T *__restrict__ u, T *__restrict__ buf, const int32_t *__restrict__ dof, const int n)
Definition gs_kernels.h:256
__global__ void gs_pack_vec_kernel(const T *__restrict__ u, T *__restrict__ buf, const int32_t *__restrict__ dof, const int n, const int nc, const int ns)
Definition gs_kernels.h:393
double real
__global__ void pushShmemKernelWait(uint64_t iter, uint64_t *doneSlot)
__global__ void postReadyShmemKernel(uint64_t *readySlot, uint64_t iter, const int srcRank)
__global__ void pushShmemKernel(T *dest, const T *__restrict__ src, const size_t n, const int destRank, uint64_t iter, uint64_t *doneSig, uint64_t *readySlot)