flow 1.4.0
Kokkos cut-cell IBM incompressible Navier-Stokes solver + pnm pore extraction
Loading...
Searching...
No Matches
bench_rbgs.cpp
Go to the documentation of this file.
1// Throughput benchmark of the Kokkos RB-GS Poisson sweep (the dominant solver kernel), for the
2// Kokkos-vs-native-CUDA efficiency comparison. Times many full Red-Black sweeps on a fixed grid and
3// reports ns/sweep + effective bandwidth. Pair with tests/cuda_bench/bench_rbgs.cu (identical
4// kernel, plain nvcc) run on the same GPU.
5//
6// `bench_rbgs p0 [rounds] [passes]` instead runs the WO-P0 instruments of
7// doc/vof_projection_cost_design.md §12 (an instrument, not a gate):
8// * t_L, the cost of an empty parallel_for (launch + join) at the running thread count;
9// * one level-0 colour pass at 128x96x64 (x, z periodic, walls in y) with variable-density face
10// weights, in four forms:
11// (a) today's FP64 wrap pass -- the production cutcellSmoothColorFaceWrap;
12// (b) the same pass with the row ends peeled (§9; host only), checked bitwise against (a);
13// (c) D-lite: FP32 face weights, FP64 arithmetic and iterates, flux/correction form (§4.3);
14// (d) the FP32 flux pass, the §4.4.3 bodies exactly as written.
15// The rounds interleave the four forms; min, median and max ms per pass are printed.
16// `bench_rbgs c0 [rounds] [launches]` times the WO-C0 reductions (§6 amendment 1): the level-0
17// dot r.z over the inner 128x96x64 cells (all-fluid body, and the AC-masked body with every
18// cell fluid), B2's scalar pencil order (ccReduce3) against the 4-lane order (ccReduce3Lanes),
19// interleaved; min/median microseconds per launch and the relative difference of the two sums.
20// The coefficients are a DOCUMENTED SYNTHETIC field, not a solver state: rho = 1 (liquid) and
21// rho = 0.02 inside 24 spheres of radius 6 cells (a smoothed one-cell interface), the staggered
22// c_f = open_f * rho0 / rho_f with the arithmetic face mean and rho0 = 1 (buildRhoCoeff), open = 1
23// except the two y-wall faces (open 0), metric gf = 1. Run it at OMP_NUM_THREADS=1, 8 and 24.
24#include <algorithm>
25#include <cmath>
26#include <cstdio>
27#include <cstdlib>
28#include <cstring>
29#include <Kokkos_Core.hpp>
30#include <vector>
31
32#include "mac_cutcell_mg.hpp"
33#include "mac_stencils.hpp"
34
35namespace pf = peclet::flow;
36
37namespace p0bench {
38
39using VReal = float; // the FP32 V-cycle data type of §4.4.2 (instrument copy)
40using FV = Kokkos::View<VReal*, pf::CCMem>;
41using FVC = Kokkos::View<const VReal*, pf::CCMem>;
42
43int runRbgs(int N, int K) {
44 const int g = 1;
45 pf::I3 e{N + 2 * g, N + 2 * g, N + 2 * g}, og{0, 0, 0};
46 const std::size_t n = (std::size_t)e.x * e.y * e.z;
47 pf::SField phi("phi", n), d("d", n);
48 Kokkos::deep_copy(phi, 1.0);
49 Kokkos::deep_copy(d, 0.5);
50
51 // warmup
52 for (int i = 0; i < 10; ++i)
53 pf::poisSweep(phi, pf::SConst(d), e, og, g);
54 Kokkos::fence();
55
56 double best = 1e30;
57 for (int rep = 0; rep < 5; ++rep) {
58 Kokkos::Timer t;
59 for (int i = 0; i < K; ++i)
60 pf::poisSweep(phi, pf::SConst(d), e, og, g);
61 Kokkos::fence();
62 double ms = t.seconds() * 1e3;
63 if (ms < best)
64 best = ms;
65 }
66 const double ns_per_sweep = best * 1e6 / K;
67 const double cells = (double)N * N * N;
68 const double ns_per_cell = ns_per_sweep / cells;
69 const double gbps =
70 cells * 64.0 / (ns_per_sweep); // 64 B/cell (6 nbr + d + write), bytes/ns = GB/s
71 std::printf("KOKKOS N=%d sweeps=%d : %.3f ns/sweep, %.4f ns/cell, %.1f GB/s (exec %s)\n", N, K,
72 ns_per_sweep, ns_per_cell, gbps, Kokkos::DefaultExecutionSpace::name());
73 return 0;
74}
75
76constexpr bool kHost = std::is_same_v<pf::CCMem, Kokkos::HostSpace>;
77
78// (b) The peeled FP64 wrap pass of §9: per row the y/z neighbour offsets once, the first and last
79// cell of the row scalar with ccWrapNbrs (today's body), the interior with i +- 1. Host only.
80template <class Exec = pf::CCExec>
82 pf::FPC AFZ, pf::C3 e, pf::C3 n, pf::C3 og, int g, int color) {
83 if constexpr (std::is_same_v<typename Exec::memory_space, Kokkos::HostSpace>) {
84 const int nyi = e.y - 2 * g, nzi = e.z - 2 * g;
85 auto pencil = [=](long t) {
86 const int ly = g + (int)(t % nyi), lz = g + (int)(t / nyi);
87 const long sx = 1, sy = e.x, sz = (long)e.x * e.y;
88 const int P = (color + og.x + og.y + ly + og.z + lz) & 1;
89 const int lx0 = g + ((P ^ (g & 1)) & 1), lxLast = g + n.x - 1;
90 const long dym = (ly == g) ? (long)(n.y - 1) * sy : -sy;
91 const long dyp = (ly == g + n.y - 1) ? -(long)(n.y - 1) * sy : sy;
92 const long dzm = (lz == g) ? (long)(n.z - 1) * sz : -sz;
93 const long dzp = (lz == g + n.z - 1) ? -(long)(n.z - 1) * sz : sz;
94 const long row = (long)ly * sy + (long)lz * sz;
95 auto scalar = [&](int lx) {
96 const long i = (long)lx + row;
97 const pf::CcNbrs w = pf::ccWrapNbrs(lx, ly, lz, n, g, i, sy, sz);
98 pf::cutcellSmoothFaceCell(phi, b, AC, AFX, AFY, AFZ, i, sx, sy, sz, w.xp, w.xm, w.yp, w.ym,
99 w.zp, w.zm);
100 };
101 int lo = lx0;
102 if (lo == g) {
103 scalar(lo);
104 lo += 2;
105 }
106 const bool lastIsColour = ((lxLast - lx0) & 1) == 0;
107 const int hi = lastIsColour ? lxLast : lxLast + 1; // exclusive
109 for (int lx = lo; lx < hi; lx += 2) {
110 const long i = (long)lx + row;
111 pf::cutcellSmoothFaceCell(phi, b, AC, AFX, AFY, AFZ, i, sx, sy, sz, i + 1, i - 1, i + dyp,
112 i + dym, i + dzp, i + dzm);
113 }
114 if (lastIsColour && lxLast > lx0)
115 scalar(lxLast);
116 };
117 Kokkos::parallel_for("bench::smooth_peeled", Kokkos::RangePolicy<Exec>(0, (long)nyi * nzi),
118 pencil);
119 }
120}
121
122// (b) == (a) bitwise check (host only).
123template <class Exec = pf::CCExec>
125 pf::FPC AFY, pf::FPC AFZ, pf::C3 e, pf::C3 n, pf::C3 og, int g) {
126 if constexpr (std::is_same_v<typename Exec::memory_space, Kokkos::HostSpace>) {
127 for (int c = 0; c < 2; ++c) {
128 pf::cutcellSmoothColorFaceWrap(xa, b, AC, AFX, AFY, AFZ, e, n, og, g, c);
129 smoothPeeledFp64(xb, b, AC, AFX, AFY, AFZ, e, n, og, g, c);
130 }
131 long ndiff = 0;
132 for (long i = 0; i < (long)xa.extent(0); ++i)
133 ndiff += std::memcmp(&xa(i), &xb(i), sizeof(double)) != 0;
134 std::printf("P0 (b) peeled vs (a) production after 2 passes: %ld differing cells -> %s\n",
135 ndiff, ndiff == 0 ? "BITWISE" : "DIFFERS");
136 }
137}
138
139// (c) D-lite cell: FP32 faces, FP64 arithmetic and iterates, flux/correction form.
140template <class XV, class BV, class WV>
141KOKKOS_INLINE_FUNCTION void smoothLiteCell(const XV& x, const BV& b, const WV& WX, const WV& WY,
142 const WV& WZ, long i, long sx, long sy, long sz,
143 const pf::CcNbrs& w) {
144 const double D = (((((double)WX(i + sx) + (double)WX(i)) + (double)WY(i + sy)) + (double)WY(i)) +
145 (double)WZ(i + sz)) +
146 (double)WZ(i);
147 if (D == 0.0)
148 return;
149 const double xi = x(i);
150 const double q = (double)WX(i) * (xi - x(w.xm)) + (double)WX(i + sx) * (xi - x(w.xp)) +
151 (double)WY(i) * (xi - x(w.ym)) + (double)WY(i + sy) * (xi - x(w.yp)) +
152 (double)WZ(i) * (xi - x(w.zm)) + (double)WZ(i + sz) * (xi - x(w.zp));
153 x(i) = xi + (b(i) - q) / D;
154}
155
156// (d) The FP32 flux pass, §4.4.3 verbatim.
157template <class XV, class BV, class WV>
158KOKKOS_INLINE_FUNCTION void smoothFp32Cell(const XV& x, const BV& b, const WV& WX, const WV& WY,
159 const WV& WZ, long i, long sx, long sy, long sz,
160 const pf::CcNbrs& w) {
161 const VReal D = ((((WX(i + sx) + WX(i)) + WY(i + sy)) + WY(i)) + WZ(i + sz)) + WZ(i);
162 if (D == 0.0f)
163 return;
164 const VReal xi = x(i);
165 const VReal q = WX(i) * (xi - x(w.xm)) + WX(i + sx) * (xi - x(w.xp)) + WY(i) * (xi - x(w.ym)) +
166 WY(i + sy) * (xi - x(w.yp)) + WZ(i) * (xi - x(w.zm)) +
167 WZ(i + sz) * (xi - x(w.zp));
168 x(i) = xi + (b(i) - q) / D;
169}
170
171template <bool Fp32, class XV, class BV, class WV>
172KOKKOS_INLINE_FUNCTION void fluxCell(const XV& x, const BV& b, const WV& WX, const WV& WY,
173 const WV& WZ, long i, long sx, long sy, long sz,
174 const pf::CcNbrs& w) {
175 if constexpr (Fp32)
176 smoothFp32Cell(x, b, WX, WY, WZ, i, sx, sy, sz, w);
177 else
178 smoothLiteCell(x, b, WX, WY, WZ, i, sx, sy, sz, w);
179}
180
181// One colour pass of a flux-form body in the production wrap launch forms (host pencil, device
182// MDRange with the colour test), so (c)/(d) differ from (a) only in their bodies and operands.
183template <bool Fp32, class XV, class BV>
184void smoothFluxPass(XV x, BV b, FVC WX, FVC WY, FVC WZ, pf::C3 e, pf::C3 n, pf::C3 og, int g,
185 int color) {
186 pf::CCExec space;
187 if (kHost) { // a plain if: nvcc rejects first captures inside if-constexpr
188 const int nyi = e.y - 2 * g, nzi = e.z - 2 * g;
189 auto pencil = KOKKOS_LAMBDA(long t) {
190 const int ly = g + (int)(t % nyi), lz = g + (int)(t / nyi);
191 const long sx = 1, sy = e.x, sz = (long)e.x * e.y;
192 const int P = (color + og.x + og.y + ly + og.z + lz) & 1;
194 for (int lx = g + ((P ^ (g & 1)) & 1); lx < e.x - g; lx += 2) {
195 const long i = (long)lx + (long)ly * sy + (long)lz * sz;
196 const pf::CcNbrs w = pf::ccWrapNbrs(lx, ly, lz, n, g, i, sy, sz);
197 fluxCell<Fp32>(x, b, WX, WY, WZ, i, sx, sy, sz, w);
198 }
199 };
200 Kokkos::parallel_for("bench::smooth_flux",
201 Kokkos::RangePolicy<pf::CCExec>(space, 0, (long)nyi * nzi), pencil);
202 } else {
203 using MD = pf::MDRange3<pf::CCExec>;
204 Kokkos::parallel_for(
205 "bench::smooth_flux", MD(space, {g, g, g}, {e.x - g, e.y - g, e.z - g}),
206 KOKKOS_LAMBDA(int lx, int ly, int lz) {
207 if (((og.x + lx + og.y + ly + og.z + lz) & 1) != color)
208 return;
209 const long sx = 1, sy = e.x, sz = (long)e.x * e.y;
210 const long i = (long)lx + (long)ly * sy + (long)lz * sz;
211 const pf::CcNbrs w = pf::ccWrapNbrs(lx, ly, lz, n, g, i, sy, sz);
212 fluxCell<Fp32>(x, b, WX, WY, WZ, i, sx, sy, sz, w);
213 });
214 }
215}
216
217void loadavg(const char* tag) {
218 FILE* f = std::fopen("/proc/loadavg", "r");
219 char buf[128] = {0};
220 if (f) {
221 if (!std::fgets(buf, sizeof buf, f))
222 buf[0] = 0;
223 std::fclose(f);
224 }
225 std::printf("P0 %s loadavg %s", tag, buf[0] ? buf : "?\n");
226}
227
228struct Stat {
229 double mn, med, mx;
230};
231Stat stats(std::vector<double> v) {
232 std::sort(v.begin(), v.end());
233 return {v.front(), v[v.size() / 2], v.back()};
234}
235
236int runP0(int rounds, int passes) {
237 const int conc = pf::CCExec().concurrency();
238 std::printf("P0 exec %s concurrency %d rounds %d passes/round %d\n", pf::CCExec::name(), conc,
239 rounds, passes);
240 loadavg("start");
241
242 // ---- t_L: empty parallel_for (launch + join), RangePolicy over `conc` and over 6144 rows ----
243 for (long len : {(long)conc, 6144L}) {
244 std::vector<double> us;
245 const int K = 2000;
246 for (int r = 0; r < rounds; ++r) {
247 Kokkos::fence();
248 Kokkos::Timer t;
249 for (int k = 0; k < K; ++k) {
250 Kokkos::parallel_for("bench::empty", Kokkos::RangePolicy<pf::CCExec>(0, len),
251 KOKKOS_LAMBDA(long){});
252 Kokkos::fence();
253 }
254 us.push_back(t.seconds() * 1e6 / K);
255 }
256 const Stat s = stats(us);
257 std::printf("P0 t_L empty parallel_for len %ld: min %.2f med %.2f max %.2f us/launch\n", len,
258 s.mn, s.med, s.mx);
259 }
260
261 // ---- the level-0 pass ----
262 const int g = 1;
263 const pf::C3 n{128, 96, 64}, e{n.x + 2, n.y + 2, n.z + 2}, og{0, 0, 0};
264 const long ne = (long)e.x * e.y * e.z;
265 std::vector<double> rho(ne), ox(ne), oy(ne), oz(ne), bh(ne, 0.0), xh(ne, 0.0);
266 auto wrap = [](int l, int nn) { return ((l - 1) % nn + nn) % nn; }; // ghost -> inner coord
267 // 24 bubbles on a fixed pseudo-random lattice (deterministic LCG).
268 unsigned long long s = 12345;
269 auto urand = [&s]() {
270 s = s * 6364136223846793005ULL + 1442695040888963407ULL;
271 return (double)(s >> 11) * (1.0 / 9007199254740992.0);
272 };
273 std::vector<double> cx, cy, cz;
274 for (int k = 0; k < 24; ++k) {
275 cx.push_back(urand() * n.x);
276 cy.push_back(8 + urand() * (n.y - 16));
277 cz.push_back(urand() * n.z);
278 }
279 for (int lz = 0; lz < e.z; ++lz)
280 for (int ly = 0; ly < e.y; ++ly)
281 for (int lx = 0; lx < e.x; ++lx) {
282 const double X = wrap(lx, n.x) + 0.5, Y = std::clamp(ly - 1, 0, n.y - 1) + 0.5,
283 Z = wrap(lz, n.z) + 0.5;
284 double C = 0; // gas fraction
285 for (int k = 0; k < 24; ++k) {
286 double dx = std::fabs(X - cx[k]), dz = std::fabs(Z - cz[k]);
287 dx = std::min(dx, n.x - dx);
288 dz = std::min(dz, n.z - dz);
289 const double r = std::sqrt(dx * dx + (Y - cy[k]) * (Y - cy[k]) + dz * dz);
290 C = std::max(C, std::clamp(6.5 - r, 0.0, 1.0));
291 }
292 rho[(long)lx + (long)ly * e.x + (long)lz * e.x * e.y] = 1.0 - C + 0.02 * C;
293 }
294 const long sy = e.x, sz = (long)e.x * e.y;
295 for (int lz = 1; lz < e.z; ++lz)
296 for (int ly = 1; ly < e.y; ++ly)
297 for (int lx = 1; lx < e.x; ++lx) {
298 const long i = (long)lx + ly * sy + lz * sz;
299 ox[i] = 1.0 / (0.5 * (rho[i] + rho[i - 1]));
300 oy[i] = (ly == 1 || ly == n.y + 1) ? 0.0 : 1.0 / (0.5 * (rho[i] + rho[i - sy]));
301 oz[i] = 1.0 / (0.5 * (rho[i] + rho[i - sz]));
302 }
303 for (int lz = 1; lz <= n.z; ++lz)
304 for (int ly = 1; ly <= n.y; ++ly)
305 for (int lx = 1; lx <= n.x; ++lx) {
306 const long i = (long)lx + ly * sy + lz * sz;
307 bh[i] = urand() - 0.5;
308 xh[i] = urand() - 0.5;
309 }
310 auto up = [ne](const std::vector<double>& h, const char* nm) {
311 pf::CCField d(nm, ne);
312 auto m = Kokkos::create_mirror_view(d);
313 for (long i = 0; i < ne; ++i)
314 m(i) = h[i];
315 Kokkos::deep_copy(d, m);
316 return d;
317 };
318 pf::CCField dox = up(ox, "ox"), doy = up(oy, "oy"), doz = up(oz, "oz"), b = up(bh, "b"),
319 x0 = up(xh, "x0");
320 pf::FPV AC("AC", ne), AFX("AFX", ne), AFY("AFY", ne), AFZ("AFZ", ne);
321 pf::buildCutcellOpFace(AC, AFX, AFY, AFZ, pf::CCConst(dox), pf::CCConst(doy), pf::CCConst(doz), e,
322 g, 1.0, 1.0, 1.0);
323 FV WX("WX", ne), WY("WY", ne), WZ("WZ", ne), xf("xf", ne), bf("bf", ne);
324 Kokkos::parallel_for(
325 "bench::fp32_data", Kokkos::RangePolicy<pf::CCExec>(0, ne), KOKKOS_LAMBDA(long i) {
326 WX(i) = static_cast<VReal>(dox(i) * 1.0);
327 WY(i) = static_cast<VReal>(doy(i) * 1.0);
328 WZ(i) = static_cast<VReal>(doz(i) * 1.0);
329 xf(i) = static_cast<VReal>(x0(i));
330 bf(i) = static_cast<VReal>(b(i));
331 });
332 pf::CCField xa("xa", ne), xb("xb", ne), xc("xc", ne);
333 Kokkos::deep_copy(xa, x0);
334 Kokkos::deep_copy(xb, x0);
335 Kokkos::deep_copy(xc, x0);
336 Kokkos::fence();
337
338 // (b) == (a) bitwise after two colour passes from the same start (host).
339 checkPeeled(xa, xb, pf::CCConst(b), pf::FPC(AC), pf::FPC(AFX), pf::FPC(AFY), pf::FPC(AFZ), e, n,
340 og, g);
341
342 const char* names[4] = {"(a) fp64 wrap (production)", "(b) fp64 peeled", "(c) D-lite fp32 faces",
343 "(d) fp32 flux"};
344 std::vector<double> ms[4];
345 auto pass = [&](int v, int c) {
346 switch (v) {
347 case 0:
349 pf::FPC(AFZ), e, n, og, g, c);
350 break;
351 case 1:
352 smoothPeeledFp64(xb, pf::CCConst(b), pf::FPC(AC), pf::FPC(AFX), pf::FPC(AFY), pf::FPC(AFZ),
353 e, n, og, g, c);
354 break;
355 case 2:
356 smoothFluxPass<false>(xc, pf::CCConst(b), FVC(WX), FVC(WY), FVC(WZ), e, n, og, g, c);
357 break;
358 default:
359 smoothFluxPass<true>(xf, FVC(bf), FVC(WX), FVC(WY), FVC(WZ), e, n, og, g, c);
360 }
361 };
362 for (int v = 0; v < 4; ++v) // warm-up
363 for (int k = 0; k < 4; ++k)
364 if (kHost || v != 1)
365 pass(v, k & 1);
366 Kokkos::fence();
367 for (int r = 0; r < rounds; ++r)
368 for (int v = 0; v < 4; ++v) {
369 if (!kHost && v == 1)
370 continue;
371 Kokkos::fence();
372 Kokkos::Timer t;
373 for (int k = 0; k < passes; ++k)
374 pass(v, k & 1);
375 Kokkos::fence();
376 ms[v].push_back(t.seconds() * 1e3 / passes);
377 }
378 const double upd = 0.5 * (double)n.x * n.y * n.z;
379 double amin = 0;
380 for (int v = 0; v < 4; ++v) {
381 if (ms[v].empty()) {
382 std::printf("P0 pass %-28s n/a (host-only variant)\n", names[v]);
383 continue;
384 }
385 const Stat st = stats(ms[v]);
386 if (v == 0)
387 amin = st.mn;
388 std::printf(
389 "P0 pass %-28s min %.4f med %.4f max %.4f ms/pass | %.3f ns/updated cell | (a)/this %.3f\n",
390 names[v], st.mn, st.med, st.mx, st.mn * 1e6 / upd, amin / st.mn);
391 }
392 loadavg("end");
393 return 0;
394}
395
396// WO-C0 instrument: the dot r.z in B2's order (ccReduce3) vs the 4-lane order (ccReduce3Lanes).
397int runC0(int rounds, int launches) {
398 const int conc = pf::CCExec().concurrency();
399 std::printf("C0 exec %s concurrency %d rounds %d launches/round %d\n", pf::CCExec::name(), conc,
400 rounds, launches);
401 loadavg("start");
402 const int g = 1;
403 const pf::C3 n{128, 96, 64}, e{n.x + 2 * g, n.y + 2 * g, n.z + 2 * g};
404 const long N = (long)e.x * e.y * e.z;
405 pf::CCField r("r", N), z("z", N);
406 pf::FPV ac("ac", N);
407 auto hr = Kokkos::create_mirror_view(r), hz = Kokkos::create_mirror_view(z);
408 auto ha = Kokkos::create_mirror_view(ac);
409 unsigned s = 12345u;
410 for (long i = 0; i < N; ++i) {
411 s = s * 1664525u + 1013904223u;
412 hr(i) = (double)(s >> 8) / 16777216.0 - 0.5;
413 s = s * 1664525u + 1013904223u;
414 hz(i) = (double)(s >> 8) / 16777216.0 - 0.5;
415 ha(i) = 1.0;
416 }
417 Kokkos::deep_copy(r, hr);
418 Kokkos::deep_copy(z, hz);
419 Kokkos::deep_copy(ac, ha);
420 const pf::C3 lo{g, g, g}, hi{e.x - g, e.y - g, e.z - g};
421 auto all = KOKKOS_LAMBDA(int x, int y, int zc, double& acc) {
422 const long i = (long)x + (long)y * e.x + (long)zc * (long)e.x * e.y;
423 acc += r(i) * z(i);
424 };
425 auto msk = KOKKOS_LAMBDA(int x, int y, int zc, double& acc) {
426 const long i = (long)x + (long)y * e.x + (long)zc * (long)e.x * e.y;
427 if (ac(i) > 1e-30f)
428 acc += r(i) * z(i);
429 };
430 const char* names[4] = {"all-fluid B2 (ccReduce3)", "all-fluid 4-lane", "masked B2 (ccReduce3)",
431 "masked 4-lane"};
432 std::vector<double> us[4];
433 double val[4] = {0, 0, 0, 0};
434 for (int rd = 0; rd < rounds; ++rd)
435 for (int v = 0; v < 4; ++v) {
436 Kokkos::fence();
437 Kokkos::Timer t;
438 for (int k = 0; k < launches; ++k) {
439 double d = 0;
440 if (v == 0)
441 pf::ccReduce3("c0_b2", lo, hi, all, d);
442 else if (v == 1)
443 pf::ccReduce3Lanes("c0_lanes", lo, hi, all, d);
444 else if (v == 2)
445 pf::ccReduce3("c0_b2m", lo, hi, msk, d);
446 else
447 pf::ccReduce3Lanes("c0_lanesm", lo, hi, msk, d);
448 val[v] = d;
449 }
450 Kokkos::fence();
451 us[v].push_back(t.seconds() * 1e6 / launches);
452 }
453 for (int v = 0; v < 4; ++v) {
454 const Stat st = stats(us[v]);
455 const Stat s0 = stats(us[v & 2]);
456 std::printf("C0 %-26s min %.2f med %.2f max %.2f us/launch | this/B2 (min) %.3f | sum %.17g\n",
457 names[v], st.mn, st.med, st.mx, st.mn / s0.mn, val[v]);
458 }
459 std::printf("C0 rel diff lanes vs B2: all %.3e masked %.3e\n",
460 std::fabs(val[1] - val[0]) / std::fabs(val[0]),
461 std::fabs(val[3] - val[2]) / std::fabs(val[2]));
462 loadavg("end");
463 return 0;
464}
465
466} // namespace p0bench
467
468int main(int argc, char** argv) {
469 Kokkos::initialize(argc, argv);
470 int rc = 0;
471 if (argc > 1 && std::strcmp(argv[1], "c0") == 0) {
472 rc = p0bench::runC0(argc > 2 ? std::atoi(argv[2]) : 7, argc > 3 ? std::atoi(argv[3]) : 200);
473 } else if (argc > 1 && std::strcmp(argv[1], "p0") == 0) {
474 rc = p0bench::runP0(argc > 2 ? std::atoi(argv[2]) : 5, argc > 3 ? std::atoi(argv[3]) : 40);
475 } else {
476 rc = p0bench::runRbgs((argc > 1) ? std::atoi(argv[1]) : 128,
477 (argc > 2) ? std::atoi(argv[2]) : 200);
478 }
479 Kokkos::finalize();
480 return rc;
481}
#define PECLET_FLOW_OMP_SIMD
flow — portable (Kokkos) geometric multigrid for the cut-cell (variable-openness) pressure Poisson.
flow — portable (Kokkos) MAC stencil operators: Red-Black Gauss-Seidel smoothers + divergence.
int runRbgs(int N, int K)
void fluxCell(const XV &x, const BV &b, const WV &WX, const WV &WY, const WV &WZ, long i, long sx, long sy, long sz, const pf::CcNbrs &w)
void smoothLiteCell(const XV &x, const BV &b, const WV &WX, const WV &WY, const WV &WZ, long i, long sx, long sy, long sz, const pf::CcNbrs &w)
void checkPeeled(pf::CCField xa, pf::CCField xb, pf::CCConst b, pf::FPC AC, pf::FPC AFX, pf::FPC AFY, pf::FPC AFZ, pf::C3 e, pf::C3 n, pf::C3 og, int g)
int runP0(int rounds, int passes)
void smoothFluxPass(XV x, BV b, FVC WX, FVC WY, FVC WZ, pf::C3 e, pf::C3 n, pf::C3 og, int g, int color)
void loadavg(const char *tag)
int runC0(int rounds, int launches)
Kokkos::View< VReal *, pf::CCMem > FV
Stat stats(std::vector< double > v)
void smoothFp32Cell(const XV &x, const BV &b, const WV &WX, const WV &WY, const WV &WZ, long i, long sx, long sy, long sz, const pf::CcNbrs &w)
void smoothPeeledFp64(pf::CCField phi, pf::CCConst b, pf::FPC AC, pf::FPC AFX, pf::FPC AFY, pf::FPC AFZ, pf::C3 e, pf::C3 n, pf::C3 og, int g, int color)
Kokkos::View< const VReal *, pf::CCMem > FVC
constexpr bool kHost
float VReal
Kokkos::DefaultExecutionSpace CCExec
Kokkos::MDRangePolicy< Exec, Kokkos::Rank< 3, Kokkos::Iterate::Left, Kokkos::Iterate::Left > > MDRange3
3-D range, x (the first index) fastest (both the tile order and the order within a tile).
Definition policy.hpp:36
Kokkos::View< double *, SMem > SField
void cutcellSmoothFaceCell(const PV &phi, const BV &b, const OpV &AC, const OpV &AFX, const OpV &AFY, const OpV &AFZ, long i, long sx, long sy, long sz, long xp, long xm, long yp, long ym, long zp, long zm)
Kokkos::View< const double *, CCMem > CCConst
void ccReduce3(const char *name, C3 lo, C3 hi, F f, R &&... reducers)
Kokkos::View< const MReal *, CCMem > FPC
void buildCutcellOpFace(OpV AC, OpV AFX, OpV AFY, OpV AFZ, CCConst ox, CCConst oy, CCConst oz, C3 e, int gb, double gfx, double gfy, double gfz)
CcNbrs ccWrapNbrs(int lx, int ly, int lz, C3 n, int g, long i, long sy, long sz)
Kokkos::View< double *, CCMem > CCField
Kokkos::View< MReal *, CCMem > FPV
void ccReduce3Lanes(const char *name, C3 lo, C3 hi, F f, R &&... reducers)
void cutcellSmoothColorFaceWrap(CCField phi, CCConst b, FPC AC, FPC AFX, FPC AFY, FPC AFZ, C3 e, C3 n, C3 og, int g, int color)
Kokkos::View< const double *, SMem > SConst
void poisSweep(SField phi, SConst d, I3 e, I3 og, int g)
static double val(long gi)
Definition symconv.cpp:27
static constexpr int N
static int wrap(int a, int n)
static constexpr double AC
static double urand(int id, int gx, int gy, int gz)