Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
18f91e5
[webgpu] Flash attention for generation (#23808)
qjia7 Apr 8, 2025
04e0b50
Use WASM f32x4 relaxed min/max for relaxed simd build (#24324)
fanchenkong1 Apr 8, 2025
f83e661
webgpu support for DequantizeLinear (#24268)
Apr 8, 2025
10e51d2
[webgpu] fix the reflect mode issue of Pad (#24202)
xhcao Apr 8, 2025
4edada6
Remove explicit batch network flag for TRT 10+ (#24298)
kevinch-nv Apr 8, 2025
2265613
[webgpu] Fix bias_split_gelu (#24342)
jchen10 Apr 8, 2025
34abb8b
[webgpu] fix bias-add (#24336)
jchen10 Apr 8, 2025
0acb048
[webgpu] optimize SkipLayerNormalization operator (#24164)
xhcao Apr 8, 2025
d7a38a5
ROCm: Remove -Wno-interference-size compiler flag (#24326)
jagadish-amd Apr 8, 2025
39e585f
[web] revise flag `ort.env.wasm.simd` (#24314)
fs-eire Apr 8, 2025
5a5e668
[WebGPU EP] Exclude zero-dim input test case for WebGPU EP. (#24350)
satyajandhyala Apr 8, 2025
4dc0e35
Group build args (#24337)
Apr 8, 2025
cda0d14
[webgpu][dawn API optimization] workgroup dispatch (#24329)
fs-eire Apr 8, 2025
89f8206
Pin wheel version to 0.45.1 (#24349)
amarin16 Apr 9, 2025
f6db653
[QNN EP] Add support for Int64 tensors (#24351)
quic-ashwshan Apr 9, 2025
1d928a1
Support WebGPU build for android and ios (#24308)
sheetalarkadam Apr 9, 2025
85e6b4c
[web] fix TypeScript typing and add a test case (#24354)
fs-eire Apr 9, 2025
5612ce5
[WebNN] Support MatMulNBits op (#24142)
Honry Apr 9, 2025
6ba73a1
[EP Perf] Extension to post benchmark perf from local devices (#24236)
yf711 Apr 9, 2025
aa87e34
Update unknown provider error message with current providers (#24352)
RyanUnderhill Apr 9, 2025
c5d1416
[WebGPU] fix compile on latest 24.02 (#24364)
Apr 9, 2025
f12a89e
[WebNN EP] Support GroupQueryAttention(GQA) (#23416)
peishenyan Apr 10, 2025
f0216fd
Merge branch 'master' into sync_msft_10_4_25
jatinwadhwa921 Apr 10, 2025
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
31 changes: 2 additions & 29 deletions cmake/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,6 @@ option(onnxruntime_ENABLE_TRAINING_OPS "Include training operators but no traini
option(onnxruntime_ENABLE_TRAINING_E2E_TESTS "Enable training end-to-end tests." OFF)
option(onnxruntime_ENABLE_CPU_FP16_OPS "Build with advanced instruction sets" ON)
option(onnxruntime_USE_NCCL "Build with NCCL support" OFF)
option(onnxruntime_USE_MPI "Build with MPI support" OFF)

# WebAssembly options
option(onnxruntime_BUILD_WEBASSEMBLY_STATIC_LIB "Enable this option to create WebAssembly static library" OFF)
Expand Down Expand Up @@ -1267,6 +1266,7 @@ function(onnxruntime_set_compile_flags target_name)
# Unsupported by Clang 18 yet.
list(REMOVE_ITEM ORT_HIP_WARNING_FLAGS -Wno-dangling-reference)

list(REMOVE_ITEM ORT_HIP_WARNING_FLAGS -Wno-interference-size)
# float16.h:90:12: error: ‘tmp’ is used uninitialized
list(APPEND ORT_HIP_WARNING_FLAGS -Wno-uninitialized)
list(APPEND ORT_HIP_WARNING_FLAGS -Wno-deprecated-copy)
Expand Down Expand Up @@ -1650,29 +1650,6 @@ if (onnxruntime_ENABLE_DLPACK)
endif()

if (UNIX OR onnxruntime_USE_NCCL)
# MPI is INDEPENDENT of NCCL for now. You can build NCLL without MPI and launch multi-GPU with your own launcher.
if (onnxruntime_USE_MPI)
if (EXISTS "${onnxruntime_MPI_HOME}")
set(MPI_HOME "${onnxruntime_MPI_HOME}")
elseif (EXISTS "/bert_ort/openmpi")
set(MPI_HOME "/bert_ort/openmpi")
endif()
find_package(MPI)

if (MPI_CXX_FOUND)
message( STATUS "MPI Version: ${MPI_CXX_VERSION}")
message( STATUS "MPI (include: ${MPI_CXX_INCLUDE_DIRS}, library: ${MPI_CXX_LIBRARIES})" )
mark_as_advanced(MPI_CXX_INCLUDE_DIRS MPI_CXX_LIBRARIES)
list(APPEND onnxruntime_EXTERNAL_LIBRARIES ${MPI_CXX_LIBRARIES} ${MPI_CXX_LINK_FLAGS})
else ()
message(
FATAL_ERROR
"MPI is not found. Please define onnxruntime_MPI_HOME to specify the path of MPI. Otherwise, NCCL will be disabled."
"or you can remove --use_mpi from build args to disable MPI."
)
endif()
endif()

# Find NCCL
if (onnxruntime_USE_NCCL)
if (onnxruntime_USE_CUDA)
Expand Down Expand Up @@ -1742,13 +1719,9 @@ if (UNIX OR onnxruntime_USE_NCCL)
endif()
else()
set(onnxruntime_USE_NCCL OFF)
set(onnxruntime_USE_MPI OFF)
message( WARNING "MPI and NCCL are disabled because build is on Windows or USE_NCCL is set to OFF." )
message( WARNING "NCCL is disabled because build is on Windows or USE_NCCL is set to OFF." )
endif()

if (onnxruntime_USE_MPI)
add_definitions(-DUSE_MPI=1)
endif()

# Default version parts for Microsoft.AI.MachineLearning.dll, onnxruntime.dll, onnxruntime_providers_openvino.dll and onnxruntime_providers_shared.dll in non-ADO pipeline local builds
set(VERSION_MAJOR_PART 0 CACHE STRING "First part of numeric file/product version.")
Expand Down
5 changes: 5 additions & 0 deletions cmake/external/onnxruntime_external_deps.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -719,6 +719,11 @@ if (onnxruntime_USE_WEBGPU)
# - (private) Remove hard-coded CMAKE_OSX_DEPLOYMENT_TARGET in Dawn's CMake files
# https://github.com/microsoft/onnxruntime/pull/23729
#
# - (private) Reduce unsafe buffer usage warning in aligned_storage.h
# https://github.com/microsoft/onnxruntime/pull/24308
# The patch disables the UNSAFE_BUFFER_USAGE warning around the AlignedStorage struct in aligned_storage.h. This is done
# by using TINT_BEGIN_DISABLE_WARNING and TINT_END_DISABLE_WARNING macros, which helps in warnings related to unsafe buffer usage
# usage when compiling the code, making the build process cleaner and faster.
#
PATCH_COMMAND ${Patch_EXECUTABLE} --binary --ignore-whitespace -p1 < ${PROJECT_SOURCE_DIR}/patches/dawn/dawn.patch
EXCLUDE_FROM_ALL
Expand Down
3 changes: 0 additions & 3 deletions cmake/onnxruntime_framework.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,6 @@ if (onnxruntime_ENABLE_TRAINING_OPS)
onnxruntime_add_include_to_target(onnxruntime_framework Python::Module dlpack::dlpack)
endif()
endif()
if (onnxruntime_USE_MPI)
target_include_directories(onnxruntime_framework PUBLIC ${MPI_CXX_INCLUDE_DIRS})
endif()

if (onnxruntime_ENABLE_ATEN)
onnxruntime_add_include_to_target(onnxruntime_framework dlpack::dlpack)
Expand Down
2 changes: 1 addition & 1 deletion cmake/onnxruntime_providers_cpu.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ if (onnxruntime_ENABLE_TRAINING)
onnxruntime_add_include_to_target(onnxruntime_providers Python::Module)
endif()

if (onnxruntime_USE_NCCL OR onnxruntime_USE_MPI)
if (onnxruntime_USE_NCCL)
target_include_directories(onnxruntime_providers PUBLIC ${MPI_CXX_INCLUDE_DIRS})
endif()
endif()
Expand Down
4 changes: 0 additions & 4 deletions cmake/onnxruntime_providers_cuda.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -252,10 +252,6 @@
target_include_directories(${target} PRIVATE ${ORTTRAINING_ROOT} ${MPI_CXX_INCLUDE_DIRS})
endif()

if(onnxruntime_USE_MPI)
target_link_libraries(${target} PRIVATE ${MPI_LIBRARIES} ${MPI_CXX_LINK_FLAGS})
endif()

if (onnxruntime_USE_NCCL)
target_include_directories(${target} PRIVATE ${NCCL_INCLUDE_DIRS})
target_link_libraries(${target} PRIVATE ${NCCL_LIBRARIES})
Expand Down
3 changes: 0 additions & 3 deletions cmake/onnxruntime_providers_rocm.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,6 @@

if (onnxruntime_ENABLE_TRAINING)
target_include_directories(onnxruntime_providers_rocm PRIVATE ${ORTTRAINING_ROOT} ${CMAKE_CURRENT_BINARY_DIR}/amdgpu/orttraining ${MPI_CXX_INCLUDE_DIRS})
if(onnxruntime_USE_MPI)
target_link_libraries(onnxruntime_providers_rocm PRIVATE ${MPI_LIBRARIES} ${MPI_CXX_LINK_FLAGS})
endif()

# RCCL is enabled by default for ROCM builds
#if (onnxruntime_USE_NCCL)
Expand Down
21 changes: 21 additions & 0 deletions cmake/patches/dawn/dawn.patch
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,24 @@ index 5bfac41dcc..71a153daaa 100644
void WGPUBufferImpl::Destroy() {
emwgpuBufferDestroy(this);
AbortPendingMap("Buffer was destroyed before mapping was resolved.");
diff --git a/src/tint/utils/memory/aligned_storage.h b/src/tint/utils/memory/aligned_storage.h
index c532c4fc38..19c950af4c 100644
--- a/src/tint/utils/memory/aligned_storage.h
+++ b/src/tint/utils/memory/aligned_storage.h
@@ -31,6 +31,9 @@
#include <cstddef>

#include "src/tint/utils/memory/bitcast.h"
+#include "src/tint/utils/macros/compiler.h"
+
+TINT_BEGIN_DISABLE_WARNING(UNSAFE_BUFFER_USAGE);

namespace tint {

@@ -50,4 +53,6 @@ struct alignas(alignof(T)) AlignedStorage {

} // namespace tint

+TINT_END_DISABLE_WARNING(UNSAFE_BUFFER_USAGE);
+
#endif // SRC_TINT_UTILS_MEMORY_ALIGNED_STORAGE_H_
1 change: 1 addition & 0 deletions java/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ test {
'USE_TENSORRT',
'USE_QNN',
'USE_XNNPACK',
'USE_WEBGPU',
])
testLogging {
events "passed", "skipped", "failed"
Expand Down
12 changes: 12 additions & 0 deletions java/src/main/java/ai/onnxruntime/OrtSession.java
Original file line number Diff line number Diff line change
Expand Up @@ -1339,6 +1339,18 @@ public void addCoreML(Map<String, String> providerOptions) throws OrtException {
addExecutionProvider(CoreMLProviderName, providerOptions);
}

/**
* Adds WebGPU as an execution backend.
*
* @param providerOptions Configuration options for the WebGPU backend. Refer to the WebGPU
* execution provider's documentation.
* @throws OrtException If there was an error in native code.
*/
public void addWebGPU(Map<String, String> providerOptions) throws OrtException {
String webGpuProviderName = "WebGPU";
addExecutionProvider(webGpuProviderName, providerOptions);
}

private native void setExecutionMode(long apiHandle, long nativeHandle, int mode)
throws OrtException;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ class SimpleTest {
runSigmoidModelTestImpl(1, OrtProvider.QNN)
}

@Test
fun runSigmoidModelTestWEBGPU() {
runSigmoidModelTestImpl(1, OrtProvider.WEBGPU)
}

@Throws(IOException::class)
private fun readModel(fileName: String): ByteArray {
return InstrumentationRegistry.getInstrumentation().context.assets.open(fileName)
Expand Down Expand Up @@ -90,6 +95,16 @@ class SimpleTest {
}
}

OrtProvider.WEBGPU -> {
if (OrtEnvironment.getAvailableProviders().contains(OrtProvider.WEBGPU)) {
val providerOptions = Collections.emptyMap<String, String>()
opts.addWebGPU(providerOptions)
} else {
Log.println(Log.INFO, TAG, "NO WEBGPU EP available, skip the test")
return
}
}

OrtProvider.CPU -> {
// No additional configuration is needed for CPU
}
Expand Down
6 changes: 6 additions & 0 deletions java/src/test/java/ai/onnxruntime/InferenceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -749,6 +749,12 @@ public void testQNN() throws OrtException {
runProvider(OrtProvider.QNN);
}

@Test
@EnabledIfSystemProperty(named = "USE_WEBGPU", matches = "1")
public void testWEBGPU() throws OrtException {
runProvider(OrtProvider.WEBGPU);
}

private void runProvider(OrtProvider provider) throws OrtException {
EnumSet<OrtProvider> providers = OrtEnvironment.getAvailableProviders();
assertTrue(providers.size() > 1);
Expand Down
16 changes: 11 additions & 5 deletions js/common/lib/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,22 @@ export declare namespace Env {
numThreads?: number;

/**
* set or get a boolean value indicating whether to enable SIMD. If set to false, SIMD will be forcely disabled.
* set a value indicating whether to enable SIMD.
*
* ONNX Runtime will perform feature detection based on the value of this property. Specifically, when the value is
* set to:
* - `undefined`, `true` or `"fixed"`: will check availability of Fixed-width SIMD.
* - `"relaxed"`: will check availability of Relaxed SIMD.
* - `false`: will not perform SIMD feature checking.
*
* Setting this property does not make ONNX Runtime to switch to the corresponding runtime automatically. User need
* to set `wasmPaths` or `wasmBinary` property to load the corresponding runtime.
*
* This setting is available only when WebAssembly SIMD feature is available in current context.
*
* @defaultValue `true`
*
* @deprecated This property is deprecated. Since SIMD is supported by all major JavaScript engines, non-SIMD
* build is no longer provided. This property will be removed in future release.
*/
simd?: boolean;
simd?: boolean | 'fixed' | 'relaxed';

/**
* set or get a boolean value indicating whether to enable trace.
Expand Down
2 changes: 2 additions & 0 deletions js/web/docs/webnn-operators.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ platforms. Check the [WebNN status](https://webmachinelearning.github.io/webnn-s
| GlobalLpPool| ai.onnx(7+) | l2Pool2d | Only supports 4-D input, 'p' value is 2 |
| Greater | ai.onnx(7-8, 9-12, 13+) | greater | |
| GreaterOrEqual | ai.onnx(12-15, 16+) | greaterOrEqual | |
| GroupQueryAttention | com.microsoft(1+) | add, cast, concat, constant, cumulativeSum, div, expand, lesser, matmul, reshape, scatterND, softmax, transpose, where | Only supports input total_sequence_length is constant and past_sequence_length of past kv equals to present_sequence_length of present kv. Does not support cos_cache and sin_cache inputs |
| GRU | ai.onnx(7-13, 14-21, 22+) | gru | Only supports 'layout' == 0. 'clip' is not supported. The activation functions in 'activations' must be one of 'Relu', 'Tanh', 'Sigmoid'. Forward and backward activations must be the same if bidirectional. 'sequence_lens' if present should be constant with values equal to the first dimension length of input 'X' |
| HardSigmoid | ai.onnx(7+) | hardSigmoid | |
| HardSwish | ai.onnx(14+) | hardSwish | |
Expand All @@ -63,6 +64,7 @@ platforms. Check the [WebNN status](https://webmachinelearning.github.io/webnn-s
| LRN | ai.onnx(7-12, 13+) | pad, averagePool2d, transpose, add, mul, pow, div | |
| LSTM | ai.onnx(7-13, 14-21, 22+) | lstm | Only supports 'layout' == 0, 'input_forget' == 0. 'clip' is not supported. The activation functions in 'activations' must be one of 'Relu', 'Tanh', 'Sigmoid'. Forward and backward activations must be the same if bidirectional. 'sequence_lens' if present should be constant with values equal to the first dimension length of input 'X' |
| MatMul | ai.onnx(7-8, 9-12, 13+) | matmul | |
| MatMulNBits | com.microsoft(1+) | add, dequantizeLinear, matmul, reshape, transpose | Inputs 'B' and 'zero_points' (if present) should be constants, input 'g_idx' is not supported, only bits=4 is supported |
| Max | ai.onnx(7, 8-11, 12, 13+) | max | |
| MaxPool | ai.onnx(7, 8-9, 10, 11, 12+) | maxPool2d | Only supports 4-D input, 2-D 'kernel_shape', 'storage_order' != 1, one output |
| Min | ai.onnx(7, 8-11, 12, 13+) | min | |
Expand Down
7 changes: 4 additions & 3 deletions js/web/lib/backend-wasm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@ export const initializeFlags = (): void => {
env.wasm.initTimeout = 0;
}

if (env.wasm.simd === false) {
const simd = env.wasm.simd;
if (typeof simd !== 'boolean' && simd !== undefined && simd !== 'fixed' && simd !== 'relaxed') {
// eslint-disable-next-line no-console
console.warn(
'Deprecated property "env.wasm.simd" is set to false. ' +
'non-SIMD build is no longer provided, and this setting will be ignored.',
`Property "env.wasm.simd" is set to unknown value "${simd}". Reset it to \`false\` and ignore SIMD feature checking.`,
);
env.wasm.simd = false;
}

if (typeof env.wasm.proxy !== 'boolean') {
Expand Down
37 changes: 36 additions & 1 deletion js/web/lib/wasm/wasm-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,34 @@ const isSimdSupported = (): boolean => {
}
};

const isRelaxedSimdSupported = (): boolean => {
try {
// Test for WebAssembly Relaxed SIMD capability (for both browsers and Node.js)
// This typed array is a WebAssembly program containing Relaxed SIMD instructions.

// The binary data is generated from the following code by wat2wasm:
// (module
// (func (result v128)
// i32.const 1
// i8x16.splat
// i32.const 2
// i8x16.splat
// i32.const 3
// i8x16.splat
// i32x4.relaxed_dot_i8x16_i7x16_add_s
// )
// )
return WebAssembly.validate(
new Uint8Array([
0, 97, 115, 109, 1, 0, 0, 0, 1, 5, 1, 96, 0, 1, 123, 3, 2, 1, 0, 10, 19, 1, 17, 0, 65, 1, 253, 15, 65, 2, 253,
15, 65, 3, 253, 15, 253, 147, 2, 11,
]),
);
} catch (e) {
return false;
}
};

export const initializeWebAssembly = async (flags: Env.WebAssemblyFlags): Promise<void> => {
if (initialized) {
return Promise.resolve();
Expand All @@ -82,7 +110,14 @@ export const initializeWebAssembly = async (flags: Env.WebAssemblyFlags): Promis
let numThreads = flags.numThreads!;

// ensure SIMD is supported
if (!isSimdSupported()) {
if (flags.simd === false) {
// skip SIMD feature checking as it is disabled explicitly by user
} else if (flags.simd === 'relaxed') {
// check if relaxed SIMD is supported
if (!isRelaxedSimdSupported()) {
throw new Error('Relaxed WebAssembly SIMD is not supported in the current environment.');
}
} else if (!isSimdSupported()) {
throw new Error('WebAssembly SIMD is not supported in the current environment.');
}

Expand Down
5 changes: 5 additions & 0 deletions js/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
"browser": "dist/ort.min.js",
"exports": {
".": {
"types": "./types.d.ts",
"node": {
"import": "./dist/ort.node.min.mjs",
"require": "./dist/ort.node.min.js"
Expand All @@ -79,24 +80,28 @@
"require": "./dist/ort.min.js"
},
"./all": {
"types": "./types.d.ts",
"import": {
"onnxruntime-web-use-extern-wasm": "./dist/ort.all.min.mjs",
"default": "./dist/ort.all.bundle.min.mjs"
},
"require": "./dist/ort.all.min.js"
},
"./wasm": {
"types": "./types.d.ts",
"import": {
"onnxruntime-web-use-extern-wasm": "./dist/ort.wasm.min.mjs",
"default": "./dist/ort.wasm.bundle.min.mjs"
},
"require": "./dist/ort.wasm.min.js"
},
"./webgl": {
"types": "./types.d.ts",
"import": "./dist/ort.webgl.min.mjs",
"require": "./dist/ort.webgl.min.js"
},
"./webgpu": {
"types": "./types.d.ts",
"import": {
"onnxruntime-web-use-extern-wasm": "./dist/ort.webgpu.min.mjs",
"default": "./dist/ort.webgpu.bundle.min.mjs"
Expand Down
6 changes: 6 additions & 0 deletions js/web/test/e2e/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,12 @@ async function main() {
await testExportsMain(PRESERVE, PACKAGES_TO_INSTALL);
}

// perform type (typescript related) testing
{
const testTypeMain = require(path.join(TEST_E2E_RUN_FOLDER, './type/main'));
await testTypeMain(PRESERVE, PACKAGES_TO_INSTALL);
}

// prepare .wasm files for path override testing
prepareWasmPathOverrideFiles();

Expand Down
23 changes: 23 additions & 0 deletions js/web/test/e2e/type/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

'use strict';

const path = require('path');
const { installOrtPackages, runShellCmd } = require('./utils');

/**
* Entry point for type tests.
*
* @param {string[]} packagesToInstall
*/
module.exports = async function main(PRESERVE, PACKAGES_TO_INSTALL) {
console.log('Running type tests...');

// testcases/module-resolution
{
await installOrtPackages('module-resolution', PRESERVE, PACKAGES_TO_INSTALL);

await runShellCmd('npx tsc', { wd: path.join(__dirname, 'testcases', 'module-resolution') });
}
};
Loading