Modern Apps git

← Modern-Apps.git

library:ml: correct the barrier cost figures in the docs

Commit
5f89aefa58fd58ca201047b9b5fb3437336d1bcb
Author
vayun-mathur <[email protected]>
When
2026-09-12 03:09 UTC (2 months ago)
Parents
4b80fc1

Diff

library/ml/src/main/rust/examples/report_barriers.rs
diff --git a/library/ml/src/main/rust/examples/report_barriers.rs b/library/ml/src/main/rust/examples/report_barriers.rsindex 1362f81f1b..cef94c4ee3 100644--- a/library/ml/src/main/rust/examples/report_barriers.rs+++ b/library/ml/src/main/rust/examples/report_barriers.rs@@ -6,9 +6,17 @@ //! //! # Why //!-//! `vulkan::run::Net::record` emits a `vkCmdPipelineBarrier` after **every** op, and on a Tensor-//! G4 that is 74% of a Supertonic utterance — 5,091 ms falling to 1,194 ms with the barriers taken-//! out. See `analysis/maml_vs_litert.md`.+//! `vulkan::run::Net::record` emits a `vkCmdPipelineBarrier` after **every** op, which is+//! expensive — but how expensive is **unmeasured**. The figure this header used to quote (74% of a+//! Supertonic utterance, 5,091 ms falling to 1,194 ms) came from a no-barrier control that+//! delivered 43,008 frames against a correct run's 150,528, so it compared a full utterance+//! against a truncated one and measured output length as much as barrier cost.+//!+//! The one valid same-work comparison available is `narrow` at 2,179 ms against `none` at+//! 1,160 ms, both at 43,008 frames: a 47% delta, at a truncated workload and with a cheaper+//! barrier than the default. Treat that as a lower bound and not as the headline. A real ceiling+//! needs the frame count pinned so both paths do identical work — that is task 11. See+//! `analysis/maml_vs_litert.md` section 6. //! //! There are two ways to spend less on that, and this decides between them before either is //! built:
library/ml/src/main/rust/src/nets/schedule.rs
diff --git a/library/ml/src/main/rust/src/nets/schedule.rs b/library/ml/src/main/rust/src/nets/schedule.rsindex 21487e85e2..fc021084b1 100644--- a/library/ml/src/main/rust/src/nets/schedule.rs+++ b/library/ml/src/main/rust/src/nets/schedule.rs@@ -2,10 +2,19 @@ //! //! [`super::Plan`]'s `ops` field says "each depends on the results of the ones before it", and //! [`crate::vulkan::run::Net::record`] takes it literally: a `vkCmdPipelineBarrier` after every-//! op. That claim is false in general, and it is expensive. Measured on a Tensor G4, removing the-//! barriers from Supertonic's sampler takes it from 5,091 ms to 1,194 ms — **74% of an utterance-//! is the drain between one op and the next**, at about 0.55 ms each. See-//! `analysis/maml_vs_litert.md`.+//! op. That claim is false in general, and serialising every op is expensive — but the **size of+//! the effect is unmeasured**. This header used to say 5,091 ms falling to 1,194 ms, 74% of an+//! utterance at about 0.55 ms a barrier. That came from a no-barrier control which delivered+//! 43,008 frames against a correct run's 150,528, so it set a full utterance against a truncated+//! one; the comparison captures output length at least as much as barrier cost.+//!+//! The one valid same-work pair is `narrow` at 2,179 ms against `none` at 1,160 ms, both at+//! 43,008 frames — a 47% delta, at a truncated workload and with a barrier cheaper than the+//! default, so it is a lower bound. A valid ceiling needs the frame count pinned so both paths do+//! identical work; that is task 11. See `analysis/maml_vs_litert.md` section 6.+//!+//! None of which changes what this module is for: whatever a barrier costs, emitting one that is+//! not needed costs all of it for nothing. //! //! This module answers the narrower question the runtime should have been asking: given what each //! op reads and writes, which pairs actually have to be ordered.
library/ml/src/main/rust/src/timing.rs
diff --git a/library/ml/src/main/rust/src/timing.rs b/library/ml/src/main/rust/src/timing.rsindex ce46195646..df815c3591 100644--- a/library/ml/src/main/rust/src/timing.rs+++ b/library/ml/src/main/rust/src/timing.rs@@ -1,10 +1,16 @@ //! Opt-in timing, silent unless it is asked for. //!-//! This runtime's cost is dominated by things that do not show up in a profile of the arithmetic-//! — see `analysis/maml_vs_litert.md`, where 74% of an utterance turned out to be the pipeline-//! barrier between one op and the next — so the numbers have to come from the runtime itself.-//! They are also useless in aggregate: "inference took 5.5 seconds" says nothing, while "the-//! sampler ran 32 times at 158 ms of which 96 ms was barriers" says everything.+//! This runtime's cost is dominated by things that do not show up in a profile of the arithmetic —+//! serialising every op is expensive, though the size of that effect is **unmeasured**: the+//! no-barrier control delivered 43,008 frames against a correct run's 150,528, so it compared a+//! full utterance against a truncated one. The one valid same-work pair, `narrow` 2,179 ms against+//! `none` 1,160 ms at 43,008 frames each, puts it at 47% of a truncated run with a cheaper+//! barrier. See `analysis/maml_vs_litert.md` section 6; pinning the frame count so both paths do+//! identical work is task 11.+//!+//! Either way the numbers have to come from the runtime itself, and they are useless in aggregate:+//! "inference took 5.5 seconds" says nothing, while "the sampler ran 32 times at 158 ms of which+//! 96 ms was barriers" says everything. //! //! Switched on by `MODELRUNNER_TIMING` or `debug.modelrunner.timing`; see [`crate::knobs`] for //! why there are two.