SEMANTICS 2102: the lockstep device pass takes a pointer loaded from thread, threadgroup or payload memory as naming no object
The device pass treated every device pointer loaded from memory as the object named by the canonical spelling of its source address (Root::Loaded). That is the right model for argument buffers, where two loads of one member name one buffer. A pointer loaded from thread, threadgroup or payload memory is different: it is a copy of a pointer that a store put there, and two slots can hold the same buffer's pointer. The pass took two accesses through two such slots never to overlap, and gave them no barrier. A convolution kernel stored through pointers reloaded from separate byval copies. An authored kernel that stores through one slot and reads its neighbour's word through another read a word that another chunk had already overwritten. Such a load now has unknown roots and meets every object, so the pair falls to the address facts like any other pair. Pointers loaded from device or constant memory still name the member's object, as the documented binding-overlap reading has it. docs/FAST-PATHS.md's known gaps record that reading. Verified (ftk2, 3f8dd8821e on69c5ab1de6): - Fail before: the new engine_simd_lockstep::a_buffer_through_two_thread_slots_is_one_object fails at development (27084; the chunked schedule read 8..15 where lockstep reads t ^ 8) and passes at the tip. - Suite at the tip (27141, -p metal2vulkan --all-features): 3566/3567. The one failure is golden_hashes. Against the table blessed at69c5ab1de6, the change moves 19 cells, all engine/generic_pointers.ll | generic_functor, one per profile. That entry reads its buffer through a pointer a functor holds in thread memory, so its accesses now meet the binding's and take the barrier. The table is re-blessed on development. - Authored compile census (27091, M3): differences 0, regressions 0, slowest compile 2663 ms, peak case worker RSS 391 MB. - clippy all-features 0 (27093), m2v_gpu 0 (27095), m2v_cpu_icd 0 (27096); rustdoc -D warnings 0 (27097). SEMANTICS_VERSION 2101 -> 2102.
This commit is contained in:
1 parent
1f8baf9af4
commit
63b71d6e2f
5 files changed
+104
-14
No files matched your search
Vendored
+1
-1
@@ -61,7 +61,7 @@ mod tests;
|
||||
/// unchanged version, and its bless records the version. Independent of the crate's version and of
|
||||
/// [`ARTIFACT_FORMAT_VERSION`]. The commit that bumps it says what changed; this comment keeps no
|
||||
/// history.
|
||||
pub const SEMANTICS_VERSION: u32 = 2101;
|
||||
pub const SEMANTICS_VERSION: u32 = 2102;
|
||||
|
||||
/// The byte-layout version of encoded artifacts (`CompiledFunction::to_bytes` and the
|
||||
/// [`PipelineArtifact`] encodings). Every encoded artifact carries it, and a decode under another
|
||||
|
||||
@@ -138,12 +138,13 @@
|
||||
//! Vulkan orders nothing (NVIDIA's independent thread scheduling and its compiler's reordering of
|
||||
//! accesses it proves apart within one thread included). The analysis runs a second pass over
|
||||
//! device memory ([`facts::Space::Device`]): its objects are the buffer parameters, device globals,
|
||||
//! and the buffer a pointer loaded from memory names (two loads of one argument-buffer member name
|
||||
//! one), its intervals end at the barriers that order device or threadgroup memory, and every
|
||||
//! barrier it inserts carries `mem_device` beside `mem_threadgroup` where the threadgroup pass
|
||||
//! needed one too, so one barrier serves both. Two bindings of one buffer, or a binding and a
|
||||
//! pointer loaded into it, are taken as distinct objects: a pair that meets only through such an
|
||||
//! overlap is not ordered. `constant` memory is never written; texture memory (`mem_texture`) is
|
||||
//! and the buffer a pointer loaded from buffer memory names (two loads of one argument-buffer
|
||||
//! member name one; a pointer loaded from thread, threadgroup or payload memory is a copy and names
|
||||
//! no object of its own, so it meets every object), its intervals end at the barriers that order
|
||||
//! device or threadgroup memory, and every barrier it inserts carries `mem_device` beside
|
||||
//! `mem_threadgroup` where the threadgroup pass needed one too, so one barrier serves both. Two
|
||||
//! bindings of one buffer, or a binding and a pointer loaded from buffer memory into it, are taken
|
||||
//! as distinct objects: a pair that meets only through such an overlap is not ordered. `constant` memory is never written; texture memory (`mem_texture`) is
|
||||
//! not ordered.
|
||||
//!
|
||||
//! **Residue.** Lockstep also fixes which thread's store wins when threads of one simdgroup
|
||||
|
||||
@@ -57,12 +57,14 @@ pub(super) enum Space {
|
||||
}
|
||||
|
||||
/// An object of the memory a pass orders: a global, a buffer parameter, or (in device memory) the
|
||||
/// buffer a pointer loaded from memory names, by the canonical spelling of the address it is
|
||||
/// loaded from, so two loads of one argument-buffer member name one object. Distinct objects are
|
||||
/// taken never to overlap. In threadgroup memory that holds (Metal allocates each object apart);
|
||||
/// in device memory it is the analysis's reading: two bindings of one buffer, or a buffer and a
|
||||
/// pointer loaded from memory into it, may overlap, and a pair reaching one byte through two
|
||||
/// such objects is not ordered.
|
||||
/// buffer a pointer loaded from buffer memory names, by the canonical spelling of the address it
|
||||
/// is loaded from, so two loads of one argument-buffer member name one object. A pointer loaded
|
||||
/// from thread, threadgroup or payload memory names none: it is a copy of a pointer a store put
|
||||
/// there (two slots may hold one buffer's), so its object is unknown and it meets every object.
|
||||
/// Distinct objects are taken never to overlap. In threadgroup memory that holds (Metal allocates
|
||||
/// each object apart); in device memory it is the analysis's reading: two bindings of one buffer,
|
||||
/// or a buffer and a pointer loaded from buffer memory into it, may overlap, and a pair reaching
|
||||
/// one byte through two such objects is not ordered.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord)]
|
||||
pub(super) enum Root {
|
||||
Global(GlobalId),
|
||||
@@ -405,6 +407,22 @@ fn space_ptr(e: &Entry, v: Value, space: Space) -> bool {
|
||||
.is_some_and(|t| matches!(t, Type::Ptr { space: at } if of_space(at)))
|
||||
}
|
||||
|
||||
/// Whether `v` is a pointer into buffer memory (`device` or `constant`): where an argument buffer's
|
||||
/// members live, rather than a copy a store made in thread, threadgroup or payload memory.
|
||||
fn buffer_ptr(e: &Entry, v: Value) -> bool {
|
||||
e.module
|
||||
.value_ty(e.func, v)
|
||||
.and_then(|t| e.module.types().get(t))
|
||||
.is_some_and(|t| {
|
||||
matches!(
|
||||
t,
|
||||
Type::Ptr {
|
||||
space: AddrSpace::Device | AddrSpace::Constant
|
||||
}
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
fn rmw_update(op: AtomicRmwOp) -> Option<Update> {
|
||||
Some(match op {
|
||||
AtomicRmwOp::Add | AtomicRmwOp::Sub => Update::Add,
|
||||
@@ -2594,9 +2612,14 @@ impl<'a> AddrFacts<'a> {
|
||||
let entry = tree_bytes(1, std::mem::size_of::<InstId>());
|
||||
m.charge(entry)?;
|
||||
charged = charged.saturating_add(entry);
|
||||
// A device pointer loaded from memory: the object its source names.
|
||||
// A device pointer loaded from buffer memory: the object its source names. One
|
||||
// loaded from any other memory is a copy of a pointer a store put there, of
|
||||
// an object the load does not name.
|
||||
if let Some(InstKind::Load { ptr: src, .. }) = self.kind(v) {
|
||||
if space_ptr(self.e, v, Space::Device) {
|
||||
if !buffer_ptr(self.e, *src) {
|
||||
break None;
|
||||
}
|
||||
let at = self.canon(*src, 0, m)?;
|
||||
if !out.contains(&Root::Loaded(at)) {
|
||||
if out.len() == MAX_ROOTS {
|
||||
|
||||
@@ -1072,6 +1072,41 @@ done:
|
||||
}
|
||||
"#;
|
||||
|
||||
/// `device_neighbor` with `out` reached through two thread slots that each hold it, written on two
|
||||
/// paths so each load keeps its slot: the store and the read go through pointers loaded from
|
||||
/// different slots, which name one buffer. Lockstep: `out[t] = t ^ 8`.
|
||||
const DEVICE_SLOTS: &str = r#"
|
||||
define void @device_slots(ptr addrspace(1) %0, i32 %1, i32 %sg) #0 {
|
||||
%a = alloca ptr addrspace(1), align 8
|
||||
%b = alloca ptr addrspace(1), align 8
|
||||
store ptr addrspace(1) %0, ptr %a, align 8
|
||||
store ptr addrspace(1) %0, ptr %b, align 8
|
||||
%c = icmp eq i32 %sg, 7
|
||||
br i1 %c, label %again, label %go
|
||||
|
||||
again:
|
||||
store ptr addrspace(1) %0, ptr %a, align 8
|
||||
store ptr addrspace(1) %0, ptr %b, align 8
|
||||
br label %go
|
||||
|
||||
go:
|
||||
%3 = zext i32 %1 to i64
|
||||
%pa0 = load ptr addrspace(1), ptr %a, align 8
|
||||
%4 = getelementptr inbounds i32, ptr addrspace(1) %pa0, i64 %3
|
||||
store i32 %1, ptr addrspace(1) %4, align 4
|
||||
tail call void @air.wg.barrier(i32 1, i32 1)
|
||||
%5 = xor i32 %1, 8
|
||||
%6 = zext i32 %5 to i64
|
||||
%pb = load ptr addrspace(1), ptr %b, align 8
|
||||
%7 = getelementptr inbounds i32, ptr addrspace(1) %pb, i64 %6
|
||||
%8 = load i32, ptr addrspace(1) %7, align 4
|
||||
%pa = load ptr addrspace(1), ptr %a, align 8
|
||||
%9 = getelementptr inbounds i32, ptr addrspace(1) %pa, i64 %3
|
||||
store i32 %8, ptr addrspace(1) %9, align 4
|
||||
ret void
|
||||
}
|
||||
"#;
|
||||
|
||||
/// Each thread stores to its own word of `out`, reads it back and overwrites it, with no barrier:
|
||||
/// no two threads touch one byte, so the device pass inserts nothing. `out[t] = t + 1`.
|
||||
const DEVICE_OWN: &str = r#"
|
||||
@@ -2101,6 +2136,31 @@ fn a_device_memory_conflict_takes_the_barrier_lockstep_stood_for() {
|
||||
assert_eq!(plan.simd.1, Tier::Direct);
|
||||
}
|
||||
|
||||
/// A buffer reached through pointers loaded from two thread slots is one object to the device
|
||||
/// pass: the read of the neighbour's word and the overwrite of its own take the threadgroup barrier
|
||||
/// lockstep stood for, as through the parameter itself. Without it the chunked schedule reads a
|
||||
/// word another chunk already overwrote.
|
||||
#[test]
|
||||
fn a_buffer_through_two_thread_slots_is_one_object() {
|
||||
for profile_name in ["lavapipe", "moltenvk-m3", "vk12-floor"] {
|
||||
let Some(plan) = check(
|
||||
"device_slots",
|
||||
DEVICE_SLOTS,
|
||||
profile_name,
|
||||
32,
|
||||
&CHUNKED,
|
||||
|t| t ^ 8,
|
||||
) else {
|
||||
return;
|
||||
};
|
||||
assert_eq!(
|
||||
uses(&plan, "barrier.lockstep.threadgroup"),
|
||||
1,
|
||||
"{profile_name}"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// Each thread's own device word takes no barrier.
|
||||
#[test]
|
||||
fn a_threads_own_device_word_takes_no_barrier() {
|
||||
|
||||
@@ -2209,3 +2209,9 @@ compares with Metal's.
|
||||
`Depth32Float` and `Stencil8` textures their earlier texels in every tile (an M3 Max under macOS
|
||||
27.0.1, with and without API validation). Which tiles Metal clears follows which draws access
|
||||
the aspect; the runtime's clear follows the draws' rectangles alone.
|
||||
- **The lockstep device pass takes two buffer bindings, and a binding against a pointer loaded
|
||||
from device or constant memory, as distinct objects** (`lower/simd/lockstep/facts.rs`):
|
||||
a program whose simdgroup threads store to the same bytes through two bindings of one buffer, or
|
||||
through a binding and an argument-buffer pointer to it, may see an order other than the one
|
||||
Apple's simdgroup lockstep gives, and no barrier is added for it. A pointer loaded from thread,
|
||||
threadgroup or payload memory names no object of its own and meets every object.
|
||||
Reference in new issue
Block a user