Neko 1.99.3
A portable framework for high-order spectral element flow simulations
Loading...
Searching...
No Matches
coef.cu
Go to the documentation of this file.
1/*
2 Copyright (c) 2022-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
35#include <stdio.h>
36#include "coef_kernel.h"
38#include <device/cuda/check.h>
39
40extern "C" {
41
45 void cuda_coef_generate_geo(void *G11, void *G12, void *G13,
46 void *G22, void *G23, void *G33,
47 void *drdx, void *drdy, void *drdz,
48 void *dsdx, void *dsdy, void *dsdz,
49 void *dtdx, void *dtdy, void *dtdz,
50 void *jacinv, void *w3, int *nel,
51 int *lx, int *gdim) {
52
53 const dim3 nthrds(1024, 1, 1);
54 const dim3 nblcks((*nel), 1, 1);
55 const cudaStream_t stream = (cudaStream_t) glb_cmd_queue;
56
57#define GEO_CASE(LX) \
58 case LX: \
59 coef_generate_geo_kernel<real, LX, 1024> \
60 <<<nblcks, nthrds, 0, stream>>> \
61 ((real *) G11, (real *) G12, (real *) G13, \
62 (real *) G22, (real *) G23, (real *) G33, \
63 (real *) drdx, (real *) drdy, (real *) drdz, \
64 (real *) dsdx, (real *) dsdy, (real *) dsdz, \
65 (real *) dtdx, (real *) dtdy, (real *) dtdz, \
66 (real *) jacinv, (real *) w3, *gdim); \
67 CUDA_CHECK(cudaGetLastError()); \
68 break
69
70 switch(*lx) {
71 GEO_CASE(2);
72 GEO_CASE(3);
73 GEO_CASE(4);
74 GEO_CASE(5);
75 GEO_CASE(6);
76 GEO_CASE(7);
77 GEO_CASE(8);
78 GEO_CASE(9);
79 GEO_CASE(10);
80 GEO_CASE(11);
81 GEO_CASE(12);
82 GEO_CASE(13);
83 GEO_CASE(14);
84 GEO_CASE(15);
85 GEO_CASE(16);
86 default:
87 {
88 fprintf(stderr, __FILE__ ": size not supported: %d\n", *lx);
89 exit(1);
90 }
91 }
92 }
93
97 void cuda_coef_generate_dxyzdrst(void *drdx, void *drdy, void *drdz,
98 void *dsdx, void *dsdy, void *dsdz,
99 void *dtdx, void *dtdy, void *dtdz,
100 void *dxdr, void *dydr, void *dzdr,
101 void *dxds, void *dyds, void *dzds,
102 void *dxdt, void *dydt, void *dzdt,
103 void *dx, void *dy, void *dz,
104 void *x, void *y, void *z,
105 void *jacinv, void *jac,
106 int *lx, int *nel) {
107
108 const int n = (*nel) * (*lx) * (*lx) * (*lx);
109 const dim3 nthrds(1024, 1, 1);
110 const dim3 nblcks_dxyz((*nel), 1, 1);
111 const dim3 nblcks_drst((n + 1024 - 1)/ 1024, 1, 1);
112 const cudaStream_t stream = (cudaStream_t) glb_cmd_queue;
113
114#define DXYZDRST_CASE(LX) \
115 case LX: \
116 coef_generate_dxyz_kernel<real, LX, 1024> \
117 <<<nblcks_dxyz, nthrds, 0, stream>>> \
118 ((real *) dxdr, (real *) dydr, (real *) dzdr, \
119 (real *) dxds, (real *) dyds, (real *) dzds, \
120 (real *) dxdt, (real *) dydt, (real *) dzdt, \
121 (real *) dx, (real *) dy, (real *) dz, \
122 (real *) x, (real *) y, (real *) z); \
123 CUDA_CHECK(cudaGetLastError()); \
124 break
125
126 switch(*lx) {
127 DXYZDRST_CASE(2);
128 DXYZDRST_CASE(3);
129 DXYZDRST_CASE(4);
130 DXYZDRST_CASE(5);
131 DXYZDRST_CASE(6);
132 DXYZDRST_CASE(7);
133 DXYZDRST_CASE(8);
134 DXYZDRST_CASE(9);
135 DXYZDRST_CASE(10);
136 DXYZDRST_CASE(11);
137 DXYZDRST_CASE(12);
138 DXYZDRST_CASE(13);
139 DXYZDRST_CASE(14);
140 DXYZDRST_CASE(15);
141 DXYZDRST_CASE(16);
142 default:
143 {
144 fprintf(stderr, __FILE__ ": size not supported: %d\n", *lx);
145 exit(1);
146 }
147 }
148
150 <<<nblcks_drst, nthrds, 0, stream>>>
151 ((real *) jac, (real *) jacinv,
152 (real *) drdx, (real *) drdy, (real *) drdz,
153 (real *) dsdx, (real *) dsdy, (real *) dsdz,
154 (real *) dtdx, (real *) dtdy, (real *) dtdz,
155 (real *) dxdr, (real *) dydr, (real *) dzdr,
156 (real *) dxds, (real *) dyds, (real *) dzds,
157 (real *) dxdt, (real *) dydt, (real *) dzdt, n);
159
160 }
161
165 void cuda_coef_generate_mass(void *B, void *Binv, void *jac,
166 void *w3, int *lxyz, int *nel) {
167
168 int n = (*lxyz) * (*nel);
169 const dim3 nthrds(1024, 1, 1);
170 const dim3 nblcks((n + 1024 - 1)/ 1024, 1, 1);
171 const cudaStream_t stream = (cudaStream_t) glb_cmd_queue;
172
174 <<<nblcks, nthrds, 0, stream>>>
175 ((real *) B, (real *) Binv, (real *) jac, (real *) w3,
176 *lxyz, *nel);
177
179
180 }
181
186 void *nx, void *ny, void *nz,
187 void *dxdr, void *dydr, void *dzdr,
188 void *dxds, void *dyds, void *dzds,
189 void *dxdt, void *dydt, void *dzdt,
190 void *wx, void *wy, void *wz,
191 int *lx, int *nel, real eps) {
192
193 const dim3 nblcks((*nel), 1, 1);
194 const dim3 nthrds(1024, 1, 1);
195 const cudaStream_t stream = (cudaStream_t) glb_cmd_queue;
196
197#define AREA_CASE(LX) \
198 case LX: \
199 coef_generate_area_and_normal_kernel<real, LX> \
200 <<<nblcks, nthrds, 0, stream>>> \
201 ((real *) area, (real *) nx, (real *) ny, (real *) nz, \
202 (real *) dxdr, (real *) dydr, (real *) dzdr, \
203 (real *) dxds, (real *) dyds, (real *) dzds, \
204 (real *) dxdt, (real *) dydt, (real *) dzdt, \
205 (real *) wx, (real *) wy, (real *) wz, eps); \
206 CUDA_CHECK(cudaGetLastError()); \
207 break
208
209 switch(*lx) {
210 AREA_CASE(2);
211 AREA_CASE(3);
212 AREA_CASE(4);
213 AREA_CASE(5);
214 AREA_CASE(6);
215 AREA_CASE(7);
216 AREA_CASE(8);
217 AREA_CASE(9);
218 AREA_CASE(10);
219 AREA_CASE(11);
220 AREA_CASE(12);
221 AREA_CASE(13);
222 AREA_CASE(14);
223 AREA_CASE(15);
224 AREA_CASE(16);
225 default:
226 {
227 fprintf(stderr, __FILE__ ": size not supported: %d\n", *lx);
228 exit(1);
229 }
230 }
231 }
232
233}
#define GEO_CASE(LX)
#define AREA_CASE(LX)
void cuda_coef_generate_area_and_normal(void *area, void *nx, void *ny, void *nz, void *dxdr, void *dydr, void *dzdr, void *dxds, void *dyds, void *dzds, void *dxdt, void *dydt, void *dzdt, void *wx, void *wy, void *wz, int *lx, int *nel, real eps)
Definition coef.cu:185
void cuda_coef_generate_mass(void *B, void *Binv, void *jac, void *w3, int *lxyz, int *nel)
Definition coef.cu:165
void cuda_coef_generate_dxyzdrst(void *drdx, void *drdy, void *drdz, void *dsdx, void *dsdy, void *dsdz, void *dtdx, void *dtdy, void *dtdz, void *dxdr, void *dydr, void *dzdr, void *dxds, void *dyds, void *dzds, void *dxdt, void *dydt, void *dzdt, void *dx, void *dy, void *dz, void *x, void *y, void *z, void *jacinv, void *jac, int *lx, int *nel)
Definition coef.cu:97
#define DXYZDRST_CASE(LX)
void cuda_coef_generate_geo(void *G11, void *G12, void *G13, void *G22, void *G23, void *G33, void *drdx, void *drdy, void *drdz, void *dsdx, void *dsdy, void *dsdz, void *dtdx, void *dtdy, void *dtdz, void *jacinv, void *w3, int *nel, int *lx, int *gdim)
Definition coef.cu:45
__global__ void T *__restrict__ T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ drdy
__global__ void T *__restrict__ T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ drdz
__global__ void T *__restrict__ T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ dsdz
__global__ void T *__restrict__ T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ dsdy
__global__ void T *__restrict__ T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ dtdy
__global__ void T *__restrict__ T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ dx
__global__ void T *__restrict__ T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ drdx
__global__ void T *__restrict__ T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ dtdz
__global__ void T *__restrict__ T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ dsdx
__global__ void T *__restrict__ T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ dtdx
__global__ void T *__restrict__ T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ dz
__global__ void T *__restrict__ T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ dy
__global__ void T *__restrict__ T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ jacinv
__global__ void const T *__restrict__ x
__global__ void const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ w3
#define CUDA_CHECK(err)
Definition check.h:6
__global__ void dirichlet_apply_scalar_kernel(const int *__restrict__ msk, T *__restrict__ x, const T g, const int m)
double real