Skip to content

Voice-to-text dictation app with local (Nvidia Parakeet/Whisper) and cloud models (BYOK). Privacy-first and available cross-platform.

1.9 KB
Raw Blame
import type { CudaWhisperStatus, VulkanWhisperStatus } from "../types/electron";

export type WhisperGpuBackend = "cuda" | "vulkan";

// Which pack the transcription GPU card describes. The pack main reports in use
// comes first: the one it runs or would start with, else an installed pack that
// failed, CUDA first (#1736), so Remove and Retry act on the pack the server
// uses. Otherwise a working pack, CUDA before Vulkan as the resolver prefers it,
// so a working Vulkan setup is never re-prompted to download the CUDA pack. Next
// comes a pack an older release installed that this version can't use (#2424):
// the startup notice names it, so the card offers its re-download even when GPU
// detection no longer sees the GPU (RDP, a VM, a failed nvidia-smi). Last, a
// first-time offer, unless the bundled whisper-server already runs on the GPU
// (a distro GPU build, #2168). Cards below the CUDA build's kernel floor (e.g.
// Maxwell) crash at the first kernel launch, so they are never offered the CUDA
// pack and get the Vulkan pack like AMD/Intel GPUs.
export function pickWhisperGpuBackend(
  cuda: CudaWhisperStatus | null | undefined,
  vulkan: VulkanWhisperStatus | null | undefined
): WhisperGpuBackend | null {
  if (cuda?.inUse) return "cuda";
  if (vulkan?.inUse) return "vulkan";
  const cudaEligible = !!cuda?.gpuInfo.hasNvidiaGpu && !!cuda.gpuInfo.cudaSupported;
  const cudaBelowFloor = !!cuda?.gpuInfo.hasNvidiaGpu && !cuda.gpuInfo.cudaSupported;
  const vulkanAvailable = !!vulkan?.vulkan.available;
  if (cudaEligible && cuda?.downloaded) return "cuda";
  if (vulkanAvailable && vulkan?.downloaded) return "vulkan";
  if (cuda?.needsUpdate && !cudaBelowFloor) return "cuda";
  if (vulkan?.needsUpdate) return "vulkan";
  if (cuda?.bundledGpu || vulkan?.bundledGpu) return null;
  if (cudaEligible) return "cuda";
  if (vulkanAvailable) return "vulkan";
  return null;
}