diff --git a/crates/metal2vulkan-harness/src/tests.rs b/crates/metal2vulkan-harness/src/tests.rs index 63d4f2b94..f9500871b 100644 --- a/crates/metal2vulkan-harness/src/tests.rs +++ b/crates/metal2vulkan-harness/src/tests.rs @@ -1406,14 +1406,11 @@ fn the_copy_moves_every_byte_in_whole_threadgroups() { /// The fixture's two cells kernels on lavapipe's `Device::from_queries` profile. Under the /// resident-table domains both observe their threadgroup partition with /// partial threadgroups through the lockstep order's barriers, which stand past the bounds test, -/// so they are SIMD-group barriers, as in the row-indexed kernels the fixture stands for. The -/// one-row variant (`LoweringInputs::one_row`) of `row_cells`, whose `int` cell arithmetic -/// compiles to `nsw` steps, does not observe it, so a runtime may run its grids in tiles; that of -/// `row_cells_uint`, the control, whose `uint` steps carry no flags, still does. Under the -/// identity domains (the runtime's), whose kernels take no lockstep order, neither observes -/// it, plain or with partial threadgroups. +/// so they are SIMD-group barriers, as in the row-indexed kernels the fixture stands for. Under the +/// identity domains (the runtime's), whose kernels take no lockstep order, neither observes it, +/// plain or with partial threadgroups. #[test] -fn the_int_cells_kernel_is_apart_in_rows_and_its_uint_control_is_not() { +fn the_cells_kernels_observe_their_partition_only_under_the_lockstep_order() { use metal2vulkan::device::{Device, DeviceDescription, DevicePolicy}; use metal2vulkan::library::Library; use metal2vulkan::pipeline::{FunctionDescriptor, LoweringInputs, StageEntries}; @@ -1433,9 +1430,7 @@ fn the_int_cells_kernel_is_apart_in_rows_and_its_uint_control_is_not() { let budget = metal2vulkan::Budget::standard(); let mut partial = LoweringInputs::new(); partial.partial_threadgroups = true; - let mut rows = partial.clone(); - rows.one_row = true; - for (name, apart) in [("row_cells", true), ("row_cells_uint", false)] { + for name in ["row_cells", "row_cells_uint"] { let function = FunctionDescriptor::new(library.function(name).unwrap()); let observes = |device: &Device, inputs: &LoweringInputs| { let entries = StageEntries::new(); @@ -1443,11 +1438,6 @@ fn the_int_cells_kernel_is_apart_in_rows_and_its_uint_control_is_not() { .unwrap_or_else(|why| panic!("{name}: {why}")) }; assert!(observes(&resident, &partial), "{name}: the partial variant"); - assert_eq!( - observes(&resident, &rows), - !apart, - "{name}: the one-row variant" - ); let own = (identity.compile_function(&function, &LoweringInputs::new(), &budget)) .unwrap_or_else(|why| panic!("{name}: {why}")); assert!( diff --git a/crates/metal2vulkan-runtime/src/pipeline.rs b/crates/metal2vulkan-runtime/src/pipeline.rs index f69630100..efabad1dc 100644 --- a/crates/metal2vulkan-runtime/src/pipeline.rs +++ b/crates/metal2vulkan-runtime/src/pipeline.rs @@ -1683,10 +1683,6 @@ pub(crate) fn interface( | RuntimeFact::DeviceAddresses { .. } => {} // The stage-in region, which the encoder pushes (`FieldValue::StageInRegion`). RuntimeFact::StageInRegion => {} - // What a variant could relieve, which the module runs without: a predicated walk - // that unit axes would make less divergent. Every dispatch runs on this module, - // keeping its whole groups. - RuntimeFact::UnitAxes { axes: 0, .. } => {} // What the translator checks against the descriptor when it compiles, and nothing on // the device reads. RuntimeFact::CallStackDepth { .. } | RuntimeFact::OpenClMode => {} diff --git a/crates/metal2vulkan-runtime/src/tests/translate.rs b/crates/metal2vulkan-runtime/src/tests/translate.rs index 083d17b07..810aa2f24 100644 --- a/crates/metal2vulkan-runtime/src/tests/translate.rs +++ b/crates/metal2vulkan-runtime/src/tests/translate.rs @@ -144,41 +144,6 @@ mod on_device { }) } - /// The facts the runtime reads of `descriptor`'s kernel, one that observes its threadgroup - /// partition, on `device`, lowered as the state lowers it: of its plain module, under the - /// inputs the kernel reads, and of its emulated-SIMD-group variant, the same inputs with - /// emulated SIMD groups. - fn facts_read( - name: &str, - device: &Device, - descriptor: &ComputePipelineDescriptor, - ) -> [Vec; 2] { - let StageSource::Function(function) = &descriptor.kernel else { - unreachable!("a fixture's kernel is a function"); - }; - let translator = device.translator(); - let budget = Budget::standard(); - let entries = StageEntries::new(); - let plain = translator - .kernel_inputs_read(function, &descriptor.lowering_inputs(), &budget, &entries) - .unwrap_or_else(|error| panic!("{name}: {error}")); - let emulated = plain.kernel_variant(KernelVariant::EmulatedSimdgroups); - [plain, emulated].map(|inputs| { - let compiled = translator - .compile_function_from_entries(function, &inputs, &budget, &entries) - .unwrap_or_else(|error| panic!("{name}: {error}")); - let mut lowered = descriptor.clone(); - lowered.kernel = StageSource::Compiled(compiled); - translator - .compile_compute_pipeline(&lowered, &budget) - .unwrap_or_else(|error| panic!("{name}: {error}")) - .dependencies - .iter() - .map(|dependency| dependency.fact) - .collect() - }) - } - /// Whether `state`'s make made its emulated-SIMD-group module. fn emulated_made(state: &ComputePipelineState) -> bool { use crate::pipeline::Lowered; @@ -2220,15 +2185,14 @@ attributes #1 = { convergent nounwind willreturn } /// `unit_axes_walk`: a loop of `(y & 3) + 1` iterations at row `y`, each a SIMD-group sum over /// the threads still in it, in one threadgroup of 8 x 8 threads and one of 8 x 10 (a partial - /// SIMD group of 16 last). Where its SIMD groups are emulated its walk is predicated, and the - /// translator states the unit axes that would make it less divergent (`RuntimeFact::UnitAxes` - /// with no axes): the module is the general one, and every device creates the state and runs - /// both sizes, on the module whose walk states it where its tier emulates SIMD groups, and on - /// the emulated module at 8 x 10 where it runs only whole ones. Every answer is Metal's (M3 Max, - /// macOS 27.0.1): thread `t` adds, at each iteration `i` of its own, `i + 1` times the threads - /// of its SIMD group whose own trip count exceeds `i`. + /// SIMD group of 16 last). Where its SIMD groups are emulated its walk is predicated: every + /// device creates the state and runs both sizes, on the module whose walk is predicated where + /// its tier emulates SIMD groups, and on the emulated module at 8 x 10 where it runs only + /// whole ones. Every answer is Metal's (M3 Max, macOS 27.0.1): thread `t` adds, at each + /// iteration `i` of its own, `i + 1` times the threads of its SIMD group whose own trip count + /// exceeds `i`. #[test] - fn every_device_runs_a_kernel_whose_walk_unit_axes_could_relieve() { + fn every_device_runs_a_kernel_whose_walk_diverges_by_row() { let Some(descriptor) = descriptor("unit_axes_walk") else { return; }; @@ -2271,26 +2235,10 @@ attributes #1 = { convergent nounwind willreturn } "{name}: the sums in a threadgroup of 8 x {rows}" ); } - // Which modules the runtime read the relief of: the plain one, and the emulated - // variant. - let relieved = |facts: &[RuntimeFact]| { - facts.iter().any(|fact| match *fact { - RuntimeFact::UnitAxes { axes, relief } => axes == 0 && relief != 0, - _ => false, - }) - }; - let [plain, emulated] = facts_read(name, &device, &descriptor); - let (plain, emulated) = (relieved(&plain), relieved(&emulated)); - let made = emulated_made(&state); - assert!( - plain || (emulated && made), - "{name}: a module that states unit axes with no axes ran (plain {plain}, emulated \ - {emulated}, emulated made {made})" - ); println!( - "{name}: unit axes with no axes stated by the {} module, which ran; sums checked \ - in threadgroups of 8 x 8 and 8 x 10", - if plain { "plain" } else { "emulated" } + "{name}: sums checked in threadgroups of 8 x 8 and 8 x 10 (emulated module made: \ + {})", + emulated_made(&state) ); }); } diff --git a/crates/metal2vulkan-validation/fixtures/public/engine/README.md b/crates/metal2vulkan-validation/fixtures/public/engine/README.md index 92916aba5..fbf85bea6 100644 --- a/crates/metal2vulkan-validation/fixtures/public/engine/README.md +++ b/crates/metal2vulkan-validation/fixtures/public/engine/README.md @@ -298,7 +298,7 @@ threadgroup's threads); an authored case that executes a loop declares it | `fold_static_init_widen` | `k` | a program-scope `uint4` built from a `uchar4` function constant (`air.convert.u.v4i32.u.v4i8` in the static initializer) and a `uint` from a `uchar` one; thread i writes `kWide + kSelWide + i` | specialized, it compiles, and another constant value is other words (`tests::engine_specialized_folds`) | | `fold_config_kernel` | `fold_config` | a kernel in `fold_config_struct`'s shape: the configuration struct (two layers' present flags, selectors and `uchar4` opcodes widened to `uint4`, a layer count) filled by the static initializer, or with `kGeneric` read from buffer 1 instead; two layers of a five-way selector and four opcodes of a 16-case integer switch (one arm a `float` multiply and add, exact for every input), in loops of constant trip count; one read at a run-time index | Metal's words for each of six cases, four specializations and two of the generic path | | `pad_simd_shape` | `simd_shape` | each thread writes its simdgroup index, its lane, the threads of its simdgroup (`simd_sum(1u)`) and its index in the threadgroup | Metal (M3 Max, macOS 27.0.1) puts thread `i` in lane `i % 32` of simdgroup `i / 32`, of `min(32, n - 32 (i / 32))` threads, at threadgroups of 80, 1, 32, 64 and 40: the runtime's device test `every_device_lays_out_simdgroups_as_metal_does` holds every module that runs a size to it | -| `unit_axes_walk` | `unit_axes_walk` | a loop of `(y & 3) + 1` iterations at grid row `y`, each adding `i + 1` times `simd_sum(1u)`, the threads of the simdgroup still in it; `out[t]` the total | Metal (M3 Max, macOS 27.0.1) answers each thread's sum over its simdgroup's threads still in the loop in threadgroups of 8 x 8 and 8 x 10; emulated, its walk is predicated and states `RuntimeFact::UnitAxes` with no axes: the runtime's device test `every_device_runs_a_kernel_whose_walk_unit_axes_could_relieve` runs it on every device | +| `unit_axes_walk` | `unit_axes_walk` | a loop of `(y & 3) + 1` iterations at grid row `y`, each adding `i + 1` times `simd_sum(1u)`, the threads of the simdgroup still in it; `out[t]` the total | Metal (M3 Max, macOS 27.0.1) answers each thread's sum over its simdgroup's threads still in the loop in threadgroups of 8 x 8 and 8 x 10; emulated, its walk is predicated: the runtime's device test `every_device_runs_a_kernel_whose_walk_diverges_by_row` runs it on every device | | `row_lockstep_tree` | `row_lockstep_tree` | a tree reduction over `threadgroup uint tg[64]` indexed by the position along x, a threadgroup barrier per step and none between a step's load of `tg[x]` and its store: in a threadgroup of two rows within one simdgroup the rows share `x` and only the simdgroup's lockstep orders them; each thread writes `tg[0]` | Metal (M3 Max, macOS 27.0.1) answers the sum of the x below min(16, width) in every thread of four threadgroups of 16 x 2, 32 x 1 and 12 x 2, fifty times each; the translator keeps the order with barriers between rows (`RuntimeFact::RowLockstep`): the runtime's device test `every_device_runs_a_kernel_whose_lockstep_orders_rows` runs it on every device | | `tgz_reads` | `tgz_reads` | every thread ORs its words of `threadgroup uint decl[2048]` and of the `[[threadgroup(0)]]` region `arg` (8192 bytes set by the encoder) before any thread of its threadgroup writes them, a barrier, stores a nonzero pattern of its threadgroup and word into both, a barrier, and reads its neighbour's words back; each simdgroup's first lane ORs into `out[0]` and `out[1]` whether a word of each read nonzero, adds the patterns' wrapping sum (`decl[i] + 2 arg[i]`) into `out[2]` and the square of its threads into `out[3]` | Metal (M3 Max, macOS 27.0.1) reads zero before the program's stores in two dispatches of 2048 threadgroups of 256, 250 and 30 threads (case `compute-threadgroup-memory-reads-zero`, `metal2vulkan_devtools::threadgroup_start::answer`); the translator null-initializes the array and the region on `Device::from_queries`' profile (`tests::engine_zeroed_threadgroup`), and the runtime's device test `every_device_reads_zero_from_threadgroup_memory_until_the_program_writes_it` runs it on every device | diff --git a/crates/metal2vulkan/src/cache/codec.rs b/crates/metal2vulkan/src/cache/codec.rs index ac6c68000..9cab64d0c 100644 --- a/crates/metal2vulkan/src/cache/codec.rs +++ b/crates/metal2vulkan/src/cache/codec.rs @@ -1222,7 +1222,6 @@ codec_enum! { OpenClMode, OpenClLineTexture { slot }, RowLockstep, - OneRow, FlatGrid, CallThreadgroups, SparseTextureWrites { slot, atomic }, @@ -1259,7 +1258,6 @@ codec_enum! { BorderTexels { slot }, RegionViewports, PartialThreadgroups, - UnitAxes { axes, relief }, TexelBufferParts { slot }, AddressAlignment { slot, align }, GridTiles, diff --git a/crates/metal2vulkan/src/cache/mod.rs b/crates/metal2vulkan/src/cache/mod.rs index 074d6f5a9..9c2bd771d 100644 --- a/crates/metal2vulkan/src/cache/mod.rs +++ b/crates/metal2vulkan/src/cache/mod.rs @@ -70,7 +70,7 @@ pub const SEMANTICS_VERSION: u32 = 2304; /// 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 = 597; +pub const ARTIFACT_FORMAT_VERSION: u32 = 598; /// The version of what this crate gives a runtime for the runs of a compiled pipeline, beside the /// compile: the device a run opens and what it enables, the Vulkan and Metal vocabularies a runtime @@ -155,19 +155,6 @@ pub struct VariantKey { /// runs simdgroups on whole subgroups. #[cfg_attr(feature = "serde", serde(default))] pub emulated_simdgroups: bool, - /// Every threadgroup of the dispatch is one row, so each of its simdgroups lies within the row: - /// a kernel whose lockstep simdgroup barriers order only pairs that meet where a simdgroup - /// spans two rows (`RuntimeFact::RowLockstep`) runs without them, keeping its threadgroup ones, - /// and without the subgroup size they pinned (`LoweringInputs::one_row`). A dispatch whose - /// every region is one row asks for it. - #[cfg_attr(feature = "serde", serde(default))] - pub one_row: bool, - /// The axes along which every threadgroup of the dispatch has one thread (bit 0 `x`, bit 1 `y`, - /// bit 2 `z`): a kernel whose walk is predicated, where those axes' thread positions alone make - /// some of its synchronizations' blocks divergent (`RuntimeFact::UnitAxes`'s `relief`), - /// compiles with them uniform (`LoweringInputs::unit_axes`). - #[cfg_attr(feature = "serde", serde(default))] - pub unit_axes: u8, /// Texture slots bound to an 8-bit sRGB texture the device cannot sample, which the runtime /// holds as the format's UNORM twin (`metal::format::srgb_raw_twin`), whose views read the /// codes (`c / 255`): every slot of a `RuntimeFact::SrgbTexture` the shape binds in such a @@ -381,8 +368,6 @@ impl VariantKey { && self.psb_slots.is_empty() && self.pulled_vertex_buffers.is_empty() && !self.emulated_simdgroups - && !self.one_row - && self.unit_axes == 0 && self.srgb_textures.is_empty() && self.texel_buffer_parts.is_empty() && self.address_maps.is_empty() @@ -445,11 +430,6 @@ impl VariantKey { .collect(); out.emulated_simdgroups = self.emulated_simdgroups && stage == crate::pipeline::sym::Stage::Kernel; - out.one_row = self.one_row && stage == crate::pipeline::sym::Stage::Kernel; - out.unit_axes = match stage { - crate::pipeline::sym::Stage::Kernel => self.unit_axes, - _ => 0, - }; out.flat_grid = self.flat_grid && stage == crate::pipeline::sym::Stage::Kernel; out.call_threadgroups = self.call_threadgroups && stage == crate::pipeline::sym::Stage::Kernel; diff --git a/crates/metal2vulkan/src/device/mechanism.rs b/crates/metal2vulkan/src/device/mechanism.rs index d4bf14db9..095441f15 100644 --- a/crates/metal2vulkan/src/device/mechanism.rs +++ b/crates/metal2vulkan/src/device/mechanism.rs @@ -125,11 +125,6 @@ pub fn mechanism(fact: &RuntimeFact, profile: &DeviceProfile) -> Mechanism { RuntimeFact::OpenClLineTexture { .. } => Mechanism::Variant, // The binder's local-size rules read it: a one-row region of the planned pipeline. RuntimeFact::RowLockstep => Mechanism::PlanTimeCheck, - // A pipeline compiled under the one-row variant; its plans state it. - RuntimeFact::OneRow => Mechanism::Variant, - // The relief a consumer reads to ask for the unit-axes variant, or the axes the variant - // was compiled under; its plans state them. - RuntimeFact::UnitAxes { .. } => Mechanism::Variant, // A pipeline compiled under the flat-grid variant; its plans state it. RuntimeFact::FlatGrid => Mechanism::Variant, RuntimeFact::CallThreadgroups => Mechanism::Variant, diff --git a/crates/metal2vulkan/src/device/tests/mechanism.rs b/crates/metal2vulkan/src/device/tests/mechanism.rs index b2b596556..b819373e1 100644 --- a/crates/metal2vulkan/src/device/tests/mechanism.rs +++ b/crates/metal2vulkan/src/device/tests/mechanism.rs @@ -97,8 +97,6 @@ fn every_fact() -> Vec { RuntimeFact::OpenClMode, RuntimeFact::OpenClLineTexture { slot }, RuntimeFact::RowLockstep, - RuntimeFact::OneRow, - RuntimeFact::UnitAxes { axes: 0, relief: 2 }, RuntimeFact::TexelBufferParts { slot }, RuntimeFact::AddressAlignment { slot, align: 16 }, RuntimeFact::FlatGrid, @@ -236,66 +234,64 @@ fn variant(f: &RuntimeFact) -> usize { RuntimeFact::RenderTargetArrayLength { .. } => 25, RuntimeFact::StageInRegion => 26, RuntimeFact::StageInStride { .. } => 27, - RuntimeFact::OneRow => 28, - RuntimeFact::RegionViewports => 29, - RuntimeFact::TileFunction => 30, - RuntimeFact::TileAttachmentFormat { .. } => 31, - RuntimeFact::StorageTextureNumericType { .. } => 32, - RuntimeFact::OutOfBoundsAlpha { .. } => 33, - RuntimeFact::BicubicTexels { .. } => 34, - RuntimeFact::StorageTextureLevels { .. } => 35, - RuntimeFact::StorageTextureLevelViews { .. } => 36, - RuntimeFact::SparseTexture { .. } => 37, - RuntimeFact::AccelerationStructureInstanceCount { .. } => 38, - RuntimeFact::PredicationVote => 39, - RuntimeFact::HeapStorageReads { .. } => 40, - RuntimeFact::SrgbTexture { .. } => 41, - RuntimeFact::ViewportCount => 42, - RuntimeFact::AliasedImageblock { .. } => 43, - RuntimeFact::CallStackDepth { .. } => 44, - RuntimeFact::FlatGrid => 45, - RuntimeFact::SparseTextureWrites { .. } => 46, - RuntimeFact::TileThreadgroupMemory { .. } => 47, - RuntimeFact::TextureSwizzle { .. } => 48, - RuntimeFact::TileImageblock { .. } => 49, - RuntimeFact::AmplificationDraws { .. } => 50, - RuntimeFact::FoldedGroups => 52, - RuntimeFact::ZeroedColor { .. } => 55, - RuntimeFact::DroppedColor { .. } => 56, - RuntimeFact::DepthClampRange => 57, - RuntimeFact::ConstantLanes { .. } => 58, - RuntimeFact::FunctionTableRange { .. } => 59, - RuntimeFact::TileThreadgroup { .. } => 61, - RuntimeFact::ConstexprSampled { .. } => 62, - RuntimeFact::CubicSampler { .. } => 63, - RuntimeFact::CubicArgumentSampler { .. } => 64, - RuntimeFact::HeapRawSamples { .. } => 68, - RuntimeFact::CrossClassReads { .. } => 71, - RuntimeFact::StorageTextureWriteRounding { .. } => 72, - RuntimeFact::HeapWriteRounding { .. } => 73, - RuntimeFact::HeapCrossClassNeutral { .. } => 74, - RuntimeFact::AnisotropicSampler { .. } => 75, - RuntimeFact::StorageTextureIntegerChannels { .. } => 76, - RuntimeFact::ObjectThreadgroupArena { .. } => 79, - RuntimeFact::ReplayBindings => 82, - RuntimeFact::MergedDraws => 67, - RuntimeFact::QuadPrimitiveIds => 54, - RuntimeFact::RotatedWeights => 77, - RuntimeFact::PrivateList => 80, - RuntimeFact::PartialObjectThreadgroups => 83, - RuntimeFact::OpenClMode => 85, - RuntimeFact::RowLockstep => 86, - RuntimeFact::BorderTexels { .. } => 60, - RuntimeFact::HeapResidency { .. } => 78, - RuntimeFact::CallThreadgroups => 84, - RuntimeFact::PartialThreadgroups => 81, - RuntimeFact::UnitAxes { .. } => 53, - RuntimeFact::TexelBufferParts { .. } => 65, - RuntimeFact::OpenClLineTexture { .. } => 69, - RuntimeFact::AddressAlignment { .. } => 66, - RuntimeFact::GridTiles => 51, - RuntimeFact::PrivateArena { .. } => 70, - RuntimeFact::StencilBitDraws => 87, + RuntimeFact::RegionViewports => 28, + RuntimeFact::TileFunction => 29, + RuntimeFact::TileAttachmentFormat { .. } => 30, + RuntimeFact::StorageTextureNumericType { .. } => 31, + RuntimeFact::OutOfBoundsAlpha { .. } => 32, + RuntimeFact::BicubicTexels { .. } => 33, + RuntimeFact::StorageTextureLevels { .. } => 34, + RuntimeFact::StorageTextureLevelViews { .. } => 35, + RuntimeFact::SparseTexture { .. } => 36, + RuntimeFact::AccelerationStructureInstanceCount { .. } => 37, + RuntimeFact::PredicationVote => 38, + RuntimeFact::HeapStorageReads { .. } => 39, + RuntimeFact::SrgbTexture { .. } => 40, + RuntimeFact::ViewportCount => 41, + RuntimeFact::AliasedImageblock { .. } => 42, + RuntimeFact::CallStackDepth { .. } => 43, + RuntimeFact::FlatGrid => 44, + RuntimeFact::SparseTextureWrites { .. } => 45, + RuntimeFact::TileThreadgroupMemory { .. } => 46, + RuntimeFact::TextureSwizzle { .. } => 47, + RuntimeFact::TileImageblock { .. } => 48, + RuntimeFact::AmplificationDraws { .. } => 49, + RuntimeFact::FoldedGroups => 51, + RuntimeFact::ZeroedColor { .. } => 53, + RuntimeFact::DroppedColor { .. } => 54, + RuntimeFact::DepthClampRange => 55, + RuntimeFact::ConstantLanes { .. } => 56, + RuntimeFact::FunctionTableRange { .. } => 57, + RuntimeFact::TileThreadgroup { .. } => 59, + RuntimeFact::ConstexprSampled { .. } => 60, + RuntimeFact::CubicSampler { .. } => 61, + RuntimeFact::CubicArgumentSampler { .. } => 62, + RuntimeFact::HeapRawSamples { .. } => 66, + RuntimeFact::CrossClassReads { .. } => 69, + RuntimeFact::StorageTextureWriteRounding { .. } => 70, + RuntimeFact::HeapWriteRounding { .. } => 71, + RuntimeFact::HeapCrossClassNeutral { .. } => 72, + RuntimeFact::AnisotropicSampler { .. } => 73, + RuntimeFact::StorageTextureIntegerChannels { .. } => 74, + RuntimeFact::ObjectThreadgroupArena { .. } => 77, + RuntimeFact::ReplayBindings => 80, + RuntimeFact::MergedDraws => 65, + RuntimeFact::QuadPrimitiveIds => 52, + RuntimeFact::RotatedWeights => 75, + RuntimeFact::PrivateList => 78, + RuntimeFact::PartialObjectThreadgroups => 81, + RuntimeFact::OpenClMode => 83, + RuntimeFact::RowLockstep => 84, + RuntimeFact::BorderTexels { .. } => 58, + RuntimeFact::HeapResidency { .. } => 76, + RuntimeFact::CallThreadgroups => 82, + RuntimeFact::PartialThreadgroups => 79, + RuntimeFact::TexelBufferParts { .. } => 63, + RuntimeFact::OpenClLineTexture { .. } => 67, + RuntimeFact::AddressAlignment { .. } => 64, + RuntimeFact::GridTiles => 50, + RuntimeFact::PrivateArena { .. } => 68, + RuntimeFact::StencilBitDraws => 85, } } @@ -303,7 +299,7 @@ fn variant(f: &RuntimeFact) -> usize { fn mechanism_is_total_over_every_fact_and_profile() { let facts = every_fact(); let covered: std::collections::BTreeSet = facts.iter().map(variant).collect(); - assert_eq!(covered, (0..88).collect(), "every_fact misses a variant"); + assert_eq!(covered, (0..86).collect(), "every_fact misses a variant"); for (stem, _) in super::committed_profiles() { let dev = device(&stem); let p = dev.profile(); @@ -369,8 +365,6 @@ fn mechanism_is_total_over_every_fact_and_profile() { | RuntimeFact::FlatGrid | RuntimeFact::CallThreadgroups | RuntimeFact::PartialThreadgroups - | RuntimeFact::OneRow - | RuntimeFact::UnitAxes { .. } | RuntimeFact::AmplificationDraws { .. } | RuntimeFact::FoldedGroups | RuntimeFact::ReplayBindings diff --git a/crates/metal2vulkan/src/lower/dispatch.rs b/crates/metal2vulkan/src/lower/dispatch.rs index e27a1c726..86404b0ab 100644 --- a/crates/metal2vulkan/src/lower/dispatch.rs +++ b/crates/metal2vulkan/src/lower/dispatch.rs @@ -686,18 +686,6 @@ pub fn plan_kernel(cx: &mut SelectCx<'_>, tier: Tier) -> Result Result, Error> { + let r = (|| -> Result, Error> { let divergent = cx.body.blocks.iter().any(|(b, block)| { !u.is_uniform(b) && block.inst_ids().any(|id| { @@ -305,21 +305,16 @@ pub fn barriers( if !divergent && !partial { return Ok(None); } - // A partial threadgroup walks to every barrier whatever its axes. - let relief = match divergent && !partial { - true => unit_relief(cx, strategy, u, set, m)?, - false => 0, - }; let (mut p, extra) = plan(cx, strategy, u, set, m)?; demote(cross, extra); p.vote_word = sync_in_loop(cx, &p, m)?; p.partial_groups = partial; - Ok(Some((p, divergent, relief))) + Ok(Some((p, divergent))) })(); if given.is_none() { m.release(u.ledger_bytes()); } - let Some((p, divergent, relief)) = r? else { + let Some((p, divergent)) = r? else { return Ok(()); }; if p.vote_word { @@ -350,80 +345,13 @@ pub fn barriers( cx.facts.insert(RuntimeFact::PredicationVote); vote_in_object_arena(cx); } - if relief != 0 { - cx.facts.insert(RuntimeFact::UnitAxes { axes: 0, relief }); - } cx.families.simd.predication = Some(p); Ok(()) } -/// The workgroup uniformity of `cx`'s entry: a kernel's under the unit axes it is compiled for -/// (`LoweringInputs::unit_axes`, `uniform`'s "Unit axes"), every other stage's as it is. +/// The workgroup uniformity of `cx`'s entry. pub fn workgroup_uniformity(cx: &SelectCx<'_>, m: &mut Meter) -> Result { - let unit = match cx.stage { - Stage::Kernel => cx.inputs.unit_axes, - _ => 0, - }; - Uniformity::with_unit_axes(cx.entry, cx.body, unit, m) -} - -/// The blocks of `cx`'s entry that hold a synchronization of `set` and that `u` does not prove -/// uniform. -fn divergent_syncs( - cx: &SelectCx<'_>, - strategy: &[Option], - u: &Uniformity, - set: SyncSet, -) -> usize { - (cx.body.blocks.iter()) - .filter(|(b, block)| { - !u.is_uniform(*b) - && block.inst_ids().any(|id| { - (cx.values.inst(id)) - .and_then(|v| strategy.get(v.index())) - .and_then(Option::as_ref) - .is_some_and(|s| set.holds(s)) - }) - }) - .count() -} - -/// The unit-axes relief of a kernel compiled without unit axes and walked predicated under `u` -/// (`RuntimeFact::UnitAxes`): bit `m − 1` for each mask `m` of axes (bit 0 `x`, bit 1 `y`, bit 2 -/// `z`) under which fewer of the blocks that hold a synchronization of `set` are divergent once the -/// threads' positions along those axes are taken as uniform (`uniform`'s "Unit axes"); 0 for any -/// other function. Taking more positions as uniform makes no block divergent, so where the three -/// axes together relieve none no mask does: one more analysis then, at most seven. -pub(super) fn unit_relief( - cx: &SelectCx<'_>, - strategy: &[Option], - u: &Uniformity, - set: SyncSet, - m: &mut Meter, -) -> Result { - if cx.stage != Stage::Kernel || cx.inputs.unit_axes != 0 { - return Ok(0); - } - let base = divergent_syncs(cx, strategy, u, set); - if base == 0 { - return Ok(0); - } - let fewer = |axes: u8, m: &mut Meter| -> Result { - let under = Uniformity::with_unit_axes(cx.entry, cx.body, axes, m)?; - let n = divergent_syncs(cx, strategy, &under, set); - m.release(under.ledger_bytes()); - Ok(n < base) - }; - if !fewer(0b111, m)? { - return Ok(0); - } - let mut relief = 1 << 6; - for axes in 1..0b111u8 { - if fewer(axes, m)? { - relief |= 1 << (axes - 1); - } - } - Ok(relief) + Uniformity::of(cx.entry, cx.body, m) } /// An object function's arena fact with the vote word in its static part, which the binder checks diff --git a/crates/metal2vulkan/src/lower/simd/lockstep.rs b/crates/metal2vulkan/src/lower/simd/lockstep.rs index 19440c1dc..0db4c3fc6 100644 --- a/crates/metal2vulkan/src/lower/simd/lockstep.rs +++ b/crates/metal2vulkan/src/lower/simd/lockstep.rs @@ -126,7 +126,6 @@ //! there; otherwise it orders only pairs whose threads meet where a simdgroup spans two rows, and //! runs only in a threadgroup whose local size lets one (more than one row, of a width not a //! multiple of 32: [`Lockstep::across_rows`], a test of specialization constants a driver folds). -//! The kernel's one-row variant leaves such barriers out. //! //! Each pair names an interval of positions in one block where its barrier may stand; one //! barrier at a position of the most intervals serves them all (interval stabbing, threadgroup @@ -633,26 +632,22 @@ struct Decision { /// What [`order`] reads besides the entry, which with it decides the order completely: of the /// device's profile, whether a subgroup barrier where the simdgroup's threads diverge orders the -/// threads that run it together; and whether the kernel is its one-row variant -/// (`LoweringInputs::one_row`); and whether the profile orders no pair (`unordered`: the identity +/// threads that run it together; and whether the profile orders no pair (`unordered`: the identity /// domains, whose kernels take no order, the module documentation). Two asks with equal keys order /// an entry the same way, so an ordered entry is kept under its key. #[derive(Clone, Copy, Debug, PartialEq, Eq)] pub struct OrderKey { tangle: bool, - one_row: bool, unordered: bool, } impl OrderKey { - /// The key of a device of profile `p`, for the one-row variant where `one_row`. Under the - /// identity domains (`lower::access::identity`) the key orders nothing: [`order`] finds the - /// kernel's pairs and inserts no barrier. - pub fn of(p: &DeviceProfile, one_row: bool) -> OrderKey { + /// The key of a device of profile `p`. Under the identity domains (`lower::access::identity`) + /// the key orders nothing: [`order`] finds the kernel's pairs and inserts no barrier. + pub fn of(p: &DeviceProfile) -> OrderKey { if crate::lower::access::identity(p) { return OrderKey { tangle: false, - one_row, unordered: true, }; } @@ -667,7 +662,6 @@ impl OrderKey { ); OrderKey { tangle, - one_row, unordered: false, } } @@ -675,12 +669,10 @@ impl OrderKey { /// Order the threadgroup-memory and device-memory accesses of kernel `e` that only Apple's /// simdgroup lockstep orders, by inserting barriers into its body (see the module -/// documentation), for the device and variant of `key`. Where the key's one-row variant -/// (`LoweringInputs::one_row`) and, with each simdgroup lying within one row, no pair wants more -/// than a threadgroup barrier, only the threadgroup barriers are inserted, on every device. Under -/// a key that orders nothing (`OrderKey::unordered`) no barrier is inserted, and a kernel with -/// such a pair states it ([`Lockstep::unordered`]). An entry of another stage, or a kernel without -/// such a pair, is returned unchanged. +/// documentation), for the device of `key`. Under a key that orders nothing +/// (`OrderKey::unordered`) no barrier is inserted, and a kernel with such a pair states it +/// ([`Lockstep::unordered`]). An entry of another stage, or a kernel without such a pair, is +/// returned unchanged. pub fn order(mut e: Entry, key: OrderKey, m: &mut Meter) -> Result { if !matches!(e.ep.stage, AbiStage::Kernel { .. }) { return Ok(e); @@ -725,11 +717,7 @@ pub fn order(mut e: Entry, key: OrderKey, m: &mut Meter) -> Result /// threads that run it together (maximal reconvergence on 32-lane subgroups); `unordered`: the /// key orders nothing, so a kernel with a pair needs no barrier. fn decide(e: &Entry, key: OrderKey, m: &mut Meter) -> Result, Error> { - let OrderKey { - tangle, - one_row, - unordered, - } = key; + let OrderKey { tangle, unordered } = key; let Some(body) = e.module.func(e.func).and_then(|f| f.body.as_ref()) else { return Ok(None); }; @@ -787,12 +775,11 @@ fn decide(e: &Entry, key: OrderKey, m: &mut Meter) -> Result = BTreeSet::new(); - if one_row || tangle || wants.iter().any(|w| w.order == Order::Threadgroup) { + if tangle || wants.iter().any(|w| w.order == Order::Threadgroup) { let mut rows_af = AddrFacts::new(e, body, &layouts, &us, true, m)?; for (_, acc) in &spaces { pairs( @@ -808,7 +795,7 @@ fn decide(e: &Entry, key: OrderKey, m: &mut Meter) -> Result = wants + let wants: BTreeSet = wants .into_iter() .map( |w| match w.order == Order::Threadgroup && !in_rows.contains(&w) { @@ -820,14 +807,6 @@ fn decide(e: &Entry, key: OrderKey, m: &mut Meter) -> Result, unit: UnitAxes) -> u8 { - if !per_invocation(b, among) { - return 0; - } - let positional = matches!( - b, - Builtin::ThreadPositionInThreadgroup | Builtin::ThreadPositionInGrid - ); - if !positional || unit == 0 || among == Among::Primitive { - return ALL; - } - match lanes { - // A scalar position is its `x`. - None => match unit & 1 { - 0 => ALL, - _ => 0, - }, - Some(n) => lane_bits(n) & !unit, - } -} - /// The mask of a value of `n` tracked lanes. fn lane_bits(n: u32) -> u8 { match n { @@ -574,18 +540,7 @@ impl Uniformity { /// The uniformity of the blocks of `e`'s entry body. The returned structure stays charged to /// `m` ([`Uniformity::ledger_bytes`]); the analysis' own tables are released. pub fn of(e: &Entry, body: &Body, m: &mut Meter) -> Result { - Uniformity::analyze(e, body, Among::Workgroup, None, &[], 0, m) - } - - /// [`of`](Self::of) for a dispatch whose threadgroups have one thread along the axes `unit` - /// (the module docs, "Unit axes"). - pub fn with_unit_axes( - e: &Entry, - body: &Body, - unit: UnitAxes, - m: &mut Meter, - ) -> Result { - Uniformity::analyze(e, body, Among::Workgroup, None, &[], unit, m) + Uniformity::analyze(e, body, Among::Workgroup, None, &[], m) } /// The uniformity of the blocks and values of vertex function `e`'s entry body among the @@ -598,7 +553,7 @@ impl Uniformity { uniform: &[u32], m: &mut Meter, ) -> Result { - Uniformity::analyze(e, body, Among::Primitive, None, uniform, 0, m) + Uniformity::analyze(e, body, Among::Primitive, None, uniform, m) } /// The uniformity of the blocks of `e`'s entry body among the invocations `among` relates, @@ -613,7 +568,7 @@ impl Uniformity { loops: &LoopForest, m: &mut Meter, ) -> Result { - Uniformity::analyze(e, body, among, Some(loops), &[], 0, m) + Uniformity::analyze(e, body, among, Some(loops), &[], m) } /// The analysis among `among`, with the barrier contract where `contract` gives the loop @@ -624,7 +579,6 @@ impl Uniformity { among: Among, contract: Option<&LoopForest>, uniform: &[u32], - unit: UnitAxes, m: &mut Meter, ) -> Result { let n = body.insts.len(); @@ -659,7 +613,7 @@ impl Uniformity { let result = PostDomTree::compute(&e.cfg, m) .map_err(Error::from) .and_then(|pdom| { - let r = State::new(e, body, among, uniform, unit, m) + let r = State::new(e, body, among, uniform, m) .and_then(|st| match contract { Some(loops) => st.pin(&pdom, loops, m), None => Ok(st), @@ -690,7 +644,6 @@ impl<'a> State<'a> { body: &'a Body, among: Among, uniform: &[u32], - unit: UnitAxes, m: &mut Meter, ) -> Result, Error> { let n = body.insts.len(); @@ -705,18 +658,14 @@ impl<'a> State<'a> { .unwrap_or_default(); let mut args = vec![ALL; params.len()]; for b in &e.ep.params { - let lanes = - (params.get(b.param as usize)).and_then(|&ty| match e.module.types().get(ty) { - Some(Type::Vector { len, .. }) if *len <= LANES => Some(*len), - _ => None, - }); if let Some(a) = args.get_mut(b.param as usize) { - *a = match &b.role { - ParamRole::Builtin(builtin) => builtin_lanes(builtin, among, lanes, unit), - role => match divergent_role(role, among) { - true => ALL, - false => 0, - }, + let divergent = match &b.role { + ParamRole::Builtin(builtin) => per_invocation(builtin, among), + role => divergent_role(role, among), + }; + *a = match divergent { + true => ALL, + false => 0, }; } } diff --git a/crates/metal2vulkan/src/lower/simd/workgroup.rs b/crates/metal2vulkan/src/lower/simd/workgroup.rs index df16387fd..83a9fd3e8 100644 --- a/crates/metal2vulkan/src/lower/simd/workgroup.rs +++ b/crates/metal2vulkan/src/lower/simd/workgroup.rs @@ -243,15 +243,9 @@ pub fn check( Some(_) => divergent::plan(cx, strategy, u, divergent::SyncSet::Emulated, m).map(Some), None => Ok(None), }; - // Where the walk is predicated, the unit axes that would relieve it. - let relief = match &planned { - Ok(Some(_)) => divergent::unit_relief(cx, strategy, u, divergent::SyncSet::Emulated, m), - _ => Ok(0), - }; if given.is_none() { m.release(u.ledger_bytes()); } - let relief = relief?; let (predication, demoted) = match planned? { Some((p, extra)) => (Some(p), Some(extra)), None => (None, None), @@ -317,9 +311,6 @@ pub fn check( if let Some(fact) = fact { cx.facts.insert(fact); } - if relief != 0 { - cx.facts.insert(RuntimeFact::UnitAxes { axes: 0, relief }); - } Ok(()) } diff --git a/crates/metal2vulkan/src/pipeline/api_tests.rs b/crates/metal2vulkan/src/pipeline/api_tests.rs index 6e95c92ef..7d0918bf6 100644 --- a/crates/metal2vulkan/src/pipeline/api_tests.rs +++ b/crates/metal2vulkan/src/pipeline/api_tests.rs @@ -197,8 +197,6 @@ mod serde_round_trips { psb_slots: BTreeSet::from([buffer(1)]), pulled_vertex_buffers: BTreeSet::from([2, 5]), emulated_simdgroups: true, - one_row: true, - unit_axes: 6, srgb_textures: BTreeSet::from([slot(Stage::Kernel, SlotClass::Texture, 4)]), texel_buffer_parts: BTreeMap::from([(slot(Stage::Kernel, SlotClass::Texture, 11), 2)]), flat_grid: true, @@ -269,7 +267,6 @@ mod serde_round_trips { storage_images: BTreeMap::new(), psb_slots: BTreeSet::from([buffer(0), buffer(30)]), emulated_simdgroups: true, - one_row: true, stage_input: Some({ let mut d = StageInputDescriptor::new(); d.attributes.insert( @@ -404,7 +401,6 @@ mod serde_round_trips { instanced_attributes: BTreeSet::from([1]), object_payload: Some(64), region_viewports: true, - unit_axes: 2, push_base: 24, }); } diff --git a/crates/metal2vulkan/src/pipeline/compile.rs b/crates/metal2vulkan/src/pipeline/compile.rs index 0ced86f65..0365f7227 100644 --- a/crates/metal2vulkan/src/pipeline/compile.rs +++ b/crates/metal2vulkan/src/pipeline/compile.rs @@ -222,15 +222,6 @@ impl<'a> InputsFrom<'a> { } } - /// Whether the stage compiles as a kernel's one-row variant (`LoweringInputs::one_row`): the - /// given inputs' say; a render pipeline's stage never does. - fn one_row(&self) -> bool { - match self { - InputsFrom::Given(i) => i.one_row, - InputsFrom::Vertex(..) | InputsFrom::Fragment(..) => false, - } - } - /// Whether the stage compiles as the kernel of a compute pipeline of OpenCL mode /// (`LoweringInputs::open_cl_mode`): the given inputs' say; a render pipeline's stage never /// does. @@ -1036,9 +1027,9 @@ struct KeptOrder { ordered: Arc, } -/// The most ordered entries one [`StageEntry`] keeps. A device's profile fixes all of the key -/// but whether the kernel is its one-row variant, so a creation asks for at most two. -const KEPT_ORDERS: usize = 2; +/// The most ordered entries one [`StageEntry`] keeps. A device's profile fixes the whole key, so a +/// creation asks for one. +const KEPT_ORDERS: usize = 1; impl std::fmt::Debug for StageEntries { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { @@ -2816,7 +2807,7 @@ fn decoded_module(r: &Request<'_>, m: &mut Meter) -> Result /// ([`StageEntries::ordered`]): the check of the partition its kernel observes and its compile /// read one ordered entry. fn ordered_entry(r: &Request<'_>, p: &DeviceProfile, m: &mut Meter) -> Result { - let key = OrderKey::of(p, r.inputs.one_row()); + let key = OrderKey::of(p); if let Shared::Entry(entries, fd) = r.shared { let open_cl = (r.inputs.open_cl_mode(), r.inputs.open_cl_lines()); let depth = r.inputs.call_stack_depth(); diff --git a/crates/metal2vulkan/src/pipeline/compile/key.rs b/crates/metal2vulkan/src/pipeline/compile/key.rs index 1fb101fdb..81f65b3ba 100644 --- a/crates/metal2vulkan/src/pipeline/compile/key.rs +++ b/crates/metal2vulkan/src/pipeline/compile/key.rs @@ -10,7 +10,7 @@ //! links functions, each linked function's list, name, specialized name, specialization, AIR //! hash, and constant values. A stage without linked functions keeps the key it had before //! linking existed, and one -//! compiled without `emulated_simdgroups`, `one_row`, +//! compiled without `emulated_simdgroups`, //! `signed_color_attachments`, `multisampled` or `replay_bindings` the key it had before those //! inputs existed. A stage that links dynamic libraries records each library //! its imports are searched in, in order (install name and content hash), and the install name @@ -193,9 +193,6 @@ pub fn function_key( if inputs.emulated_simdgroups { h.bytes(b"emulated-simdgroups"); } - if inputs.one_row { - h.bytes(b"one-row"); - } // Appended only when set, canonical, in its derived `Debug` form (ordered maps of plain enums // and integers, a total encoding as `inputs_encoding`'s). if let Some(d) = &inputs.stage_input { @@ -462,10 +459,6 @@ pub fn function_key( h.bytes(b"region-viewports"); } // Appended only when set. - if inputs.unit_axes != 0 { - h.bytes(b"unit-axes").u64(u64::from(inputs.unit_axes)); - } - // Appended only when set. if inputs.push_base != 0 { h.bytes(b"push-base").u64(u64::from(inputs.push_base)); } diff --git a/crates/metal2vulkan/src/pipeline/compile/tests.rs b/crates/metal2vulkan/src/pipeline/compile/tests.rs index 4cbc23f03..0e4e9c549 100644 --- a/crates/metal2vulkan/src/pipeline/compile/tests.rs +++ b/crates/metal2vulkan/src/pipeline/compile/tests.rs @@ -641,7 +641,6 @@ fn the_inputs_encoding_is_the_earlier_derived_debug() { inputs_encoding(&inputs), derived .replace(", emulated_simdgroups: false", "") - .replace(", one_row: false", "") .replace(", stage_input: None", "") .replace(", signed_color_attachments: {}", "") .replace(", tile_attachments: None", "") @@ -698,7 +697,6 @@ fn the_inputs_encoding_is_the_earlier_derived_debug() { .replace(", object_payload: None", "") .replace(", tessellation: None", "") .replace(", region_viewports: false", "") - .replace(", unit_axes: 0", "") .replace(", push_base: 0", ""), "{derived}" ); diff --git a/crates/metal2vulkan/src/pipeline/facts.rs b/crates/metal2vulkan/src/pipeline/facts.rs index 52511f4cd..2d310e05a 100644 --- a/crates/metal2vulkan/src/pipeline/facts.rs +++ b/crates/metal2vulkan/src/pipeline/facts.rs @@ -250,25 +250,7 @@ pub enum RuntimeFact { /// where a simdgroup spans two rows of its threadgroup (`Lockstep::rows`). A dispatch region /// of one row runs on the planned pipeline whatever its width, without whole subgroups, where /// no pair meets; any other region keeps the tier's whole subgroups or emulated simdgroups. - /// A dispatch whose every region is one row asks for the kernel's one-row variant - /// (`VariantKey::one_row`), which has none of those barriers. RowLockstep, - /// The kernel was compiled under `VariantKey::one_row` (`LoweringInputs::one_row`): it runs - /// threadgroups whose simdgroups each lie within one row, without the lockstep barriers that - /// order only pairs meeting where a simdgroup spans two rows (its threadgroup ones kept), - /// whatever its device. Its plans state the variant, and a dispatch with a region of more than - /// one row asks for the variant without it. - OneRow, - /// Unit axes (`lower::simd::uniform`, "Unit axes"; bit 0 `x`, bit 1 `y`, bit 2 `z`). Where - /// `axes` is 0, the kernel's walk is predicated and `relief` holds, at bit `m − 1`, each mask - /// `m` of axes under which fewer of its synchronizations' blocks are divergent once its - /// threads' positions along them are taken as uniform: a dispatch whose threadgroups have one - /// thread along exactly the axes `m` may run the kernel's unit-axes variant - /// (`VariantKey::unit_axes`). Where `axes` is not 0, the - /// kernel was compiled under that variant (`LoweringInputs::unit_axes`), `relief` is 0, its - /// plans state the variant, and a dispatch with more than one thread along one of `axes` asks - /// for the variant without it. - UnitAxes { axes: u8, relief: u8 }, /// The kernel was compiled under `VariantKey::flat_grid` (`LoweringInputs::flat_grid`): it /// runs any grid in threadgroups of its own size, reading the grid from the 32-byte region /// record at its `PushField::ReplayRegionAddress`, which a preprocess writes beside the @@ -677,8 +659,6 @@ impl RuntimeFact { RuntimeFact::OpenClMode => "OpenClMode", RuntimeFact::OpenClLineTexture { .. } => "OpenClLineTexture", RuntimeFact::RowLockstep => "RowLockstep", - RuntimeFact::OneRow => "OneRow", - RuntimeFact::UnitAxes { .. } => "UnitAxes", RuntimeFact::FlatGrid => "FlatGrid", RuntimeFact::CallThreadgroups => "CallThreadgroups", RuntimeFact::SparseTextureWrites { .. } => "SparseTextureWrites", diff --git a/crates/metal2vulkan/src/pipeline/lower_inputs.rs b/crates/metal2vulkan/src/pipeline/lower_inputs.rs index c670db5b6..5dee8ff41 100644 --- a/crates/metal2vulkan/src/pipeline/lower_inputs.rs +++ b/crates/metal2vulkan/src/pipeline/lower_inputs.rs @@ -38,15 +38,6 @@ pub struct LoweringInputs { /// kernel has simdgroups this emulates; a vertex or fragment function compiles as without it. #[cfg_attr(feature = "serde", serde(default))] pub emulated_simdgroups: bool, - /// A kernel runs threadgroups whose simdgroups each lie within one row - /// (`VariantKey::one_row`): the lockstep barriers it takes are its threadgroup ones alone - /// where, so dispatched, no pair wants more than a threadgroup barrier, on every device (the - /// old binder asks for it where `air::Lockstep::rows` holds), and with no simdgroup barrier it - /// takes no simd class and pins no subgroup for them. A kernel - /// compiled under it depends on `RuntimeFact::OneRow`. Any other function compiles as without - /// it. - #[cfg_attr(feature = "serde", serde(default))] - pub one_row: bool, /// A kernel's stage-input descriptor (`MTLComputePipelineDescriptor.stageInputDescriptor`): how /// each `[[stage_in]]` attribute is fetched from its buffer. A kernel reading a stage-in /// attribute needs it (`NeedsInput(StageInputDescriptor)` without it); @@ -760,17 +751,6 @@ pub struct LoweringInputs { /// function that writes none. Any other stage compiles as without it. #[cfg_attr(feature = "serde", serde(default))] pub region_viewports: bool, - /// The axes along which every threadgroup the kernel runs has one thread - /// (`VariantKey::unit_axes`; bit 0 `x`, bit 1 `y`, bit 2 `z`): there every thread's - /// `thread_position_in_threadgroup` is 0 and its `thread_position_in_grid` is its - /// threadgroup's `threadgroup_position_in_grid`, partial threadgroups included, so the - /// workgroup-uniformity analysis takes those lanes of the two builtins as uniform - /// (`lower::simd::uniform`, "Unit axes") and a block they alone made divergent is walked as a - /// uniform one. A kernel compiled under it states `RuntimeFact::UnitAxes { axes, .. }`, and its - /// plans run only dispatches whose threadgroups have one thread along every such axis. Any - /// other stage compiles as without it. - #[cfg_attr(feature = "serde", serde(default))] - pub unit_axes: u8, /// Where a fragment function's push fields start on `Device::from_queries`' profile, whose /// render pipeline pushes one range `[0, W)` for both stages, `W` the device's push window /// ([`DeviceProfile::push_window`](crate::device::DeviceProfile::push_window), 256 or 128): diff --git a/crates/metal2vulkan/src/tests/engine_simd_emulated.rs b/crates/metal2vulkan/src/tests/engine_simd_emulated.rs index 9e0cd7785..ee3132d1c 100644 --- a/crates/metal2vulkan/src/tests/engine_simd_emulated.rs +++ b/crates/metal2vulkan/src/tests/engine_simd_emulated.rs @@ -2131,18 +2131,14 @@ fn run_local(plan: &Plan, m: &TypedModule, local: [u32; 3], lanes: SubgroupSize) words(&run_orders(m, lanes, &res)[0]) } -/// A threadgroup of one row runs a tile whose halves meet only across rows without its lockstep -/// simdgroup barrier ([`row_tile_kernel`], on the Iris Xe, whose maximal reconvergence on -/// 32-lane subgroups makes that barrier a tangle barrier). Its own pipeline keeps the barrier, -/// takes `CrossLane(BASIC)` and `Direct` (32 lanes pinned), records `RowLockstep`, and leaves -/// Metal's words in a threadgroup 144 wide and 2 tall, which runs on it, the shared lane's word -/// included. Its one-row variant (`LoweringInputs::one_row`) keeps the threadgroup barrier the -/// `@nb` pair takes, has no simdgroup barrier, no simd class and no pinned subgroup, states -/// `OneRow`, and leaves Metal's words in a threadgroup of one row (128 or 48 threads) at every -/// width. The same kernel with a simdgroup sum keeps its pinned pipeline and records no -/// `RowLockstep`. +/// A tile whose halves meet only across rows ([`row_tile_kernel`], on the Iris Xe, whose maximal +/// reconvergence on 32-lane subgroups makes its lockstep simdgroup barrier a tangle barrier) keeps +/// that barrier and the threadgroup barrier the `@nb` pair takes, takes `CrossLane(BASIC)` and +/// `Direct` (32 lanes pinned), records `RowLockstep`, and leaves Metal's words in a threadgroup +/// 144 wide and 2 tall, the shared lane's word included. The same kernel with a simdgroup sum keeps +/// its pinned pipeline and records no `RowLockstep`. #[test] -fn a_one_row_dispatch_drops_the_lockstep_simdgroup_barriers() { +fn a_row_tile_keeps_its_lockstep_barriers_and_records_row_lockstep() { let dev = device("intel-irisxe-rplp-anv"); let p = dev.profile(); let name = "row_tile"; @@ -2170,43 +2166,11 @@ fn a_one_row_dispatch_drops_the_lockstep_simdgroup_barriers() { (SimdClass::CrossLane(OpBits::BASIC), Tier::Direct) ); assert!(own.facts.contains(&RuntimeFact::RowLockstep)); - assert!(!own.facts.contains(&RuntimeFact::OneRow)); assert_eq!( run_local(&own, &m, wide, SubgroupSize::W32), row_tile_words(wide) ); - // The one-row variant. - let mut inputs = LoweringInputs::new(); - inputs.one_row = true; - let (row, rm) = - typed_module_with(&bc, name, p, &inputs).unwrap_or_else(|e| panic!("{name}: {e}")); - assert_eq!( - uses(&row, "barrier.lockstep.simdgroup"), - 0, - "{:?}", - row.census() - ); - assert_eq!( - uses(&row, "barrier.lockstep.threadgroup"), - 1, - "{:?}", - row.census() - ); - assert_eq!(row.simd, (SimdClass::None, Tier::NoSubgroup)); - assert_eq!(row.subgroup, SubgroupRequirement::NONE); - assert!(row.facts.contains(&RuntimeFact::OneRow)); - assert!(!row.facts.contains(&RuntimeFact::RowLockstep)); - for local in [[128, 1, 1], [48, 1, 1]] { - for lanes in [SubgroupSize::W8, SubgroupSize::W16, SubgroupSize::W32] { - assert_eq!( - run_local(&row, &rm, local, lanes), - row_tile_words(local), - "{local:?} at {lanes:?}" - ); - } - } - // With a simdgroup operation of its own the kernel keeps its pinned pipeline. let summed = "row_tile_sum"; let Some(bc) = assemble_text( diff --git a/crates/metal2vulkan/src/tests/engine_simd_lockstep.rs b/crates/metal2vulkan/src/tests/engine_simd_lockstep.rs index 0d9594a74..bc32bb9f7 100644 --- a/crates/metal2vulkan/src/tests/engine_simd_lockstep.rs +++ b/crates/metal2vulkan/src/tests/engine_simd_lockstep.rs @@ -35,7 +35,7 @@ use std::collections::BTreeMap; use crate::budget::{Budget, Meter, SPIRV_WORDS}; -use crate::device::subgroup::{OpBits, SimdClass, SubgroupRequirement, Tier}; +use crate::device::subgroup::{OpBits, SimdClass, Tier}; use crate::device::DevicePolicy; use crate::error::Error; use crate::library::FunctionConstantValues; @@ -43,9 +43,7 @@ use crate::lower::select::{LowerInputs, Plan}; use crate::pipeline::compile::{compile_bitcode, EntryRef}; use crate::pipeline::facts::RuntimeFact; use crate::pipeline::sym::{ResourceKind, ResourceSlot, Stage}; -use crate::pipeline::testing::{ - llvm_assemble, profile, typed_module, typed_module_with, AssembleError, Scratch, -}; +use crate::pipeline::testing::{llvm_assemble, profile, typed_module, AssembleError, Scratch}; use crate::spirv::interp::{run, Buffer, Config, Order, Resources, SubgroupSize}; use crate::spirv::ir::TypedModule; @@ -3346,42 +3344,20 @@ done: /// A tree reduction whose guard tests its `ushort` index widened to 32 bits ([`ZEXT_GUARD`]), /// or its `short` index sign-extended so ([`SEXT_GUARD`]), on the 780M (whose maximal /// reconvergence on 32-lane subgroups makes a lockstep simdgroup barrier a tangle barrier). Its -/// own pipeline keeps the pair of `tg[x]`'s load and store, which threads of two rows meet in: -/// `Direct`, 32 lanes pinned, `RowLockstep`, and lockstep's words in a simdgroup of two rows. Its -/// one-row variant takes no simdgroup barrier, no simd class and no pinned subgroup, and leaves -/// the sum at every width. A signed test of zero-extended indices ([`MIXED_GUARD`]) clears -/// nothing: its one-row variant keeps the barrier and the pin. +/// pipeline keeps the pair of `tg[x]`'s load and store, which threads of two rows meet in: +/// `Direct`, 32 lanes pinned, `RowLockstep` (no pair meets where each simdgroup lies within one +/// row), and lockstep's words in a simdgroup of two rows. A signed test of zero-extended indices +/// ([`MIXED_GUARD`]) clears nothing there: it keeps the barrier and the pin, and records no +/// `RowLockstep`. #[test] -fn a_guard_on_its_index_widened_once_clears_a_tree_reduction_in_one_row() { +fn a_guard_on_its_index_widened_once_clears_a_tree_reduction_in_rows() { let p = profile("amd-780m-radv", DevicePolicy::RESIDENT_TABLES).expect("profile"); - let mut one_row = LowerInputs::new(); - one_row.one_row = true; let sum: u32 = (0..16).sum(); for (name, body) in [("zext_guard", ZEXT_GUARD), ("sext_guard", SEXT_GUARD)] { let Some(bc) = assemble_text(name, &format!("{HEADER}\n{body}\n{}", footer_ushort(name))) else { return; }; - let (row, rm) = - typed_module_with(&bc, name, &p, &one_row).unwrap_or_else(|e| panic!("{name}: {e}")); - assert_eq!( - uses(&row, "barrier.lockstep.simdgroup"), - 0, - "{name}: {:?}", - row.census() - ); - assert_eq!(row.simd, (SimdClass::None, Tier::NoSubgroup), "{name}"); - assert_eq!(row.subgroup, SubgroupRequirement::NONE, "{name}"); - for local in [[16, 1, 1], [32, 1, 1]] { - let threads = local.iter().product::() as usize; - for lanes in CHUNKED { - assert_eq!( - run_shape(&row, &rm, local, lanes), - vec![sum; threads], - "{name} at {local:?} {lanes:?}" - ); - } - } let (own, m) = typed_module(&bc, name, &p).unwrap_or_else(|e| panic!("{name}: {e}")); assert_eq!(own.simd.1, Tier::Direct, "{name}: {:?}", own.census()); assert_eq!(own.subgroup.size, Some(32), "{name}"); @@ -3399,13 +3375,13 @@ fn a_guard_on_its_index_widened_once_clears_a_tree_reduction_in_one_row() { ) else { return; }; - let (row, _) = - typed_module_with(&bc, name, &p, &one_row).unwrap_or_else(|e| panic!("{name}: {e}")); + let (own, _) = typed_module(&bc, name, &p).unwrap_or_else(|e| panic!("{name}: {e}")); assert!( - uses(&row, "barrier.lockstep.simdgroup") > 0, + uses(&own, "barrier.lockstep.simdgroup") > 0, "{:?}", - row.census() + own.census() ); - assert_eq!(row.simd.1, Tier::Direct); - assert_eq!(row.subgroup.size, Some(32)); + assert_eq!(own.simd.1, Tier::Direct); + assert_eq!(own.subgroup.size, Some(32)); + assert!(!own.facts.contains(&RuntimeFact::RowLockstep)); } diff --git a/crates/metal2vulkan/tests/api_signatures.tsv b/crates/metal2vulkan/tests/api_signatures.tsv index ffeb66b1b..d7623fbb5 100644 --- a/crates/metal2vulkan/tests/api_signatures.tsv +++ b/crates/metal2vulkan/tests/api_signatures.tsv @@ -1928,7 +1928,6 @@ field metal2vulkan::cache::VariantKey.folded_groups pub folded_groups: bool field metal2vulkan::cache::VariantKey.kept_imageblock_bytes pub kept_imageblock_bytes: Option field metal2vulkan::cache::VariantKey.line_band pub line_band: Option field metal2vulkan::cache::VariantKey.merged_draws pub merged_draws: bool -field metal2vulkan::cache::VariantKey.one_row pub one_row: bool field metal2vulkan::cache::VariantKey.open_cl_lines pub open_cl_lines: BTreeSet field metal2vulkan::cache::VariantKey.partial_threadgroups pub partial_threadgroups: bool field metal2vulkan::cache::VariantKey.primitive_id_indices pub primitive_id_indices: Option @@ -1943,7 +1942,6 @@ field metal2vulkan::cache::VariantKey.srgb_textures pub srgb_textures: BTreeSet< field metal2vulkan::cache::VariantKey.storage_images pub storage_images: BTreeMap field metal2vulkan::cache::VariantKey.swizzled_storage pub swizzled_storage: BTreeSet field metal2vulkan::cache::VariantKey.texel_buffer_parts pub texel_buffer_parts: BTreeMap -field metal2vulkan::cache::VariantKey.unit_axes pub unit_axes: u8 field metal2vulkan::cache::VariantKey.zeroed_colors pub zeroed_colors: BTreeMap field metal2vulkan::device::AllocationLimits.max_buffer_size pub max_buffer_size: u64 field metal2vulkan::device::AllocationLimits.max_memory_allocation_size pub max_memory_allocation_size: u64 @@ -2434,7 +2432,6 @@ field metal2vulkan::pipeline::LoweringInputs.max_call_stack_depth pub max_call_s field metal2vulkan::pipeline::LoweringInputs.merged_draws pub merged_draws: bool field metal2vulkan::pipeline::LoweringInputs.multisampled pub multisampled: bool field metal2vulkan::pipeline::LoweringInputs.object_payload pub object_payload: Option -field metal2vulkan::pipeline::LoweringInputs.one_row pub one_row: bool field metal2vulkan::pipeline::LoweringInputs.open_cl_lines pub open_cl_lines: BTreeSet field metal2vulkan::pipeline::LoweringInputs.open_cl_mode pub open_cl_mode: bool field metal2vulkan::pipeline::LoweringInputs.partial_threadgroups pub partial_threadgroups: bool @@ -2464,7 +2461,6 @@ field metal2vulkan::pipeline::LoweringInputs.threadgroup_size_matches_tile_size field metal2vulkan::pipeline::LoweringInputs.tile_attachments pub tile_attachments: Option> field metal2vulkan::pipeline::LoweringInputs.unattached_colors pub unattached_colors: BTreeSet field metal2vulkan::pipeline::LoweringInputs.uniform_varyings pub uniform_varyings: BTreeSet -field metal2vulkan::pipeline::LoweringInputs.unit_axes pub unit_axes: u8 field metal2vulkan::pipeline::LoweringInputs.vertex_fetch pub vertex_fetch: Option field metal2vulkan::pipeline::LoweringInputs.viewport_index_varying pub viewport_index_varying: bool field metal2vulkan::pipeline::LoweringInputs.word_colors pub word_colors: BTreeMap @@ -9970,7 +9966,6 @@ variant metal2vulkan::pipeline::RuntimeFact::LocalSizeConstraint LocalSizeConstr variant metal2vulkan::pipeline::RuntimeFact::LocalSizeLimits LocalSizeLimits variant metal2vulkan::pipeline::RuntimeFact::MergedDraws MergedDraws variant metal2vulkan::pipeline::RuntimeFact::ObjectThreadgroupArena ObjectThreadgroupArena { static_bytes: u32, payload: Option } -variant metal2vulkan::pipeline::RuntimeFact::OneRow OneRow variant metal2vulkan::pipeline::RuntimeFact::OpenClLineTexture OpenClLineTexture { slot: SlotRef } variant metal2vulkan::pipeline::RuntimeFact::OpenClMode OpenClMode variant metal2vulkan::pipeline::RuntimeFact::OutOfBoundsAlpha OutOfBoundsAlpha { slot: SlotRef } @@ -10012,7 +10007,6 @@ variant metal2vulkan::pipeline::RuntimeFact::TileFunction TileFunction variant metal2vulkan::pipeline::RuntimeFact::TileImageblock TileImageblock { data_size: u32, alignment: u32 } variant metal2vulkan::pipeline::RuntimeFact::TileThreadgroup TileThreadgroup { tile_sized: bool } variant metal2vulkan::pipeline::RuntimeFact::TileThreadgroupMemory TileThreadgroupMemory { index: u32 } -variant metal2vulkan::pipeline::RuntimeFact::UnitAxes UnitAxes { axes: u8, relief: u8 } variant metal2vulkan::pipeline::RuntimeFact::VertexBufferStride VertexBufferStride { layout: u32 } variant metal2vulkan::pipeline::RuntimeFact::VertexFetch VertexFetch { attr: u32 } variant metal2vulkan::pipeline::RuntimeFact::ViewportCount ViewportCount diff --git a/docs/API.md b/docs/API.md index 27df8a10d..5d0e0e108 100644 --- a/docs/API.md +++ b/docs/API.md @@ -520,23 +520,13 @@ the widest mode is not weighed for it. The pin to 32 stays where 32 is the devic On the emulated tier, a simdgroup operation or barrier in a block whose control flow differs between threads is walked predicated: each thread carries a live flag, the threads that do not run the block take part in its exchanges as inactive lanes, and a loop that holds one votes on its -exit. A kernel whose threads' positions alone make such a block differ, along some axes -(`thread_position_in_threadgroup` or `thread_position_in_grid`, read by lane), states -`RuntimeFact::UnitAxes { axes: 0, relief }`: `relief` holds, at bit `m - 1`, each mask `m` of axes -(bit 0 `x`, bit 1 `y`, bit 2 `z`) under which fewer of those blocks differ once the positions along -them are taken as uniform. In a threadgroup of one thread along an axis, Metal's -`threads_per_threadgroup` is 1 there, so every thread's `thread_position_in_threadgroup` on that -axis is 0 and its `thread_position_in_grid` is its threadgroup's position, partial threadgroups -included. A dispatch of such threadgroups, where its axes are among the masks of `relief`, may -run on the kernel's unit-axes variant (`VariantKey::unit_axes`, which `LoweringInputs::unit_axes` -compiles): the same kernel with those positions uniform, walked without the predication they -caused, giving the same answers. Its compile states `UnitAxes { axes, relief: 0 }`, and a -dispatch with more than one thread along one of its axes takes the variant without them. A kernel has at most seven -such variants per variant it runs on, one per mask. On the Iris Xe, an authored kernel of four shuffles each way and a -simdgroup sum in a loop of 8 to 11 trips, in threadgroups of 8 x 1 x 16, ran 1.14 to 2.16 times -the GPU time predicated (its trip count read from `thread_position_in_grid.y`) as with the same -trip counts read from `threadgroup_position_in_grid.y`, over four sizes from 46 to 126 estimated -words (one run each), with the same bits. +exit. A block that the threads' positions alone make differ (`thread_position_in_threadgroup` or +`thread_position_in_grid`, read by lane) is walked predicated at every threadgroup size. On the +Iris Xe, an authored kernel of four shuffles each way and a simdgroup sum in a loop of 8 to 11 +trips, in threadgroups of 8 x 1 x 16, ran 1.14 to 2.16 times the GPU time predicated (its trip +count read from `thread_position_in_grid.y`) as with the same trip counts read from +`threadgroup_position_in_grid.y`, over four sizes from 46 to 126 estimated words (one run each), +with the same bits. ### What the module contains