You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix: prefer CUDA for GPUs shared with Vulkan in auto-fit - #2478
If this PR adds or changes model support, I have added or updated its usage guide and relevant model index/README entries following the model documentation requirements.
Summary by CodeRabbit
Improvements
Auto-fit now lists a GPU exposed through multiple backends only once and uses the lowest available memory budget across those backends. When choosing a backend, it prefers a discrete GPU over an integrated GPU, and CUDA over other backends when GPU types are otherwise equal.
Documentation
Clarified that auto-fit prefers CUDA when CUDA and Vulkan expose the same GPU.
No actionable comments were generated in the recent review.
Walkthrough
Auto-fit now groups backend entries for the same physical GPU, keeps the minimum budget across those backends, and selects a representative backend. It uses PCI IDs when available and can match a Vulkan device without one to a unique CUDA device with the same description.
Changes: GPU auto-fit selection
Layer / File(s)
Summary
GPU budget calculation src/core/backend_fit.cpp
GPU enumeration calculates budgets from queried free memory. The Device structure no longer stores free-memory values or descriptions, and a helper identifies CUDA and Vulkan backend registrations.
Physical device matching src/core/backend_fit.cpp
Devices continue to match by PCI ID when available. A Vulkan device without a PCI ID can use the key of a unique CUDA device with the same description.
physical_budgets groups entries by physical-device key, retains the minimum budget, and selects a discrete GPU over an integrated GPU, or CUDA over a non-CUDA backend when device types match. The API comment and guide state that CUDA is preferred when CUDA and Vulkan expose the same GPU.
leejet/stable-diffusion.cpp#2259: Changes auto-fit ranking to prefer a discrete GPU with a larger positive budget, which relates to the device-selection rules updated here.
Suggested reviewers:pwilkin
Merge Risk: Minimal · up to 8f348
Auto-fit now prefers CUDA when CUDA and Vulkan expose the same GPU, which addresses the reported issue. No concrete merge-blocking risk was established.
Pre-merge checks: 4
Check name
Status
Explanation
Title check
The title states the main change: auto-fit now prefers CUDA for GPUs that Vulkan also exposes. The raw summary confirms that physical_budgets merges backends for the same device and selects CUDA over …
Description check
The description follows the template sections: Summary, Related Issue / Discussion, Additional Information, and Checklist. The Summary explains the CUDA preference and the PCI ID or unique model-name …
Linked Issues check
[#2475] requires auto-fit to prefer CUDA over Vulkan when both expose the same GPU, while keeping auto-fit. The diff in src/core/backend_fit.cpp implements this. In physical_budgets(), duplicate backe…
Out of Scope Changes check
All changes support the linked objective. The backend_fit.cpp changes implement CUDA preference, device deduplication, and PCI or unique-name matching. Removing the description and free_bytes fields f…
Full details: Title check
Explanation
The title states the main change: auto-fit now prefers CUDA for GPUs that Vulkan also exposes. The raw summary confirms that physical_budgets merges backends for the same device and selects CUDA over non-CUDA, so the title matches the changeset. It is short, specific, and follows a conventional commit prefix.
Full details: Description check
Explanation
The description follows the template sections: Summary, Related Issue / Discussion, Additional Information, and Checklist. The Summary explains the CUDA preference and the PCI ID or unique model-name matching. It links issue #2475, and both checklist items are checked. The Additional Information section is filled only with N/A, which is acceptable for a non-critical section. The description does not mention verification steps, such as testing on a CUDA+Vulkan build, so a reviewer must rely on the code and linked issue for validation.
Full details: Linked Issues check
Explanation
[#2475] requires auto-fit to prefer CUDA over Vulkan when both expose the same GPU, while keeping auto-fit. The diff in src/core/backend_fit.cpp implements this. In physical_budgets(), duplicate backend entries for one physical device merge into one entry. The representative backend is the discrete GPU over an integrated GPU. If the types match, CUDA is preferred over non-CUDA. Registration order no longer decides the result. The merged budget is the minimum of the backend budgets. physical_device_key() uses the PCI ID when present. If a Vulkan device has no PCI ID, it uses the model description only when find_cuda_alias() finds exactly one CUDA device with that description and no ambiguous Vulkan match. Otherwise the key falls back to the device name, so distinct GPUs stay separate and budget-based selection still applies. gpu_device_budgets() now lists each physical GPU once. The summary does not show new automated tests for these paths. That gap does not change the coding-requirement result, because the code path matches the requirement.
Full details: Out of Scope Changes check
Explanation
All changes support the linked objective. The backend_fit.cpp changes implement CUDA preference, device deduplication, and PCI or unique-name matching. Removing the description and free_bytes fields from Device and the <set> include is refactoring needed by the new logic. The change to the gpu_device_budgets() comment in backend_fit.h and the one-line backend guide update in docs/guides/backend.md describe the new behavior. No unrelated functional change appears in the reviewed diff.
Finishing Touches
Generate unit tests (beta)
Commit to this branch
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
File: No configuration file from this repository applied
Commit: Unavailable
Layers: Repository UI
Review profile: CHILL
Plan: Advanced
Run ID: 7003ff0b-9f6f-4a7a-a6fb-221a51f39e9f
Commits
Reviewing files that changed from the base of the PR and between 5c86023 and 8f34838.
Files selected for processing: 3
docs/guides/backend.md
src/core/backend_fit.cpp
src/core/backend_fit.h
Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 6 remain after this review.
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
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.
Summary
Related Issue / Discussion
Fix #2475.
Additional Information
N/A
Checklist
Summary by CodeRabbit