Neko 1.99.6
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);
50 cudaMemset(*ptr, 0, size);
52 }
53
54 void cudafree_nvshmem(void** ptr, size_t size)
55 {
56 nvshmem_free(*ptr);
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);
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);
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,
121 }
122
127 void cuda_gs_push_wait(cudaStream_t stream, int iter,
128 void *done_d, int srcRank)
129 {
131 (uint64_t *) done_d + srcRank);
133 }
134
140 void cuda_gs_post_ready(cudaStream_t stream, int iter, void *ready_d,
141 int mype, int srcRank)
142 {
144 (uint64_t) iter, srcRank);
146 }
147#endif
148}
__global__ void ale_add_kinematics_kernel(const int n, T *__restrict__ wx, T *__restrict__ wy, T *__restrict__ wz, const T *__restrict__ x_ref, const T *__restrict__ y_ref, const T *__restrict__ z_ref, const T *__restrict__ phi, const T *__restrict__ x, const T *__restrict__ y, const T *__restrict__ z, const kinematics_params_t kin_params)
#define CUDA_CHECK(err)
Definition check.h:6
double real