-
Notifications
You must be signed in to change notification settings - Fork 2
/
ewKernels.sycl.cpp
261 lines (201 loc) · 8.13 KB
/
ewKernels.sycl.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
/*
* EasyWave - A realtime tsunami simulation program with GPU support.
* Copyright (C) 2014 Andrey Babeyko, Johannes Spazier
* GFZ German Research Centre for Geosciences (http://www.gfz-potsdam.de)
*
* Parts of this program (especially the GPU extension) were developed
* within the context of the following publicly funded project:
* - TRIDEC, EU 7th Framework Programme, Grant Agreement 258723
* (http://www.tridec-online.eu)
*
* Licensed under the EUPL, Version 1.1 or - as soon they will be approved by
* the European Commission - subsequent versions of the EUPL (the "Licence"),
* complemented with the following provision: For the scientific transparency
* and verification of results obtained and communicated to the public after
* using a modified version of the work, You (as the recipient of the source
* code and author of this modified version, used to produce the published
* results in scientific communications) commit to make this modified source
* code available in a repository that is easily and freely accessible for a
* duration of five years after the communication of the obtained results.
*
* You may not use this work except in compliance with the Licence.
*
* You may obtain a copy of the Licence at:
* https://joinup.ec.europa.eu/software/page/eupl
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the Licence is distributed on an "AS IS" basis,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the Licence for the specific language governing permissions and
* limitations under the Licence.
*/
#include <sycl/sycl.hpp>
#include "ewGpuNode.hpp"
#include "ewKernels.sycl.hpp"
#ifdef USE_STD_MATH
#include <cmath>
#endif
SYCL_EXTERNAL void waveUpdate(KernelData data, cl::sycl::nd_item<2> item_ct1)
{
Params& dp = data.params;
int i = item_ct1.get_group(0) * item_ct1.get_local_range().get(0) + item_ct1.get_local_id(0) + dp.iMin;
int j = item_ct1.get_group(1) * item_ct1.get_local_range().get(1) + item_ct1.get_local_id(1) + dp.jMin;
int ij = data.idx(i,j);
float absH;
/* maybe unnecessary if controlled from outside */
if( i <= dp.iMax && j <= dp.jMax && data.d[ij] != 0 ) {
float hh = data.h[ij] - data.cR1[ij] * ( data.fM[ij] - data.fM[data.le(ij)] + data.fN[ij] * data.cR6[j] - data.fN[data.dn(ij)]*data.cR6[j-1] );
absH = cl::sycl::fabs(hh);
if( absH < dp.sshZeroThreshold ) {
hh = 0.f;
} else if( hh > data.hMax[ij] ) {
data.hMax[ij] = hh;
//hMax[ij] = fmaxf(hMax[ij],h[ij]);
}
if( dp.sshArrivalThreshold && data.tArr[ij] < 0 && absH > dp.sshArrivalThreshold )
data.tArr[ij] = dp.mTime;
data.h[ij] = hh;
}
}
SYCL_EXTERNAL void fluxUpdate(KernelData data, cl::sycl::nd_item<2> item_ct1)
{
Params& dp = data.params;
int i = item_ct1.get_group(0) * item_ct1.get_local_range().get(0) + item_ct1.get_local_id(0) + dp.iMin;
int j = item_ct1.get_group(1) * item_ct1.get_local_range().get(1) + item_ct1.get_local_id(1) + dp.jMin;
int ij = data.idx(i,j);
if( i <= dp.iMax && j <= dp.jMax && data.d[ij] != 0 ) {
float hh = data.h[ij];
if( data.d[data.ri(ij)] != 0 ) {
data.fM[ij] = data.fM[ij] - data.cR2[ij]*(data.h[data.ri(ij)] - hh);
}
if( data.d[data.up(ij)] != 0 )
data.fN[ij] = data.fN[ij] - data.cR4[ij]*(data.h[data.up(ij)] - hh);
}
}
#define SQR(x) ((x) * (x))
#ifdef USE_STD_MATH
#define SQRT(x) std::sqrt(x)
#else
#define SQRT(x) cl::sycl::sqrt(x)
#endif
SYCL_EXTERNAL void waveBoundary(KernelData data, cl::sycl::nd_item<1> item_ct1)
{
KernelData& dt = data;
Params& dp = data.params;
int id = item_ct1.get_group(0) * item_ct1.get_local_range().get(0) + item_ct1.get_local_id(0) + 2;
int ij;
if( dp.jMin <= 2 && id <= dp.nI-1 ) {
ij = dt.idx(id,1);
dt.h[ij] = SQRT( SQR(dt.fN[ij]) + 0.25f*SQR((dt.fM[ij] + dt.fM[dt.le(ij)])) )*dt.cB1[id-1];
if( dt.fN[ij] > 0 ) dt.h[ij] = -dt.h[ij];
}
if( dp.iMin <= 2 && id <= dp.nJ-1 ) {
ij = dt.idx(1,id);
dt.h[ij] = SQRT( SQR(dt.fM[ij]) + 0.25f*SQR((dt.fN[ij] + dt.fN[dt.dn(ij)])) )*dt.cB2[id-1];
if( dt.fM[ij] > 0 ) dt.h[ij] = -dt.h[ij];
}
if( dp.jMax >= dp.nJ - 1 && id <= dp.nI-1 ) {
ij = dt.idx(id,dp.nJ);
dt.h[ij] = SQRT( SQR(dt.fN[dt.dn(ij)]) + 0.25f*SQR((dt.fM[ij] + dt.fM[dt.dn(ij)])) )*dt.cB3[id-1];
if( dt.fN[dt.dn(ij)] < 0 ) dt.h[ij] = -dt.h[ij];
}
if( dp.iMax >= dp.nI -1 && id <= dp.nJ-1 ) {
ij = dt.idx(dp.nI,id);
dt.h[ij] = SQRT( SQR(dt.fM[dt.le(ij)]) + 0.25f*SQR((dt.fN[ij] + dt.fN[dt.dn(ij)])) )*dt.cB4[id-1];
if( dt.fM[dt.le(ij)] < 0 ) dt.h[ij] = -dt.h[ij];
}
if( id == 2 && dp.jMin <= 2 ) {
ij = dt.idx(1,1);
dt.h[ij] = SQRT( SQR(dt.fM[ij]) + SQR(dt.fN[ij]) )*dt.cB1[0];
if( dt.fN[ij] > 0 ) dt.h[ij] = -dt.h[ij];
ij = dt.idx(dp.nI,1);
dt.h[ij] = SQRT( SQR(dt.fM[dt.le(ij)]) + SQR(dt.fN[ij]) )*dt.cB1[dp.nI-1];
if( dt.fN[ij] > 0 ) dt.h[ij] = -dt.h[ij];
}
if( id == 2 && dp.jMin >= dp.nJ - 1 ) {
ij = dt.idx(1,dp.nJ);
dt.h[ij] = SQRT( SQR(dt.fM[ij]) + SQR(dt.fN[dt.dn(ij)]) )*dt.cB3[0];
if( dt.fN[dt.dn(ij)] < 0 ) dt.h[ij] = -dt.h[ij];
ij = dt.idx(dp.nI,dp.nJ);
dt.h[ij] = SQRT( SQR(dt.fM[dt.le(ij)]) + SQR(dt.fN[dt.dn(ij)]) )*dt.cB3[dp.nI-1];
if( dt.fN[dt.dn(ij)] < 0 ) dt.h[ij] = -dt.h[ij];
}
}
SYCL_EXTERNAL void fluxBoundary(KernelData data, cl::sycl::nd_item<1> item_ct1)
{
KernelData& dt = data;
Params& dp = data.params;
int id = item_ct1.get_group(0) * item_ct1.get_local_range().get(0) + item_ct1.get_local_id(0) + 1;
int ij;
if( dp.jMin <= 2 && id <= dp.nI-1 ) {
ij = dt.idx(id,1);
dt.fM[ij] = dt.fM[ij] - dt.cR2[ij]*(dt.h[dt.ri(ij)] - dt.h[ij]);
}
if( dp.iMin <= 2 && id <= dp.nJ ) {
ij = dt.idx(1,id);
dt.fM[ij] = dt.fM[ij] - dt.cR2[ij]*(dt.h[dt.ri(ij)] - dt.h[ij]);
}
if( dp.jMax >= dp.nJ - 1 && id <= dp.nI-1 ) {
ij = dt.idx(id,dp.nJ);
dt.fM[ij] = dt.fM[ij] - dt.cR2[ij]*(dt.h[dt.ri(ij)] - dt.h[ij]);
}
if( dp.iMin <= 2 && id <= dp.nJ-1 ) {
ij = dt.idx(1,id);
dt.fN[ij] = dt.fN[ij] - dt.cR4[ij]*(dt.h[dt.up(ij)] - dt.h[ij]);
}
if( dp.jMin <= 2 && id <= dp.nI ) {
ij = dt.idx(id,1);
dt.fN[ij] = dt.fN[ij] - dt.cR4[ij]*(dt.h[dt.up(ij)] - dt.h[ij]);
}
if( dp.iMax >= dp.nJ - 1 && id <= dp.nJ-1 ) {
ij = dt.idx(dp.nI,id);
dt.fN[ij] = dt.fN[ij] - dt.cR4[ij]*(dt.h[dt.up(ij)] - dt.h[ij]);
}
}
SYCL_EXTERNAL void gridExtend(KernelData data, cl::sycl::nd_item<1> item_ct1)
{
Params& dp = data.params;
int id = item_ct1.get_group(0) * item_ct1.get_local_range().get(0) + item_ct1.get_local_id(0) + 1;
#ifndef USE_LOOP_EXTEND
if ( id >= dp.jMin && id <= dp.jMax ) {
if (cl::sycl::fabs(data.h[data.idx(dp.iMin + 2, id)]) > dp.sshClipThreshold) {
zib::sycl::atomic_inc(&(data.g_MinMax->x()));
}
if (cl::sycl::fabs(data.h[data.idx(dp.iMax - 2, id)]) > dp.sshClipThreshold)
zib::sycl::atomic_inc(&(data.g_MinMax->y()));
}
if ( id >= dp.iMin && id <= dp.iMax ) {
if (cl::sycl::fabs(data.h[data.idx(id, dp.jMin + 2)]) > dp.sshClipThreshold)
zib::sycl::atomic_inc(&(data.g_MinMax->z()));
if (cl::sycl::fabs(data.h[data.idx(id, dp.jMax - 2)]) > dp.sshClipThreshold)
zib::sycl::atomic_inc(&(data.g_MinMax->w()));
}
#else
if( id == 1 ) {
for( int j = dp.jMin; j <= dp.jMax; j++ ) {
if (cl::sycl::fabs(data.h[data.idx(dp.iMin + 2, j)]) > dp.sshClipThreshold) {
data.g_MinMax->x() = 1;
break;
}
}
for( int j = dp.jMin; j <= dp.jMax; j++ ) {
if (cl::sycl::fabs(data.h[data.idx(dp.iMax - 2, j)]) > dp.sshClipThreshold) {
data.g_MinMax->y() = 1;
break;
}
}
for( int i = dp.iMin; i <= dp.iMax; i++ ) {
if (cl::sycl::fabs(data.h[data.idx(i, dp.jMin + 2)]) > dp.sshClipThreshold) {
data.g_MinMax->z() = 1;
break;
}
}
for( int i = dp.iMin; i <= dp.iMax; i++ ) {
if (cl::sycl::fabs(data.h[data.idx(i, dp.jMax - 2)]) > dp.sshClipThreshold) {
data.g_MinMax->w() = 1;
break;
}
}
}
#endif
}