[Core ML](https://developer.apple.com/machine-learning/core-ml/) is a machine learning framework introduced by Apple. It is designed to seamlessly take advantage of powerful hardware technology including CPU, GPU, and Neural Engine, in the most efficient way in order to maximize performance while minimizing memory and power consumption.
There are several run time options available for the CoreML EP.
To use the CoreML EP run time options, create an unsigned integer representing the options, and set each individual option by using the bitwise OR operator.
`ModelFormat` can be one of the following values: (`NeuralNetwork` by default )
-`MLProgram`: Create an MLProgram format model. Requires Core ML 5 or later (iOS 15+ or macOS 12+).
-`NeuralNetwork`: Create a NeuralNetwork format model. Requires Core ML 3 or later (iOS 13+ or macOS 10.15+).
`MLComputeUnits` can be one of the following values: (`ALL` by default )
-`CPUOnly`: Limit CoreML to running on CPU only.
-`CPUAndNeuralEngine`: Enable CoreML EP for Apple devices with a compatible Apple Neural Engine (ANE).
-`CPUAndGPU`: Enable CoreML EP for Apple devices with a compatible GPU.
-`ALL`: Enable CoreML EP for all compatible Apple devices.
`RequireStaticInputShapes` can be one of the following values: (`0` by default )
Only allow the CoreML EP to take nodes with inputs that have static shapes.
By default the CoreML EP will also allow inputs with dynamic shapes, however performance may be negatively impacted by inputs with dynamic shapes.
-`0`: Allow the CoreML EP to take nodes with inputs that have dynamic shapes.
-`1`: Only allow the CoreML EP to take nodes with inputs that have static shapes.
`EnableOnSubgraphs` can be one of the following values: (`0` by default )
Enable CoreML EP to run on a subgraph in the body of a control flow operator (i.e. a [Loop](https://github.com/onnx/onnx/blob/master/docs/Operators.md#loop), [Scan](https://github.com/onnx/onnx/blob/master/docs/Operators.md#scan) or [If](https://github.com/onnx/onnx/blob/master/docs/Operators.md#if) operator).
-`0`: Disable CoreML EP to run on a subgraph in the body of a control flow operator.
-`1`: Enable CoreML EP to run on a subgraph in the body of a control flow operator.
`SpecializationStrategy`: This feature is available since macOS>=10.15 or iOS>=18.0. This process can affect the model loading time and the prediction latency. Use this option to tailor the specialization strategy for your model. Navigate to [Apple Doc](https://developer.apple.com/documentation/coreml/mloptimizationhints-swift.struct/specializationstrategy-swift.property) for more information. Can be one of the following values: (`Default` by default )
-`Default`:
-`FastPrediction`:
`ProfileComputePlan`:Profile the Core ML MLComputePlan. This logs the hardware each operator is dispatched to and the estimated execution time. Intended for developer usage but provides useful diagnostic information if performance is not as expected. can be one of the following values: (`0` by default )
-`0`: Disable profile.
-`1`: Enable profile.
`AllowLowPrecisionAccumulationOnGPU`: please refer to [Apple Doc](https://developer.apple.com/documentation/coreml/mlmodelconfiguration/allowlowprecisionaccumulationongpu). can be one of the following values: (`0` by default )
-`0`: Use float32 data type to accumulate data.
-`1`: Use low precision data(float16) to accumulate data.
`ModelCacheDirectory`: The path to the directory where the Core ML model cache is stored. CoreML EP will compile the captured subgraph to CoreML format graph and saved to disk.
For the given model, if caching is not enabled, CoreML EP will compile and save to disk every time, which may cost significant time (even minutes) for a complicated model. By providing a cache path the CoreML format model can be reused. (Cache disbled by default).
-`""` : Disable cache. (empty string by default)
-`"/path/to/cache"` : Enable cache. (path to cache directory, will be created if not exist)
The cached information for the model is stored under a model hash in the cache directory. There are three ways the hash may be calculated, in order of preference.
1. Read from the model metadata_props. This provides the user a way to directly control the hash, and is the recommended usage. The cache key should satisfy that, (1) The value must only contain alphanumeric characters. (2) len(value) <64.EPwillre-hashthecache-keytosatisfytheseconditions.
2. Hash of the model url the inference session was created with.
3. Hash of the graph inputs and node outputs if the inference session was created with in memory bytes (i.e. there was no model path).
It is critical that if the model changes either the hash value must change, or you must clear out the previous cache information. e.g. if the model url is being used for the hash (option 2 above) the updated model must be loaded from a different path to change the hash value.
ONNX Runtime does NOT have a mechanism to track model changes and does not delete the cache entries.
Here is an example of how to fill model hash in metadata of model:
```python
import onnx
import hashlib
# You can use any other hash algorithms to ensure the model and its hash-value is a one-one mapping.
Enable CoreML EP to run on a subgraph in the body of a control flow operator (i.e. a [Loop](https://github.com/onnx/onnx/blob/master/docs/Operators.md#loop), [Scan](https://github.com/onnx/onnx/blob/master/docs/Operators.md#scan) or [If](https://github.com/onnx/onnx/blob/master/docs/Operators.md#if) operator).
##### COREML_FLAG_ONLY_ENABLE_DEVICE_WITH_ANE
By default the CoreML EP will be enabled for all compatible Apple devices.
|ai.onnx:Pad|Only constant mode and last two dim padding is supported.<br/>Input pads and constant_value should be constant.<br/>If provided, axes should be constant.|
|ai.onnx:Pow|Only supports cases when both inputs are fp32.|
|ai.onnx:Resize|4D input.<br/>`coordinate_transformation_mode` == `asymmetric`.<br/>`mode` == `linear` or `nearest`.<br/>`nearest_mode` == `floor`.<br/>`exclude_outside` == false<br/>`scales` or `sizes` must be constant.|
|ai.onnx:ConvTranspose|Weight and bias must be constant.<br/>padding_type of SAME_UPPER/SAME_LOWER is not supported.<br/>kernel_shape must have default values.<br/>output_shape is not supported.<br/>output_padding must have default values.|
|ai.onnx:Resize|See [resize_op_builder.cc](https://github.com/microsoft/onnxruntime/blob/main/onnxruntime/core/providers/coreml/builders/impl/resize_op_builder.cc) implementation. There are too many permutations to describe the valid combinations.|