| 4387 | if (ctx->webgpu_global_ctx->capabilities.supports_subgroup_matrix) { |
| 4388 | required_features.push_back(wgpu::FeatureName::ChromiumExperimentalSubgroupMatrix); |
| 4389 | } |
| 4390 | #endif |
| 4391 | |
| 4392 | if (ctx->webgpu_global_ctx->capabilities.supports_subgroups) { |
| 4393 | required_features.push_back(wgpu::FeatureName::Subgroups); |
| 4394 | } |
| 4395 | |
| 4396 | #ifdef GGML_WEBGPU_GPU_PROFILE |
| 4397 | required_features.push_back(wgpu::FeatureName::TimestampQuery); |
| 4398 | #endif |
| 4399 | |
| 4400 | wgpu::DeviceDescriptor dev_desc; |
| 4401 | dev_desc.requiredLimits = &ctx->webgpu_global_ctx->capabilities.limits; |
| 4402 | dev_desc.requiredFeatures = required_features.data(); |
| 4403 | dev_desc.requiredFeatureCount = required_features.size(); |
| 4404 | dev_desc.SetDeviceLostCallback( |
| 4405 | wgpu::CallbackMode::AllowSpontaneous, |
| 4406 | [](const wgpu::Device & device, wgpu::DeviceLostReason reason, wgpu::StringView message) { |
| 4407 | if (reason == wgpu::DeviceLostReason::Destroyed) { |
| 4408 | return; |
| 4409 | } |
| 4410 | GGML_UNUSED(device); |
| 4411 | GGML_LOG_ERROR("ggml_webgpu: Device lost! Reason: %d, Message: %s\n", static_cast<int>(reason), |
| 4412 | std::string(message).c_str()); |
| 4413 | }); |
| 4414 | dev_desc.SetUncapturedErrorCallback( |
| 4415 | [](const wgpu::Device & device, wgpu::ErrorType reason, wgpu::StringView message) { |
| 4416 | GGML_UNUSED(device); |
| 4417 | GGML_ABORT("ggml_webgpu: Device error! Reason: %d, Message: %s\n", static_cast<int>(reason), |
| 4418 | std::string(message).c_str()); |
| 4419 | }); |
| 4420 | |
| 4421 | #if !defined(__EMSCRIPTEN__) && !defined(__wasi__) |
| 4422 | // Enable Dawn-specific toggles to increase native performance |
| 4423 | // TODO: Maybe WebGPU needs a "fast" mode where you can request compilers skip adding checks like these, |
| 4424 | // only for native performance? |
| 4425 | const char * const deviceEnabledToggles[] = { "disable_robustness", "disable_workgroup_init", |
| 4426 | "disable_polyfills_on_integer_div_and_mod" }; |
| 4427 | const char * const deviceDisabledToggles[] = { "timestamp_quantization" }; |
| 4428 | wgpu::DawnTogglesDescriptor deviceTogglesDesc; |
| 4429 | deviceTogglesDesc.enabledToggles = deviceEnabledToggles; |
| 4430 | deviceTogglesDesc.enabledToggleCount = 3; |
| 4431 | deviceTogglesDesc.disabledToggles = deviceDisabledToggles; |
| 4432 | deviceTogglesDesc.disabledToggleCount = 1; |
| 4433 | |
| 4434 | dev_desc.nextInChain = &deviceTogglesDesc; |
| 4435 | #endif |
| 4436 | |
| 4437 | ctx->webgpu_global_ctx->instance.WaitAny( |
| 4438 | ctx->webgpu_global_ctx->adapter.RequestDevice( |
| 4439 | &dev_desc, wgpu::CallbackMode::AllowSpontaneous, |
| 4440 | [ctx](wgpu::RequestDeviceStatus status, wgpu::Device device, wgpu::StringView message) { |
| 4441 | if (status != wgpu::RequestDeviceStatus::Success) { |
| 4442 | GGML_LOG_ERROR("ggml_webgpu: Failed to get a device: %s\n", std::string(message).c_str()); |
| 4443 | return; |
| 4444 | } |
| 4445 | ctx->webgpu_global_ctx->device = std::move(device); |
| 4446 | }), |
no test coverage detected