TechnologiesMachine Learning & AI

MetalPerformanceShadersGraph

iOSmacOStvOSwatchOSvisionOS

MetalPerformanceShadersGraph compiles and runs GPU-accelerated compute and neural-network operations through Metal. You construct an MPSGraph, add operations such as 2D and 3D convolutions, pooling, recurrent layers, FFTs, and scaled dot-product attention using descriptors like MPSGraphConvolution2DOpDescriptor, MPSGraphPooling2DOpDescriptor, MPSGraphLSTMDescriptor, MPSGraphFFTDescriptor, and MPSGraphSDPADescriptor, then compile and execute it on an MPSGraphDevice. Compilation and execution are controlled through MPSGraphCompilationDescriptor and MPSGraphExecutionDescriptor, and a compiled graph can be serialized and rerun as an MPSGraphExecutable. The framework runs on iOS, macOS, tvOS, and visionOS.

Essentials 5

The core graph object and the tensors and operations that make up a compute graph.

  • Cl
    MPSGraphiOS 14.0+
    The optimized representation of a compute graph of operations and tensors.
  • Cl
    MPSGraphTensoriOS 14.0+
    The symbolic representation of a compute data type.
  • Cl
    MPSGraphTensorDataiOS 14.0+
    The representation of a compute data type.
  • Cl
    MPSGraphOperationiOS 14.0+
    A symbolic representation of a compute operation.
  • Cl
    MPSGraphVariableOpiOS 14.0+
    The class that defines the parameters for a variable.

Graph Object Model 3

The base classes and type descriptions shared across graph entities.

  • Cl
    MPSGraphObjectiOS 17.0+
    The common base class for all Metal Performance Shaders Graph objects.
  • Cl
    MPSGraphTypeiOS 15.0+
    The base type class for types on tensors.
  • Cl
    MPSGraphShapedTypeiOS 14.0+
    The shaped type class for types on tensors with a shape and data type.

Compilation and Execution 6

Descriptors and objects that compile, serialize, and run a graph on a Metal device.

  • Cl
    MPSGraphCompilationDescriptoriOS 15.0+
    A class that consists of all the levers for compiling graphs.
  • Cl
    MPSGraphExecutionDescriptoriOS 14.0+
    A class that consists of all the levers to synchronize and schedule graph execution.
  • Cl
    MPSGraphExecutableiOS 15.0+
    The compiled representation of a compute graph executable.
  • Cl
    MPSGraphExecutableExecutionDescriptoriOS 15.0+
    A class that consists of all the levers to synchronize and schedule executable execution.
  • Cl
    MPSGraphExecutableSerializationDescriptoriOS 17.0+
    A class that consists of all the levers to serialize an executable.
  • Cl
    MPSGraphDeviceiOS 14.0+
    A class that describes the compute device.

Convolution Operations 5

Descriptors that configure 2D, 3D, and depthwise convolution operations.

  • Cl
    MPSGraphConvolution2DOpDescriptoriOS 14.0+
    A class that describes the properties of a 2D-convolution operator.
  • Cl
    MPSGraphConvolution3DOpDescriptoriOS 16.3+
    A class that describes the properties of a 3D-convolution operator.
  • Cl
    MPSGraphDepthwiseConvolution2DOpDescriptoriOS 14.0+
    A class that defines the parameters for a 2D-depthwise convolution operation.
  • Cl
    MPSGraphDepthwiseConvolution3DOpDescriptoriOS 15.0+
    The class that defines the parameters for a 3D-depthwise convolution operation.
  • Cl
    MPSGraphImToColOpDescriptoriOS 17.0+
    The class that defines the parameters for an image to column or column to image operation.

Pooling Operations 2

Descriptors that configure 2D and 4D pooling operations.

  • Cl
    MPSGraphPooling2DOpDescriptoriOS 14.0+
    The class that defines the parameters for a 2D pooling operation.
  • Cl
    MPSGraphPooling4DOpDescriptoriOS 15.0+
    The class that defines the parameters for a 4D pooling operation.

Recurrent Operations 3

Descriptors that configure recurrent neural-network layers.

  • Cl
    MPSGraphSingleGateRNNDescriptoriOS 15.4+
    The class that defines the parameters for a single gate RNN operation.
  • Cl
    MPSGraphLSTMDescriptoriOS 15.4+
    The class that defines the parameters for a long short-term memory (LSTM) operation.
  • Cl
    MPSGraphGRUDescriptoriOS 16.0+
    The class that defines the parameters for a gated recurrent unit (GRU) operation.

Signal, Attention, and Specialized Operations 5

Descriptors for FFT, scaled dot-product attention, stencil, random, and sparse operations.

  • Cl
    MPSGraphFFTDescriptoriOS 17.0+
    The class that defines the parameters for a fast Fourier transform (FFT) operation.
  • Cl
    MPSGraphSDPADescriptoriOS 26.0+
    A descriptor that configures a scaled dot product attention (SDPA) operation.
  • Cl
    MPSGraphStencilOpDescriptoriOS 15.0+
    The class that defines the parameters for a stencil operation.
  • Cl
    MPSGraphRandomOpDescriptor
    A class that describes the random operation.
  • Cl
    MPSGraphCreateSparseOpDescriptoriOS 15.0+
    A class that describes the properties of a create sparse operation.

Tensor Layout and Padding 3

Enumerations that describe tensor data layouts and padding behavior.

  • En
    MPSGraphTensorNamedDataLayout
    The tensor layout.
  • En
    MPSGraphPaddingStyle
    The tensor padding style.
  • En
    MPSGraphPaddingMode
    The tensor padding mode.

Compilation and Device Options 7

Options and enumerations that control graph optimization, deployment, and device selection.

  • En
    MPSGraphOptions
    The options available to a graph.
  • En
    MPSGraphOptimization
    The optimization levels to trade compilation time for even more runtime performance by running more passes.
  • En
    MPSGraphOptimizationProfile
    The optimization profile used as a heuristic as the graph compiler optimizes the network.
  • En
    MPSGraphExecutionStage
    Execution events that can be used with shared events.
  • En
    MPSGraphDeviceType
    The device type.
  • En
    MPSGraphDeploymentPlatform
    The options available to a graph.
  • St
    MPSGraphReducedPrecisionFastMathiOS 26.0+
    MPSGraph could use these reduced precision paths to deliver faster math, but it is not guaranteed.

Operation Modes and Constants 12

Enumerations that select modes for reductions, resizing, scatter, FFT, random, and other operations.

  • En
    MPSGraphReductionMode
    The reduction mode.
  • En
    MPSGraphFFTScalingMode
    The scaling modes for Fourier transform operations.
  • En
    MPSGraphLossReductionType
    The type of the reduction the graph applies in the loss operations.
  • En
    MPSGraphNonMaximumSuppressionCoordinateMode
    The non-maximum suppression coordinate mode.
  • En
    MPSGraphPoolingReturnIndicesModeiOS 15.3+
    The flattening mode for returned indices with max-pooling.
  • En
    MPSGraphRNNActivation
    The activation modes for RNN operations.
  • En
    MPSGraphRandomDistribution
    The distributions supported by random operations.
  • En
    MPSGraphRandomNormalSamplingMethod
    The sampling method to use when generating values in the normal distribution.
  • En
    MPSGraphResizeMode
    The resize mode to use for resizing.
  • En
    MPSGraphResizeNearestRoundingMode
    The rounding mode to use when using nearest resize mode.
  • En
    MPSGraphScatterMode
    The scatter mode.
  • En
    MPSGraphSparseStorageType
    The sparse storage options in the Metal Performance Shaders Graph framework.

Type Aliases 10

  • Ty
    MPSGraphCompletionHandler
    A notification that appears when graph execution finishes.
  • Ty
    MPSGraphScheduledHandler
    A notification that appears when graph execution schedules.
  • Ty
    MPSGraphCompilationCompletionHandler
    A notification that appears when compilation finishes.
  • Ty
    MPSGraphControlFlowDependencyBlock
    The scope where all the operations defined in this block get control-dependency operations.
  • Ty
    MPSGraphIfThenElseBlock
    A block of operations executed under either the if or else condition.
  • Ty
    MPSGraphWhileBeforeBlock
    The block that executes before the condition evaluates for each iteration.
  • Ty
    MPSGraphWhileAfterBlock
    The block that executes after the condition evaluates for each iteration.
  • Ty
    MPSGraphForLoopBodyBlock
    A block for the body in the for loop.
  • Ty
    MPSGraphExecutableCompletionHandler
    A notification when graph executable execution finishes.
  • Ty
    MPSGraphExecutableScheduledHandler
    A notification when graph executable execution schedules.

Extends 1

IOSurfaceRef
← Machine Learning & AI