Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 29 additions & 6 deletions benchmarks/vtk_compare/pairs.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
normals, no cached search structures.

``check`` compares the two outputs before any timing is believed: counts
and integrated area or volume for filters that make a dataset, values for
those that make an array.
(cells, and the points the cells use) and integrated area or volume for
filters that make a dataset, values for those that make an array.
"""

from dataclasses import dataclass, field
Expand Down Expand Up @@ -43,6 +43,10 @@ class Pair:
vtk_values: Callable = None # VTK output -> host array
tack_values: Callable = None # Tack result -> host array
others: dict = field(default_factory=dict) # other VTK implementations
# The Tack result is kept with the mesh (``mesh_kept``: ``cell_geometry``), so a
# warm run on the same dataset would read it back: warm runs get a new dataset
# on the same topology, which keeps what the topology derived but not this.
kept_with_mesh: bool = False


def _center(mesh):
Expand Down Expand Up @@ -115,6 +119,8 @@ def _table_clip(grid, mesh, form):


def _geometry_filter(grid, mesh, form):
# Keeps every input point (merging off is the fast path); since 0.7 Tack keeps
# only the points its faces use, so ``check`` counts the points cells use.
from vtkmodules.vtkFiltersGeometry import vtkGeometryFilter

return vtkGeometryFilter(input_data=grid, merging=False, pass_through_cell_ids=False,
Expand Down Expand Up @@ -232,11 +238,16 @@ def _tack():
point_fields=("p",), output="surface"),
Pair("cell volume",
vtk=_cell_size, vtk_values=_cell_array("Volume"),
tack=lambda d, m: _tack()[1].cell_geometry(d)[0], tack_values=_host),
tack=lambda d, m: _tack()[1].cell_geometry(d)[0], tack_values=_host,
kept_with_mesh=True),
# VTK's vtkPointDataToCellData takes the mean of a cell's points; Tack's
# ``project`` into Constant is the integral average by default (since 0.7), a
# quadrature over each cell: ``average="nodes"`` is the mean, like for like.
Pair("point to cell",
vtk=_point_to_cell, vtk_values=_cell_array("p"),
tack=lambda d, m: _tack()[1].project(d, d.fields["p"], _tack()[0].Constant(d)), tack_values=_host,
point_fields=("p",)),
tack=lambda d, m: _tack()[1].project(d, d.fields["p"], _tack()[0].Constant(d),
average="nodes"),
tack_values=_host, point_fields=("p",)),
Pair("cell to point",
vtk=_cell_to_point, vtk_values=_point_array("c"),
tack=lambda d, m: _tack()[1].project(d, d.fields["c"], _tack()[0].H1(d)), tack_values=_host,
Expand Down Expand Up @@ -267,6 +278,18 @@ def _integrated(dataset, what):
return float(cell_data[what][0]) if what in cell_data.keys() else 0.0


def _used_points(dataset):
"""How many distinct points ``dataset``'s cells use: VTK's geometry filter
keeps unused points, Tack's ``extract_surface`` drops them."""
if hasattr(dataset, "polys"):
ids = [np.asarray(c.connectivity_array) for c in
(dataset.verts, dataset.lines, dataset.polys, dataset.strips)
if c.number_of_cells]
else:
ids = [np.asarray(dataset.cells.connectivity_array)] if dataset.number_of_cells else []
return int(np.unique(np.concatenate(ids)).size) if ids else 0


def summary(pair, vtk_output=None, tack_result=None):
"""What the check compares, from one side's output."""
if pair.output == "array":
Expand All @@ -276,7 +299,7 @@ def summary(pair, vtk_output=None, tack_result=None):

vtk_output = dataset_to_vtk(tack_result)
what = "Area" if pair.output == "surface" else "Volume"
return {"cells": vtk_output.number_of_cells, "points": vtk_output.number_of_points,
return {"cells": vtk_output.number_of_cells, "points": _used_points(vtk_output),
what.lower(): _integrated(vtk_output, what)}


Expand Down
16 changes: 12 additions & 4 deletions benchmarks/vtk_compare/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,15 @@
3. VTK is timed as ``Modified(); Update()``, repeated;
4. Tack is timed -- through ``tack.sync()``, since Metal queues launches -- two ways: ``warm`` -- the same dataset each run, so what it
derived on earlier runs (faces, edges, launch groups) is kept, as in a
pipeline -- and ``fresh`` -- a new topology each run, built from the same
pipeline, except a result kept with the mesh itself (``Pair.kept_with_mesh``:
cell volume), timed on a new dataset over the same topology each run -- and ``fresh`` -- a new topology each run, built from the same
arrays outside the timing, holding only what VTK's grid holds.

Each measurement repeats for ``--budget`` seconds (at least 3 and at most 30
runs) and records every time; reports use the median. Converting a VTK grid
runs) and records every time; reports use the median.

Tack's threads come from the configuration (``cpuN`` makes a device of N
threads), so ``TACK_CPU_THREADS`` changes nothing here: use ``--config cpu1``. Converting a VTK grid
to Tack, and shape cells to polyhedra, are timed as ``import``.

Usage:
Expand Down Expand Up @@ -271,8 +275,12 @@ def update(_, f=f):
f.Update()
_record(records, **key, impl=impl, mode="warm", comparable=ok,
times=_measure(update, budget=budget))
_record(records, **key, impl="tack", mode="warm", comparable=ok,
times=_measure(lambda _: run_tack(data), budget=budget))
if pair.kept_with_mesh:
warm = _measure(run_tack, setup=lambda: source.dataset(fields),
budget=budget)
else:
warm = _measure(lambda _: run_tack(data), budget=budget)
_record(records, **key, impl="tack", mode="warm", comparable=ok, times=warm)
_record(records, **key, impl="tack", mode="fresh", comparable=ok,
times=_measure(run_tack,
setup=lambda: source.dataset(fields, fresh=True),
Expand Down
Loading