Skip to content

Commit 4fd5477

Browse files
authored
metal : support build for iOS/tvOS (#3089)
1 parent ec2a24f commit 4fd5477

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

ggml-metal.m

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,14 +117,17 @@ @implementation GGMLMetalClass
117117
struct ggml_metal_context * ggml_metal_init(int n_cb) {
118118
metal_printf("%s: allocating\n", __func__);
119119

120-
// Show all the Metal device instances in the system
121-
NSArray * devices = MTLCopyAllDevices();
122120
id <MTLDevice> device;
123121
NSString * s;
122+
123+
#if TARGET_OS_OSX
124+
// Show all the Metal device instances in the system
125+
NSArray * devices = MTLCopyAllDevices();
124126
for (device in devices) {
125127
s = [device name];
126128
metal_printf("%s: found device: %s\n", __func__, [s UTF8String]);
127129
}
130+
#endif
128131

129132
// Pick and show default Metal device
130133
device = MTLCreateSystemDefaultDevice();
@@ -247,13 +250,15 @@ @implementation GGMLMetalClass
247250
#undef GGML_METAL_ADD_KERNEL
248251
}
249252

250-
metal_printf("%s: recommendedMaxWorkingSetSize = %8.2f MB\n", __func__, ctx->device.recommendedMaxWorkingSetSize / 1024.0 / 1024.0);
251253
metal_printf("%s: hasUnifiedMemory = %s\n", __func__, ctx->device.hasUnifiedMemory ? "true" : "false");
254+
#if TARGET_OS_OSX
255+
metal_printf("%s: recommendedMaxWorkingSetSize = %8.2f MB\n", __func__, ctx->device.recommendedMaxWorkingSetSize / 1024.0 / 1024.0);
252256
if (ctx->device.maxTransferRate != 0) {
253257
metal_printf("%s: maxTransferRate = %8.2f MB/s\n", __func__, ctx->device.maxTransferRate / 1024.0 / 1024.0);
254258
} else {
255259
metal_printf("%s: maxTransferRate = built-in GPU\n", __func__);
256260
}
261+
#endif
257262

258263
return ctx;
259264
}
@@ -454,6 +459,7 @@ bool ggml_metal_add_buffer(
454459
}
455460
}
456461

462+
#if TARGET_OS_OSX
457463
metal_printf(", (%8.2f / %8.2f)",
458464
ctx->device.currentAllocatedSize / 1024.0 / 1024.0,
459465
ctx->device.recommendedMaxWorkingSetSize / 1024.0 / 1024.0);
@@ -463,6 +469,9 @@ bool ggml_metal_add_buffer(
463469
} else {
464470
metal_printf("\n");
465471
}
472+
#else
473+
metal_printf(", (%8.2f)\n", ctx->device.currentAllocatedSize / 1024.0 / 1024.0);
474+
#endif
466475
}
467476

468477
return true;

0 commit comments

Comments
 (0)