Skip to content

feat(linux): optional GPU (CUDA) Parakeet via sherpa-onnx CUDA prebuilt#85

Closed
nephalemsec wants to merge 2 commits into
mainfrom
linux/gpu-parakeet
Closed

feat(linux): optional GPU (CUDA) Parakeet via sherpa-onnx CUDA prebuilt#85
nephalemsec wants to merge 2 commits into
mainfrom
linux/gpu-parakeet

Conversation

@nephalemsec

Copy link
Copy Markdown
Collaborator

Opt-in GPU Parakeet for NVIDIA, off current main. Default builds are byte-for-byte unchanged (Parakeet stays CPU; macOS stays CoreML).

How it works

Parakeet runs through sherpa-onnx (ONNX Runtime). The crate downloads CPU prebuilts by default, but k2-fsa also ships a CUDA prebuilt (...-cuda-12.x-cudnn-9.x-linux-x64-gpu) containing libonnxruntime_providers_cuda.so. The crate's SHERPA_ONNX_LIB_DIR hook lets us link that instead.

  • Cargo: parakeet-cuda = ["parakeet", "sherpa-onnx/shared"]. sherpa-onnx is now default-features = false; the default parakeet feature still resolves to static CPU (sherpa-onnx-sys defaults to static when no link feature is set), so current builds are unaffected.
  • parakeet.rs: under parakeet-cuda on Linux, request the cuda provider, fall back to CPU if it can't init — mirrors the existing macOS CoreML path.
  • flake: a cuda dev shell fetches the k2-fsa CUDA prebuilt and wires SHERPA_ONNX_LIB_DIR + LD_LIBRARY_PATH (sherpa libs, cuDNN, cudart, cublas, driver).

Use it

nix develop .#cuda
pnpm tauri dev   --no-default-features --features parakeet-cuda,vulkan
# or
pnpm tauri build --no-default-features --features parakeet-cuda,vulkan

What's verified vs. not

  • ✅ Builds and links against the CUDA sherpa-onnx (libonnxruntime_providers_cuda.so); cargo check/build clean; rustfmt clean.
  • ✅ Default CPU build unaffected (cargo check --features parakeet passes).
  • ⚠️ Real GPU engagement must be confirmed on-device with nvidia-smi during a transcription. onnxruntime silently falls back to CPU if cuDNN/driver libs aren't found at runtime — the logs print Attempting CUDA provider... / CUDA provider initialised, but that alone doesn't prove the GPU is doing the work, hence the nvidia-smi check.

This is additive and opt-in, so it won't disturb the default CPU/Metal paths.

Adds an opt-in `parakeet-cuda` feature that runs Parakeet on an NVIDIA GPU
through sherpa-onnx's CUDA execution provider. Default builds are unchanged
(Parakeet stays CPU; macOS stays CoreML).

- Cargo: `parakeet-cuda = ["parakeet", "sherpa-onnx/shared"]`. sherpa-onnx is
  now `default-features = false` so the link mode is explicit — the default
  `parakeet` feature still resolves to static CPU (sherpa-onnx-sys defaults to
  static when no link feature is set), so nothing changes for current builds.
- parakeet.rs: under `parakeet-cuda` on Linux, request the `cuda` provider and
  fall back to CPU if the EP can't initialise (mirrors the macOS CoreML path).
- flake: a `cuda` dev shell fetches the k2-fsa CUDA prebuilt (CUDA 12 / cuDNN 9)
  and wires SHERPA_ONNX_LIB_DIR + LD_LIBRARY_PATH (sherpa libs, cuDNN, cudart,
  cublas, driver) so the CUDA provider loads at build and runtime.

Build/run:
  nix develop .#cuda
  pnpm tauri dev --no-default-features --features parakeet-cuda,vulkan

Verified: links against the CUDA sherpa-onnx (libonnxruntime_providers_cuda.so)
and the default CPU build is unaffected. Real GPU engagement should be confirmed
on-device with `nvidia-smi` during a transcription — onnxruntime silently falls
back to CPU if cuDNN/driver libs aren't found.
The onnxruntime CUDA provider dlopen()s libcublasLt/cublas/curand/cufft/cudart/
cudnn; a single missing one aborts the process (no CPU fallback). The cuda dev
shell only had cudnn/cudart/cublas, so it failed on libcurand.so.10. Add
libcurand, libcufft, libcusparse to LD_LIBRARY_PATH (cublasLt ships with cublas).
@nephalemsec

Copy link
Copy Markdown
Collaborator Author

Superseded by #86 (linux/everything), which contains every commit from this branch plus the rest of the Linux/Wayland work in one consolidated PR. Closing to keep a single branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant