ctx->memset_pipeline = ggml_webgpu_create_pipeline(ctx->device, wgsl_memset, "memset", constants);
}
-static void create_webgpu_device(ggml_backend_webgpu_reg_context * ctx) {
+static void ggml_backend_webgpu_request_adapter(wgpu::Instance & instance, wgpu::Adapter & adapter) {
wgpu::RequestAdapterOptions options = {};
#ifndef __EMSCRIPTEN__
options.nextInChain = &adapterTogglesDesc;
#endif
- ctx->webgpu_global_ctx->instance.WaitAny(
- ctx->webgpu_global_ctx->instance.RequestAdapter(
- &options, wgpu::CallbackMode::AllowSpontaneous,
- [&ctx](wgpu::RequestAdapterStatus status, wgpu::Adapter adapter, const char * message) {
- if (status != wgpu::RequestAdapterStatus::Success) {
- GGML_LOG_ERROR("ggml_webgpu: Failed to get an adapter: %s\n", message);
- return;
- }
- ctx->webgpu_global_ctx->adapter = std::move(adapter);
- }),
- UINT64_MAX);
+ instance.WaitAny(instance.RequestAdapter(
+ &options, wgpu::CallbackMode::AllowSpontaneous,
+ [&adapter](wgpu::RequestAdapterStatus status, wgpu::Adapter _adapter, const char * message) {
+ if (status != wgpu::RequestAdapterStatus::Success) {
+ GGML_LOG_ERROR("ggml_webgpu: Failed to get an adapter: %s\n", message);
+ return;
+ }
+ adapter = std::move(_adapter);
+ }),
+ UINT64_MAX);
+}
+
+static void create_webgpu_device(ggml_backend_webgpu_reg_context * ctx) {
+ ggml_backend_webgpu_request_adapter(ctx->webgpu_global_ctx->instance, ctx->webgpu_global_ctx->adapter);
GGML_ASSERT(ctx->webgpu_global_ctx->adapter != nullptr);
ctx->webgpu_global_ctx->adapter.GetLimits(&ctx->webgpu_global_ctx->capabilities.limits);
// Probe for adapter support
wgpu::Adapter adapter;
if (ctx->webgpu_global_ctx->instance != nullptr) {
- wgpu::RequestAdapterOptions options = {};
-
- // probe for adapter support
- ctx->webgpu_global_ctx->instance.WaitAny(
- ctx->webgpu_global_ctx->instance.RequestAdapter(
- &options, wgpu::CallbackMode::AllowSpontaneous,
- [&adapter](wgpu::RequestAdapterStatus status, wgpu::Adapter _adapter, const char * message) {
- if (status != wgpu::RequestAdapterStatus::Success) {
- GGML_LOG_ERROR("ggml_webgpu: Failed to get an adapter: %s\n", message);
- return;
- }
- adapter = std::move(_adapter);
- }),
- UINT64_MAX);
+ ggml_backend_webgpu_request_adapter(ctx->webgpu_global_ctx->instance, adapter);
}
// WebGPU backend requires f16 support and, on native, implicit device synchronization.