Instance Method


Encodes GPU commands to evaluate the custom layer.


optional func encode(commandBuffer: MTLCommandBuffer, inputs: [MTLTexture], outputs: [MTLTexture]) throws



The command buffer that defines the work performed on the GPU.


The array of textures representing the input to be evaluated.


The array of textures representing the outputs to be populated by evaluating the inputs.


Implement this method to use the GPU to evaluate your layer. Fill the command buffer with the necessary commands to evaluate the layer on the GPU. For performance reasons, cache any MTLComputePipelineState objects that you create, to reuse on subsequent calls.

Core ML executes the command buffer, so this method shouldn't commit the buffer. It should only prepare the command buffer and return.

Implementing this method doesn't guarantee that the layer will be evaluated on the GPU; system conditions might constrain computation to the CPU. If this method is not provided, evaluate(inputs:outputs:) will be used.

For more information about using the GPU for general purpose programming, see Compute Processing.

See Also

Evaluating a Layer

func evaluate(inputs: [MLMultiArray], outputs: [MLMultiArray])

Evaluates the custom layer with the given inputs.


Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software