ffiBackendFallbackOrder function

List<BackendKind> ffiBackendFallbackOrder(
  1. BackendKind? preferredBackend, {
  2. required bool npuAvailable,
})

The backends to try, in order, for a preferredBackend request, the NPU only when npuAvailable.

Implementation

List<BackendKind> ffiBackendFallbackOrder(
  BackendKind? preferredBackend, {
  required bool npuAvailable,
}) => switch (preferredBackend) {
  BackendKind.npu => [
    // Offered only where a dispatch stack exists. Dropping it here is what
    // makes the reported `activeBackend` true on the other four platforms.
    if (npuAvailable) BackendKind.npu,
    BackendKind.gpu,
    BackendKind.cpu,
  ],
  BackendKind.gpu || null => const [BackendKind.gpu, BackendKind.cpu],
  BackendKind.cpu => const [BackendKind.cpu],
};