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
- type ComputeDevice
- type ComputeUnits
- type Config
- func (c *Config) ANECompilerOptions() string
- func (c *Config) AllowFloat16AccumulationOnGPU() bool
- func (c *Config) AllowsInstrumentation() bool
- func (c *Config) Close() error
- func (c *Config) ComputeUnits() int
- func (c *Config) DeviceMask() uint64
- func (c *Config) DynamicCallableFunctions() any
- func (c *Config) ExperimentalMLE5BNNSGraphBackendUsage() int64
- func (c *Config) ExperimentalMLE5EngineUsage() int64
- func (c *Config) ExperimentalMLProgramEncryptedCacheUsage() int64
- func (c *Config) FunctionName() string
- func (c *Config) MutableMILWeightURLs() any
- func (c *Config) NeuralEngineCompilerOptions() any
- func (c *Config) ParentModelName() string
- func (c *Config) PredictionConcurrencyHint() int64
- func (c *Config) PreparesLazily() bool
- func (c *Config) ProfilingOptions() int64
- func (c *Config) Raw() any
- func (c *Config) RootModelURL() any
- func (c *Config) SerializesMILTextForDebugging() bool
- func (c *Config) SetANECompilerOptions(_ string)
- func (c *Config) SetAllowFloat16AccumulationOnGPU(_ bool)
- func (c *Config) SetAllowsInstrumentation(_ bool)
- func (c *Config) SetComputeUnits(_ int)
- func (c *Config) SetDeviceMask(_ uint64)
- func (c *Config) SetDynamicCallableFunctions(_ any)
- func (c *Config) SetExperimentalMLE5BNNSGraphBackendUsage(_ int64)
- func (c *Config) SetExperimentalMLE5EngineUsage(_ int64)
- func (c *Config) SetExperimentalMLProgramEncryptedCacheUsage(_ int64)
- func (c *Config) SetFunctionName(_ string)
- func (c *Config) SetMutableMILWeightURLs(_ any)
- func (c *Config) SetParentModelName(_ string)
- func (c *Config) SetPredictionConcurrencyHint(_ int64)
- func (c *Config) SetPreferredMTLDevice(_ any)
- func (c *Config) SetPreparesLazily(_ bool)
- func (c *Config) SetProfilingOptions(_ int64)
- func (c *Config) SetRootModelURL(_ any)
- func (c *Config) SetSerializesMILTextForDebugging(_ bool)
- func (c *Config) SetUsePrecompiledE5Bundle(_ bool)
- func (c *Config) UsePrecompiledE5Bundle() bool
- type OperationPlan
- type Plan
- func (p *Plan) ANEFraction() float64
- func (p *Plan) ANEOperations() []OperationPlan
- func (p *Plan) Analyzable() bool
- func (p *Plan) CPUFraction() float64
- func (p *Plan) CPUOperations() []OperationPlan
- func (p *Plan) GPUFraction() float64
- func (p *Plan) GPUOperations() []OperationPlan
- func (p *Plan) Operations() []OperationPlan
- func (p *Plan) RequestedComputeUnits() int
- func (p *Plan) SupportsANE() bool
- func (p *Plan) Unreadable() string
- type PlanOptions
- type SupportState
- type SupportStatePattern
Constants ¶
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 ¶
ANECompilerOptions returns the current E5rt custom ANE compiler options.
func (*Config) AllowFloat16AccumulationOnGPU ¶
AllowFloat16AccumulationOnGPU reports whether float16 GPU accumulation is enabled.
func (*Config) AllowsInstrumentation ¶
AllowsInstrumentation reports whether instrumentation is enabled.
func (*Config) ComputeUnits ¶
ComputeUnits returns the current compute unit setting.
func (*Config) DeviceMask ¶
DeviceMask returns the E5rt compute device type mask.
func (*Config) DynamicCallableFunctions ¶
DynamicCallableFunctions returns the private dynamic callable functions dictionary.
func (*Config) ExperimentalMLE5BNNSGraphBackendUsage ¶
ExperimentalMLE5BNNSGraphBackendUsage returns the experimental BNNS graph backend mode.
func (*Config) ExperimentalMLE5EngineUsage ¶
ExperimentalMLE5EngineUsage returns the experimental private engine usage mode.
func (*Config) ExperimentalMLProgramEncryptedCacheUsage ¶
ExperimentalMLProgramEncryptedCacheUsage returns the experimental encrypted cache mode.
func (*Config) FunctionName ¶
FunctionName returns the selected entry point, empty for the default.
func (*Config) MutableMILWeightURLs ¶
MutableMILWeightURLs returns the mutable MIL weight URL mapping.
func (*Config) NeuralEngineCompilerOptions ¶
NeuralEngineCompilerOptions returns the neural engine compiler options object.
func (*Config) ParentModelName ¶
ParentModelName returns the configured parent model name.
func (*Config) PredictionConcurrencyHint ¶
PredictionConcurrencyHint returns the configured concurrency hint.
func (*Config) PreparesLazily ¶
PreparesLazily returns whether lazy preparation is enabled.
func (*Config) ProfilingOptions ¶
ProfilingOptions returns the private profiling flags.
func (*Config) RootModelURL ¶
RootModelURL returns the configured root model URL.
func (*Config) SerializesMILTextForDebugging ¶
SerializesMILTextForDebugging returns whether MIL text debugging is enabled.
func (*Config) SetANECompilerOptions ¶
SetANECompilerOptions sets the E5rt custom ANE compiler options string.
func (*Config) SetAllowFloat16AccumulationOnGPU ¶
SetAllowFloat16AccumulationOnGPU toggles float16 accumulation for GPU execution.
func (*Config) SetAllowsInstrumentation ¶
SetAllowsInstrumentation enables private runtime instrumentation.
func (*Config) SetComputeUnits ¶
SetComputeUnits sets which processing units the model may use.
func (*Config) SetDeviceMask ¶
SetDeviceMask sets the E5rt compute device type mask.
func (*Config) SetDynamicCallableFunctions ¶
SetDynamicCallableFunctions sets the private dynamic callable functions dictionary.
func (*Config) SetExperimentalMLE5BNNSGraphBackendUsage ¶
SetExperimentalMLE5BNNSGraphBackendUsage sets the experimental BNNS graph backend mode.
func (*Config) SetExperimentalMLE5EngineUsage ¶
SetExperimentalMLE5EngineUsage sets the experimental private engine usage mode.
func (*Config) SetExperimentalMLProgramEncryptedCacheUsage ¶
SetExperimentalMLProgramEncryptedCacheUsage sets the experimental encrypted cache mode.
func (*Config) SetFunctionName ¶
SetFunctionName selects which entry point of a multi-function model to load.
func (*Config) SetMutableMILWeightURLs ¶
SetMutableMILWeightURLs sets the private mutable MIL weight URL mapping.
func (*Config) SetParentModelName ¶
SetParentModelName sets the parent model name for nested-model loads.
func (*Config) SetPredictionConcurrencyHint ¶
SetPredictionConcurrencyHint sets the model preparation/prediction concurrency hint.
func (*Config) SetPreferredMTLDevice ¶
SetPreferredMTLDevice routes GPU work to a specific Metal device.
func (*Config) SetPreparesLazily ¶
SetPreparesLazily controls whether model preparation is deferred.
func (*Config) SetProfilingOptions ¶
SetProfilingOptions sets private profiling flags.
func (*Config) SetRootModelURL ¶
SetRootModelURL sets the root model URL for nested-model loads.
func (*Config) SetSerializesMILTextForDebugging ¶
SetSerializesMILTextForDebugging enables MIL text serialization for debugging.
func (*Config) SetUsePrecompiledE5Bundle ¶
SetUsePrecompiledE5Bundle controls whether the E5 precompiled bundle is used.
func (*Config) UsePrecompiledE5Bundle ¶
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 ¶
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 ¶
Analyzable reports whether the plan's operations could be read.
func (*Plan) CPUFraction ¶
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 ¶
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 ¶
RequestedComputeUnits reports the CoreML compute-unit selection applied to this plan.
func (*Plan) SupportsANE ¶
SupportsANE reports whether any operation lists the Neural Engine among its supported devices.
func (*Plan) Unreadable ¶
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.