harness: deep rows at other threadgroup sizes, and deep layers that read their own source

Rows for the deep image tile's choice, beside sampling_deep_512x512x16 (threadgroups of 8x8x4):
- sampling_deep_512x512x16_8x8x1, _16x16x1 and _4x4x4: the same work, sample_down_layers over
  512x512x16, in threadgroups of 8x8x1, 16x16x1 and 4x4x4;
- sampling_distinct_64x64x16 and sampling_distinct_512x512x16, in threadgroups of 8x8x4, through
  a new fixture kernel, sample_down_distinct: layer z is a 2x downsample of its own rows of the
  source into its own rows of the destination, so no two layers read the same texels.
  sample_down_layers samples the same source texels on every layer, which gives a tile deep in z
  cache reuse across layers that a kernel reading distinct layers does not get.

Each is checked against its CPU reference. MSL in fixtures/public/harness/workloads.metal,
compiled with scripts/regen-air-fixtures --dir harness on the M3 (job m3-max-47067; the
TOOLCHAIN is unchanged).
This commit is contained in:
Anees Iqbal committed 2026-11-18 09:43:26 -08:00
1 parent a47fc3e69d
commit fbdaa5fb9a
4 files changed
+931 -764

No files matched your search

+111 -20
View File
@@ -21,7 +21,7 @@ pub struct Workload {
}
/// The authored workloads.
pub const WORKLOADS: [Workload; 31] = [
pub const WORKLOADS: [Workload; 36] = [
Workload {
name: "bandwidth",
plan: bandwidth,
@@ -114,6 +114,26 @@ pub const WORKLOADS: [Workload; 31] = [
name: "sampling_deep_1x1x192",
plan: sampling_deep_1x1x192,
},
Workload {
name: "sampling_deep_512x512x16_8x8x1",
plan: sampling_deep_512x512x16_8x8x1,
},
Workload {
name: "sampling_deep_512x512x16_16x16x1",
plan: sampling_deep_512x512x16_16x16x1,
},
Workload {
name: "sampling_deep_512x512x16_4x4x4",
plan: sampling_deep_512x512x16_4x4x4,
},
Workload {
name: "sampling_distinct_64x64x16",
plan: sampling_distinct_64x64x16,
},
Workload {
name: "sampling_distinct_512x512x16",
plan: sampling_distinct_512x512x16,
},
Workload {
name: "wide_bindings",
plan: wide_bindings,
@@ -1106,10 +1126,15 @@ fn texture(index: u32, texture: usize) -> Binding {
/// below 4.
const TEXEL_TOLERANCE: f32 = 1.0 / 256.0;
/// A `side` by `side` texture's starting texels, four channels each, every one a sixteenth of a
/// whole number below 64: exact in `half`.
/// A `side` by `side` texture's starting texels ([`sixteenths_of`]).
fn sixteenths(seed: u64, side: u32) -> Vec<f32> {
let count = 4 * side as usize * side as usize;
sixteenths_of(seed, side, side)
}
/// A `width` by `height` texture's starting texels, four channels each, every one a sixteenth of
/// a whole number below 64: exact in `half`.
fn sixteenths_of(seed: u64, width: u32, height: u32) -> Vec<f32> {
let count = 4 * width as usize * height as usize;
(words(seed, count).into_iter())
.map(|word| (word & 63) as f32 / 16.0)
.collect()
@@ -1238,36 +1263,57 @@ fn constexpr_sampling() -> Plan {
/// texel kernels need), one texture write a thread: each texel in the grid the mean of its four
/// source texels, the rest left zero. The shapes are those a recorded stream's image-only kernels
/// ran deep grids at, thin and ragged ones among them.
fn sampling_deep(name: &str, [x, y, z]: [u32; 3]) -> Plan {
fn sampling_deep(name: &str, threads: [u32; 3]) -> Plan {
deep_sampling(name, threads, [8, 8, 4], false)
}
/// [`sampling_deep`] in threadgroups of `per_group`; with `distinct`, through
/// `sample_down_distinct`, whose layer `z` downsamples its own `2t` by `2t` rows of a `2t` by
/// `2t·z` source, so no two layers read the same texels.
fn deep_sampling(name: &str, [x, y, z]: [u32; 3], per_group: [u32; 3], distinct: bool) -> Plan {
let t = x.max(y).next_multiple_of(16);
let side = 2 * t;
let source = sixteenths(18, side);
let layers = if distinct { z } else { 1 };
let source = sixteenths_of(18, side, side * layers);
let at = |i: u32, j: u32, c: u32| source[(4 * (j * side + i) + c) as usize];
let layer: Vec<f32> = (0..t)
.flat_map(|j| (0..t).flat_map(move |i| (0..4).map(move |c| (i, j, c))))
.map(|(i, j, c)| match i < x && j < y {
true => {
let (i, j) = (2 * i, 2 * j);
(at(i, j, c) + at(i + 1, j, c) + at(i, j + 1, c) + at(i + 1, j + 1, c)) / 4.0
}
false => 0.0,
})
.collect();
let expected = (0..z).flat_map(|_| layer.iter().copied()).collect();
let layer = |k: u32| -> Vec<f32> {
let rows = 2 * t * k.min(layers - 1);
(0..t)
.flat_map(|j| (0..t).flat_map(move |i| (0..4).map(move |c| (i, j, c))))
.map(|(i, j, c)| match i < x && j < y {
true => {
let (i, j) = (2 * i, rows + 2 * j);
(at(i, j, c) + at(i + 1, j, c) + at(i, j + 1, c) + at(i + 1, j + 1, c)) / 4.0
}
false => 0.0,
})
.collect()
};
let expected = match distinct {
true => (0..z).flat_map(layer).collect(),
false => {
let one = layer(0);
(0..z).flat_map(|_| one.iter().copied()).collect()
}
};
let function = match distinct {
true => "sample_down_distinct",
false => "sample_down_layers",
};
let mut plan = sampling_plan(
name,
"sample_down_layers",
function,
(16, Vec::new()),
(16, expected),
Some(Filter::Linear),
);
plan.textures = vec![
TexturePlan::rgba16_float(side, side, Some(source)),
TexturePlan::rgba16_float(side, side * layers, Some(source)),
TexturePlan::rgba16_float(t, t * z, Some(vec![0.0; 4 * (t * t * z) as usize])),
];
plan.dispatches[0].grid = Grid::Threads {
threads: [u64::from(x), u64::from(y), u64::from(z)],
per_group: [8, 8, 4],
per_group: per_group.map(u64::from),
};
plan
}
@@ -1302,6 +1348,51 @@ fn sampling_deep_1x1x192() -> Plan {
sampling_deep("sampling_deep_1x1x192", [1, 1, 192])
}
/// [`sampling_deep`] over a 512x512x16 grid in threadgroups of 8x8x1.
fn sampling_deep_512x512x16_8x8x1() -> Plan {
deep_sampling(
"sampling_deep_512x512x16_8x8x1",
[512, 512, 16],
[8, 8, 1],
false,
)
}
/// [`sampling_deep`] over a 512x512x16 grid in threadgroups of 16x16x1.
fn sampling_deep_512x512x16_16x16x1() -> Plan {
deep_sampling(
"sampling_deep_512x512x16_16x16x1",
[512, 512, 16],
[16, 16, 1],
false,
)
}
/// [`sampling_deep`] over a 512x512x16 grid in threadgroups of 4x4x4.
fn sampling_deep_512x512x16_4x4x4() -> Plan {
deep_sampling(
"sampling_deep_512x512x16_4x4x4",
[512, 512, 16],
[4, 4, 4],
false,
)
}
/// [`deep_sampling`] of distinct layers over a 64x64x16 grid in threadgroups of 8x8x4.
fn sampling_distinct_64x64x16() -> Plan {
deep_sampling("sampling_distinct_64x64x16", [64, 64, 16], [8, 8, 4], true)
}
/// [`deep_sampling`] of distinct layers over a 512x512x16 grid in threadgroups of 8x8x4.
fn sampling_distinct_512x512x16() -> Plan {
deep_sampling(
"sampling_distinct_512x512x16",
[512, 512, 16],
[8, 8, 4],
true,
)
}
/// A texture read out to a buffer: each thread of a 2048x2048 grid, in threadgroups of 16x16,
/// reads its texel of an `RGBA16Float` texture and stores it as a `float4` at `y * 2048 + x`
/// (`texels_out`), 64 MiB stored. The kernel reads its position in the grid and nothing of its
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
@@ -195,6 +195,20 @@ kernel void sample_down_layers(texture2d<float, access::sample> source [[texture
destination.write(texel, uint2(position.x, position.y + position.z * height));
}
// Sampling over a grid more than one deep, each layer from its own source: layer `z` is a 2x
// downsample of its own rows of the source into its own rows of the destination (both `z` times
// a layer's height on, the destination's layers as tall as it is wide), so no two layers read
// the same texels; one texture write a thread.
kernel void sample_down_distinct(texture2d<float, access::sample> source [[texture(0)]],
texture2d<float, access::write> destination [[texture(1)]],
sampler filter [[sampler(0)]],
uint3 position [[thread_position_in_grid]]) {
uint side = destination.get_width();
float2 size = float2(side, destination.get_height());
uint2 at = uint2(position.x, position.y + position.z * side);
destination.write(source.sample(filter, (float2(at) + 0.5f) / size), at);
}
// Many buffers bound for one kernel: each thread folds one word of each of 23 inputs into the
// 24th, so a dispatch reads 24 buffer addresses, and many small dispatches each bind all 24.
kernel void wide_bindings(device const uint *b0 [[buffer(0)]],