rt: count the dispatches that run a kernel's emulated-SIMD-group module

For the consumer: Metrics gains emulated_simdgroup_dispatches. It counts the dispatches, direct
and indirect, that ran a kernel's emulated-SIMD-group module. That is a threadgroup whose thread
count is not whole groups of the width the kernel's own module runs only whole groups of
(Interface::multiples, the module's LocalSizeConstraint): 80 threads, say, or 32 on a device of
64-lane subgroups. The field is additive; Metrics has no Metal counterpart, and Metal runs any
threadgroup size at its own SIMD width.

Why: SIMD groups are one of the eight forms a Vulkan query chooses. Nobody has measured how often
a guest takes the slower side, such as a 32-thread group on a card whose subgroups are 64 wide.

How: encoder::decide picks Module::Emulated in its `Some(&width)` branch. The count is not taken
there, because ComputePipelineState::prepare_dispatch decides through it too. It is taken in
ComputeCommandEncoder's dispatch, once the dispatch's commands are recorded: the recording's
result is kept, and an Ok on the emulated module counts once. A dispatch refused on its way, or one
of a zero grid, which records nothing, is not counted. The runtime README's counters list and its
paragraph on the emulated-SIMD-group variant (Compute pipeline states) name the metric. The
signatures table is regenerated.

Test: every_device_runs_simd_groups_at_metals_width dispatches threadgroups of 64, 32, 80 and 1.
Each dispatch must count 1 where its size is not a multiple of every width in the kernel's
interface.multiples, and 0 otherwise.

Verified:
- On its own tree over the previous base (e063482211), compile job m3-max-66965. The signatures
  and refusal-surface checks, fmt, clippy (plain, --cfg m2v_gpu, --cfg m2v_cpu_icd), workspace
  Rustdoc -D warnings and scripts/api-docs all exit 0. The runtime suite on lavapipe: 642 passed
  (1 slow), 3 skipped. Lavapipe's kernel runs no whole-group constraint ("pinned at None, whole
  groups of [], the others on the same module"), so it checks only the zeros.
- On 198cf51e5a with the commit before (tree 6fe94cfc26, the same tree as this commit): compile job
  m3-max-66982, the same checks all exit 0, and the lavapipe runtime suite: 642 passed, 3 skipped.
  The test passed on lavapipe with the zeros alone, as above.
- RX 550, job m3-max-66992 (archive m3-max-66990): the test printed "SIMD-group products checked
  in threadgroups of 64, 32, 80 and 1; pinned at None, whole groups of [64], the others emulated"
  and passed. So the threadgroups of 32, 80 and 1 each counted 1 and that of 64 counted 0. The
  runtime suite: 644 passed, 3 skipped.
This commit is contained in:
Anees Iqbal committed 2026-11-22 02:49:08 -08:00
1 parent 7135c1bc6c
commit 0d0c621ae1
5 files changed
+30 -4

No files matched your search

+4 -2
View File
@@ -208,7 +208,8 @@ the copies of textures over a buffer that no linear image holds are split by cau
out a device address of, each counted at the first (`exported_blocks_addressed`, the exported
block's rule in Textures below), 0 where none went out; the pipeline cache's replacements past its
bound and its blob writes skipped past it (`pipeline_caches_replaced`,
`pipeline_cache_writes_skipped`, The cache directory below);
`pipeline_cache_writes_skipped`, The cache directory below); the dispatches that ran a kernel's
emulated-SIMD-group module (`emulated_simdgroup_dispatches`, Compute pipeline states below);
`gauges()` are live counts per kind of resource, every one zero after teardown, and
`handles_out`, 1 while a handle of the device is out (Teardown). They are relaxed atomics, always
on. What an encoder's commands count arrives when the encoder ends.
@@ -2590,7 +2591,8 @@ while the driver's exit handler waited on a lock, with every runtime thread alre
80 or of 1 thread, or of 32 on a device of 64-lane subgroups) runs it at its own size, the last
SIMD group partly filled, as Metal runs it. The state's creation lowers it, through the cache
directory, whether or not a dispatch needs it. In a threadgroup of one thread the module's
exchanges pass no barrier.
exchanges pass no barrier. `Metrics::emulated_simdgroup_dispatches` counts the dispatches that
ran it.
- The dispatch region (two `uvec4`) gives every direct dispatch's kernel Metal's grid: its first
threadgroup (0, or a split piece's), the threadgroup size packed as
`(x-1) | (y-1) << 10 | (z-1) << 20`, and Metal's threads per grid; an indirect dispatch pushes a
@@ -212,6 +212,8 @@ pub(crate) enum Metric {
DispatchesWithoutEffects,
/// [`Metrics::private_arena_dispatches`].
PrivateArenaDispatches,
/// [`Metrics::emulated_simdgroup_dispatches`].
EmulatedSimdgroupDispatches,
/// [`Metrics::private_arena_pieces`].
PrivateArenaPieces,
/// [`Metrics::private_arena_blocks`].
@@ -300,6 +302,7 @@ const METRIC_ORDER: [Metric; METRICS] = [
Metric::BlocksMade,
Metric::DispatchesWithoutEffects,
Metric::PrivateArenaDispatches,
Metric::EmulatedSimdgroupDispatches,
Metric::PrivateArenaPieces,
Metric::PrivateArenaBlocks,
Metric::Translations,
@@ -641,6 +644,7 @@ struct Atomics {
maker_yield_nanos: AtomicU64,
dispatches_without_effects: AtomicU64,
private_arena_dispatches: AtomicU64,
emulated_simdgroup_dispatches: AtomicU64,
private_arena_pieces: AtomicU64,
private_arena_blocks: AtomicU64,
shared_long_reuses: AtomicU64,
@@ -832,6 +836,7 @@ impl Counters {
Metric::BlocksMade => &a.blocks_made,
Metric::DispatchesWithoutEffects => &a.dispatches_without_effects,
Metric::PrivateArenaDispatches => &a.private_arena_dispatches,
Metric::EmulatedSimdgroupDispatches => &a.emulated_simdgroup_dispatches,
Metric::PrivateArenaPieces => &a.private_arena_pieces,
Metric::PrivateArenaBlocks => &a.private_arena_blocks,
Metric::Translations => &a.translations,
@@ -1649,6 +1654,7 @@ impl Counters {
allocation_map_refusals: a.allocation_map_refusals.load(Relaxed),
dispatches_without_effects: a.dispatches_without_effects.load(Relaxed),
private_arena_dispatches: a.private_arena_dispatches.load(Relaxed),
emulated_simdgroup_dispatches: a.emulated_simdgroup_dispatches.load(Relaxed),
private_arena_pieces: a.private_arena_pieces.load(Relaxed),
private_arena_blocks: a.private_arena_blocks.load(Relaxed),
translations: a.translations.load(Relaxed),
@@ -2205,6 +2211,10 @@ pub struct Metrics {
/// translator's floor (`crate::arena`). No Metal counterpart: Metal holds such a kernel's
/// private memory itself.
pub private_arena_dispatches: u64,
/// Dispatches that ran a kernel's emulated-SIMD-group module: a threadgroup not whole groups
/// of the width its own module runs, as 80 threads, or 32 on 64-lane subgroups. No Metal
/// counterpart: Metal runs any threadgroup size at its own SIMD width.
pub emulated_simdgroup_dispatches: u64,
/// The `vkCmdDispatch`es those recorded: one each, and one more for each piece past the first
/// of a dispatch whose slots passed the arena's budget.
pub private_arena_pieces: u64,
+6 -2
View File
@@ -1142,7 +1142,7 @@ impl ComputeCommandEncoder {
.ok_or(Error::Refused(Refusal::ThreadgroupSize { size, max }))
};
let ids = &state.numbered.ids;
match (direct, grid) {
let recorded = match (direct, grid) {
(Some((threads, groups, ragged)), _) => {
// A count past the device's limit on an axis is split, and so is one whose slots
// of the private arena pass its budget (`crate::arena`): each piece starts at its
@@ -1212,8 +1212,12 @@ impl ComputeCommandEncoder {
&Launch::Indirect(buffer, offset),
)
}
(None, Grid::Direct(_)) => Ok(()),
(None, Grid::Direct(_)) => return Ok(()),
};
if recorded.is_ok() && module == Module::Emulated {
recording(&mut self.building).count(Metric::EmulatedSimdgroupDispatches);
}
recorded
}
/// Whether a dispatch of a kernel of `interface` reaches a bound buffer that has a device
@@ -1459,6 +1459,8 @@ mod on_device {
encoder.set_compute_pipeline_state(&state).expect("a state");
encoder.set_buffer(Some(&a), 0, 0).expect("a buffer");
encoder.set_buffer(Some(&out), 0, 1).expect("a buffer");
let emulated = || device.counters().metrics().emulated_simdgroup_dispatches;
let before = emulated();
encoder
.dispatch_threadgroups([GROUPS, 1, 1], [size, 1, 1])
.unwrap_or_else(|error| panic!("{name}: threadgroups of {size}: {error}"));
@@ -1466,6 +1468,13 @@ mod on_device {
command_buffer.commit().expect("a commit");
finished(name, &command_buffer);
assert_eq!(command_buffer.error(), None, "{name}");
let partial = (interface.multiples.iter()).any(|&width| size % width.max(1) != 0);
assert_eq!(
emulated() - before,
u64::from(partial),
"{name}: threadgroups of {size}, whole groups of {:?}: emulated dispatches",
interface.multiples
);
let mut want = Vec::new();
for t in 0..threads {
let first = t - t % size;
@@ -1487,6 +1487,7 @@ field metal2vulkan-runtime::Metrics.consumer_allocation_nanos pub consumer_alloc
field metal2vulkan-runtime::Metrics.consumer_allocations pub consumer_allocations: u64
field metal2vulkan-runtime::Metrics.creations_before_seed pub creations_before_seed: u64
field metal2vulkan-runtime::Metrics.dispatches_without_effects pub dispatches_without_effects: u64
field metal2vulkan-runtime::Metrics.emulated_simdgroup_dispatches pub emulated_simdgroup_dispatches: u64
field metal2vulkan-runtime::Metrics.event_holds pub event_holds: [u64; STAGE_BUCKETS]
field metal2vulkan-runtime::Metrics.export_allocations pub export_allocations: Timed
field metal2vulkan-runtime::Metrics.export_claims pub export_claims: Timed
Can't render this file because it is too large.