Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions include/stable-diffusion.h
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,10 @@ SD_API void disable_imatrix_collection(void);
// assignment specs. Returns the number of bytes required, excluding the null
// terminator. Passing nullptr or buffer_size 0 only queries the required size.
SD_API size_t sd_list_devices(char* buffer, size_t buffer_size);
// Report the free and total memory in bytes of the device at `index` in the
// sd_list_devices order. Returns false if the index is out of range or an
// output pointer is null.
SD_API bool sd_device_memory(size_t index, size_t* free_bytes, size_t* total_bytes);

// Register comma-separated RPC endpoints (host:port) before listing devices.
// Repeated endpoints are safe; nullptr or an empty string is a no-op.
Expand Down
14 changes: 14 additions & 0 deletions src/core/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1224,6 +1224,20 @@ std::vector<std::pair<std::string, float>> split_quotation_attention(
return result;
}

bool sd_device_memory(size_t index, size_t* free_bytes, size_t* total_bytes) {
if (free_bytes == nullptr || total_bytes == nullptr) {
return false;
}
if (ggml_backend_dev_count() == 0) {
ggml_backend_load_all();
}
if (index >= ggml_backend_dev_count()) {
return false;
}
ggml_backend_dev_memory(ggml_backend_dev_get(index), free_bytes, total_bytes);
return true;
}

size_t sd_list_devices(char* buffer, size_t buffer_size) {
if (ggml_backend_dev_count() == 0) {
// dynamic-backend builds discover their backend modules at runtime
Expand Down
Loading