flow 1.3.0
Kokkos cut-cell IBM incompressible Navier-Stokes solver + pnm pore extraction
Loading...
Searching...
No Matches
advance_profile.py
Go to the documentation of this file.
1#!/usr/bin/env python
2"""WO-9b instrument: wall time of advance_scalars on G-perf's 128^3 bed (dt D/h^2 = 1, koren,
3Dirichlet spheres) after 3 flow steps; NS timed advances (env N = cells per axis, NS). The CUDA
4profiler range wraps the timed advances (nsys --capture-range=cudaProfilerApi). On host, run with
5KOKKOS_TOOLS_LIBS = the Kokkos simple kernel timer at NS=0 and NS=k and difference the two tables:
6
7 NS=3 OMP_NUM_THREADS=1 KOKKOS_TOOLS_LIBS=<kp_kernel_timer.so> PYTHONPATH=build_dev \
8 python advance_profile.py > kt3.txt (and NS=0 > kt0.txt)
9 python advance_profile.py diff kt0.txt kt3.txt 3
10"""
11import sys
12if len(sys.argv) > 1 and sys.argv[1] == "diff":
13 import re
14 def parse(p):
15 d = {}; name = None; on = False
16 for line in open(p):
17 if line.startswith("Kernels:"): on = True; continue
18 if not on: continue
19 if line.startswith("- "): name = line[2:].strip(); continue
20 m = re.match(r"\s*\‍((\w+)\‍)\s+([\d.]+)\s+(\d+)", line)
21 if m and name: d[name] = (float(m.group(2)), int(m.group(3))); name = None
22 if line.startswith("Summary"): break
23 return d
24 A, B = parse(sys.argv[2]), parse(sys.argv[3]); n = float(sys.argv[4])
25 rows = []
26 for k in B:
27 t = B[k][0] - A.get(k, (0, 0))[0]; c = B[k][1] - A.get(k, (0, 0))[1]
28 rows.append((t / n * 1e3, c / n, k))
29 rows.sort(reverse=True)
30 tot = sum(r[0] for r in rows)
31 print(f"per advance: {tot:.1f} ms in kernels, {sum(r[1] for r in rows):.0f} launches")
32 for t, c, k in rows[:int(sys.argv[5]) if len(sys.argv) > 5 else 25]:
33 print(f" {t:8.2f} ms {c:8.0f} {k}")
34 sys.exit(0)
35import os, sys, time, math
36sys.path.insert(0, "/home/frankp/Codes/suite/flow-scalar-ibm/tests/study/scalar_ibm")
37sys.path.insert(0, "/home/frankp/Codes/suite/flow-scalar-ibm/tests/python")
38import numpy as np
39import peclet.flow as pf
40import test_scalar_cutcell_gates as g
41n = int(os.environ.get("N", "128"))
42s = pf.Solver((n, n, n), extent=(1.0, 1.0, 1.0))
43s.set_rho(1.0); s.set_mu(1.0); dt = 0.01; s.set_dt(dt)
44R = (0.3 * 3.0 / (4.0 * math.pi)) ** (1.0 / 3.0)
45X, Y, Z = g.grid(s)
46s.set_solid(np.asfortranarray(np.sqrt((X - 0.513) ** 2 + (Y - 0.479) ** 2 + (Z - 0.507) ** 2) - R), cutcell_pressure=True)
47s.set_body_force((30.0, 9.0, 0.0))
48for _ in range(3): s.step()
49h = 1.0 / n
50s.add_scalar("c", diffusivity=h * h / dt, scheme="koren", cutcell=True)
51s.set_scalar_wall("c", "dirichlet", 0.0)
52geo = s.diagnostics.scalar_geometry("c")
53s.set_field("c", np.asfortranarray(np.where(geo["unknown"] > 0.5, 1.0, 0.0)))
54s.step()
55s.advance_scalars(); s.diagnostics.scalar_budget("c")
56import ctypes
57try:
58 cudart = ctypes.CDLL("libcudart.so")
59except OSError:
60 cudart = None
61if cudart: cudart.cudaProfilerStart()
62t0 = time.perf_counter()
63NS = int(os.environ.get("NS", "3"))
64for _ in range(NS):
65 s.advance_scalars(); s.diagnostics.scalar_budget("c")
66t = (time.perf_counter() - t0) / max(NS, 1)
67if cudart: cudart.cudaProfilerStop()
68print(f"advance_scalars {t*1e3:.1f} ms/step, its {s.diagnostics.scalar_census('c')['krylov_iterations']}")