coremlconfig

package
v0.6.20 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 3, 2026 License: MIT Imports: 2 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package coremlconfig provides compute plan analysis and model configuration for CoreML models.

Load a compute plan from a compiled model bundle to inspect which operations target the ANE, GPU, or CPU:

plan, err := coremlconfig.LoadPlan("model.mlmodelc", coremlconfig.PlanOptions{})
if err != nil {
	log.Fatal(err)
}
for _, op := range plan.Operations() {
	fmt.Printf("%-20s device=%-4s cost=%.3f\n",
		op.Name, op.Device, op.Cost)
}

PlanOptions.ComputeUnits controls the target compute unit selection. Its zero value is ComputeUnitsDefault, which allows every available unit including the ANE; restrict a plan with an explicit value such as ComputeUnitsCPUOnly.

The devices reported by a plan are CoreML's own planning values, not a measurement of execution. A compute-unit selection constrains the planner; it does not establish where an operation ran.

Model Configuration

NewConfig creates an MLModelConfiguration with helpers for compute unit selection and private ANE compiler options.

Index

Constants

View Source
const (
	DeviceMaskCPU          uint64 = 1 << 0
	DeviceMaskGPU          uint64 = 1 << 1
	DeviceMaskNeuralEngine uint64 = 1 << 2
)

DeviceMask bits for E5rtComputeDeviceTypeMask.

Variables

This section is empty.

Functions

This section is empty.

Types

type ComputeDevice

type ComputeDevice int

ComputeDevice represents a target compute device for an operation.

const (
	DeviceUnknown      ComputeDevice = iota
	DeviceCPU                        // CPU execution
	DeviceGPU                        // GPU execution
	DeviceNeuralEngine               // Apple Neural Engine
)

func (ComputeDevice) String

func (d ComputeDevice) String() string

type ComputeUnits

type ComputeUnits int

ComputeUnits selects which compute units a plan load targets.

const (
	ComputeUnitsDefault ComputeUnits = iota
	ComputeUnitsCPUOnly
	ComputeUnitsCPUAndGPU
	ComputeUnitsCPUAndNeuralEngine
	ComputeUnitsAll
)

func (ComputeUnits) String

func (u ComputeUnits) String() string

type Config

type Config struct{}

Config wraps MLModelConfiguration with access to both public and private ANE compiler settings. Only functional on darwin.

func NewConfig

func NewConfig() *Config

NewConfig creates a default model configuration targeting all compute units.

func (*Config) ANECompilerOptions

func (c *Config) ANECompilerOptions() string

ANECompilerOptions returns the current E5rt custom ANE compiler options.

func (*Config) AllowFloat16AccumulationOnGPU

func (c *Config) AllowFloat16AccumulationOnGPU() bool

AllowFloat16AccumulationOnGPU reports whether float16 GPU accumulation is enabled.

func (*Config) AllowsInstrumentation

func (c *Config) AllowsInstrumentation() bool

AllowsInstrumentation reports whether instrumentation is enabled.

func (*Config) Close

func (c *Config) Close() error

Close releases the underlying MLModelConfiguration.

func (*Config) ComputeUnits

func (c *Config) ComputeUnits() int

ComputeUnits returns the current compute unit setting.

func (*Config) DeviceMask

func (c *Config) DeviceMask() uint64

DeviceMask returns the E5rt compute device type mask.

func (*Config) DynamicCallableFunctions

func (c *Config) DynamicCallableFunctions() any

DynamicCallableFunctions returns the private dynamic callable functions dictionary.

func (*Config) ExperimentalMLE5BNNSGraphBackendUsage

func (c *Config) ExperimentalMLE5BNNSGraphBackendUsage() int64

ExperimentalMLE5BNNSGraphBackendUsage returns the experimental BNNS graph backend mode.

func (*Config) ExperimentalMLE5EngineUsage

func (c *Config) ExperimentalMLE5EngineUsage() int64

ExperimentalMLE5EngineUsage returns the experimental private engine usage mode.

func (*Config) ExperimentalMLProgramEncryptedCacheUsage

func (c *Config) ExperimentalMLProgramEncryptedCacheUsage() int64

ExperimentalMLProgramEncryptedCacheUsage returns the experimental encrypted cache mode.

func (*Config) FunctionName

func (c *Config) FunctionName() string

FunctionName returns the selected entry point, empty for the default.

func (*Config) MutableMILWeightURLs

func (c *Config) MutableMILWeightURLs() any

MutableMILWeightURLs returns the mutable MIL weight URL mapping.

func (*Config) NeuralEngineCompilerOptions

func (c *Config) NeuralEngineCompilerOptions() any

NeuralEngineCompilerOptions returns the neural engine compiler options object.

func (*Config) ParentModelName

func (c *Config) ParentModelName() string

ParentModelName returns the configured parent model name.

func (*Config) PredictionConcurrencyHint

func (c *Config) PredictionConcurrencyHint() int64

PredictionConcurrencyHint returns the configured concurrency hint.

func (*Config) PreparesLazily

func (c *Config) PreparesLazily() bool

PreparesLazily returns whether lazy preparation is enabled.

func (*Config) ProfilingOptions

func (c *Config) ProfilingOptions() int64

ProfilingOptions returns the private profiling flags.

func (*Config) Raw

func (c *Config) Raw() any

Raw returns the underlying MLModelConfiguration.

func (*Config) RootModelURL

func (c *Config) RootModelURL() any

RootModelURL returns the configured root model URL.

func (*Config) SerializesMILTextForDebugging

func (c *Config) SerializesMILTextForDebugging() bool

SerializesMILTextForDebugging returns whether MIL text debugging is enabled.

func (*Config) SetANECompilerOptions

func (c *Config) SetANECompilerOptions(_ string)

SetANECompilerOptions sets the E5rt custom ANE compiler options string.

func (*Config) SetAllowFloat16AccumulationOnGPU

func (c *Config) SetAllowFloat16AccumulationOnGPU(_ bool)

SetAllowFloat16AccumulationOnGPU toggles float16 accumulation for GPU execution.

func (*Config) SetAllowsInstrumentation

func (c *Config) SetAllowsInstrumentation(_ bool)

SetAllowsInstrumentation enables private runtime instrumentation.

func (*Config) SetComputeUnits

func (c *Config) SetComputeUnits(_ int)

SetComputeUnits sets which processing units the model may use.

func (*Config) SetDeviceMask

func (c *Config) SetDeviceMask(_ uint64)

SetDeviceMask sets the E5rt compute device type mask.

func (*Config) SetDynamicCallableFunctions

func (c *Config) SetDynamicCallableFunctions(_ any)

SetDynamicCallableFunctions sets the private dynamic callable functions dictionary.

func (*Config) SetExperimentalMLE5BNNSGraphBackendUsage

func (c *Config) SetExperimentalMLE5BNNSGraphBackendUsage(_ int64)

SetExperimentalMLE5BNNSGraphBackendUsage sets the experimental BNNS graph backend mode.

func (*Config) SetExperimentalMLE5EngineUsage

func (c *Config) SetExperimentalMLE5EngineUsage(_ int64)

SetExperimentalMLE5EngineUsage sets the experimental private engine usage mode.

func (*Config) SetExperimentalMLProgramEncryptedCacheUsage

func (c *Config) SetExperimentalMLProgramEncryptedCacheUsage(_ int64)

SetExperimentalMLProgramEncryptedCacheUsage sets the experimental encrypted cache mode.

func (*Config) SetFunctionName

func (c *Config) SetFunctionName(_ string)

SetFunctionName selects which entry point of a multi-function model to load.

func (*Config) SetMutableMILWeightURLs

func (c *Config) SetMutableMILWeightURLs(_ any)

SetMutableMILWeightURLs sets the private mutable MIL weight URL mapping.

func (*Config) SetParentModelName

func (c *Config) SetParentModelName(_ string)

SetParentModelName sets the parent model name for nested-model loads.

func (*Config) SetPredictionConcurrencyHint

func (c *Config) SetPredictionConcurrencyHint(_ int64)

SetPredictionConcurrencyHint sets the model preparation/prediction concurrency hint.

func (*Config) SetPreferredMTLDevice

func (c *Config) SetPreferredMTLDevice(_ any)

SetPreferredMTLDevice routes GPU work to a specific Metal device.

func (*Config) SetPreparesLazily

func (c *Config) SetPreparesLazily(_ bool)

SetPreparesLazily controls whether model preparation is deferred.

func (*Config) SetProfilingOptions

func (c *Config) SetProfilingOptions(_ int64)

SetProfilingOptions sets private profiling flags.

func (*Config) SetRootModelURL

func (c *Config) SetRootModelURL(_ any)

SetRootModelURL sets the root model URL for nested-model loads.

func (*Config) SetSerializesMILTextForDebugging

func (c *Config) SetSerializesMILTextForDebugging(_ bool)

SetSerializesMILTextForDebugging enables MIL text serialization for debugging.

func (*Config) SetUsePrecompiledE5Bundle

func (c *Config) SetUsePrecompiledE5Bundle(_ bool)

SetUsePrecompiledE5Bundle controls whether the E5 precompiled bundle is used.

func (*Config) UsePrecompiledE5Bundle

func (c *Config) UsePrecompiledE5Bundle() bool

UsePrecompiledE5Bundle returns whether the E5 precompiled bundle is used.

type OperationPlan

type OperationPlan struct {
	Name      string
	Device    ComputeDevice
	Cost      float64
	Supported []ComputeDevice
	Path      []string
	MilID     int64
}

OperationPlan describes the planned execution for a single ML Program operation.

type Plan

type Plan struct{}

Plan holds a loaded compute plan and its analyzed operations.

func LoadPlan

func LoadPlan(_ string, _ PlanOptions) (*Plan, error)

LoadPlan loads and analyzes a compute plan from a compiled .mlmodelc bundle.

func (*Plan) ANEFraction

func (p *Plan) ANEFraction() float64

ANEFraction returns the fraction of total estimated cost on the Neural Engine.

func (*Plan) ANEOperations

func (p *Plan) ANEOperations() []OperationPlan

ANEOperations returns only operations targeting the Neural Engine.

func (*Plan) Analyzable

func (p *Plan) Analyzable() bool

Analyzable reports whether the plan's operations could be read.

func (*Plan) CPUFraction

func (p *Plan) CPUFraction() float64

CPUFraction returns the fraction of total estimated cost on the CPU.

func (*Plan) CPUOperations

func (p *Plan) CPUOperations() []OperationPlan

CPUOperations returns only operations targeting the CPU.

func (*Plan) GPUFraction

func (p *Plan) GPUFraction() float64

GPUFraction returns the fraction of total estimated cost on the GPU.

func (*Plan) GPUOperations

func (p *Plan) GPUOperations() []OperationPlan

GPUOperations returns only operations targeting the GPU.

func (*Plan) Operations

func (p *Plan) Operations() []OperationPlan

Operations returns the analyzed operation plans.

func (*Plan) RequestedComputeUnits

func (p *Plan) RequestedComputeUnits() int

RequestedComputeUnits reports the CoreML compute-unit selection applied to this plan.

func (*Plan) SupportsANE

func (p *Plan) SupportsANE() bool

SupportsANE reports whether any operation lists the Neural Engine among its supported devices.

func (*Plan) Unreadable

func (p *Plan) Unreadable() string

Unreadable returns why the plan's operations could not be read.

type PlanOptions

type PlanOptions struct {
	ComputeUnits ComputeUnits
	Timeout      time.Duration
}

PlanOptions configures compute plan loading.

type SupportState

type SupportState int64

SupportState classifies a CoreML validation/support message.

func SupportStateForValidationMessage

func SupportStateForValidationMessage(_ string) SupportState

SupportStateForValidationMessage classifies a CoreML validation message.

type SupportStatePattern

type SupportStatePattern struct {
	Regex string
	State SupportState
}

SupportStatePattern describes a matcher regex and the support state it maps to.

func SupportStatePatterns

func SupportStatePatterns() []SupportStatePattern

SupportStatePatterns returns the framework's current support-state regex patterns.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL