---
title: "encode(withMTL4CommandEncoder:sourceArray:destinationArray:)"
framework: metalperformanceshaders
role: symbol
role_heading: Instance Method
path: "metalperformanceshaders/mpsndarrayunarykernel/encode(withmtl4commandencoder:sourcearray:destinationarray:)"
---

# encode(withMTL4CommandEncoder:sourceArray:destinationArray:)

## Declaration

```swift
func encode(withMTL4CommandEncoder encoder: any MTL4ComputeCommandEncoder, sourceArray: MPSNDArray, destinationArray destination: MPSNDArray)
```

## Parameters

- `encoder`: The MTL4ComputeCommandEncoder to encode the kernel with.
- `sourceArray`: The source NDArray.
- `destination`: The destination NDArray.

## Discussion

Discussion Encode a simple inference NDArray kernel. The encoder associates the commands with MTLStageDispatch. Synchronize your workloads against this stage when using this function to prevent race conditions.
