liteRtLmLoadNpuTarget function
NpuStamp?
liteRtLmLoadNpuTarget({
- required String path,
- required BundleInfo? bundle,
- required bool supportImage,
- required bool supportAudio,
- required String abi,
The NPU a load of bundle runs on when it runs on one: the text model's
(its own stamp, else tf_lite_aux's), else that of an encoder the load
turns on. Null for a bundle compiled for no NPU, and for one that was not
read. The engine asks it before the plan, to look up that vendor's stack.
Every section the load turns on that is compiled for an NPU this package
has no dispatch for on abi is refused for its vendor first: the NPU
question has no answer for a vendor this host does not run, and its reason
would name the wrong stack. Sections compiled for two different NPUs are
refused next (LiteRtLmBundleProblem.unsupportedNpu): one load runs one
vendor's dispatch.
Implementation
NpuStamp? liteRtLmLoadNpuTarget({
required String path,
required BundleInfo? bundle,
required bool supportImage,
required bool supportAudio,
required String abi,
}) {
final textTarget = _textNpuTarget(bundle);
final active = <(String?, NpuStamp)>[
if (textTarget != null) (null, textTarget),
if (supportImage && bundle?.visionEncoder?.npuTarget != null)
('vision', bundle!.visionEncoder!.npuTarget!),
if (supportAudio && bundle?.audioEncoder?.npuTarget != null)
('audio', bundle!.audioEncoder!.npuTarget!),
];
for (final (kind, target) in active) {
_checkNpuVendor(path, target, abi, encoder: kind);
}
if (active.isEmpty) return null;
final first = active.first.$2;
final targets = {for (final (_, target) in active) target};
if (targets.length > 1) {
throw LiteRtLmBundleException(
LiteRtLmBundleProblem.unsupportedNpu,
'$path has sections the load turns on compiled for different NPUs '
'(${targets.join(', ')}); litertlm_dart runs one NPU\'s '
'dispatch per load. Load it ${_withoutEncoders(['vision', 'audio'])} to run '
'the text model alone, or install a bundle compiled for one NPU '
'throughout.',
path: path,
);
}
return first;
}