@@ -187,6 +187,7 @@ static void ggml_backend_webgpu_buffer_memset(webgpu_context ctx, wgpu::Buffer b
187
187
/* * GGML Backend Interface */
188
188
189
189
static const char * ggml_backend_webgpu_name (ggml_backend_t backend) {
190
+ WEBGPU_LOG_DEBUG (" ggml_backend_webgpu_name()" );
190
191
ggml_backend_webgpu_context * ctx = (ggml_backend_webgpu_context *)backend->context ;
191
192
return ctx->name .c_str ();
192
193
}
@@ -219,13 +220,15 @@ static ggml_backend_i ggml_backend_webgpu_i = {
219
220
/* GGML Backend Buffer Interface */
220
221
221
222
static void ggml_backend_webgpu_buffer_free_buffer (ggml_backend_buffer_t buffer) {
223
+ WEBGPU_LOG_DEBUG (" ggml_backend_webgpu_buffer_free_buffer()" );
222
224
ggml_backend_webgpu_buffer_context * ctx = static_cast <ggml_backend_webgpu_buffer_context *>(buffer->context );
223
225
ctx->buffer .Destroy ();
224
226
delete ctx;
225
227
}
226
228
227
229
// Returns the "fake" base pointer.
228
230
static void * ggml_backend_webgpu_buffer_get_base (ggml_backend_buffer_t buffer) {
231
+ WEBGPU_LOG_DEBUG (" ggml_backend_webgpu_buffer_get_base()" );
229
232
GGML_UNUSED (buffer);
230
233
return webgpu_ptr_base;
231
234
}
@@ -315,6 +318,7 @@ static ggml_backend_buffer_i ggml_backend_webgpu_buffer_interface = {
315
318
/* GGML Backend Buffer Type Interface */
316
319
317
320
static const char * ggml_backend_webgpu_buffer_type_get_name (ggml_backend_buffer_type_t buft) {
321
+ WEBGPU_LOG_DEBUG (" ggml_backend_webgpu_buffer_type_get_name()" );
318
322
ggml_backend_webgpu_device_context * ctx = static_cast <ggml_backend_webgpu_device_context *>(buft->device ->context );
319
323
return ctx->device_name .c_str ();
320
324
}
@@ -333,12 +337,14 @@ static ggml_backend_buffer_t ggml_backend_webgpu_buffer_type_alloc_buffer(ggml_b
333
337
}
334
338
335
339
static size_t ggml_backend_webgpu_buffer_type_get_alignment (ggml_backend_buffer_type_t buft) {
340
+ WEBGPU_LOG_DEBUG (" ggml_backend_webgpu_buffer_type_get_alignment()" );
336
341
ggml_backend_webgpu_device_context * ctx = static_cast <ggml_backend_webgpu_device_context *>(buft->device ->context );
337
342
return ctx->webgpu_ctx ->limits .minStorageBufferOffsetAlignment ;
338
343
}
339
344
340
345
// maxBufferSize might be larger, but you can't bind more than maxStorageBufferBindingSize to a single binding.
341
346
static size_t ggml_backend_webgpu_buffer_type_get_max_size (ggml_backend_buffer_type_t buft) {
347
+ WEBGPU_LOG_DEBUG (" ggml_backend_webgpu_buffer_type_get_max_size()" );
342
348
ggml_backend_webgpu_device_context * ctx = static_cast <ggml_backend_webgpu_device_context *>(buft->device ->context );
343
349
return ctx->webgpu_ctx ->limits .maxStorageBufferBindingSize ;
344
350
}
@@ -348,23 +354,28 @@ static size_t ggml_backend_webgpu_buffer_type_get_max_size(ggml_backend_buffer_t
348
354
/* GGML Backend Device Interface */
349
355
350
356
static const char * ggml_backend_webgpu_device_get_name (ggml_backend_dev_t dev) {
357
+ WEBGPU_LOG_DEBUG (" ggml_backend_webgpu_device_get_name()" );
351
358
ggml_backend_webgpu_device_context * ctx = static_cast <ggml_backend_webgpu_device_context *>(dev->context );
352
359
return ctx->device_name .c_str ();
353
360
}
354
361
355
362
static const char * ggml_backend_webgpu_device_get_description (ggml_backend_dev_t dev) {
363
+ WEBGPU_LOG_DEBUG (" ggml_backend_webgpu_device_get_description()" );
356
364
ggml_backend_webgpu_device_context * ctx = static_cast <ggml_backend_webgpu_device_context *>(dev->context );
357
365
return ctx->device_desc .c_str ();
358
366
}
359
367
360
368
static void ggml_backend_webgpu_device_get_memory (ggml_backend_dev_t dev, size_t * free, size_t * total) {
369
+ WEBGPU_LOG_DEBUG (" ggml_backend_webgpu_device_get_memory()" );
370
+
361
371
ggml_backend_webgpu_device_context * ctx = static_cast <ggml_backend_webgpu_device_context *>(dev->context );
362
372
// TODO: what do we actually want to return here?
363
373
*free = ctx->webgpu_ctx ->limits .maxBufferSize * WEBGPU_MAX_BUFFERS;
364
374
*total = ctx->webgpu_ctx ->limits .maxBufferSize * WEBGPU_MAX_BUFFERS;
365
375
}
366
376
367
377
static enum ggml_backend_dev_type ggml_backend_webgpu_device_get_type (ggml_backend_dev_t dev) {
378
+ WEBGPU_LOG_DEBUG (" ggml_backend_webgpu_device_get_type()" );
368
379
GGML_UNUSED (dev);
369
380
return GGML_BACKEND_DEVICE_TYPE_GPU;
370
381
}
@@ -413,21 +424,22 @@ static ggml_backend_t ggml_backend_webgpu_device_init(ggml_backend_dev_t dev, co
413
424
WEBGPU_LOG_DEBUG (" ggml_backend_webgpu_device_init()" );
414
425
415
426
ggml_backend_webgpu_device_context * dev_ctx = static_cast <ggml_backend_webgpu_device_context *>(dev->context );
427
+ webgpu_context webgpu_ctx = dev_ctx->webgpu_ctx ;
416
428
417
429
// Initialize device
418
- wgpu::DeviceDescriptor deviceDescriptor;
419
- deviceDescriptor.SetDeviceLostCallback (wgpu::CallbackMode::AllowSpontaneous,
430
+ wgpu::DeviceDescriptor dev_desc;
431
+ dev_desc.requiredLimits = &webgpu_ctx->limits ;
432
+ dev_desc.SetDeviceLostCallback (wgpu::CallbackMode::AllowSpontaneous,
420
433
[](const wgpu::Device& device, wgpu::DeviceLostReason reason, wgpu::StringView message) {
421
434
GGML_UNUSED (device);
422
435
GGML_LOG_ERROR (" ggml_webgpu: Device lost! Reason: %d, Message: %s\n " , static_cast <int >(reason), message.data );
423
436
});
424
- deviceDescriptor .SetUncapturedErrorCallback (
437
+ dev_desc .SetUncapturedErrorCallback (
425
438
[](const wgpu::Device& device, wgpu::ErrorType reason, wgpu::StringView message) {
426
439
GGML_UNUSED (device);
427
440
GGML_LOG_ERROR (" ggml_webgpu: Device error! Reason: %d, Message: %s\n " , static_cast <int >(reason), message.data );
428
441
});
429
- webgpu_context webgpu_ctx = dev_ctx->webgpu_ctx ;
430
- webgpu_ctx->instance .WaitAny (webgpu_ctx->adapter .RequestDevice (&deviceDescriptor, wgpu::CallbackMode::WaitAnyOnly,
442
+ webgpu_ctx->instance .WaitAny (webgpu_ctx->adapter .RequestDevice (&dev_desc, wgpu::CallbackMode::WaitAnyOnly,
431
443
[webgpu_ctx](wgpu::RequestDeviceStatus status, wgpu::Device device, wgpu::StringView message) {
432
444
if (status != wgpu::RequestDeviceStatus::Success) {
433
445
GGML_LOG_ERROR (" ggml_webgpu: Failed to get a device: %s\n " , message.data );
@@ -515,11 +527,13 @@ static struct ggml_backend_device_i ggml_backend_webgpu_device_i = {
515
527
/* GGML Backend Registration Interface */
516
528
517
529
static const char * ggml_backend_webgpu_reg_get_name (ggml_backend_reg_t reg) {
530
+ WEBGPU_LOG_DEBUG (" ggml_backend_webgpu_reg_get_name()" );
518
531
ggml_backend_webgpu_reg_context * ctx = static_cast <ggml_backend_webgpu_reg_context *>(reg->context );
519
532
return ctx->name ;
520
533
}
521
534
522
535
static size_t ggml_backend_webgpu_reg_get_device_count (ggml_backend_reg_t reg) {
536
+ WEBGPU_LOG_DEBUG (" ggml_backend_webgpu_reg_get_device_count()" );
523
537
ggml_backend_webgpu_reg_context * ctx = static_cast <ggml_backend_webgpu_reg_context *>(reg->context );
524
538
return ctx->device_count ;
525
539
}
0 commit comments