diff --git a/src/models/model.cpp b/src/models/model.cpp index 06e0dda316..daf4d18c51 100644 --- a/src/models/model.cpp +++ b/src/models/model.cpp @@ -4,10 +4,12 @@ // Modifications Copyright (C) 2024-2026 Advanced Micro Devices, Inc. All rights reserved. // Portions of this file consist of AI generated content. #include +#include #include #include #include #include +#include #include #include "../generators.h" @@ -406,7 +408,37 @@ void EnsureDeviceOrtInit(DeviceInterface& device, const Config& config) { // Create an OrtSessionOptions and set the options to use the DeviceType we're using here auto session_options = OrtSessionOptions::Create(); std::vector provider_options_list; - provider_options_list.emplace_back(Config::ProviderOptions{device_type_names[static_cast(type)], {}}); + const char* provider_name = device_type_names[static_cast(type)]; + Config::ProviderOptions init_session_provider_options{provider_name, {}}; + + // Forward only global/singleton WebGPU options to the init session so that the + // process-wide WebGpuContext singleton is initialized with the correct settings. + // Per-session options (enableGraphCapture, enableInt64, etc.) are excluded + // because they are meaningless for the trivial initialization model. + if (type == DeviceType::WEBGPU) { + constexpr std::array kWebGpuGlobalOptions = { + "deviceId", + "webgpuInstance", + "webgpuDevice", + "dawnBackendType", + "powerPreference", + "validationMode", + "dawnProcTable", + }; + for (const auto& user_po : config.model.decoder.session_options.provider_options) { + if (user_po.name == provider_name) { + for (const auto& opt : user_po.options) { + if (std::find(kWebGpuGlobalOptions.begin(), kWebGpuGlobalOptions.end(), opt.first) != kWebGpuGlobalOptions.end()) { + init_session_provider_options.options.emplace_back(opt); + } + } + init_session_provider_options.device_filtering_options = user_po.device_filtering_options; + break; + } + } + } + + provider_options_list.emplace_back(std::move(init_session_provider_options)); // QnnHtpShared is a special case. This allocator is only made available when the provider option // 'enable_htp_shared_memory_allocator' is set to 1. if (type == DeviceType::QNN) {