create static method
(InterpreterOptions, Delegate?)
create(
- PerformanceConfig? config, {
- bool addMediaPipeCustomOps = false,
Creates InterpreterOptions and an optional Delegate based on config.
Never throws for an unavailable delegate: it warns on stderr and returns options for the next best path. PerformanceMode.gpu on bundled Android returns an XNNPACK delegate, and on Play services no delegate.
Implementation
static (InterpreterOptions, Delegate?) create(
PerformanceConfig? config, {
bool addMediaPipeCustomOps = false,
}) {
final options = InterpreterOptions();
if (addMediaPipeCustomOps) options.addMediaPipeCustomOps();
final effectiveConfig = config ?? const PerformanceConfig();
final threadCount =
effectiveConfig.numThreads?.clamp(0, 8) ??
math.min(4, Platform.numberOfProcessors);
options.threads = threadCount;
if (effectiveConfig.mode == PerformanceMode.disabled) {
return (options, null);
}
if (effectiveConfig.mode == PerformanceMode.auto) {
return _createAutoMode(options, threadCount);
}
if (effectiveConfig.mode == PerformanceMode.xnnpack) {
return _createXnnpack(options, threadCount);
}
if (effectiveConfig.mode == PerformanceMode.gpu) {
return _createGpu(options, threadCount);
}
if (effectiveConfig.mode == PerformanceMode.coreml) {
return _createCoreml(options);
}
return (options, null);
}