Skip to content

Commit e26d224

Browse files
committed
metal: Log recommendedMaxWorkingSetSize on iOS 16+
1 parent 467a882 commit e26d224

File tree

1 file changed

+22
-30
lines changed

1 file changed

+22
-30
lines changed

ggml-metal.m

Lines changed: 22 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -369,8 +369,11 @@ static void ggml_metal_log(enum ggml_log_level level, const char * format, ...){
369369
GGML_METAL_LOG_INFO("%s: simdgroup reduction support = %s\n", __func__, ctx->support_simdgroup_reduction ? "true" : "false");
370370
GGML_METAL_LOG_INFO("%s: simdgroup matrix mul. support = %s\n", __func__, ctx->support_simdgroup_mm ? "true" : "false");
371371
GGML_METAL_LOG_INFO("%s: hasUnifiedMemory = %s\n", __func__, ctx->device.hasUnifiedMemory ? "true" : "false");
372+
373+
if (@available(macOS 10.12, iOS 16.0, *)) {
374+
GGML_METAL_LOG_INFO("%s: recommendedMaxWorkingSetSize = %8.2f MB\n", __func__, ctx->device.recommendedMaxWorkingSetSize / 1e6);
375+
}
372376
#if TARGET_OS_OSX
373-
GGML_METAL_LOG_INFO("%s: recommendedMaxWorkingSetSize = %8.2f MB\n", __func__, ctx->device.recommendedMaxWorkingSetSize / 1e6);
374377
if (ctx->device.maxTransferRate != 0) {
375378
GGML_METAL_LOG_INFO("%s: maxTransferRate = %8.2f MB/s\n", __func__, ctx->device.maxTransferRate / 1e6);
376379
} else {
@@ -2369,6 +2372,22 @@ static void ggml_backend_metal_buffer_clear(ggml_backend_buffer_t buffer, uint8_
23692372
UNUSED(buft);
23702373
}
23712374

2375+
static void ggml_backend_metal_log_allocated_size(id<MTLDevice> device) {
2376+
if (@available(macOS 10.12, iOS 16.0, *)) {
2377+
GGML_METAL_LOG_INFO(", (%8.2f / %8.2f)",
2378+
device.currentAllocatedSize / 1024.0 / 1024.0,
2379+
device.recommendedMaxWorkingSetSize / 1024.0 / 1024.0);
2380+
2381+
if (device.currentAllocatedSize > device.recommendedMaxWorkingSetSize) {
2382+
GGML_METAL_LOG_WARN("%s: warning: current allocated size is greater than the recommended max working set size\n", __func__);
2383+
} else {
2384+
GGML_METAL_LOG_INFO("\n");
2385+
}
2386+
} else {
2387+
GGML_METAL_LOG_INFO(", (%8.2f)\n", device.currentAllocatedSize / 1024.0 / 1024.0);
2388+
}
2389+
}
2390+
23722391
static ggml_backend_buffer_t ggml_backend_metal_buffer_type_alloc_buffer(ggml_backend_buffer_type_t buft, size_t size) {
23732392
struct ggml_backend_metal_buffer_context * ctx = malloc(sizeof(struct ggml_backend_metal_buffer_context));
23742393

@@ -2401,22 +2420,7 @@ static ggml_backend_buffer_t ggml_backend_metal_buffer_type_alloc_buffer(ggml_ba
24012420
}
24022421

24032422
GGML_METAL_LOG_INFO("%s: allocated buffer, size = %8.2f MiB", __func__, size_aligned / 1024.0 / 1024.0);
2404-
2405-
2406-
#if TARGET_OS_OSX
2407-
GGML_METAL_LOG_INFO(", (%8.2f / %8.2f)",
2408-
device.currentAllocatedSize / 1024.0 / 1024.0,
2409-
device.recommendedMaxWorkingSetSize / 1024.0 / 1024.0);
2410-
2411-
if (device.currentAllocatedSize > device.recommendedMaxWorkingSetSize) {
2412-
GGML_METAL_LOG_WARN("%s: warning: current allocated size is greater than the recommended max working set size\n", __func__);
2413-
} else {
2414-
GGML_METAL_LOG_INFO("\n");
2415-
}
2416-
#else
2417-
GGML_METAL_LOG_INFO(", (%8.2f)\n", device.currentAllocatedSize / 1024.0 / 1024.0);
2418-
#endif
2419-
2423+
ggml_backend_metal_log_allocated_size(device);
24202424

24212425
return ggml_backend_buffer_init(buft, ggml_backend_metal_buffer_i, ctx, size);
24222426
}
@@ -2524,19 +2528,7 @@ ggml_backend_buffer_t ggml_backend_metal_buffer_from_ptr(void * data, size_t siz
25242528
}
25252529
}
25262530

2527-
#if TARGET_OS_OSX
2528-
GGML_METAL_LOG_INFO(", (%8.2f / %8.2f)",
2529-
device.currentAllocatedSize / 1024.0 / 1024.0,
2530-
device.recommendedMaxWorkingSetSize / 1024.0 / 1024.0);
2531-
2532-
if (device.currentAllocatedSize > device.recommendedMaxWorkingSetSize) {
2533-
GGML_METAL_LOG_WARN("%s: warning: current allocated size is greater than the recommended max working set size\n", __func__);
2534-
} else {
2535-
GGML_METAL_LOG_INFO("\n");
2536-
}
2537-
#else
2538-
GGML_METAL_LOG_INFO(", (%8.2f)\n", device.currentAllocatedSize / 1024.0 / 1024.0);
2539-
#endif
2531+
ggml_backend_metal_log_allocated_size(device);
25402532

25412533
return ggml_backend_buffer_init(ggml_backend_metal_buffer_type(), ggml_backend_metal_buffer_i, ctx, size);
25422534
}

0 commit comments

Comments
 (0)