Neko 1.99.5
A portable framework for high-order spectral element flow simulations
Loading...
Searching...
No Matches
gs.cu
Go to the documentation of this file.
1/*
2 Copyright (c) 2021-2025, 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
35#include <climits>
36#include <cstdio>
38#include <device/cuda/check.h>
39#include "gs_kernels.h"
40
41#define GS_OP_ADD 1
42#define GS_OP_MUL 2
43#define GS_OP_MIN 3
44#define GS_OP_MAX 4
45
46extern "C" {
47
51 void cuda_gather_kernel(void *v, int *m, int *o, void *dg,
52 void *u, int *n, void *gd, int *nb,
53 void *b, void *bo, int *op,
54 cudaStream_t stream) {
55
56 if ((*m) == 0) return;
57
58 const dim3 nthrds(1024, 1, 1);
59 const dim3 nblcks(((*m)+ 1024 - 1)/ 1024, 1, 1);
60
61 switch (*op) {
62 case GS_OP_ADD:
64 <<<nblcks, nthrds, 0, stream>>>((real *) v, *m, *o, (int *) dg,
65 (real *) u, *n, (int *) gd,
66 *nb, (int *) b, (int *) bo);
68 break;
69 case GS_OP_MUL:
71 <<<nblcks, nthrds, 0, stream>>>((real *) v, *m, *o, (int *) dg,
72 (real *) u, *n, (int *) gd,
73 *nb, (int *) b, (int *) bo);
75 break;
76 case GS_OP_MIN:
78 <<<nblcks, nthrds, 0, stream>>>((real *) v, *m, *o, (int *) dg,
79 (real *) u, *n, (int *) gd,
80 *nb, (int *) b, (int *) bo);
82 break;
83 case GS_OP_MAX:
85 <<<nblcks, nthrds, 0, stream>>>((real *) v, *m, *o, (int *) dg,
86 (real *) u, *n, (int *) gd,
87 *nb, (int *) b, (int *) bo);
89 break;
90 }
91 }
92
96 void cuda_scatter_kernel(void *v, int *m, void *dg,
97 void *u, int *n, void *gd,
98 int *nb, void *b, void *bo,
99 cudaStream_t stream) {
100
101 if ((*m) == 0) return;
102
103 const dim3 nthrds(1024, 1, 1);
104 const dim3 nblcks(((*m)+1024 - 1)/ 1024, 1, 1);
105
107 <<<nblcks, nthrds, 0, stream>>>((real *) v, *m, (int *) dg,
108 (real *) u, *n, (int *) gd,
109 *nb, (int *) b, (int *) bo);
111 }
112
116 void cuda_gs_pack(void *u_d, void *buf_d, void *dof_d,
117 int offset, int n, cudaStream_t stream) {
118
119 const int nthrds = 1024;
120 const int nblcks = (n + nthrds - 1) / nthrds;
121
123 <<<nblcks, nthrds, 0, stream>>>((real *) u_d, (real *) buf_d + offset,
124 (int *) dof_d + offset, n);
125
127 }
128
132 void cuda_gs_unpack(real *u_d, int op, real *buf_d, int *dof_d,
133 int offset, int n, cudaStream_t stream) {
134
135 const int nthrds = 1024;
136 const int nblcks = (n + nthrds - 1) / nthrds;
137
138 switch (op) {
139 case GS_OP_ADD:
141 <<<nblcks, nthrds, 0, stream>>>(u_d, buf_d + offset,
142 dof_d + offset, n);
143 break;
144 case GS_OP_MIN:
146 <<<nblcks, nthrds, 0, stream>>>(u_d, buf_d + offset,
147 dof_d + offset, n);
148 break;
149 case GS_OP_MAX:
151 <<<nblcks, nthrds, 0, stream>>>(u_d, buf_d + offset,
152 dof_d + offset, n);
153 break;
154 default:
155 printf("%s: unknown gs op %d\n", __FILE__, op);
156 abort();
157 }
158
160 }
161
166 void cuda_gs_pack_vec(void *u_d, void *buf_d, void *dof_d,
167 int offset, int n, int nc, int ns,
168 cudaStream_t stream) {
169
170 const int nthrds = 1024;
171 const int nblcks = (n + nthrds - 1) / nthrds;
172
174 <<<nblcks, nthrds, 0, stream>>>((real *) u_d, (real *) buf_d + nc*offset,
175 (int *) dof_d + offset, n, nc, ns);
176
178 }
179
183 void cuda_gs_unpack_vec(real *u_d, int op, real *buf_d, int *dof_d,
184 int offset, int n, int nc, int ns,
185 cudaStream_t stream) {
186
187 const int nthrds = 1024;
188 const int nblcks = (n + nthrds - 1) / nthrds;
189
190 switch (op) {
191 case GS_OP_ADD:
193 <<<nblcks, nthrds, 0, stream>>>(u_d, buf_d + nc*offset,
194 dof_d + offset, n, nc, ns);
195 break;
196 case GS_OP_MIN:
198 <<<nblcks, nthrds, 0, stream>>>(u_d, buf_d + nc*offset,
199 dof_d + offset, n, nc, ns);
200 break;
201 case GS_OP_MAX:
203 <<<nblcks, nthrds, 0, stream>>>(u_d, buf_d + nc*offset,
204 dof_d + offset, n, nc, ns);
205 break;
206 default:
207 printf("%s: unknown gs op %d\n", __FILE__, op);
208 abort();
209 }
210
212 }
213}
__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)
__global__ void T *__restrict__ T *__restrict__ const T *__restrict__ u
__global__ void T *__restrict__ T *__restrict__ const T *__restrict__ const T *__restrict__ v
#define CUDA_CHECK(err)
Definition check.h:6
double real
#define GS_OP_MAX
Definition gs.cu:44
void cuda_gs_unpack(real *u_d, int op, real *buf_d, int *dof_d, int offset, int n, cudaStream_t stream)
Definition gs.cu:132
#define GS_OP_ADD
Definition gs.cu:41
void cuda_gs_pack(void *u_d, void *buf_d, void *dof_d, int offset, int n, cudaStream_t stream)
Definition gs.cu:116
void cuda_gather_kernel(void *v, int *m, int *o, void *dg, void *u, int *n, void *gd, int *nb, void *b, void *bo, int *op, cudaStream_t stream)
Definition gs.cu:51
void cuda_scatter_kernel(void *v, int *m, void *dg, void *u, int *n, void *gd, int *nb, void *b, void *bo, cudaStream_t stream)
Definition gs.cu:96
#define GS_OP_MUL
Definition gs.cu:42
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)
Definition gs.cu:166
#define GS_OP_MIN
Definition gs.cu:43
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)
Definition gs.cu:183