old-runtime regression fix: the stage bounds return to Device::new's ANV rows; the bound on every device is a fact of from_queries' profile

576a7348bc put one stage bound on every device on the shared translator
path, so the old runtime (Device::new) newly refused what it compiled
before: on the UHD 630 and on every committed profile without maximal
reconvergence, 6 corpus modules (12 rows) went from compiled (emulated
simdgroups, entry weights 104,424 to 188,554) to Needs::StageBound.
Measured on gem10 through Device::new at 9cb90de8cc (job m3-max-41747).

Restored for Device::new, as before 576a7348bc:
DriverWorkaround::SerializedStageWrapsLargeModules and
CompilerMemoryGrowsWithStageSize on ANV's identity row, their bounds
(786,432 and 99,109), the re-plan keeping the widest pin, and the
refusal as Needs::DriverDefect naming the defect; no bound elsewhere.
The old runtime's heap-trim test, warm-refusal kinds and their tests go
back to their text before 576a7348bc.

rt keeps what landed, carried with no switch. The bound is a fact of
the profile (device::profile::StageBound): Device::new builds
StageBound::Defects (the bounds of its rows), Device::from_queries
builds StageBound::Every (99,109 on every device, refused as
Needs::StageBound). stage_bound::emit reads that one field. The
fingerprint renders the fact only when it is Every, so every
Device::new fingerprint is byte-identical to before 576a7348bc. Every
from_queries fingerprint moves, so an rt profile is never one of the
old path's.

Tests:
- The pre-576a7348bc ANV tests are back (both defects' bounds, and the
  same profile without them emitting under every bound).
- New every_stage_from_queries_keeps_the_widest_pin_or_is_refused:
  re-planned, then StageBound; the serialized bound is none there; RADV
  through Device::new is unbounded.
- the_stage_bound_fixture_keeps_the_pin_or_is_refused covers both
  paths. Iris pinned through both. Without maximal reconvergence:
  StageBound through from_queries, DriverDefect on ANV through
  Device::new, and emitted emulated through Device::new under Intel's
  Windows driver (the UHD 630's case).
- New the_stage_bound_is_a_fact_of_the_profile checks every committed
  profile.

Docs:
- FAST-PATHS' known gap is ANV's again.
- The rt README's known gaps gain the every-device bound.
- API.md and the Needs::StageBound and Feature::StageSize docs name
  both paths.
- REFUSALS.md regenerated; the API table regains the two variants.

SEMANTICS_VERSION 2153.
This commit is contained in:
Anees Iqbal committed 2026-11-17 10:57:34 -08:00
1 parent 75b422338a
commit d5a475f1a0
20 files changed
+698 -257

No files matched your search

+6
View File
@@ -324,6 +324,12 @@ on disk; the `VkPipelineCache` still serves the device's own pipelines.
- NVIDIA 615.71.09 on GA10x gives sign-extended bits for a mask over a signed clamp, to exactly N
bits' range, of a sum or difference of two values sign-extended from N bits; not reproduced on
620.70.06.
- A kernel whose translated entry weighs more than 99,109 instructions (each call counted as its
callee's body) is made on no device: that is the heaviest stage measured to compile within
host-sized memory on the slowest compiler measured (ANV, Mesa 26.2.6, on the Iris Xe of RPL-P).
One that emulated its SIMD groups only in place of the 32-lane pin is translated again pinned,
and every other is refused (`Error::Translation`: `Feature::StageSize`, `Needs::StageBound`)
where Metal makes it.
## One path for every device
@@ -134,7 +134,7 @@ mod tests {
assert_ne!(refusal_name(&other, record), name, "{other:?}");
}
assert_ne!(refusal_name(&identity, b"another record"), name);
let kind = "Unsupported{StageSize; StageBound}";
let kind = "Unsupported{StageSize; DriverDefect(SerializedStageWrapsLargeModules)}";
let bytes = refusal_record(&name, kind);
assert_eq!(refusal_kind(&bytes, &name).unwrap(), kind);
assert!(refusal_kind(&bytes, &refusal_name(&identity, b"another")).is_err());
@@ -1,6 +1,7 @@
//! The free heap a large making's compile leaves is handed back (`pipeline/compile_memory.rs`):
//! a kernel of fused multiply-adds, each step's operand some values behind it ([`WIDE`]: a short
//! chain of many values live), made as two `VkPipeline`s of its partial-threadgroups variant, which runs a large kernel's whole and ragged grids alike
//! two kernels of fused multiply-adds, each step's operand some values behind it ([`KERNELS`]:
//! a long chain of few values live, and a short one of many), each made as two `VkPipeline`s of
//! its partial-threadgroups variant, which runs a large kernel's whole and ragged grids alike
//! (`compute::partial_direct`), one per threadgroup size, each a large making. glibc keeps what
//! the driver's compile frees in the compiling thread's arena; handed back after each, the
//! process's resident set stays within [`BOUND_MIB`] of what it was before the first, and the
@@ -25,14 +26,18 @@
//! | 320,000, 64 | 334 MB; 60.5 s, 18.4 s | 277 MB; 7.0 s, 3.7 s |
//!
//! NVIDIA's compile frees about 0.7 KB a step whatever the values live, fastest with few; RADV's
//! leaves 200 to 280 MB with up to 256 live, at the floor or under it, and far more with 600.
//! Every shape NVIDIA's compile frees past the floor is past the stage bound no device is handed
//! (`Feature::StageSize`, an entry weight of 99,109; 320,000 steps weigh 320,038), and under it
//! NVIDIA's frees 189 MB at most measured (80,000 steps, 600 live). So the test makes the wide
//! chain alone, which RADV's and ANV's compiles free past the floor, and asks for a trim where its
//! making left more than the floor free. Each shape made once in a process of its own on the Iris
//! Xe of RPL-P (ANV, Mesa 26.2.6), the free heap after the making, its time and the process's peak
//! resident set (one run, the host shared):
//! leaves 200 to 280 MB with up to 256 live, at the floor or under it (0 trims at 320,000 and 64
//! once), and far more with 600. So no one shape passes the floor fast on both: the test makes,
//! on every device, the long chain NVIDIA's compile frees past it and the wide one RADV's does.
//!
//! On ANV the long chain is refused: its entry weighs 320,038, past the heaviest stage the driver
//! is measured to compile (`Feature::StageSize`,
//! `DriverWorkaround::CompilerMemoryGrowsWithStageSize`, a bound of 99,109), and the shapes
//! NVIDIA's compile frees past the floor are past that bound (303 MB at 240,000 steps; 189 MB at
//! 80,000 with 600 live), so no long chain serves both. The test takes that refusal, asserting it
//! is the bound's, and the wide chain trims there. Each shape made once in a process of its own on
//! the Iris Xe of RPL-P (ANV, Mesa 26.2.6), the free heap after the making, its time and the
//! process's peak resident set (one run, the host shared):
//!
//! | steps, live | Iris Xe |
//! |---|---|
@@ -54,16 +59,18 @@ use super::opencl_mode::words_buffer;
use super::spares_bench::process_memory;
use super::uniform_bind_offsets::idle;
use crate::pipeline::compile_memory::heap_bytes;
use crate::pipeline::compile_memory::FREE_FLOOR;
use crate::{CommandBufferStatus, ComputePipelineState, Device, PipelineOptions, Size};
use crate::{CommandBufferStatus, ComputePipelineState, Device, Error, PipelineOptions, Size};
use metal2vulkan::device::DriverWorkaround;
use metal2vulkan::error::{Feature, Needs};
use metal2vulkan::pipeline::{ComputePipelineDescriptor, StageSource};
use std::fmt::Write;
use std::time::{Duration, Instant};
/// The kernel's fused multiply-adds and the values each step's operand is behind (so many live
/// at once): a short chain of many, whose compile RADV's and ANV's drivers free past the trim's
/// floor (the module docs).
const WIDE: (usize, usize) = (20_000, 600);
/// The kernels' fused multiply-adds and the values each step's operand is behind (so many live
/// at once): a long chain of few, whose compile NVIDIA's driver frees past the trim's floor and
/// which ANV refuses as past its stage bound, and a short chain of many, whose compile RADV and
/// ANV free past it (the module docs).
const KERNELS: [(usize, usize); 2] = [(320_000, 64), (20_000, 600)];
/// The longest a command buffer of a large making waits.
const MAKING_WAIT: Duration = Duration::from_secs(300);
@@ -110,8 +117,11 @@ entry:\n{body}ret void\n}}\n\n\
)
}
/// The state of `heavy` of `steps` steps, `window` live.
fn state(device: &Device, (steps, window): (usize, usize)) -> ComputePipelineState {
/// The state of `heavy` of `steps` steps, `window` live, or `None` where the device refuses it as
/// past the heaviest stage its driver is measured to compile (`Feature::StageSize`,
/// `DriverWorkaround::CompilerMemoryGrowsWithStageSize`), the refusal naming an entry weight past
/// its bound. Every other refusal fails the test.
fn state(device: &Device, (steps, window): (usize, usize)) -> Option<ComputePipelineState> {
let air = metal2vulkan_devtools::llvm_assemble_text(&kernel(steps, window)).unwrap();
let library = metal2vulkan::library::Library::from_air(&air).unwrap();
let function = device
@@ -120,9 +130,28 @@ fn state(device: &Device, (steps, window): (usize, usize)) -> ComputePipelineSta
.unwrap();
let descriptor =
ComputePipelineDescriptor::new(StageSource::Function(function.function_descriptor()));
device
.new_compute_pipeline_state(&descriptor, &PipelineOptions::default())
.unwrap_or_else(|e| panic!("{steps} steps, {window} live: {e:?}"))
let u = match device.new_compute_pipeline_state(&descriptor, &PipelineOptions::default()) {
Ok(state) => return Some(state),
Err(Error::Unsupported(u)) => u,
Err(other) => panic!("{steps} steps, {window} live: {other:?}"),
};
let bound = Needs::DriverDefect(DriverWorkaround::CompilerMemoryGrowsWithStageSize);
assert!(u.feature == Feature::StageSize && u.needs == bound, "{u:?}");
let named = u
.symbol
.as_ref()
.map(ToString::to_string)
.unwrap_or_default();
let passed = (named.strip_prefix("entry weight "))
.and_then(|rest| rest.split_once(", past the bound "))
.and_then(|(weight, bound)| {
Some((weight.parse::<u64>().ok()?, bound.parse::<u64>().ok()?))
});
assert!(
matches!(passed, Some((weight, bound)) if weight > bound),
"{steps} steps, {window} live: {u:?}"
);
None
}
/// Dispatch `n` threads in threadgroups of `group` and wait.
@@ -158,31 +187,40 @@ fn a_large_makings_free_heap_is_handed_back() {
let device = device(&scratch.0);
let before = resident_mib();
let trims = || device.work_counts().heap_trims;
let (steps, window) = WIDE;
let made = Instant::now();
let state = state(&device, WIDE);
dispatch(&device, &state, 128, 128);
// What the first making left glibc free (`compile_memory::FREE_FLOOR`'s measure).
let free = heap_bytes().map_or(0, |(_, free)| free);
idle(&device);
let first = resident_mib();
dispatch(&device, &state, 129, 64);
idle(&device);
println!(
"HEAP-TRIMMED {}: resident {before} MiB before; {steps} steps, {window} live: {free} bytes \
free and {first} MiB resident after the first making, {} MiB after the second, {} \
trims, {:.1} s",
device.name(),
resident_mib(),
trims(),
made.elapsed().as_secs_f64()
let mut line = format!(
"HEAP-TRIMMED {}: resident {before} MiB before",
device.name()
);
for (steps, window) in KERNELS {
let made = Instant::now();
let Some(state) = state(&device, (steps, window)) else {
write!(
line,
"; {steps} steps, {window} live: refused past the stage bound"
)
.unwrap();
continue;
};
dispatch(&device, &state, 128, 128);
// What the first making left glibc free (`compile_memory::FREE_FLOOR`'s measure).
let free = heap_bytes().map_or(0, |(_, free)| free);
idle(&device);
let first = resident_mib();
dispatch(&device, &state, 129, 64);
idle(&device);
write!(
line,
"; {steps} steps, {window} live: {free} bytes free and {first} MiB resident after the \
first making, {} MiB after the second, {} trims, {:.1} s",
resident_mib(),
trims(),
made.elapsed().as_secs_f64()
)
.unwrap();
}
println!("{line}");
let after = resident_mib();
// Only a making that left more than the floor free hands it back (the module docs).
assert!(
free <= FREE_FLOOR || trims() > 0,
"a making left {free} bytes free, and none was handed back"
);
assert!(trims() > 0, "no large making handed its free heap back");
assert!(
after <= before + BOUND_MIB,
"the resident set grew from {before} MiB to {after} over the makings"
@@ -226,7 +226,7 @@ fn a_warm_refusal_is_found_by_its_own_driver_only() {
};
let kept = Identity::new(0x8086, 0xa7a0, 0x6802006, [1; 16]);
let (name, written) = entry(&kept, &NO_PROFILE);
let kind = "Unsupported{StageSize; StageBound}";
let kind = "Unsupported{StageSize; DriverDefect(SerializedStageWrapsLargeModules)}";
store
.write_soon(&written, refusal_record(&name, kind))
.unwrap();
+5 -5
View File
@@ -795,16 +795,16 @@ mod tests {
}
/// A refusal of the record on this device is kept for later passes: a typed refusal (a stage
/// past the stage bound, or past the private memory a thread holds), and a translator
/// past its driver's bound, or past the private memory a thread holds), and a translator
/// outcome permanent for its input. A transient failure is not (a deadline, a cancellation, a
/// host allocation that failed, out of memory, a lost device), nor a missing input that a
/// later boot may supply, nor a runtime error that is no refusal.
#[test]
fn only_a_refusal_for_good_is_kept() {
use metal2vulkan::device::VkLimit;
use metal2vulkan::error::{Capability, InternalError, InternalKind, Limit, Needs};
let mut stage = Unsupported::not_implemented(Feature::StageSize);
stage.needs = Needs::StageBound;
use metal2vulkan::device::{DriverWorkaround, VkLimit};
use metal2vulkan::error::{Capability, InternalError, InternalKind, Limit};
let defect = DriverWorkaround::SerializedStageWrapsLargeModules;
let stage = Unsupported::driver_defect(Feature::StageSize, defect);
let storage = Capability::Limit {
limit: VkLimit::FunctionStorageBytesPerThread,
required: 256 << 10,
+19 -11
View File
@@ -17,7 +17,7 @@ use crate::device::profile::{
BufferAccess, Containment, CubeGradientRoute, CubeGradients, DescriptorCaps, DeviceProfile,
DriverWorkaround, EnabledCaps, FloatFunctions, FormatTable, FragmentCaps, GuestIsolation,
HandleDomain, ImageCaps, Independence, LeafCaps, NanEncoding, PointerDomain, ProfileFields,
Robustness,
Robustness, StageBound,
};
use crate::device::requirements::{
ApiVersion, FloatControl, FloatWidth, FormatUsage, ResolveMode, SubgroupOp, VkExtension,
@@ -88,10 +88,11 @@ impl Device {
/// on every device, whatever its type.
pub fn from_queries(desc: DeviceDescription, policy: DevicePolicy) -> Result<Device, Error> {
Device::derived(desc.without_identity(), policy, |desc, policy| {
ProfileFields {
let fields = ProfileFields {
ycbcr_in_place: true,
..derive_fields(desc, policy, &BTreeSet::new())
}
};
(fields, StageBound::Every)
})
}
@@ -122,16 +123,19 @@ impl Device {
deviations: BTreeSet<DriverDeviation>,
) -> Result<Device, Error> {
Device::derived(desc, policy, |desc, policy| {
derive_fields(desc, policy, &deviations)
(
derive_fields(desc, policy, &deviations),
StageBound::Defects,
)
})
}
/// The device of `desc` under `policy`, its profile's fields as `fields` derives them, once
/// the description and the policy pass their checks.
/// The device of `desc` under `policy`, its profile's fields and stage bound as `fields`
/// derives them, once the description and the policy pass their checks.
fn derived(
desc: DeviceDescription,
policy: DevicePolicy,
fields: impl FnOnce(&DeviceDescription, &DevicePolicy) -> ProfileFields,
fields: impl FnOnce(&DeviceDescription, &DevicePolicy) -> (ProfileFields, StageBound),
) -> Result<Device, Error> {
if desc.api_version < ApiVersion::V1_2 {
return Err(Unsupported::needs(
@@ -151,8 +155,8 @@ impl Device {
));
}
identity_domains(&desc, &policy)?;
let fields = fields(&desc, &policy);
let profile = DeviceProfile::of(fields);
let (fields, stage_bound) = fields(&desc, &policy);
let profile = DeviceProfile::bounded(fields, stage_bound);
let metal = MetalDeviceProperties::derive(&profile, &desc.allocation);
Ok(Device(Arc::new(DeviceInner {
fingerprint: profile.fingerprint(),
@@ -475,11 +479,15 @@ fn by_identity(desc: &DeviceDescription) -> Vec<DriverWorkaround> {
{
vec![DriverWorkaround::NarrowMaskAfterSignedClamp]
}
// A register allocator that faults compiling a module past a word bound, and products of
// one value by zeros of opposite sign kept as one, on every GPU it drives.
// A register allocator that faults compiling a module past a word bound, products of one
// value by zeros of opposite sign kept as one, a stage past 2^20 objects of its
// serialized form corrupted, and a compiler whose memory outgrows the stage, on every GPU
// it drives.
Some(vk::DriverId::INTEL_OPEN_SOURCE_MESA) => vec![
DriverWorkaround::RegisterAllocatorOverflowsLargeModules,
DriverWorkaround::OppositeZeroProductsMerged,
DriverWorkaround::SerializedStageWrapsLargeModules,
DriverWorkaround::CompilerMemoryGrowsWithStageSize,
],
_ => Vec::new(),
}
+68 -7
View File
@@ -53,6 +53,8 @@ const SPIRV_VAL_RELAXATIONS: [(VkFeature, &str); 5] = [
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct DeviceProfile {
fields: ProfileFields,
/// Which stages the compile holds under a stage bound ([`StageBound`]).
stage_bound: StageBound,
/// [`DeviceProfile::fingerprint`], derived once here, where the fields are fixed.
///
/// Deriving it renders every field of the profile -- a format table alone is tens of
@@ -66,13 +68,15 @@ pub struct DeviceProfile {
}
impl DeviceProfile {
/// The profile of `fields`, with its fingerprint derived (the only way to build one): the
/// fingerprint is a function of the fields, so holding them together is what keeps it true of
/// them. A test's edit goes through `edit`, which only the crate's tests build.
pub(crate) fn of(fields: ProfileFields) -> DeviceProfile {
let fingerprint = fingerprint_of(&fields);
/// The profile of `fields` whose stages are held under `stage_bound`, with its fingerprint
/// derived (the only way to build one): the fingerprint is a function of both, so holding them
/// together is what keeps it true of them. A test's edit goes through `edit`, which only the
/// crate's tests build.
pub(crate) fn bounded(fields: ProfileFields, stage_bound: StageBound) -> DeviceProfile {
let fingerprint = fingerprint_of(&fields, stage_bound);
DeviceProfile {
fields,
stage_bound,
fingerprint,
}
}
@@ -83,10 +87,15 @@ impl DeviceProfile {
#[cfg(test)]
pub(crate) fn edit<T>(&mut self, change: impl FnOnce(&mut ProfileFields) -> T) -> T {
let answer = change(&mut self.fields);
self.fingerprint = fingerprint_of(&self.fields);
self.fingerprint = fingerprint_of(&self.fields, self.stage_bound);
answer
}
/// Which stages the compile holds under a stage bound.
pub(crate) fn stage_bound(&self) -> StageBound {
self.stage_bound
}
/// 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 {
@@ -481,7 +490,7 @@ pub(crate) fn fingerprints_derived() -> u64 {
/// The fingerprint of `fields` ([`DeviceProfile::fingerprint`]): the rendering streams into the
/// hash, because a materialized rendering of a profile with a format table is tens of kilobytes
/// that no input-scaled ledger charge accounts for.
fn fingerprint_of(fields: &ProfileFields) -> Hash256 {
fn fingerprint_of(fields: &ProfileFields, stage_bound: StageBound) -> Hash256 {
use sha2::{Digest, Sha256};
use std::fmt::Write as _;
struct Hashing(Sha256);
@@ -497,9 +506,31 @@ fn fingerprint_of(fields: &ProfileFields) -> Hash256 {
// `Hashing` never fails, and `Debug` of these plain-data types only fails when the
// writer does.
let _ = write!(h, "{:?}", fields);
// A profile whose stage bounds are its defects' renders its fields alone, as every profile
// did before the bound became a fact of its own; the other renders the bound after them.
if stage_bound != StageBound::Defects {
let _ = write!(h, "{stage_bound:?}");
}
h.0.finalize().into()
}
/// Which stages a profile's compile holds under a stage bound (`pipeline::compile`'s stage
/// bounds): the entry weight past which a module is not handed to the driver, a kernel planned
/// again keeping the widest mode's pin where only its emulation passed it, and every other module
/// refused.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub(crate) enum StageBound {
/// Only where the profile names a stage-size defect of its driver
/// (`DriverWorkaround::SerializedStageWrapsLargeModules`,
/// `DriverWorkaround::CompilerMemoryGrowsWithStageSize`), refused as that defect
/// (`Needs::DriverDefect`): `Device::new`'s profile.
Defects,
/// Every stage, on every device, at the heaviest entry measured to compile within host-sized
/// memory (`pipeline::compile::COMPILED_STAGE_WEIGHT`), refused as `Needs::StageBound`:
/// `Device::from_queries`' profile, keyed on no identity.
Every,
}
/// Every field of a profile, policy included. The fingerprint hashes all of them.
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct ProfileFields {
@@ -1524,6 +1555,36 @@ pub enum DriverWorkaround {
/// `f32` constant with a `-0.0` component multiplies by `+0.0` in that component and negates
/// it (`ProductForm::PositiveZeroFactors`), the same value on every device.
OppositeZeroProductsMerged,
/// The driver's pipeline creation corrupts a stage of more than 2^20 objects of its own
/// intermediate form. Mesa's common pipeline runtime (`vk_pipeline.c`), which ANV's pipelines
/// go through, writes each stage after the driver's preprocessing into a precompiled shader
/// with `nir_serialize` and reads it back with `nir_deserialize` before compiling it, on every
/// pipeline it makes, cached or not. The serialized form names a value by a 20-bit index, and
/// the bound (`MAX_OBJECT_IDS`, `1 << 20`) is held only by an assertion, which a release build
/// leaves out: past it the indices wrap, and the reader takes other objects for them. Measured
/// with ANV (`VK_DRIVER_ID_INTEL_OPEN_SOURCE_MESA`), Mesa 26.2.6, on the Iris Xe of RPL-P: a
/// kernel whose serialized stage held 1,096,128 objects faulted in `vkCreateComputePipelines`
/// (`SEGV_MAPERR` at address `0x40`, in the reader, at its 1,048,578th object), and so did a
/// synthetic compute module of 360,000 chained multiply-adds (about three objects each). Keyed
/// on the driver whatever its GPU and release, in `device::derive`. A module whose entry weighs more than
/// the bound the compile keeps under (`pipeline::compile`'s stage bound) is planned again in
/// the `Direct` simdgroup tier where it took the `Emulated` one only in place of the widest
/// mode's pin, and refused otherwise (`Needs::DriverDefect`), never handed to the driver.
SerializedStageWrapsLargeModules,
/// The driver's shader compiler takes memory that grows faster than the stage it compiles,
/// inside the process that creates the pipeline: past the largest stage measured to compile in
/// host-sized memory, one pipeline creation may take the host's memory. Measured with ANV
/// (`VK_DRIVER_ID_INTEL_OPEN_SOURCE_MESA`), Mesa 26.2.6, on the Iris Xe of RPL-P, compute
/// kernels created cold through `vkCreateComputePipelines` (job m3-max-26147): modules of
/// entry weight 73,814, 75,886 and 99,109 were created in 45 s, 47 s and 132 s at peak
/// resident sets of 1.76, 2.24 and 3.65 GiB; one of entry weight 532,213 passed 16 GiB at
/// 358 s without finishing, where it was stopped. Keyed on the driver whatever its GPU and
/// release, in `device::derive`. A module whose entry weighs more than the largest measured
/// to compile (`pipeline::compile`'s stage bound) is planned again in the `Direct` simdgroup
/// tier where it took the `Emulated` one only in place of the widest mode's pin, and refused
/// otherwise (`Needs::DriverDefect`), never handed to the driver. The bound rises when a larger
/// compile is measured within host-sized memory.
CompilerMemoryGrowsWithStageSize,
/// A compute shader that reads a push constant runs each thread with a longer payload, and so
/// more slowly on a light kernel: a measured cost fact (`device::driver_facts`) that chooses
/// between two exact encodings of a buffer slot's offset. ANV
@@ -1118,10 +1118,11 @@ fn half_rounding_follows_the_queries_alone() {
}
}
/// `DriverWorkaround::RegisterAllocatorOverflowsLargeModules` is keyed on ANV, whatever its GPU
/// and release; every committed ANV profile carries it, and no other profile does. The Iris Xe's
/// description under RADV or NVIDIA's driver loses it. The stage bound is no workaround: it holds
/// on every device (`pipeline::compile`'s `stage_bound`).
/// `DriverWorkaround::RegisterAllocatorOverflowsLargeModules`,
/// `DriverWorkaround::SerializedStageWrapsLargeModules` and
/// `DriverWorkaround::CompilerMemoryGrowsWithStageSize` are keyed on ANV, whatever its GPU and
/// release; every committed ANV profile carries them, and no other profile does. The Iris Xe's
/// description under RADV or NVIDIA's driver loses them.
#[test]
fn large_module_defects_are_keyed_on_anv() {
use crate::device::profile::DriverWorkaround;
@@ -1131,7 +1132,11 @@ fn large_module_defects_are_keyed_on_anv() {
.profile()
.clone()
};
for fact in [DriverWorkaround::RegisterAllocatorOverflowsLargeModules] {
for fact in [
DriverWorkaround::RegisterAllocatorOverflowsLargeModules,
DriverWorkaround::SerializedStageWrapsLargeModules,
DriverWorkaround::CompilerMemoryGrowsWithStageSize,
] {
for (stem, text) in committed_profiles() {
let desc = DeviceDescription::from_khronos_json(&text, None).unwrap();
let anv = desc.driver_id == Some(vk::DriverId::INTEL_OPEN_SOURCE_MESA);
@@ -1148,6 +1153,29 @@ fn large_module_defects_are_keyed_on_anv() {
}
}
/// The stage bound is a fact of the profile: `Device::new` bounds a stage only where its driver's
/// identity names a stage-size defect (`StageBound::Defects`), `Device::from_queries` bounds every
/// stage (`StageBound::Every`), on every committed profile. The fact keys the fingerprint: a
/// profile of the same fields bounded otherwise is another profile.
#[test]
fn the_stage_bound_is_a_fact_of_the_profile() {
use crate::device::profile::{DeviceProfile, StageBound};
for (stem, text) in committed_profiles() {
let desc = DeviceDescription::from_khronos_json(&text, None).unwrap();
let old = Device::new(desc.clone(), DevicePolicy::default()).unwrap();
let queries = Device::from_queries(desc, DevicePolicy::default()).unwrap();
assert_eq!(old.profile().stage_bound(), StageBound::Defects, "{stem}");
assert_eq!(queries.profile().stage_bound(), StageBound::Every, "{stem}");
let fields = queries.profile().fields().clone();
let other = DeviceProfile::bounded(fields, StageBound::Defects);
assert_ne!(
other.fingerprint(),
queries.profile().fingerprint(),
"{stem}"
);
}
}
/// The two view facts (`DriverWorkaround::UniformBufferPerLaneReadsSerialize` and
/// `DriverWorkaround::ExternalUniformReadsSkipACache`) come from the description's measured set
/// alone: no committed profile carries either by its identity, the GPUs they were first measured
+14 -7
View File
@@ -16,7 +16,8 @@
//! mechanism, [`Needs::DriverDefect`] is a mechanism the device's driver is measured to run
//! wrong ([`Needs::RuntimeDriverDefect`] one the runtime records for itself), and
//! [`Needs::StageBound`] is a stage the device's plan writes heavier than the translator hands
//! any driver. The runtime adds
//! any driver of a device [`Device::from_queries`](crate::device::Device::from_queries) made.
//! The runtime adds
//! [`Needs::MetalGpuFamily`]: Metal's own refusal
//! on a device without the family, and [`Needs::MetalRefuses`]: Metal's own refusal of the
//! form on the devices it was measured on. The translator does not return different output in place
@@ -542,11 +543,14 @@ pub enum Needs {
/// change. A device without the defect runs the input.
RuntimeDriverDefect(RuntimeDriverDefect),
/// The stage, as this device's plan writes it, is heavier than the translator hands any
/// driver: its entry weight passes the heaviest stage measured to compile within host-sized
/// memory ([`Unsupported::symbol`] names the weight and the bound). The weight is the plan's,
/// so a device whose plan writes the stage lighter translates it: one that keeps its widest
/// driver of a device [`Device::from_queries`](crate::device::Device::from_queries) made: its
/// entry weight passes the heaviest stage measured to compile within host-sized memory
/// ([`Unsupported::symbol`] names the weight and the bound). The weight is the plan's, so a
/// device whose plan writes the stage lighter translates it: one that keeps its widest
/// simdgroup mode pinned where this one emulates simdgroups. A gap of the translator rather
/// than of the device: no device is handed a stage past the bound.
/// than of the device: no such device is handed a stage past the bound. A device
/// [`Device::new`](crate::device::Device::new) made bounds a stage only where its driver is
/// measured to need it ([`Needs::DriverDefect`]).
StageBound,
/// A device that claims this Metal GPU family (`MTLGPUFamily`'s raw value, 1010 for Apple10),
/// which the device does not: Metal itself refuses the input on a device without the family,
@@ -1293,8 +1297,11 @@ pub enum Feature {
ImageAtomics,
/// Too many descriptors of one kind in a stage or pipeline.
DescriptorCount,
/// A stage module heavier than the translator hands any driver: past the heaviest measured to
/// compile within host-sized memory ([`Needs::StageBound`]).
/// A stage module heavier than the translator hands the device's driver: past the heaviest
/// measured to compile within host-sized memory, on a device
/// [`Device::from_queries`](crate::device::Device::from_queries) made ([`Needs::StageBound`]),
/// or larger than the device's driver is measured to compile, intact and within host-sized
/// memory ([`Needs::DriverDefect`] names the defect).
StageSize,
/// A buffer window beyond the descriptor range limits.
BufferRange,
+4 -2
View File
@@ -344,8 +344,10 @@ pub const DEVICE_LOCKSTEP: &str = "barrier.lockstep.device";
/// Whether [`widest_pin`] weighs a kernel for the `Emulated` tier, or the kernel keeps the
/// `Direct` tier's pin to the device's widest mode whatever its pressure: a kernel whose emulated
/// module passed the stage bound (`pipeline::compile`'s `stage_bound`) is planned again keeping
/// it.
/// module passed a bound its driver compiles within, or the bound every stage of a profile
/// `Device::from_queries` built is held under, is planned again keeping it (`pipeline::compile`'s
/// stage bounds, `DriverWorkaround::SerializedStageWrapsLargeModules`,
/// `DriverWorkaround::CompilerMemoryGrowsWithStageSize`, `device::profile::StageBound`).
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum WidestPin {
/// [`widest_pin`] weighs the kernel.
+15 -15
View File
@@ -62,7 +62,7 @@ use crate::reflection;
use crate::spirv::ir::TypedModule;
pub use entry::{EntryDescriptor, EntryPlan, StandaloneModule};
pub(crate) use stage_bound::COMPILED_STAGE_WEIGHT;
pub(crate) use stage_bound::StageBounds;
/// Which entry of a bitcode module to compile.
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
@@ -1683,36 +1683,36 @@ pub(crate) fn compile_bitcode_kept(
})
}
/// [`compile_bitcode_kept`] under the stage bound `bound` in place of [`COMPILED_STAGE_WEIGHT`],
/// so a test reaches the bound with a small module.
/// [`compile_bitcode_kept`] under the stage bounds `bounds` in place of
/// [`StageBounds::MEASURED`], so a test reaches each bound with a small module.
#[cfg(test)]
pub(crate) fn compile_bitcode_bounded(
bitcode: &[u8],
entry: EntryRef<'_>,
p: &DeviceProfile,
m: &mut Meter,
bound: u64,
bounds: StageBounds,
) -> Result<(CompiledFunction, Plan, TypedModule), Error> {
guarded(|| {
let consts = FunctionConstantValues::defaults();
let inputs = LowerInputs::new();
let r = Request::bitcode(bitcode, entry, &consts, &[], &inputs);
compile_bounded(&r, p, m, (SPIRV_WORDS, bound), TypedModule::clone)
compile_bounded(&r, p, m, (SPIRV_WORDS, bounds), TypedModule::clone)
.map(|(artifact, plan, module)| (CompiledFunction::new(artifact), plan, module))
})
}
/// Stage `fd` compiled with default lowering inputs as [`compile_stage`] compiles it, or as
/// [`compile_stage_from`] compiles it reading `entries` where given, under the stage bound `bound`
/// in place of [`COMPILED_STAGE_WEIGHT`]: so a test reaches the bound with a small module through
/// either path.
/// [`compile_stage_from`] compiles it reading `entries` where given, under the stage bounds
/// `bounds` in place of [`StageBounds::MEASURED`]: so a test reaches each bound with a small
/// module through either path.
#[cfg(test)]
pub(crate) fn compile_stage_bounded(
fd: &FunctionDescriptor,
p: &DeviceProfile,
entries: Option<&StageEntries>,
m: &mut Meter,
bound: u64,
bounds: StageBounds,
) -> Result<CompiledFunction, Error> {
let inputs = LowerInputs::new();
let shared = entries.map_or(Shared::Nothing, |e| Shared::Entry(e, fd));
@@ -1724,7 +1724,7 @@ pub(crate) fn compile_stage_bounded(
InputsFrom::Given(&inputs),
shared,
|r| {
compile_bounded(r, p, m, (SPIRV_WORDS, bound), |_| ())
compile_bounded(r, p, m, (SPIRV_WORDS, bounds), |_| ())
.map(|(artifact, _, ())| CompiledFunction::new(artifact))
},
)
@@ -2928,16 +2928,16 @@ fn compile_kept<K>(
word_cap: u64,
keep: impl FnOnce(&TypedModule) -> K,
) -> Result<(Arc<FunctionArtifact>, Plan, K), Error> {
compile_bounded(r, p, m, (word_cap, COMPILED_STAGE_WEIGHT), keep)
compile_bounded(r, p, m, (word_cap, StageBounds::MEASURED), keep)
}
/// [`compile_kept`] under the stage bound `bound` (`stage_bound`; [`COMPILED_STAGE_WEIGHT`] in
/// production).
/// [`compile_kept`] under the stage bounds `bounds` where the profile has their defects or bounds
/// every stage (`stage_bound`; [`StageBounds::MEASURED`] in production).
fn compile_bounded<K>(
r: &Request<'_>,
p: &DeviceProfile,
m: &mut Meter,
(word_cap, bound): (u64, u64),
(word_cap, bounds): (u64, StageBounds),
keep: impl FnOnce(&TypedModule) -> K,
) -> Result<(Arc<FunctionArtifact>, Plan, K), Error> {
let (
@@ -2950,7 +2950,7 @@ fn compile_bounded<K>(
unbound,
},
crate::lower::emit::Emitted { mut module, merged },
) = stage_bound::emit(r, p, (word_cap, bound), m)?;
) = stage_bound::emit(r, p, (word_cap, bounds), m)?;
// On a driver whose compiler loses a simdgroup's storage writes after an `optnone` call only
// its helper invocations make, those invocations take another arm where that is exact, and
// each such call left is fenced once every analysis below has read the module.
@@ -169,7 +169,10 @@ impl DeviceProfile {
/// Everything [`DeviceProfile::compile_entry`] does before emission (decode, specialize,
/// analyze, select), and what it cost against `budget`: its first plan, which a kernel whose
/// emitted module passes the stage bound replaces (`pipeline::compile`'s `stage_bound`).
/// emitted module passes a bound its driver compiles within, or the bound every stage of a
/// profile `Device::from_queries` built is held under, replaces
/// (`DriverWorkaround::SerializedStageWrapsLargeModules`,
/// `DriverWorkaround::CompilerMemoryGrowsWithStageSize`, `device::profile::StageBound`).
pub fn plan_entry(
&self,
d: &EntryDescriptor<'_>,
@@ -1,58 +1,144 @@
//! The stage bound: every module kept under the heaviest stage measured to compile within
//! host-sized memory, on every device.
//! The stage bounds: a module kept under the sizes its driver's compiler takes intact
//! (`DriverWorkaround::SerializedStageWrapsLargeModules`) and in host-sized memory
//! (`DriverWorkaround::CompilerMemoryGrowsWithStageSize`), where `Device::new`'s profile names
//! those defects; and on a profile `Device::from_queries` built, every module kept under the
//! compiled bound on every device (`device::profile::StageBound`).
//!
//! A driver's shader compiler can take memory that grows faster than the stage it compiles, inside
//! the process that creates the pipeline. Measured on ANV, Mesa 26.2.6, on the Iris Xe of RPL-P:
//! compute modules created cold through `vkCreateComputePipelines` (job m3-max-26147) of entry
//! weights 73,814, 75,886 and 99,109 took 45 s, 47 s and 132 s and peak resident sets of 1.76,
//! 2.24 and 3.65 GiB, and one of entry weight 532,213 passed 16 GiB at 358 s without finishing,
//! where it was stopped. Far above that, the same driver faults: Mesa's common pipeline runtime
//! (`vk_pipeline.c`) writes each stage into a serialized form that names an object by a 20-bit
//! index, which wraps past 2^20 objects (a stage of entry weight 1,603,989 faulted inside
//! `vkCreateComputePipelines`).
//! Mesa's common pipeline runtime (`vk_pipeline.c`), which ANV's pipelines go through, writes each
//! stage after the driver's preprocessing into a precompiled shader (`nir_serialize`) and reads it
//! back (`nir_deserialize`) before compiling it, on every pipeline it makes, cached or not. The
//! serialized form names a value by a 20-bit index, and the bound (`MAX_OBJECT_IDS`, 2^20 objects:
//! values, blocks, variables) is held only by an assertion a release build leaves out: past it the
//! indices wrap, the reader takes other objects for them, and the driver faults inside
//! `vkCreateComputePipelines` (Mesa 26.2.6, ANV on the Iris Xe). Below that bound, the driver's
//! compiler takes memory that grows faster than the stage, in the process that creates the
//! pipeline, so one creation past the largest stage measured to compile may take the host's
//! memory.
//!
//! The bound is one form for every device: the heaviest stage measured to compile on the slowest
//! compiler measured ([`COMPILED_STAGE_WEIGHT`]). No margin is taken below it, as no weight above
//! it is measured to compile there; it rises when a larger compile is measured within host-sized
//! memory. A device whose compiler would take a heavier stage is refused it all the same, a
//! known gap (`docs/FAST-PATHS.md`).
//!
//! A module whose entry weighs more than the bound (`spirv::roll::entry_weight`: the entry's
//! instructions with each call counted as its callee's body, as the driver inlines every call)
//! after the repeated regions are rolled is past it:
//! On a profile with either defect, a module whose entry weighs more than its bound
//! (`spirv::roll::entry_weight`: the entry's instructions with each call counted as its callee's
//! body, as the driver inlines every call) after the repeated regions are rolled is past it:
//!
//! - a kernel that took the `Emulated` simdgroup tier only in place of the `Direct` tier's pin to
//! the device's widest mode (`lower::simd::widest_pin`, which the subgroup size range decides)
//! is planned again keeping the pin (`lower::simd::WidestPin::Kept`), its emulated module
//! dropped and what its plan and emission hold of the ledger released. Only the selection is
//! made again: the entry is decoded, specialized, ordered and analyzed once, so the kernel is
//! charged what any compile of it is charged, whichever path reached it (`super::Analyzed`);
//! the device's widest mode (`lower::simd::widest_pin`) is planned again keeping the pin
//! (`lower::simd::WidestPin::Kept`), its emulated module dropped and what its plan and emission
//! hold of the ledger released. Only the selection is made again: the entry is decoded,
//! specialized, ordered and analyzed once, so the kernel is charged what any compile of it is
//! charged, whichever path reached it (`super::Analyzed`);
//! - every other module past it, a kernel planned again that still is among them, is refused
//! (`Unsupported`, `Feature::StageSize`, `Needs::StageBound`, and as its symbol the module's
//! entry weight and the bound it passed).
//! (`Unsupported`, `Feature::StageSize`, `Needs::DriverDefect`, naming the serialized stage's
//! defect past its bound and the compiler's memory below it, and as its symbol the module's
//! entry weight and the bound it passed): Metal compiles it, so the refusal is the device's
//! gap, recorded in `docs/FAST-PATHS.md`'s known gaps.
//!
//! **Every device.** A profile `Device::from_queries` built reads no driver identity, so it names
//! no defect: it holds every stage, on every device, under the compiled bound, the heaviest stage
//! measured to compile on the slowest compiler measured, one form for every device. A kernel past
//! it is planned again keeping the widest mode's pin as above, and every other module past it is
//! refused as `Needs::StageBound`, with the same symbol: a device whose compiler would take a
//! heavier stage is refused it all the same, a known gap of `metal2vulkan-rt`.
//!
//! **The serialized bound.** The driver's object count is not the module's: it counts the stage
//! after its own inlining and optimization. Measured on ANV, Mesa 26.2.6, on the Iris Xe of RPL-P
//! (the count each serialized stage holds, read where the driver reads it back), over 22 compute
//! stages: the heaviest, of entry weight 1,603,989, held 1,096,128 objects, 0.683 per instruction
//! of its weight, and faulted the driver; the other 21 held 0.14 to 0.99 objects per instruction
//! of a count of the entry's instructions that ran 1.9 to 2.7% below the entry weight on the five
//! modules both counted. [`SERIALIZED_STAGE_WEIGHT`] is three quarters of 2^20: a stage at the
//! bound stays under the driver's 2^20 objects at up to 4/3 objects per instruction, a third above
//! the largest ratio measured.
//!
//! **The compiled bound.** [`COMPILED_STAGE_WEIGHT`] is the heaviest entry measured to compile
//! within host-sized memory: on ANV, Mesa 26.2.6, on the Iris Xe of RPL-P, compute modules created
//! cold through `vkCreateComputePipelines` (job m3-max-26147) of entry weights 73,814, 75,886 and
//! 99,109 took 45 s, 47 s and 132 s and peak resident sets of 1.76, 2.24 and 3.65 GiB, and one of
//! entry weight 532,213 passed 16 GiB at 358 s without finishing, where it was stopped. No margin
//! is taken below it, as no weight above it is measured to compile; it rises when a larger compile
//! is measured within host-sized memory.
use super::{analyze_one, Planned, Request};
use crate::budget::Meter;
use crate::device::profile::{DriverWorkaround, StageBound};
use crate::device::DeviceProfile;
use crate::error::{DiagName, Error, Feature, Needs, Unsupported};
use crate::lower::emit::Emitted;
use crate::lower::simd::WidestPin;
/// The heaviest entry ([`crate::spirv::roll::entry_weight`]) any device is handed: the largest
/// measured to compile within host-sized memory (the module docs).
/// The heaviest entry ([`crate::spirv::roll::entry_weight`]) a profile with
/// `DriverWorkaround::SerializedStageWrapsLargeModules` is handed (the module docs' serialized
/// bound).
pub(crate) const SERIALIZED_STAGE_WEIGHT: u64 = 3 << 18;
/// The heaviest entry ([`crate::spirv::roll::entry_weight`]) a profile with
/// `DriverWorkaround::CompilerMemoryGrowsWithStageSize`, or one whose every stage is bounded
/// (`StageBound::Every`), is handed: the largest measured to compile (the module docs' compiled
/// bound).
pub(crate) const COMPILED_STAGE_WEIGHT: u64 = 99_109;
/// The entry weights past which a profile with each defect, or one whose every stage is bounded, is
/// not handed a module: the measured ones in production ([`StageBounds::MEASURED`]), others in a
/// test, so it reaches each bound with a small module.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub(crate) struct StageBounds {
/// `DriverWorkaround::SerializedStageWrapsLargeModules`' bound.
pub(crate) serialized: u64,
/// `DriverWorkaround::CompilerMemoryGrowsWithStageSize`'s bound, and every stage's on a
/// profile whose every stage is bounded.
pub(crate) compiled: u64,
}
impl StageBounds {
/// The bounds measured on the defects' drivers (the module docs).
pub(crate) const MEASURED: StageBounds = StageBounds {
serialized: SERIALIZED_STAGE_WEIGHT,
compiled: COMPILED_STAGE_WEIGHT,
};
/// `p`'s bounds, each with what a module past it is refused as: on a profile whose every
/// stage is bounded, the compiled bound alone; else its defects', the serialized stage's
/// first, so a module past both is refused for the one that faults the driver.
fn of(self, p: &DeviceProfile) -> Vec<(Past, u64)> {
if p.stage_bound() == StageBound::Every {
return vec![(Past::Every, self.compiled)];
}
[
(
DriverWorkaround::SerializedStageWrapsLargeModules,
self.serialized,
),
(
DriverWorkaround::CompilerMemoryGrowsWithStageSize,
self.compiled,
),
]
.into_iter()
.filter(|(defect, _)| p.workarounds().contains(defect))
.map(|(defect, bound)| (Past::Defect(defect), bound))
.collect()
}
}
/// What a module past a bound is refused as.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
enum Past {
/// The driver's stage-size defect (`Needs::DriverDefect`).
Defect(DriverWorkaround),
/// The bound every stage is held under (`Needs::StageBound`).
Every,
}
/// `r`'s function planned and emitted with its repeated regions rolled, under the plan's word
/// estimate `word_cap` and the stage bound `bound` ([`COMPILED_STAGE_WEIGHT`] in production, a
/// smaller one in a test, so it reaches the bound with a small module): planned again keeping the
/// widest mode's pin where only that pin's emulation passed it, else refused, naming the module's
/// entry weight and the bound ([`past_bound`]).
/// estimate `word_cap` and, on a profile with a stage bound's defect or whose every stage is
/// bounded, under `bounds` (the module docs): planned again keeping the widest mode's pin where
/// only that pin's emulation passed one, else refused as the first bound the module passes, naming
/// the module's entry weight and that bound ([`past_bound`]).
pub(super) fn emit(
r: &Request<'_>,
p: &DeviceProfile,
(word_cap, bound): (u64, u64),
(word_cap, bounds): (u64, StageBounds),
m: &mut Meter,
) -> Result<(Planned, Emitted), Error> {
let bounded = bounds.of(p);
let analyzed = analyze_one(r, p, m)?;
let mut widest = WidestPin::Weighed;
loop {
@@ -65,12 +151,21 @@ pub(super) fn emit(
crate::spirv::roll::roll_entry(&mut emitted.module, m)?;
// A load of a uniform view that every trip of its loop reads alike leaves the loop.
crate::spirv::hoist::hoist_uniform_loads(&mut emitted.module, p.containment(), m)?;
let weight = crate::spirv::roll::entry_weight(&emitted.module, m)?;
if weight <= bound {
let past = match bounded.is_empty() {
true => None,
false => {
let weight = crate::spirv::roll::entry_weight(&emitted.module, m)?;
bounded
.iter()
.find(|&&(_, cap)| weight > cap)
.map(|&(past, cap)| (past, weight, cap))
}
};
let Some((past, weight, bound)) = past else {
return Ok((analyzed.planned(plan, kernel), emitted));
}
};
if widest == WidestPin::Kept || !plan.families.simd.widest_pin {
return Err(past_bound(weight, bound));
return Err(refused(past, weight, bound));
}
// The emulated plan and module go, and with them what they hold of the ledger.
drop((plan, emitted));
@@ -80,13 +175,23 @@ pub(super) fn emit(
}
}
/// The refusal of a stage of entry weight `weight`, past the bound `bound`: its symbol names both.
fn past_bound(weight: u64, bound: u64) -> Error {
let named = format!("entry weight {weight}, past the bound {bound}");
Error::Unsupported(Unsupported {
feature: Feature::StageSize,
needs: Needs::StageBound,
location: None,
symbol: Some(DiagName::new(named)),
})
/// The refusal of a module of entry weight `weight` past `bound`, as `past` says.
fn refused(past: Past, weight: u64, bound: u64) -> Error {
let named = past_bound(weight, bound);
match past {
Past::Defect(defect) => Unsupported::driver_defect(Feature::StageSize, defect)
.naming(named)
.into(),
Past::Every => Error::Unsupported(Unsupported {
feature: Feature::StageSize,
needs: Needs::StageBound,
location: None,
symbol: Some(named),
}),
}
}
/// What a stage's refusal names as its symbol: the module's entry weight and the bound it passed.
fn past_bound(weight: u64, bound: u64) -> DiagName {
DiagName::new(format!("entry weight {weight}, past the bound {bound}"))
}
@@ -2387,20 +2387,133 @@ fn a_pressured_kernel_takes_the_emulated_tier_in_place_of_the_widest_mode() {
);
}
/// On every device, a module whose entry weighs more than the stage bound (`pipeline::compile`'s
/// `stage_bound`, here bounds the test sets) is never emitted: the pressured kernel of
/// `a_pressured_kernel_takes_the_emulated_tier_in_place_of_the_widest_mode`, whose emulated module
/// passes the bound, is planned again keeping the `Direct` tier's pin to 32 lanes, its answers
/// Metal's; under a bound its `Direct` module passes too, it is refused (`Feature::StageSize`,
/// `Needs::StageBound`, and as its symbol, which its Display prints, the module's entry weight and
/// the bound it passed). The Iris Xe's description under RADV's driver answers alike: the bound
/// is no driver's workaround.
/// On a driver with a stage bound's defect (`DriverWorkaround::SerializedStageWrapsLargeModules`,
/// a stage corrupted past the size it compiles intact, and
/// `DriverWorkaround::CompilerMemoryGrowsWithStageSize`, a compile past the size measured within
/// host-sized memory; ANV: the Iris Xe of RPL-P), a module whose entry weighs more than either
/// bound (`pipeline::compile`'s `stage_bound`, here bounds the test sets) is never emitted: the
/// pressured kernel of `a_pressured_kernel_takes_the_emulated_tier_in_place_of_the_widest_mode`,
/// whose emulated module passes a bound, is planned again keeping the `Direct` tier's pin to 32
/// lanes, its answers Metal's; under a bound its `Direct` module passes too, it is refused
/// (`Feature::StageSize`, that bound's defect named, and as its symbol, which its Display prints,
/// the module's entry weight and the bound it passed), and past both, the serialized stage's
/// defect, which faults the driver, is named. The same profile without either defect emits the
/// emulated module under every bound.
#[test]
fn a_kernel_past_the_stage_bound_keeps_the_widest_pin_or_is_refused() {
use crate::device::profile::DriverWorkaround;
use crate::device::Device;
use crate::error::{DiagName, Feature, Needs};
use crate::lower::simd::{WIDEST_PIN, WIDEST_PIN_FLOOR, WIDEST_PIN_WORDS};
use crate::pipeline::compile::compile_bitcode_bounded;
use crate::pipeline::compile::{compile_bitcode_bounded, StageBounds};
use crate::pipeline::testing::meter;
use crate::spirv::roll::entry_weight;
let half = |t: u32| if t & 31 < 16 { t ^ 1 } else { t };
let fan = Padding::Fan((WIDEST_PIN_FLOOR / 2 + 16).max(WIDEST_PIN_WORDS as usize + 8));
let Some(bc) = assemble("device_half", &device_half_padded(fan, None)) else {
return;
};
let entry = EntryRef::Name("device_half");
let weight = |module: &TypedModule| entry_weight(module, &mut meter()).expect("weight");
let serialized = DriverWorkaround::SerializedStageWrapsLargeModules;
let memory = DriverWorkaround::CompilerMemoryGrowsWithStageSize;
let iris_desc = crate::pipeline::testing::description("intel-irisxe-rplp-anv").unwrap();
let iris = Device::new(iris_desc, DevicePolicy::default()).unwrap();
let iris = iris.profile();
assert!(iris.workarounds().contains(&serialized));
assert!(iris.workarounds().contains(&memory));
// The same profile without either defect: every other workaround kept, so its modules are the
// Iris Xe's.
let mut other = iris.fields().clone();
other
.workarounds
.retain(|w| *w != serialized && *w != memory);
let other = &crate::device::profile::DeviceProfile::bounded(
other,
crate::device::profile::StageBound::Defects,
);
assert!(!other.workarounds().contains(&serialized));
assert!(!other.workarounds().contains(&memory));
// One defect's bound at `cap`, the other's past every module.
let at = |defect, cap| match defect == serialized {
true => StageBounds {
serialized: cap,
compiled: u64::MAX,
},
false => StageBounds {
serialized: u64::MAX,
compiled: cap,
},
};
// The defect a refusal names, checking it names the module's entry weight `weight` and the
// bound `bound` it passed.
let refused_for = |refused: Error, weight: u64, bound: u64| match refused {
Error::Unsupported(u) if u.feature == Feature::StageSize => {
let named = format!("entry weight {weight}, past the bound {bound}");
assert_eq!(u.symbol, Some(DiagName::new(named.as_str())), "{u}");
assert!(u.to_string().contains(&named), "{u}");
match u.needs {
Needs::DriverDefect(defect) => defect,
needs => panic!("{needs:?}"),
}
}
refused => panic!("{refused:?}"),
};
// Unbounded, the kernel emulates its simdgroups in place of the widest mode on both.
let compile = |p, bounds| compile_bitcode_bounded(&bc, entry, p, &mut meter(), bounds);
let (_, plan, emulated) = compile(iris, at(serialized, u64::MAX)).expect("emulated");
assert_eq!((plan.simd.1, uses(&plan, WIDEST_PIN)), (Tier::Emulated, 1));
let emulated = weight(&emulated);
let want: Vec<u32> = (0..64).map(half).collect();
let mut pinned = 0;
for defect in [serialized, memory] {
// Under a bound the emulated module passes: planned again keeping the pin, exact at 32
// lanes.
let (_, plan, module) = compile(iris, at(defect, emulated - 1)).expect("planned again");
assert_eq!(plan.simd.1, Tier::Direct, "{defect:?}");
assert_eq!(uses(&plan, WIDEST_PIN), 0);
assert_eq!(plan.subgroup.size, Some(32));
pinned = weight(&module);
assert!(pinned < emulated, "pinned {pinned}, emulated {emulated}");
assert_eq!(run_words(&plan, &module, 64, SubgroupSize::W32), want);
// Under a bound the pinned module passes too: refused, the bound's defect named.
let refused = compile(iris, at(defect, pinned - 1)).expect_err("past the bound");
assert_eq!(refused_for(refused, pinned, pinned - 1), defect);
// Without the defect, the emulated module is emitted under either bound.
for cap in [emulated - 1, pinned - 1] {
let (_, plan, module) = compile(other, at(defect, cap)).expect("emitted");
assert_eq!((plan.simd.1, uses(&plan, WIDEST_PIN)), (Tier::Emulated, 1));
assert!(weight(&module) > cap, "{cap}");
for lanes in CHUNKED {
assert_eq!(run_words(&plan, &module, 64, lanes), want, "{lanes:?}");
}
}
}
// Past both bounds, the serialized stage's defect is named.
let both = StageBounds {
serialized: pinned - 1,
compiled: pinned - 1,
};
let refused = compile(iris, both).expect_err("past both bounds");
assert_eq!(refused_for(refused, pinned, pinned - 1), serialized);
}
/// On a profile `Device::from_queries` built, every stage is held under the compiled bound
/// (`device::profile::StageBound::Every`; here bounds the test sets), whatever the driver: the
/// pressured kernel of `a_pressured_kernel_takes_the_emulated_tier_in_place_of_the_widest_mode`,
/// whose emulated module passes the bound, is planned again keeping the `Direct` tier's pin to 32
/// lanes, its answers Metal's; under a bound its `Direct` module passes too, it is refused
/// (`Feature::StageSize`, `Needs::StageBound`, and as its symbol the module's entry weight and the
/// bound it passed). The serialized stage's bound is no bound there. Through `Device::new`, the
/// same description under a driver that names no stage-size defect (RADV) emits the emulated
/// module under every bound.
#[test]
fn every_stage_from_queries_keeps_the_widest_pin_or_is_refused() {
use crate::device::profile::StageBound;
use crate::device::Device;
use crate::error::{DiagName, Feature, Needs};
use crate::lower::simd::{WIDEST_PIN, WIDEST_PIN_FLOOR, WIDEST_PIN_WORDS};
use crate::pipeline::compile::{compile_bitcode_bounded, StageBounds};
use crate::pipeline::testing::meter;
use crate::spirv::roll::entry_weight;
let half = |t: u32| if t & 31 < 16 { t ^ 1 } else { t };
@@ -2412,33 +2525,58 @@ fn a_kernel_past_the_stage_bound_keeps_the_widest_pin_or_is_refused() {
let weight = |module: &TypedModule| entry_weight(module, &mut meter()).expect("weight");
let want: Vec<u32> = (0..64).map(half).collect();
let mut desc = crate::pipeline::testing::description("intel-irisxe-rplp-anv").unwrap();
let iris = Device::new(desc.clone(), DevicePolicy::default()).unwrap();
let queries = Device::from_queries(desc.clone(), DevicePolicy::default()).unwrap();
let queries = queries.profile();
assert_eq!(queries.stage_bound(), StageBound::Every);
desc.driver_id = Some(crate::vk::DriverId::MESA_RADV);
let radv = Device::new(desc, DevicePolicy::default()).unwrap();
for (driver, p) in [("ANV", iris.profile()), ("RADV", radv.profile())] {
let compile = |bound| compile_bitcode_bounded(&bc, entry, p, &mut meter(), bound);
// Unbounded, the kernel emulates its simdgroups in place of the widest mode.
let (_, plan, emulated) = compile(u64::MAX).expect("emulated");
let radv = radv.profile();
assert_eq!(radv.stage_bound(), StageBound::Defects);
let compile = |p, bounds| compile_bitcode_bounded(&bc, entry, p, &mut meter(), bounds);
let compiled = |cap| StageBounds {
serialized: u64::MAX,
compiled: cap,
};
// Unbounded, the kernel emulates its simdgroups in place of the widest mode.
let (_, plan, emulated) = compile(queries, compiled(u64::MAX)).expect("emulated");
assert_eq!((plan.simd.1, uses(&plan, WIDEST_PIN)), (Tier::Emulated, 1));
let emulated = weight(&emulated);
// Under a bound the emulated module passes: planned again keeping the pin, exact at 32 lanes.
let (_, plan, module) = compile(queries, compiled(emulated - 1)).expect("planned again");
assert_eq!((plan.simd.1, uses(&plan, WIDEST_PIN)), (Tier::Direct, 0));
assert_eq!(plan.subgroup.size, Some(32));
let pinned = weight(&module);
assert!(pinned < emulated, "pinned {pinned}, emulated {emulated}");
assert_eq!(run_words(&plan, &module, 64, SubgroupSize::W32), want);
// Under a bound the pinned module passes too: refused, naming its weight and the bound.
match compile(queries, compiled(pinned - 1)).expect_err("past the bound") {
Error::Unsupported(u) if u.feature == Feature::StageSize => {
let named = format!("entry weight {pinned}, past the bound {}", pinned - 1);
assert_eq!(u.symbol, Some(DiagName::new(named.as_str())), "{u}");
assert!(u.to_string().contains(&named), "{u}");
assert_eq!(u.needs, Needs::StageBound);
}
refused => panic!("{refused:?}"),
}
// The serialized stage's bound is none of its bounds.
let serialized = StageBounds {
serialized: pinned - 1,
compiled: u64::MAX,
};
let (_, plan, module) = compile(queries, serialized).expect("emitted");
assert_eq!((plan.simd.1, uses(&plan, WIDEST_PIN)), (Tier::Emulated, 1));
assert_eq!(weight(&module), emulated);
// Through `Device::new` under a driver that names no stage-size defect, no bound at all.
for cap in [emulated - 1, pinned - 1] {
let both = StageBounds {
serialized: cap,
compiled: cap,
};
let (_, plan, module) = compile(radv, both).expect("emitted");
assert_eq!((plan.simd.1, uses(&plan, WIDEST_PIN)), (Tier::Emulated, 1));
let emulated = weight(&emulated);
// Under a bound the emulated module passes: planned again keeping the pin, exact at 32
// lanes.
let (_, plan, module) = compile(emulated - 1).expect("planned again");
assert_eq!(plan.simd.1, Tier::Direct, "{driver}");
assert_eq!(uses(&plan, WIDEST_PIN), 0);
assert_eq!(plan.subgroup.size, Some(32));
let pinned = weight(&module);
assert!(pinned < emulated, "pinned {pinned}, emulated {emulated}");
assert_eq!(run_words(&plan, &module, 64, SubgroupSize::W32), want);
// Under a bound the pinned module passes too: refused, naming its weight and the bound.
match compile(pinned - 1).expect_err("past the bound") {
Error::Unsupported(u) if u.feature == Feature::StageSize => {
let named = format!("entry weight {pinned}, past the bound {}", pinned - 1);
assert_eq!(u.symbol, Some(DiagName::new(named.as_str())), "{u}");
assert!(u.to_string().contains(&named), "{u}");
assert_eq!(u.needs, Needs::StageBound, "{driver}");
}
refused => panic!("{refused:?}"),
assert_eq!(weight(&module), emulated, "{cap}");
for lanes in CHUNKED {
assert_eq!(run_words(&plan, &module, 64, lanes), want, "{lanes:?}");
}
}
}
@@ -2460,7 +2598,7 @@ fn a_kernel_past_the_stage_bound_gets_one_answer_through_either_path() {
use crate::library::Library;
use crate::lower::simd::{WIDEST_PIN_FLOOR, WIDEST_PIN_WORDS};
use crate::pipeline::compile::{
compile_bitcode_bounded, compile_stage_bounded, plan_bitcode, StageEntries,
compile_bitcode_bounded, compile_stage_bounded, plan_bitcode, StageBounds, StageEntries,
};
use crate::pipeline::testing::meter;
use crate::pipeline::FunctionDescriptor;
@@ -2474,9 +2612,19 @@ fn a_kernel_past_the_stage_bound_gets_one_answer_through_either_path() {
let iris = iris.profile();
let library = Library::from_air(&bc).expect("library");
let fd = FunctionDescriptor::new(library.function("device_half").expect("the kernel"));
// The serialized stage's bound at `cap`; the compiled one past every module.
let at = |cap| StageBounds {
serialized: cap,
compiled: u64::MAX,
};
let weight = |cap| {
let compiled =
compile_bitcode_bounded(&bc, EntryRef::Name("device_half"), iris, &mut meter(), cap);
let compiled = compile_bitcode_bounded(
&bc,
EntryRef::Name("device_half"),
iris,
&mut meter(),
at(cap),
);
let (_, _, module) = compiled.expect("compiled");
entry_weight(&module, &mut meter()).expect("weight")
};
@@ -2497,7 +2645,7 @@ fn a_kernel_past_the_stage_bound_gets_one_answer_through_either_path() {
let entries = StageEntries::new();
let work = |entries: Option<&StageEntries>| {
let mut m = meter();
let got = answer(compile_stage_bounded(&fd, iris, entries, &mut m, cap));
let got = answer(compile_stage_bounded(&fd, iris, entries, &mut m, at(cap)));
(got, m.work())
};
let (alone, made, found) = (work(None), work(Some(&entries)), work(Some(&entries)));
@@ -2517,7 +2665,7 @@ fn a_kernel_past_the_stage_bound_gets_one_answer_through_either_path() {
for (budget, expected) in [(w, want.clone()), (w - 1, Err(Err(Limit::WorkUnits)))] {
for via in [None, Some(&entries)] {
let mut m = capped(budget);
let got = answer(compile_stage_bounded(&fd, iris, via, &mut m, cap));
let got = answer(compile_stage_bounded(&fd, iris, via, &mut m, at(cap)));
let shared = via.is_some();
assert_eq!(
got, expected,
@@ -2531,7 +2679,7 @@ fn a_kernel_past_the_stage_bound_gets_one_answer_through_either_path() {
let consts = FunctionConstantValues::defaults();
let entry = EntryRef::Name("device_half");
plan_bitcode(&bc, entry, &consts, iris, &LowerInputs::new(), &mut m).expect("planned");
let got = answer(compile_stage_bounded(&fd, iris, None, &mut m, cap));
let got = answer(compile_stage_bounded(&fd, iris, None, &mut m, at(cap)));
assert_eq!(
got,
Err(Err(Limit::WorkUnits)),
@@ -2541,21 +2689,24 @@ fn a_kernel_past_the_stage_bound_gets_one_answer_through_either_path() {
}
/// The owned stage-bound fixture (`validation/fixtures/public/stage_bound/stage_bound_matrix`: 512
/// simdgroup matrix multiply-accumulates beside a lockstep pair in divergent flow) under the stage
/// bound every device has (`COMPILED_STAGE_WEIGHT`). On the Iris Xe, whose subgroup size range
/// simdgroup matrix multiply-accumulates beside a lockstep pair in divergent flow) under the
/// measured stage bounds (`StageBounds::MEASURED`). On the Iris Xe, whose subgroup size range
/// offers the widest mode's pin and which has maximal reconvergence, the kernel emulates its
/// simdgroups, a module past the bound, and is planned again keeping the pin, a module under it.
/// The same description without maximal reconvergence emulates its simdgroups for the lockstep
/// pair, so it has no pin to keep: the kernel is refused (`Feature::StageSize`,
/// `Needs::StageBound`), its symbol naming the emulated module's weight and the bound.
/// simdgroups, a module past the compiled bound, and is planned again keeping the pin, a module
/// under it: through `Device::new`, whose ANV identity names the compiler's memory defect, and
/// through `Device::from_queries`, which bounds every stage. The same description without maximal
/// reconvergence emulates its simdgroups for the lockstep pair, so it has no pin to keep: it is
/// refused, its symbol naming the emulated module's weight and the bound, as `Needs::StageBound`
/// through `Device::from_queries` and as the compiler's memory defect through `Device::new` on
/// ANV; through `Device::new` under a driver that names no stage-size defect (Intel's Windows
/// driver), its emulated module is emitted past the bound.
#[test]
fn the_stage_bound_fixture_keeps_the_pin_or_is_refused() {
use crate::device::profile::{DeviceProfile, DriverWorkaround, StageBound};
use crate::device::{Device, DeviceDescription};
use crate::error::{DiagName, Feature, Needs};
use crate::lower::simd::WIDEST_PIN;
use crate::pipeline::compile::{
compile_bitcode_bounded, compile_bitcode_kept, COMPILED_STAGE_WEIGHT,
};
use crate::pipeline::compile::{compile_bitcode_bounded, compile_bitcode_kept, StageBounds};
use crate::pipeline::testing::meter;
use crate::spirv::roll::entry_weight;
let dir = std::path::Path::new(env!("CARGO_MANIFEST_DIR"))
@@ -2570,28 +2721,38 @@ fn the_stage_bound_fixture_keeps_the_pin_or_is_refused() {
};
let entry = EntryRef::Name("stage_bound_matrix");
let weight = |module: &TypedModule| entry_weight(module, &mut meter()).expect("weight");
let iris = crate::pipeline::testing::description("intel-irisxe-rplp-anv").unwrap();
let iris = Device::new(iris, DevicePolicy::default()).unwrap();
let iris = iris.profile();
assert!(iris.fields().subgroup.maximal_reconvergence);
// Unbounded, the kernel emulates its simdgroups in place of the widest mode, past the bound.
let compiled = compile_bitcode_bounded(&bc, entry, iris, &mut meter(), u64::MAX);
let (_, plan, module) = compiled.expect("emulated");
assert_eq!((plan.simd.1, uses(&plan, WIDEST_PIN)), (Tier::Emulated, 1));
let emulated = weight(&module);
assert!(emulated > COMPILED_STAGE_WEIGHT, "emulated {emulated}");
// Under the bound, as every compile is: planned again keeping the pin, under it.
let bound = StageBounds::MEASURED.compiled;
let unbounded = StageBounds {
serialized: u64::MAX,
compiled: u64::MAX,
};
let inputs = LowerInputs::new();
let compiled = compile_bitcode_kept(&bc, entry, iris, &inputs, &mut meter(), SPIRV_WORDS);
let (_, plan, module) = compiled.expect("planned again");
assert_eq!((plan.simd.1, uses(&plan, WIDEST_PIN)), (Tier::Direct, 0));
assert_eq!(plan.subgroup.size, Some(32));
let pinned = weight(&module);
assert!(pinned <= COMPILED_STAGE_WEIGHT, "pinned {pinned}");
// Without maximal reconvergence: emulated for the lockstep pair, with no pin to keep.
let kept =
|p: &DeviceProfile| compile_bitcode_kept(&bc, entry, p, &inputs, &mut meter(), SPIRV_WORDS);
let path = std::path::Path::new(env!("CARGO_MANIFEST_DIR"))
.join("../metal2vulkan-validation/profiles/intel-irisxe-rplp-anv.json");
let text = std::fs::read_to_string(path).expect("profile");
let desc = DeviceDescription::from_khronos_json(&text, None).expect("description");
let anv = Device::new(desc.clone(), DevicePolicy::default()).unwrap();
let queries = Device::from_queries(desc, DevicePolicy::default()).unwrap();
assert_eq!(queries.profile().stage_bound(), StageBound::Every);
for p in [anv.profile(), queries.profile()] {
assert!(p.fields().subgroup.maximal_reconvergence);
// Unbounded, the kernel emulates its simdgroups in place of the widest mode, past the
// bound.
let compiled = compile_bitcode_bounded(&bc, entry, p, &mut meter(), unbounded);
let (_, plan, module) = compiled.expect("emulated");
assert_eq!((plan.simd.1, uses(&plan, WIDEST_PIN)), (Tier::Emulated, 1));
let emulated = weight(&module);
assert!(emulated > bound, "emulated {emulated}");
// Under the measured bounds: planned again keeping the pin, under the bound.
let (_, plan, module) = kept(p).expect("planned again");
assert_eq!((plan.simd.1, uses(&plan, WIDEST_PIN)), (Tier::Direct, 0));
assert_eq!(plan.subgroup.size, Some(32));
let pinned = weight(&module);
assert!(pinned <= bound, "pinned {pinned}");
}
// Without maximal reconvergence: emulated for the lockstep pair, with no pin to keep.
let cleared = text.replace(
"\"shaderMaximalReconvergence\": true",
"\"shaderMaximalReconvergence\": false",
@@ -2601,22 +2762,36 @@ fn the_stage_bound_fixture_keeps_the_pin_or_is_refused() {
"the description names shaderMaximalReconvergence"
);
let desc = DeviceDescription::from_khronos_json(&cleared, None).expect("description");
let nomr = Device::new(desc, DevicePolicy::default()).unwrap();
let nomr = nomr.profile();
assert!(!nomr.fields().subgroup.maximal_reconvergence);
let compiled = compile_bitcode_bounded(&bc, entry, nomr, &mut meter(), u64::MAX);
let (_, plan, module) = compiled.expect("emulated");
assert_eq!((plan.simd.1, uses(&plan, WIDEST_PIN)), (Tier::Emulated, 0));
let alone = weight(&module);
assert!(alone > COMPILED_STAGE_WEIGHT, "emulated {alone}");
match compile_bitcode_kept(&bc, entry, nomr, &inputs, &mut meter(), SPIRV_WORDS) {
Err(Error::Unsupported(u)) if u.feature == Feature::StageSize => {
let named = format!("entry weight {alone}, past the bound {COMPILED_STAGE_WEIGHT}");
assert_eq!(u.symbol, Some(DiagName::new(named.as_str())), "{u}");
assert_eq!(u.needs, Needs::StageBound);
let anv = Device::new(desc.clone(), DevicePolicy::default()).unwrap();
let queries = Device::from_queries(desc.clone(), DevicePolicy::default()).unwrap();
let mut windows = desc;
windows.driver_id = Some(crate::vk::DriverId::INTEL_PROPRIETARY_WINDOWS);
let windows = Device::new(windows, DevicePolicy::default()).unwrap();
let memory = Needs::DriverDefect(DriverWorkaround::CompilerMemoryGrowsWithStageSize);
let paths = [
(anv.profile(), Some(memory)),
(queries.profile(), Some(Needs::StageBound)),
(windows.profile(), None),
];
for (p, needs) in paths {
assert!(!p.fields().subgroup.maximal_reconvergence);
let compiled = compile_bitcode_bounded(&bc, entry, p, &mut meter(), unbounded);
let (_, plan, module) = compiled.expect("emulated");
assert_eq!((plan.simd.1, uses(&plan, WIDEST_PIN)), (Tier::Emulated, 0));
let alone = weight(&module);
assert!(alone > bound, "emulated {alone}");
match (kept(p), needs) {
(Err(Error::Unsupported(u)), Some(needs)) if u.feature == Feature::StageSize => {
let named = format!("entry weight {alone}, past the bound {bound}");
assert_eq!(u.symbol, Some(DiagName::new(named.as_str())), "{u}");
assert_eq!(u.needs, needs);
}
(Ok((_, plan, module)), None) => {
assert_eq!((plan.simd.1, uses(&plan, WIDEST_PIN)), (Tier::Emulated, 0));
assert_eq!(weight(&module), alone);
}
(got, needs) => panic!("{needs:?}: {:?}", got.map(|_| ())),
}
Err(e) => panic!("{e:?}"),
Ok(_) => panic!("compiled past the bound"),
}
}
@@ -16,8 +16,8 @@
//! twice, and nothing counted it: the SPIR-V, the keys and the artifacts all came out identical,
//! so no golden table, no artifact check and no existing count could see the work.
//!
//! The derivation now happens where the profile is built (`DeviceProfile::of`), which is the only
//! place a profile comes from, and `fingerprint()` is a read.
//! The derivation now happens where the profile is built (`DeviceProfile::bounded`), which is the
//! only place a profile comes from, and `fingerprint()` is a read.
//!
//! # Why this is a count
//!
@@ -14439,6 +14439,7 @@ variant metal2vulkan::device::DriverWorkaround::BothBarycentricFormsRejected Bot
variant metal2vulkan::device::DriverWorkaround::BufferAtomicsUncontained BufferAtomicsUncontained
variant metal2vulkan::device::DriverWorkaround::ClippedCoverageNotMetals ClippedCoverageNotMetals
variant metal2vulkan::device::DriverWorkaround::ClippedTrianglesSplitPixelFragments ClippedTrianglesSplitPixelFragments
variant metal2vulkan::device::DriverWorkaround::CompilerMemoryGrowsWithStageSize CompilerMemoryGrowsWithStageSize
variant metal2vulkan::device::DriverWorkaround::CompositeInsertsWrittenInPlace CompositeInsertsWrittenInPlace
variant metal2vulkan::device::DriverWorkaround::DiscardDropsSimdgroupStores DiscardDropsSimdgroupStores
variant metal2vulkan::device::DriverWorkaround::DontInlineKeepsCalls DontInlineKeepsCalls
@@ -14456,6 +14457,7 @@ variant metal2vulkan::device::DriverWorkaround::OppositeZeroProductsMerged Oppos
variant metal2vulkan::device::DriverWorkaround::PerspectiveReadsExtrapolated PerspectiveReadsExtrapolated
variant metal2vulkan::device::DriverWorkaround::PushReadsLengthenThreadPayload PushReadsLengthenThreadPayload
variant metal2vulkan::device::DriverWorkaround::RegisterAllocatorOverflowsLargeModules RegisterAllocatorOverflowsLargeModules
variant metal2vulkan::device::DriverWorkaround::SerializedStageWrapsLargeModules SerializedStageWrapsLargeModules
variant metal2vulkan::device::DriverWorkaround::TessellatorNotMetals TessellatorNotMetals
variant metal2vulkan::device::DriverWorkaround::UniformBufferPerLaneReadsSerialize UniformBufferPerLaneReadsSerialize
variant metal2vulkan::device::DriverWorkaround::VertexGroupingNotApples VertexGroupingNotApples
Can't render this file because it is too large.
+5 -3
View File
@@ -2119,9 +2119,11 @@ match floor.compile_function(&min_lod, &LoweringInputs::new(), &Budget::standard
- `NotImplemented`: a gap of this version. `NotRepresentable`: no Vulkan mechanism exists.
- `DriverDefect`: a defect the device's driver is measured to have. `RuntimeDriverDefect`: one in a
command the runtime records.
- `StageBound`: a stage that the device's plan writes heavier than the translator hands any
driver (the heaviest measured to compile within host-sized memory); `symbol` names its entry
weight and the bound. A device whose plan writes it lighter compiles it.
- `StageBound`: on a device `Device::from_queries` made, a stage that the device's plan writes
heavier than the translator hands any driver (the heaviest measured to compile within
host-sized memory); `symbol` names its entry weight and the bound. A device whose plan writes it
lighter compiles it. A device `Device::new` made bounds a stage only where its driver is measured
to need it (`DriverDefect`).
- `MetalGpuFamily`: a Metal GPU family the device does not claim, where Metal itself refuses the
input without it.
+26 -22
View File
@@ -821,29 +821,33 @@ driver's. Each is open work.
ANV then writes through a null state inside `vkCmdDraw*` instead of failing the command
buffer. What spare pools keep of such recordings is freed as they go
back (`RECORDED`); what command buffers alive at once record is not bounded.
- **On every device, a stage module heavier than the heaviest measured to compile within
host-sized memory is refused, or keeps the widest mode's pin** (`pipeline/compile/stage_bound.rs`).
ANV's compiler takes memory that grows faster than the stage, inside the process that creates
the pipeline, and far above that its pipeline runtime faults on a stage past 2^20 objects of
its serialized form. A module whose entry weighs more than `COMPILED_STAGE_WEIGHT` (99,109
instructions, every call counted as its callee's body), the heaviest measured to compile there,
is handed to no driver: a kernel that emulated its simdgroups only in place of the widest
mode's pin, where the subgroup size range offers it, is compiled pinned to 32 lanes again, and
every other one is refused (`Feature::StageSize`, `Needs::StageBound`, and as its symbol the
module's entry weight and the bound it passed), where Metal compiles it. The bound is one form
for every device, the slowest compiler's: a device whose compiler would take a heavier stage is
refused it all the same. A kernel whose lockstep pair in
divergent flow makes it emulate its simdgroups where the device lacks maximal reconvergence has
no pin to keep: the owned fixture `stage_bound/stage_bound_matrix` (hundreds of simdgroup
matrix products beside such a pair) is planned again under the bound on the Iris Xe and refused
on that profile without maximal reconvergence. Measured on the Iris Xe of RPL-P (ANV, Mesa
26.2.6), compute modules created cold through `vkCreateComputePipelines` (job m3-max-26147):
entry weights 73,814, 75,886 and 99,109 took 45 s, 47 s and 132 s and peak resident sets of
1.76, 2.24 and 3.65 GiB; a module of entry weight 532,213 passed 16 GiB at 358 s without
finishing, and one of 796,525 passed 20 GiB in under two minutes (job m3-max-26086), each where
it was stopped; a kernel of entry weight 1,603,989 faulted inside `vkCreateComputePipelines`.
- **On ANV, a stage module heavier than the driver is measured to compile is refused, or keeps
the widest mode's pin** (`pipeline/compile/stage_bound.rs`,
`DriverWorkaround::SerializedStageWrapsLargeModules`,
`DriverWorkaround::CompilerMemoryGrowsWithStageSize`). Mesa's common pipeline runtime writes
each stage into a precompiled shader and reads it back before compiling it, naming each of its
objects by a 20-bit index that wraps without a word past 2^20 objects in a release build (Mesa
26.2.6: the driver faults inside `vkCreateComputePipelines`); and below that, the driver's
compiler takes memory that grows faster than the stage, inside the process that creates the
pipeline. A module whose entry weighs more than `COMPILED_STAGE_WEIGHT` (99,109 instructions,
every call counted as its callee's body), the heaviest measured to compile within host-sized
memory, is never handed to the driver: a kernel that emulated its simdgroups only in place of
the widest mode's pin is compiled pinned to 32 lanes again, and every other one is refused
(`Feature::StageSize`, naming the serialized stage's defect past `SERIALIZED_STAGE_WEIGHT`,
786,432, and the compiler's memory below it, and as its symbol the module's entry weight and
the bound it passed), where Metal compiles it. Measured on the Iris Xe
of RPL-P (ANV, Mesa 26.2.6), compute modules created cold through `vkCreateComputePipelines`
(job m3-max-26147): entry weights 73,814, 75,886 and 99,109 took 45 s, 47 s and 132 s and peak
resident sets of 1.76, 2.24 and 3.65 GiB; a module of entry weight 532,213 passed 16 GiB at
358 s without finishing, and one of 796,525, with its heap raw-texture arms dead (the
specialization a plan gives it where no texture its handles can name is held by its raw texels
alone), passed 20 GiB in under two minutes (job m3-max-26086), each where it was stopped.
Weights between 99,109 and 532,213 are unmeasured there. The bound rises when a larger compile
is measured within host-sized memory.
is measured within host-sized memory. The refusal follows what the driver compiles, not the
serialized form alone: a kernel of entry weight 1,603,989 created as a `VK_EXT_shader_object`
compute shader (`vkCreateShadersEXT`), which the driver compiles without that round trip, did
not finish: its peak resident set was 2.0 to 2.1 GiB from 60 s to 360 s and 5.3 GiB at 420 s,
and passed 20 GiB at 435 s, where it was stopped.
- **A rate-mapped pass's work is cut into bounded pieces only between its executed commands'
draws, and between ranges of a draw's indices where the draw is cut so**
+2 -2
View File
@@ -98,7 +98,7 @@ Columns:
| `Int64Atomics` | 64-bit atomics | devices short of a Vulkan feature the site names; devices without buffer device addresses (`addressed_needs`) | `device` | 2: `crates/metal2vulkan/src/lower/access/atomic.rs (select, 2 sites)` | `rare`: 64-bit atomics |
| `ImageAtomics` | Image atomics beyond 32-bit integers | devices without a capability the site computes (`gaps`); every device (no Vulkan mechanism) | `device` | 3: `crates/metal2vulkan-runtime/src/families/formats.rs (atomic_gap, 2 sites)`, `crates/metal2vulkan/src/lower/texture/slot.rs (atomic_format)` | `rare`: texture atomics beyond 32-bit integers |
| `DescriptorCount` | Too many descriptors of one kind in a stage or pipeline | devices short of a device limit the site names; devices without VkLimit::MaxUniformBufferRange | `device` | 3: `crates/metal2vulkan/src/lower/access/mod.rs (accept_placement)`, `crates/metal2vulkan/src/lower/select.rs (finish)` (+1) | `app`: many textures or buffers in one stage on a smaller device |
| `StageSize` | A stage module heavier than the translator hands any driver | devices whose plan writes the stage past the stage bound | `device` | 1: `crates/metal2vulkan/src/pipeline/compile/stage_bound.rs (past_bound)` | `rare`: a kernel heavier than the heaviest stage measured to compile within host-sized memory, as the device's plan writes it |
| `StageSize` | A stage module heavier than the translator hands the device's driver | devices whose plan writes the stage past the stage bound; drivers with a defect | `device` | 2: `crates/metal2vulkan/src/pipeline/compile/stage_bound.rs (refused, 2 sites)` | `rare`: a kernel heavier than the heaviest stage measured to compile within host-sized memory, as the device's plan writes it (from_queries), or too large for a driver measured to corrupt one past its bound or to outgrow host memory below it |
| `BufferRange` | A buffer window beyond the descriptor range limits | devices without a capability the site computes (`needs`); devices without buffer device addresses (`addressed_needs`); every device (no Vulkan mechanism) | `device` | 8: `crates/metal2vulkan-runtime/src/function_table.rs (past_storage_buffer_range)`, `crates/metal2vulkan/src/bind/graphics.rs (patch_binding, 3 sites)` (+4) | `app`: a buffer window past a device's descriptor range |
| `Int64Arithmetic` | 64-bit integer arithmetic | devices without VkFeature::ShaderInt64 | `device` | 2: `crates/metal2vulkan/src/lower/arith/legal.rs (check_scalar)`, `crates/metal2vulkan/src/lower/select.rs (selector_form)` | `rare`: 64-bit integers on a device without shaderInt64 |
| `Float64Arithmetic` | 64-bit float arithmetic | devices without VkFeature::ShaderFloat64 | `device` | 2: `crates/metal2vulkan/src/device/metal.rs (unsupported_features)`, `crates/metal2vulkan/src/lower/arith/legal.rs (check_scalar)` | `rare`: doubles (MSL has none outside Apple's own code) |
@@ -682,7 +682,7 @@ Each refusal's sites, with the function that builds it.
- `feature::Int64Atomics`: `crates/metal2vulkan/src/lower/access/atomic.rs (select, 2 sites)`
- `feature::ImageAtomics`: `crates/metal2vulkan-runtime/src/families/formats.rs (atomic_gap, 2 sites)`; `crates/metal2vulkan/src/lower/texture/slot.rs (atomic_format)`
- `feature::DescriptorCount`: `crates/metal2vulkan/src/lower/access/mod.rs (accept_placement)`; `crates/metal2vulkan/src/lower/select.rs (finish)`; `crates/metal2vulkan/src/pipeline/link.rs (limit_error)`
- `feature::StageSize`: `crates/metal2vulkan/src/pipeline/compile/stage_bound.rs (past_bound)`
- `feature::StageSize`: `crates/metal2vulkan/src/pipeline/compile/stage_bound.rs (refused, 2 sites)`
- `feature::BufferRange`: `crates/metal2vulkan-runtime/src/function_table.rs (past_storage_buffer_range)`; `crates/metal2vulkan/src/bind/graphics.rs (patch_binding, 3 sites)`; `crates/metal2vulkan/src/bind/graphics.rs (rebind_with)`; `crates/metal2vulkan/src/bind/instantiate.rs (bind_buffers)`; `crates/metal2vulkan/src/lower/access/function_table.rs (select)`; `crates/metal2vulkan/src/lower/access/mod.rs (place_slots)`
- `feature::Int64Arithmetic`: `crates/metal2vulkan/src/lower/arith/legal.rs (check_scalar)`; `crates/metal2vulkan/src/lower/select.rs (selector_form)`
- `feature::Float64Arithmetic`: `crates/metal2vulkan/src/device/metal.rs (unsupported_features)`; `crates/metal2vulkan/src/lower/arith/legal.rs (check_scalar)`
+1 -1
View File
@@ -37,7 +37,7 @@ feature CoherentMemory rare coherent(device) accesses
feature Int64Atomics rare 64-bit atomics
feature ImageAtomics rare texture atomics beyond 32-bit integers
feature DescriptorCount app many textures or buffers in one stage on a smaller device
feature StageSize rare a kernel heavier than the heaviest stage measured to compile within host-sized memory, as the device's plan writes it
feature StageSize rare a kernel heavier than the heaviest stage measured to compile within host-sized memory, as the device's plan writes it (from_queries), or too large for a driver measured to corrupt one past its bound or to outgrow host memory below it
feature BufferRange app a buffer window past a device's descriptor range
feature Int64Arithmetic rare 64-bit integers on a device without shaderInt64
feature Float64Arithmetic rare doubles (MSL has none outside Apple's own code)
Can't render this file because it contains an unexpected character in line 17 and column 65.