MCPcopy Create free account
hub / github.com/0xShug0/audio.cpp / query_backend_memory

Function query_backend_memory

src/framework/core/backend.cpp:247–296  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

245 BackendMemorySnapshot snapshot;
246 if (backend == nullptr) {
247 return snapshot;
248 }
249 ggml_backend_dev_t device = ggml_backend_get_device(backend);
250 if (device != nullptr) {
251 size_t free_bytes = 0;
252 size_t total_bytes = 0;
253 ggml_backend_dev_memory(device, &free_bytes, &total_bytes);
254 if (total_bytes > 0 && free_bytes <= total_bytes) {
255 snapshot.available = true;
256 snapshot.total_bytes = static_cast<int64_t>(total_bytes);
257 snapshot.free_bytes = static_cast<int64_t>(free_bytes);
258 snapshot.used_bytes = static_cast<int64_t>(total_bytes - free_bytes);
259 }
260 }
261 (void)device_hint;
262 return snapshot;
263}
264
265BackendMemorySnapshot query_backend_memory(const BackendConfig & config) {
266 BackendMemorySnapshot snapshot;
267 switch (config.type) {
268 case BackendType::Cpu:
269 return snapshot;
270 case BackendType::BestAvailable:
271 return snapshot;
272 default:
273 break;
274 }
275 ggml_backend_dev_t device = find_device_by_backend_type(config.type, config.device);
276 if (device != nullptr) {
277 size_t free_bytes = 0;
278 size_t total_bytes = 0;
279 ggml_backend_dev_memory(device, &free_bytes, &total_bytes);
280 if (total_bytes > 0 && free_bytes <= total_bytes) {
281 snapshot.available = true;
282 snapshot.total_bytes = static_cast<int64_t>(total_bytes);
283 snapshot.free_bytes = static_cast<int64_t>(free_bytes);
284 snapshot.used_bytes = static_cast<int64_t>(total_bytes - free_bytes);
285 }
286 }
287 return snapshot;
288}
289
290ggml_backend_graph_plan_t create_backend_graph_plan_if_host(ggml_backend_t backend, ggml_cgraph * graph) {
291 if (backend == nullptr || graph == nullptr || !is_host_backend(backend)) {
292 return nullptr;
293 }
294 return ggml_backend_graph_plan_create(backend, graph);
295}
296
297void free_backend_graph_plan(ggml_backend_t backend, ggml_backend_graph_plan_t & plan) {
298 if (plan != nullptr) {
299 ggml_backend_graph_plan_free(backend, plan);

Callers 1

memory_snapshotMethod · 0.85

Calls 8

is_cuda_backend_handleFunction · 0.85
is_vulkan_backend_handleFunction · 0.85
is_metal_backend_handleFunction · 0.85
ggml_backend_get_deviceFunction · 0.85
ggml_backend_dev_memoryFunction · 0.85
ggml_backend_reg_dev_getFunction · 0.85
ggml_backend_metal_regFunction · 0.50

Tested by

no test coverage detected