@@ -3788,7 +3788,7 @@ static void ggml_webgpu_init_memset_pipeline(webgpu_global_context & ctx) {
37883788 ctx->memset_pipeline = ggml_webgpu_create_pipeline (ctx->device , wgsl_memset, " memset" , constants);
37893789}
37903790
3791- static void create_webgpu_device (ggml_backend_webgpu_reg_context * ctx ) {
3791+ static void ggml_backend_webgpu_request_adapter (wgpu::Instance & instance, wgpu::Adapter & adapter ) {
37923792 wgpu::RequestAdapterOptions options = {};
37933793
37943794#ifndef __EMSCRIPTEN__
@@ -3800,17 +3800,20 @@ static void create_webgpu_device(ggml_backend_webgpu_reg_context * ctx) {
38003800 options.nextInChain = &adapterTogglesDesc;
38013801#endif
38023802
3803- ctx->webgpu_global_ctx ->instance .WaitAny (
3804- ctx->webgpu_global_ctx ->instance .RequestAdapter (
3805- &options, wgpu::CallbackMode::AllowSpontaneous,
3806- [&ctx](wgpu::RequestAdapterStatus status, wgpu::Adapter adapter, const char * message) {
3807- if (status != wgpu::RequestAdapterStatus::Success) {
3808- GGML_LOG_ERROR (" ggml_webgpu: Failed to get an adapter: %s\n " , message);
3809- return ;
3810- }
3811- ctx->webgpu_global_ctx ->adapter = std::move (adapter);
3812- }),
3813- UINT64_MAX );
3803+ instance.WaitAny (instance.RequestAdapter (
3804+ &options, wgpu::CallbackMode::AllowSpontaneous,
3805+ [&adapter](wgpu::RequestAdapterStatus status, wgpu::Adapter _adapter, const char * message) {
3806+ if (status != wgpu::RequestAdapterStatus::Success) {
3807+ GGML_LOG_ERROR (" ggml_webgpu: Failed to get an adapter: %s\n " , message);
3808+ return ;
3809+ }
3810+ adapter = std::move (_adapter);
3811+ }),
3812+ UINT64_MAX );
3813+ }
3814+
3815+ static void create_webgpu_device (ggml_backend_webgpu_reg_context * ctx) {
3816+ ggml_backend_webgpu_request_adapter (ctx->webgpu_global_ctx ->instance , ctx->webgpu_global_ctx ->adapter );
38143817 GGML_ASSERT (ctx->webgpu_global_ctx ->adapter != nullptr );
38153818
38163819 ctx->webgpu_global_ctx ->adapter .GetLimits (&ctx->webgpu_global_ctx ->capabilities .limits );
@@ -4543,20 +4546,7 @@ ggml_backend_reg_t ggml_backend_webgpu_reg() {
45434546 // Probe for adapter support
45444547 wgpu::Adapter adapter;
45454548 if (ctx->webgpu_global_ctx ->instance != nullptr ) {
4546- wgpu::RequestAdapterOptions options = {};
4547-
4548- // probe for adapter support
4549- ctx->webgpu_global_ctx ->instance .WaitAny (
4550- ctx->webgpu_global_ctx ->instance .RequestAdapter (
4551- &options, wgpu::CallbackMode::AllowSpontaneous,
4552- [&adapter](wgpu::RequestAdapterStatus status, wgpu::Adapter _adapter, const char * message) {
4553- if (status != wgpu::RequestAdapterStatus::Success) {
4554- GGML_LOG_ERROR (" ggml_webgpu: Failed to get an adapter: %s\n " , message);
4555- return ;
4556- }
4557- adapter = std::move (_adapter);
4558- }),
4559- UINT64_MAX );
4549+ ggml_backend_webgpu_request_adapter (ctx->webgpu_global_ctx ->instance , adapter);
45604550 }
45614551
45624552 // WebGPU backend requires f16 support and, on native, implicit device synchronization.
0 commit comments