210
210
GGML_METAL_KERNEL_TYPE_COUNT
211
211
};
212
212
213
- struct ggml_metal_context {
213
+ struct ggml_backend_metal_context {
214
214
int n_cb;
215
215
216
216
id <MTLDevice > device;
@@ -293,7 +293,7 @@ static void ggml_metal_log(enum ggml_log_level level, const char * format, ...){
293
293
return data;
294
294
}
295
295
296
- static struct ggml_metal_context * ggml_metal_init (int n_cb) {
296
+ static struct ggml_backend_metal_context * ggml_metal_init (int n_cb) {
297
297
GGML_METAL_LOG_INFO (" %s : allocating\n " , __func__);
298
298
299
299
#if TARGET_OS_OSX && !GGML_METAL_NDEBUG
@@ -310,7 +310,7 @@ static void ggml_metal_log(enum ggml_log_level level, const char * format, ...){
310
310
GGML_METAL_LOG_INFO (" %s : picking default device: %s \n " , __func__, [[device name ] UTF8String ]);
311
311
312
312
// Configure context
313
- struct ggml_metal_context * ctx = malloc (sizeof (struct ggml_metal_context ));
313
+ struct ggml_backend_metal_context * ctx = malloc (sizeof (struct ggml_backend_metal_context ));
314
314
ctx->device = device;
315
315
ctx->n_cb = MIN (n_cb, GGML_METAL_MAX_BUFFERS);
316
316
ctx->queue = [ctx->device newCommandQueue ];
@@ -672,7 +672,7 @@ static void ggml_metal_log(enum ggml_log_level level, const char * format, ...){
672
672
return ctx;
673
673
}
674
674
675
- static void ggml_metal_free (struct ggml_metal_context * ctx) {
675
+ static void ggml_metal_free (struct ggml_backend_metal_context * ctx) {
676
676
GGML_METAL_LOG_INFO (" %s : deallocating\n " , __func__);
677
677
678
678
for (int i = 0 ; i < GGML_METAL_KERNEL_TYPE_COUNT; ++i) {
@@ -738,7 +738,7 @@ static void ggml_metal_free(struct ggml_metal_context * ctx) {
738
738
return nil ;
739
739
}
740
740
741
- static bool ggml_metal_supports_op (const struct ggml_metal_context * ctx, const struct ggml_tensor * op) {
741
+ static bool ggml_metal_supports_op (const struct ggml_backend_metal_context * ctx, const struct ggml_tensor * op) {
742
742
for (size_t i = 0 , n = 3 ; i < n; ++i) {
743
743
if (op->src [i] != NULL && op->src [i]->type == GGML_TYPE_BF16) {
744
744
return false ;
@@ -849,7 +849,7 @@ static bool ggml_metal_supports_op(const struct ggml_metal_context * ctx, const
849
849
}
850
850
851
851
static enum ggml_status ggml_metal_graph_compute (
852
- struct ggml_metal_context * ctx,
852
+ struct ggml_backend_metal_context * ctx,
853
853
struct ggml_cgraph * gf) {
854
854
855
855
@autoreleasepool {
@@ -3176,7 +3176,7 @@ GGML_CALL ggml_backend_buffer_t ggml_backend_metal_buffer_from_ptr(void * data,
3176
3176
}
3177
3177
3178
3178
GGML_CALL static void ggml_backend_metal_free (ggml_backend_t backend) {
3179
- struct ggml_metal_context * ctx = (struct ggml_metal_context *)backend->context ;
3179
+ struct ggml_backend_metal_context * ctx = (struct ggml_backend_metal_context *)backend->context ;
3180
3180
ggml_metal_free (ctx);
3181
3181
free (backend);
3182
3182
}
@@ -3188,13 +3188,13 @@ GGML_CALL static ggml_backend_buffer_type_t ggml_backend_metal_get_default_buffe
3188
3188
}
3189
3189
3190
3190
GGML_CALL static enum ggml_status ggml_backend_metal_graph_compute (ggml_backend_t backend, struct ggml_cgraph * cgraph) {
3191
- struct ggml_metal_context * metal_ctx = (struct ggml_metal_context *)backend->context ;
3191
+ struct ggml_backend_metal_context * metal_ctx = (struct ggml_backend_metal_context *)backend->context ;
3192
3192
3193
3193
return ggml_metal_graph_compute (metal_ctx, cgraph);
3194
3194
}
3195
3195
3196
3196
GGML_CALL static bool ggml_backend_metal_supports_op (ggml_backend_t backend, const struct ggml_tensor * op) {
3197
- struct ggml_metal_context * metal_ctx = (struct ggml_metal_context *)backend->context ;
3197
+ struct ggml_backend_metal_context * metal_ctx = (struct ggml_backend_metal_context *)backend->context ;
3198
3198
3199
3199
return ggml_metal_supports_op (metal_ctx, op);
3200
3200
}
@@ -3239,9 +3239,9 @@ static ggml_guid_t ggml_backend_metal_guid(void) {
3239
3239
}
3240
3240
3241
3241
ggml_backend_t ggml_backend_metal_init (void ) {
3242
- struct ggml_metal_context * ctx = ggml_metal_init (GGML_DEFAULT_N_THREADS);
3243
-
3242
+ struct ggml_backend_metal_context * ctx = ggml_metal_init (GGML_DEFAULT_N_THREADS);
3244
3243
if (ctx == NULL ) {
3244
+ GGML_METAL_LOG_ERROR (" %s : error: failed to allocate context\n " , __func__);
3245
3245
return NULL ;
3246
3246
}
3247
3247
@@ -3263,15 +3263,15 @@ bool ggml_backend_is_metal(ggml_backend_t backend) {
3263
3263
void ggml_backend_metal_set_n_cb (ggml_backend_t backend, int n_cb) {
3264
3264
GGML_ASSERT (ggml_backend_is_metal (backend));
3265
3265
3266
- struct ggml_metal_context * ctx = (struct ggml_metal_context *)backend->context ;
3266
+ struct ggml_backend_metal_context * ctx = (struct ggml_backend_metal_context *)backend->context ;
3267
3267
3268
3268
ctx->n_cb = MIN (n_cb, GGML_METAL_MAX_BUFFERS);
3269
3269
}
3270
3270
3271
3271
void ggml_backend_metal_set_abort_callback (ggml_backend_t backend, ggml_abort_callback abort_callback, void * user_data) {
3272
3272
GGML_ASSERT (ggml_backend_is_metal (backend));
3273
3273
3274
- struct ggml_metal_context * ctx = (struct ggml_metal_context *)backend->context ;
3274
+ struct ggml_backend_metal_context * ctx = (struct ggml_backend_metal_context *)backend->context ;
3275
3275
3276
3276
ctx->abort_callback = abort_callback;
3277
3277
ctx->abort_callback_data = user_data;
@@ -3280,15 +3280,15 @@ void ggml_backend_metal_set_abort_callback(ggml_backend_t backend, ggml_abort_ca
3280
3280
bool ggml_backend_metal_supports_family (ggml_backend_t backend, int family) {
3281
3281
GGML_ASSERT (ggml_backend_is_metal (backend));
3282
3282
3283
- struct ggml_metal_context * ctx = (struct ggml_metal_context *)backend->context ;
3283
+ struct ggml_backend_metal_context * ctx = (struct ggml_backend_metal_context *)backend->context ;
3284
3284
3285
3285
return [ctx->device supportsFamily: (MTLGPUFamilyApple1 + family - 1 )];
3286
3286
}
3287
3287
3288
3288
void ggml_backend_metal_capture_next_compute (ggml_backend_t backend) {
3289
3289
GGML_ASSERT (ggml_backend_is_metal (backend));
3290
3290
3291
- struct ggml_metal_context * ctx = (struct ggml_metal_context *)backend->context ;
3291
+ struct ggml_backend_metal_context * ctx = (struct ggml_backend_metal_context *)backend->context ;
3292
3292
ctx->should_capture_next_compute = true ;
3293
3293
}
3294
3294
0 commit comments