24#include <Kokkos_Core.hpp>
33using Clock = std::chrono::steady_clock;
36std::map<const void*, std::uint64_t> gLive;
37std::uint64_t gBytes = 0, gPeak = 0;
40bool defaultSpace(
const Kokkos::Profiling::SpaceHandle h) {
41 return std::strcmp(
h.name, Kokkos::DefaultExecutionSpace::memory_space::name()) == 0;
43void onAlloc(
const Kokkos::Profiling::SpaceHandle h,
const char*,
const void* p,
44 const std::uint64_t n) {
45 if (!gArmed || !defaultSpace(h))
49 gPeak = gBytes > gPeak ? gBytes : gPeak;
51void onFree(
const Kokkos::Profiling::SpaceHandle h,
const char*,
const void* p,
52 const std::uint64_t) {
55 auto it = gLive.find(p);
56 if (it == gLive.end())
62double seconds(Clock::time_point t0) {
63 return std::chrono::duration<double>(Clock::now() - t0).count();
67 const std::size_t
n = std::size_t(1) << 26;
68 Kokkos::View<double*>
a(
"a", n),
b(
"b", n),
c(
"c", n);
69 Kokkos::deep_copy(b, 1.0);
70 Kokkos::deep_copy(c, 2.0);
72 for (
int r = 0;
r < 11; ++
r) {
74 const auto t0 = Clock::now();
76 "bench_triad", Kokkos::RangePolicy<>(0, n),
77 KOKKOS_LAMBDA(
const std::size_t i) {
a(i) =
b(i) + 0.5 *
c(i); });
80 best = std::fmin(best, seconds(t0));
82 return 24.0 * (double)n / best / 1e9;
86 const double R = std::cbrt(0.3 * 3.0 / (4.0 * M_PI)) *
n;
87 const double c[3] = {0.513 *
n, 0.479 *
n, 0.507 *
n};
88 std::vector<double>
s((std::size_t)n * n * n);
89 for (
int z = 0;
z <
n; ++
z)
90 for (
int y = 0;
y <
n; ++
y)
91 for (
int x = 0;
x <
n; ++
x) {
92 const double dx =
x + 0.5 -
c[0],
dy =
y + 0.5 -
c[1],
dz =
z + 0.5 -
c[2];
93 s[(std::size_t)x + (std::size_t)
y *
n + (std::size_t)z * n * n] =
94 std::sqrt(dx * dx + dy * dy + dz * dz) -
R;
100int main(
int argc,
char** argv) {
101 Kokkos::initialize(argc, argv);
103 const int n = argc > 1 ? std::atoi(argv[1]) : 128;
104 const int reps = argc > 2 ? std::atoi(argv[2]) : 50;
105 Kokkos::Tools::Experimental::set_allocate_data_callback(onAlloc);
106 Kokkos::Tools::Experimental::set_deallocate_data_callback(onFree);
108 const double bwStream = streamTriad();
109 std::printf(
"G-perf backend %s, n = %d\n", Kokkos::DefaultExecutionSpace::name(), n);
110 std::printf(
" stream triad: %.1f GB/s\n", bwStream);
116 s.setAdvection(
false);
119 const double cells = (double)n * n * n;
121 const auto t0 = Clock::now();
122 (void)s.scalarCutGeometry();
124 const double tGeom = seconds(t0);
125 const std::uint64_t geomBytes = gBytes;
128 const auto t1 = Clock::now();
129 s.addScalar(
"c", 0.7, 1, 50,
true);
130 s.setScalarWall(
"c", 1, 1.0, 0.0, -1);
131 s.setScalarSource(
"c", -0.3);
132 s.solveScalarSteady(
"c");
134 const double tSolve = seconds(t1);
136 auto& sc = s.scalarField(
"c");
138 " memory: geometry record (per solver, shared) %.0f B/cell; one single-phase scalar "
139 "(steady, %d MG levels) live %.0f B/cell, peak %.0f B/cell (bound 300)\n",
140 (
double)geomBytes / cells, sc.cut->mgLevels, (
double)gBytes / cells, (
double)gPeak / cells);
141 std::printf(
" geometry record build: %.3f s\n", tGeom);
142 std::printf(
" first steady solve (assembly + MG build + %d iterations): %.3f s\n",
143 sc.cut->iterations, tSolve);
145 const std::size_t ne = sc.c.extent(0);
146 CCField x(
"bx", ne), y(
"by", ne);
147 Kokkos::deep_copy(x, sc.c);
148 s.scalarCutMatvec(sc, y, x);
150 double best = 1e30, sum = 0.0;
151 for (
int r = 0; r < reps; ++r) {
152 const auto t1 = Clock::now();
153 s.scalarCutMatvec(sc, y, x);
155 const double t = seconds(t1);
156 best = std::fmin(best, t);
159 const double bw = 9.0 * 8.0 * (double)ne / best / 1e9;
161 " matvec: best %.3f ms, mean %.3f ms; effective %.1f GB/s on 72 B per extended cell = "
162 "%.0f %% of the triad (red flag < 50 %%)\n",
163 1e3 * best, 1e3 * sum / reps, bw, 100.0 * bw / bwStream);
flow โ host-facing Kokkos IBM Navier-Stokes solver (drop-in flow-style API).
Kokkos::View< double *, CCMem > CCField
Solver< Staggered > IbmSolver
static std::vector< double > sphereSdf()
Kokkos::View< double *, CCMem > CCField
peclet::flow::IbmSolver IbmSolver
static constexpr double R