<!--
{
  "availability" : [
    "iOS: 11.0.0 -",
    "iPadOS: 11.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.13.0 -",
    "tvOS: 14.5.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Metal",
  "identifier" : "/documentation/Metal/MTLComputeCommandEncoder/dispatchThreads(_:threadsPerThreadgroup:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Metal"
    ],
    "preciseIdentifier" : "c:objc(pl)MTLComputeCommandEncoder(im)dispatchThreads:threadsPerThreadgroup:"
  },
  "title" : "dispatchThreads(_:threadsPerThreadgroup:)"
}
-->

# dispatchThreads(_:threadsPerThreadgroup:)

Encodes a compute command using an arbitrarily sized grid.

```
func dispatchThreads(_ threadsPerGrid: MTLSize, threadsPerThreadgroup: MTLSize)
```

## Parameters

`threadsPerGrid`

The number of threads in the grid, in each dimension.

`threadsPerThreadgroup`

The number of threads in one threadgroup, in each dimension.

## Discussion> Warning:
> Use this method only if the device your app is running on supports nonuniform threadgroup sizes. Check for device capabilities with ``doc://com.apple.metal/documentation/Metal/MTLDevice/supportsFamily(_:)`` on the device providing your compute command encoder. See [Metal Feature Set Tables (PDF)](https://developer.apple.com/metal/Metal-Feature-Set-Tables.pdf) for device support information.

This method encodes a call that uses an arbitrary number of threads in its execution grid. Metal calculates the number of threadgroups needed, providing partial threadgroups if necessary. Prefer this method to [`dispatchThreadgroups(_:threadsPerThreadgroup:)`](/documentation/Metal/MTLComputeCommandEncoder/dispatchThreadgroups(_:threadsPerThreadgroup:)) if your app requires bounds checking or you need extra data allocations to saturate a uniform grid.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)