One Logo Pool Ball
CoreML · IOS API REFERENCE

MLComputePlan

class · iOS 17.4+ · SDK 27.1

class MLComputePlan

A class representing the compute plan of a model. The application can use the compute plan to estimate the necessary cost and resources of the model before running the predictions. ``` // Load the compute plan of an ML Program model. let computePlan = try await MLComputePlan.load(contentsOf: modelURL, configuration: configuration) guard case let .program(program) = computePlan.modelStructure else { fatalError("Unexpected model type.") } // Get the main function. guard let mainFunction = program.functions["main"] else { fatalError("Missing main function.") } let operations = mainFunction.block.operations for operation in operations { // Get the compute device usage for the operation. let computeDeviceUsage = computePlan.deviceUsage(for: operation) // Get the estimated cost of executing the operation. let estimatedCost = computePlan.estimatedCost(of: operation) } ```

Members (6)

method · iOS 17.4+

deviceUsage

TypeScript
deviceUsageFor(layer: MLModelStructure_NeuralNetwork_Layer): (MLComputePlan_DeviceUsage) | null
Swift declaration
func deviceUsage(for layer: MLModelStructure.NeuralNetwork.Layer) -> MLComputePlan.DeviceUsage?

Returns the anticipated compute devices that would be used for executing a NeuralNetwork layer. - Parameters: - layer: A NeuralNetwork layer - Returns: The anticipated compute devices that would be used for evaluating the layer or `nil` if the usage couldn't be determined.

method · iOS 17.4+

deviceUsage

TypeScript
deviceUsageFor32006(operation: MLModelStructure_Program_Operation): (MLComputePlan_DeviceUsage) | null
Swift declaration
func deviceUsage(for operation: MLModelStructure.Program.Operation) -> MLComputePlan.DeviceUsage?

Returns the anticipated compute devices that would be used for executing a MLProgram operation. - Parameters: - operation: A MLProgram operation - Returns: The anticipated compute devices that would be used for executing the layer or `nil` if the usage couldn't be determined.

method · iOS 17.4+

estimatedCost

TypeScript
estimatedCost(operation: MLModelStructure_Program_Operation): (MLComputePlan_Cost) | null
Swift declaration
func estimatedCost(of operation: MLModelStructure.Program.Operation) -> MLComputePlan.Cost?

Returns the estimated cost of executing a MLProgram operation. - Parameters: - operation: A MLProgram operation - Returns: The estimated cost of executing the operation.

get · iOS 17.4+

modelStructure

TypeScript
get modelStructure(): MLModelStructure
Swift declaration
final let modelStructure: MLModelStructure

The model structure.

static · iOS 17.4+

load

TypeScript
static loadContentsOfConfiguration(url: string, configuration: MLModelConfiguration): Promise<MLComputePlan>
Swift declaration
static func load(contentsOf url: URL, configuration: MLModelConfiguration) async throws -> MLComputePlan

Construct the compute plan of a model asynchronously given the location of its on-disk representation. - Parameters: - url: The on-disk location of the compiled model (.mlmodelc directory). - configuration: The model configuration.

static · iOS 17.4+

load

TypeScript
static loadAssetConfiguration(asset: MLModelAsset, configuration: MLModelConfiguration): Promise<MLComputePlan>
Swift declaration
static func load(asset: MLModelAsset, configuration: MLModelConfiguration) async throws -> MLComputePlan

Construct the compute plan of a model asynchronously given the model asset. - Parameters: - asset: The model asset. - configuration: The model configuration.

Skipped declarations

No declarations were skipped in this snapshot.

All CoreML types →