<!--
{
  "availability" : [
    "iOS: 14.0.0 -",
    "iPadOS: 14.0.0 -",
    "macCatalyst: 14.0.0 -",
    "macOS: 11.0.0 -",
    "tvOS: 14.0.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "MetalPerformanceShadersGraph",
  "identifier" : "/documentation/MetalPerformanceShadersGraph/MPSGraph/encode(to:feeds:targetOperations:resultsDictionary:executionDescriptor:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Metal Performance Shaders Graph"
    ],
    "preciseIdentifier" : "c:objc(cs)MPSGraph(im)encodeToCommandBuffer:feeds:targetOperations:resultsDictionary:executionDescriptor:"
  },
  "title" : "encode(to:feeds:targetOperations:resultsDictionary:executionDescriptor:)"
}
-->

# encode(to:feeds:targetOperations:resultsDictionary:executionDescriptor:)

Encodes the graph for the given feeds to returns the target tensor values in the results dictionary provided by the user.

```
func encode(to commandBuffer: MPSCommandBuffer, feeds: [MPSGraphTensor : MPSGraphTensorData], targetOperations: [MPSGraphOperation]?, resultsDictionary: [MPSGraphTensor : MPSGraphTensorData], executionDescriptor: MPSGraphExecutionDescriptor?)
```

## Parameters

`commandBuffer`

commandBuffer passed to execute the graph on, commitAndContinue might be called, please don’t rely on underlying MTLCommandBuffer to remain uncommitted.

`feeds`

Feeds dictionary for the placeholder tensors.

`targetOperations`

Operations to be completed at the end of the run.

`resultsDictionary`

MPSGraphTensors dictionary passed by user, these will be filled with graph output data.

`executionDescriptor`

ExecutionDescriptor to be passed in and used.

## Discussion

It ensures all target operations also executed. This call is asynchronous and will return immediately if a completionHandler is set.

---

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)