harness: sampling over deep grids, each layer into rows of its own (sample_down_layers)

A fixture kernel for image-only work over a grid more than one deep: sample_down_layers samples
its source into each layer's own rows of a 2D destination, so every thread writes a texel of its
own (sample_down over a deep grid wrote one texel from every layer, which made the deep rows
measure write sharing between layers). MSL in fixtures/public/harness/workloads.metal, compiled
with scripts/regen-air-fixtures --dir harness on the M3 (the TOOLCHAIN is unchanged).

Six rows, sampling_deep_<x>x<y>x<z>, at the grid shapes a recorded stream's image-only kernels ran
deep grids at: 152x152x6, 40x40x90, 64x64x16, 512x512x16, 4x16x252, 1x1x192, in threadgroups
of 8x8x4. Each is checked against its CPU reference: inside the grid the mean of four source
texels, the rest of each layer's rows zero.
This commit is contained in:
Anees Iqbal committed 2026-11-18 06:11:38 -08:00
1 parent b0175c0234
commit d15602eb6a
4 files changed
+883 -704

No files matched your search

+96 -1
View File
@@ -21,7 +21,7 @@ pub struct Workload {
}
/// The authored workloads.
pub const WORKLOADS: [Workload; 25] = [
pub const WORKLOADS: [Workload; 31] = [
Workload {
name: "bandwidth",
plan: bandwidth,
@@ -90,6 +90,30 @@ pub const WORKLOADS: [Workload; 25] = [
name: "constexpr_sampling",
plan: constexpr_sampling,
},
Workload {
name: "sampling_deep_152x152x6",
plan: sampling_deep_152x152x6,
},
Workload {
name: "sampling_deep_40x40x90",
plan: sampling_deep_40x40x90,
},
Workload {
name: "sampling_deep_64x64x16",
plan: sampling_deep_64x64x16,
},
Workload {
name: "sampling_deep_512x512x16",
plan: sampling_deep_512x512x16,
},
Workload {
name: "sampling_deep_4x16x252",
plan: sampling_deep_4x16x252,
},
Workload {
name: "sampling_deep_1x1x192",
plan: sampling_deep_1x1x192,
},
Workload {
name: "wide_bindings",
plan: wide_bindings,
@@ -1207,6 +1231,77 @@ fn constexpr_sampling() -> Plan {
)
}
/// Sampling over a grid more than one deep (`sample_down_layers`, through a runtime sampler,
/// linear, clamped to the edge): a grid `x` by `y` by `z` in threadgroups of 8x8x4, each layer a
/// 2x downsample of a `2t` by `2t` `RGBA16Float` texture into its own `t` by `t` rows of the
/// destination (`t` the larger of `x` and `y` rounded up to whole 16x16 tiles, as the harness's
/// 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 {
let t = x.max(y).next_multiple_of(16);
let side = 2 * t;
let source = sixteenths(18, side);
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 mut plan = sampling_plan(
name,
"sample_down_layers",
(16, Vec::new()),
(16, expected),
Some(Filter::Linear),
);
plan.textures = vec![
TexturePlan::rgba16_float(side, side, 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],
};
plan
}
/// [`sampling_deep`] over a 152x152x6 grid.
fn sampling_deep_152x152x6() -> Plan {
sampling_deep("sampling_deep_152x152x6", [152, 152, 6])
}
/// [`sampling_deep`] over a 40x40x90 grid.
fn sampling_deep_40x40x90() -> Plan {
sampling_deep("sampling_deep_40x40x90", [40, 40, 90])
}
/// [`sampling_deep`] over a 64x64x16 grid.
fn sampling_deep_64x64x16() -> Plan {
sampling_deep("sampling_deep_64x64x16", [64, 64, 16])
}
/// [`sampling_deep`] over a 512x512x16 grid.
fn sampling_deep_512x512x16() -> Plan {
sampling_deep("sampling_deep_512x512x16", [512, 512, 16])
}
/// [`sampling_deep`] over a 4x16x252 grid.
fn sampling_deep_4x16x252() -> Plan {
sampling_deep("sampling_deep_4x16x252", [4, 16, 252])
}
/// [`sampling_deep`] over a 1x1x192 grid.
fn sampling_deep_1x1x192() -> Plan {
sampling_deep("sampling_deep_1x1x192", [1, 1, 192])
}
/// 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
@@ -1,9 +1,10 @@
// Owned fixture: the kernels of the harness's authored workloads (crates/metal2vulkan-harness), each
// standing for a class of compute work: bandwidth-bound, ALU-bound, threadgroup memory with
// barriers, SIMD reductions, 2D image-like indexing, many tiny dispatches in a chain, narrow
// integer arithmetic, sampling through a runtime sampler and through a constexpr one, products
// by a constant zero of either sign, many buffers bound for each of many dispatches, many
// one-wave threadgroups that each do almost nothing, and reads of a table of constants. Written
// integer arithmetic, sampling through a runtime sampler, through a constexpr one and over a grid
// more than one deep, products by a constant zero of either sign, many buffers bound for each of
// many dispatches, many one-wave threadgroups that each do almost nothing, and reads of a table
// of constants. Written
// from scratch for it; `scripts/regen-air-fixtures/regen-air-fixtures.sh --dir harness` compiles
// it. The harness holds a CPU reference of every result. No translator sweep reads this directory.
#include <metal_stdlib>
@@ -181,6 +182,19 @@ kernel void sample_up(texture2d<float, access::sample> source [[texture(0)]],
destination.write(source.sample(filter, (float2(position) + 0.5f) / size), position);
}
// Sampling over a grid more than one deep: a 2x downsample of the source into each layer's own
// rows of the destination, layer `z` at row `z` times the source's height over 2, so every thread
// writes a texel of its own; one texture write a thread.
kernel void sample_down_layers(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 height = source.get_height() / 2;
float2 size = float2(destination.get_width(), height);
float4 texel = source.sample(filter, (float2(position.xy) + 0.5f) / size);
destination.write(texel, uint2(position.x, position.y + position.z * height));
}
// 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)]],