Skip to content

feat: optional CUDA GPU acceleration with CPU fallback - #5

Open
Geoffery10 wants to merge 1 commit into
jolehuit:mainfrom
Geoffery10:feat/cuda-gpu-acceleration
Open

Geoffery10 wants to merge 1 commit into
jolehuit:mainfrom
Geoffery10:feat/cuda-gpu-acceleration

Conversation

@Geoffery10

@Geoffery10 Geoffery10 commented Sep 1, 2026

Copy link
Copy Markdown

What's this?

This lets blurcam use an NVIDIA GPU for the AI background segmentation when one is available, while still working exactly as before on CPU (ARM64, Raspberry Pi, etc.).

I tested it on an RTX 5080 and the segmentation now runs on the GPU.

What changed

Two small, backward-compatible tweaks:

  1. pyproject.toml: swapped onnxruntime for onnxruntime-gpu so the CUDA provider is available.
  2. src/linuxcam/segmentation.py: instead of hardcoding CPUExecutionProvider, it now picks CUDAExecutionProvider first and falls back to CPU if CUDA isn't available. It also logs which provider is active so it's easy to confirm.

Why it's safe

  • If you don't have an NVIDIA GPU, nothing changes, it just uses the CPU like before.
  • The provider list is built from what ONNX Runtime actually reports as available, so there's no hard dependency on CUDA being present.

How to verify

After restarting the daemon and opening the camera in your video app, you should see:

Segmentation provider: ['CUDAExecutionProvider', 'CPUExecutionProvider']

One note for NVIDIA users

If your CUDA libraries live in a non-standard location (e.g. /usr/lib), you may need to add export LD_LIBRARY_PATH=/usr/lib to the service environment for ONNX to find them.

Thanks for the great project, hope this helps broaden it to x86_64 + NVIDIA users!


Note on PR #2: I made this change for my own use and submitted it as a PR. Afterward I came across PR #2, which is very similar, it also adds CUDA support. Mine is a simpler implementation, while PR #2 may have more features like model switching, debug/preview modes, profiling, and distro fixes. If PR #2 gets merged, this one can probably be safely closed.

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