---
title: "withMLTensorComputePolicy(_:_:)"
framework: coreml
role: symbol
role_heading: Function
path: "coreml/withmltensorcomputepolicy(_:_:)"
---

# withMLTensorComputePolicy(_:_:)

Calls the given closure within a task-local context using the specified compute policy to influence what compute device tensor operations are executed on.

## Declaration

```swift
func withMLTensorComputePolicy<R>(_ computePolicy: MLComputePolicy, _ body: () async throws -> R) async rethrows -> R
```

## Parameters

- `computePolicy`: A compute policy that will be set before the closure gets called and restored after the closure returns.
- `body`: A nullary closure. If the closure has a return value, that value is also used as the return value of the withMLTensorComputePolicy(_:_:) function.

## Return Value

Return Value The return value, if any, of the body closure.

## See Also

### Model tensor

- [MLTensor](coreml/mltensor.md)
- [MLTensorScalar](coreml/mltensorscalar.md)
- [MLTensorRangeExpression](coreml/mltensorrangeexpression.md)
- [pointwiseMin(_:_:)](coreml/pointwisemin(_:_:).md)
- [pointwiseMax(_:_:)](coreml/pointwisemax(_:_:).md)
