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
feat: add sd_device_memory to query device memory - #2483
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
New Features
Added an API to retrieve a device’s free and total memory in bytes by its listed index. It returns an error result for an invalid index or missing output values.
No actionable comments were generated in the recent review.
Walkthrough
Adds sd_device_memory, a public C API that returns free and total memory for a device by its sd_list_devices index.
Changes: Device Memory Query API
Layer / File(s)
Summary
Declare and implement device memory query include/stable-diffusion.h, src/core/util.cpp
The public declaration documents the device index and failure conditions. The implementation checks output pointers and index, loads backends if no devices are registered, and retrieves the selected device’s memory values.
This adds a small, additive C API for querying device memory. Existing APIs are unchanged and no merge-blocking risk was found.
Pre-merge checks: 4
Check name
Status
Explanation
Title check
The title names the main change: a new public function, sd_device_memory, that queries device memory. It is short, specific, and follows the conventional commit style. The changeset adds this function…
Linked Issues check
[#2482] The issue asks for a public C API that reports free and total memory for a device in sd_list_devices order. The whole-PR summary shows `bool sd_device_memory(size_t index, size_t* free_bytes…
Out of Scope Changes check
The whole-PR summary lists only two changed files: include/stable-diffusion.h (one added declaration) and src/core/util.cpp (the added function). Both changes implement the requested `sd_device_me…
Description check
The description covers the change well. The Summary states that the PR adds sd_device_memory(index, &free_bytes, &total_bytes), that the index follows sd_list_devices order, that values come from …
Full details: Title check
Explanation
The title names the main change: a new public function, sd_device_memory, that queries device memory. It is short, specific, and follows the conventional commit style. The changeset adds this function to include/stable-diffusion.h and src/core/util.cpp, which matches the title.
Full details: Linked Issues check
Explanation
[#2482] The issue asks for a public C API that reports free and total memory for a device in sd_list_devices order. The whole-PR summary shows bool sd_device_memory(size_t index, size_t* free_bytes, size_t* total_bytes) added to include/stable-diffusion.h (+4 lines) and implemented in src/core/util.cpp (+14 lines). The summary states that the function returns false for a null output pointer or an out-of-range index, and that it loads backend devices when none are registered before checking the index. The PR description states that the values come from ggml_backend_dev_memory. The author reports tests with a C caller: a query before sd_list_devices succeeded, CUDA0 and CPU returned positive totals with free bytes at or below total, index 2 returned false, and null pointers returned false. Limit: the repository diff tool could not read the changed blobs, and the head file view of src/core/util.cpp was truncated before the new function. The function body was therefore not read directly. The assessment relies on the supplied summary and PR description.
Full details: Out of Scope Changes check
Explanation
The whole-PR summary lists only two changed files: include/stable-diffusion.h (one added declaration) and src/core/util.cpp (the added function). Both changes implement the requested sd_device_memory API. No unrelated changes appear in the summary. The raw diff could not be read, so this conclusion relies on the summary's file list and line counts.
Full details: Description check
Explanation
The description covers the change well. The Summary states that the PR adds sd_device_memory(index, &free_bytes, &total_bytes), that the index follows sd_list_devices order, that values come from ggml_backend_dev_memory, and that null pointers or out-of-range indices return false. It also explains the backend-loading behavior. The Related Issue section links issue #2482. The Additional Information section lists concrete test results from a CUDA 12.8 build, including queries before sd_list_devices, device enumeration, the out-of-range index check, and null-pointer checks. The checklist is filled in. The template's required sections are all present and substantive.
Finishing Touches
Generate unit tests (beta)
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: a292c2da-ed3a-4a1b-b8f9-4d5a0258eec4
Commits
Reviewing files that changed from the base of the PR and between f93d45b and 1c92d3e.
Files selected for processing: 2
include/stable-diffusion.h
src/core/util.cpp
Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 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
Applications using
stable-diffusion.hcan query free and total memory for each device listed bysd_list_devices.sd_device_memory(index, &free_bytes, &total_bytes). The index follows thesd_list_devicesorder, and the values come fromggml_backend_dev_memory.sd_list_devices, it callsggml_backend_load_all()when no device is registered, so dynamic-backend builds work without listing devices first.Related Issue / Discussion
Closes #2482.
Additional Information
Tested a C caller against the current implementation with the CUDA 12.8 build's ggml libraries.
sd_list_devices. The query succeeded.Checklist
Summary by CodeRabbit