Repository navigation
EWave: the step's numbers worked out on the host in double, no sin, cos, exp, sqrt or tanh on the GPU - #1219
Merged
Merged
Conversation
…t and tanh in float cvcgl_ewave fails on the macOS package lanes (Apple Software Renderer): the GPU window drifts from the CPU one at a steady 4.2e-3 of the RMS height per second of simulated time, the same at dt 0.2 and 0.1, to 3e-2 by step 48 against a 1e-3 bound (#1171, job 131824127881). A per-step error in cos, sin or exp would double its rate when dt halves; a rate off by about 1e-3 (omega = sqrt(g kappa), kappa = k tanh(min(k d, 20))) does not. #1174's macOS package jobs were all cancelled, so it never showed there. The update pass now reads omega, kappa / omega, g / omega and the damping rate from an RGBA32F texture that init() fills in double with the CPU window's formulas (det::tanh), and takes only the cos, sin and exp of a step, so a new dt still costs nothing. On Windows (Intel Arc) cvcgl_ewave passes before and after: step 48 h 1.95e-5 before, 1.92e-5 after; the wall run 5.62e-5 before, 5.60e-5 after.
transfix
enabled auto-merge (squash)
November 13, 2026 23:38
This was referenced Nov 14, 2026
Merged
… no cos/sin/exp on the GPU The first try (fea1efb) moved each mode's rates to a texture worked out in double but left the step's cos, sin and exp in the shader. On macOS CI (Apple Software Renderer) cvcgl_ewave failed with the same numbers to the digit: h 3.05e-2 at step 48, the wall run 4.36e-2. So the rates were never the problem. A drift that grows per second of simulated time is what a sin or cos off in proportion to its small angle gives. Now the host works out, in double and only when dt or the mask changes, what ewave::prepare and ewave::step work out on the CPU: each mode's 2 x 2 update with its damping (RGBA32F) and each cell's real-space factor (R32F, the beach, the sponge and land). The update and real-space passes are multiply-adds only. A new dt costs that host work and an n^2 upload; the same dt costs nothing more. Windows (Intel Arc): cvcgl_ewave step 48 h 1.92e-5 -> 8.80e-6, phi -> 9.06e-6; the wall run 5.60e-5 -> 9.62e-6. So Intel's in-shader cos/sin/exp were most of its GPU-CPU difference too.
transfix
added a commit
that referenced
this pull request
Nov 14, 2026
…#1192) Threaded execution Stage S (docs/STATE_EXEC_THREADED.md 4.4; plan state-exec-perf/threaded-impl/S2.md, decisions S2-Q1..Q17). A pick in the async scheduler runs up to slice_steps steps of one process, a run, sharing one step's guards, clock reading and accounting. The default, 1, is the old loop exactly; hosts opt in. Settings: async_scheduler::set_slice(steps, seconds), the tree's state_exec.slice_steps and state_exec.slice_seconds, CVC_EXEC_SLICE_STEPS (read when a scheduler is made, no process-wide copy), and exec_group::options::slice_steps / slice_seconds. Runs: above 1, step_run takes up to slice_steps charged steps, clipped to the run's step budget. - Every step can end the run: a park or status change, max_steps, a post from another thread, a stop, a reap, a better priority level made ready or the runner's own level worsening, a pending signal or watch event, max_messages or max_message_bytes. - The clock is read at run steps 2, 4, 8 and 16, then every 16th. A reading ends the run past slice_seconds (only with a time budget, so steps-only runs stay deterministic), the run's budget, the process's time or CPU half, a due timer, or an async call whose charge is due. - A process with max_step_time or max_memory still takes one step a pick, so Ariadne's residents and actions gain nothing yet; heap accounting per run is a follow-up. - A run charges CPU with each step's cap scaled by its steps, splits its time over step kinds by count, and counts in total_steps_ and the 64-step cycle check. Tests: Slices.SL01-SL18 (the review and skeptic findings each failed first), Groups.OC01 pinned to 1, and state_exec_async_test_slice256 / ariadne_runtime_test_slice256, the whole suites again at CVC_EXEC_SLICE_STEPS=256. The Ariadne one is RUN_SERIAL: an action's 0.1 s cap counts its first half on the wall clock, and parallel ctest jobs used it up in a Debug build. Bench: slice_steps on sched.single.* and limits.*, sched.slice_fair, limits.ariadne, compare --geomean-better, and a CTest pin that steps_total at 256 equals 1. Docs: STATE_EXEC_THREADED.md, the developer guide's section on runs, STATE_EXEC_BENCH.md. Measured: the quiet-window A/B (2026-11-12) passed the runs gate, 44.5% fewer ns/step at 256 than at 1 against the 20% go bar, and steps_total was unchanged everywhere. The 3% timing gates against master were inconclusive (rep noise above 3%) and were accepted as recorded. CI: every required check passed on fa34957. The optional package-macos lanes failed only in master's cvcgl_ewave on Apple's software renderer, which #1219 fixes.
…ates #1194 gave EWave the CPU's symmetric step for no-flux walls (fill, multiply and gather passes) and #1224 gave the update and multiply passes their own sin and cos series. Both rewrote the code this branch changed, so EWave.cpp and EWave.h start from master's and take this branch's change on both paths: - The exact step reads each mode's coefficients (modeCoefficients, as ewave::prepare) and each cell's real-space factor (realFactors, as ewave::update_real) from textures worked out on the host in double. - The symmetric step's multiply pass reads kappa~ and damping_k2's 1 - F (symmetricMultipliers, as ewave::prepare_symmetric, -expm1 for 1 - F), and its gather pass reads the real-space factors for dt_s. - The last pass home only zeroes walls, as before. No pass takes a sin, cos, exp, sqrt or tanh of its own, so #1224's series goes. - Each table is worked out again only when the step, the depth (setDepth) or the mask changes; dt_s is fixed, so the symmetric step pays once. cvcgl_ewave and cvcgl_wake pass on Windows (Intel Arc). Against master's #1224 on the same machine: step 48 (no-flux walls) h 3.14e-6 -> 2.20e-6, phi 2.23e-6 -> 1.53e-6; the zero-wall run 1.04e-5 -> 9.62e-6, the no-flux wall run 5.05e-6 -> 3.63e-6. Step times within run-to-run noise.
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.
EWave's passes now read the step's numbers from tables the host works out in double, as the CPU window (
cvc::ocean::ewave) does. No pass takes asin,cos,exp,sqrtortanhof its own. This covers both of EWave's paths: the exact step and #1194's symmetric step for no-flux walls.Why
cvcgl_ewavefailed on macOS CI's Apple Software Renderer: the GPU window drifted from the CPU one at a steady rate per second of simulated time, reaching 3.05e-2 of the RMS height at step 48 (#1171'spackage-macos / libcvc-release-grpc, job 131824127881). GLSL boundssinandcosonly to an absolute 2^-11 on [-pi, pi], and that renderer uses the slack.#1224 (merged) fixed the failure by giving the update and multiply passes their own
sin/cosseries. This PR takes the rest of the step's arithmetic off the GPU as well, so the GPU result no longer depends on any driver's transcendentals. #1224's series is no longer needed and goes.The change
src/cvcGL/ocean/EWave.cppandEWave.h, three tables worked out on the host in double (cvc::algo::det):modeCoefficients(p, dt):ewave::prepare's 2 × 2 update per mode with its damping, an RGBA32F texture for the exact step's update pass.symmetricMultipliers(p, dts):ewave::prepare_symmetric's kappa~ = 4 sin²(ω dts / 2) / (g dts²) and damping_k2's 1 − F (as −expm1) per mode, an RG32F texture for the symmetric step's multiply pass.realFactors(p, mask, dt):ewave::update_real's beach and sponge factor per cell, exp(−rate dt), 0 on walls, an R32F texture. The exact step's real-space pass reads it for dt, and the symmetric step's gather pass for dt_s.A table is worked out again only when what it depends on changes:
setDepth);setMask).The symmetric step's dt_s is fixed, so it pays once. The exact step at a new dt costs the host work plus an n² RGBA32F and R32F upload, about 1.3 MB at 256². The passes are otherwise unchanged: the same counts, and the same last pass home that zeroes walls.
Checked
cvcgl_ewaveandcvcgl_wakepass on Windows (Intel Arc, Release). Against master's #1224, on the same machine:Step times are within run-to-run noise. The exact step took 1.12 ms GPU in both runs at 256². The no-flux step took 2.41 and 2.61 ms, but the untouched OceanFFT cascade moved by the same ~12% between the two runs. clang-format is clean on the changed lines.
macOS: this PR's earlier version, from before #1194 (1486843, exact step only), passed
cvcgl_ewaveon all four package-macos lanes (ci/full/ewave-gpu-rates, run 43559322708). This merge is pushed toci/full/ewave-gpu-ratestoo; its macOS result is not in yet.History
The first try (fea1efb) moved only each mode's rates (ω, κ/ω, g/ω and the damping rate) to the host, leaving
cos,sinandexpin the shader. macOS gave the same numbers to the digit, which showed the shader'ssin/coswere the cause.