Skip to content

Commit 444fceb

Browse files
fs-eireCopilot
andauthored
Pre-requisites of upgrading EMSDK (#23347)
### Description This PR contains a part of the changes in #23318. The reason of creating this PR is: The works to support building WebGPU EP in WASM depends on #23318, which cannot be merged since it's blocked by upstream (llvm/llvm-project#122166). This PR contains the changes can be safely merged separately and can unblock the development of supporting building WebGPU EP in WASM. --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 4a0269a commit 444fceb

File tree

10 files changed

+38
-73
lines changed

10 files changed

+38
-73
lines changed

cmake/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -680,6 +680,7 @@ else()
680680
check_cxx_compiler_flag(-Wdeprecated-builtins HAS_DEPRECATED_BUILTINS)
681681
check_cxx_compiler_flag(-Wdeprecated-copy HAS_DEPRECATED_COPY)
682682
check_cxx_compiler_flag(-Wdeprecated-declarations HAS_DEPRECATED_DECLARATIONS)
683+
check_cxx_compiler_flag(-Wdeprecated-literal-operator HAS_DEPRECATED_LITERAL_OPERATOR)
683684
check_cxx_compiler_flag(-Wdeprecated-this-capture HAS_DEPRECATED_THIS_CAPTURE)
684685
check_cxx_compiler_flag(-Wenum-constexpr-conversion HAS_ENUM_CONSTEXPR_CONVERSION)
685686
check_cxx_compiler_flag(-Wformat-truncation HAS_FORMAT_TRUNCATION)
@@ -736,6 +737,9 @@ else()
736737
if (HAS_DEPRECATED_BUILTINS)
737738
list(APPEND ORT_WARNING_FLAGS -Wno-deprecated-builtins)
738739
endif()
740+
if (HAS_DEPRECATED_LITERAL_OPERATOR)
741+
list(APPEND ORT_WARNING_FLAGS -Wno-deprecated-literal-operator)
742+
endif()
739743
#see:https://reviews.llvm.org/D131307
740744
#It was intended that the 'enum-constexpr-conversion' type warnings can not be silenced by -w
741745
if(HAS_ENUM_CONSTEXPR_CONVERSION AND NOT Protobuf_FOUND)

cmake/onnxruntime_config.h.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#cmakedefine HAS_CLASS_MEMACCESS
1010
#cmakedefine HAS_DEPRECATED_COPY
1111
#cmakedefine HAS_DEPRECATED_DECLARATIONS
12+
#cmakedefine HAS_DEPRECATED_LITERAL_OPERATOR
1213
#cmakedefine HAS_DEPRECATED_THIS_CAPTURE
1314
#cmakedefine HAS_FORMAT_TRUNCATION
1415
#cmakedefine HAS_IGNORED_ATTRIBUTES

cmake/onnxruntime_unittests.cmake

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -221,19 +221,11 @@ function(AddTest)
221221
)
222222
else()
223223
set(TEST_NODE_FLAGS)
224-
if (onnxruntime_ENABLE_WEBASSEMBLY_THREADS)
225-
list(APPEND TEST_NODE_FLAGS "--experimental-wasm-threads")
226-
endif()
227-
if (onnxruntime_ENABLE_WEBASSEMBLY_SIMD)
228-
list(APPEND TEST_NODE_FLAGS "--experimental-wasm-simd")
229-
endif()
230224

231225
# prefer Node from emsdk so the version is more deterministic
232226
if (DEFINED ENV{EMSDK_NODE})
233227
set(NODE_EXECUTABLE $ENV{EMSDK_NODE})
234228
else()
235-
# warning as we don't know what node version is being used and whether things like the TEST_NODE_FLAGS
236-
# will be valid. e.g. "--experimental-wasm-simd" is not valid with node v20 or later.
237229
message(WARNING "EMSDK_NODE environment variable was not set. Falling back to system `node`.")
238230
set(NODE_EXECUTABLE node)
239231
endif()

cmake/onnxruntime_webassembly.cmake

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -380,10 +380,15 @@ jsepDownload:_pp_")
380380
"SHELL:--pre-js \"${ONNXRUNTIME_ROOT}/wasm/pre-jsep.js\""
381381
"SHELL:-s ASYNCIFY=1"
382382
"SHELL:-s ASYNCIFY_STACK_SIZE=65536"
383-
"SHELL:-s ASYNCIFY_EXPORTS=['OrtRun']"
384-
"SHELL:-s ASYNCIFY_IMPORTS=['Module.jsepCopy','Module.jsepCopyAsync','jsepDownload']"
385383
)
386384
set_target_properties(onnxruntime_webassembly PROPERTIES LINK_DEPENDS ${ONNXRUNTIME_ROOT}/wasm/pre-jsep.js)
385+
386+
if (onnxruntime_ENABLE_WEBASSEMBLY_MEMORY64)
387+
target_link_options(onnxruntime_webassembly PRIVATE
388+
"SHELL:-s ASYNCIFY_EXPORTS=['OrtRun']"
389+
"SHELL:-s ASYNCIFY_IMPORTS=['Module.jsepCopy','Module.jsepCopyAsync','jsepDownload']"
390+
)
391+
endif()
387392
endif()
388393

389394
if (onnxruntime_EMSCRIPTEN_SETTINGS)

include/onnxruntime/core/framework/float16.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -261,19 +261,19 @@ struct BFloat16 : onnxruntime_float16::BFloat16Impl<BFloat16> {
261261
// initializers with MLFloat16 and BFloat16 from unsigned short
262262
// E.g 10_f16 or 10_b16
263263
#if !defined(__CUDACC__) && !defined(__HIPCC__)
264-
inline MLFloat16 operator"" _f16(unsigned long long int v) noexcept {
264+
inline MLFloat16 operator""_f16(unsigned long long int v) noexcept {
265265
return MLFloat16::FromBits(narrow<uint16_t>(v));
266266
}
267267

268-
inline MLFloat16 operator"" _fp16(long double v) noexcept {
268+
inline MLFloat16 operator""_fp16(long double v) noexcept {
269269
return MLFloat16(static_cast<float>(v));
270270
}
271271

272-
inline BFloat16 operator"" _b16(unsigned long long int v) noexcept {
272+
inline BFloat16 operator""_b16(unsigned long long int v) noexcept {
273273
return BFloat16::FromBits((narrow<uint16_t>(v)));
274274
}
275275

276-
inline BFloat16 operator"" _bfp16(long double v) noexcept {
276+
inline BFloat16 operator""_bfp16(long double v) noexcept {
277277
return BFloat16(static_cast<float>(v));
278278
}
279279
#endif

include/onnxruntime/core/framework/float8.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -165,11 +165,11 @@ inline ORT_HOST_DEVICE bool operator<(const Float8E4M3FN& left, const Float8E4M3
165165
// initializers with MLFloat8E4M3FN and Float8E4M3FN from unsigned char
166166
#if !defined(__CUDACC__) && !defined(__HIPCC__)
167167

168-
inline Float8E4M3FN operator"" _f8e4m3fn(unsigned long long int v) {
168+
inline Float8E4M3FN operator""_f8e4m3fn(unsigned long long int v) {
169169
return Float8E4M3FN(narrow<uint8_t>(v), Float8E4M3FN::FromBits());
170170
}
171171

172-
inline Float8E4M3FN operator"" _f8e4m3fnp8(long double v) {
172+
inline Float8E4M3FN operator""_f8e4m3fnp8(long double v) {
173173
return Float8E4M3FN(static_cast<float>(v), true);
174174
}
175175

@@ -323,11 +323,11 @@ inline ORT_HOST_DEVICE bool operator<(const Float8E4M3FNUZ& left, const Float8E4
323323
// initializers with MLFloat8E4M3FN and Float8E4M3FN from unsigned char
324324
#if !defined(__CUDACC__) && !defined(__HIPCC__)
325325

326-
inline Float8E4M3FNUZ operator"" _f8e4m3p8fnuz(unsigned long long int v) {
326+
inline Float8E4M3FNUZ operator""_f8e4m3p8fnuz(unsigned long long int v) {
327327
return Float8E4M3FNUZ(narrow<uint8_t>(v), Float8E4M3FNUZ::FromBits());
328328
}
329329

330-
inline Float8E4M3FNUZ operator"" _f8e4m3fnuzp8(long double v) {
330+
inline Float8E4M3FNUZ operator""_f8e4m3fnuzp8(long double v) {
331331
return Float8E4M3FNUZ(static_cast<float>(v), true);
332332
}
333333

@@ -493,11 +493,11 @@ inline ORT_HOST_DEVICE bool operator<(const Float8E5M2& left, const Float8E5M2&
493493
// initializers with MLFloat8E5M2 and Float8E5M2 from unsigned char
494494
#if !defined(__CUDACC__) && !defined(__HIPCC__)
495495

496-
inline Float8E5M2 operator"" _f8e5m2fn(unsigned long long int v) {
496+
inline Float8E5M2 operator""_f8e5m2fn(unsigned long long int v) {
497497
return Float8E5M2(narrow<uint8_t>(v), Float8E5M2::FromBits());
498498
}
499499

500-
inline Float8E5M2 operator"" _f8e5m2fnp8(long double v) {
500+
inline Float8E5M2 operator""_f8e5m2fnp8(long double v) {
501501
return Float8E5M2(static_cast<float>(v), true);
502502
}
503503

@@ -642,11 +642,11 @@ inline ORT_HOST_DEVICE bool operator<(const Float8E5M2FNUZ& left, const Float8E5
642642
// initializers with MLFloat8E5M2 and Float8E5M2 from unsigned char
643643
#if !defined(__CUDACC__) && !defined(__HIPCC__)
644644

645-
inline Float8E5M2FNUZ operator"" _f8e5m2fnuz(unsigned long long int v) {
645+
inline Float8E5M2FNUZ operator""_f8e5m2fnuz(unsigned long long int v) {
646646
return Float8E5M2FNUZ(narrow<uint8_t>(v), Float8E5M2FNUZ::FromBits());
647647
}
648648

649-
inline Float8E5M2FNUZ operator"" _f8e5m2fnuzp8(long double v) {
649+
inline Float8E5M2FNUZ operator""_f8e5m2fnuzp8(long double v) {
650650
return Float8E5M2FNUZ(static_cast<float>(v), true);
651651
}
652652

js/package-lock.json

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"mocha": "^11.0.1",
2424
"npmlog": "^7.0.1",
2525
"prettier": "^3.3.3",
26-
"terser": "^5.31.0",
26+
"terser": "^5.37.0",
2727
"typescript": "^5.2.2"
2828
},
2929
"scripts": {

js/web/script/build.ts

Lines changed: 3 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -145,51 +145,15 @@ async function minifyWasmModuleJsForBrowser(filepath: string): Promise<string> {
145145
`new Worker(import.meta.url.startsWith('file:')?new URL(BUILD_DEFS.BUNDLE_FILENAME, import.meta.url):new URL(import.meta.url),`,
146146
);
147147

148-
// Find the first and the only occurrence of minified function implementation of "_emscripten_thread_set_strongref":
149-
// ```js
150-
// _emscripten_thread_set_strongref: (thread) => {
151-
// if (ENVIRONMENT_IS_NODE) {
152-
// PThread.pthreads[thread].ref();
153-
// }
154-
// }
155-
// ```
156-
//
157-
// It is minified to: (example)
158-
// ```js
159-
// function Pb(a){D&&N[a>>>0].ref()}
160-
// ```
161-
162-
// The following code will look for the function name and mark the function call as pure, so that Terser will
163-
// minify the code correctly.
164-
165-
const markedAsPure = [];
166-
// First, try if we are working on the original (not minified) source file. This is when we are working with the
167-
// debug build.
168-
const isOriginal = contents.includes('PThread.pthreads[thread].ref()');
169-
if (isOriginal) {
170-
markedAsPure.push('PThread.pthreads[thread].ref');
171-
} else {
172-
// If it is not the original source file, we need to find the minified function call.
173-
const matches = [...contents.matchAll(/\{[_a-zA-Z][_a-zA-Z0-9]*&&([_a-zA-Z][_a-zA-Z0-9]*\[.+?]\.ref)\(\)}/g)];
174-
if (matches.length !== 1) {
175-
throw new Error(
176-
`Unexpected number of matches for minified "PThread.pthreads[thread].ref()" in "${filepath}": ${
177-
matches.length
178-
}.`,
179-
);
180-
}
181-
// matches[0] is the first and the only match.
182-
// matches[0][0] is the full matched string and matches[0][1] is the first capturing group.
183-
markedAsPure.push(matches[0][1]);
184-
}
185-
148+
// Use terser to minify the code with special configurations:
149+
// - use `global_defs` to define `process` and `globalThis.process` as `undefined`, so terser can tree-shake the
150+
// Node.js specific code.
186151
const terser = await import('terser');
187152
const result = await terser.minify(contents, {
188153
module: true,
189154
compress: {
190155
passes: 2,
191156
global_defs: { process: undefined, 'globalThis.process': undefined },
192-
pure_funcs: markedAsPure,
193157
},
194158
});
195159

js/web/test/e2e/exports/testcases/vite-default/src/components/onnx-helper.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
import * as ort from 'onnxruntime-web';
22

3-
// The following line uses Vite's "Explicit URL Imports" feature to load the wasm files as asset.
3+
// The following line uses Vite's "Explicit URL Imports" feature to load the wasm file as an asset.
44
//
55
// see https://vite.dev/guide/assets.html#explicit-url-imports
66
//
77
import wasmFileUrl from '/node_modules/onnxruntime-web/dist/ort-wasm-simd-threaded.jsep.wasm?url';
8-
import mjsFileUrl from '/node_modules/onnxruntime-web/dist/ort-wasm-simd-threaded.jsep.mjs?url';
98

10-
// wasmFileUrl is a string that contains the URL of the wasm file.
11-
ort.env.wasm.wasmPaths = { wasm: wasmFileUrl, mjs: mjsFileUrl };
9+
// wasmFileUrl is the URL of the wasm file. Vite will make sure it's available in both development and production.
10+
ort.env.wasm.wasmPaths = { wasm: wasmFileUrl };
1211

1312
// Model data for "test_abs/model.onnx"
1413
const testModelData =

0 commit comments

Comments
 (0)