Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Microsoft Onnxruntime CoreMLFlags

From Leeroopedia


Knowledge Sources Description
Source File java/src/main/java/ai/onnxruntime/providers/CoreMLFlags.java
Repository Microsoft/onnxruntime

Domains

  • Machine Learning Runtime
  • Execution Provider Configuration
  • Apple CoreML

Overview

CoreMLFlags is a public enum providing bitwise flags for configuring the Apple CoreML execution provider. It implements the OrtFlags interface, allowing flags to be aggregated into a single integer bitmask via EnumSet. These flags control CPU-only mode, subgraph enablement, Apple Neural Engine requirements, static shape constraints, MLProgram creation, and GPU usage.

Description

The enum defines six flags:

  • CPU_ONLY (1): Use only CPU, disabling GPU and Apple Neural Engine. Not recommended for production.
  • ENABLE_ON_SUBGRAPH (2): Enables CoreML on subgraphs.
  • ONLY_ENABLE_DEVICE_WITH_ANE (4): Only enable CoreML if the device has an Apple Neural Engine.
  • ONLY_ALLOW_STATIC_INPUT_SHAPES (8): Restrict CoreML to inputs with static shapes (dynamic shapes may reduce performance).
  • CREATE_MLPROGRAM (16): Create an MLProgram instead of a NeuralNetwork model. Requires Core ML 5+.
  • CPU_AND_GPU (32): Exclude the Apple Neural Engine, use CPU and GPU only.

Code Reference

Source Location

// File: java/src/main/java/ai/onnxruntime/providers/CoreMLFlags.java
// Package: ai.onnxruntime.providers

Signature

public enum CoreMLFlags implements OrtFlags {
    CPU_ONLY(1), ENABLE_ON_SUBGRAPH(2), ONLY_ENABLE_DEVICE_WITH_ANE(4),
    ONLY_ALLOW_STATIC_INPUT_SHAPES(8), CREATE_MLPROGRAM(16), CPU_AND_GPU(32);

    public final int value;
    public int getValue();
}

Import

import ai.onnxruntime.providers.CoreMLFlags;

I/O Contract

Inputs

Name Type Description
(enum constant) CoreMLFlags The flag to include in the configuration

Outputs

Name Type Description
getValue() int The native bitmask value for this flag

Usage Examples

import ai.onnxruntime.*;
import ai.onnxruntime.providers.CoreMLFlags;
import java.util.EnumSet;

try (OrtSession.SessionOptions opts = new OrtSession.SessionOptions()) {
    // Add CoreML with MLProgram and static shapes only
    opts.addCoreML(EnumSet.of(
        CoreMLFlags.CREATE_MLPROGRAM,
        CoreMLFlags.ONLY_ALLOW_STATIC_INPUT_SHAPES));

    OrtEnvironment env = OrtEnvironment.getEnvironment();
    try (OrtSession session = env.createSession("/path/to/model.onnx", opts)) {
        // Model will use CoreML MLProgram backend
    }
}

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment