<!--
{
  "availability" : [
    "iOS: 15.0.0 -",
    "iPadOS: 15.0.0 -",
    "macCatalyst: 15.0.0 -",
    "macOS: 12.0.0 -",
    "tvOS: 15.0.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "MetalPerformanceShadersGraph",
  "identifier" : "/documentation/MetalPerformanceShadersGraph/MPSGraph/compile(with:feeds:targetTensors:targetOperations:compilationDescriptor:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Metal Performance Shaders Graph"
    ],
    "preciseIdentifier" : "c:objc(cs)MPSGraph(im)compileWithDevice:feeds:targetTensors:targetOperations:compilationDescriptor:"
  },
  "title" : "compile(with:feeds:targetTensors:targetOperations:compilationDescriptor:)"
}
-->

# compile(with:feeds:targetTensors:targetOperations:compilationDescriptor:)

Compiles the graph for the given feeds to returns the target tensor values, ensuring all target operations would be executed.

```
func compile(with device: MPSGraphDevice?, feeds: [MPSGraphTensor : MPSGraphShapedType], targetTensors: [MPSGraphTensor], targetOperations: [MPSGraphOperation]?, compilationDescriptor: MPSGraphCompilationDescriptor?) -> MPSGraphExecutable
```

## Parameters

`device`

MPSGraph device to optimize for.

`feeds`

Feeds dictionary for the placeholder tensors.

`targetTensors`

Tensors for which the caller wishes MPSGraphTensorData to be returned.

`targetOperations`

Operations to be completed at the end of the run.

`compilationDescriptor`

compilation descriptor to set different compilation parameters.

## Return Value

A valid MPSGraphExecutable object

## Discussion

This call blocks until execution has completed. The compilation descriptor helps specialize the executable returned.

---

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)