liteRtLmEncoderOnNpu function

bool liteRtLmEncoderOnNpu({
  1. required BundleInfo? bundle,
  2. required bool supportImage,
  3. required bool supportAudio,
  4. BackendKind? preferredVisionBackend,
  5. BackendKind? preferredAudioBackend,
})

Whether an encoder the load turns on runs on the NPU of a bundle that was read, by the rule planLiteRtLmLoad applies (the request, else _encoderDefault). The engine asks it with liteRtLmTextCandidates, so that it looks for the app's NPU stack also when only an encoder needs the NPU. A request the plan then refuses may count: the plan throws before the stack's answer is used. A file that could not be read keeps the old rules.

Implementation

bool liteRtLmEncoderOnNpu({
  required BundleInfo? bundle,
  required bool supportImage,
  required bool supportAudio,
  BackendKind? preferredVisionBackend,
  BackendKind? preferredAudioBackend,
}) {
  if (bundle == null) return false;
  bool onNpu(BundleSection? encoder, BackendKind? requested) =>
      encoder != null &&
      (requested ?? _encoderDefault(encoder)) == BackendKind.npu;
  return (supportImage &&
          onNpu(bundle.visionEncoder, preferredVisionBackend)) ||
      (supportAudio && onNpu(bundle.audioEncoder, preferredAudioBackend));
}