Repository navigation
clip of polyhedra numbers its kept points through a point map (#318, D2) - #464
Open
berkgeveci wants to merge 6 commits into
Open
berkgeveci wants to merge 6 commits into
berkgeveci wants to merge 6 commits into
Conversation
runtime/memory_stats (private) counts the bytes of every array Tack makes, per device, with a peak: live, peak, reset_peak. The count is taken where every backend's allocate_array is called, _allocate and _empty_for_mpi, and given back by a weak reference's callback when the buffer is collected (0.9 us an array; weakref.finalize was 1.4). A view is counted once, with its buffer; memory from outside (wrap_ptr, DLPack, array_from_ptr) not at all; a block Metal's pool or HIP's cache reuses while an array holds it. The CPU, Metal, CUDA, HIP, Level Zero and Warp are counted alike, where the allocator's statistics see the CPU only and the drivers see the pools. The root conftest's peak_memory fixture measures one call's peak with it, for the plan's tests holding each cut filter's peak. The VTK comparison gains a clip pair (vtkTableBasedClipDataSet against td.clip: the same cells and points), and memory.py reports Tack's counted peak beside the allocator's.
Every input point a cell keeps (the corners of a cell kept whole, the input points a cut cell's pieces use, a centroid's members that are input points) is written as its id and marked used in a map of one entry per input point; records are made only for crossings on cut edges, and only those are sorted. Points are numbered as the sort of every point's (low, high) key numbered them: a used point p after the used points before it and the crossings whose low end is below it (a binary search of the sorted crossings), a crossing after the used points up to its low end. One pass renumbers the connectivity and the centroids' members; crossings' slots and centroids' placeholders hold negative markers it leaves alone. The output is the same bits: 117 clips (every shape, 2D and 3D, both sides, values at mesh points, implicit functions, hidden cells, 911 centroid points) hash alike before and after, on the CPU and on Metal. On 5M cells (CPU) the counted peak fell from 364 to 256 MiB on tetrahedra and from 574 to 315 MiB on hexahedra (the count and scan of every cell's outputs are the peak now, D3), and a warm clip from 43 to 30 ms and from 61 to 54 ms. test_clip: clip's peak at most 3 times its output where it keeps most of the mesh, on every backend (4.4 to 5 before, 1.4 to 2.6 now).
…e#318, D2) The polyhedral clip named every point its clipped faces use -- (a, a) for a kept point, (low, high) for a crossing -- and sorted them all, with the caps' iso-vertices. Now a kept face point, and a cap vertex at a point whose value is the level (López's (a, a)), is written as its id and marked used in a map of one entry per input point; only crossings get records, and only those are sorted. Points are numbered as before, by the shapes' clip's kernels (_number_points, _renumber), and polyhedra beside shapes (clip_mixed, through clip_parts) take the same path. The output is the same bits: 32 clips of polyhedral hexahedra and tetrahedra and of a mixed mesh, hidden cells among them, both sides, with 16 cap vertices at mesh points, hash alike before and after, on the CPU and on Metal. Where the clip keeps most of the mesh, its peak fell from 3.8 to 4.5 times its output to 2.5 to 3.4; test_clip_polyhedra holds it to 3.6.
berkgeveci
commented
Nov 15, 2026
| if va >= iso: | ||
| keys[at] = [a, a] | ||
| point_of[at] = a | ||
| used[a] = 1 |
Collaborator
Author
There was a problem hiding this comment.
[P2] Different faces can contain the same point, so parallel _face_keys iterations can write used[a] concurrently. _cap_names has the same issue for repeated cap vertices at line 405. Please mark used atomically at both sites, for example with tack.atomic_max; _extract._kept_cells already uses that for shared points.
Collaborator
Author
There was a problem hiding this comment.
Neighbouring cells share points, so two iterations could store 1 to one entry of the map at once: a data race under the language contract, however equal the stores. Each mark is tack.atomic_max(used, p, 1), as _extract._kept_cells marks, into an i32 map (every backend's atomics take i32), scanned in place where the output's ids are i32 and into a new array where they are i64 (_scanned_map). The 117 clips hash as before; a warm clip of 5M hexahedra takes 59 ms where it took 54 (61 before the map), tetrahedra 31 as before.
Faces sharing a point, and repeated cap vertices at a point, marked its entry of the map from different iterations: each mark is tack.atomic_max(used, p, 1) into an i32 map, scanned by clip's _scanned_map. The 32 polyhedral and mixed clips hash as before.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part of #318: D2 for polyhedra, step 3 of the cut filters' memory plan (
docs/design/plans/cut-filters-memory.md). Stacked on #463 (D2 for shapes), which is stacked on #462 (D1); review the commit after #463's,7b74f665. This merges after #463.What changes
The polyhedral clip (
_clip_polyhedra.py) named every point its clipped faces use,(a, a)for a kept point and(low, high)for a crossing, and sorted them all along with the caps' iso-vertices. Now, as #463 does for shapes:(a, a)._number_points,_renumber).clip_mixed, throughclip_parts) take the same path.The same output
32 clips hash alike before and after, on the CPU and on Metal:
as_polyhedra) and a mixed mesh of hexahedra and polyhedra, one with hidden cells;Measured
Where the clip keeps most of the mesh (27,000 polyhedral hexahedra, 135,000 polyhedral tetrahedra), its peak by #462's count:
Tests
test_a_polyhedral_clip_holds_little_more_than_its_output, at most 3.6 times the output (fails before at 3.76 and 4.04). It runs on the backends with f64, as the module does.test_deprecations' registry test, which fails in any worktree).test_clip.py,test_clip_polyhedra.py,test_mixed_cells.pyandtest_masked_filters.py, 390 passed with the CPU's.D3, clip counting in batches, is next.
🤖 Generated with Claude Code