summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKarsten Weiss <knweiss@gmail.com>2023-09-02 14:29:09 +0200
committerGitHub <noreply@github.com>2023-09-02 15:29:09 +0300
commit8b56b4f2c396eae1f4417e5a859557fed989e0ee (patch)
treec1c31895e38cb838c95b7ec4acbab5cb21aa344c
parent21f3d1be867b4d7be07c26f5da6e4bc69bcf4d27 (diff)
metal : show all Metal device instances in the system (#2952)
* ggml_metal_init: Show all Metal device instances in the system Also show the default Metal device that was picked. * Update ggml-metal.m --------- Co-authored-by: Georgi Gerganov <ggerganov@gmail.com>
-rw-r--r--ggml-metal.m18
1 files changed, 16 insertions, 2 deletions
diff --git a/ggml-metal.m b/ggml-metal.m
index 4267db9b..88e7e135 100644
--- a/ggml-metal.m
+++ b/ggml-metal.m
@@ -116,10 +116,24 @@ static NSString * const msl_library_source = @"see metal.metal";
struct ggml_metal_context * ggml_metal_init(int n_cb) {
metal_printf("%s: allocating\n", __func__);
- struct ggml_metal_context * ctx = malloc(sizeof(struct ggml_metal_context));
+ // Show all the Metal device instances in the system
+ NSArray * devices = MTLCopyAllDevices();
+ id <MTLDevice> device;
+ NSString * s;
+ for (device in devices) {
+ s = [device name];
+ metal_printf("%s: found device: %s\n", __func__, [s UTF8String]);
+ }
+ // Pick and show default Metal device
+ device = MTLCreateSystemDefaultDevice();
+ s = [device name];
+ metal_printf("%s: picking default device: %s\n", __func__, [s UTF8String]);
+
+ // Configure context
+ struct ggml_metal_context * ctx = malloc(sizeof(struct ggml_metal_context));
+ ctx->device = device;
ctx->n_cb = MIN(n_cb, GGML_METAL_MAX_BUFFERS);
- ctx->device = MTLCreateSystemDefaultDevice();
ctx->queue = [ctx->device newCommandQueue];
ctx->n_buffers = 0;
ctx->concur_list_len = 0;