Deep threadgroups run as one row: SpecKey::DeepThreadgroup on from_queries, rt keys it on the size
Metal allows 1024 threads along z; a device's maxComputeWorkGroupSize[2] may hold 64 (NVIDIA's), so rt refused a kernel's threadgroup of 1x1x320 (Limit::ThreadgroupShape) and could not play a recorded stream past its frame 216 on any NVIDIA card. One form serves every shape on every device: a threadgroup deeper than DEEP_THREADGROUP (64) runs as one row of its threads. Translator, on Device::from_queries' profile only (ProfileFacts::deep_threadgroups, OneRow; Device::new keeps Axes and is byte-equal): a kernel whose workgroup is its threadgroup (LocalSizeForm::Spec, no compute derivatives) declares the boolean SpecKey::DeepThreadgroup. Its WorkgroupSize is (Deep ? sx*sy*sz : sx, Deep ? 1 : sy, Deep ? 1 : sz), OpSpecConstantOp selects (the WorkgroupSize rule now takes spec-constant operations whose defaults are positive), and its position in the threadgroup Deep ? LocalInvocationIndex unflattened over (sx, sy) : LocalInvocationId. The linear index, workgroup and grid builtins keep their values, so group counts, regions and indirect buffers are untouched. The binder sets it for a region deeper than 64 and checks that region as the flattened tiers' are. MetalDeviceProperties on that profile reports the capped invocations on every axis (1024 on every floor device) instead of the device's per-axis sizes. SEMANTICS_VERSION 2172, ARTIFACT_FORMAT_VERSION 536. rt: the key is a function of the variant's size (size[2] > DEEP_THREADGROUP), so it adds no pipeline and no cache key. choose() takes no device limit: an image-only kernel's deep tile runs whole as one row on every device (it ran whole on RADV/ANV and in tiles on NVIDIA). fits(), ComputeLimits::max_group_size and Limit::ThreadgroupShape are deleted: every workgroup is within the floor by construction (a const assertion). A module that neither flattens nor declares the key is a creation gap. README: the deep form, worst-case pipeline counts, the 50-pipeline line. REFUSALS.md regenerated; API.md; api_signatures blessed; api_surface pins DEEP_THREADGROUP. Tests: the translator runs a barrier-exchange kernel at 1x1x320, 2x3x100, 1x4x256 (deep) and 4x4x4 on the interpreter, checks the evaluated WorkgroupSize, no key on Device::new, the binder's setting on an NVIDIA profile, and the reported maxima; rt's choice tests drop the device limit; the observing-kernel device test adds deep whole, ragged and indirect dispatches; the square test adds a column 256 deep. Verified: built and tested under the check job named in the report.
This commit is contained in:
1 parent
5c5ce57119
commit
70dffca0c2
25 files changed
+551
-167
No files matched your search
@@ -869,8 +869,7 @@ that touch blocks first.
|
||||
where it is deeper, on one `VkPipeline` per tile, made at the kernel's first dispatch at that
|
||||
tile, which waits for it, each thread's position the workgroup's origin plus its place in it,
|
||||
with no decode. Those pipelines are kept with the kernel's others, at most one per tile of the
|
||||
45 a rule's tile can be. A tile past the device's `maxComputeWorkGroupSize` runs as the next
|
||||
item's;
|
||||
45 a rule's tile can be. A tile deeper than 64 runs as one row of its 256 threads (below);
|
||||
- a grid of any other such kernel in tiles: workgroups of 256 threads on one `VkPipeline`, made
|
||||
with the state, each one tile of the grid, which its region carries. A thread's position is
|
||||
the tile's origin plus its index masked and shifted by the tile's sides, with no division.
|
||||
@@ -884,6 +883,19 @@ that touch blocks first.
|
||||
second time, plainly: its whole grids, `dispatch_threadgroups` and indirect dispatches run that
|
||||
module at their own size, and a `dispatch_threads` grid that is not a whole number of
|
||||
threadgroups runs the variant.
|
||||
- A threadgroup deeper than 64, the floor's `maxComputeWorkGroupSize[2]`, runs as one row of its
|
||||
threads, a workgroup of `x·y·z` by 1 by 1, each thread's position its index unflattened in
|
||||
Metal's order (the translator's `SpecKey::DeepThreadgroup`), on every device alike; any other
|
||||
threadgroup is its own workgroup. A kernel's threadgroup memory, barriers, SIMD groups and grid
|
||||
are the same either way, an indirect dispatch's included. So every threadgroup Metal allows,
|
||||
up to 1,024 threads on any axis, runs on every device, and `MetalDeviceProperties` on the
|
||||
runtime's profile reports 1,024 on each axis of `max_threads_per_threadgroup`. The form follows
|
||||
from the size, which keys a `VkPipeline` already, so it adds none, and the most a kernel makes
|
||||
is the same with it or without: for its direct dispatches, one for the tiles of a kernel that
|
||||
runs its grid in tiles, 46 for an image-only one (the square one and one per tile, three of
|
||||
whose tiles are deeper than 64), and for one that observes its partition one per threadgroup
|
||||
size and threadgroup memory lengths, and one more per size for grids that are not whole
|
||||
threadgroups; for any kernel's indirect dispatches, one per size and lengths.
|
||||
- A kernel whose SIMD groups run one per subgroup of 32 (pinned where the device lists compute in
|
||||
`requiredSubgroupSizeStages` with 32 between its sizes, or the device's own 32), or one per
|
||||
32-lane cluster of a 64- or 128-lane subgroup, runs only workgroups of whole subgroups.
|
||||
@@ -977,11 +989,10 @@ With no directory, nothing is kept on disk, and each `VkPipeline` is made withou
|
||||
- An image-only kernel's first dispatch over a grid more than one deep at a tile no state of its
|
||||
content has run makes that tile's `VkPipeline` on the calling thread, which waits for it
|
||||
(`Metrics::first_use_waits`), from its file in the cache directory where there is one. In each of
|
||||
the two recorded streams measured, that made 49 pipelines, all in one frame: the frame where the
|
||||
stream's image-only dispatches over such grids start (frame 224 of one stream and 312 of the
|
||||
other). One more in each, of tile 1x1x256, runs where the device's `maxComputeWorkGroupSize` is 64
|
||||
deep (NVIDIA's) in the tiles its regions carry, on the pipeline made with the state, and makes a
|
||||
50th elsewhere.
|
||||
the two recorded streams measured, on a device that holds 1,024 threads along `z`, that made 50
|
||||
pipelines, all in one frame: the frame where the stream's image-only dispatches over such grids
|
||||
start (frame 224 of one stream and 312 of the other). The 50th, of tile 1x1x256, runs as one row,
|
||||
so a device that holds 64 makes the same 50.
|
||||
- A kernel that observes its threadgroup partition is lowered twice at creation (its variant and
|
||||
its plain module). For the observing kernel the device tests run, a grid template over
|
||||
threadgroup memory, the second lowering took 0.61 to 0.63 ms and the whole creation 2.7 to
|
||||
@@ -1367,7 +1378,7 @@ Metal's 1,024 threads in any shape up to 1,024 by 1,024 by 64. A Boolean limit's
|
||||
| `maxComputeWorkGroupInvocations` | `1024` | Metal's most threads per threadgroup |
|
||||
| `maxComputeWorkGroupSize[0]` | `1024` | a threadgroup's width |
|
||||
| `maxComputeWorkGroupSize[1]` | `1024` | a threadgroup's height |
|
||||
| `maxComputeWorkGroupSize[2]` | `64` | a threadgroup's depth |
|
||||
| `maxComputeWorkGroupSize[2]` | `64` | a threadgroup's depth; a deeper one runs as one row |
|
||||
| `timestampComputeAndGraphics` | `1` | GPU times of command buffers |
|
||||
| `timestampValidBits` | `36` | GPU times of command buffers |
|
||||
|
||||
|
||||
@@ -422,7 +422,6 @@ impl Device {
|
||||
let sampler_cap = limits.max_sampler_allocation_count.saturating_sub(2);
|
||||
let limits = EncoderLimits {
|
||||
max_group_count: limits.max_compute_work_group_count,
|
||||
max_group_size: limits.max_compute_work_group_size,
|
||||
max_shared_memory: limits.max_compute_shared_memory_size,
|
||||
max_viewport: limits.max_viewport_dimensions,
|
||||
viewport_bounds: limits.viewport_bounds_range,
|
||||
@@ -968,8 +967,6 @@ unsafe fn objects(
|
||||
pub(crate) struct EncoderLimits {
|
||||
/// `maxComputeWorkGroupCount`.
|
||||
pub(crate) max_group_count: [u32; 3],
|
||||
/// `maxComputeWorkGroupSize`.
|
||||
pub(crate) max_group_size: [u32; 3],
|
||||
/// `maxComputeSharedMemorySize`.
|
||||
pub(crate) max_shared_memory: u32,
|
||||
/// `maxViewportDimensions`.
|
||||
|
||||
@@ -5,6 +5,7 @@ use crate::command::{Building, CommandBuffer};
|
||||
use crate::counters::Metric;
|
||||
use crate::error::{Error, Gap, Limit, Refusal};
|
||||
use crate::fence::Fence;
|
||||
use crate::floor;
|
||||
use crate::hazard::Access;
|
||||
use crate::memory::BlockId;
|
||||
use crate::over;
|
||||
@@ -18,7 +19,9 @@ use crate::sampler::SamplerState;
|
||||
use crate::texture::Texture;
|
||||
use ash::vk;
|
||||
use metal2vulkan::metal::format::integer_channels_word;
|
||||
use metal2vulkan::pipeline::{grid_tile, nonuniform_region_bytes, region_bytes, GRID_TILE_THREADS};
|
||||
use metal2vulkan::pipeline::{
|
||||
grid_tile, nonuniform_region_bytes, region_bytes, DEEP_THREADGROUP, GRID_TILE_THREADS,
|
||||
};
|
||||
use std::ops::BitOr;
|
||||
use std::sync::Arc;
|
||||
|
||||
@@ -230,17 +233,19 @@ pub(crate) struct Choice {
|
||||
}
|
||||
|
||||
/// How a state of `form` runs a dispatch of threadgroup size `size`, direct over `direct` or
|
||||
/// indirect, on a device whose `maxComputeWorkGroupSize` is `max`:
|
||||
/// indirect, the same on every device:
|
||||
/// - 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 the grid's `grid_tile` tile over a deeper one,
|
||||
/// the region carrying them, flagged where they do not divide the grid; a tile past `max` runs
|
||||
/// as a tiling kernel's does;
|
||||
/// 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.
|
||||
pub(crate) fn choose(form: &Form, direct: Option<Direct>, size: [u32; 3], max: [u32; 3]) -> Choice {
|
||||
///
|
||||
/// A size deeper than `DEEP_THREADGROUP` runs as one row of its threads ([`Constant::Deep`]),
|
||||
/// so every workgroup is within the floor's `maxComputeWorkGroupSize`.
|
||||
pub(crate) fn choose(form: &Form, direct: Option<Direct>, size: [u32; 3]) -> Choice {
|
||||
let Some(direct) = direct else {
|
||||
return Choice {
|
||||
module: Module::Whole,
|
||||
@@ -267,16 +272,14 @@ pub(crate) fn choose(form: &Form, direct: Option<Direct>, size: [u32; 3], max: [
|
||||
};
|
||||
match form {
|
||||
Form::Square if threads[2] == 1 => whole(SQUARE),
|
||||
Form::Tiled | Form::Square => {
|
||||
Form::Square => whole(grid_tile(threads)),
|
||||
Form::Tiled => {
|
||||
let tile = grid_tile(threads);
|
||||
match form {
|
||||
Form::Square if fits(tile, max) => whole(tile),
|
||||
_ => Choice {
|
||||
module: Module::Tiles,
|
||||
local: [GRID_TILE_THREADS, 1, 1],
|
||||
nominal: tile,
|
||||
direct: over(tile),
|
||||
},
|
||||
Choice {
|
||||
module: Module::Tiles,
|
||||
local: [GRID_TILE_THREADS, 1, 1],
|
||||
nominal: tile,
|
||||
direct: over(tile),
|
||||
}
|
||||
}
|
||||
Form::Sized { .. } => Choice {
|
||||
@@ -291,10 +294,12 @@ pub(crate) fn choose(form: &Form, direct: Option<Direct>, size: [u32; 3], max: [
|
||||
}
|
||||
}
|
||||
|
||||
/// Whether a workgroup of `local` is within the device's `maxComputeWorkGroupSize`, `max`.
|
||||
pub(crate) fn fits(local: [u32; 3], max: [u32; 3]) -> bool {
|
||||
local.iter().zip(max).all(|(&axis, max)| axis <= max)
|
||||
}
|
||||
// A workgroup one deep at most `DEEP_THREADGROUP`, or one row of at most Metal's 1,024
|
||||
// threads, is within the floor's sizes.
|
||||
const _: () = assert!(
|
||||
DEEP_THREADGROUP <= floor::WORKGROUP_SIZE[2]
|
||||
&& floor::WORKGROUP_INVOCATIONS <= floor::WORKGROUP_SIZE[0]
|
||||
);
|
||||
|
||||
impl CommandBuffer {
|
||||
/// `computeCommandEncoderWithDispatchType:`; `computeCommandEncoder` is this call with
|
||||
@@ -591,7 +596,7 @@ impl ComputeCommandEncoder {
|
||||
///
|
||||
/// Err: [`Refusal::NoPipeline`]; [`Refusal::ThreadgroupSize`];
|
||||
/// [`Refusal::BufferOffsetAlignment`] for a buffer the kernel reaches bound off its argument's
|
||||
/// alignment, which nothing records; [`Limit::ThreadgroupShape`];
|
||||
/// alignment, which nothing records;
|
||||
/// [`Limit::ThreadgroupMemory`]; [`Gap::PartialSimdgroups`] for a threadgroup that is not
|
||||
/// whole SIMD groups of a kernel whose tier needs them and that has no emulated module;
|
||||
/// [`Error::Quiesced`] where the device was quiesced before that module was lowered;
|
||||
@@ -753,16 +758,7 @@ impl ComputeCommandEncoder {
|
||||
local,
|
||||
nominal,
|
||||
direct,
|
||||
} = choose(&inner.form, direct, size, limits.max_group_size);
|
||||
// The workgroup Vulkan runs is within the device's sizes: the threadgroup itself where it
|
||||
// is the workgroup, else the tiles' or the square workgroup, which the floor holds, or a
|
||||
// tile, which `choose` held to them.
|
||||
if !fits(local, limits.max_group_size) {
|
||||
return Err(Error::Limit(Limit::ThreadgroupShape {
|
||||
size: local,
|
||||
max: limits.max_group_size,
|
||||
}));
|
||||
}
|
||||
} = choose(&inner.form, direct, size);
|
||||
let kernel = match (module, &inner.form) {
|
||||
(
|
||||
Module::Partial,
|
||||
|
||||
@@ -942,19 +942,6 @@ pub enum Limit {
|
||||
///
|
||||
/// Basis: ours (block numbers are 32 bits).
|
||||
BlockIds,
|
||||
/// A threadgroup longer on an axis than the device's `maxComputeWorkGroupSize` (the floor holds
|
||||
/// 1,024 by 1,024 by 64), where the threadgroup is the Vulkan workgroup: a kernel that observes
|
||||
/// its threadgroup partition, and any kernel's indirect dispatch. A direct dispatch of a kernel
|
||||
/// that does not observe it runs in workgroups of the runtime's, within the floor, whatever its
|
||||
/// threadgroup size. Metal's go to 1,024 on every axis.
|
||||
///
|
||||
/// Basis: device (the device's `maxComputeWorkGroupSize`).
|
||||
ThreadgroupShape {
|
||||
/// The threadgroup size asked for.
|
||||
size: [u32; 3],
|
||||
/// The device's most.
|
||||
max: [u32; 3],
|
||||
},
|
||||
/// A dispatch whose threadgroup memory, the kernel's own and the lengths set (each rounded up
|
||||
/// to 16 bytes), is past the device's `maxComputeSharedMemorySize`; for a threadgroup that
|
||||
/// runs the emulated-SIMD-group module, with the scratch of its SIMD groups. Metal's
|
||||
@@ -1407,9 +1394,6 @@ impl fmt::Display for Limit {
|
||||
"a block of {len} bytes is past the device's largest, {max} bytes"
|
||||
),
|
||||
Limit::BlockIds => f.write_str("every block number has been used"),
|
||||
Limit::ThreadgroupShape { size, max } => {
|
||||
write!(f, "a threadgroup of {size:?} is past the device's {max:?}")
|
||||
}
|
||||
Limit::ThreadgroupMemory { length, max } => write!(
|
||||
f,
|
||||
"{length} bytes of threadgroup memory are past the device's {max}"
|
||||
|
||||
@@ -57,7 +57,7 @@ use metal2vulkan::pipeline::{
|
||||
ComputePipelineDescriptor, DescriptorSetLayout, FunctionDescriptor, LoweringInputs,
|
||||
NumberedSampler, PrecisionNote, PushField, PushLoc, RuntimeFact, SamplerRef, SlotClass,
|
||||
SlotInterface, SlotRef, SpecKey, Stage, StageEntries, StageSource, TextureAccess,
|
||||
GRID_TILE_THREADS,
|
||||
DEEP_THREADGROUP, GRID_TILE_THREADS,
|
||||
};
|
||||
use metal2vulkan::Budget;
|
||||
use std::ffi::CString;
|
||||
@@ -248,8 +248,8 @@ pub(crate) enum Form {
|
||||
/// The kernel does not observe its partition and is image-only
|
||||
/// (`CompiledFunction::is_image_only`): `whole` runs a direct dispatch at `MultiRegion` 0,
|
||||
/// whatever the threadgroup size, in workgroups of [`SQUARE`] over a grid one deep and of the
|
||||
/// grid's `grid_tile` tile over a deeper one, a tile past the device's
|
||||
/// `maxComputeWorkGroupSize` as [`Form::Tiled`] does.
|
||||
/// grid's `grid_tile` tile over a deeper one, a tile deeper than `DEEP_THREADGROUP` as one
|
||||
/// row ([`Constant::Deep`]).
|
||||
Square,
|
||||
/// 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
|
||||
@@ -372,6 +372,9 @@ pub(crate) enum Constant {
|
||||
/// tile; 0 for every other launch, whose region states the pipeline's own threadgroup size,
|
||||
/// so the kernel takes `L` from its workgroup size and reads no decode.
|
||||
MultiRegion,
|
||||
/// `DeepThreadgroup`: 1 where the threadgroup is deeper than `DEEP_THREADGROUP`, which then
|
||||
/// runs as one row of its threads, 0 for every other, whose workgroup is the threadgroup.
|
||||
Deep,
|
||||
}
|
||||
|
||||
/// A parameter and where it goes.
|
||||
@@ -971,6 +974,7 @@ fn interface(
|
||||
.ok_or_else(gap)?,
|
||||
),
|
||||
SpecKey::MultiRegion => Constant::MultiRegion,
|
||||
SpecKey::DeepThreadgroup => Constant::Deep,
|
||||
_ => return Err(gap()),
|
||||
};
|
||||
constants.push((constant.id, set));
|
||||
@@ -983,6 +987,15 @@ fn interface(
|
||||
if !multiples.is_empty() && !flat {
|
||||
return Err(gap());
|
||||
}
|
||||
// Every workgroup is within the floor's sizes: a flattened one is one row of the threadgroup,
|
||||
// and any other runs a threadgroup deeper than `DEEP_THREADGROUP` as one row, which a module
|
||||
// that cannot (compute derivatives) does not declare.
|
||||
let deep = constants
|
||||
.iter()
|
||||
.any(|(_, set)| matches!(set, Constant::Deep));
|
||||
if !flat && !deep {
|
||||
return Err(gap());
|
||||
}
|
||||
let max_total_threads = match required_size {
|
||||
Some(size) => size.iter().product(),
|
||||
None => pipeline.metal_info.max_total_threads_per_threadgroup,
|
||||
@@ -1291,6 +1304,7 @@ impl Kernel {
|
||||
Constant::Threads => variant.size.iter().product(),
|
||||
Constant::ThreadgroupLength(at) => variant.threadgroup_lengths[at],
|
||||
Constant::MultiRegion => u32::from(variant.tiles),
|
||||
Constant::Deep => u32::from(variant.size[2] > DEEP_THREADGROUP),
|
||||
})
|
||||
.flat_map(u32::to_ne_bytes)
|
||||
.collect();
|
||||
|
||||
@@ -1,18 +1,16 @@
|
||||
//! What runs a compute dispatch (`encoder::choose`), with no device. An image-only kernel that does
|
||||
//! not observe its threadgroup partition runs its grid at `MultiRegion` 0 in workgroups of 16x16x1
|
||||
//! where it is one deep and of its tile where it is deeper, with no tile decode and its edge tested
|
||||
//! where they do not divide the grid. A kernel that does not observe it and is not image-only runs
|
||||
//! every grid in the tiles the region carries, as an image-only kernel does where its tile is past
|
||||
//! the device's sizes. An observing kernel runs at its own size. Every workgroup a kernel that does not observe its
|
||||
//! partition runs is within the device's `maxComputeWorkGroupSize`, whatever its threadgroup size.
|
||||
//! What runs a compute dispatch (`encoder::choose`), with no device: the same on every device. An
|
||||
//! image-only kernel that does not observe its threadgroup partition runs its grid at
|
||||
//! `MultiRegion` 0 in workgroups of 16x16x1 where it is one deep and of its tile where it is
|
||||
//! deeper, with no tile decode and its edge tested where they do not divide the grid. A kernel that
|
||||
//! does not observe it and is not image-only runs every grid in the tiles the region carries. An
|
||||
//! observing kernel runs at its own size. A size deeper than `DEEP_THREADGROUP` runs as one row of
|
||||
//! its threads, so every workgroup is within the floor's `maxComputeWorkGroupSize`, whatever the
|
||||
//! threadgroup size.
|
||||
|
||||
use crate::encoder::{choose, fits, Choice, Direct, Module};
|
||||
use crate::encoder::{choose, Choice, Direct, Module};
|
||||
use crate::floor::{WORKGROUP_INVOCATIONS, WORKGROUP_SIZE};
|
||||
use crate::pipeline::{Form, SQUARE};
|
||||
use ash::vk;
|
||||
use metal2vulkan::pipeline::{grid_tile, GRID_TILE_THREADS};
|
||||
|
||||
/// A `maxComputeWorkGroupSize` of 1,024 by 1,024 by 64: the floor's, and NVIDIA's.
|
||||
const MAX: [u32; 3] = [1024, 1024, 64];
|
||||
use metal2vulkan::pipeline::{grid_tile, DEEP_THREADGROUP, GRID_TILE_THREADS};
|
||||
|
||||
/// A `dispatchThreads` grid of `threads` in threadgroups of `size`.
|
||||
fn threads_of(threads: [u32; 3], size: [u32; 3]) -> Direct {
|
||||
@@ -47,7 +45,6 @@ fn an_image_only_kernels_grid_one_deep_runs_in_square_workgroups() {
|
||||
&Form::Square,
|
||||
Some(threads_of(threads, [8, 8, 1])),
|
||||
[8, 8, 1],
|
||||
MAX,
|
||||
);
|
||||
assert_eq!(
|
||||
choice,
|
||||
@@ -72,7 +69,6 @@ fn an_image_only_kernels_deeper_grid_runs_in_workgroups_of_its_tile() {
|
||||
&Form::Square,
|
||||
Some(threads_of(threads, [4, 4, 4])),
|
||||
[4, 4, 4],
|
||||
MAX,
|
||||
);
|
||||
assert_eq!(
|
||||
choice,
|
||||
@@ -105,7 +101,6 @@ fn a_tiling_kernel_runs_every_grid_in_its_regions_tiles() {
|
||||
&Form::Tiled,
|
||||
Some(threads_of(threads, [32, 1, 1])),
|
||||
[32, 1, 1],
|
||||
MAX,
|
||||
);
|
||||
assert_eq!(
|
||||
choice,
|
||||
@@ -125,22 +120,12 @@ fn a_tiling_kernel_runs_every_grid_in_its_regions_tiles() {
|
||||
#[test]
|
||||
fn an_observing_kernel_and_an_indirect_dispatch_run_at_their_own_size() {
|
||||
let sized = Form::Sized { partial: None };
|
||||
let whole = choose(
|
||||
&sized,
|
||||
Some(threads_of([64, 64, 1], [8, 8, 1])),
|
||||
[8, 8, 1],
|
||||
MAX,
|
||||
);
|
||||
let whole = choose(&sized, Some(threads_of([64, 64, 1], [8, 8, 1])), [8, 8, 1]);
|
||||
assert_eq!((whole.module, whole.local), (Module::Whole, [8, 8, 1]));
|
||||
let ragged = choose(
|
||||
&sized,
|
||||
Some(threads_of([60, 64, 1], [8, 8, 1])),
|
||||
[8, 8, 1],
|
||||
MAX,
|
||||
);
|
||||
let ragged = choose(&sized, Some(threads_of([60, 64, 1], [8, 8, 1])), [8, 8, 1]);
|
||||
assert_eq!(ragged.module, Module::Partial);
|
||||
for form in [Form::Tiled, Form::Square, Form::Sized { partial: None }] {
|
||||
let indirect = choose(&form, None, [4, 2, 1], MAX);
|
||||
let indirect = choose(&form, None, [4, 2, 1]);
|
||||
assert_eq!(
|
||||
indirect,
|
||||
Choice {
|
||||
@@ -153,34 +138,46 @@ fn an_observing_kernel_and_an_indirect_dispatch_run_at_their_own_size() {
|
||||
}
|
||||
}
|
||||
|
||||
/// A threadgroup 320 deep, on a device whose `maxComputeWorkGroupSize` is 1,024 by 1,024 by 64: a
|
||||
/// kernel that does not observe its partition runs it in a workgroup within the device's sizes,
|
||||
/// square, tiled or of its tile, over a grid one deep and a deeper one alike; an observing
|
||||
/// kernel's workgroup is the threadgroup, past the device's depth, which the encoder refuses
|
||||
/// (`Limit::ThreadgroupShape`). An image-only kernel whose grid's tile is past the device's depth
|
||||
/// (a column 1,024 deep, whose tile is 1 by 1 by 256) runs it in the tiles its regions carry.
|
||||
/// The workgroup a pipeline of local size `local` runs: one row of its threads where it is deeper
|
||||
/// than `DEEP_THREADGROUP` (`DeepThreadgroup` 1), else the threadgroup.
|
||||
fn workgroup(local: [u32; 3]) -> [u32; 3] {
|
||||
match local[2] > DEEP_THREADGROUP {
|
||||
true => [local.iter().product(), 1, 1],
|
||||
false => local,
|
||||
}
|
||||
}
|
||||
|
||||
/// A threadgroup 320 deep: every kernel runs it in a workgroup within the floor's sizes, the same
|
||||
/// on every device. One that does not observe its partition runs it square, tiled or of its tile,
|
||||
/// over a grid one deep and a deeper one alike; an observing kernel at its own size, as one row of
|
||||
/// its 320 threads, and so does an indirect dispatch. An image-only kernel whose grid's tile is
|
||||
/// deeper than `DEEP_THREADGROUP` (a column 1,024 deep, whose tile is 1 by 1 by 256) runs it whole,
|
||||
/// as one row of the tile's threads.
|
||||
#[test]
|
||||
fn a_threadgroup_deeper_than_the_device_runs_only_where_it_is_not_the_workgroup() {
|
||||
let limits = vk::PhysicalDeviceLimits {
|
||||
max_compute_work_group_size: MAX,
|
||||
..Default::default()
|
||||
fn a_threadgroup_deeper_than_the_floor_runs_as_one_row() {
|
||||
let within = |local: [u32; 3]| {
|
||||
let at = workgroup(local);
|
||||
(0..3).all(|axis| at[axis] <= WORKGROUP_SIZE[axis])
|
||||
&& at.iter().product::<u32>() <= WORKGROUP_INVOCATIONS
|
||||
};
|
||||
let max = limits.max_compute_work_group_size;
|
||||
let size = [1, 1, 320];
|
||||
for threads in [[4, 16, 320], [64, 64, 1], [1, 1, 1024]] {
|
||||
let direct = Some(threads_of(threads, size));
|
||||
for form in [Form::Tiled, Form::Square] {
|
||||
let choice = choose(&form, direct, size, max);
|
||||
assert!(fits(choice.local, max), "{threads:?}: {:?}", choice.local);
|
||||
for form in [Form::Tiled, Form::Square, Form::Sized { partial: None }] {
|
||||
let choice = choose(&form, direct, size);
|
||||
assert!(within(choice.local), "{threads:?}: {:?}", choice.local);
|
||||
}
|
||||
let sized = choose(&Form::Sized { partial: None }, direct, size, max);
|
||||
assert!(!fits(sized.local, max), "{threads:?}");
|
||||
let sized = choose(&Form::Sized { partial: None }, direct, size);
|
||||
assert_eq!(workgroup(sized.local), [320, 1, 1], "{threads:?}");
|
||||
}
|
||||
let indirect = choose(&Form::Sized { partial: None }, None, size);
|
||||
assert_eq!(workgroup(indirect.local), [320, 1, 1]);
|
||||
let column = [1, 1, 1024];
|
||||
assert_eq!(grid_tile(column), [1, 1, 256]);
|
||||
let choice = choose(&Form::Square, Some(threads_of(column, size)), size, max);
|
||||
let choice = choose(&Form::Square, Some(threads_of(column, size)), size);
|
||||
assert_eq!(
|
||||
(choice.module, choice.local, choice.nominal),
|
||||
(Module::Tiles, [GRID_TILE_THREADS, 1, 1], [1, 1, 256])
|
||||
(Module::Whole, [1, 1, 256], [1, 1, 256])
|
||||
);
|
||||
assert_eq!(workgroup(choice.local), [256, 1, 1]);
|
||||
}
|
||||
@@ -305,7 +305,8 @@ mod on_device {
|
||||
/// edge: over a grid of 20 by 12, ragged in both, a 32x32 destination holds the sample in the
|
||||
/// grid's texels and nothing past them, with no first-use wait. A grid two deep runs in
|
||||
/// workgroups of its tile on a `VkPipeline` made at that dispatch: one wait, the same
|
||||
/// texels.
|
||||
/// texels. A column 256 deep, whose tile is 1 by 1 by 256, deeper than 64, runs its tile as
|
||||
/// one row of 256 threads on every device: one wait, its one texel.
|
||||
#[test]
|
||||
fn every_device_runs_an_image_only_kernel_in_square_workgroups() {
|
||||
let Some(library) = library() else {
|
||||
@@ -372,8 +373,8 @@ mod on_device {
|
||||
"{name}: the square workgroups' pipeline, made with the state"
|
||||
);
|
||||
let queue = device.new_command_queue(4).expect("a queue");
|
||||
let grid = [20, 12];
|
||||
for (depth, waits) in [(1, 0), (2, 1)] {
|
||||
for (grid, depth, waits) in [([20, 12], 1, 0), ([20, 12], 2, 1), ([1, 1], 256, 1)] {
|
||||
fill(&output, OUT, [0.0; 4]);
|
||||
let before = counters.metrics();
|
||||
let command_buffer = queue.command_buffer().expect("a command buffer");
|
||||
let mut encoder = command_buffer
|
||||
|
||||
@@ -395,8 +395,10 @@ mod on_device {
|
||||
/// a barrier, and every builtin of the partition), translated twice at creation: a whole
|
||||
/// `dispatchThreads` grid runs its plain module at the call's size, a ragged one its
|
||||
/// partial-threadgroups variant, and a threadgroup count past the device's limit on an axis
|
||||
/// runs split, each piece reading Metal's whole grid. Each answer is Metal's, and each new
|
||||
/// size or module a first-use wait. Prints the creation's time and one lowering's.
|
||||
/// 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
|
||||
/// indirect. Each answer is Metal's, and each new size or module a first-use wait. Prints the
|
||||
/// creation's time and one lowering's.
|
||||
#[test]
|
||||
fn every_device_runs_an_observing_kernel_at_its_own_threadgroup_size() {
|
||||
let Some(descriptor) = descriptor("icb_replay_grid_template") else {
|
||||
@@ -414,22 +416,38 @@ mod on_device {
|
||||
let past = limits.max_compute_work_group_count[1]
|
||||
.checked_add(3)
|
||||
.filter(|&count| count <= 1 << 20);
|
||||
let runs: Vec<([u32; 3], [u32; 3], bool)> = [
|
||||
([10, 3, 1], [4, 2, 1], true),
|
||||
([8, 4, 1], [4, 2, 1], true),
|
||||
([3, 2, 1], [4, 2, 1], false),
|
||||
// How each run dispatches: a `dispatchThreads` grid, or threadgroup counts, direct or
|
||||
// from a buffer.
|
||||
#[derive(Clone, Copy, PartialEq)]
|
||||
enum How {
|
||||
Threads,
|
||||
Groups,
|
||||
Indirect,
|
||||
}
|
||||
let runs: Vec<([u32; 3], [u32; 3], How)> = [
|
||||
([10, 3, 1], [4, 2, 1], How::Threads),
|
||||
([8, 4, 1], [4, 2, 1], How::Threads),
|
||||
([3, 2, 1], [4, 2, 1], How::Groups),
|
||||
([1, 1, 2], [1, 1, 320], How::Groups),
|
||||
([1, 1, 500], [1, 1, 320], How::Threads),
|
||||
([1, 1, 2], [1, 1, 320], How::Indirect),
|
||||
([4, 3, 200], [2, 3, 100], How::Threads),
|
||||
]
|
||||
.into_iter()
|
||||
.chain(past.map(|count| ([1, count, 1], [1, 1, 1], false)))
|
||||
.chain(past.map(|count| ([1, count, 1], [1, 1, 1], How::Groups)))
|
||||
.collect();
|
||||
let mut buffers = Buffers::new(&device, 8 << 20);
|
||||
let arguments = buffers.buffer(16);
|
||||
write(&arguments, 0, &le_bytes(&[1, 1, 2]));
|
||||
let outs: Vec<(Buffer, Vec<u32>)> = runs
|
||||
.iter()
|
||||
.map(|&(grid, size, threads)| {
|
||||
.map(|&(grid, size, how)| {
|
||||
// A threadgroup dispatch's grid is its counts times its size.
|
||||
let grid = match threads {
|
||||
true => grid,
|
||||
false => std::array::from_fn(|axis| grid[axis] * size[axis]),
|
||||
let grid = match how {
|
||||
How::Threads => grid,
|
||||
How::Groups | How::Indirect => {
|
||||
std::array::from_fn(|axis| grid[axis] * size[axis])
|
||||
}
|
||||
};
|
||||
let slots = grid.iter().product::<u32>();
|
||||
let want = grid_template(grid, size, [1000, slots]);
|
||||
@@ -465,7 +483,7 @@ mod on_device {
|
||||
.compute_command_encoder(DispatchType::Serial)
|
||||
.expect("an encoder");
|
||||
encoder.set_compute_pipeline_state(&state).expect("a state");
|
||||
for (&(grid, size, threads), (out, want)) in runs.iter().zip(&outs) {
|
||||
for (&(grid, size, how), (out, want)) in runs.iter().zip(&outs) {
|
||||
let n = size.iter().product::<u32>();
|
||||
encoder
|
||||
.set_threadgroup_memory_length((4 * n).next_multiple_of(16), 0)
|
||||
@@ -474,9 +492,12 @@ mod on_device {
|
||||
.set_bytes(&le_bytes(&[1000, want.len() as u32]), 0)
|
||||
.expect("the parameters");
|
||||
encoder.set_buffer(Some(out), 0, 1).expect("a buffer");
|
||||
match threads {
|
||||
true => encoder.dispatch_threads(grid, size),
|
||||
false => encoder.dispatch_threadgroups(grid, size),
|
||||
match how {
|
||||
How::Threads => encoder.dispatch_threads(grid, size),
|
||||
How::Groups => encoder.dispatch_threadgroups(grid, size),
|
||||
How::Indirect => {
|
||||
encoder.dispatch_threadgroups_with_indirect_buffer(&arguments, 0, size)
|
||||
}
|
||||
}
|
||||
.unwrap_or_else(|error| panic!("{name}: {grid:?} by {size:?}: {error}"));
|
||||
}
|
||||
@@ -493,8 +514,10 @@ mod on_device {
|
||||
);
|
||||
}
|
||||
let after = device.counters().metrics();
|
||||
// The ragged grid's variant, the whole grid's size, the one-thread size.
|
||||
let sizes = 2 + u64::from(past.is_some());
|
||||
// The ragged grid's variant, the whole grid's size, the one-thread size; the deep
|
||||
// size, its ragged grid's variant (its indirect dispatch runs the whole one) and the
|
||||
// second deep size.
|
||||
let sizes = 5 + u64::from(past.is_some());
|
||||
assert_eq!(
|
||||
after.first_use_waits - created.first_use_waits,
|
||||
sizes,
|
||||
|
||||
@@ -36,8 +36,9 @@
|
||||
//! as Metal's threadgroup and the tiles times the tile as the grid, as plain Metal answers them
|
||||
//! under `threadgroupSizeMatchesTileSize`.
|
||||
//!
|
||||
//! Every region's local size is checked: in the flattened tiers `sn = x·y·z` against
|
||||
//! `maxComputeWorkGroupSize[0]`, `maxComputeWorkGroupInvocations`, and
|
||||
//! Every region's local size is checked: in the flattened tiers, and in a region deeper than
|
||||
//! `DEEP_THREADGROUP` of a kernel that declares `SpecKey::DeepThreadgroup` (which the region sets),
|
||||
//! `sn = x·y·z` against `maxComputeWorkGroupSize[0]`, `maxComputeWorkGroupInvocations`, and
|
||||
//! `maxComputeWorkgroupSubgroups · S`; otherwise each axis and the product; and against every
|
||||
//! `LocalSizeConstraint{multiple}` (`ComputeDerivatives` outside the flattened tiers). Metal's
|
||||
//! nominal size must be 1..=1024 per axis (the `DispatchRegion` packing).
|
||||
@@ -114,7 +115,8 @@ use crate::device::requirements::VkLimit;
|
||||
use crate::error::{BindError, Capability, Feature, LowerFamily, Unsupported};
|
||||
use crate::indirect_commands::BINDING_COUNT;
|
||||
use crate::lower::dispatch::{
|
||||
grid_tile, nonuniform_region_bytes, pack_nominal, region_bytes, GRID_TILE_THREADS,
|
||||
grid_tile, nonuniform_region_bytes, pack_nominal, region_bytes, DEEP_THREADGROUP,
|
||||
GRID_TILE_THREADS,
|
||||
};
|
||||
use crate::metal::vertex::vertex_bytes;
|
||||
use crate::metal::{StepFunction, VertexFormat};
|
||||
@@ -362,7 +364,7 @@ pub(crate) fn fit(
|
||||
fn check_local(rules: &LocalRules, r: [u32; 3]) -> Result<(), BindError> {
|
||||
let n: u64 = r.iter().map(|&x| u64::from(x)).product();
|
||||
let total = Feature::LocalSize { axis: None };
|
||||
if rules.flat {
|
||||
if rules.flat || (rules.deep && r[2] > DEEP_THREADGROUP) {
|
||||
let x = Feature::LocalSize {
|
||||
axis: Some(Axis::X),
|
||||
};
|
||||
@@ -1251,9 +1253,10 @@ impl BindingPlan {
|
||||
}
|
||||
|
||||
/// The specialization of a region of `local` threads of `t`: the template's fixed constants, the
|
||||
/// local size, whether the region reads its record (`MultiRegion`), and whether a stage-in element
|
||||
/// it fetches may lie past the first `2^32` bytes from its bind offset (`StageInReach`,
|
||||
/// [`stage_in_reach`]).
|
||||
/// local size, whether the region reads its record (`MultiRegion`), whether a stage-in element it
|
||||
/// fetches may lie past the first `2^32` bytes from its bind offset (`StageInReach`,
|
||||
/// [`stage_in_reach`]), and whether it runs as one row (`DeepThreadgroup`, deeper than
|
||||
/// [`DEEP_THREADGROUP`]).
|
||||
fn region_specialization(
|
||||
t: &ComputeTemplate,
|
||||
local: [u32; 3],
|
||||
@@ -1284,6 +1287,7 @@ fn region_specialization_into(
|
||||
SpecKey::FlatLocalSize => Some(n),
|
||||
SpecKey::MultiRegion => Some(u64::from(multi)),
|
||||
SpecKey::StageInReach => Some(u64::from(reach)),
|
||||
SpecKey::DeepThreadgroup => Some(u64::from(local[2] > DEEP_THREADGROUP)),
|
||||
other => match t.fixed.get(next.get()) {
|
||||
Some(&(at, v)) if at == other => {
|
||||
next.set(next.get() + 1);
|
||||
|
||||
@@ -28,6 +28,7 @@ fn compute_plan(t: &ComputeTemplate, variant: VariantKey) -> BindingPlan {
|
||||
|
||||
fn rules() -> LocalRules {
|
||||
LocalRules {
|
||||
deep: false,
|
||||
flat: false,
|
||||
multiples: Vec::new(),
|
||||
max_size: [1024, 1024, 64],
|
||||
|
||||
@@ -582,6 +582,9 @@ pub(crate) enum BoundKind {
|
||||
pub(crate) struct LocalRules {
|
||||
/// The flattened tiers' `(sn, 1, 1)` workgroup (`SpecKey::FlatLocalSize`).
|
||||
pub flat: bool,
|
||||
/// The kernel declares `SpecKey::DeepThreadgroup`: a region deeper than
|
||||
/// [`crate::pipeline::DEEP_THREADGROUP`] runs as one row, checked as the flattened tiers'.
|
||||
pub deep: bool,
|
||||
/// Every `LocalSizeConstraint{multiple}` of the pipeline.
|
||||
pub multiples: Vec<u32>,
|
||||
pub max_size: [u32; 3],
|
||||
|
||||
@@ -707,7 +707,8 @@ fn plan(p: &ComputePipeline, device: &Device, shape: &BindShape) -> Result<Bindi
|
||||
SpecKey::LocalSize(_)
|
||||
| SpecKey::FlatLocalSize
|
||||
| SpecKey::MultiRegion
|
||||
| SpecKey::StageInReach => continue,
|
||||
| SpecKey::StageInReach
|
||||
| SpecKey::DeepThreadgroup => continue,
|
||||
SpecKey::TgLength(n) => {
|
||||
let len = u64::from(ks.threadgroup_lengths.get(&n).copied().unwrap_or(0));
|
||||
let len = len.next_multiple_of(TG_ALIGN);
|
||||
@@ -813,6 +814,7 @@ fn plan(p: &ComputePipeline, device: &Device, shape: &BindShape) -> Result<Bindi
|
||||
.unwrap_or((0, 0));
|
||||
let local = LocalRules {
|
||||
flat: layout.iter().any(|c| c.key == SpecKey::FlatLocalSize),
|
||||
deep: layout.iter().any(|c| c.key == SpecKey::DeepThreadgroup),
|
||||
multiples,
|
||||
max_size: limits.max_compute_work_group_size,
|
||||
max_invocations: limits.max_compute_work_group_invocations,
|
||||
|
||||
+1
-1
@@ -887,7 +887,7 @@ codec_enum! {
|
||||
SamplerAnisotropy(f0), RangeAtBindOffset(f0), PlainHalfTexels(f0),
|
||||
NearestPixelSampler(f0), BoundSamplerWord(f0), HeapYCbCrTextures(f0),
|
||||
FilteringArgumentSampler, StageInReach, HeapRawTextures(f0), BorderTexels(f0),
|
||||
HeapNanFamilies(f0), HeapYCbCrWrites(f0),
|
||||
HeapNanFamilies(f0), HeapYCbCrWrites(f0), DeepThreadgroup,
|
||||
}
|
||||
PushField {
|
||||
RootTableAddress, ExecutionStatusAddress, DispatchRegion, BaseVertexInstance,
|
||||
|
||||
Vendored
+2
-2
@@ -61,7 +61,7 @@ mod tests;
|
||||
/// unchanged version, and its bless records the version. Independent of the crate's version and of
|
||||
/// [`ARTIFACT_FORMAT_VERSION`]. The commit that bumps it says what changed; this comment keeps no
|
||||
/// history.
|
||||
pub const SEMANTICS_VERSION: u32 = 2171;
|
||||
pub const SEMANTICS_VERSION: u32 = 2172;
|
||||
|
||||
/// The byte-layout version of encoded artifacts (`CompiledFunction::to_bytes` and the
|
||||
/// [`PipelineArtifact`] encodings). Every encoded artifact carries it, and a decode under another
|
||||
@@ -71,7 +71,7 @@ pub const SEMANTICS_VERSION: u32 = 2171;
|
||||
/// re-typed in an encoded type, its `codec` body or its `envelope`. A variant removed while its tag
|
||||
/// stays unused needs no bump: an entry holding it fails to decode, which is a miss. The commit that
|
||||
/// bumps it says what changed; this comment keeps no history.
|
||||
pub const ARTIFACT_FORMAT_VERSION: u32 = 535;
|
||||
pub const ARTIFACT_FORMAT_VERSION: u32 = 536;
|
||||
|
||||
/// The version of what this crate's runtime does with a compiled pipeline: instantiating a binding
|
||||
/// plan (`BindingPlan::instantiate_*`: descriptor ranges, push bytes, root, argument, and handle
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
//! drives translation.
|
||||
|
||||
use crate::device::description::AllocationLimits;
|
||||
use crate::device::profile::{BufferAccess, DeviceProfile};
|
||||
use crate::device::profile::{BufferAccess, DeepThreadgroups, DeviceProfile};
|
||||
use crate::device::requirements::{FormatUsage, VkFeature};
|
||||
use crate::device::subgroup::{tier, OpBits, SimdClass};
|
||||
use crate::error::{Capability, Feature, Unsupported};
|
||||
@@ -19,7 +19,8 @@ pub struct MetalDeviceProperties {
|
||||
/// `CmdGetComputeInfo` key 3).
|
||||
pub thread_execution_width: u32,
|
||||
/// Per axis: `maxComputeWorkGroupSize[i]` capped by `maxComputeWorkGroupInvocations`, and by an
|
||||
/// Apple GPU's 1024.
|
||||
/// Apple GPU's 1024; on `Device::from_queries`' profile, which runs a deep threadgroup as one
|
||||
/// row (`SpecKey::DeepThreadgroup`), the capped invocations on every axis.
|
||||
pub max_threads_per_threadgroup: [u32; 3],
|
||||
/// `maxComputeWorkGroupInvocations` (pipelines report a flattened-tier cap of their own),
|
||||
/// capped by an Apple GPU's 1024.
|
||||
@@ -168,7 +169,10 @@ impl MetalDeviceProperties {
|
||||
let threads = l
|
||||
.max_compute_work_group_invocations
|
||||
.min(apple_gpu::MAX_THREADS_PER_THREADGROUP);
|
||||
let per_axis = l.max_compute_work_group_size.map(|axis| axis.min(threads));
|
||||
let per_axis = match profile.deep_threadgroups() {
|
||||
DeepThreadgroups::Axes => l.max_compute_work_group_size.map(|axis| axis.min(threads)),
|
||||
DeepThreadgroups::OneRow => [threads; 3],
|
||||
};
|
||||
let d = &f.descriptors;
|
||||
let argument_buffers_tier = if f.buffer_access == BufferAccess::Addressed
|
||||
&& d.runtime_descriptor_array
|
||||
|
||||
@@ -138,6 +138,12 @@ impl DeviceProfile {
|
||||
self.facts.oblivious_edge
|
||||
}
|
||||
|
||||
/// How a kernel whose workgroup is its threadgroup runs a threadgroup deeper than the
|
||||
/// device's `maxComputeWorkGroupSize[2]`.
|
||||
pub(crate) fn deep_threadgroups(&self) -> DeepThreadgroups {
|
||||
self.facts.deep_threadgroups
|
||||
}
|
||||
|
||||
/// The profile's fields: internal; the profile is opaque to consumers, who compare
|
||||
/// [`DeviceProfile::fingerprint`] and read its facts through the accessors.
|
||||
pub(crate) fn fields(&self) -> &ProfileFields {
|
||||
@@ -582,6 +588,9 @@ pub(crate) struct ProfileFacts {
|
||||
/// How the partial-threadgroups variant of a kernel that does not observe its threadgroup
|
||||
/// partition runs the threads past its grid.
|
||||
pub(crate) oblivious_edge: ObliviousEdge,
|
||||
/// How a kernel whose workgroup is its threadgroup runs a deep threadgroup, and the
|
||||
/// threadgroup the device reports it runs.
|
||||
pub(crate) deep_threadgroups: DeepThreadgroups,
|
||||
}
|
||||
|
||||
impl ProfileFacts {
|
||||
@@ -596,6 +605,7 @@ impl ProfileFacts {
|
||||
half_fma: HalfFma::Measured,
|
||||
identity_region: IdentityRegion::Grid,
|
||||
oblivious_edge: ObliviousEdge::Partial,
|
||||
deep_threadgroups: DeepThreadgroups::Axes,
|
||||
};
|
||||
|
||||
/// `Device::from_queries`': each fact the same on every device.
|
||||
@@ -609,6 +619,7 @@ impl ProfileFacts {
|
||||
half_fma: HalfFma::Native,
|
||||
identity_region: IdentityRegion::Sized,
|
||||
oblivious_edge: ObliviousEdge::Grid,
|
||||
deep_threadgroups: DeepThreadgroups::OneRow,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -671,6 +682,22 @@ pub(crate) enum ObliviousEdge {
|
||||
Grid,
|
||||
}
|
||||
|
||||
/// How a kernel whose workgroup is its threadgroup (`lower::dispatch::LocalSizeForm::Spec`) runs
|
||||
/// a threadgroup deeper than the device's `maxComputeWorkGroupSize[2]`, and so what the device
|
||||
/// reports as Metal's `maxThreadsPerThreadgroup` (`MetalDeviceProperties`).
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
pub(crate) enum DeepThreadgroups {
|
||||
/// As its workgroup, axis for axis, so a device that holds fewer threads along `z` than the
|
||||
/// threadgroup refuses it at its plan (`bind::dispatch`'s local-size checks), and the device
|
||||
/// reports each axis's `maxComputeWorkGroupSize`: `Device::new`'s profile.
|
||||
Axes,
|
||||
/// As one row past [`DEEP_THREADGROUP`](crate::lower::dispatch::DEEP_THREADGROUP) along `z`
|
||||
/// (`SpecKey::DeepThreadgroup`), within every device's sizes, so the device reports
|
||||
/// `maxComputeWorkGroupInvocations` on every axis, as an Apple GPU reports 1024 on each:
|
||||
/// `Device::from_queries`' profile.
|
||||
OneRow,
|
||||
}
|
||||
|
||||
/// Which `half` fused multiply-adds take the device's 16-bit `Fma` (`lower::arith::fma::half_route`).
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
pub(crate) enum HalfFma {
|
||||
|
||||
@@ -12,6 +12,17 @@
|
||||
//! [`DispatchPlan::keys`]): link gives a key one id over the pipeline, and a mesh render pipeline's
|
||||
//! object and mesh threadgroups take separate sizes.
|
||||
//!
|
||||
//! **Deep threadgroups.** On `Device::from_queries`' profile (`DeepThreadgroups::OneRow`) a
|
||||
//! kernel of the `Spec` form declares `SpecKey::DeepThreadgroup` ([`DispatchPlan::deep`]), under
|
||||
//! which its `WorkgroupSize` is `(sn, 1, 1)`, `sn = sx·sy·sz` (each part an `OpSpecConstantOp`
|
||||
//! select of the constants) and its position in the threadgroup `LocalInvocationIndex`
|
||||
//! unflattened over `(sx, sy, sz)`: Metal allows 1024 threads along `z`, where a device's
|
||||
//! `maxComputeWorkGroupSize[2]` may hold 64, and a threadgroup of at most 1024 threads in one row
|
||||
//! fits every device the profile serves. The linear index keeps its value, `x` fastest either
|
||||
//! way, and so does every builtin derived from it, the workgroup's and the grid's. The runtime
|
||||
//! sets it for a threadgroup deeper than [`DEEP_THREADGROUP`] alone, so a pipeline of any other
|
||||
//! size specializes it away.
|
||||
//!
|
||||
//! **Builtins** ([`KernelBuiltin`]). Every Metal kernel builtin derives from a handful of Vulkan
|
||||
//! ones and the linear local index `lin`:
|
||||
//!
|
||||
@@ -172,7 +183,7 @@
|
||||
|
||||
use crate::air::abi::{Builtin, ParamBinding, ParamRole};
|
||||
use crate::air::ir::{ArgIdx, Value};
|
||||
use crate::device::profile::{IdentityRegion, ObliviousEdge};
|
||||
use crate::device::profile::{DeepThreadgroups, IdentityRegion, ObliviousEdge};
|
||||
use crate::device::subgroup::{self, SimdClass, Tier};
|
||||
use crate::error::{Error, Feature, LowerFamily, Unsupported};
|
||||
use crate::lower::arith;
|
||||
@@ -185,8 +196,8 @@ use crate::spirv::builder::{FunctionBuilder, ModuleBuilder};
|
||||
use crate::spirv::error::BResult;
|
||||
use crate::spirv::ids::{ConstId, DemoteTy, GlobalId, ScalarTy, TypeId, Value as SValue};
|
||||
use crate::spirv::ir::{
|
||||
BinOp, ConstBits, Constant, ConvOp, ExecMode, GlslOp, IoDir, MemAccess, StorageClass, Type,
|
||||
UnOp,
|
||||
BinOp, ConstBits, Constant, ConvOp, ExecMode, GlslOp, IoDir, MemAccess, SpecOp, StorageClass,
|
||||
Type, UnOp,
|
||||
};
|
||||
|
||||
/// The builder's error for a value the declarations do not hold.
|
||||
@@ -534,6 +545,10 @@ pub struct DispatchPlan {
|
||||
/// never reads `SubgroupSize`. `None` outside the flattened tiers and where the stage pins no
|
||||
/// size, where `lin` reads the builtin.
|
||||
pub pinned_subgroup_size: Option<u32>,
|
||||
/// A kernel of the [`LocalSizeForm::Spec`] form on a profile whose `DeepThreadgroups` is
|
||||
/// `OneRow`, without compute derivatives (whose quads are two-dimensional): it declares
|
||||
/// `SpecKey::DeepThreadgroup`, under which its threadgroup runs as one row (the module docs).
|
||||
pub deep: bool,
|
||||
}
|
||||
|
||||
/// The words a flat grid adds: its thread's index, position, and early return, derived once for the
|
||||
@@ -725,6 +740,10 @@ pub fn plan_kernel(cx: &mut SelectCx<'_>, tier: Tier) -> Result<DispatchPlan, Er
|
||||
if grid_edge {
|
||||
cx.facts.insert(RuntimeFact::GridTiles);
|
||||
}
|
||||
let deep = local_size == LocalSizeForm::Spec
|
||||
&& cx.stage == crate::pipeline::sym::Stage::Kernel
|
||||
&& cx.profile.deep_threadgroups() == DeepThreadgroups::OneRow
|
||||
&& !cx.families.barrier.compute_derivatives;
|
||||
Ok(DispatchPlan {
|
||||
local_size,
|
||||
builtins,
|
||||
@@ -744,6 +763,7 @@ pub fn plan_kernel(cx: &mut SelectCx<'_>, tier: Tier) -> Result<DispatchPlan, Er
|
||||
identity_region: crate::lower::access::identity(cx.profile)
|
||||
.then(|| cx.profile.identity_region()),
|
||||
pinned_subgroup_size,
|
||||
deep,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -977,6 +997,8 @@ pub struct KernelDecl {
|
||||
uvec3: TypeId,
|
||||
/// `sx, sy, sz`.
|
||||
size: [ConstId; 3],
|
||||
/// `SpecKey::DeepThreadgroup`, where the plan declares it ([`DispatchPlan::deep`]).
|
||||
deep: Option<ConstId>,
|
||||
/// How the kernel tells a region, when it reads a grid builtin.
|
||||
multi_region: Option<RegionSelect>,
|
||||
local_id: Option<GlobalId>,
|
||||
@@ -1128,6 +1150,11 @@ pub fn pack_nominal(l: [u32; 3]) -> Option<u32> {
|
||||
/// (`RuntimeFact::GridTiles`).
|
||||
pub const GRID_TILE_THREADS: u32 = 256;
|
||||
|
||||
/// The deepest threadgroup a kernel runs as its own workgroup on `Device::from_queries`' profile:
|
||||
/// one deeper runs as one row (`SpecKey::DeepThreadgroup`). The least `maxComputeWorkGroupSize[2]`
|
||||
/// of the devices that profile serves (Vulkan's own minimum).
|
||||
pub const DEEP_THREADGROUP: u32 = 64;
|
||||
|
||||
/// The tile a kernel's grid tiles (`RuntimeFact::GridTiles`) cover a grid of `threads` with: sides
|
||||
/// `2^a, 2^b, 2^c` with `a + b + c = 8`, so that one workgroup of [`GRID_TILE_THREADS`] is one
|
||||
/// tile, dispatched as `⌈threads / tile⌉` workgroups per axis. Of every such tile it is the first
|
||||
@@ -1245,7 +1272,22 @@ impl KernelDecl {
|
||||
]
|
||||
.map(|(k, d)| mb.spec(k, u32_, ConstBits(u64::from(d))));
|
||||
let size = [sx?, sy?, sz?];
|
||||
let mut deep = None;
|
||||
match dp.local_size {
|
||||
LocalSizeForm::Spec if dp.deep => {
|
||||
let b = mb.ty(Type::Bool)?;
|
||||
let one_row = mb.spec(SpecKey::DeepThreadgroup, b, ConstBits(0))?;
|
||||
let row = mb.spec_op(SpecOp::IMul, u32_, &[size[0], size[1]])?;
|
||||
let sn = mb.spec_op(SpecOp::IMul, u32_, &[row, size[2]])?;
|
||||
let one = mb.constant(Constant::Scalar {
|
||||
ty: u32_,
|
||||
bits: ConstBits(1),
|
||||
})?;
|
||||
let [x, y, z] = [(sn, size[0]), (one, size[1]), (one, size[2])]
|
||||
.map(|(deep, own)| mb.spec_op(SpecOp::Select, u32_, &[one_row, deep, own]));
|
||||
mb.workgroup_size(x?, y?, z?)?;
|
||||
deep = Some(one_row);
|
||||
}
|
||||
LocalSizeForm::Spec => {
|
||||
mb.workgroup_size(size[0], size[1], size[2])?;
|
||||
}
|
||||
@@ -1280,8 +1322,10 @@ impl KernelDecl {
|
||||
// A flat grid counts its threads by `LocalInvocationIndex` in either form: it reads no
|
||||
// simdgroup. One of the call's threadgroups counts them by `lin`, its simdgroups' lanes.
|
||||
let by_index = dp.flat_grid && !dp.call_threadgroups;
|
||||
// A grid tile counts by `LocalInvocationIndex` in either form too.
|
||||
let index = needs.lin && (!flat || by_index || dp.grid_edge);
|
||||
// A grid tile counts by `LocalInvocationIndex` in either form too, and a deep
|
||||
// threadgroup's position is unflattened from it.
|
||||
let index = (needs.lin && (!flat || by_index || dp.grid_edge))
|
||||
|| (needs.local_pos && deep.is_some());
|
||||
let subgroups = needs.lin && flat && !by_index && !dp.grid_edge;
|
||||
use crate::spv::BuiltIn as B;
|
||||
// A wrapper that computes the threadgroup's position and grid stores them into private
|
||||
@@ -1320,6 +1364,7 @@ impl KernelDecl {
|
||||
draw_index: var(dp.draw_pieces, B::DrawIndex, u32_)?,
|
||||
uvec3,
|
||||
size,
|
||||
deep,
|
||||
multi_region,
|
||||
local_id: var(
|
||||
needs.local_pos && !flat && !dp.tile,
|
||||
@@ -1481,7 +1526,26 @@ impl KernelDecl {
|
||||
return self.tile_pos(fb, lin);
|
||||
}
|
||||
let uniform = match self.form {
|
||||
LocalSizeForm::Spec => self.load(fb, self.local_id)?,
|
||||
LocalSizeForm::Spec => {
|
||||
let id = self.load(fb, self.local_id)?;
|
||||
match self.deep {
|
||||
// A deep threadgroup's row, unflattened as the flattened tiers' is; any
|
||||
// other's own position, which the driver keeps alone when it specializes.
|
||||
Some(deep) => {
|
||||
let index = self.load(fb, self.local_index)?;
|
||||
let sx = fb.module().const_value(self.size[0])?;
|
||||
let sy = fb.module().const_value(self.size[1])?;
|
||||
let x = fb.binary(BinOp::UMod, index, sx)?;
|
||||
let row = fb.binary(BinOp::UDiv, index, sx)?;
|
||||
let y = fb.binary(BinOp::UMod, row, sy)?;
|
||||
let z = fb.binary(BinOp::UDiv, row, sy)?;
|
||||
let at = fb.composite_construct(self.uvec3, &[x, y, z])?;
|
||||
let deep = fb.module().const_value(deep)?;
|
||||
fb.select(deep, at, id)?
|
||||
}
|
||||
None => id,
|
||||
}
|
||||
}
|
||||
LocalSizeForm::Flat => {
|
||||
let lin = self.lin(fb)?;
|
||||
let sx = fb.module().const_value(self.size[0])?;
|
||||
|
||||
@@ -149,9 +149,11 @@ pub use compile::{
|
||||
};
|
||||
pub use facts::{Mechanism, RuntimeFact, UniformViewChoice};
|
||||
// The `DispatchRegion` push field's bytes, which a consumer of the identity domains pushes with
|
||||
// each dispatch, and the tile a kernel's grid tiles cover a grid with (`RuntimeFact::GridTiles`).
|
||||
// each dispatch, the tile a kernel's grid tiles cover a grid with (`RuntimeFact::GridTiles`), and
|
||||
// the depth past which a threadgroup runs as one row (`SpecKey::DeepThreadgroup`).
|
||||
pub use crate::lower::dispatch::{
|
||||
grid_tile, nonuniform_region_bytes, region_bytes, GRID_TILE_THREADS, NONUNIFORM,
|
||||
grid_tile, nonuniform_region_bytes, region_bytes, DEEP_THREADGROUP, GRID_TILE_THREADS,
|
||||
NONUNIFORM,
|
||||
};
|
||||
// The threadgroup memory of an emulated-simdgroup module's arena (`RuntimeFact::SimdgroupEmulation`),
|
||||
// which a consumer of the identity domains counts with each dispatch's scratch.
|
||||
|
||||
@@ -947,6 +947,15 @@ pub enum SpecKey {
|
||||
/// nothing for it and the write's test is dead code at pipeline creation, exactly, since no
|
||||
/// handle the command names then names such a texture. A pipeline's key carries it.
|
||||
HeapYCbCrWrites(Stage),
|
||||
/// Boolean: the kernel's threadgroup runs as one row (default false). Its workgroup is then
|
||||
/// `(sx·sy·sz, 1, 1)`, and its position in the threadgroup is its `LocalInvocationIndex`
|
||||
/// unflattened over `(sx, sy, sz)`, `x` fastest, which is Metal's order, so its linear index
|
||||
/// and every other builtin keep their values. Declared on `Device::from_queries`' profile by
|
||||
/// a kernel whose workgroup is its threadgroup (`LocalSizeForm::Spec`), so a threadgroup
|
||||
/// deeper than [`DEEP_THREADGROUP`](crate::pipeline::DEEP_THREADGROUP) runs within every
|
||||
/// device's `maxComputeWorkGroupSize`; where it is false the workgroup is `(sx, sy, sz)` and
|
||||
/// the pipeline is the one the kernel makes without it.
|
||||
DeepThreadgroup,
|
||||
}
|
||||
|
||||
impl SpecKey {
|
||||
|
||||
@@ -375,8 +375,9 @@ impl Consts {
|
||||
}
|
||||
|
||||
/// Declare the module's `WorkgroupSize` composite of `ty` (a `u32` 3-vector) from three
|
||||
/// positive `u32` constants, at least one of them a specialization constant. Declaring it again with the same parts returns the first
|
||||
/// declaration; different parts are a conflict.
|
||||
/// positive `u32` constants ([`Consts::positive`]), at least one of them a specialization
|
||||
/// constant or an `OpSpecConstantOp` of them. Declaring it again with the same parts returns
|
||||
/// the first declaration; different parts are a conflict.
|
||||
pub fn workgroup_size(
|
||||
&mut self,
|
||||
ty: TypeId,
|
||||
@@ -410,17 +411,11 @@ impl Consts {
|
||||
let mut specs = 0;
|
||||
for p in parts {
|
||||
let def = self.get(p)?;
|
||||
// A local size of zero is invalid on every axis, so a part (a specialization
|
||||
// constant's default, or a plain constant) must be positive.
|
||||
let positive = match &def.kind {
|
||||
ConstKind::Spec { default, .. } => {
|
||||
specs += 1;
|
||||
default.0 != 0
|
||||
}
|
||||
ConstKind::Plain(Constant::Scalar { bits, .. }) => bits.0 != 0,
|
||||
_ => false,
|
||||
};
|
||||
if def.ty != u32_elem || !positive {
|
||||
if matches!(def.kind, ConstKind::Spec { .. } | ConstKind::SpecOp { .. }) {
|
||||
specs += 1;
|
||||
}
|
||||
// A local size of zero is invalid on every axis, so a part must be positive.
|
||||
if def.ty != u32_elem || !self.positive(p)? {
|
||||
return Err(BuildError::Constant(ConstRule::CompositeParts));
|
||||
}
|
||||
}
|
||||
@@ -436,6 +431,25 @@ impl Consts {
|
||||
Ok((id, true))
|
||||
}
|
||||
|
||||
/// Whether constant `c` is positive at its defaults: a plain scalar or a specialization
|
||||
/// constant's default above 0, or a product or select of such. An `OpSpecConstantOp` of any
|
||||
/// other operation is not known to be.
|
||||
fn positive(&self, c: ConstId) -> BResult<bool> {
|
||||
Ok(match &self.get(c)?.kind {
|
||||
ConstKind::Spec { default, .. } => default.0 != 0,
|
||||
ConstKind::Plain(Constant::Scalar { bits, .. }) => bits.0 != 0,
|
||||
ConstKind::SpecOp {
|
||||
op: SpecOp::IMul,
|
||||
operands,
|
||||
} => self.positive(operands[0])? && self.positive(operands[1])?,
|
||||
ConstKind::SpecOp {
|
||||
op: SpecOp::Select,
|
||||
operands,
|
||||
} => self.positive(operands[1])? && self.positive(operands[2])?,
|
||||
_ => false,
|
||||
})
|
||||
}
|
||||
|
||||
/// The module's `WorkgroupSize` composite, if declared.
|
||||
pub fn workgroup_size_const(&self) -> Option<ConstId> {
|
||||
self.iter()
|
||||
|
||||
@@ -87,9 +87,11 @@ use crate::pipeline::testing::{
|
||||
typed_module_with, AssembleError,
|
||||
};
|
||||
use crate::pipeline::{ComputePipelineDescriptor, FunctionDescriptor, StageSource};
|
||||
use crate::spirv::ids::ConstId;
|
||||
use crate::spirv::interp::{
|
||||
run, run_with_images, BarrierRule, Buffer, Config, Image, Order, Resources,
|
||||
};
|
||||
use crate::spirv::ir::{ConstKind, TypedModule};
|
||||
use crate::spirv::testing::spirv_dis;
|
||||
use crate::vk;
|
||||
|
||||
@@ -1476,6 +1478,226 @@ entry:\n\
|
||||
.to_string()
|
||||
}
|
||||
|
||||
/// A kernel that stores, for its thread `t` of threadgroup `g` along `x`, two words at `2 · (g ·
|
||||
/// n + t)` of a threadgroup of `n` threads: its position in the threadgroup `x | y << 10 | z << 20`,
|
||||
/// and the index of thread `n - 1 - t`, which it reads from threadgroup memory that thread wrote
|
||||
/// before a threadgroup barrier.
|
||||
fn deep_kernel() -> String {
|
||||
"target datalayout = \"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v16:16:16-v24:32:32-v32:32:32-v48:64:64-v64:64:64-v96:128:128-v128:128:128-v192:256:256-v256:256:256-v512:512:512-v1024:1024:1024-n8:16:32\"\n\
|
||||
target triple = \"air64_v28-apple-macosx26.0.0\"\n\n\
|
||||
@s = internal addrspace(3) global [1024 x i32] undef, align 4\n\n\
|
||||
define void @deep(ptr addrspace(1) noundef \"air-buffer-no-alias\" %0, <3 x i32> noundef %1, i32 noundef %2, <3 x i32> noundef %3, <3 x i32> noundef %4) {\n\
|
||||
entry:\n\
|
||||
%ps = getelementptr inbounds [1024 x i32], ptr addrspace(3) @s, i32 0, i32 %2\n\
|
||||
store i32 %2, ptr addrspace(3) %ps, align 4\n\
|
||||
tail call void @air.wg.barrier(i32 2, i32 1)\n\
|
||||
%sx = extractelement <3 x i32> %3, i64 0\n\
|
||||
%sy = extractelement <3 x i32> %3, i64 1\n\
|
||||
%sz = extractelement <3 x i32> %3, i64 2\n\
|
||||
%sxy = mul i32 %sx, %sy\n\
|
||||
%n = mul i32 %sxy, %sz\n\
|
||||
%last = sub i32 %n, 1\n\
|
||||
%r = sub i32 %last, %2\n\
|
||||
%pr = getelementptr inbounds [1024 x i32], ptr addrspace(3) @s, i32 0, i32 %r\n\
|
||||
%v = load i32, ptr addrspace(3) %pr, align 4\n\
|
||||
%x = extractelement <3 x i32> %1, i64 0\n\
|
||||
%y = extractelement <3 x i32> %1, i64 1\n\
|
||||
%z = extractelement <3 x i32> %1, i64 2\n\
|
||||
%y10 = shl i32 %y, 10\n\
|
||||
%z20 = shl i32 %z, 20\n\
|
||||
%xy = or i32 %x, %y10\n\
|
||||
%w = or i32 %xy, %z20\n\
|
||||
%g = extractelement <3 x i32> %4, i64 0\n\
|
||||
%gn = mul i32 %g, %n\n\
|
||||
%idx = add i32 %gn, %2\n\
|
||||
%i2 = shl i32 %idx, 1\n\
|
||||
%i = zext i32 %i2 to i64\n\
|
||||
%p = getelementptr inbounds i32, ptr addrspace(1) %0, i64 %i\n\
|
||||
store i32 %w, ptr addrspace(1) %p, align 4\n\
|
||||
%q = getelementptr inbounds i32, ptr addrspace(1) %p, i64 1\n\
|
||||
store i32 %v, ptr addrspace(1) %q, align 4\n\
|
||||
ret void\n\
|
||||
}\n\n\
|
||||
declare void @air.wg.barrier(i32, i32)\n\n\
|
||||
!air.kernel = !{!9}\n!air.version = !{!17}\n!air.language_version = !{!18}\n\
|
||||
!9 = !{ptr @deep, !10, !11}\n!10 = !{}\n!11 = !{!12, !13, !14, !15, !16}\n\
|
||||
!12 = !{i32 0, !\"air.buffer\", !\"air.location_index\", i32 0, i32 1, !\"air.read_write\", !\"air.address_space\", i32 1, !\"air.arg_type_size\", i32 4, !\"air.arg_type_align_size\", i32 4, !\"air.arg_type_name\", !\"uint\", !\"air.arg_name\", !\"out\"}\n\
|
||||
!13 = !{i32 1, !\"air.thread_position_in_threadgroup\", !\"air.arg_type_name\", !\"uint3\", !\"air.arg_name\", !\"pos\"}\n\
|
||||
!14 = !{i32 2, !\"air.thread_index_in_threadgroup\", !\"air.arg_type_name\", !\"uint\", !\"air.arg_name\", !\"t\"}\n\
|
||||
!15 = !{i32 3, !\"air.threads_per_threadgroup\", !\"air.arg_type_name\", !\"uint3\", !\"air.arg_name\", !\"size\"}\n\
|
||||
!16 = !{i32 4, !\"air.threadgroup_position_in_grid\", !\"air.arg_type_name\", !\"uint3\", !\"air.arg_name\", !\"group\"}\n\
|
||||
!17 = !{i32 2, i32 8, i32 0}\n!18 = !{!\"Metal\", i32 4, i32 0, i32 0}\n"
|
||||
.to_string()
|
||||
}
|
||||
|
||||
/// The workgroup `module` declares under `spec`: its `WorkgroupSize` composite, each part a
|
||||
/// constant, a specialization constant or an operation of them, at those values.
|
||||
fn workgroup_of(module: &TypedModule, spec: &BTreeMap<SpecKey, u64>) -> [u32; 3] {
|
||||
fn value(module: &TypedModule, spec: &BTreeMap<SpecKey, u64>, c: ConstId) -> u64 {
|
||||
match &module.consts().get(c).expect("a constant").kind {
|
||||
ConstKind::Plain(crate::spirv::ir::Constant::Scalar { bits, .. }) => bits.0,
|
||||
ConstKind::Spec { key, default } => spec.get(key).copied().unwrap_or(default.0),
|
||||
ConstKind::SpecOp { op, operands } => {
|
||||
let values: Vec<u64> = (operands.iter()).map(|&o| value(module, spec, o)).collect();
|
||||
op.eval(32, &values).expect("an operation of its arity")
|
||||
}
|
||||
other => panic!("a workgroup size part {other:?}"),
|
||||
}
|
||||
}
|
||||
let size = module
|
||||
.consts()
|
||||
.workgroup_size_const()
|
||||
.expect("a WorkgroupSize");
|
||||
let ConstKind::WorkgroupSize { parts } = module.consts().get(size).expect("it").kind else {
|
||||
panic!("not a WorkgroupSize");
|
||||
};
|
||||
parts.map(|part| value(module, spec, part) as u32)
|
||||
}
|
||||
|
||||
/// On `Device::from_queries`' profile a kernel whose workgroup is its threadgroup declares
|
||||
/// `SpecKey::DeepThreadgroup`, default false, and on `Device::new`'s it does not. Set for a
|
||||
/// threadgroup deeper than `DEEP_THREADGROUP`, its workgroup is one row of the threadgroup's
|
||||
/// threads and its threads' positions, linear indices and threadgroup memory are Metal's:
|
||||
/// [`deep_kernel`] over two threadgroups of 1 by 1 by 320, 2 by 3 by 100 and 1 by 4 by 256 stores
|
||||
/// what Metal's do, and so does one of 4 by 4 by 4, at its own workgroup with the key unset. The
|
||||
/// device reports Metal's 1,024 threads along every axis there, where `Device::new` on a profile of
|
||||
/// 64 along `z` reports 64.
|
||||
#[test]
|
||||
fn a_deep_threadgroup_runs_as_one_row_on_from_queries() {
|
||||
use crate::pipeline::DEEP_THREADGROUP;
|
||||
let Some(bc) = assemble_text("deep", &deep_kernel()) else {
|
||||
return;
|
||||
};
|
||||
for stem in PROFILES {
|
||||
let p = profile(stem, identity()).unwrap_or_else(|e| panic!("{e}"));
|
||||
let (a, _, _) = compile_kept(&bc, "deep", &p).unwrap_or_else(|e| panic!("{stem}: {e}"));
|
||||
assert!(
|
||||
(a.interface.spec.iter()).all(|c| c.key != SpecKey::DeepThreadgroup),
|
||||
"{stem}: DeepThreadgroup on Device::new"
|
||||
);
|
||||
let desc = crate::pipeline::testing::description(stem).unwrap_or_else(|e| panic!("{e}"));
|
||||
let device = Device::from_queries(desc, identity()).unwrap_or_else(|e| panic!("{e}"));
|
||||
let p = device.profile();
|
||||
let (a, plan, module) =
|
||||
compile_kept(&bc, "deep", p).unwrap_or_else(|e| panic!("{stem}: {e}"));
|
||||
let declared: Vec<u64> = (a.interface.spec.iter())
|
||||
.filter(|c| c.key == SpecKey::DeepThreadgroup)
|
||||
.map(|c| c.default)
|
||||
.collect();
|
||||
assert_eq!(declared, [0], "{stem}");
|
||||
link_and_validate(&a, p).unwrap_or_else(|e| panic!("{stem}: L3: {e}"));
|
||||
for size in [[1, 1, 320], [2, 3, 100], [1, 4, 256], [4, 4, 4]] {
|
||||
let n = size.iter().product::<u32>();
|
||||
let deep = size[2] > DEEP_THREADGROUP;
|
||||
let mut spec = local_size3(size);
|
||||
spec.insert(SpecKey::DeepThreadgroup, u64::from(deep));
|
||||
let want_group = match deep {
|
||||
true => [n, 1, 1],
|
||||
false => size,
|
||||
};
|
||||
assert_eq!(workgroup_of(&module, &spec), want_group, "{stem} {size:?}");
|
||||
let mut want = Vec::new();
|
||||
for _ in 0..2 {
|
||||
for t in 0..n {
|
||||
let (x, y, z) = (t % size[0], t / size[0] % size[1], t / (size[0] * size[1]));
|
||||
want.extend((x | y << 10 | z << 20).to_le_bytes());
|
||||
want.extend((n - 1 - t).to_le_bytes());
|
||||
}
|
||||
}
|
||||
let grid = [2 * size[0], size[1], size[2]];
|
||||
let region = region_bytes([0; 3], grid, size).expect("packs");
|
||||
let res = Resources {
|
||||
buffers: vec![Buffer {
|
||||
slot: None,
|
||||
address: Some(OUT),
|
||||
bytes: vec![0; want.len()],
|
||||
}],
|
||||
push: grid_push(&plan, OUT, region),
|
||||
spec,
|
||||
};
|
||||
let cfg = Config {
|
||||
workgroups: [2, 1, 1],
|
||||
..Config::default()
|
||||
};
|
||||
let got = run(&module, &cfg, res).unwrap_or_else(|e| panic!("{stem} {size:?}: {e}"));
|
||||
assert_eq!(got.buffers[0], want, "{stem} {size:?}");
|
||||
}
|
||||
}
|
||||
let desc = crate::pipeline::testing::description("nvidia-rtx50-linux")
|
||||
.unwrap_or_else(|e| panic!("{e}"));
|
||||
let new = Device::new(desc.clone(), identity()).unwrap_or_else(|e| panic!("{e}"));
|
||||
assert_eq!(
|
||||
new.metal_properties().max_threads_per_threadgroup,
|
||||
[1024, 1024, 64]
|
||||
);
|
||||
let queries = Device::from_queries(desc, identity()).unwrap_or_else(|e| panic!("{e}"));
|
||||
assert_eq!(
|
||||
queries.metal_properties().max_threads_per_threadgroup,
|
||||
[1024; 3]
|
||||
);
|
||||
}
|
||||
|
||||
/// Through the binder on `Device::from_queries`' profile of a device that holds 64 threads along
|
||||
/// `z` (NVIDIA's): a dispatch of [`deep_kernel`] in threadgroups 320 deep is planned, its region
|
||||
/// setting `SpecKey::DeepThreadgroup`, and one 4 deep is planned with it unset.
|
||||
#[test]
|
||||
fn the_binder_sets_deep_threadgroup_for_a_threadgroup_deeper_than_the_floor() {
|
||||
let Some(bc) = assemble_text("deep", &deep_kernel()) else {
|
||||
return;
|
||||
};
|
||||
let desc = crate::pipeline::testing::description("nvidia-rtx50-linux")
|
||||
.unwrap_or_else(|e| panic!("{e}"));
|
||||
let dev = Device::from_queries(desc, identity()).unwrap_or_else(|e| panic!("{e}"));
|
||||
let lib = Library::from_air(&bc).unwrap_or_else(|e| panic!("{e}"));
|
||||
let f = FunctionDescriptor::new(lib.function("deep").unwrap_or_else(|e| panic!("{e}")));
|
||||
let compiled = dev
|
||||
.compile_function(&f, &LowerInputs::new(), &Budget::standard())
|
||||
.unwrap_or_else(|e| panic!("{e}"));
|
||||
let d = ComputePipelineDescriptor::new(StageSource::Compiled(compiled));
|
||||
let pipe = dev
|
||||
.compile_compute_pipeline(&d, &Budget::standard())
|
||||
.unwrap_or_else(|e| panic!("{e}"));
|
||||
let mut table = StageTable::default();
|
||||
table.buffers.insert(
|
||||
0,
|
||||
BoundBuffer::Buffer {
|
||||
length: 1 << 20,
|
||||
offset: 0,
|
||||
gpu_address: OUT,
|
||||
device_address: Some(OUT),
|
||||
attribute_stride: None,
|
||||
},
|
||||
);
|
||||
let mut state = BindState::default();
|
||||
state.stages.insert(Stage::Kernel, table);
|
||||
let plan = pipe
|
||||
.plan(&dev, &state.shape())
|
||||
.unwrap_or_else(|e| panic!("{e}"));
|
||||
let id = (pipe.stage.specialization.constants.iter())
|
||||
.find(|c| c.key == SpecKey::DeepThreadgroup)
|
||||
.map(|c| c.id)
|
||||
.expect("the kernel declares DeepThreadgroup");
|
||||
for (threads_per_group, deep) in [([1, 1, 320], true), ([4, 4, 4], false)] {
|
||||
let dispatch = Dispatch::Threadgroups {
|
||||
groups: [2, 1, 1],
|
||||
threads_per_group,
|
||||
};
|
||||
let commands = plan
|
||||
.instantiate_dispatch(&state, &dispatch)
|
||||
.unwrap_or_else(|e| panic!("{threads_per_group:?}: {e}"));
|
||||
assert!(!commands.regions.is_empty());
|
||||
for region in &commands.regions {
|
||||
let entry = (region.specialization.entries.iter())
|
||||
.find(|e| e.constant_id == id)
|
||||
.expect("every region sets DeepThreadgroup");
|
||||
let at = entry.offset as usize;
|
||||
let set =
|
||||
(region.specialization.data[at..at + entry.size as usize].iter()).any(|&b| b != 0);
|
||||
assert_eq!(set, deep, "{threads_per_group:?}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// A partial-threadgroups variant over a ragged grid, its region flagged `NONUNIFORM`, answers
|
||||
/// each edge threadgroup's own size, and its invocations past the grid store nothing.
|
||||
#[test]
|
||||
|
||||
@@ -1164,6 +1164,7 @@ const metal2vulkan::cache::SOURCE_DIGEST pub const SOURCE_DIGEST: &str
|
||||
const metal2vulkan::device::NVIDIA_AMPERE_GA10X pub const NVIDIA_AMPERE_GA10X: &[u32]
|
||||
const metal2vulkan::metal::sampler::NOT_MIPMAPPED_MAX_LOD pub const NOT_MIPMAPPED_MAX_LOD: f32
|
||||
const metal2vulkan::metal::vertex::MAX_VERTEX_ALIGNMENT pub const MAX_VERTEX_ALIGNMENT: u32
|
||||
const metal2vulkan::pipeline::DEEP_THREADGROUP pub const DEEP_THREADGROUP: u32
|
||||
const metal2vulkan::pipeline::GRID_TILE_THREADS pub const GRID_TILE_THREADS: u32
|
||||
const metal2vulkan::pipeline::NONUNIFORM pub const NONUNIFORM: u32
|
||||
const-value metal2vulkan-air::bitstream::BLOCKINFO_BLOCK_ID 0
|
||||
@@ -1265,6 +1266,7 @@ const-value metal2vulkan::cache::SOURCE_DIGEST env!("M2V_SOURCE_DIGEST")
|
||||
const-value metal2vulkan::device::NVIDIA_AMPERE_GA10X &[0x2200, 0x2203, 0x2204, 0x2205, 0x2206, 0x2207, 0x2208, 0x220a, 0x220d, 0x2216, 0x222b, 0x222f, 0x2230, 0x2231, 0x2232, 0x2233, 0x2235, 0x2236, 0x2237, 0x2238, 0x223f, 0x2414, 0x2420, 0x2438, 0x2460, 0x2480, 0x2482, 0x2483, 0x2484, 0x2486, 0x2487, 0x2488, 0x2489, 0x248a, 0x248c, 0x248d, 0x248e, 0x249c, 0x249d, 0x249f, 0x24a0, 0x24a4, 0x24ac, 0x24ad, 0x24af, 0x24b0, 0x24b1, 0x24b6, 0x24b7, 0x24b8, 0x24b9, 0x24ba, 0x24bb, 0x24bf, 0x24c0, 0x24c7, 0x24c8, 0x24c9, 0x24dc, 0x24dd, 0x24df, 0x24e0, 0x24fa, 0x2501, 0x2503, 0x2504, 0x2505, 0x2507, 0x2508, 0x2509, 0x2520, 0x2521, 0x2523, 0x252f, 0x2531, 0x2544, 0x2560, 0x2561, 0x2563, 0x2571, 0x2582, 0x2583, 0x2584, 0x25a0, 0x25a2, 0x25a3, 0x25a4, 0x25a5, 0x25a6, 0x25a7, 0x25a9, 0x25aa, 0x25ab, 0x25ac, 0x25ad, 0x25af, 0x25b0, 0x25b2, 0x25b5, 0x25b6, 0x25b8, 0x25b9, 0x25ba, 0x25bb, 0x25bc, 0x25bd, 0x25e0, 0x25e2, 0x25e5, 0x25ec, 0x25ed, 0x25f9, 0x25fa, 0x25fb]
|
||||
const-value metal2vulkan::metal::sampler::NOT_MIPMAPPED_MAX_LOD 0.25
|
||||
const-value metal2vulkan::metal::vertex::MAX_VERTEX_ALIGNMENT 4
|
||||
const-value metal2vulkan::pipeline::DEEP_THREADGROUP 64
|
||||
const-value metal2vulkan::pipeline::GRID_TILE_THREADS 256
|
||||
const-value metal2vulkan::pipeline::NONUNIFORM 1
|
||||
enum metal2vulkan-air::abi::AbiHandle #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] pub enum AbiHandle
|
||||
@@ -13594,7 +13596,6 @@ variant metal2vulkan-rt::Limit::MemoryAllocations MemoryAllocations { max: u32 }
|
||||
variant metal2vulkan-rt::Limit::TextureSamples TextureSamples { sample_count: u32, counts: u32 }
|
||||
variant metal2vulkan-rt::Limit::TextureSize TextureSize { extent: [u32; 3], layers: u32, max_extent: [u32; 3], max_layers: u32 }
|
||||
variant metal2vulkan-rt::Limit::ThreadgroupMemory ThreadgroupMemory { length: u64, max: u32 }
|
||||
variant metal2vulkan-rt::Limit::ThreadgroupShape ThreadgroupShape { size: [u32; 3], max: [u32; 3] }
|
||||
variant metal2vulkan-rt::LoadAction::Clear Clear
|
||||
variant metal2vulkan-rt::LoadAction::DontCare DontCare
|
||||
variant metal2vulkan-rt::LoadAction::Load Load
|
||||
@@ -16840,6 +16841,7 @@ variant metal2vulkan::pipeline::SpecKey::BorderTexels BorderTexels(SlotRef)
|
||||
variant metal2vulkan::pipeline::SpecKey::BoundSamplerWord BoundSamplerWord(SlotRef)
|
||||
variant metal2vulkan::pipeline::SpecKey::BoundTexelFormat BoundTexelFormat(SlotRef)
|
||||
variant metal2vulkan::pipeline::SpecKey::ConstantLanes ConstantLanes(SlotRef)
|
||||
variant metal2vulkan::pipeline::SpecKey::DeepThreadgroup DeepThreadgroup
|
||||
variant metal2vulkan::pipeline::SpecKey::FilteringArgumentSampler FilteringArgumentSampler
|
||||
variant metal2vulkan::pipeline::SpecKey::FlatLocalSize FlatLocalSize
|
||||
variant metal2vulkan::pipeline::SpecKey::HeapNanFamilies HeapNanFamilies(Stage)
|
||||
|
||||
|
Can't render this file because it is too large.
|
@@ -339,6 +339,7 @@ surface! {
|
||||
const NONUNIFORM;
|
||||
fn grid_tile;
|
||||
const GRID_TILE_THREADS;
|
||||
const DEEP_THREADGROUP;
|
||||
struct ComputePipeline N;
|
||||
struct ComputePipelineMetalInfo N;
|
||||
struct CompileReport N;
|
||||
|
||||
+9
-1
@@ -134,7 +134,15 @@ compile does. `DevicePolicy::default()` is `DevicePolicy::UNTRUSTED`:
|
||||
made by `Device::from_queries` it reads its first threadgroup from every region (0 where the
|
||||
dispatch is not split, and for an indirect one) and declares `MultiRegion`, default 0: at 0
|
||||
Metal's threadgroup size is the pipeline's workgroup size; at 1 it is the region's, for a region
|
||||
whose workgroup size is not Metal's (an edge region). A texture slot's `gpuResourceID` is pushed as
|
||||
whose workgroup size is not Metal's (an edge region). There a kernel whose workgroup is its
|
||||
threadgroup (one outside the flattened SIMD-group tiers, without compute derivatives) also
|
||||
declares `SpecKey::DeepThreadgroup`, default false: at true its workgroup is one row of the
|
||||
threadgroup's threads, `(sx·sy·sz, 1, 1)`, each thread's position its `LocalInvocationIndex`
|
||||
unflattened in Metal's order, so a threadgroup deeper than a device's
|
||||
`maxComputeWorkGroupSize[2]` runs; the binder sets it for a region deeper than
|
||||
`pipeline::DEEP_THREADGROUP` (64) alone, and so does a runtime, so every other pipeline
|
||||
specializes it away. `MetalDeviceProperties::max_threads_per_threadgroup` on that profile is
|
||||
the capped `maxComputeWorkGroupInvocations` on every axis. A texture slot's `gpuResourceID` is pushed as
|
||||
its `PushField::SlotGuestBase`, and its texture is the element at the ID's index of set 1's two
|
||||
fixed arrays, the same layout for every pipeline ([RESOURCE-ID.md](RESOURCE-ID.md)); it binds no
|
||||
descriptor of its own and declares no specialization constant. An argument buffer's texture is
|
||||
|
||||
+2
-4
@@ -38,7 +38,7 @@ Columns:
|
||||
| What a call did wrong, in detail | 174 | 157 | 0 | 0 | 0 | 0 | 0 |
|
||||
| Devices below the new runtime's floor | 8 | 8 | 0 | 0 | 0 | 0 | 0 |
|
||||
| The new runtime's `Refusal` | 51 | 51 | 0 | 0 | 0 | 0 | 0 |
|
||||
| The new runtime's `Limit` | 11 | 11 | 0 | 0 | 0 | 0 | 0 |
|
||||
| The new runtime's `Limit` | 10 | 10 | 0 | 0 | 0 | 0 | 0 |
|
||||
| The new runtime's `Gap` | 20 | 20 | 0 | 0 | 0 | 0 | 0 |
|
||||
|
||||
## Totals by basis
|
||||
@@ -56,7 +56,7 @@ Columns:
|
||||
| What a call did wrong, in detail | 60 | 26 | 23 | 0 | 39 | 26 | 0 | 0 |
|
||||
| Devices below the new runtime's floor | 0 | 0 | 0 | 8 | 0 | 0 | 0 | 0 |
|
||||
| The new runtime's `Refusal` | 16 | 15 | 0 | 0 | 20 | 0 | 0 | 0 |
|
||||
| The new runtime's `Limit` | 0 | 0 | 0 | 8 | 3 | 0 | 0 | 0 |
|
||||
| The new runtime's `Limit` | 0 | 0 | 0 | 7 | 3 | 0 | 0 | 0 |
|
||||
| The new runtime's `Gap` | 0 | 0 | 0 | 0 | 20 | 0 | 0 | 0 |
|
||||
|
||||
## 1. Translator and front-end refusals (`Unsupported`: a `Feature` and its `Needs`)
|
||||
@@ -674,7 +674,6 @@ Columns:
|
||||
|---|---|---|---|---|---|
|
||||
| `BlockLen` | A block longer than one allocation and one buffer hold on the device (`Device::take_block` past `maxMemoryAllocationSize` or `maxBufferSize`) | at the device's limit | `device`: the device's `maxMemoryAllocationSize` and `maxBufferSize` | 1: `crates/metal2vulkan-rt/src/memory.rs (round)` | `-` |
|
||||
| `BlockIds` | A block after every block number has been used (`Device::take_block`) | every device (a public call's own check of its arguments) | `ours`: block numbers are 32 bits | 1: `crates/metal2vulkan-rt/src/memory.rs (number)` | `-` |
|
||||
| `ThreadgroupShape` | A threadgroup longer on an axis than the device's `maxComputeWorkGroupSize` (the floor holds 1,024 by 1,024 by 64), where the threadgroup is the... | at the device's limit | `device`: the device's `maxComputeWorkGroupSize` | 1: `crates/metal2vulkan-rt/src/encoder.rs (dispatch)` | `-` |
|
||||
| `ThreadgroupMemory` | A dispatch whose threadgroup memory, the kernel's own and the lengths set (each rounded up to 16 bytes), is past the device's... | at the device's limit | `device`: the device's `maxComputeSharedMemorySize` | 1: `crates/metal2vulkan-rt/src/encoder.rs (dispatch)` | `-` |
|
||||
| `BytesLength` | `setBytes` data longer than one parameter ring chunk | every device (a public call's own check of its arguments) | `ours`: a ring chunk is 64 KiB | 2: `crates/metal2vulkan-rt/src/encoder.rs (set_bytes)`, `crates/metal2vulkan-rt/src/render_encoder.rs (set_bytes)` | `-` |
|
||||
| `IndexRange` | A grant of no indices, or one past its class's range (`Device::grant_indices`, [`IndexClass::range`]) | every device (a public call's own check of its arguments) | `ours`: the descriptor arrays are 65,536 sampled textures, 4,096 storage textures and 4,000 samplers of each use, and index 0 is nil | 1: `crates/metal2vulkan-rt/src/arrays.rs (grant)` | `-` |
|
||||
@@ -1252,7 +1251,6 @@ Each refusal's sites, with the function that builds it.
|
||||
- `rt:Refusal::StencilAttachment`: `crates/metal2vulkan-rt/src/render_encoder.rs (draw)`
|
||||
- `rt:Limit::BlockLen`: `crates/metal2vulkan-rt/src/memory.rs (round)`
|
||||
- `rt:Limit::BlockIds`: `crates/metal2vulkan-rt/src/memory.rs (number)`
|
||||
- `rt:Limit::ThreadgroupShape`: `crates/metal2vulkan-rt/src/encoder.rs (dispatch)`
|
||||
- `rt:Limit::ThreadgroupMemory`: `crates/metal2vulkan-rt/src/encoder.rs (dispatch)`
|
||||
- `rt:Limit::BytesLength`: `crates/metal2vulkan-rt/src/encoder.rs (set_bytes)`; `crates/metal2vulkan-rt/src/render_encoder.rs (set_bytes)`
|
||||
- `rt:Limit::IndexRange`: `crates/metal2vulkan-rt/src/arrays.rs (grant)`
|
||||
|
||||
Reference in new issue
Block a user