feat: optional CUDA GPU acceleration with CPU fallback - #5
Open
Geoffery10 wants to merge 1 commit into
Open
Geoffery10 wants to merge 1 commit into
Geoffery10 wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
pyproject.toml: swappedonnxruntimeforonnxruntime-gpuso the CUDA provider is available.src/linuxcam/segmentation.py: instead of hardcodingCPUExecutionProvider, it now picksCUDAExecutionProviderfirst 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
How to verify
After restarting the daemon and opening the camera in your video app, you should see:
One note for NVIDIA users
If your CUDA libraries live in a non-standard location (e.g.
/usr/lib), you may need to addexport LD_LIBRARY_PATH=/usr/libto 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.