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

# 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

### Compute plan

- [MLComputePlan](coreml/mlcomputeplan-1w21n.md)
- [MLModelStructure](coreml/mlmodelstructure-swift.enum.md)
- [MLComputePolicy](coreml/mlcomputepolicy.md)
- [withMLTensorComputePolicy(_:_:)](coreml/withmltensorcomputepolicy(_:_:)-6z33x.md)
