---
title: "encode(withMTL4CommandEncoder:sourceArrays:destinationArray:)"
framework: metalperformanceshaders
role: symbol
role_heading: Instance Method
path: "metalperformanceshaders/mpsndarraymultiarykernel/encode(withmtl4commandencoder:sourcearrays:destinationarray:)"
---

# encode(withMTL4CommandEncoder:sourceArrays:destinationArray:)

## Declaration

```swift
func encode(withMTL4CommandEncoder encoder: any MTL4ComputeCommandEncoder, sourceArrays: [MPSNDArray], destinationArray destination: MPSNDArray)
```

## Parameters

- `encoder`: The MTL4ComputeCommandEncoder to encode the kernel with.
- `sourceArrays`: The source NDArray instances in a NSArray. Make sure the instances are arranged in the order required by the MPSNDArrayMultiaryKernel subclass.
- `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.
