---
title: "dispatchThreads(_:threadsPerThreadgroup:)"
framework: metal
role: symbol
role_heading: Instance Method
path: "metal/mtlcomputecommandencoder/dispatchthreads(_:threadsperthreadgroup:)"
---

# dispatchThreads(_:threadsPerThreadgroup:)

Encodes a compute command using an arbitrarily sized grid.

## Declaration

```swift
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.

## Mentioned in

Calculating threadgroup and grid sizes

## Discussion

Discussion warning: Use this method only if the device your app is running on supports nonuniform threadgroup sizes. Check for device capabilities with supportsFamily(_:) on the device providing your compute command encoder. See 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:) if your app requires bounds checking or you need extra data allocations to saturate a uniform grid.

## See Also

### Dispatching kernel calls directly

- [dispatchThreadgroups(_:threadsPerThreadgroup:)](metal/mtlcomputecommandencoder/dispatchthreadgroups(_:threadsperthreadgroup:).md)
