Skip to content

Commit a85fe10

Browse files
committed
Base commit for using EMSDK 3.1.74 (LTO disabled)
1 parent 1ce5957 commit a85fe10

File tree

16 files changed

+103
-83
lines changed

16 files changed

+103
-83
lines changed

.gitmodules

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@
77
[submodule "cmake/external/emsdk"]
88
path = cmake/external/emsdk
99
url = https://github.com/emscripten-core/emsdk.git
10-
branch = 3.1.59
10+
branch = 3.1.74

cgmanifests/generated/cgmanifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"component": {
77
"type": "git",
88
"git": {
9-
"commitHash": "d52c46520124845b1e0e0525f2759299d840143f",
9+
"commitHash": "3d6d8ee910466516a53e665b86458faa81dae9ba",
1010
"repositoryUrl": "https://github.com/emscripten-core/emsdk.git"
1111
},
1212
"comments": "git submodule at cmake/external/emsdk"

cmake/CMakeLists.txt

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

cmake/adjust_global_compile_flags.cmake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ if (CMAKE_SYSTEM_NAME STREQUAL "Emscripten")
3838
# (2) "-flto=thin" does not work correctly for wasm-ld.
3939
# we don't set onnxruntime_ENABLE_LTO because it appends flag "-flto=thin"
4040
# instead, we manually set CMAKE_CXX_FLAGS "-flto"
41-
string(APPEND CMAKE_C_FLAGS " -flto")
42-
string(APPEND CMAKE_CXX_FLAGS " -flto")
41+
#string(APPEND CMAKE_C_FLAGS " -flto=thin")
42+
#string(APPEND CMAKE_CXX_FLAGS " -flto=thin")
4343
endif()
4444

4545
if (onnxruntime_ENABLE_WEBASSEMBLY_DEBUG_INFO)

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: 62 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)
@@ -461,4 +466,59 @@ jsepDownload:_pp_")
461466
endif()
462467

463468
set_target_properties(onnxruntime_webassembly PROPERTIES OUTPUT_NAME ${target_name} SUFFIX ".mjs")
469+
470+
#
471+
# The following POST_BUILD script is a workaround for enabling:
472+
# - using onnxruntime-web with Multi-threading enabled when import from CDN
473+
# - using onnxruntime-web when consumed in some frameworks like Vite
474+
#
475+
# In the use case mentioned above, the file name of the script may be changed. So we need to replace the line:
476+
# `new Worker(new URL("ort-wasm-*.mjs", import.meta.url),`
477+
# with
478+
# `new Worker(new URL(import.meta.url),`
479+
#
480+
# This behavior is introduced in https://github.com/emscripten-core/emscripten/pull/22165. Since it's unlikely to be
481+
# reverted, and there is no config to disable this behavior, we have to use a post-build script to workaround it.
482+
#
483+
484+
# Generate a script to do the post-build work
485+
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/wasm_post_build.js "
486+
const fs = require('fs');
487+
const path = require('path');
488+
489+
// node wasm_post_build.js <mjsFilePath>
490+
const mjsFilePath = process.argv[2];
491+
let contents = fs.readFileSync(mjsFilePath).toString();
492+
493+
const regex = 'new Worker\\\\(new URL\\\\(\".+?\", ?import\\\\.meta\\\\.url\\\\),';
494+
const matches = [...contents.matchAll(new RegExp(regex, 'g'))];
495+
if (matches.length !== 1) {
496+
throw new Error(
497+
`Unexpected number of matches for \"${regex}\" in \"${filepath}\": ${matches.length}.`,
498+
);
499+
}
500+
501+
// Replace the only occurrence.
502+
contents = contents.replace(
503+
new RegExp(regex),
504+
`new Worker(new URL(import.meta.url),`,
505+
);
506+
507+
fs.writeFileSync(mjsFilePath, contents);
508+
"
509+
)
510+
511+
find_program(NODE_EXECUTABLE node required)
512+
if (NOT NODE_EXECUTABLE)
513+
message(FATAL_ERROR "Node is required to run the post-build script")
514+
endif()
515+
516+
add_custom_command(
517+
TARGET onnxruntime_webassembly
518+
POST_BUILD
519+
COMMAND ${CMAKE_COMMAND} -E echo "Backup file at $<TARGET_FILE_NAME:onnxruntime_webassembly>.bak"
520+
COMMAND ${CMAKE_COMMAND} -E copy_if_different "$<TARGET_FILE_NAME:onnxruntime_webassembly>" "$<TARGET_FILE_NAME:onnxruntime_webassembly>.bak"
521+
COMMAND ${CMAKE_COMMAND} -E echo "Performing workaround for $<TARGET_FILE_NAME:onnxruntime_webassembly>"
522+
COMMAND ${NODE_EXECUTABLE} "${CMAKE_CURRENT_BINARY_DIR}/wasm_post_build.js" "$<TARGET_FILE_NAME:onnxruntime_webassembly>"
523+
)
464524
endif()

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

0 commit comments

Comments
 (0)