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)
}
```
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.
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.
Returns the estimated cost of executing a MLProgram operation.
- Parameters:
- operation: A MLProgram operation
- Returns: The estimated cost of executing the operation.
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.
Construct the compute plan of a model asynchronously given the model asset.
- Parameters:
- asset: The model asset.
- configuration: The model configuration.