From 0dfaa10bf0eb0853d6145b2fcaab24c31b93aadd Mon Sep 17 00:00:00 2001 From: Julian Ng-Thow-Hing Date: Sat, 4 Jul 2026 18:19:52 -0700 Subject: [PATCH] Update [ghstack-poisoned] --- backends/webgpu/runtime/WebGPUDevice.cpp | 17 ++++++++++++----- backends/webgpu/runtime/WebGPUDevice.h | 3 +++ 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/backends/webgpu/runtime/WebGPUDevice.cpp b/backends/webgpu/runtime/WebGPUDevice.cpp index 9f48347c16b..7506686f2dd 100644 --- a/backends/webgpu/runtime/WebGPUDevice.cpp +++ b/backends/webgpu/runtime/WebGPUDevice.cpp @@ -13,9 +13,7 @@ #include #include #include -#ifdef WGPU_BACKEND_ENABLE_PROFILING #include -#endif // WGPU_BACKEND_ENABLE_PROFILING namespace executorch { namespace backends { @@ -143,16 +141,25 @@ WebGPUContext create_webgpu_context() { device_desc.requiredLimits = &supported_limits; } + // Request optional features the backend uses when the adapter supports them; + // fail-open (absence just disables the corresponding fast path). The vector + // must outlive wgpuAdapterRequestDevice below (device_desc points into it). + std::vector required_features; + if (wgpuAdapterHasFeature(ctx.adapter, WGPUFeatureName_ShaderF16)) { + required_features.push_back(WGPUFeatureName_ShaderF16); + ctx.shader_f16_supported = true; + } #ifdef WGPU_BACKEND_ENABLE_PROFILING // Bench: enable TimestampQuery if available; fail-open (skip timing if not). - std::vector required_features; if (wgpuAdapterHasFeature(ctx.adapter, WGPUFeatureName_TimestampQuery)) { required_features.push_back(WGPUFeatureName_TimestampQuery); - device_desc.requiredFeatureCount = required_features.size(); - device_desc.requiredFeatures = required_features.data(); ctx.timestamp_supported = true; } #endif // WGPU_BACKEND_ENABLE_PROFILING + if (!required_features.empty()) { + device_desc.requiredFeatureCount = required_features.size(); + device_desc.requiredFeatures = required_features.data(); + } device_desc.uncapturedErrorCallbackInfo.callback = on_device_error; diff --git a/backends/webgpu/runtime/WebGPUDevice.h b/backends/webgpu/runtime/WebGPUDevice.h index a332edef443..6ae62c20c2c 100644 --- a/backends/webgpu/runtime/WebGPUDevice.h +++ b/backends/webgpu/runtime/WebGPUDevice.h @@ -25,6 +25,9 @@ struct WebGPUContext { WGPUAdapter adapter = nullptr; WGPUDevice device = nullptr; WGPUQueue queue = nullptr; + // True if the device was created with the ShaderF16 feature (enables the + // fp16 storage/compute path in hot kernels; fp32 fallback when false). + bool shader_f16_supported = false; #ifdef WGPU_BACKEND_ENABLE_PROFILING // True if the device was created with the TimestampQuery feature (bench). bool timestamp_supported = false;