mirror of
https://github.com/saymrwulf/onnxruntime.git
synced 2026-05-18 21:21:17 +00:00
Pre-requisites of upgrading EMSDK
This commit is contained in:
parent
80d8931f1d
commit
a82c24eb03
10 changed files with 38 additions and 73 deletions
|
|
@ -679,6 +679,7 @@ else()
|
|||
check_cxx_compiler_flag(-Wdeprecated-builtins HAS_DEPRECATED_BUILTINS)
|
||||
check_cxx_compiler_flag(-Wdeprecated-copy HAS_DEPRECATED_COPY)
|
||||
check_cxx_compiler_flag(-Wdeprecated-declarations HAS_DEPRECATED_DECLARATIONS)
|
||||
check_cxx_compiler_flag(-Wdeprecated-literal-operator HAS_DEPRECATED_LITERAL_OPERATOR)
|
||||
check_cxx_compiler_flag(-Wdeprecated-this-capture HAS_DEPRECATED_THIS_CAPTURE)
|
||||
check_cxx_compiler_flag(-Wenum-constexpr-conversion HAS_ENUM_CONSTEXPR_CONVERSION)
|
||||
check_cxx_compiler_flag(-Wformat-truncation HAS_FORMAT_TRUNCATION)
|
||||
|
|
@ -735,6 +736,9 @@ else()
|
|||
if (HAS_DEPRECATED_BUILTINS)
|
||||
list(APPEND ORT_WARNING_FLAGS -Wno-deprecated-builtins)
|
||||
endif()
|
||||
if (HAS_DEPRECATED_LITERAL_OPERATOR)
|
||||
list(APPEND ORT_WARNING_FLAGS -Wno-deprecated-literal-operator)
|
||||
endif()
|
||||
#see:https://reviews.llvm.org/D131307
|
||||
#It was intended that the 'enum-constexpr-conversion' type warnings can not be silenced by -w
|
||||
if(HAS_ENUM_CONSTEXPR_CONVERSION AND NOT Protobuf_FOUND)
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@
|
|||
#cmakedefine HAS_CLASS_MEMACCESS
|
||||
#cmakedefine HAS_DEPRECATED_COPY
|
||||
#cmakedefine HAS_DEPRECATED_DECLARATIONS
|
||||
#cmakedefine HAS_DEPRECATED_LITERAL_OPERATOR
|
||||
#cmakedefine HAS_DEPRECATED_THIS_CAPTURE
|
||||
#cmakedefine HAS_FORMAT_TRUNCATION
|
||||
#cmakedefine HAS_IGNORED_ATTRIBUTES
|
||||
|
|
|
|||
|
|
@ -221,19 +221,11 @@ function(AddTest)
|
|||
)
|
||||
else()
|
||||
set(TEST_NODE_FLAGS)
|
||||
if (onnxruntime_ENABLE_WEBASSEMBLY_THREADS)
|
||||
list(APPEND TEST_NODE_FLAGS "--experimental-wasm-threads")
|
||||
endif()
|
||||
if (onnxruntime_ENABLE_WEBASSEMBLY_SIMD)
|
||||
list(APPEND TEST_NODE_FLAGS "--experimental-wasm-simd")
|
||||
endif()
|
||||
|
||||
# prefer Node from emsdk so the version is more deterministic
|
||||
if (DEFINED ENV{EMSDK_NODE})
|
||||
set(NODE_EXECUTABLE $ENV{EMSDK_NODE})
|
||||
else()
|
||||
# warning as we don't know what node version is being used and whether things like the TEST_NODE_FLAGS
|
||||
# will be valid. e.g. "--experimental-wasm-simd" is not valid with node v20 or later.
|
||||
message(WARNING "EMSDK_NODE environment variable was not set. Falling back to system `node`.")
|
||||
set(NODE_EXECUTABLE node)
|
||||
endif()
|
||||
|
|
|
|||
|
|
@ -380,10 +380,15 @@ jsepDownload:_pp_")
|
|||
"SHELL:--pre-js \"${ONNXRUNTIME_ROOT}/wasm/pre-jsep.js\""
|
||||
"SHELL:-s ASYNCIFY=1"
|
||||
"SHELL:-s ASYNCIFY_STACK_SIZE=65536"
|
||||
"SHELL:-s ASYNCIFY_EXPORTS=['OrtRun']"
|
||||
"SHELL:-s ASYNCIFY_IMPORTS=['Module.jsepCopy','Module.jsepCopyAsync','jsepDownload']"
|
||||
)
|
||||
set_target_properties(onnxruntime_webassembly PROPERTIES LINK_DEPENDS ${ONNXRUNTIME_ROOT}/wasm/pre-jsep.js)
|
||||
|
||||
if (onnxruntime_ENABLE_WEBASSEMBLY_MEMORY64)
|
||||
target_link_options(onnxruntime_webassembly PRIVATE
|
||||
"SHELL:-s ASYNCIFY_EXPORTS=['OrtRun']"
|
||||
"SHELL:-s ASYNCIFY_IMPORTS=['Module.jsepCopy','Module.jsepCopyAsync','jsepDownload']"
|
||||
)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if (onnxruntime_EMSCRIPTEN_SETTINGS)
|
||||
|
|
|
|||
|
|
@ -261,19 +261,19 @@ struct BFloat16 : onnxruntime_float16::BFloat16Impl<BFloat16> {
|
|||
// initializers with MLFloat16 and BFloat16 from unsigned short
|
||||
// E.g 10_f16 or 10_b16
|
||||
#if !defined(__CUDACC__) && !defined(__HIPCC__)
|
||||
inline MLFloat16 operator"" _f16(unsigned long long int v) noexcept {
|
||||
inline MLFloat16 operator""_f16(unsigned long long int v) noexcept {
|
||||
return MLFloat16::FromBits(narrow<uint16_t>(v));
|
||||
}
|
||||
|
||||
inline MLFloat16 operator"" _fp16(long double v) noexcept {
|
||||
inline MLFloat16 operator""_fp16(long double v) noexcept {
|
||||
return MLFloat16(static_cast<float>(v));
|
||||
}
|
||||
|
||||
inline BFloat16 operator"" _b16(unsigned long long int v) noexcept {
|
||||
inline BFloat16 operator""_b16(unsigned long long int v) noexcept {
|
||||
return BFloat16::FromBits((narrow<uint16_t>(v)));
|
||||
}
|
||||
|
||||
inline BFloat16 operator"" _bfp16(long double v) noexcept {
|
||||
inline BFloat16 operator""_bfp16(long double v) noexcept {
|
||||
return BFloat16(static_cast<float>(v));
|
||||
}
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -165,11 +165,11 @@ inline ORT_HOST_DEVICE bool operator<(const Float8E4M3FN& left, const Float8E4M3
|
|||
// initializers with MLFloat8E4M3FN and Float8E4M3FN from unsigned char
|
||||
#if !defined(__CUDACC__) && !defined(__HIPCC__)
|
||||
|
||||
inline Float8E4M3FN operator"" _f8e4m3fn(unsigned long long int v) {
|
||||
inline Float8E4M3FN operator""_f8e4m3fn(unsigned long long int v) {
|
||||
return Float8E4M3FN(narrow<uint8_t>(v), Float8E4M3FN::FromBits());
|
||||
}
|
||||
|
||||
inline Float8E4M3FN operator"" _f8e4m3fnp8(long double v) {
|
||||
inline Float8E4M3FN operator""_f8e4m3fnp8(long double v) {
|
||||
return Float8E4M3FN(static_cast<float>(v), true);
|
||||
}
|
||||
|
||||
|
|
@ -323,11 +323,11 @@ inline ORT_HOST_DEVICE bool operator<(const Float8E4M3FNUZ& left, const Float8E4
|
|||
// initializers with MLFloat8E4M3FN and Float8E4M3FN from unsigned char
|
||||
#if !defined(__CUDACC__) && !defined(__HIPCC__)
|
||||
|
||||
inline Float8E4M3FNUZ operator"" _f8e4m3p8fnuz(unsigned long long int v) {
|
||||
inline Float8E4M3FNUZ operator""_f8e4m3p8fnuz(unsigned long long int v) {
|
||||
return Float8E4M3FNUZ(narrow<uint8_t>(v), Float8E4M3FNUZ::FromBits());
|
||||
}
|
||||
|
||||
inline Float8E4M3FNUZ operator"" _f8e4m3fnuzp8(long double v) {
|
||||
inline Float8E4M3FNUZ operator""_f8e4m3fnuzp8(long double v) {
|
||||
return Float8E4M3FNUZ(static_cast<float>(v), true);
|
||||
}
|
||||
|
||||
|
|
@ -493,11 +493,11 @@ inline ORT_HOST_DEVICE bool operator<(const Float8E5M2& left, const Float8E5M2&
|
|||
// initializers with MLFloat8E5M2 and Float8E5M2 from unsigned char
|
||||
#if !defined(__CUDACC__) && !defined(__HIPCC__)
|
||||
|
||||
inline Float8E5M2 operator"" _f8e5m2fn(unsigned long long int v) {
|
||||
inline Float8E5M2 operator""_f8e5m2fn(unsigned long long int v) {
|
||||
return Float8E5M2(narrow<uint8_t>(v), Float8E5M2::FromBits());
|
||||
}
|
||||
|
||||
inline Float8E5M2 operator"" _f8e5m2fnp8(long double v) {
|
||||
inline Float8E5M2 operator""_f8e5m2fnp8(long double v) {
|
||||
return Float8E5M2(static_cast<float>(v), true);
|
||||
}
|
||||
|
||||
|
|
@ -642,11 +642,11 @@ inline ORT_HOST_DEVICE bool operator<(const Float8E5M2FNUZ& left, const Float8E5
|
|||
// initializers with MLFloat8E5M2 and Float8E5M2 from unsigned char
|
||||
#if !defined(__CUDACC__) && !defined(__HIPCC__)
|
||||
|
||||
inline Float8E5M2FNUZ operator"" _f8e5m2fnuz(unsigned long long int v) {
|
||||
inline Float8E5M2FNUZ operator""_f8e5m2fnuz(unsigned long long int v) {
|
||||
return Float8E5M2FNUZ(narrow<uint8_t>(v), Float8E5M2FNUZ::FromBits());
|
||||
}
|
||||
|
||||
inline Float8E5M2FNUZ operator"" _f8e5m2fnuzp8(long double v) {
|
||||
inline Float8E5M2FNUZ operator""_f8e5m2fnuzp8(long double v) {
|
||||
return Float8E5M2FNUZ(static_cast<float>(v), true);
|
||||
}
|
||||
|
||||
|
|
|
|||
14
js/package-lock.json
generated
14
js/package-lock.json
generated
|
|
@ -29,7 +29,7 @@
|
|||
"mocha": "^11.0.1",
|
||||
"npmlog": "^7.0.1",
|
||||
"prettier": "^3.3.3",
|
||||
"terser": "^5.31.0",
|
||||
"terser": "^5.37.0",
|
||||
"typescript": "^5.2.2"
|
||||
}
|
||||
},
|
||||
|
|
@ -4783,9 +4783,9 @@
|
|||
}
|
||||
},
|
||||
"node_modules/terser": {
|
||||
"version": "5.31.0",
|
||||
"resolved": "https://registry.npmjs.org/terser/-/terser-5.31.0.tgz",
|
||||
"integrity": "sha512-Q1JFAoUKE5IMfI4Z/lkE/E6+SwgzO+x4tq4v1AyBLRj8VSYvRO6A/rQrPg1yud4g0En9EKI1TvFRF2tQFcoUkg==",
|
||||
"version": "5.37.0",
|
||||
"resolved": "https://registry.npmjs.org/terser/-/terser-5.37.0.tgz",
|
||||
"integrity": "sha512-B8wRRkmre4ERucLM/uXx4MOV5cbnOlVAqUst+1+iLKPI0dOgFO28f84ptoQt9HEI537PMzfYa/d+GEPKTRXmYA==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"@jridgewell/source-map": "^0.3.3",
|
||||
|
|
@ -8518,9 +8518,9 @@
|
|||
"dev": true
|
||||
},
|
||||
"terser": {
|
||||
"version": "5.31.0",
|
||||
"resolved": "https://registry.npmjs.org/terser/-/terser-5.31.0.tgz",
|
||||
"integrity": "sha512-Q1JFAoUKE5IMfI4Z/lkE/E6+SwgzO+x4tq4v1AyBLRj8VSYvRO6A/rQrPg1yud4g0En9EKI1TvFRF2tQFcoUkg==",
|
||||
"version": "5.37.0",
|
||||
"resolved": "https://registry.npmjs.org/terser/-/terser-5.37.0.tgz",
|
||||
"integrity": "sha512-B8wRRkmre4ERucLM/uXx4MOV5cbnOlVAqUst+1+iLKPI0dOgFO28f84ptoQt9HEI537PMzfYa/d+GEPKTRXmYA==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@jridgewell/source-map": "^0.3.3",
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@
|
|||
"mocha": "^11.0.1",
|
||||
"npmlog": "^7.0.1",
|
||||
"prettier": "^3.3.3",
|
||||
"terser": "^5.31.0",
|
||||
"terser": "^5.37.0",
|
||||
"typescript": "^5.2.2"
|
||||
},
|
||||
"scripts": {
|
||||
|
|
|
|||
|
|
@ -145,51 +145,15 @@ async function minifyWasmModuleJsForBrowser(filepath: string): Promise<string> {
|
|||
`new Worker(import.meta.url.startsWith('file:')?new URL(BUILD_DEFS.BUNDLE_FILENAME, import.meta.url):new URL(import.meta.url),`,
|
||||
);
|
||||
|
||||
// Find the first and the only occurrence of minified function implementation of "_emscripten_thread_set_strongref":
|
||||
// ```js
|
||||
// _emscripten_thread_set_strongref: (thread) => {
|
||||
// if (ENVIRONMENT_IS_NODE) {
|
||||
// PThread.pthreads[thread].ref();
|
||||
// }
|
||||
// }
|
||||
// ```
|
||||
//
|
||||
// It is minified to: (example)
|
||||
// ```js
|
||||
// function Pb(a){D&&N[a>>>0].ref()}
|
||||
// ```
|
||||
|
||||
// The following code will look for the function name and mark the function call as pure, so that Terser will
|
||||
// minify the code correctly.
|
||||
|
||||
const markedAsPure = [];
|
||||
// First, try if we are working on the original (not minified) source file. This is when we are working with the
|
||||
// debug build.
|
||||
const isOriginal = contents.includes('PThread.pthreads[thread].ref()');
|
||||
if (isOriginal) {
|
||||
markedAsPure.push('PThread.pthreads[thread].ref');
|
||||
} else {
|
||||
// If it is not the original source file, we need to find the minified function call.
|
||||
const matches = [...contents.matchAll(/\{[_a-zA-Z][_a-zA-Z0-9]*&&([_a-zA-Z][_a-zA-Z0-9]*\[.+?]\.ref)\(\)}/g)];
|
||||
if (matches.length !== 1) {
|
||||
throw new Error(
|
||||
`Unexpected number of matches for minified "PThread.pthreads[thread].ref()" in "${filepath}": ${
|
||||
matches.length
|
||||
}.`,
|
||||
);
|
||||
}
|
||||
// matches[0] is the first and the only match.
|
||||
// matches[0][0] is the full matched string and matches[0][1] is the first capturing group.
|
||||
markedAsPure.push(matches[0][1]);
|
||||
}
|
||||
|
||||
// Use terser to minify the code with special configurations:
|
||||
// - use `global_defs` to define `process` and `globalThis.process` as `undefined`, so terser can tree-shake the
|
||||
// Node.js specific code.
|
||||
const terser = await import('terser');
|
||||
const result = await terser.minify(contents, {
|
||||
module: true,
|
||||
compress: {
|
||||
passes: 2,
|
||||
global_defs: { process: undefined, 'globalThis.process': undefined },
|
||||
pure_funcs: markedAsPure,
|
||||
},
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -1,14 +1,13 @@
|
|||
import * as ort from 'onnxruntime-web';
|
||||
|
||||
// The following line uses Vite's "Explicit URL Imports" feature to load the wasm files as asset.
|
||||
// The following line uses Vite's "Explicit URL Imports" feature to load the wasm file as asset.
|
||||
//
|
||||
// see https://vite.dev/guide/assets.html#explicit-url-imports
|
||||
//
|
||||
import wasmFileUrl from '/node_modules/onnxruntime-web/dist/ort-wasm-simd-threaded.jsep.wasm?url';
|
||||
import mjsFileUrl from '/node_modules/onnxruntime-web/dist/ort-wasm-simd-threaded.jsep.mjs?url';
|
||||
|
||||
// wasmFileUrl is a string that contains the URL of the wasm file.
|
||||
ort.env.wasm.wasmPaths = { wasm: wasmFileUrl, mjs: mjsFileUrl };
|
||||
// wasmFileUrl is the URL of the wasm file. Vite will make sure it's available in both development and production.
|
||||
ort.env.wasm.wasmPaths = { wasm: wasmFileUrl };
|
||||
|
||||
// Model data for "test_abs/model.onnx"
|
||||
const testModelData =
|
||||
|
|
|
|||
Loading…
Reference in a new issue