Lowering: a quad-only kernel takes its quads from the subgroup at the size the device gives below 32
The 32 lanes of a Metal simdgroup are needed only by operations that read outside a quad. A kernel whose every cross-lane operation is a quad operation (lower::simd::quad_only: some group operation, each of quad scope, and no simdgroup-scope operation, AGX or matrix multiply-add, or subgroup-scope barrier or fence) now takes the Direct tier with full subgroups and no required size where the kernel stage runs full subgroups of its operations and its narrowest subgroup is below 32 lanes (device::subgroup::quad_free, read from the stage's size range alone). Its requirement (quad_requirement) sets ALLOW_VARYING_SUBGROUP_SIZE where the stage can take a size, and a local size that is a multiple of the stage's largest size (VUID-VkPipelineShaderStageCreateInfo-flags-02758); a threadgroup that is not runs the emulated-simdgroups variant, as a pinned kernel's does. Such a kernel pins nothing, so the widest-pin rule does not weigh it. The pin to 32 stays where 32 is the device's narrowest size. Why it is exact: a quad is four subgroup lanes from a multiple of 4, all in one subgroup (Vulkan 9.27.9), and a compute dispatch runs one subgroup size (9.5.2); the kernel's simdgroup builtins derive from the linear index (SubgroupId * SubgroupSize + SubgroupLocalInvocationId, reading the SubgroupSize builtin where no size is pinned), and its quad operations from SubgroupLocalInvocationId & 3 and & ~3, so every size of 4 lanes or more gives Metal's quads. The guard min >= 4: a quad must be four lanes of one subgroup. A stage whose narrowest subgroup is 1 or 2 lanes could split a quad across subgroups, so such a stage keeps the tier its class takes. A kernel with compute derivatives keeps the tier its class takes: their quads need its two-dimensional local size, which the flattened tiers refuse (ComputeDerivativesWithSimd). Without this exclusion lavapipe's quad kernels with derivatives, which run emulated today, would be refused. Where it applies among the committed profiles: the four Intel ANV profiles (8 to 32: multiple 32, varying), lavapipe and gate-lavapipe-x86_64 (8: multiple 8) and gate-lavapipe (4: multiple 4). Not on NVIDIA (32), RDNA (32 to 64), moltenvk-m3 (its kernel stage takes no size, so it runs the API's 32 alone) or runtime-floor (no quad class). Measured on the Iris Xe (RPL-P, ANV), job m3-max-71702, the lane-only form of this change (E: the base at eda92e1207, Q: this form, E2: the base again; cold plays of the consumer's recording to frame 345): the regression row's kernel took Q in all 21 of its constant sets (15832 dispatches, 100%); per dispatch E 1.6018 ms, Q 0.7314 ms, E2 1.6006 ms (Q/E 45.7%); values E/Q and E/E2 0 differing of 261 buffers; translation 18 s and 0.92 GiB peak against 17 s and 0.92 GiB. The driver's executable statistics (job m3-max-71726): Q compiles at SIMD8 (SIMD16 for one state), 15 to 50% fewer instructions than the emulated form, against about 2800 spills a state when pinned to 32. SEMANTICS_VERSION 2297 (modules change on the profiles above); ARTIFACT_FORMAT_VERSION 595 (SubgroupRequirement gains `varying`). Tests: device::tests::subgroup (the predicate over size ranges, the guard, and the committed profiles it takes), engine_simd (a quad-only kernel's requirement on every committed profile, and the flattened kernels' constraint), engine_quad_ops (the quad fixture's kernels in the Direct tier at 8 on lavapipe and at 8, 16 and 32 on an Intel profile; the emulated variant on lavapipe), engine_dispatch (derivatives beside a quad keep lavapipe's emulated tier), and the runtime's every_device_runs_a_quad_only_kernel_at_the_size_it_gives under a device cfg.
This commit is contained in:
1 parent
3f6f66463b
commit
932ef756df
15 files changed
+571
-37
No files matched your search
+14
-1
@@ -455,7 +455,8 @@ gives the specialization constants' keys, and with the stage's `stage_flags` and
|
||||
declares from it, never one alone: a kernel that declares `DeepThreadgroup` takes its Vulkan
|
||||
workgroup from the `WorkgroupSize` parts only, so one given its `LocalSize` without them runs
|
||||
workgroups of the parts' defaults. A required subgroup size needs `subgroupSizeControl` and the stage in
|
||||
`requiredSubgroupSizeStages`; full subgroups need `computeFullSubgroups`. A pipeline compiled for
|
||||
`requiredSubgroupSizeStages`; full subgroups need `computeFullSubgroups`; a size that varies
|
||||
(`ALLOW_VARYING_SUBGROUP_SIZE`) needs `subgroupSizeControl`. A pipeline compiled for
|
||||
one device pins only what that device can take; `DeviceProfile::check` tells whether another
|
||||
device can.
|
||||
|
||||
@@ -496,6 +497,18 @@ faster; from 40 the pinned compile took 1.6 to 24 times the emulated one and its
|
||||
were the same bits on both tiers. The estimate costs time linear in the body: 5 ms of a 3.4 s
|
||||
release translation of a 162,914-instruction kernel.
|
||||
|
||||
The 32 lanes are needed only by operations that read outside a quad. A kernel whose every
|
||||
cross-lane operation is a quad operation (no simdgroup operation, multiply-add, or simdgroup barrier
|
||||
or fence) pins nothing where the kernel stage runs full subgroups, can take a size, and has a
|
||||
narrowest size below 32 lanes and at least 4 (ANV's 8 to 32, lavapipe's 8): it takes its quads
|
||||
from the subgroup at the size the device gives, with full subgroups,
|
||||
`ALLOW_VARYING_SUBGROUP_SIZE` and a local size that is a multiple of `maxSubgroupSize`. A quad is
|
||||
four lanes of one subgroup at every such size (Vulkan 9.27.9), so its answers do not change, and
|
||||
the widest mode is not weighed for it. The pin to 32 stays where 32 is the device's narrowest size
|
||||
(NVIDIA's 32, RDNA's 32 to 64); a device whose compute stage takes no size runs the API's
|
||||
`subgroupSize`. A kernel with compute derivatives keeps the tier its class takes.
|
||||
|
||||
|
||||
On the emulated tier, a simdgroup operation or barrier in a block whose control flow differs
|
||||
between threads is walked predicated: each thread carries a live flag, the threads that do not run
|
||||
the block take part in its exchanges as inactive lanes, and a loop that holds one votes on its
|
||||
|
||||
Reference in new issue
Block a user