Skip to content

ports: result_job, node keys, generic intrinsics, T7 harness, pycvc jobs (P0b, part 2) - #1113

Merged
transfix merged 10 commits into
masterfrom
p0b/result-job
Nov 11, 2026
Merged

transfix merged 10 commits into
masterfrom
p0b/result-job

Conversation

@transfix

Copy link
Copy Markdown
Owner

Part 2 of phase P0b, the VolumeRover ports' shared pieces (docs/roadmap/VOLROVER-LIBRARY-PORTS-ROADMAP.md §1.4, §1.6, §1.9, §7). Stacked on #1110: merge that first, and this one retargets to master. Additive and non-breaking.

No port exists yet, so each piece is proved on libcvc's own steppers: contour_tree_builder, resize_stepper, and, where libigl is built in, fem::stepped_solve.

What it adds

  • cvc::result_job<R> (cvc/core/result_job.h) runs any resumable stepper as a sliced_job that owns its result.

    • The stepper needs step(budget) and progress(). phase(), status(), done(), a thread-safe cancel() and take() are optional.
    • Once the stepper is done, the job takes the result and destroys the stepper.
    • cancel() works from any thread: the next step ends the job with nothing.
    • A step that throws fails the job: status() is "failed: <message>", and result() rethrows the stepper's own exception.
    • It records step timings.
    • cvc/volume/volume_jobs.h adds contour_tree_job and resize_job.
  • The node keys (cvc/core/job_keys.h) are fe_lab's keys, published from a task's hooks by schedule_published_job:

    • busy, stoppable, status;
    • progress (0–100), phase ("sorting 42%");
    • stats.work_ms, pid.

    fe_lab now writes its job keys through job_keys. Its own WorkTimer still times stats.work_ms, because that spans a chain of commands. sliced_task gains two additive pieces:

    • an on_cancelled hook, for a job stopped through its own cancel();
    • stop_sliced_job(app, pid), which is safe from inside another process's step.
  • The generic intrinsic forms (cvc/core/job_intrinsics.h): a port registers an op from its stepper factory and parameter table, and gets:

    • (<op> ...), which parks the caller on the task (an async function whose work runs by itself, STATE_EXEC_EXCEPTIONS.md 3.12);
    • (<op>-async ...), which returns a future;
    • (<op>-start ... target), which returns the pid at once, publishes the keys under target, and puts the result at target.result;
    • (job.cancel pid), params.defaults and params.check.

    Inputs are data objects or state paths. Parameters are read through the table, and every problem raises ValueError. Tasks carry the caller's owner tag.

  • The T7 harness (src/cvc/tests/resumable_harness.h), for ports to reuse:

    • budgets 1, 64, a seeded random budget and 0 must match the blocking result bit for bit;
    • progress stays in [0, 1] and never falls, and phases are named;
    • a cancel in each phase leaves no result and destroys the stepper;
    • it records the slowest step at the default budget and the stepping overhead;
    • a cooperative frame-time run on an app's scheduler.
  • pycvc (pycvc_jobs.i): PYCVC_RESULT_JOB wraps result_job<R> once, generically: step, done, cancel, progress, phase, status, result, take_result and run. The GIL is released inside each step. It adds pycvc.contour_tree_job, pycvc.resize_job, pycvc.compute_contour_tree and the tree type.

Tests

  • result_job_test:
    • the job's own semantics, on fake steppers (failure, cancel from another thread, a stepper's own status and cancel);
    • T7 on the contour tree (noise; resampled and quantized blobs), on the resize, and on fem Poisson where libigl is built in;
    • the node keys, cooperative and threaded.
  • job_intrinsics_test (T10):
    • each form, cooperative and threaded;
    • bad parameters and inputs, failures, job.cancel, killing the caller or the task, owner tags;
    • an Ariadne button whose on: action calls -start under the default action limits (not raised). Its progress keys rise frame by frame, and the result lands at job.result.
  • test_pycvc_jobs.py, including a check that another Python thread runs during a step.

Both C++ tests join the ports (wasm-mt, node) lane (added in #1110, where param_table_test passes 20/20 under node 22) and the sanitizer lanes. The Python test joins SAN_PY_TESTS.

Checked locally on Windows (MSVC 2022, Release):

  • param_table_test 20/20, result_job_test 18/18, job_intrinsics_test 21/21;
  • pycvc_jobs, pycvc_params, pycvc_smoke, pycvc_algorithm and pycvc_state pass;
  • cvcgl_fe_interval and cvcgl_ariadne_realize pass.

The local deps have no libigl, so the fem T7 case and fe_lab's mesh and solve paths are first exercised here in CI. clang-format 18 reports no changes.

T7 numbers measured locally (Release, desktop):

  • a 4096-unit contour-tree step takes at most 0.3–0.7 ms;
  • stepping costs −2% to +19% against budget 0 (noise, on runs of 2–14 ms);
  • the T10 run took 212 frames and saw 9 distinct progress values.

Notes for review

  • Wiring the ops into every host (cvc exec, pycvc's Exec, Ariadne) belongs to P0a's per-app provider list (§1.3). Until then a host registers them itself; the test uses register_action_intrinsics.
  • SWIG cannot read the C++20 concepts in result_job.h, so pycvc_jobs.i declares the class's members as the header has them. It is the real type, not a facade.

The first of the VolumeRover ports' shared pieces (VOLROVER-LIBRARY-PORTS-ROADMAP.md §1.5, §7
P0b). A params struct is declared once, as a constexpr table of its fields (name, member, unit,
range, doc; an enum's choices from BOOST_DESCRIBE_ENUM), and generic code gives:

- params_validate(): a list of what is wrong (range, NaN, choices, the table's own check);
- params_to_state / params_from_state: one key per field, missing keys seeded with their
  defaults, a value that does not parse reported (not replaced), and the properties written on
  each key (comment, doc, unit, min, max, choices, default, type, access);
- param_cli.h: the CLI flags and their help on boost::program_options;
- param_dsl.h: the DSL dict an intrinsic takes, and the app's registry of tables behind
  (params.defaults name) and (params.check name dict), held in the app's data map;
- pycvc_params.i: PYCVC_PARAM_TABLE, keywords (an unknown one raises TypeError naming the valid
  ones), validate(), from_state / to_state, from_dict / to_dict;
- params_markdown(): the table for a port's docs.

Numbers are written in their shortest round-trip form, so struct -> tree -> struct is exact.
compute_contour_tree's options get the first real table (contour_tree_params.h), which pycvc
wraps as contour_tree_options.

Tests: param_table_test (T8 for the piece itself: every field round-trips through text, the tree,
the CLI and the DSL; defaults seeded, properties written, bad values named; two apps keep their
own registries) and test_pycvc_params.py.

src/cvc/tests/port_tests.cmake lists the ports' googletest binaries. CVC_BUILD_PORT_TESTS builds
only those (with CVC_BUILD_TESTS off), and the new `ports (wasm-mt, node)` CI lane builds them for
wasm-mt and runs each under node (T14). param_table_test also joins the sanitizer lanes.
…obs (P0b, part 2)

The VolumeRover ports' job pieces (VOLROVER-LIBRARY-PORTS-ROADMAP.md §1.4, §1.6, §1.9, §7 P0b),
proved on libcvc's own steppers, since no port exists yet.

- cvc::result_job<R> (cvc/core/result_job.h): any resumable stepper as a sliced_job that owns its
  result. step(budget) takes the result and destroys the stepper once done; cancel() from any
  thread ends it at the next step with nothing; a throwing step fails the job (status "failed:
  <message>", result() rethrows); phase/progress/status for UIs; step timings. make_result_job
  takes the stepper by value or unique_ptr, with take() or a taker. cvc/volume/volume_jobs.h:
  contour_tree_job and resize_job.
- cvc::job_keys and schedule_published_job (cvc/core/job_keys.h): fe_lab's node keys (busy,
  stoppable, status, progress 0-100, phase "<phase> 42%", stats.work_ms, pid) published from a
  task's hooks. fe_lab now writes its job keys through it (its own WorkTimer still times
  stats.work_ms). sliced_task gains on_cancelled (a job stopped through its own cancel()) and
  stop_sliced_job (safe from another process's step).
- cvc/core/job_intrinsics.h: a port registers an op from its stepper factory and parameter table
  and gets (<op> ...) (parks on the task), (<op>-async ...) (a future), (<op>-start ... target)
  (the pid at once; keys under target, the result at target.result), plus (job.cancel pid) and
  params.defaults / params.check. Tasks carry the caller's owner tag; killing the caller or the
  task cancels the job.
- The T7 harness (src/cvc/tests/resumable_harness.h): budgets 1, 64, seeded random and 0 against
  the blocking result bit for bit; monotone progress and named phases; a cancel in each phase
  leaves no result and destroys the stepper; the slowest step at the default budget and the
  stepping overhead recorded; a cooperative frame-time run on an app's scheduler.
- pycvc_jobs.i: PYCVC_RESULT_JOB wraps result_job<R> generically (step, done, cancel, progress,
  phase, status, result, take_result, run), with the GIL released inside each step;
  pycvc.contour_tree_job, pycvc.resize_job, pycvc.compute_contour_tree and the tree.

Tests: result_job_test (the job on fake steppers; T7 on contour_tree_builder, resize_stepper and,
with libigl, fem::stepped_solve; the node keys cooperative and threaded) and job_intrinsics_test
(T10: each form cooperative and threaded, bad parameters and inputs, failures, job.cancel, kills,
owner tags, and an Ariadne button's on: action starting a job with -start under the default action
limits while its progress keys rise frame by frame). Both join the ports (wasm-mt, node) lane and
the sanitizer lanes; test_pycvc_jobs.py joins pycvc's.
The T7 harness's fem::stepped_solve case (result_job_test, built where libigl is) found that a
budget-0 step returned three times before the solve was done. fem.h, like every stepper's
contract, says budget 0 runs to the end. The builder and the factorization stages spend whatever
budget they are handed, so even an unbounded budget ended run() after each of them. With budget 0,
step() now calls run() until the solve is done. A budgeted step is unchanged, and so are its
results: the harness's bit-for-bit comparisons across budgets 1, 64, random and 0 already passed.
@transfix
transfix deleted the branch p0b/param-table November 10, 2026 07:34
@transfix transfix closed this Nov 10, 2026
@transfix transfix reopened this Nov 10, 2026
#1110 merged as ed2e0d5, a squash of this branch's first commit (cc48acd). This merge's tree is
master plus this PR's own changes (cc48acd..49eb2cd), so the PR's diff against master is only
part 2. The conflicts were only where part 2's lines sit next to part 1's (ci.yml's sanitizer and
path-filter lines, port_tests.cmake, src/cvc/CMakeLists.txt, pycvc's CMakeLists.txt and
pycvc_contour_tree.i, docs/PORT_SHARED_PIECES.md).
@transfix
transfix changed the base branch from p0b/param-table to master November 10, 2026 07:41
@transfix
transfix enabled auto-merge (squash) November 10, 2026 07:47
Changing a PR's base doesn't start the pull_request workflow, and this branch's last push came
while its base was #1110's branch, which CI/CD skips. This empty commit starts it.
The clang-tsan lane found a heap-use-after-free in test_pycvc_jobs.py. result() returned a
reference into the job, so `pycvc.contour_tree_job(vol).run()`, which drops its job at once, left
the tree pointing at freed memory (dims_list, nodes.__len__). A reference would dangle the same way
once the result is taken. pycvc_jobs.i now declares result() by value, so SWIG copies it and Python
owns the copy; take_result() still moves it out. New test: a result outlives its job and a take.
@transfix
transfix disabled auto-merge November 10, 2026 20:07
Two failures at 55da976:

- clang-tsan: test_pycvc_jobs.py still read freed memory. tree.nodes was a view into the tree that
  does not keep the tree alive, so len(pycvc.compute_contour_tree(vol).nodes) read it after the
  temporary tree was collected. %naturalvar makes nodes and arcs copies Python owns. The test now
  checks that nodes outlive their tree.
- ports (wasm-mt, node): job_intrinsics_test reaches Ariadne, which links cvc::net's fetch backend,
  and an executable must add -sFETCH=1 for it (src/cvc/CMakeLists.txt). The port tests now link
  with it.
…e OpenMP thread

%naturalvar left tree.nodes a view into the tree (the sanitizers caught
len(pycvc.compute_contour_tree(vol).nodes) reading the freed tree):
nodes and arcs are now properties over getters that return the vectors
by value, which Python owns.

The tsan lanes configure CVC_ENABLE_OPENMP=OFF, yet voxels.cpp's
parallel regions arrive compiled with -fopenmp; libgomp is not built
with TSan, so result_job_test's ResizeStepper reference (voxels::resize)
reported the main thread racing its workers. run.sh sets
OMP_NUM_THREADS=1 for tsan and clang-tsan.
…h once

ImageMagick's own build flags no longer turn OpenMP on. CMake's
FindImageMagick copies pkg-config's CFLAGS_OTHER into the
ImageMagick::* targets' INTERFACE_COMPILE_OPTIONS, and cvcpkg's Linux
ImageMagick (built with configure's default OpenMP) lists -fopenmp
there. Linked PUBLIC, it compiled every cvc source with OpenMP whatever
CVC_ENABLE_OPENMP said, so the sanitizer lanes' OFF still built
voxels.cpp's parallel regions, run on a libgomp TSan cannot see into.
src/cvc/CMakeLists.txt drops the OpenMP flags (with an -Xpreprocessor or
-Xclang that introduces one) from those targets. The previous commit's
OMP_NUM_THREADS=1 in .github/sanitizers/run.sh goes again.

The parallel writers that still wrote through operator(), and so called
preWrite() on every voxel from every thread, now detach the buffer and
dirty the histogram once before the region and write with setValueRaw,
as fillsub and map do: resizeTrilinearCPU (newvox), composite (whose
threads raced to detach a shared buffer) and anisotropicDiffusion
(tempt). preWrite() writes the histogram flag only when it is clean, so
gdtvFilter's gradient (a fresh voxels, already dirty) is written in
parallel without a race on it.
@transfix
transfix merged commit f36edd0 into master Nov 11, 2026
33 checks passed
@transfix
transfix deleted the p0b/result-job branch November 11, 2026 20:30
transfix added a commit that referenced this pull request Nov 11, 2026
Master's #1137 makes the action-intrinsic providers each app's own (an
app.slot table, with a keyed form that replaces in place), and this branch
gives each provider a kind (any / host_proxied / host_only). Both are kept:

- ariadne.h: register_action_intrinsics takes the app, with or without a key,
  and with or without a kind; the forms without a kind register host_only.
- ariadne.cpp: the app's table holds this branch's registered_provider (key,
  provider, kind). install_providers, the placement generation and
  host_only_bindings read the app's table. A keyed registration replaces both
  the provider and its kind.
- The stream (any) and room (host_proxied) providers keep their kinds under
  master's keys. net, AppRuntime's seven providers, nav_compute and the tests
  pass the app.
- Tests: the guards that cleared the process-wide list (isolated_providers_
  cleared, StreamActionGuard, ari_providers_reset) are gone, since each test's
  providers now go with its app; use_host_in_contexts and register_thread_probe
  take the app. Master's job_intrinsics_test (#1113) still called the
  pre-#1137 forms, which do not compile at master's head; it passes the app.
- ci.yml's sanitizer list keeps both sides' tests. The allowlist is the
  three-way merge of both sides (802 lines, cvc 453), rendered by scan.py:
  #1137 dropped the registry's and room_calls.cpp's statics.
- Docs name the app-taking forms.
transfix added a commit that referenced this pull request Nov 12, 2026
#1137 made the action-intrinsic providers each app's own
(register_action_intrinsics(app, ...), clear_action_intrinsics(app)), and
#1113, merged just before it, added job_intrinsics_test with the
process-wide calls, so master's tests no longer build.
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