Skip to content

fe_lab: jobs as sliced scheduler tasks with a progress bar; LBIE, SDF and resize a slice at a time - #890

Merged
transfix merged 8 commits into
masterfrom
feat/fem-sliced-tasks
Oct 30, 2026
Merged

transfix merged 8 commits into
masterfrom
feat/fem-sliced-tasks

Conversation

@transfix

Copy link
Copy Markdown
Owner

What

fe_lab's long-running work (loading a source, meshing, solving, and its cut-away and slice views) now runs as sliced tasks on the app's state_exec scheduler, and the FEM controls show a progress bar.

  • Single-threaded wasm: each job runs a few milliseconds a frame on the scheduler thread.
  • Native and wasm-mt: each job runs in ~250 ms chunks on the app's background pool.
  • Either way: the page stays live, and fe.progress / fe.phase move while a job runs.

Pieces

  • cvc/core/sliced_task.h: a scheduler runner for any resumable job (step(budget) / phase() / progress() / cancel()). It was moved out of overlay_tasks, and the tf overlays now run on it.
    • CVC_SLICED_THREADING=cooperative runs every automatic task cooperatively, so a native build runs the way single-threaded wasm does.
  • cvc::fem::stepped_solve: Poisson, heat (with snapshots and stop) and modes.
    • Assembly is chunked, and the factorization is an up-looking LDLᵀ with AMD ordering, stepped a column at a time.
    • Results match the one-shot solves to 1e-10, and the eigenvalues to 1e-9.
  • cvc::sdf_stepper: SDF v2's distance transform runs a stage at a time, and SDF_IGL a range of grid nodes at a time. Both are bit-identical to sdf().
  • cvc::mesher_stepper: LBIE's iso, tetrahedralize, hexahedralize and tetrahedralize2 run a slice at a time.
    • The one-shot functions now run the same stepper, so their output is unchanged.
  • cvc::resize_stepper: volume::resize(dimension) a range of voxels at a time, bit-identical to its CPU path.
    • LBIE's (2^n+1)³ resample and fe_lab's source.dim resample both use it.
  • cvc::tet_slicer: slice_tets in pieces, for fe_lab's field-view cut.
  • Ariadne progress: widget: a read-only bar showing bind over [lo, hi] with an overlay text.
    • ImGui draws a progress bar; other backends get a text bar.
    • fe_controls and fem_gallery use it.

Verified

Test suites, all passing:

Suite Result
ariadne_loader 198 pass
ariadne_runtime 188 pass
fem 20 pass
geometry 114 pass, the same 8 skips as before
mtxlib 43 pass
tf_overlay_tasks 15 pass
mesh_contour 13 pass
mesh_ops 39 pass
lbie_mesher 67 pass
volume 30 pass
contour_spectrum 25 pass
cvcgl_ariadne_realize pass
cvcgl_tf_editor pass
cvcgl_tf_binding pass
cvcgl_fe_interval pass

Single-threaded behaviour: the cvcgl programs also pass with CVC_SLICED_THREADING=cooperative. The only exceptions are two checks that assert automatic picks threads natively, which the override switches off by design.

Bit-identity:

  • Stepped and one-shot outputs are compared bit for bit for the SDF (v2, igl), every LBIE entry point and resize_stepper.
  • 25 one-shot meshes of resampled volumes hash the same before and after the resample change.

fem_gallery snapshots: mid-load, the bar reads "distances 39%"; the finished frame shows the Poisson field.

Known limits

  • Remaining long steps: each of these runs once per job, as one step, on the 48³ bunny:

    • reading the mesh file, ~107 ms;
    • libigl's AABB tree build, ~80–107 ms;
    • the tets' boundary (igl::boundary_facets), ~100 ms;
    • quality, locator and constraint setup, 16–26 ms each.

    Everything else is a few ms per call.

  • Not covered here:

    • mesh_lab still uses its async lane.
    • No single-threaded wasm build with the mesher and SDF exists locally or in CI. The cooperative run above stands in for one.

…ce at a time

cvc::schedule_sliced_job (cvc/core/sliced_task.h) runs a cvc::sliced_job as a
state_exec process: cooperative slices per frame where there are no threads,
background-pool chunks where there are. It is the overlay tasks' machinery
made generic, and cvc::tf's overlay tasks now run on it.

cvc::fem::stepped_solve runs solve_poisson, solve_heat and
laplacian_eigenmodes a slice at a time: chunked libigl assembly, a sliced
sparse build, Dirichlet elimination, and a sparse LDL^T over Eigen's AMD
ordering (src/cvc/geometry/sliced_ldlt), column by column. Results match the
one-shot solves to rounding.
DistanceTransform's init and transform become one stage machine (triangle
cells, near-surface marks, the x / y / z line passes, near and far
distances), stepped in budgets of cells and voxels; init() and transform()
run the same loops to the end. cvc::sdf_stepper wraps it with sdf()'s v2
setup and box expansion, and gives sdf()'s volume bit for bit. Also frees
transform1D's scratch on its early return.
The octree's operations -- setting the volume, collapse, QEFs, traversal,
extraction, quality improvement -- become stage machines stepped in budgets
of units (a voxel, an octree cell, a leaf's edge, a vertex of a flow round,
64 entries of an array being filled), and so do Mesher's extractMesh and
qualityImprove, to_geometry, and a new LBIE::mesh_stepper that is do_mesh
and do_mesh_geometry. The loops' bodies are the old ones, moved; the
one-shot calls run the same steps to the end and give the same meshes bit
for bit (93 configurations of iso, tetrahedralize, hexahedralize and
tetrahedralize2 compared with the previous code).

cvc::mesher_stepper makes those steppers from the four meshers' own
arguments, gives their geometry however it is stepped, and rethrows a
failure on every later step. Edge contraction, Joe-Liu, minimal volume and
optimization step a round at a time; resampling a volume that is not
(2^n+1)^3 and converting one to float, property interpolation, and the
FASTCONTOURING and LIBISOCONTOUR extractions are one piece each.

mesh_extract no longer computes B-spline coefficients for normals that
never read them.
A stepped mesh's last steps freed the octree (a QEF is an allocation of its
own) and the mesh at once. The QEFs now go 16 a unit and the arrays one at
a time, and to_geometry_stepper reserves its arrays rather than growing
them. A hexahedral vertex's templates count 256 units, as they cost about
as much. Measured at a budget of 64 on 65^3 volumes, a step's median is a
few microseconds and its 99.9th percentile under half a millisecond; the
rest are a handful of one-off allocations and the resampling of a volume
that is not (2^n+1)^3.
…epper)

The contour spectrum's resumable copy of resizeTrilinearCPU's dimension mode moves to
src/cvc/volume/resample_detail.h, and cvc::resize_stepper drives it a range of output voxels
per step: the same taps, edge rule and conversion, so the voxels are bit-identical to
volume::resize(dimension)'s CPU path.

LBIE's resample to (2^n+1)^3 now uses it (a new "resampling" stage, 4 voxels a unit), so
meshing a 64^3 volume no longer spends one long step resampling it to 65^3. Twenty-five
one-shot meshes of resampled volumes (tetrahedralize with and without geometric flow, iso,
hexahedralize, tetrahedralize2's layer; float spheres at 30^3 and 64^3, a torus, a
non-cubic float and a uchar volume) hash the same before and after.
sdf_stepper steps SDF_IGL too: sdf_igl's AABB tree, then its winding-number hierarchy, a
step each, then the grid's nodes a range per step, the same query points, so the volume is
sdf()'s bit for bit (AlgorithmTest.SDFIglSteppedMatchesOneShot). fem_gallery's 48^3 bunny
SDF had been one 1.3 s step.

A bounded DistanceTransform step now ends where its stage does, so a budget sized for a
cheap stage is not spent in a dear one (a 145 ms step in the tf_binding test), and a near
voxel costs a unit per triangle it tests rather than a flat 20.
…ooperatively

For running a native build the way a single-threaded wasm page runs: every `automatic` task
is sliced on the scheduler thread. Read once from the environment.
…; a progress widget

fe_lab's jobs leave its async lanes for the app's state_exec scheduler (cvc/core/sliced_task.h):
a few milliseconds a frame on the scheduler thread where there are no threads (single-threaded
wasm), ~250 ms chunks on the background pool where there are. Every stage steps:
- load: an SDF source's SDF (cvc::sdf_stepper, v2 or libigl), a volume source's resample to
  source.dim (cvc::resize_stepper);
- mesh: LBIE (cvc::mesher_stepper; tetrahedralize_interval's bounds shared through
  interval_mesher_bounds), then the hex boundary (CutawayStepper), the tets' orientation,
  boundary and quality, a volume source's isosurface (stepped) and the transfer onto the smooth
  surface (a mesh_locator, a range of vertices a step);
- solve: cvc::fem::stepped_solve (Poisson, heat with its snapshots and stop, modes);
- the elements view's cut-away (CutawayStepper) and the field view's cut (cvc::tet_slicer,
  slice_tets a range of tetrahedra at a time).
run_fe_mesh, run_fe_solve and cut_away go; fe.phase publishes the running stage and percent.

Ariadne gains a read-only `progress:` widget: bind's number over [lo, hi] with an overlay's
text, an ImGui progress bar (a text bar on other backends). It precedes `overlay` in the
loader's type scan, since a bar's `overlay:` is its text. fe_controls and fem_gallery show the
job's progress and phase with it.

The realize, tf_binding and fe_interval tests pump the scheduler while they wait on fe_lab's
jobs; all pass threaded and with CVC_SLICED_THREADING=cooperative (save the two checks that
assert automatic picks threads natively). On fem_gallery's 48^3 bunny the longest steps left
are whole-mesh passes run once: reading the mesh file (~107 ms), libigl's AABB tree
(~80-107 ms) and the tets' boundary (~100 ms).
@transfix
transfix enabled auto-merge (squash) October 30, 2026 04:04
@transfix
transfix merged commit 4580d12 into master Oct 30, 2026
18 of 26 checks passed
@transfix
transfix deleted the feat/fem-sliced-tasks branch October 30, 2026 04:37
transfix added a commit that referenced this pull request Oct 30, 2026
…d builds (#908)

LbieMesherTest.SteppedTetrahedralize2MatchesOneShot took 127-230 s in the
Debug package lanes (8.7 s in Release) and went past ctest's 300 s on
loaded runners: master 276887d's libcvc-debug, all 3 tries. Each case
meshes its volume three times (one-shot, whole, sliced). Its siblings
SteppedTetrahedralizeMatchesOneShot and
AlgorithmTest.MesherSteppedMatchesOneShotOnTheBunny, and the older
GeometryTest.QualityImproveTetrahedralMesh, timed out the same way on
master 2d40710's libcvc-debug-grpc.

Unoptimized builds now mesh 17-sample stepped volumes (33 optimized) and
a 16-wide bunny SDF (32), decided by the optimizer as the locks tests
do, not by NDEBUG. With the small sizes forced in a Release build every
check passes (step counts, phases) in 3.5-5x less time.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant