---
title: maxTotalThreadsPerThreadgroup
framework: metal
role: symbol
role_heading: Instance Property
path: metal/mtlcomputepipelinedescriptor/maxtotalthreadsperthreadgroup
---

# maxTotalThreadsPerThreadgroup

A property that limits the number of threads you can dispatch in a threadgroup for the compute function.

## Declaration

```swift
var maxTotalThreadsPerThreadgroup: Int { get set }
```

## Discussion

Discussion Metal automatically selects a maximum threadgroup size when you set this value to 0. Your shader can also configure the maximum number of threads per threadgroup with the [[max_total_threads_per_threadgroup]] attribute. See the Metal Shading Language Specification for more information. important: Set this property to the same value as your shader’s [[max_total_threads_per_threadgroup]] attribute when setting both values; different values can create a runtime error. By default, this property’s value is 0, which instructs Metal to calculate the maximum number of threads per threadgroup based on the device’s capabilities and the compute shader’s memory usage. The maxTotalThreadsPerThreadgroup property of an MTLComputePipelineState instance reports the maximum number of threads you can dispatch in a threadgroup for that specific compute shader. Metal may return an error if this value exceeds the available resources for the device, or Metal may lower the thread limit when creating the compute pipeline state, which can reduce runtime performance. tip: Verify whether setting this property improves runtime performance by profiling your app. For more information on performance profiling, see Analyzing the performance of your Metal app.

## See Also

### Configuring the compute execution environment

- [computeFunction](metal/mtlcomputepipelinedescriptor/computefunction.md)
- [threadGroupSizeIsMultipleOfThreadExecutionWidth](metal/mtlcomputepipelinedescriptor/threadgroupsizeismultipleofthreadexecutionwidth.md)
- [maxCallStackDepth](metal/mtlcomputepipelinedescriptor/maxcallstackdepth.md)
