Skip to content

Commit b924848

Browse files
committed
GPU Metal: bound the threadgroup size when creating pipelines
Pass the tuned thread count as maxTotalThreadsPerThreadgroup, the Metal equivalent of __launch_bounds__. Without it the register allocation can leave room for fewer threads than the tuning table assumes, and the launch was clamped: on an M1 Max (applegpu_g13s) the two TRD tracker kernels got 384 instead of 512, and the TPC compression gather kernel 832 instead of 1024, which breaks its block-wide scans.
1 parent edc3fc1 commit b924848

1 file changed

Lines changed: 11 additions & 4 deletions

File tree

‎GPU/GPUTracking/Base/metal/GPUReconstructionMetalKernels.mm‎

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,17 +64,24 @@
6464
return 1;
6565
}
6666

67+
// The kernel sizes its threadgroup memory from the tuning table at compile
68+
// time, so a launch must not exceed what it was built for either way.
69+
const uint32_t tunedThreads = this->template getKernelProperties<T, I>().nThreads;
70+
71+
// Like __launch_bounds__: without it the register allocation may leave room
72+
// for fewer threads than the kernel is tuned for.
73+
MTLComputePipelineDescriptor* desc = [MTLComputePipelineDescriptor new];
74+
desc.computeFunction = krnl;
75+
desc.maxTotalThreadsPerThreadgroup = tunedThreads;
6776
NSError* error = nil;
68-
id<MTLComputePipelineState> pso = [mInternals->device newComputePipelineStateWithFunction:krnl error:&error];
77+
id<MTLComputePipelineState> pso = [mInternals->device newComputePipelineStateWithDescriptor:desc options:MTLPipelineOptionNone reflection:nil error:&error];
78+
[desc release];
6979
if (pso == nil) {
7080
NSLog(@"%@", error);
7181
GPUError("Error creating Metal pipeline state: %s", [kname cStringUsingEncoding:NSUTF8StringEncoding]);
7282
return 1;
7383
}
7484

75-
// The kernel sizes its threadgroup memory from the tuning table at compile
76-
// time, so a launch must not exceed what it was built for either way.
77-
const uint32_t tunedThreads = this->template getKernelProperties<T, I>().nThreads;
7885
if (tunedThreads > pso.maxTotalThreadsPerThreadgroup) {
7986
// Fewer threads than the kernel was built for: safe for the shared arrays,
8087
// but the scan and compaction kernels assume every slot has an owner.

0 commit comments

Comments
 (0)