Skip to content

Commit f8a53ee

Browse files
committed
Finish rest of setup
1 parent d0480ca commit f8a53ee

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

ggml/src/ggml-webgpu/ggml-webgpu.cpp

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ static void ggml_backend_webgpu_buffer_memset(webgpu_context ctx, wgpu::Buffer b
187187
/** GGML Backend Interface */
188188

189189
static const char * ggml_backend_webgpu_name(ggml_backend_t backend) {
190+
WEBGPU_LOG_DEBUG("ggml_backend_webgpu_name()");
190191
ggml_backend_webgpu_context * ctx = (ggml_backend_webgpu_context *)backend->context;
191192
return ctx->name.c_str();
192193
}
@@ -219,13 +220,15 @@ static ggml_backend_i ggml_backend_webgpu_i = {
219220
/* GGML Backend Buffer Interface */
220221

221222
static void ggml_backend_webgpu_buffer_free_buffer(ggml_backend_buffer_t buffer) {
223+
WEBGPU_LOG_DEBUG("ggml_backend_webgpu_buffer_free_buffer()");
222224
ggml_backend_webgpu_buffer_context * ctx = static_cast<ggml_backend_webgpu_buffer_context *>(buffer->context);
223225
ctx->buffer.Destroy();
224226
delete ctx;
225227
}
226228

227229
// Returns the "fake" base pointer.
228230
static void * ggml_backend_webgpu_buffer_get_base(ggml_backend_buffer_t buffer) {
231+
WEBGPU_LOG_DEBUG("ggml_backend_webgpu_buffer_get_base()");
229232
GGML_UNUSED(buffer);
230233
return webgpu_ptr_base;
231234
}
@@ -315,6 +318,7 @@ static ggml_backend_buffer_i ggml_backend_webgpu_buffer_interface = {
315318
/* GGML Backend Buffer Type Interface */
316319

317320
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()");
318322
ggml_backend_webgpu_device_context * ctx = static_cast<ggml_backend_webgpu_device_context *>(buft->device->context);
319323
return ctx->device_name.c_str();
320324
}
@@ -333,12 +337,14 @@ static ggml_backend_buffer_t ggml_backend_webgpu_buffer_type_alloc_buffer(ggml_b
333337
}
334338

335339
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()");
336341
ggml_backend_webgpu_device_context * ctx = static_cast<ggml_backend_webgpu_device_context *>(buft->device->context);
337342
return ctx->webgpu_ctx->limits.minStorageBufferOffsetAlignment;
338343
}
339344

340345
// maxBufferSize might be larger, but you can't bind more than maxStorageBufferBindingSize to a single binding.
341346
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()");
342348
ggml_backend_webgpu_device_context * ctx = static_cast<ggml_backend_webgpu_device_context *>(buft->device->context);
343349
return ctx->webgpu_ctx->limits.maxStorageBufferBindingSize;
344350
}
@@ -348,23 +354,28 @@ static size_t ggml_backend_webgpu_buffer_type_get_max_size(ggml_backend_buffer_t
348354
/* GGML Backend Device Interface */
349355

350356
static const char * ggml_backend_webgpu_device_get_name(ggml_backend_dev_t dev) {
357+
WEBGPU_LOG_DEBUG("ggml_backend_webgpu_device_get_name()");
351358
ggml_backend_webgpu_device_context * ctx = static_cast<ggml_backend_webgpu_device_context *>(dev->context);
352359
return ctx->device_name.c_str();
353360
}
354361

355362
static const char * ggml_backend_webgpu_device_get_description(ggml_backend_dev_t dev) {
363+
WEBGPU_LOG_DEBUG("ggml_backend_webgpu_device_get_description()");
356364
ggml_backend_webgpu_device_context * ctx = static_cast<ggml_backend_webgpu_device_context *>(dev->context);
357365
return ctx->device_desc.c_str();
358366
}
359367

360368
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+
361371
ggml_backend_webgpu_device_context * ctx = static_cast<ggml_backend_webgpu_device_context *>(dev->context);
362372
// TODO: what do we actually want to return here?
363373
*free = ctx->webgpu_ctx->limits.maxBufferSize * WEBGPU_MAX_BUFFERS;
364374
*total = ctx->webgpu_ctx->limits.maxBufferSize * WEBGPU_MAX_BUFFERS;
365375
}
366376

367377
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()");
368379
GGML_UNUSED(dev);
369380
return GGML_BACKEND_DEVICE_TYPE_GPU;
370381
}
@@ -413,21 +424,22 @@ static ggml_backend_t ggml_backend_webgpu_device_init(ggml_backend_dev_t dev, co
413424
WEBGPU_LOG_DEBUG("ggml_backend_webgpu_device_init()");
414425

415426
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;
416428

417429
// 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,
420433
[](const wgpu::Device& device, wgpu::DeviceLostReason reason, wgpu::StringView message) {
421434
GGML_UNUSED(device);
422435
GGML_LOG_ERROR("ggml_webgpu: Device lost! Reason: %d, Message: %s\n", static_cast<int>(reason), message.data);
423436
});
424-
deviceDescriptor.SetUncapturedErrorCallback(
437+
dev_desc.SetUncapturedErrorCallback(
425438
[](const wgpu::Device& device, wgpu::ErrorType reason, wgpu::StringView message) {
426439
GGML_UNUSED(device);
427440
GGML_LOG_ERROR("ggml_webgpu: Device error! Reason: %d, Message: %s\n", static_cast<int>(reason), message.data);
428441
});
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,
431443
[webgpu_ctx](wgpu::RequestDeviceStatus status, wgpu::Device device, wgpu::StringView message) {
432444
if (status != wgpu::RequestDeviceStatus::Success) {
433445
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 = {
515527
/* GGML Backend Registration Interface */
516528

517529
static const char * ggml_backend_webgpu_reg_get_name(ggml_backend_reg_t reg) {
530+
WEBGPU_LOG_DEBUG("ggml_backend_webgpu_reg_get_name()");
518531
ggml_backend_webgpu_reg_context * ctx = static_cast<ggml_backend_webgpu_reg_context *>(reg->context);
519532
return ctx->name;
520533
}
521534

522535
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()");
523537
ggml_backend_webgpu_reg_context * ctx = static_cast<ggml_backend_webgpu_reg_context *>(reg->context);
524538
return ctx->device_count;
525539
}

0 commit comments

Comments
 (0)