Runtime: an unbound write's barrier after its dispatch, and an arena dispatch kept in the hazard sets
What: two dispatch-barrier ordering fixes, and nothing else. - A dispatch in a serial encoder that writes through an address outside its resources owes its barrier once it is recorded (ComputeCommandEncoder::dispatch, after the record), so the next command pays it after the dispatch. dispatch_hazards owed it before the record, and the dispatch's own record_dispatch paid it, before the dispatch: two barriers before it and none after. - A dispatch over a Private arena puts what it touches back in the hazard sets after its pieces (mark_dispatch, split out of dispatch_hazards): the barriers before its later pieces started the sets again and dropped the marks the dispatch made, so a later dependent dispatch got no barrier. Why: both left a dependent dispatch without the barrier Metal orders it by. The barrier before an unbound-writing dispatch was redundant with its own hazard check (a write outside its resources after anything touched already takes one), so moving it adds none: a dispatch that writes outside its resources takes one barrier before it where it conflicts, and its next command pays the one after it. Re-marking an arena dispatch leaves exactly its own marks after its last piece's barrier, so no barrier is added for commands before it. The runtime README's arena paragraph says so. Verified: the two tests of the commit before fail at it on lavapipe, job m3-max-74991 (compute.rs:760, the unbound source [0,0,0,0,0,1,0,0,0] against the write dependency [1,0,0,0,0,0,0,0,0]; private_arena.rs:288, write dependency 0 against 1). The gate on this commit follows.
This commit is contained in:
1 parent
1af01940f6
commit
c6518caf3b
2 files changed
+30
-17
No files matched your search
@@ -2724,7 +2724,8 @@ while the driver's exit handler waited on a lock, with every runtime thread alre
|
||||
budget holds, its region carrying its first threadgroup, as a count past
|
||||
`maxComputeWorkGroupCount` does. Each piece is ordered after the commands before it by a
|
||||
barrier, but the first in a block the dispatch took new, which nothing reached before; a
|
||||
dispatch of a kernel without an arena takes no such barrier.
|
||||
dispatch of a kernel without an arena takes no such barrier. Those barriers leave the dispatch
|
||||
in the hazard sets, so a later dispatch that depends on it takes its barrier as after any other.
|
||||
`Metrics::private_arena_dispatches`, `private_arena_pieces` and `private_arena_blocks` count
|
||||
them, and `private_arena_allocations` the takes that allocated. An indirect dispatch of such a kernel
|
||||
is `Gap::IndirectPrivateArena`: the GPU reads its counts, so the runtime can neither size its
|
||||
|
||||
@@ -1284,18 +1284,18 @@ impl ComputeCommandEncoder {
|
||||
}
|
||||
}
|
||||
}
|
||||
let accesses = Accesses {
|
||||
slots: &self.slots,
|
||||
textures: &self.textures,
|
||||
declared: &self.declared,
|
||||
indirect: match grid {
|
||||
Grid::Indirect(buffer, _) => {
|
||||
Some(([buffer.id(), buffer.tracked_id()], buffer.span()))
|
||||
}
|
||||
Grid::Direct(_) => None,
|
||||
},
|
||||
};
|
||||
let wrote = {
|
||||
let accesses = Accesses {
|
||||
slots: &self.slots,
|
||||
textures: &self.textures,
|
||||
declared: &self.declared,
|
||||
indirect: match grid {
|
||||
Grid::Indirect(buffer, _) => {
|
||||
Some(([buffer.id(), buffer.tracked_id()], buffer.span()))
|
||||
}
|
||||
Grid::Direct(_) => None,
|
||||
},
|
||||
};
|
||||
let building = recording(&mut self.building);
|
||||
// Heap textures it writes that an alias's write left stale move from undefined first
|
||||
// (`crate::alias`).
|
||||
@@ -1411,6 +1411,11 @@ impl ComputeCommandEncoder {
|
||||
}
|
||||
}
|
||||
}
|
||||
// The barriers before its pieces started the hazard sets again, and its later
|
||||
// pieces come after them: what the dispatch touches goes back in the sets.
|
||||
if arena.is_some() {
|
||||
recording(&mut self.building).mark_dispatch(interface, &accesses);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
(None, Grid::Indirect(buffer, offset)) => {
|
||||
@@ -1428,6 +1433,11 @@ impl ComputeCommandEncoder {
|
||||
}
|
||||
(None, Grid::Direct(_)) => return Ok(()),
|
||||
};
|
||||
if recorded.is_ok() && self.serial && interface.writes_unbound {
|
||||
// A write through an address outside its resources conflicts with everything after
|
||||
// it: the barrier is owed once the dispatch is recorded, to the next command.
|
||||
recording(&mut self.building).owe(Owed::Unbound);
|
||||
}
|
||||
if recorded.is_ok() && module == Module::Emulated {
|
||||
recording(&mut self.building).count(Metric::EmulatedSimdgroupDispatches);
|
||||
}
|
||||
@@ -2112,6 +2122,12 @@ impl Building {
|
||||
self.barrier(command, reach, cause);
|
||||
self.hazards().clear();
|
||||
}
|
||||
Ok(self.mark_dispatch(interface, accesses))
|
||||
}
|
||||
|
||||
/// Adds what a dispatch of a kernel of `interface` touches to the hazard sets. True where it
|
||||
/// writes.
|
||||
fn mark_dispatch(&mut self, interface: &Interface, accesses: &Accesses<'_>) -> bool {
|
||||
let hazards = self.hazards();
|
||||
let mut wrote = false;
|
||||
for ([tracked, own], access) in accesses.each(interface) {
|
||||
@@ -2127,15 +2143,11 @@ impl Building {
|
||||
if interface.writes_unbound {
|
||||
hazards.mark_wild_write();
|
||||
wrote = true;
|
||||
if serial {
|
||||
// Such a write conflicts with everything after it.
|
||||
self.owe(Owed::Unbound);
|
||||
}
|
||||
}
|
||||
if wrote {
|
||||
self.wrote();
|
||||
}
|
||||
Ok(wrote)
|
||||
wrote
|
||||
}
|
||||
|
||||
/// Binds `pipeline` where it is not bound, writes the parameters' ring block and its address,
|
||||
|
||||
Reference in new issue
Block a user