cross_class_storage: the NaN notes are those of the stages the runtime ran
What happened on Iris (m3-max-10431, after 3d49ce60ec): the notes helper compiled the cross-class kernel under the format's storage choice and was refused: "RwRead Int over R8Unorm: unsupported: Format; needs NotRepresentable". For a cross-class storage read, the runtime's variant pairs the slot's storage choice with the bound format's class (VariantKey::cross_class, bind::plan::compute's cross_variant). A test-side recompile that reproduces only half of that is not the runtime's variant. So the test stops recompiling. dispatch_noted returns the dispatch's words and the precision notes of the stage the dispatch ran, specialized ones included, as CommandBuffer::executions records them: the variant the runtime compiled for the bound texture. A read leaves its NaN bits to the device where the native or the cross dispatch's stage records one of NAN_NOTES. leaves_nan_bits and driver_deviations::stage_notes_under (3d49ce60ec) are removed. Verified: the Iris run follows. (cherry picked from commit d2d2db125454a800256467fcf949b6d4eeca5150)
This commit is contained in:
1 parent
553a7dfeb3
commit
0b52add1c9
2 files changed
+60
-72
No files matched your search
@@ -33,21 +33,17 @@
|
||||
//! only queries answers the texture's width and height.
|
||||
|
||||
use super::degrade_notices::on_device;
|
||||
use super::driver_deviations::{half_nan, stage_notes_under};
|
||||
use super::driver_deviations::half_nan;
|
||||
use super::extended_range_targets::half_value;
|
||||
use super::{buffer_with, read_buffer, Messages};
|
||||
use crate::air_library::AirLibrary;
|
||||
use metal2vulkan::cache::VariantKey;
|
||||
use metal2vulkan::error::{Error as CompileError, RuntimeInput};
|
||||
use metal2vulkan::metal::format::{sampled_type, storage_image_choice};
|
||||
use metal2vulkan::metal::format::sampled_type;
|
||||
use metal2vulkan::metal::{PixelFormat, TextureUsage};
|
||||
use metal2vulkan::pipeline::{
|
||||
ComputePipelineDescriptor, PrecisionNote, SampledType, Stage, StageSource,
|
||||
};
|
||||
use metal2vulkan::pipeline::{ComputePipelineDescriptor, PrecisionNote, SampledType, StageSource};
|
||||
use metal2vulkan_devtools::llvm_assemble_text;
|
||||
use metal2vulkan_runtime::{
|
||||
CommandBufferStatus, ComputePipelineState, Degradation, Device, PipelineOptions, Region,
|
||||
ResourceOptions, Size, Texture, TextureDescriptor,
|
||||
CommandBufferStatus, ComputePipelineState, Degradation, Device, ExecutedPipeline,
|
||||
PipelineOptions, Region, ResourceOptions, Size, Texture, TextureDescriptor,
|
||||
};
|
||||
use std::collections::{BTreeMap, BTreeSet};
|
||||
use std::time::Duration;
|
||||
@@ -404,6 +400,18 @@ fn dispatch(
|
||||
texture: &Texture,
|
||||
src: &[u8],
|
||||
) -> Result<Vec<[u32; 4]>, String> {
|
||||
dispatch_noted(device, (pipeline, kind), texture, src).map(|(words, _)| words)
|
||||
}
|
||||
|
||||
/// [`dispatch`], and the precision notes of the stage the dispatch ran, specialized ones included:
|
||||
/// the variant the runtime compiled for the bound texture (its format's storage choice, its
|
||||
/// cross-class input), as `CommandBuffer::executions` records it.
|
||||
fn dispatch_noted(
|
||||
device: &Device,
|
||||
(pipeline, kind): (&ComputePipelineState, Kind),
|
||||
texture: &Texture,
|
||||
src: &[u8],
|
||||
) -> Result<(Vec<[u32; 4]>, BTreeSet<PrecisionNote>), String> {
|
||||
let n = kind.threads();
|
||||
let src = buffer_with(device, src).unwrap();
|
||||
let out = buffer_with(device, &vec![0x5a; (n * 16) as usize]).unwrap();
|
||||
@@ -422,15 +430,26 @@ fn dispatch(
|
||||
command_buffer.wait_until_completed_for(WAIT).unwrap();
|
||||
assert_eq!(command_buffer.status(), CommandBufferStatus::Completed);
|
||||
assert_eq!(command_buffer.error(), None);
|
||||
let executions = command_buffer.executions();
|
||||
let [execution] = executions.as_slice() else {
|
||||
panic!("{} executions of one dispatch", executions.len());
|
||||
};
|
||||
let ExecutedPipeline::Compute(executed) = execution.pipeline() else {
|
||||
panic!("a dispatch of a render pipeline");
|
||||
};
|
||||
let notes = (executed.stage.precision_notes.iter().copied())
|
||||
.chain(executed.stage.specialized_notes.iter().map(|s| s.note))
|
||||
.collect();
|
||||
let bytes = read_buffer(&out, 0, n * 16).unwrap();
|
||||
Ok(bytes
|
||||
let words = bytes
|
||||
.as_chunks::<16>()
|
||||
.0
|
||||
.iter()
|
||||
.map(|v| {
|
||||
std::array::from_fn(|k| u32::from_le_bytes(v[4 * k..4 * k + 4].try_into().unwrap()))
|
||||
})
|
||||
.collect())
|
||||
.collect();
|
||||
Ok((words, notes))
|
||||
}
|
||||
|
||||
/// What Metal answers for a `ty` result where the native slot's result is `native`: its words,
|
||||
@@ -460,29 +479,6 @@ const NAN_NOTES: [PrecisionNote; 3] = [
|
||||
PrecisionNote::DeviceNanEncoding,
|
||||
];
|
||||
|
||||
/// Whether the stage of kernel `k` doing `kind` with `ty` texels of a texture of `format` leaves a
|
||||
/// NaN's bits to the device: it records one of [`NAN_NOTES`]. Compiled as the runtime compiles it
|
||||
/// for that texture: with no input where the device reads and writes the slot's format without
|
||||
/// declaring one, and elsewhere with the format's storage choice (`storage_image_choice`), the
|
||||
/// input the function asks for (`NeedsInput(StorageTextureFormat)`; ANV on the Iris Xe, Mesa
|
||||
/// 26.2.6, reads some of [`FORMATS`] only through a declared format).
|
||||
fn leaves_nan_bits(device: &Device, kind: Kind, ty: Ty, format: PixelFormat) -> bool {
|
||||
let bitcode = llvm_assemble_text(&kernel(kind, ty)).unwrap();
|
||||
let mut inputs = VariantKey::new().lowering_inputs(Stage::Kernel);
|
||||
let notes = match stage_notes_under(device, &bitcode, "k", &inputs) {
|
||||
Err(CompileError::NeedsInput(RuntimeInput::StorageTextureFormat { slot })) => {
|
||||
let profile = device.compile_device().profile();
|
||||
let choice = storage_image_choice(format, profile)
|
||||
.unwrap_or_else(|e| panic!("{kind:?} {ty:?} over {format:?}: {e}"));
|
||||
inputs.storage_images.insert(slot, choice);
|
||||
stage_notes_under(device, &bitcode, "k", &inputs)
|
||||
}
|
||||
notes => notes,
|
||||
}
|
||||
.unwrap_or_else(|e| panic!("{kind:?} {ty:?} over {format:?}: {e}"));
|
||||
NAN_NOTES.iter().any(|n| notes.contains(n))
|
||||
}
|
||||
|
||||
/// Whether `got`'s words answer `want`'s for a `ty` result: the same words, but where `nan_bits`
|
||||
/// a 16-bit result's lane (the low and high halves of its first two words) that is a `half` NaN
|
||||
/// in both may hold other bits.
|
||||
@@ -549,7 +545,6 @@ fn neutral_announced(messages: &Messages) -> BTreeSet<Degradation> {
|
||||
fn cross_class_storage_and_buffer_reads_are_the_native_words() {
|
||||
on_device(|device, messages| {
|
||||
let mut pipelines: BTreeMap<(Kind, Ty), ComputePipelineState> = BTreeMap::new();
|
||||
let mut nan_bits: BTreeMap<(Kind, Ty, PixelFormat), bool> = BTreeMap::new();
|
||||
let (mut checked, mut differ, mut skipped, mut nonzero) = (0usize, 0usize, 0usize, 0usize);
|
||||
let mut nans = 0usize;
|
||||
let _ = messages.take_notices();
|
||||
@@ -571,20 +566,22 @@ fn cross_class_storage_and_buffer_reads_are_the_native_words() {
|
||||
};
|
||||
for ty in Ty::ALL.into_iter().filter(|ty| ty.class() != class) {
|
||||
let native = state(ty.native(class));
|
||||
let want = match dispatch(device, (&native, kind), &texture, &[0; 16]) {
|
||||
Ok(w) => w,
|
||||
Err(e) => {
|
||||
println!(
|
||||
"CROSS-CLASS-SKIP {}: {kind:?} of {format:?}: {e}",
|
||||
device.name()
|
||||
);
|
||||
skipped += 1;
|
||||
continue;
|
||||
}
|
||||
};
|
||||
let (want, native_notes) =
|
||||
match dispatch_noted(device, (&native, kind), &texture, &[0; 16]) {
|
||||
Ok(w) => w,
|
||||
Err(e) => {
|
||||
println!(
|
||||
"CROSS-CLASS-SKIP {}: {kind:?} of {format:?}: {e}",
|
||||
device.name()
|
||||
);
|
||||
skipped += 1;
|
||||
continue;
|
||||
}
|
||||
};
|
||||
let cross = state(ty);
|
||||
let got = dispatch(device, (&cross, kind), &texture, &[0; 16])
|
||||
.unwrap_or_else(|e| panic!("{kind:?} {ty:?} over {format:?}: {e}"));
|
||||
let (got, cross_notes) =
|
||||
dispatch_noted(device, (&cross, kind), &texture, &[0; 16])
|
||||
.unwrap_or_else(|e| panic!("{kind:?} {ty:?} over {format:?}: {e}"));
|
||||
checked += got.len();
|
||||
nonzero += got.iter().filter(|w| w[..2] != [0, 0]).count();
|
||||
// A float format's 16-bit integer result is the native `half` result's bits,
|
||||
@@ -593,12 +590,11 @@ fn cross_class_storage_and_buffer_reads_are_the_native_words() {
|
||||
true => native,
|
||||
false => expected(native, t),
|
||||
};
|
||||
let mut leaves = |t: Ty| {
|
||||
*nan_bits
|
||||
.entry((kind, t, format))
|
||||
.or_insert_with(|| leaves_nan_bits(device, kind, t, format))
|
||||
};
|
||||
let bits = leaves(ty) || leaves(ty.native(class));
|
||||
// Whether either stage the runtime ran leaves a NaN's bits to the device: it
|
||||
// records one of [`NAN_NOTES`].
|
||||
let bits = NAN_NOTES
|
||||
.iter()
|
||||
.any(|n| native_notes.contains(n) || cross_notes.contains(n));
|
||||
let unlike = (0..got.len()).filter(|&i| got[i] != expected(want[i], ty));
|
||||
nans += unlike.count();
|
||||
let wrong: Vec<usize> = (0..got.len())
|
||||
|
||||
@@ -130,8 +130,8 @@ use metal2vulkan::error::{Capability, DriverDeviation, Error as CompileError, Fe
|
||||
use metal2vulkan::library::Library;
|
||||
use metal2vulkan::metal::{PixelFormat, PrimitiveType, TextureUsage};
|
||||
use metal2vulkan::pipeline::{
|
||||
ColorAttachmentDescriptor, ComputePipelineDescriptor, FunctionDescriptor, LoweringInputs,
|
||||
PrecisionNote, RenderPipelineDescriptor, Stage, StageSource,
|
||||
ColorAttachmentDescriptor, ComputePipelineDescriptor, FunctionDescriptor, PrecisionNote,
|
||||
RenderPipelineDescriptor, Stage, StageSource,
|
||||
};
|
||||
use metal2vulkan::vk::DriverId;
|
||||
use metal2vulkan::Budget;
|
||||
@@ -685,28 +685,20 @@ fn rounds_under_float_controls(device: &Device, case: &PublicCase) -> bool {
|
||||
/// The precision notes of kernel `entry` of `bitcode`'s stage, as `device`'s compile layer compiles
|
||||
/// its pipeline.
|
||||
pub(super) fn stage_notes(device: &Device, bitcode: &[u8], entry: &str) -> Vec<PrecisionNote> {
|
||||
let inputs = VariantKey::new().lowering_inputs(Stage::Kernel);
|
||||
stage_notes_under(device, bitcode, entry, &inputs).unwrap()
|
||||
}
|
||||
|
||||
/// [`stage_notes`] under the lowering inputs `inputs`, or the compile's error: a function that
|
||||
/// needs an input the inputs do not give (`Error::NeedsInput`) included.
|
||||
pub(super) fn stage_notes_under(
|
||||
device: &Device,
|
||||
bitcode: &[u8],
|
||||
entry: &str,
|
||||
inputs: &LoweringInputs,
|
||||
) -> Result<Vec<PrecisionNote>, CompileError> {
|
||||
let compile = device.compile_device();
|
||||
let budget = Budget::standard();
|
||||
let library = Library::from_air(bitcode).unwrap();
|
||||
let function = FunctionDescriptor::new(library.function(entry).unwrap());
|
||||
let compiled = compile.compile_function(&function, inputs, &budget)?;
|
||||
let inputs = VariantKey::new().lowering_inputs(Stage::Kernel);
|
||||
let compiled = compile
|
||||
.compile_function(&function, &inputs, &budget)
|
||||
.unwrap();
|
||||
let descriptor = ComputePipelineDescriptor::new(StageSource::Compiled(compiled));
|
||||
Ok(compile
|
||||
.compile_compute_pipeline(&descriptor, &budget)?
|
||||
compile
|
||||
.compile_compute_pipeline(&descriptor, &budget)
|
||||
.unwrap()
|
||||
.stage
|
||||
.precision_notes)
|
||||
.precision_notes
|
||||
}
|
||||
|
||||
/// [`stage_notes`] of `case`'s kernel.
|
||||
|
||||
Reference in new issue
Block a user