Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions cmake/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,8 @@ option(onnxruntime_USE_CANN "Build with CANN support" OFF)
option(onnxruntime_USE_XNNPACK "Build with XNNPACK support. Provides an alternative math library on ARM, WebAssembly and x86." OFF)
option(onnxruntime_USE_WEBNN "Build with WebNN support. Enable hardware acceleration in web browsers." OFF)
option(onnxruntime_USE_WEBGPU "Build with WebGPU support. Enable WebGPU via C/C++ interface." OFF)
option(onnxruntime_USE_EP_API_ADAPTERS "Build EP (e.g. WebGPU) as a plugin EP shared library using EP API adapters" OFF)
option(onnxruntime_WGSL_TEMPLATE "Specify the code generator for WGSL template. Default is static." "static")
option(onnxruntime_BUILD_WEBGPU_EP_STATIC_LIB "Build WebGPU EP as a static library" OFF)
option(onnxruntime_USE_EXTERNAL_DAWN "Build with treating Dawn as external dependency. Will not link Dawn at build time." OFF)
option(onnxruntime_CUSTOM_DAWN_SRC_PATH "Path to custom Dawn src dir.")
option(onnxruntime_BUILD_DAWN_SHARED_LIBRARY "Build Dawn as a shared library" OFF)
Expand Down Expand Up @@ -397,6 +397,11 @@ if (onnxruntime_ENABLE_TRITON)
endif()
endif()

# Building plugin EPs that depend on EP API adapters.
if(onnxruntime_USE_EP_API_ADAPTERS)
Comment thread
fs-eire marked this conversation as resolved.
add_compile_definitions(ORT_USE_EP_API_ADAPTERS=1)
endif()

# General C# properties
if (onnxruntime_BUILD_CSHARP)
check_language(CSharp)
Expand Down Expand Up @@ -982,10 +987,10 @@ if (onnxruntime_USE_WEBGPU)
endif()

if (onnxruntime_BUILD_DAWN_SHARED_LIBRARY)
if (onnxruntime_BUILD_WEBGPU_EP_STATIC_LIB)
if (NOT onnxruntime_USE_EP_API_ADAPTERS)
list(APPEND ORT_PROVIDER_FLAGS -DBUILD_DAWN_SHARED_LIBRARY=1)
else()
message(FATAL_ERROR "onnxruntime_BUILD_WEBGPU_EP_STATIC_LIB=OFF is not supported with onnxruntime_BUILD_DAWN_SHARED_LIBRARY=ON")
message(FATAL_ERROR "onnxruntime_USE_EP_API_ADAPTERS=ON is not supported with onnxruntime_BUILD_DAWN_SHARED_LIBRARY=ON")
endif()
endif()

Expand Down
2 changes: 1 addition & 1 deletion cmake/onnxruntime.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ if (onnxruntime_BUILD_QNN_EP_STATIC_LIB)
list(APPEND onnxruntime_INTERNAL_PROVIDER_LIBRARIES onnxruntime_providers_qnn)
endif()

if (onnxruntime_BUILD_WEBGPU_EP_STATIC_LIB)
if (onnxruntime_USE_WEBGPU AND NOT onnxruntime_USE_EP_API_ADAPTERS)
list(APPEND onnxruntime_INTERNAL_PROVIDER_LIBRARIES onnxruntime_providers_webgpu)
endif()

Expand Down
5 changes: 1 addition & 4 deletions cmake/onnxruntime_providers_webgpu.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@
endif()

add_compile_definitions(USE_WEBGPU=1)
if(onnxruntime_BUILD_WEBGPU_EP_STATIC_LIB)
add_compile_definitions(BUILD_WEBGPU_EP_STATIC_LIB=1)
endif()

if (onnxruntime_ENABLE_WEBASSEMBLY_THREADS)
add_definitions(-DENABLE_WEBASSEMBLY_THREADS=1)
Expand All @@ -33,7 +30,7 @@
list(APPEND onnxruntime_providers_webgpu_cc_srcs ${onnxruntime_webgpu_contrib_ops_cc_srcs})
endif()

if(onnxruntime_BUILD_WEBGPU_EP_STATIC_LIB)
if(NOT onnxruntime_USE_EP_API_ADAPTERS)
#
# Build WebGPU EP as a static library
#
Expand Down
2 changes: 1 addition & 1 deletion cmake/onnxruntime_python.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ set(onnxruntime_pybind11_state_static_providers
if(onnxruntime_BUILD_QNN_EP_STATIC_LIB)
list(APPEND onnxruntime_pybind11_state_static_providers PRIVATE onnxruntime_providers_qnn)
endif()
if(onnxruntime_BUILD_WEBGPU_EP_STATIC_LIB)
if(onnxruntime_USE_WEBGPU AND NOT onnxruntime_USE_EP_API_ADAPTERS)
list(APPEND onnxruntime_pybind11_state_static_providers PRIVATE onnxruntime_providers_webgpu)
endif()
if(WIN32)
Expand Down
4 changes: 2 additions & 2 deletions cmake/onnxruntime_unittests.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -696,7 +696,7 @@ set(ONNXRUNTIME_TEST_STATIC_PROVIDER_LIBS
if (onnxruntime_BUILD_QNN_EP_STATIC_LIB)
list(APPEND ONNXRUNTIME_TEST_STATIC_PROVIDER_LIBS onnxruntime_providers_qnn)
endif()
if (onnxruntime_BUILD_WEBGPU_EP_STATIC_LIB)
if (onnxruntime_USE_WEBGPU AND NOT onnxruntime_USE_EP_API_ADAPTERS)
list(APPEND ONNXRUNTIME_TEST_STATIC_PROVIDER_LIBS onnxruntime_providers_webgpu)
endif()

Expand Down Expand Up @@ -757,7 +757,7 @@ if(onnxruntime_USE_JSEP)
list(APPEND onnxruntime_test_providers_libs onnxruntime_providers_js)
endif()

if(onnxruntime_USE_WEBGPU AND onnxruntime_BUILD_WEBGPU_EP_STATIC_LIB)
if(onnxruntime_USE_WEBGPU AND NOT onnxruntime_USE_EP_API_ADAPTERS)
list(APPEND onnxruntime_test_framework_src_patterns ${TEST_SRC_DIR}/providers/webgpu/*)
list(APPEND onnxruntime_test_providers_dependencies onnxruntime_providers_webgpu)
list(APPEND onnxruntime_test_providers_libs onnxruntime_providers_webgpu)
Expand Down
12 changes: 8 additions & 4 deletions include/onnxruntime/ep/adapters.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,17 @@

#pragma once

#include "api.h"
#include "common.h"

// This header is only used when building WebGPU/CUDA EP as a shared library.
// This header is only used when building WebGPU/CUDA EP as a plugin EP library.
//
// This header file is used as a precompiled header so it is always included first.

#if !defined(ORT_USE_EP_API_ADAPTERS)
#error "This header should only be included when building with EP API adapters (i.e. plugin EP shared library). Please make sure ORT_USE_EP_API_ADAPTERS is defined."
#endif

#include "api.h"

Check warning on line 14 in include/onnxruntime/ep/adapters.h

View workflow job for this annotation

GitHub Actions / Optional Lint C++

[cpplint] reported by reviewdog 🐶 Include the directory when naming header files [build/include_subdir] [4] Raw Output: include/onnxruntime/ep/adapters.h:14: Include the directory when naming header files [build/include_subdir] [4]
#include "common.h"

Check warning on line 15 in include/onnxruntime/ep/adapters.h

View workflow job for this annotation

GitHub Actions / Optional Lint C++

[cpplint] reported by reviewdog 🐶 Include the directory when naming header files [build/include_subdir] [4] Raw Output: include/onnxruntime/ep/adapters.h:15: Include the directory when naming header files [build/include_subdir] [4]

#pragma push_macro("ORT_EP_API_ADAPTER_HEADER_INCLUDED")
#undef ORT_EP_API_ADAPTER_HEADER_INCLUDED
#define ORT_EP_API_ADAPTER_HEADER_INCLUDED
Expand Down
10 changes: 5 additions & 5 deletions onnxruntime/core/dll/delay_load_hook.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@
// - https://learn.microsoft.com/en-us/windows/win32/dlls/dynamic-link-library-search-order#alternate-search-order-for-unpackaged-apps
//
// The DLL DelayLoad hook is only enabled when the compiler is MSVC and at least one of the following is True:
// - all of the following are defined:
// - USE_WEBGPU
// - BUILD_WEBGPU_EP_STATIC_LIB
// - BUILD_DAWN_SHARED_LIBRARY
// - all of the following are true:
// - USE_WEBGPU is defined
// - ORT_USE_EP_API_ADAPTERS is NOT defined (i.e., WebGPU EP is statically linked)
// - BUILD_DAWN_SHARED_LIBRARY is defined
// - USE_DML is defined
//
#if defined(USE_WEBGPU) && defined(BUILD_WEBGPU_EP_STATIC_LIB) && defined(BUILD_DAWN_SHARED_LIBRARY)
#if defined(USE_WEBGPU) && !defined(ORT_USE_EP_API_ADAPTERS) && defined(BUILD_DAWN_SHARED_LIBRARY)
#define ORT_DELAY_LOAD_WEBGPU_DAWN_DLL 1
#else
#define ORT_DELAY_LOAD_WEBGPU_DAWN_DLL 0
Expand Down
2 changes: 1 addition & 1 deletion onnxruntime/core/providers/get_execution_providers.cc
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ constexpr ProviderInfo kProvidersInPriorityOrder[] =
},
{
kWebGpuExecutionProvider,
#if defined(USE_WEBGPU) && defined(BUILD_WEBGPU_EP_STATIC_LIB)
#if defined(USE_WEBGPU) && !defined(ORT_USE_EP_API_ADAPTERS)
true,
#else
false,
Expand Down
4 changes: 2 additions & 2 deletions onnxruntime/core/session/ort_env.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ std::atomic<bool> g_is_shutting_down(false);
using namespace onnxruntime;
using namespace onnxruntime::logging;

#if defined(USE_WEBGPU) && defined(BUILD_WEBGPU_EP_STATIC_LIB)
#if defined(USE_WEBGPU) && !defined(ORT_USE_EP_API_ADAPTERS)
namespace onnxruntime {
namespace webgpu {
void CleanupWebGpuContexts();
Expand All @@ -41,7 +41,7 @@ OrtEnv::~OrtEnv() {
UnloadSharedProviders();
#endif

#if defined(USE_WEBGPU) && defined(BUILD_WEBGPU_EP_STATIC_LIB)
#if defined(USE_WEBGPU) && !defined(ORT_USE_EP_API_ADAPTERS)
// Explicitly destroy the Environment first, which will properly clean up DataTransferManager
// and call ReleaseImpl on WebGpuDataTransferImpl
value_.reset();
Expand Down
4 changes: 2 additions & 2 deletions onnxruntime/core/session/plugin_ep/ep_factory_webgpu.cc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

#if defined(USE_WEBGPU) && defined(BUILD_WEBGPU_EP_STATIC_LIB)
#if defined(USE_WEBGPU) && !defined(ORT_USE_EP_API_ADAPTERS)
#include "core/session/plugin_ep/ep_factory_webgpu.h"

#include "core/framework/error_code_helper.h"
Expand Down Expand Up @@ -73,4 +73,4 @@ OrtStatus* WebGpuEpFactory::CreateDataTransfer(_Outptr_result_maybenull_ OrtData

} // namespace onnxruntime

#endif // defined(USE_WEBGPU) && defined(BUILD_WEBGPU_EP_STATIC_LIB)
#endif // defined(USE_WEBGPU) && !defined(ORT_USE_EP_API_ADAPTERS)
4 changes: 2 additions & 2 deletions onnxruntime/core/session/plugin_ep/ep_factory_webgpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#pragma once

#if defined(USE_WEBGPU) && defined(BUILD_WEBGPU_EP_STATIC_LIB)
#if defined(USE_WEBGPU) && !defined(ORT_USE_EP_API_ADAPTERS)
#include "core/session/plugin_ep/ep_factory_internal_impl.h"

#include "core/graph/constants.h"
Expand Down Expand Up @@ -34,4 +34,4 @@ class WebGpuEpFactory : public EpFactoryInternalImpl {
};
} // namespace onnxruntime

#endif // defined(USE_WEBGPU) && defined(BUILD_WEBGPU_EP_STATIC_LIB)
#endif // defined(USE_WEBGPU) && !defined(ORT_USE_EP_API_ADAPTERS)
4 changes: 2 additions & 2 deletions onnxruntime/core/session/plugin_ep/ep_library_internal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ std::unique_ptr<EpLibraryInternal> EpLibraryInternal::CreateDmlEp() {
}
#endif

#if defined(USE_WEBGPU) && defined(BUILD_WEBGPU_EP_STATIC_LIB)
#if defined(USE_WEBGPU) && !defined(ORT_USE_EP_API_ADAPTERS)
std::unique_ptr<EpLibraryInternal> EpLibraryInternal::CreateWebGpuEp() {
auto webgpu_factory_impl = std::make_unique<WebGpuEpFactory>();
auto internal_factory = std::make_unique<EpFactoryInternal>(std::move(webgpu_factory_impl));
Expand All @@ -38,7 +38,7 @@ std::vector<std::unique_ptr<EpLibraryInternal>> EpLibraryInternal::CreateInterna
// CPU EP
internal_eps.push_back(CreateCpuEp());

#if defined(USE_WEBGPU) && defined(BUILD_WEBGPU_EP_STATIC_LIB)
#if defined(USE_WEBGPU) && !defined(ORT_USE_EP_API_ADAPTERS)
internal_eps.push_back(CreateWebGpuEp());
#endif

Expand Down
2 changes: 1 addition & 1 deletion onnxruntime/core/session/plugin_ep/ep_library_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class EpLibraryInternal : public EpLibrary {
#if defined(USE_DML)
static std::unique_ptr<EpLibraryInternal> CreateDmlEp();
#endif
#if defined(USE_WEBGPU) && defined(BUILD_WEBGPU_EP_STATIC_LIB)
#if defined(USE_WEBGPU) && !defined(ORT_USE_EP_API_ADAPTERS)
static std::unique_ptr<EpLibraryInternal> CreateWebGpuEp();
#endif

Expand Down
2 changes: 1 addition & 1 deletion onnxruntime/core/session/provider_registration.cc
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ ORT_API_STATUS_IMPL(OrtApis::SessionOptionsAppendExecutionProvider,
break;
}
case EpID::WebGPU: {
#if defined(USE_WEBGPU) && defined(BUILD_WEBGPU_EP_STATIC_LIB)
#if defined(USE_WEBGPU) && !defined(ORT_USE_EP_API_ADAPTERS)
options->provider_factories.push_back(WebGpuProviderFactoryCreator::Create(options->value.config_options));
#else
status = create_not_supported_status();
Expand Down
4 changes: 2 additions & 2 deletions onnxruntime/test/unittest_util/base_tester.cc
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,7 @@ void BaseTester::RunWithConfig(size_t* number_of_pre_packed_weights_counter,
kQnnExecutionProvider,
kSnpeExecutionProvider,
kXnnpackExecutionProvider,
#if defined(USE_WEBGPU) && defined(BUILD_WEBGPU_EP_STATIC_LIB)
#if defined(USE_WEBGPU) && !defined(ORT_USE_EP_API_ADAPTERS)
kWebGpuExecutionProvider,
#endif
};
Expand Down Expand Up @@ -750,7 +750,7 @@ void BaseTester::RunWithConfig(size_t* number_of_pre_packed_weights_counter,
execution_provider = DefaultXnnpackExecutionProvider();
else if (provider_type == onnxruntime::kDmlExecutionProvider)
execution_provider = DefaultDmlExecutionProvider();
#if !defined(USE_WEBGPU) || defined(BUILD_WEBGPU_EP_STATIC_LIB)
#if !defined(USE_WEBGPU) || !defined(ORT_USE_EP_API_ADAPTERS)
else if (provider_type == onnxruntime::kWebGpuExecutionProvider)
execution_provider = DefaultWebGpuExecutionProvider();
#endif
Expand Down
4 changes: 2 additions & 2 deletions onnxruntime/test/util/default_providers.cc
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ std::unique_ptr<IExecutionProvider> DefaultXnnpackExecutionProvider() {
}

std::unique_ptr<IExecutionProvider> DefaultWebGpuExecutionProvider(bool is_nhwc) {
#if defined(USE_WEBGPU) && defined(BUILD_WEBGPU_EP_STATIC_LIB)
#if defined(USE_WEBGPU) && !defined(ORT_USE_EP_API_ADAPTERS)
ConfigOptions config_options{};
// Disable storage buffer cache
ORT_ENFORCE(config_options.AddConfigEntry(webgpu::options::kStorageBufferCacheMode,
Expand All @@ -302,7 +302,7 @@ std::unique_ptr<IExecutionProvider> DefaultWebGpuExecutionProvider(bool is_nhwc)
}

std::unique_ptr<IExecutionProvider> WebGpuExecutionProviderWithOptions(const ConfigOptions& config_options) {
#if defined(USE_WEBGPU) && defined(BUILD_WEBGPU_EP_STATIC_LIB)
#if defined(USE_WEBGPU) && !defined(ORT_USE_EP_API_ADAPTERS)
return WebGpuProviderFactoryCreator::Create(config_options)->CreateProvider();
#else
ORT_UNUSED_PARAMETER(config_options);
Expand Down
8 changes: 3 additions & 5 deletions tools/ci_build/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -884,11 +884,9 @@ def generate_build_tree(
raise BuildError(
"Enable PIX Capture (--enable_pix_capture) must be enabled with WebGPU (--use_webgpu) on Windows"
)
elif args.use_webgpu == "static_lib":
cmake_args += ["-Donnxruntime_BUILD_WEBGPU_EP_STATIC_LIB=ON"]
else:
# Shared library build
cmake_args += ["-Donnxruntime_BUILD_WEBGPU_EP_STATIC_LIB=OFF"]
elif args.use_webgpu == "shared_lib":
# Shared library build (plugin EP)
cmake_args += ["-Donnxruntime_USE_EP_API_ADAPTERS=ON"]
if args.build_wasm:
raise BuildError("Only static library build of WebGPU EP is supported for WebAssembly build.")

Expand Down
Loading