flow 1.3.0
Kokkos cut-cell IBM incompressible Navier-Stokes solver + pnm pore extraction
Loading...
Searching...
No Matches
test_iteration_order.py
Go to the documentation of this file.
1#!/usr/bin/env python3
2"""Iteration-order guard: every multidimensional kernel iterates x fastest, on every backend.
3
4Fields are x-fastest (I = x + y*nx + z*nx*ny; suite/docs/CONVENTIONS.md). Kokkos' default
5MDRange iteration is Iterate::Left (first index fastest) on CUDA/HIP but Iterate::Right (LAST index
6fastest) on the host backends, so a bare `Kokkos::MDRangePolicy<Exec, Kokkos::Rank<3>>` strides
7against memory on OpenMP/Serial -- measured 2026-09-25 on the bubble column. The policies are the
8aliases `MDRange2` / `MDRange3` of `src/policy.hpp`, which pin Iterate::Left explicitly; this test
9fails if `Kokkos::Rank<` or `MDRangePolicy<` appears in `src/` or `tests/` anywhere else.
10"""
11import pathlib
12import re
13import sys
14
15ROOT = pathlib.Path(__file__).resolve().parents[2]
16ALIAS_HEADER = ROOT / "src" / "policy.hpp"
17BARE = re.compile(r"Kokkos::Rank\s*<|MDRangePolicy\s*<")
18
19
21 offenders = []
22 for top in ("src", "tests"):
23 for path in sorted((ROOT / top).rglob("*")):
24 if path.suffix not in (".hpp", ".cpp", ".h") or path == ALIAS_HEADER:
25 continue
26 for lineno, line in enumerate(path.read_text().splitlines(), 1):
27 if BARE.search(line.split("//", 1)[0]):
28 offenders.append(f"{path.relative_to(ROOT)}:{lineno}: {line.strip()}")
29 assert not offenders, (
30 "bare MDRange policies (backend-default iteration order) found -- use MDRange2/MDRange3 "
31 "from src/policy.hpp:\n " + "\n ".join(offenders)
32 )
33
34
35if __name__ == "__main__":
36 try:
38 except AssertionError as e:
39 print(e)
40 sys.exit(1)
41 print("every MDRange kernel in src/ and tests/ uses the x-fastest aliases [OK]")