rt: an observing kernel's whole grids, threadgroup dispatches and indirect dispatches run its plain module again; its partial-threadgroups variant runs ragged grids only

This restores 28e1026b3d's routing, in a new commit past four that changed it:
- 6453edbea7 ran an observer's whole grids on its partial-threadgroups variant;
- f090d99c9a added its indirect dispatches;
- 9a01f1e8ee kept the plain module only where the variant's vote word passed the limit;
- a103b4dc5a lowered the variant alone unless keeps_plain held.

The variant's predicated walk and partial-group answers cost each whole grid. The series was
measured at 3.5% slower a dispatch on an RX 7900 XTX when it landed (README known gap,
m3-max-67284), and the guest's GPU fall on the 3090 lies in 28e1026b3d..f979769faf, which holds
the series.

- encoder.rs decide(): the observer route goes. A dispatch runs choose()'s module: whole grids,
  threadgroup dispatches and indirect dispatches the plain module, a ragged grid the variant, and
  a threadgroup that is not whole SIMD groups the emulated variant. decide() takes the device's
  threadgroup memory bytes alone, for the vote word's refusal site. The ragged grid's
  threadgroup memory check is unchanged: a ragged grid whose lengths with the variant's vote word
  pass the limit is still Limit::ThreadgroupMemory (9a01f1e8ee's refusal, kept).
- pipeline.rs: an observing kernel's state lowers its plain module and its variant beside it,
  always (Partial::Alone and keeps_plain go). Its main pipelines at the declared size are two,
  as before the series: the plain module's (main_key, now the whole module's by decide) and the
  variant's ragged grid (ragged_key). finish_pipeline makes both, a kernel past the stage bound
  makes both at the creation, and a first use of either is an unfinished-pipeline wait. No
  variant is made lazily at a first ragged grid.
- Metrics::partial_variant_whole_grids stays, and reads 0. The conformance runner's
  dispatch-forms line prints only where it is above 0.
- Docs: the rt README's compute pipeline states (the routing, and the main pipelines), with the
  known-gap bullet the series added (3.5% XTX, 2.7% Iris) gone; docs/API.md section on the
  variant's regions; the Metrics docs; decide(), choose(), dispatch_threads and pipeline.rs's
  module docs.

No translation changes: the translator's modules and keys are the same, so there is no SEMANTICS
or ARTIFACT bump and no bless. Only rt files change.

Tests (red at 8a2f9109aa, green here):
- every_device_runs_an_observing_kernel_at_its_own_threadgroup_size: its whole grids,
  threadgroup and indirect dispatches add 0 to partial_variant_whole_grids, its ragged grids
  count in partial_variant_ragged_grids, and the creation lowers two modules.
- every_device_keys_a_dispatch_by_the_pipeline_it_runs: the whole, threadgroup and indirect
  entries share the plain module's key; the ragged ones take the variant's.
- every_device_finds_made_what_prepare_dispatch_made: a ragged grid and u32::MAX threads each make
  the variant's pipeline.
- every_device_keeps_a_kernel_that_reads_across_rows_after_a_barrier_at_its_own_size and
  every_device_makes_a_declared_bound_s_grids_with_the_state: a declared size makes two pipelines
  with the state, and its whole and ragged grids make nothing and wait for nothing.
- kernel_map's shared-content test: the observing content lowers twice.
The ragged-grid tests stay as they were:
- every_device_runs_a_stage_in_kernels_partial_threadgroup;
- every_device_runs_a_1024_thread_observers_ragged_grid_in_the_limit_less_its_vote_word;
- every_device_runs_a_kernel_without_a_vote_word_at_a_length_past_its_answer;
- every_device_runs_an_observer_on_its_plain_module_where_the_vote_word_passes_the_limit.
This commit is contained in:
Anees Iqbal committed 2026-11-23 06:16:29 -08:00
1 parent 8a2f9109aa
commit e59c621e48
7 files changed
+236 -298

No files matched your search

+12 -24
View File
@@ -2800,23 +2800,16 @@ while the driver's exit handler waited on a lock, with every runtime thread alre
`NONUNIFORM`), and an invocation past the grid returns before the kernel's body: only there does
a thread compare its position with the grid's last thread, inside one branch on the flag. Every
other dispatch, on the same pipeline, branches past that test. An indirect dispatch runs at its
own threadgroup size, unflagged. A kernel that observes its partition is lowered as its
partial-threadgroups variant at the state's creation, through the cache directory, and plainly
too only where the variant's predicated walk adds a 4-byte vote word of threadgroup memory (a
barrier in a loop; the plain module holds none) and the kernel takes a threadgroup memory length
from the encoder, or its own memory with the word passes the device's
`maxComputeSharedMemorySize`, or where the variant is refused: every dispatch, a whole
`dispatch_threads` grid,
`dispatch_threadgroups`, `dispatch_threadgroups_with_indirect_buffer` or a grid that is not a
whole number of threadgroups, runs the variant at its own size, every region but a ragged grid's
unflagged, so one `VkPipeline` of a size runs them all (`Metrics::partial_variant_whole_grids`
counts the dispatches of whole threadgroups, `Metrics::partial_variant_ragged_grids` those of a
ragged grid). A dispatch runs the plain module where the variant
is refused, where its threadgroup memory, the lengths set with the variant's own, passes the
device's `maxComputeSharedMemorySize` once the variant's predicated walk adds its 4-byte vote
word (a barrier in a loop; the plain module holds none), or where the threadgroup is not whole
SIMD groups of a kernel that runs only whole ones (below); a ragged grid of such a kernel is
refused as `Limit::ThreadgroupMemory`. The translator gives a kernel no order of the
own threadgroup size, unflagged. A kernel that observes its partition is lowered plainly and
as its partial-threadgroups variant at the state's creation, through the cache directory: its
whole `dispatch_threads` grids, `dispatch_threadgroups` and
`dispatch_threadgroups_with_indirect_buffer` run the plain module at their own size, and a
`dispatch_threads` grid that is not a whole number of threadgroups runs the variant at its size,
its regions flagged ragged (`Metrics::partial_variant_ragged_grids` counts those dispatches;
`Metrics::partial_variant_whole_grids` stays 0). A ragged grid whose threadgroup memory, the
lengths set with the variant's own, passes the device's `maxComputeSharedMemorySize` once the
variant's predicated walk adds its 4-byte vote word (a barrier in a loop; the plain module holds
none) is refused as `Limit::ThreadgroupMemory`. The translator gives a kernel no order of the
accesses Apple's SIMD-group lockstep orders (docs/API.md, accepted differences), so only the
kernel's own barriers, fences, atomics of threadgroup or SIMD-group scope, SIMD-group and quad
functions, threadgroup memory and builtins of the partition observe it.
@@ -2855,7 +2848,8 @@ while the driver's exit handler waited on a lock, with every runtime thread alre
errors, and the samplers' numbering; then it answers. The main pipeline is the one `VkPipeline`
whose key the descriptor holds: a tiling kernel's tiles' or an image-only kernel's square
workgroups', or, where the kernel takes no threadgroup memory length from the encoder, an
observing kernel's of a whole and of a ragged grid at the descriptor's
observing kernel's two, its plain module's of a whole grid and its partial-threadgroups
variant's of a ragged grid, at the descriptor's
`requiredThreadsPerThreadgroup`, or, where it sets none and the state declares a bound of
threads (the descriptor's `maxTotalThreadsPerThreadgroup` or the kernel's
`[[max_total_threads_per_threadgroup(n)]]`), at `[N, 1, 1]`, `N` the state's
@@ -3523,12 +3517,6 @@ cache is answered compile-required on both.
cache directory. For the observing kernel the device tests run, a grid template over
threadgroup memory, one lowering took 0.61 to 0.63 ms on an RX 7900 XTX in a release build; a
larger kernel's lowering takes longer.
- An observing kernel's whole grids, threadgroup dispatches and indirect dispatches run its
partial-threadgroups variant, the module its ragged grids run, so that one `VkPipeline` a size
runs them all: a whole grid there is measured 3.5% slower a dispatch on an RX 7900 XTX (4.22
against 4.08 µs over the 34,904 whole grids of one recorded stream's 12 bounded observers, job
m3-max-67284) and 2.7% faster on an Iris Xe (m3-max-67285), and is not timed per dispatch on
NVIDIA; the consumer reopens it.
- On Intel's Windows driver (101.2145) for the UHD 630, the driver's compile of a tiling kernel's
`VkPipeline`, the state's main one, took medians of 6,680 to 6,853 µs for the harness's
`create_state` kernel, in three processes of 40 compiles each with no driver cache hit. The
+4 -4
View File
@@ -2411,9 +2411,9 @@ pub struct Metrics {
pub private_arena_blocks: u64,
/// Dispatches of whole threadgroups, `dispatchThreads` of a whole grid, `dispatchThreadgroups`
/// or `dispatchThreadgroupsWithIndirectBuffer`, that ran a kernel's partial-threadgroups
/// variant: a kernel that observes its threadgroup partition runs every dispatch on that one
/// module where the variant takes the threadgroup and its threadgroup memory, a predicated
/// walk's vote word with it. No Metal counterpart: Metal compiles one function.
/// variant: none, as a kernel that observes its threadgroup partition runs them on its plain
/// module and only its ragged grids on the variant. No Metal counterpart: Metal compiles one
/// function.
pub partial_variant_whole_grids: u64,
/// Dispatches of a grid that ends in partial threadgroups, `dispatchThreads` of a grid that is
/// not a whole number of threadgroups, that ran a kernel's partial-threadgroups variant: a
@@ -2430,7 +2430,7 @@ pub struct Metrics {
pub extended_view_dispatches: u64,
/// Functions the translator lowered, each a module of a pipeline content the device did not
/// hold compiled: of a compute content, one for its partial-threadgroups variant, one more for
/// the plain module of an observing kernel whose state keeps one beside the variant, and one
/// the plain module of an observing kernel, which its state keeps beside the variant, and one
/// more for an emulated-SIMD-group variant the state lowers; of a render content, one for each
/// of its functions that the cache directory did not hold. A state of a content the device
/// holds lowers nothing.
+13 -39
View File
@@ -341,16 +341,14 @@ pub(crate) struct Choice {
/// How a state of `form` runs a dispatch of threadgroup size `size`, direct over `direct` or
/// indirect, the same on every device:
/// - indirect: the whole module at its own size ([`decide`] runs an observing kernel's on its
/// partial-threadgroups variant);
/// - indirect: the whole module at its own size;
/// - an image-only kernel ([`Form::Square`]): the whole module at `MultiRegion` 0 in workgroups
/// of [`SQUARE`] over a grid one deep, and of its [`image_tile`] over a deeper one, the region
/// carrying them, flagged where they do not divide the grid;
/// - a tiling kernel ([`Form::Tiled`]): its tiles, workgroups of `GRID_TILE_THREADS`, each one
/// `grid_tile` tile of the grid, which its region carries;
/// - an observing kernel ([`Form::Sized`]): its own size, a ragged grid on its
/// partial-threadgroups variant ([`decide`] runs its whole grids and indirect dispatches there
/// too).
/// partial-threadgroups variant.
///
/// A size deeper than `DEEP_THREADGROUP` runs as one row of its threads (`DeepThreadgroup`,
/// [`Constant::Threadgroup`](crate::pipeline::Constant::Threadgroup)), so every workgroup is
@@ -968,9 +966,9 @@ impl ComputeCommandEncoder {
/// `dispatchThreads:threadsPerThreadgroup:`: the threadgroups the grid's threads fill, the
/// last along an axis running only the threads left, with the grid's extent a parameter of
/// the kernel. A kernel that observes its threadgroup partition runs the grid, a whole number
/// of threadgroups or not, on its partial-threadgroups variant, as it runs
/// [`dispatch_threadgroups`](Self::dispatch_threadgroups).
/// the kernel. A kernel that observes its threadgroup partition runs a grid that is not a
/// whole number of threadgroups on its partial-threadgroups variant, and a whole one on its
/// plain module, as it runs [`dispatch_threadgroups`](Self::dispatch_threadgroups).
///
/// Err: as [`dispatch_threadgroups`](Self::dispatch_threadgroups);
/// [`Gap::PartialThreadgroups`] for such a grid of a kernel whose partial-threadgroups
@@ -1144,8 +1142,7 @@ impl ComputeCommandEncoder {
lengths: &self.threadgroup_lengths,
imageblock: self.imageblock,
};
let memory = (set, limits.max_shared_memory);
let (choice, module, kernel) = decide(inner, direct, size, memory)?;
let (choice, module, kernel) = decide(inner, direct, size, limits.max_shared_memory)?;
let Choice {
local,
nominal,
@@ -1398,25 +1395,17 @@ pub(crate) fn size_checked(interface: &Interface, size: [u32; 3]) -> Result<(),
}
/// What a dispatch at threadgroup size `size`, direct over `direct` or indirect, of the content
/// `compiled` runs, with the encoder's threadgroup memory lengths and imageblock size `set`
/// against the device's `max` bytes, decided once for the dispatch and for
/// [`ComputePipelineState::prepare_dispatch`]: [`choose`]'s choice, then its module, an
/// observer's partial-threadgroups variant for a ragged grid, and the emulated variant for a
/// threadgroup that is not whole groups of a module that runs only whole ones (the
/// partial-threadgroups variant has none), each lowered with the state. An observer's dispatch of
/// a whole grid, of threadgroups, or indirect, that its whole module would run runs on the
/// partial-threadgroups variant instead, unflagged, where the variant is lowered and takes the
/// threadgroup and its threadgroup memory (the lengths `set` with the variant's own, a predicated
/// walk's vote word included, within `max`): one module, and one `VkPipeline` a size, runs every
/// dispatch of it the variant takes. The variant is the state's module itself where its make
/// lowered no plain module beside it (`pipeline::Partial::Alone`). An indirect dispatch states no
/// grid in its region, so the variant runs it in the single-region form, every invocation live,
/// as the translator's dispatch regions say (`lower::dispatch`).
/// `compiled` runs, on a device of `max` bytes of threadgroup memory, decided once for the
/// dispatch and for [`ComputePipelineState::prepare_dispatch`]: [`choose`]'s choice, then its
/// module, an observer's partial-threadgroups variant for a ragged grid, and the emulated variant
/// for a threadgroup that is not whole groups of a module that runs only whole ones (the
/// partial-threadgroups variant has none), each lowered with the state. An observer's whole grids,
/// threadgroup dispatches and indirect dispatches run its plain module.
pub(crate) fn decide<'a>(
compiled: &'a Compiled,
direct: Option<Direct>,
size: [u32; 3],
(set, max): (Sizes<'_>, u32),
max: u32,
) -> Result<(Choice, Module, &'a Kernel), Error> {
let choice = choose(&compiled.form, direct, size);
let partial_threadgroups = |site: PartialThreadgroupsSite| {
@@ -1446,21 +1435,6 @@ pub(crate) fn decide<'a>(
.find(|&&multiple| !threads.is_multiple_of(u64::from(multiple.max(1))))
.copied()
};
let observes = matches!(compiled.form, Form::Sized { .. });
if observes && choice.module == Module::Whole && short(&compiled.whole).is_none() {
if let Ok(partial) = compiled.variant_kernel(Which::Partial, refused) {
if short(partial).is_none()
&& threadgroup_memory(partial, set, choice.local, (compiled.static_length(), max))
.is_ok()
{
let choice = Choice {
module: Module::Partial,
..choice
};
return Ok((choice, Module::Partial, partial));
}
}
}
let kernel = match choice.module {
Module::Partial => compiled.variant_kernel(Which::Partial, refused)?,
_ => &compiled.whole,
+117 -144
View File
@@ -12,11 +12,9 @@
//! grid and the threadgroup size pick (`encoder::image_tile`) over a deeper one, on one
//! `VkPipeline` per tile made at its first dispatch. An indirect
//! dispatch runs at its own threadgroup size. A kernel that observes its partition is lowered
//! plainly, and as its partial-threadgroups variant with the state: every dispatch, a whole
//! grid, threadgroups, an indirect dispatch or a `dispatchThreads` grid that is not a whole number
//! of threadgroups, runs the variant at its own threadgroup size, all but the last unflagged; the
//! dispatches where the content has no variant or the variant does not take the threadgroup run
//! the plain module.
//! plainly, and as its partial-threadgroups variant with the state: its whole grids, threadgroup
//! dispatches and indirect dispatches run the plain module at their own threadgroup size, and a
//! `dispatchThreads` grid that is not a whole number of threadgroups runs the variant at its size.
//! Each `VkPipeline` is keyed by its module, threadgroup size and threadgroup memory lengths. A
//! module keeps the first 8 it made and at most 56 more, the least recently dispatched one no
//! command buffer holds evicted past them, and a command buffer holds each of those 56 it
@@ -173,11 +171,10 @@ pub(crate) struct Compiled {
core: Arc<Core>,
/// Its number ([`CONTENTS`]).
id: u64,
/// For a kernel that observes its threadgroup partition, its partial-threadgroups variant
/// ([`Partial::Alone`]), or the plain module where the state keeps one beside the variant
/// ([`keeps_plain`]), which runs the dispatches the variant does not; for a kernel that does
/// not observe it, the module of indirect dispatches, and of every dispatch where it is the
/// only one. Its interface numbers the state's samplers and answers Metal's state.
/// The module of whole grids, threadgroup dispatches and indirect dispatches of a kernel that
/// observes its threadgroup partition; for a kernel that does not observe it, the module of
/// indirect dispatches, and of every dispatch where it is the only one. Its interface numbers
/// the state's samplers and answers Metal's state.
pub(crate) whole: Kernel,
/// How a direct dispatch runs.
pub(crate) form: Form,
@@ -196,6 +193,9 @@ pub(crate) struct Compiled {
/// [`ComputePipelineState::finish_pipeline`] makes, or its creation for a kernel past the
/// stage bound; none where its descriptor holds no key of a `VkPipeline`.
main: Option<DispatchVariant>,
/// The key of an observing kernel's ragged grids at its main pipeline's size, on its
/// partial-threadgroups variant ([`Compiled::ragged_key`]), made with the main pipeline.
ragged: Option<DispatchVariant>,
}
/// What Metal's compute state answers of a content beside its threads, from its whole module's
@@ -439,17 +439,15 @@ pub(crate) enum Form {
/// `encoder::image_tile` over a deeper one, a tile deeper than `DEEP_THREADGROUP` as one row
/// (`DeepThreadgroup`, [`Constant::Threadgroup`]).
Square,
/// The kernel observes its partition: a dispatch runs at its own threadgroup size, every one,
/// direct or indirect, on the partial-threadgroups variant (`partial`), wherever the variant
/// takes the dispatch's threadgroup and threadgroup memory (`encoder::decide`).
/// The kernel observes its partition: a dispatch runs at its own threadgroup size, and a
/// `dispatchThreads` grid that is not a whole number of threadgroups on the
/// partial-threadgroups variant (`partial`), lowered with the state where the content has a
/// function to lower it from.
Sized { partial: Partial },
}
/// An observing kernel's partial-threadgroups variant ([`Form::Sized`]).
pub(crate) enum Partial {
/// The variant is the content's module, [`Compiled::whole`]: the make lowers no plain module
/// beside it ([`keeps_plain`]).
Alone,
/// The variant, lowered with the state beside the plain module, which is the content's.
Beside(Box<Lowered>),
/// The content has no function to lower the variant from.
@@ -967,15 +965,12 @@ impl crate::Device {
/// thread, which waits for it, within the translator's 20-second budget per lowering: a
/// kernel that does not observe its threadgroup partition as its partial-threadgroups
/// variant, whose main pipeline is its 256-wide tile's `VkPipeline`, or an image-only
/// kernel's 16x16 workgroups' one, and one that does as its partial-threadgroups variant,
/// which its dispatches run, and its plain module too only where the variant's predicated
/// walk takes a vote word of threadgroup memory the plain module does not and the kernel
/// takes a threadgroup memory length from the encoder, or its own memory with the word is
/// past the device's `maxComputeSharedMemorySize`. Its main pipeline is the one `VkPipeline`
/// its dispatches run, whole grids, ragged and indirect ones (the plain module's where the
/// variant's threadgroup memory, the vote word with it, is past the device's), at the
/// descriptor's `requiredThreadsPerThreadgroup` where it sets one, or else at `[N, 1, 1]`
/// where the state declares a bound of threads (the descriptor's
/// kernel's 16x16 workgroups' one, and one that does as its plain module and its
/// partial-threadgroups variant. Its main pipelines are the `VkPipeline`s its whole grids,
/// threadgroup dispatches and indirect dispatches run (the plain module's) and its ragged
/// grids run (the variant's), at the descriptor's `requiredThreadsPerThreadgroup` where it
/// sets one, or else at `[N, 1, 1]` where the state declares a bound of threads (the
/// descriptor's
/// `maxTotalThreadsPerThreadgroup`, or the kernel's
/// `[[max_total_threads_per_threadgroup(n)]]`), `N` the state's
/// `maxTotalThreadsPerThreadgroup`, where the kernel takes no threadgroup memory length from
@@ -1111,7 +1106,7 @@ impl Compiled {
// The partial-threadgroups variant: what the cache directory holds, else lowered
// where the kernel does not observe its partition; where the translator answers
// that it observes it, it is lowered below, before the plain module the state
// keeps beside it where it keeps one. The translator's refusal of the variant
// keeps beside it. The translator's refusal of the variant
// (emulated simdgroups, a vote word its workgroup memory cannot hold) is kept like
// a lowering, and so is its answer that the kernel observes it, which a device on
// the directory then reads in place of asking.
@@ -1158,48 +1153,33 @@ impl Compiled {
let (whole, notes) = made(&core, pipeline, required)?;
(whole, notes, partial, image_only, Some(source), answers)
}
// The kernel observes its partition, or its variant is refused: the variant,
// which alone is the content's module where it is made and the state keeps no
// plain module beside it (`keeps_plain`), else the plain module, and the
// variant beside it for the grids that need it.
// The kernel observes its partition, or its variant is refused: the plain
// module, which its whole grids, threadgroup dispatches and indirect
// dispatches run, and the variant beside it for the grids that need it.
variant => {
let max = core.limits.max_shared_memory;
let variant = link_variant(&core, descriptor, function, &inputs, variant)
.map(|(lowered, pipeline)| {
let imageblock = declares_imageblock(descriptor, &lowered, &budget);
let answers = Answers::of(&pipeline, imageblock);
(made_variant(&core, pipeline, required), answers)
});
match variant {
Ok((Lowered::Made(variant, notes), answers))
if !keeps_plain(&variant.interface, max) =>
{
let partial = Some(Partial::Alone);
(*variant, notes, partial, false, Some(source), answers)
let mut variant =
link_variant(&core, descriptor, function, &inputs, variant)
.map_or_else(
|lowered| lowered,
|(_, pipeline)| made_variant(&core, pipeline, required),
);
let plain = (|| {
let plain = lower(&plain).map_err(Error::translation)?;
let imageblock = declares_imageblock(descriptor, &plain, &budget);
let plain = compiled(plain).map_err(Error::translation)?;
let answers = Answers::of(&plain, imageblock);
Ok::<_, Error>((made(&core, plain, required)?, answers))
})();
let ((whole, notes), answers) = match plain {
Ok(plain) => plain,
Err(error) => {
variant.release(&core);
return Err(error);
}
variant => {
let mut variant =
variant.map_or_else(|lowered| lowered, |made| made.0);
let plain = (|| {
let plain = lower(&plain).map_err(Error::translation)?;
let imageblock =
declares_imageblock(descriptor, &plain, &budget);
let plain = compiled(plain).map_err(Error::translation)?;
let answers = Answers::of(&plain, imageblock);
Ok::<_, Error>((made(&core, plain, required)?, answers))
})();
let ((whole, notes), answers) = match plain {
Ok(plain) => plain,
Err(error) => {
variant.release(&core);
return Err(error);
}
};
let variant = beside(&core, variant, &whole.interface);
let partial = Some(Partial::Beside(Box::new(variant)));
(whole, notes, partial, false, Some(source), answers)
}
}
};
let variant = beside(&core, variant, &whole.interface);
let partial = Some(Partial::Beside(Box::new(variant)));
(whole, notes, partial, false, Some(source), answers)
}
}
}
@@ -1261,15 +1241,15 @@ impl Compiled {
};
let mut compiled = Compiled::new(core, whole, form, emulated, (notes, answers));
compiled.main = compiled.main_key(descriptor);
compiled.ragged = compiled.ragged_key(descriptor);
if let StageSource::Function(function) = &descriptor.kernel {
compiled.linked = function.linked.clone();
}
// A kernel past the stage bound makes its main pipeline here, so that a make the stage
// A kernel past the stage bound makes its main pipelines here, so that a make the stage
// bound refuses refuses the state's, which the consumer's helper then fills. Every other
// error of the make is the dispatch's that makes it again, as a failed
// `finish_pipeline`'s is.
let main = compiled.main_kernel();
if let Some((kernel, variant)) = main.filter(|(kernel, _)| kernel.is_heavy()) {
for (kernel, variant) in compiled.ahead().filter(|(kernel, _)| kernel.is_heavy()) {
match kernel.make_ahead(&compiled.core, variant, VariantStart::State) {
Err(error) if past_stage_bound(&error) => return Err(error),
Ok(_) | Err(_) => {}
@@ -1286,37 +1266,61 @@ impl Compiled {
/// threads, `N` its `maxTotalThreadsPerThreadgroup`. The bound is declared by the
/// descriptor's `maxTotalThreadsPerThreadgroup`, or by the kernel's
/// `[[max_total_threads_per_threadgroup(n)]]`, which alone brings Metal's answer below its
/// 1024; the device's own limit is no declared bound. Its dispatches of that size run the
/// partial-threadgroups variant's, which runs whole grids, ragged and indirect ones alike, or
/// the whole module's where the content has no such variant or the variant's threadgroup
/// memory, a predicated walk's vote word with it, is past the device's (`encoder::decide`);
/// none where the module takes a threadgroup memory length or an imageblock size from the
/// encoder.
/// 1024; the device's own limit is no declared bound. Its whole grids, threadgroup
/// dispatches and indirect dispatches of that size run the plain module's
/// (`encoder::decide`); none where the module takes a threadgroup memory length or an
/// imageblock size from the encoder.
fn main_key(&self, descriptor: &ComputePipelineDescriptor) -> Option<DispatchVariant> {
let (module, size) = match &self.form {
Form::Tiled => (Module::Tiles, [GRID_TILE_THREADS, 1, 1]),
Form::Square => (Module::Whole, SQUARE),
Form::Sized { .. } => {
let interface = &self.whole.interface;
let declared = descriptor.max_total_threads_per_threadgroup.is_some()
|| interface.metal_max_total_threads < METAL_MAX_THREADS;
let bound = declared.then_some([interface.max_total_threads, 1, 1]);
let size = descriptor.required_threads_per_threadgroup.or(bound)?;
let dispatch = Dispatch::Threadgroups([1; 3]);
let set = Sizes {
lengths: &[],
imageblock: [1, 1],
};
let (kernel, module, local, lengths) = self.dispatched(dispatch, size, set)?;
let interface = &kernel.interface;
return (interface.threadgroups.is_empty() && interface.imageblock.is_none())
.then(|| self.dispatch_key(module, local, lengths));
let size = self.declared_size(descriptor)?;
return self.sized_key(Dispatch::Threadgroups([1; 3]), size);
}
};
let lengths = Lengths::zeros(self.whole.interface.threadgroups.len());
Some(self.dispatch_key(module, size, lengths))
}
/// The key of an observing kernel's ragged grids at the size of its main pipeline
/// ([`Compiled::main_key`]): its partial-threadgroups variant's, where the content has it
/// and the variant takes that size, under the main pipeline's condition.
fn ragged_key(&self, descriptor: &ComputePipelineDescriptor) -> Option<DispatchVariant> {
let size = self.declared_size(descriptor)?;
let ragged = Dispatch::Threads(size.map(|axis| axis.saturating_add(1)));
self.sized_key(ragged, size)
.filter(|key| key.module == Module::Partial)
}
/// The size an observing kernel's state gives its dispatches: the descriptor's
/// `requiredThreadsPerThreadgroup`, or `[N, 1, 1]` where the state declares a bound of
/// threads ([`Compiled::main_key`]); none for another form.
fn declared_size(&self, descriptor: &ComputePipelineDescriptor) -> Option<[u32; 3]> {
if !matches!(self.form, Form::Sized { .. }) {
return None;
}
let interface = &self.whole.interface;
let declared = descriptor.max_total_threads_per_threadgroup.is_some()
|| interface.metal_max_total_threads < METAL_MAX_THREADS;
let bound = declared.then_some([interface.max_total_threads, 1, 1]);
descriptor.required_threads_per_threadgroup.or(bound)
}
/// The key of `dispatch` at `size` of an observing kernel, decided as the dispatch decides
/// it, where its module takes no threadgroup memory length or imageblock size from the
/// encoder.
fn sized_key(&self, dispatch: Dispatch, size: [u32; 3]) -> Option<DispatchVariant> {
let set = Sizes {
lengths: &[],
imageblock: [1, 1],
};
let (kernel, module, local, lengths) = self.dispatched(dispatch, size, set)?;
let interface = &kernel.interface;
(interface.threadgroups.is_empty() && interface.imageblock.is_none())
.then(|| self.dispatch_key(module, local, lengths))
}
/// The content of `whole`, its form, emulated variant, notes and Metal's answers, counted
/// live, with no main pipeline.
fn new(
@@ -1337,6 +1341,7 @@ impl Compiled {
answers,
linked: LinkedFunctions::new(),
main: None,
ragged: None,
}
}
}
@@ -1373,7 +1378,7 @@ enum Found {
Refused(VariantRefusal),
/// Not lowered yet: the emulated-SIMD-group variant, which is lowered once the content's
/// module is, or an observing kernel's partial-threadgroups one, lowered before the plain
/// module its state keeps beside it where it keeps one ([`keeps_plain`]).
/// module its state keeps beside it.
Unlowered,
}
@@ -1475,20 +1480,6 @@ fn made(
Ok((Kernel::new(core, pipeline, required)?, notes))
}
/// Whether an observing kernel's state keeps its plain module beside its partial-threadgroups
/// variant, whose module's interface is `variant`: where the variant's predicated walk takes a
/// vote word of threadgroup memory the plain module does not ([`Memory::vote`]), and the kernel
/// takes a threadgroup memory length or an imageblock size from the encoder or its own memory
/// with the word is past the device's `max` bytes, so that a dispatch the plain module takes may
/// find the variant past the limit (`encoder::decide`). Every other dispatch either module takes,
/// the variant takes.
fn keeps_plain(variant: &Interface, max: u32) -> bool {
variant.memory.vote != 0
&& (!variant.threadgroups.is_empty()
|| variant.imageblock.is_some()
|| variant.memory.bytes(&[], 0, 0) > u64::from(max))
}
/// The lowering of `FunctionCompileKey` digest `key` a device kept in the cache directory, where
/// its bytes decode for that key; not counted.
pub(crate) fn loaded(core: &Core, key: &Hash256) -> Option<CompiledFunction> {
@@ -1989,9 +1980,10 @@ impl ComputePipelineState {
/// on a thread of its own after it has answered.
///
/// The main pipeline is the one whose key the descriptor holds: a tiling kernel's tiles', an
/// image-only kernel's square workgroups', or an observing kernel's at the descriptor's
/// image-only kernel's square workgroups', or an observing kernel's two at the descriptor's
/// `requiredThreadsPerThreadgroup` or its declared bound of threads where the kernel takes no
/// threadgroup memory length from the encoder
/// threadgroup memory length from the encoder, its plain module's and its
/// partial-threadgroups variant's
/// ([`new_compute_pipeline_state`](crate::Device::new_compute_pipeline_state)). A state with
/// none makes nothing here. A kernel past the stage bound makes its main pipeline at the
/// creation, so that the stage bound's refusal is the creation's, and makes nothing here.
@@ -2015,16 +2007,14 @@ impl ComputePipelineState {
pub fn finish_pipeline(&self) -> Result<(), Error> {
let compiled = &self.inner.compiled;
let core = &compiled.core;
let main = compiled.main_kernel();
let Some((kernel, variant)) = main.filter(|(kernel, _)| !kernel.is_heavy()) else {
return Ok(());
};
match kernel.make_ahead(core, variant, VariantStart::Finish) {
Ok(Some(nanos)) => core.counters.finished(nanos),
Ok(None) => {}
Err(error) => {
core.counters.finish_failed();
return Err(error);
for (kernel, variant) in compiled.ahead().filter(|(kernel, _)| !kernel.is_heavy()) {
match kernel.make_ahead(core, variant, VariantStart::Finish) {
Ok(Some(nanos)) => core.counters.finished(nanos),
Ok(None) => {}
Err(error) => {
core.counters.finish_failed();
return Err(error);
}
}
}
Ok(())
@@ -2309,8 +2299,7 @@ impl Compiled {
}
}
/// The module of the content's `which` variant, lowered with the state: [`Compiled::whole`]
/// for a partial-threadgroups variant that is the content's module ([`Partial::Alone`]).
/// The module of the content's `which` variant, lowered with the state.
///
/// Err: `refused` of why where the content has no such variant (as the translator's other
/// refusals) or the translator refused it ([`Lowered::Refused`]); [`Error::Translation`] where its lowering or compile failed
@@ -2321,15 +2310,6 @@ impl Compiled {
which: Which,
refused: impl FnOnce(VariantRefusal) -> Error,
) -> Result<&Kernel, Error> {
if let (
Which::Partial,
Form::Sized {
partial: Partial::Alone,
},
) = (which, &self.form)
{
return Ok(&self.whole);
}
match self.variant(which) {
Some(lowered) => lowered.kernel(refused),
None => Err(refused(VariantRefusal::Translator)),
@@ -2344,15 +2324,6 @@ impl Compiled {
Module::Partial => Which::Partial,
Module::Emulated => Which::Emulated,
};
if let (
Which::Partial,
Form::Sized {
partial: Partial::Alone,
},
) = (which, &self.form)
{
return Some(&self.whole);
}
match self.variant(which)? {
Lowered::Made(kernel, _) => Some(&**kernel),
Lowered::Refused(_)
@@ -2362,16 +2333,19 @@ impl Compiled {
}
}
/// The content's main pipeline's kernel and key, where it has one ([`Compiled::main`]).
fn main_kernel(&self) -> Option<(&Kernel, DispatchVariant)> {
let variant = self.main?;
Some((self.kernel_of(variant.module)?, variant))
/// The content's main pipelines' kernels and keys, where it has them ([`Compiled::main`],
/// [`Compiled::ragged`]).
fn ahead(&self) -> impl Iterator<Item = (&Kernel, DispatchVariant)> {
[self.main, self.ragged]
.into_iter()
.flatten()
.filter_map(|variant| Some((self.kernel_of(variant.module)?, variant)))
}
/// Where a first use of `variant` waits ([`FirstUse`]): the content's main pipeline's
/// Where a first use of `variant` waits ([`FirstUse`]): a main pipeline's
/// ([`FirstUse::Unfinished`]), or a variant's no state of the content has run.
pub(crate) fn first_use(&self, variant: DispatchVariant) -> FirstUse {
match self.main == Some(variant) {
match self.main == Some(variant) || self.ragged == Some(variant) {
true => FirstUse::Unfinished,
false => FirstUse::Variant,
}
@@ -2413,8 +2387,7 @@ impl Compiled {
return None;
}
let max = self.core.limits.max_shared_memory;
let (choice, module, kernel) =
decide(self, dispatch.direct(size), size, (set, max)).ok()?;
let (choice, module, kernel) = decide(self, dispatch.direct(size), size, max).ok()?;
if (choice.direct).is_some_and(|(_, groups, _)| groups.contains(&0)) {
return None;
}
@@ -127,8 +127,8 @@ mod on_device {
/// Two states of one content share one translation, one shader module and one `VkPipeline`
/// per variant: `a1_bool_from_float`, which tiles its grid (one lowering, and its tiles'
/// `VkPipeline` made with the first state alone), and `icb_replay_grid_template`, which
/// observes its threadgroups (one lowering, its partial-threadgroups variant, with the first
/// state alone). The map holds one
/// observes its threadgroups (two lowerings, its plain module and its partial-threadgroups
/// variant, with the first state alone). The map holds one
/// entry each, and a kernel lives while a state or the map holds it. A make kept under a key
/// the map holds already answers the map's kernel, and counts in
/// `Metrics::kernel_makes_dropped`.
@@ -151,7 +151,7 @@ mod on_device {
each_device("kernel_map_shared", |name, _, device| {
let counters = device.counters();
for (kernel, descriptor, lowerings, pipelines) in
[("tiled", &tiled, 1, 1), ("observing", &observing, 1, 0)]
[("tiled", &tiled, 1, 1), ("observing", &observing, 2, 0)]
{
let before = counters.metrics();
let first = state(name, &device, descriptor);
@@ -17,9 +17,9 @@
//! attributes are fetched from the element each step function names in that region, in a ragged
//! grid's partial threadgroup too, whose invocations past the grid write nothing. A read of a texture the kernel's function constants removed takes zero,
//! and a read through a buffer argument bound to nothing reads the nil buffer's zeros.
//! An observer whose partial-threadgroups variant's vote word takes its threadgroup memory past
//! the device's limit runs its whole grids, threadgroup dispatches and indirect ones on its plain
//! module. Threadgroup memory, a declared array's and a threadgroup argument's, reads zero until
//! An observer runs its whole grids, threadgroup dispatches and indirect ones on its plain module,
//! and its ragged grids on its partial-threadgroups variant, whose vote word may take its
//! threadgroup memory past the device's limit. Threadgroup memory, a declared array's and a threadgroup argument's, reads zero until
//! the program writes it, in a dispatch's later threadgroups, in a second dispatch and on the
//! emulated-SIMD-group module alike. Every module is lowered with the state, the variants
//! included, so no dispatch makes a translation; an observing kernel's state made at its
@@ -436,11 +436,11 @@ mod on_device {
}
/// `icb_replay_grid_template`, which observes its threadgroup partition (threadgroup memory,
/// a barrier, and every builtin of the partition), translated at creation as its
/// partial-threadgroups variant alone, whose walk takes no vote word, so the state keeps no
/// plain module: every dispatch, a whole `dispatchThreads` grid, a ragged one,
/// threadgroup counts or an indirect one, runs the variant at the call's size, with no
/// translation at any dispatch, and a
/// a barrier, and every builtin of the partition), translated at creation, plainly and as its
/// partial-threadgroups variant: a whole `dispatchThreads` grid, threadgroup counts and an
/// indirect dispatch run its plain module at the call's size, none of them counted in
/// `Metrics::partial_variant_whole_grids`, and a ragged grid the variant, each counted in
/// `Metrics::partial_variant_ragged_grids`, with no translation at any dispatch, and a
/// threadgroup count past the device's limit on an axis
/// runs split, each piece reading Metal's whole grid. Threadgroups deeper than 64, 1 by 1 by
/// 320 and 2 by 3 by 100, run as one row of their threads on every device, whole, ragged and
@@ -526,8 +526,8 @@ mod on_device {
);
assert_eq!(
created.translations - made.translations,
1,
"{name}: the partial-threadgroups variant alone at creation"
2,
"{name}: the plain module and the partial-threadgroups variant at creation"
);
let queue = device.new_command_queue(4).expect("a queue");
let command_buffer = queue.command_buffer().expect("a command buffer");
@@ -571,7 +571,7 @@ mod on_device {
"{name}: no translation at a dispatch, the first ragged grid's included"
);
// One pipeline for each module and size the runs take: a ragged grid the variant; a
// threadgroup of whole SIMD groups of the device's tier the variant, direct or
// threadgroup of whole SIMD groups of the device's tier the plain module, direct or
// indirect; any other the emulated variant.
let simd = &state.inner.compiled.whole.interface.multiples;
let whole_simd = |size: [u32; 3]| {
@@ -580,17 +580,17 @@ mod on_device {
.all(|&width| threads.is_multiple_of(width.max(1)))
};
let mut pipelines = std::collections::HashSet::new();
let mut on_variant = 0;
let mut ragged_grids = 0;
for &(grid, size, how) in &runs {
let ragged = how == How::Threads
&& (0..3).any(|axis| !grid[axis].is_multiple_of(size[axis]));
let module = match (ragged, whole_simd(size)) {
(true, _) => "variant",
(false, false) => "emulated",
(false, true) => {
on_variant += 1;
(true, _) => {
ragged_grids += 1;
"variant"
}
(false, false) => "emulated",
(false, true) => "plain",
};
pipelines.insert((module, size));
}
@@ -601,9 +601,14 @@ mod on_device {
);
assert_eq!(
after.partial_variant_whole_grids - created.partial_variant_whole_grids,
on_variant,
0,
"{name}: whole threadgroups, direct and indirect, on the partial-threadgroups variant"
);
assert_eq!(
after.partial_variant_ragged_grids - created.partial_variant_ragged_grids,
ragged_grids,
"{name}: ragged grids on the partial-threadgroups variant"
);
println!(
"{name}: observing kernel checked over {} runs{}; creation {creation} ns, one lowering {lowering} ns; precision notes {}",
runs.len(),
@@ -679,15 +684,16 @@ mod on_device {
}
/// `ComputePipelineState::prepare_dispatch` makes what a dispatch of `icb_replay_grid_template`,
/// an observing kernel, then finds made: for a whole `dispatchThreads` grid, a
/// `dispatchThreadgroups` grid and an indirect dispatch, each prepared with the dispatch's own
/// arguments, the call makes exactly one pipeline and lowers nothing, and the dispatch adds no
/// first-use wait and makes nothing; a ragged grid and an indirect dispatch of the whole grid's
/// size find the whole grid's made, since every dispatch runs the partial-threadgroups variant,
/// lowered with the state. A `dispatchThreadgroups` grid whose threads saturate on an axis, prepared alone,
/// makes what a small grid of the same call and size then runs with no wait, and a
/// `dispatchThreads` grid of exactly `u32::MAX` threads on that size, which does not divide
/// it, finds that made. A second call with the same arguments makes nothing. A call for what the dispatch records nothing for (a grid with no
/// an observing kernel, then finds made: for a whole `dispatchThreads` grid, a ragged one (its
/// partial-threadgroups variant, lowered with the state), a `dispatchThreadgroups` grid and an
/// indirect dispatch, each prepared with the dispatch's own arguments, the call makes exactly
/// one pipeline and lowers nothing, and the dispatch adds no first-use wait and makes nothing;
/// an indirect dispatch of the whole grid's size finds the whole grid's made, since both run
/// the plain module. A `dispatchThreadgroups` grid whose threads saturate on an axis, and a
/// `dispatchThreads` grid of exactly `u32::MAX` threads on a size that does not divide it,
/// prepared alone, make what a small grid of the same call and size then runs with no wait:
/// the plain module and the partial-threadgroups variant. A second call with the same
/// arguments makes nothing. A call for what the dispatch records nothing for (a grid with no
/// threads) or refuses (a threadgroup past Metal's, threadgroup memory past the device's)
/// makes nothing, and the dispatch answers as it does unprepared. Each answer is Metal's.
#[test]
@@ -722,7 +728,7 @@ mod on_device {
Dispatch::Threads([10, 3, 1]),
[4, 2, 1],
([10, 3, 1], How::Threads),
0,
1,
),
(Dispatch::Indirect, [4, 2, 1], ([2, 2, 1], How::Indirect), 0),
(
@@ -742,7 +748,7 @@ mod on_device {
Dispatch::Threads([u32::MAX, 1, 1]),
[2, 1, 1],
([3, 1, 1], How::Threads),
0,
1,
),
];
for (prepared, size, (grid, how), made) in cases {
@@ -1217,10 +1223,10 @@ mod on_device {
/// `ComputePipelineState::dispatch_variant`'s keys name exactly the `VkPipeline`s the
/// dispatches run: over a table of dispatches of `icb_replay_grid_template`, an observing
/// kernel with a threadgroup memory argument, two keys are equal exactly when the entries run
/// one module at one size and threadgroup memory length. Direct grids that differ only in their
/// extent, their call or whether they are whole threadgroups, and an indirect dispatch, share a
/// key, all on the partial-threadgroups variant; a different threadgroup size or length gives
/// another. `prepare_dispatch` on
/// one module at one size and threadgroup memory length. Grids that differ only in their
/// extent or their call, and an indirect dispatch, share a key on the plain module, the ragged
/// ones on the partial-threadgroups variant another, and a different threadgroup size or
/// length gives another. `prepare_dispatch` on
/// each entry in turn makes one pipeline for each key not met before and none for one met. A
/// second state of the same content answers the same keys and finds their pipelines made; a
/// state of another content (the same function with a required threadgroup size) answers
@@ -1248,28 +1254,28 @@ mod on_device {
// Each entry: the dispatch, its size, its threadgroup memory length, and the pipeline
// it runs.
let table = [
(Dispatch::Threads([8, 4, 1]), size, length(size), "size"),
(Dispatch::Threads([16, 8, 1]), size, length(size), "size"),
(Dispatch::Threads([8, 4, 1]), size, length(size), "whole"),
(Dispatch::Threads([16, 8, 1]), size, length(size), "whole"),
(
Dispatch::Threadgroups([3, 2, 1]),
size,
length(size),
"size",
"whole",
),
(Dispatch::Indirect, size, length(size), "size"),
(Dispatch::Threads([10, 3, 1]), size, length(size), "size"),
(Dispatch::Threads([9, 5, 1]), size, length(size), "size"),
(Dispatch::Indirect, size, length(size), "whole"),
(Dispatch::Threads([10, 3, 1]), size, length(size), "partial"),
(Dispatch::Threads([9, 5, 1]), size, length(size), "partial"),
(
Dispatch::Threadgroups([3, 2, 1]),
small,
length(small),
"small",
"whole, small",
),
(
Dispatch::Threads([8, 4, 1]),
size,
2 * length(size),
"longer",
"whole, longer",
),
];
let first = state(name, &device, &descriptor);
@@ -2260,8 +2266,8 @@ mod on_device {
/// and constexpr uses, the buffer and texture accesses, whether the kernel writes memory,
/// reads the stage-in region or takes a private arena, its storage reads, formatless slots and
/// unbound accesses, its threadgroup arguments, SIMD-group multiples and subgroup size, and the
/// buffer alignments it takes. So a state whose only module is the variant
/// (`Partial::Alone`) answers as one of its plain module. Prints how many kernels it
/// buffer alignments it takes. So a ragged grid, which runs the variant, finds what the
/// state's plain module answers. Prints how many kernels it
/// compared, and each one it could not, with why.
#[test]
fn every_device_s_observers_answer_the_same_on_their_variant() {
@@ -3812,21 +3818,20 @@ define void @nil_read_kernel(ptr addrspace(1) %in, ptr addrspace(1) %out, i32 %t
/// The harness fixture's `row_barrier` holds no threadgroup memory and observes its
/// threadgroup partition through `threadgroup_barrier(mem_flags::mem_device)`: each thread
/// stores `((y << 16) | x) + 1` to its cell, then, past the barrier, copies the word of its
/// column in row `y ^ 1` where that row is in the grid. The state lowers its
/// partial-threadgroups variant alone, whose walk takes no vote word, and makes no pipeline,
/// and its grids run at their own size on that variant: 512 x
/// 4 in 32 x 2, whole, makes its pipeline by a first-use wait with no translation, 512 x 3 in
/// 32 x 2, ragged, finds it made, and 96 x 5 in 32 x 4 makes its own; the whole grid counts in
/// column in row `y ^ 1` where that row is in the grid. The state lowers both modules and makes
/// no pipeline, and its grids run at their own size: 512 x 4 in 32 x 2 on the plain module,
/// 512 x 3 in 32 x 2 and 96 x 5 in 32 x 4 on the partial-threadgroups variant, each its own
/// pipeline made by a first-use wait, with no translation; no grid counts in
/// `Metrics::partial_variant_whole_grids`. A state of the descriptor with
/// `requiredThreadsPerThreadgroup` 32 x 2 makes, with the state, the one pipeline a whole and a
/// `requiredThreadsPerThreadgroup` 32 x 2 makes, with the state, the pipelines a whole and a
/// ragged grid run at that size, so its 512 x 4 and 512 x 3 grids make nothing and wait for
/// nothing. Every read sees the other row's word, Metal's answer: the probe
/// `metal2vulkan-conformance/probes/row_barrier_reads.m` ran the same source over the same
/// grids on an Apple M3 Max under macOS 27.0.1, and no word of `seen` differed from it. A
/// state whose descriptor declares `maxTotalThreadsPerThreadgroup` 64 and no required size
/// makes, with the state, the one pipeline a whole and a ragged grid run at 64 x 1, so its
/// first 512 x 1 and 500 x 1 grids in 64 x 1 make nothing and wait for nothing; one row reads
/// no other row's word.
/// makes, with the state, the pipelines a whole and a ragged grid run at 64 x 1, so its first
/// 512 x 1 and 500 x 1 grids in 64 x 1 make nothing and wait for nothing; one row reads no
/// other row's word.
#[test]
fn every_device_keeps_a_kernel_that_reads_across_rows_after_a_barrier_at_its_own_size() {
let Some(descriptor) = harness_kernel("row_barrier") else {
@@ -3842,8 +3847,8 @@ define void @nil_read_kernel(ptr addrspace(1) %in, ptr addrspace(1) %out, i32 %t
created.pipelines_created - made.pipelines_created,
created.translations - made.translations,
),
(0, 1),
"{name}: no pipeline made by finish_pipeline, and the variant alone lowered"
(0, 2),
"{name}: no pipeline made with the state, and both modules lowered"
);
let queue = device.new_command_queue(4).expect("a queue");
let run = |state: &ComputePipelineState, grid: [u32; 3], size: [u32; 3]| {
@@ -3880,13 +3885,13 @@ define void @nil_read_kernel(ptr addrspace(1) %in, ptr addrspace(1) %out, i32 %t
"{name}: {grid:?} in {size:?}"
);
};
// Each grid on the partial variant at its own size: one pipeline, made by a first-use
// wait, where the state has not run the size, and no translation.
// Each grid at a size its state has not run: one pipeline, made by a first-use wait,
// and no translation.
let mut before = created;
for (grid, size, made, whole, what) in [
([512, 4, 1], [32, 2, 1], 1, 1, "a whole grid at 32 x 2"),
([512, 3, 1], [32, 2, 1], 0, 0, "a ragged grid at 32 x 2"),
([96, 5, 1], [32, 4, 1], 1, 0, "a ragged grid at 32 x 4"),
for (grid, size, what) in [
([512, 4, 1], [32, 2, 1], "the plain module at 32 x 2"),
([512, 3, 1], [32, 2, 1], "the partial variant at 32 x 2"),
([96, 5, 1], [32, 4, 1], "the partial variant at 32 x 4"),
] {
run(&state, grid, size);
let after = device.counters().metrics();
@@ -3897,12 +3902,12 @@ define void @nil_read_kernel(ptr addrspace(1) %in, ptr addrspace(1) %out, i32 %t
after.translations - before.translations,
after.partial_variant_whole_grids - before.partial_variant_whole_grids,
),
(made, made, 0, whole),
(1, 1, 0, 0),
"{name}: pipelines, first-use waits, translations and whole grids of {what}"
);
before = after;
}
// At the descriptor's required size, the make makes what both grids run: one pipeline.
// At the descriptor's required size, the make makes what both grids run.
let mut required = descriptor.clone();
required.required_threads_per_threadgroup = Some([32, 2, 1]);
let sized = self::state(name, &device, &required);
@@ -3912,8 +3917,8 @@ define void @nil_read_kernel(ptr addrspace(1) %in, ptr addrspace(1) %out, i32 %t
made.pipelines_created - before.pipelines_created,
made.translations - before.translations,
),
(1, 1),
"{name}: the required size's state: its whole and ragged grids' pipeline"
(2, 2),
"{name}: the required size's state: its whole and ragged grids' pipelines"
);
run(&sized, [512, 4, 1], [32, 2, 1]);
run(&sized, [512, 3, 1], [32, 2, 1]);
@@ -3928,7 +3933,7 @@ define void @nil_read_kernel(ptr addrspace(1) %in, ptr addrspace(1) %out, i32 %t
"{name}: the required size's grids made nothing and waited for nothing"
);
// At a declared bound and no required size, the make makes what a whole and a ragged
// grid run at the bound's row: one pipeline.
// grid run at the bound's row.
let mut bounded = descriptor.clone();
bounded.max_total_threads_per_threadgroup = Some(64);
let before = device.counters().metrics();
@@ -3937,8 +3942,8 @@ define void @nil_read_kernel(ptr addrspace(1) %in, ptr addrspace(1) %out, i32 %t
assert_eq!(bound.max_total_threads_per_threadgroup(), 64, "{name}");
assert_eq!(
made.pipelines_created - before.pipelines_created,
1,
"{name}: the declared bound's state: its whole and ragged grids' pipeline"
2,
"{name}: the declared bound's state: its whole and ragged grids' pipelines"
);
run(&bound, [512, 1, 1], [64, 1, 1]);
run(&bound, [500, 1, 1], [64, 1, 1]);
@@ -3953,18 +3958,18 @@ define void @nil_read_kernel(ptr addrspace(1) %in, ptr addrspace(1) %out, i32 %t
);
println!(
"{name}: row barrier reads checked in 512 x 4 and 512 x 3 in 32 x 2 and 96 x 5 in \
32 x 4, at their own size on the partial variant; declared bound 64: whole and \
ragged grids' pipeline made by finish_pipeline"
32 x 4, at their own size; declared bound 64: whole and ragged grids' pipelines \
made by finish_pipeline"
);
});
}
/// `compute_thread_limit_64` declares `[[max_total_threads_per_threadgroup(64)]]` and observes
/// its threadgroups, with no required size: its state makes the one pipeline a whole and a
/// ragged grid run at 64 x 1 x 1, the partial-threadgroups variant's, so its first 128 x 1 and
/// 100 x 1 grids in 64 x 1 make nothing and wait for nothing, the whole one counted in
/// `Metrics::partial_variant_whole_grids`, and each grid runs each of its threads once in
/// threadgroups of 64. The same kernel without the attribute, bounded only by the device,
/// its threadgroups, with no required size: its state makes the pipelines a whole and a
/// ragged grid run at 64 x 1 x 1, the plain module's and the partial-threadgroups variant's,
/// so its first 128 x 1 and 100 x 1 grids in 64 x 1 make nothing and wait for nothing, the
/// whole one on the plain module (uncounted in `Metrics::partial_variant_whole_grids`), and
/// each grid runs each of its threads once in threadgroups of 64. The same kernel without the attribute, bounded only by the device,
/// makes none with its state.
#[test]
fn every_device_makes_a_declared_bound_s_grids_with_the_state() {
@@ -3990,8 +3995,8 @@ define void @nil_read_kernel(ptr addrspace(1) %in, ptr addrspace(1) %out, i32 %t
assert_eq!(state.max_total_threads_per_threadgroup(), 64, "{name}");
assert_eq!(
created.pipelines_created - made.pipelines_created,
1,
"{name}: the whole and ragged grids' pipeline, made by finish_pipeline"
2,
"{name}: the whole and ragged grids' pipelines, made by finish_pipeline"
);
let queue = device.new_command_queue(4).expect("a queue");
for threads in [128, 100] {
@@ -4023,13 +4028,13 @@ define void @nil_read_kernel(ptr addrspace(1) %in, ptr addrspace(1) %out, i32 %t
after.first_use_waits - created.first_use_waits,
after.partial_variant_whole_grids - created.partial_variant_whole_grids,
),
(0, 0, 1),
(0, 0, 0),
"{name}: the declared bound's grids made nothing and waited for nothing, the \
whole one on the partial variant"
whole one on the plain module"
);
println!(
"{name}: declared bound 64: 128 x 1 and 100 x 1 in 64 x 1 made by finish_pipeline, \
both on the partial variant"
the whole one on the plain module and the ragged one on the partial variant"
);
});
}
+4 -6
View File
@@ -1280,12 +1280,10 @@ square workgroups. On that variant a grid of whole threadgroups, of `dispatchThr
`dispatchThreadgroups`, takes the same regions unflagged (each `MultiRegion` 1, every thread
live), so one `VkPipeline` of a threadgroup size runs all of a kernel's direct dispatches. The
runtime lowers a kernel that does not observe its partition once, as that variant, and runs every
direct dispatch of it in its tiles; a kernel that observes its partition runs every dispatch, a
whole grid, threadgroups, an indirect dispatch or a `dispatchThreads` grid that is not a whole
number of threadgroups, on its partial-threadgroups variant at its own threadgroup size, where the
variant takes the dispatch's threadgroup memory (the variant's predicated walk may add a vote
word); an indirect dispatch states no grid in its region and takes the single-region form,
unflagged.
direct dispatch of it in its tiles; a kernel that observes its partition runs its whole grids,
threadgroup dispatches and indirect dispatches on its plain module at their own threadgroup size,
and a `dispatchThreads` grid that is not a whole number of threadgroups on its
partial-threadgroups variant.
### Levels a slot reads