---
title: MPSKernel
framework: metalperformanceshaders
role: symbol
role_heading: Class
path: metalperformanceshaders/mpskernel
---

# MPSKernel

A standard interface for Metal Performance Shaders kernels.

## Declaration

```swift
class MPSKernel
```

## Mentioned in

The MPSKernel Class

## Overview

Overview You should not use the MPSKernel class directly. Instead, a number of subclasses are available that define specific high-performance data-parallel operations. The basic sequence for applying a kernel to an image is as follows: Initialize a kernel corresponding to the operation you wish to perform: Encode the kernel into a command buffer. Encoding the kernel merely encodes the operation into a command buffer. It does not modify any pixels, yet. All kernel state has been copied to the command buffer. Kernels may be reused. If the texture was previously operated on by another command encoder (e.g. a render command encoder), you should call the endEncoding() method on the other encoder before encoding the filter. Some kernels work in place, even in situations where Metal might not normally allow in-place operation on textures. If in-place operation is desired, you may attempt to call the encode(commandBuffer:inPlaceTexture:fallbackCopyAllocator:) method. If the operation cannot be completed in place, then false will be returned and you will have to create a new result texture and try again. To make an in-place image filter reliable, pass a fallback MPSCopyAllocator block to the method to create a new texture to write to in the event that a filter cannot operate in place. You may repeat step 2 to encode more kernels, as desired. 3. After encoding any additional work to the command buffer using other encoders, submit the command buffer to your command queue, using: note: It should be self evident that step 2 may not be thread safe. That is, you can not have multiple threads manipulating the same properties on the same kernel object at the same time and achieve coherent output. In common usage, the kernel properties don’t often need to be changed from their default values, but if you need to apply the same filter to multiple images on multiple threads with cropping/tiling, make additional kernel objects per thread (they are cheap). You can use multiple kernel objects on multiple threads, as long as only one thread is operating on any particular kernel object at a time.

## Topics

### Initializers

- [init(coder:)](metalperformanceshaders/mpskernel/init(coder:).md)
- [init(coder:device:)](metalperformanceshaders/mpskernel/init(coder:device:).md)

### Methods

- [init(device:)](metalperformanceshaders/mpskernel/init(device:).md)
- [copy(with:device:)](metalperformanceshaders/mpskernel/copy(with:device:).md)

### Properties

- [options](metalperformanceshaders/mpskernel/options.md)
- [MPSKernelOptions](metalperformanceshaders/mpskerneloptions.md)
- [device](metalperformanceshaders/mpskernel/device.md)
- [label](metalperformanceshaders/mpskernel/label.md)

## Relationships

### Inherits From

- [NSObject](objectivec/nsobject-swift.class.md)

### Inherited By

- [MPSAccelerationStructure](metalperformanceshaders/mpsaccelerationstructure.md)
- [MPSBinaryImageKernel](metalperformanceshaders/mpsbinaryimagekernel.md)
- [MPSCNNBinaryKernel](metalperformanceshaders/mpscnnbinarykernel.md)
- [MPSCNNKernel](metalperformanceshaders/mpscnnkernel.md)
- [MPSCNNMultiaryKernel](metalperformanceshaders/mpscnnmultiarykernel.md)
- [MPSImageCopyToMatrix](metalperformanceshaders/mpsimagecopytomatrix.md)
- [MPSImageEDLines](metalperformanceshaders/mpsimageedlines.md)
- [MPSImageFindKeypoints](metalperformanceshaders/mpsimagefindkeypoints.md)
- [MPSImageGuidedFilter](metalperformanceshaders/mpsimageguidedfilter.md)
- [MPSImageHistogram](metalperformanceshaders/mpsimagehistogram.md)
- [MPSImageNormalizedHistogram](metalperformanceshaders/mpsimagenormalizedhistogram.md)
- [MPSMatrixBinaryKernel](metalperformanceshaders/mpsmatrixbinarykernel.md)
- [MPSMatrixCopy](metalperformanceshaders/mpsmatrixcopy.md)
- [MPSMatrixCopyToImage](metalperformanceshaders/mpsmatrixcopytoimage.md)
- [MPSMatrixMultiplication](metalperformanceshaders/mpsmatrixmultiplication.md)
- [MPSMatrixRandom](metalperformanceshaders/mpsmatrixrandom.md)
- [MPSMatrixSum](metalperformanceshaders/mpsmatrixsum.md)
- [MPSMatrixUnaryKernel](metalperformanceshaders/mpsmatrixunarykernel.md)
- [MPSNDArrayMultiaryBase](metalperformanceshaders/mpsndarraymultiarybase.md)
- [MPSNNGraph](metalperformanceshaders/mpsnngraph.md)
- [MPSNNOptimizer](metalperformanceshaders/mpsnnoptimizer.md)
- [MPSRNNMatrixInferenceLayer](metalperformanceshaders/mpsrnnmatrixinferencelayer.md)
- [MPSRNNMatrixTrainingLayer](metalperformanceshaders/mpsrnnmatrixtraininglayer.md)
- [MPSRayIntersector](metalperformanceshaders/mpsrayintersector.md)
- [MPSSVGF](metalperformanceshaders/mpssvgf.md)
- [MPSTemporalAA](metalperformanceshaders/mpstemporalaa.md)
- [MPSUnaryImageKernel](metalperformanceshaders/mpsunaryimagekernel.md)

### Conforms To

- [CVarArg](swift/cvararg.md)
- [CustomDebugStringConvertible](swift/customdebugstringconvertible.md)
- [CustomStringConvertible](swift/customstringconvertible.md)
- [Equatable](swift/equatable.md)
- [Hashable](swift/hashable.md)
- [NSCoding](foundation/nscoding.md)
- [NSCopying](foundation/nscopying.md)
- [NSObjectProtocol](objectivec/nsobjectprotocol.md)
- [NSSecureCoding](foundation/nssecurecoding.md)
