onnxruntime-node 1.17.0 → 1.17.3-rev.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +23 -5
- package/bin/napi-v3/darwin/arm64/{libonnxruntime.1.17.0.dylib → libonnxruntime.1.17.3.dylib} +0 -0
- package/bin/napi-v3/darwin/arm64/onnxruntime_binding.node +0 -0
- package/bin/napi-v3/darwin/x64/{libonnxruntime.1.17.0.dylib → libonnxruntime.1.17.3.dylib} +0 -0
- package/bin/napi-v3/darwin/x64/onnxruntime_binding.node +0 -0
- package/bin/napi-v3/linux/arm64/{libonnxruntime.so.1.17.0 → libonnxruntime.so.1.17.3} +0 -0
- package/bin/napi-v3/linux/arm64/onnxruntime_binding.node +0 -0
- package/bin/napi-v3/linux/x64/{libonnxruntime.so.1.17.0 → libonnxruntime.so.1.17.3} +0 -0
- package/bin/napi-v3/linux/x64/libonnxruntime_providers_shared.so +0 -0
- package/bin/napi-v3/linux/x64/onnxruntime_binding.node +0 -0
- package/bin/napi-v3/win32/arm64/DirectML.dll +0 -0
- package/bin/napi-v3/win32/arm64/onnxruntime.dll +0 -0
- package/bin/napi-v3/win32/arm64/onnxruntime_binding.node +0 -0
- package/bin/napi-v3/win32/x64/DirectML.dll +0 -0
- package/bin/napi-v3/win32/x64/onnxruntime.dll +0 -0
- package/bin/napi-v3/win32/x64/onnxruntime_binding.node +0 -0
- package/dist/backend.js +2 -2
- package/dist/backend.js.map +1 -1
- package/dist/version.js +1 -1
- package/dist/version.js.map +1 -1
- package/lib/backend.ts +2 -2
- package/lib/version.ts +1 -1
- package/package.json +4 -2
- package/script/build.js +124 -0
- package/script/build.ts +106 -0
- package/script/install.js +140 -0
- package/script/prepack.js +42 -0
- package/script/prepack.ts +20 -0
- package/bin/napi-v3/win32/arm64/onnxruntime_providers_shared.dll +0 -0
- package/bin/napi-v3/win32/x64/onnxruntime_providers_shared.dll +0 -0
package/README.md
CHANGED
|
@@ -14,13 +14,17 @@ Refer to [ONNX Runtime JavaScript examples](https://github.com/microsoft/onnxrun
|
|
|
14
14
|
|
|
15
15
|
## Requirements
|
|
16
16
|
|
|
17
|
-
ONNXRuntime works on Node.js
|
|
17
|
+
ONNXRuntime works on Node.js v16.x+ (recommend v18.x+) or Electron v15.x+ (recommend v28.x+).
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
The following table lists the supported versions of ONNX Runtime Node.js binding provided with pre-built binaries.
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
| EPs/Platforms | Windows x64 | Windows arm64 | Linux x64 | Linux arm64 | MacOS x64 | MacOS arm64 |
|
|
22
|
+
| ------------- | ----------- | ------------- | ----------------- | ----------- | --------- | ----------- |
|
|
23
|
+
| CPU | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ |
|
|
24
|
+
| DirectML | ✔️ | ✔️ | ❌ | ❌ | ❌ | ❌ |
|
|
25
|
+
| CUDA | ❌ | ❌ | ✔️<sup>\[1]</sup> | ❌ | ❌ | ❌ |
|
|
26
|
+
|
|
27
|
+
- \[1]: CUDA v11.8.
|
|
24
28
|
|
|
25
29
|
To use on platforms without pre-built binaries, you can build Node.js binding from source and consume it by `npm install <onnxruntime_repo_root>/js/node/`. See also [instructions](https://onnxruntime.ai/docs/build/inferencing.html#apis-and-language-bindings) for building ONNX Runtime Node.js binding locally.
|
|
26
30
|
|
|
@@ -28,6 +32,20 @@ To use on platforms without pre-built binaries, you can build Node.js binding fr
|
|
|
28
32
|
|
|
29
33
|
Right now, the Windows version supports only the DML provider. Linux x64 can use CUDA and TensorRT.
|
|
30
34
|
|
|
35
|
+
## CUDA EP Installation
|
|
36
|
+
|
|
37
|
+
To use CUDA EP, you need to install the CUDA EP binaries. By default, the CUDA EP binaries are installed automatically when you install the package. If you want to skip the installation, you can pass the `--onnxruntime-node-install-cuda=skip` flag to the installation command.
|
|
38
|
+
|
|
39
|
+
```
|
|
40
|
+
npm install onnxruntime-node --onnxruntime-node-install-cuda=skip
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
You can also use this flag to specify the version of the CUDA: (v11 or v12)
|
|
44
|
+
|
|
45
|
+
```
|
|
46
|
+
npm install onnxruntime-node --onnxruntime-node-install-cuda=v12
|
|
47
|
+
```
|
|
48
|
+
|
|
31
49
|
## License
|
|
32
50
|
|
|
33
51
|
License information can be found [here](https://github.com/microsoft/onnxruntime/blob/main/README.md#license).
|
package/bin/napi-v3/darwin/arm64/{libonnxruntime.1.17.0.dylib → libonnxruntime.1.17.3.dylib}
RENAMED
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/dist/backend.js
CHANGED
|
@@ -40,7 +40,7 @@ class OnnxruntimeSessionHandler {
|
|
|
40
40
|
}
|
|
41
41
|
async run(feeds, fetches, options) {
|
|
42
42
|
return new Promise((resolve, reject) => {
|
|
43
|
-
|
|
43
|
+
setImmediate(() => {
|
|
44
44
|
try {
|
|
45
45
|
resolve(__classPrivateFieldGet(this, _OnnxruntimeSessionHandler_inferenceSession, "f").run(feeds, fetches, options));
|
|
46
46
|
}
|
|
@@ -59,7 +59,7 @@ class OnnxruntimeBackend {
|
|
|
59
59
|
}
|
|
60
60
|
async createInferenceSessionHandler(pathOrBuffer, options) {
|
|
61
61
|
return new Promise((resolve, reject) => {
|
|
62
|
-
|
|
62
|
+
setImmediate(() => {
|
|
63
63
|
try {
|
|
64
64
|
resolve(new OnnxruntimeSessionHandler(pathOrBuffer, options || {}));
|
|
65
65
|
}
|
package/dist/backend.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"backend.js","sourceRoot":"","sources":["../lib/backend.ts"],"names":[],"mappings":";AAAA,4DAA4D;AAC5D,kCAAkC;;;;;;;;;;;;;;;AAI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yB,CAAC,YAAY,EAAE,OAAO,IAAI,EAAE,CAAC,CAAC,CAAC;iBACrE;gBAAC,OAAO,CAAC,EAAE;oBACV,gCAAgC;oBAChC,MAAM,CAAC,CAAC,CAAC,CAAC;iBACX;YACH,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AAEY,QAAA,kBAAkB,GAAG,IAAI,kBAAkB,EAAE,CAAC;AAC9C,QAAA,qBAAqB,GAAG,iBAAO,CAAC,qBAAqB,CAAC"}
|
package/dist/version.js
CHANGED
|
@@ -5,5 +5,5 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
5
5
|
exports.version = void 0;
|
|
6
6
|
// This file is generated by /js/scripts/update-version.ts
|
|
7
7
|
// Do not modify file content manually.
|
|
8
|
-
exports.version = '1.17.
|
|
8
|
+
exports.version = '1.17.3-rev.1';
|
|
9
9
|
//# sourceMappingURL=version.js.map
|
package/dist/version.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.js","sourceRoot":"","sources":["../lib/version.ts"],"names":[],"mappings":";AAAA,4DAA4D;AAC5D,kCAAkC;;;AAElC,0DAA0D;AAC1D,uCAAuC;AAE1B,QAAA,OAAO,GAAG,
|
|
1
|
+
{"version":3,"file":"version.js","sourceRoot":"","sources":["../lib/version.ts"],"names":[],"mappings":";AAAA,4DAA4D;AAC5D,kCAAkC;;;AAElC,0DAA0D;AAC1D,uCAAuC;AAE1B,QAAA,OAAO,GAAG,cAAc,CAAC"}
|
package/lib/backend.ts
CHANGED
|
@@ -36,7 +36,7 @@ class OnnxruntimeSessionHandler implements InferenceSessionHandler {
|
|
|
36
36
|
async run(feeds: SessionHandler.FeedsType, fetches: SessionHandler.FetchesType, options: InferenceSession.RunOptions):
|
|
37
37
|
Promise<SessionHandler.ReturnType> {
|
|
38
38
|
return new Promise((resolve, reject) => {
|
|
39
|
-
|
|
39
|
+
setImmediate(() => {
|
|
40
40
|
try {
|
|
41
41
|
resolve(this.#inferenceSession.run(feeds, fetches, options));
|
|
42
42
|
} catch (e) {
|
|
@@ -56,7 +56,7 @@ class OnnxruntimeBackend implements Backend {
|
|
|
56
56
|
async createInferenceSessionHandler(pathOrBuffer: string|Uint8Array, options?: InferenceSession.SessionOptions):
|
|
57
57
|
Promise<InferenceSessionHandler> {
|
|
58
58
|
return new Promise((resolve, reject) => {
|
|
59
|
-
|
|
59
|
+
setImmediate(() => {
|
|
60
60
|
try {
|
|
61
61
|
resolve(new OnnxruntimeSessionHandler(pathOrBuffer, options || {}));
|
|
62
62
|
} catch (e) {
|
package/lib/version.ts
CHANGED
package/package.json
CHANGED
|
@@ -13,11 +13,13 @@
|
|
|
13
13
|
3
|
|
14
14
|
]
|
|
15
15
|
},
|
|
16
|
-
"version": "1.17.
|
|
16
|
+
"version": "1.17.3-rev.1",
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"onnxruntime-common": "1.17.
|
|
18
|
+
"onnxruntime-common": "1.17.3",
|
|
19
|
+
"tar": "^7.0.1"
|
|
19
20
|
},
|
|
20
21
|
"scripts": {
|
|
22
|
+
"postinstall": "node ./script/install",
|
|
21
23
|
"buildr": "tsc && node ./script/build --config=RelWithDebInfo",
|
|
22
24
|
"preprepare": "node -e \"require('node:fs').copyFileSync('./node_modules/long/index.d.ts', './node_modules/long/umd/index.d.ts')\"",
|
|
23
25
|
"prepare": "tsc --build script test .",
|
package/script/build.js
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
// Licensed under the MIT License.
|
|
4
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
5
|
+
if (k2 === undefined) k2 = k;
|
|
6
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
7
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
8
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
9
|
+
}
|
|
10
|
+
Object.defineProperty(o, k2, desc);
|
|
11
|
+
}) : (function(o, m, k, k2) {
|
|
12
|
+
if (k2 === undefined) k2 = k;
|
|
13
|
+
o[k2] = m[k];
|
|
14
|
+
}));
|
|
15
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
16
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
17
|
+
}) : function(o, v) {
|
|
18
|
+
o["default"] = v;
|
|
19
|
+
});
|
|
20
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
21
|
+
if (mod && mod.__esModule) return mod;
|
|
22
|
+
var result = {};
|
|
23
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
24
|
+
__setModuleDefault(result, mod);
|
|
25
|
+
return result;
|
|
26
|
+
};
|
|
27
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
28
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
29
|
+
};
|
|
30
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
31
|
+
const child_process_1 = require("child_process");
|
|
32
|
+
const fs = __importStar(require("fs-extra"));
|
|
33
|
+
const minimist_1 = __importDefault(require("minimist"));
|
|
34
|
+
const os = __importStar(require("os"));
|
|
35
|
+
const path = __importStar(require("path"));
|
|
36
|
+
// command line flags
|
|
37
|
+
const buildArgs = (0, minimist_1.default)(process.argv.slice(2));
|
|
38
|
+
// --config=Debug|Release|RelWithDebInfo
|
|
39
|
+
const CONFIG = buildArgs.config || (os.platform() === 'win32' ? 'RelWithDebInfo' : 'Release');
|
|
40
|
+
if (CONFIG !== 'Debug' && CONFIG !== 'Release' && CONFIG !== 'RelWithDebInfo') {
|
|
41
|
+
throw new Error(`unrecognized config: ${CONFIG}`);
|
|
42
|
+
}
|
|
43
|
+
// --arch=x64|ia32|arm64|arm
|
|
44
|
+
const ARCH = buildArgs.arch || os.arch();
|
|
45
|
+
if (ARCH !== 'x64' && ARCH !== 'ia32' && ARCH !== 'arm64' && ARCH !== 'arm') {
|
|
46
|
+
throw new Error(`unrecognized architecture: ${ARCH}`);
|
|
47
|
+
}
|
|
48
|
+
// --onnxruntime-build-dir=
|
|
49
|
+
const ONNXRUNTIME_BUILD_DIR = buildArgs['onnxruntime-build-dir'];
|
|
50
|
+
// --rebuild
|
|
51
|
+
const REBUILD = !!buildArgs.rebuild;
|
|
52
|
+
// --use_dml
|
|
53
|
+
const USE_DML = !!buildArgs.use_dml;
|
|
54
|
+
// --use_cuda
|
|
55
|
+
const USE_CUDA = !!buildArgs.use_cuda;
|
|
56
|
+
// --use_tensorrt
|
|
57
|
+
const USE_TENSORRT = !!buildArgs.use_tensorrt;
|
|
58
|
+
// --use_coreml
|
|
59
|
+
const USE_COREML = !!buildArgs.use_coreml;
|
|
60
|
+
// build path
|
|
61
|
+
const ROOT_FOLDER = path.join(__dirname, '..');
|
|
62
|
+
const BIN_FOLDER = path.join(ROOT_FOLDER, 'bin');
|
|
63
|
+
const BUILD_FOLDER = path.join(ROOT_FOLDER, 'build');
|
|
64
|
+
// if rebuild, clean up the dist folders
|
|
65
|
+
if (REBUILD) {
|
|
66
|
+
fs.removeSync(BIN_FOLDER);
|
|
67
|
+
fs.removeSync(BUILD_FOLDER);
|
|
68
|
+
}
|
|
69
|
+
const args = [
|
|
70
|
+
'cmake-js',
|
|
71
|
+
(REBUILD ? 'reconfigure' : 'configure'),
|
|
72
|
+
`--arch=${ARCH}`,
|
|
73
|
+
'--CDnapi_build_version=6',
|
|
74
|
+
`--CDCMAKE_BUILD_TYPE=${CONFIG}`,
|
|
75
|
+
];
|
|
76
|
+
if (ONNXRUNTIME_BUILD_DIR && typeof ONNXRUNTIME_BUILD_DIR === 'string') {
|
|
77
|
+
args.push(`--CDONNXRUNTIME_BUILD_DIR=${ONNXRUNTIME_BUILD_DIR}`);
|
|
78
|
+
}
|
|
79
|
+
if (USE_DML) {
|
|
80
|
+
args.push('--CDUSE_DML=ON');
|
|
81
|
+
}
|
|
82
|
+
if (USE_CUDA) {
|
|
83
|
+
args.push('--CDUSE_CUDA=ON');
|
|
84
|
+
}
|
|
85
|
+
if (USE_TENSORRT) {
|
|
86
|
+
args.push('--CDUSE_TENSORRT=ON');
|
|
87
|
+
}
|
|
88
|
+
if (USE_COREML) {
|
|
89
|
+
args.push('--CDUSE_COREML=ON');
|
|
90
|
+
}
|
|
91
|
+
// set CMAKE_OSX_ARCHITECTURES for macOS build
|
|
92
|
+
if (os.platform() === 'darwin') {
|
|
93
|
+
if (ARCH === 'x64') {
|
|
94
|
+
args.push('--CDCMAKE_OSX_ARCHITECTURES=x86_64');
|
|
95
|
+
}
|
|
96
|
+
else if (ARCH === 'arm64') {
|
|
97
|
+
args.push('--CDCMAKE_OSX_ARCHITECTURES=arm64');
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
throw new Error(`architecture not supported for macOS build: ${ARCH}`);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
// In Windows, "npx cmake-js configure" uses a powershell script to detect the Visual Studio installation.
|
|
104
|
+
// The script uses the environment variable LIB. If an invalid path is specified in LIB, the script will fail.
|
|
105
|
+
// So we override the LIB environment variable to remove invalid paths.
|
|
106
|
+
const envOverride = os.platform() === 'win32' && process.env.LIB ?
|
|
107
|
+
{ ...process.env, LIB: process.env.LIB.split(';').filter(fs.existsSync).join(';') } :
|
|
108
|
+
process.env;
|
|
109
|
+
// launch cmake-js configure
|
|
110
|
+
const procCmakejs = (0, child_process_1.spawnSync)('npx', args, { shell: true, stdio: 'inherit', cwd: ROOT_FOLDER, env: envOverride });
|
|
111
|
+
if (procCmakejs.status !== 0) {
|
|
112
|
+
if (procCmakejs.error) {
|
|
113
|
+
console.error(procCmakejs.error);
|
|
114
|
+
}
|
|
115
|
+
process.exit(procCmakejs.status === null ? undefined : procCmakejs.status);
|
|
116
|
+
}
|
|
117
|
+
// launch cmake to build
|
|
118
|
+
const procCmake = (0, child_process_1.spawnSync)('cmake', ['--build', '.', '--config', CONFIG], { shell: true, stdio: 'inherit', cwd: BUILD_FOLDER });
|
|
119
|
+
if (procCmake.status !== 0) {
|
|
120
|
+
if (procCmake.error) {
|
|
121
|
+
console.error(procCmake.error);
|
|
122
|
+
}
|
|
123
|
+
process.exit(procCmake.status === null ? undefined : procCmake.status);
|
|
124
|
+
}
|
package/script/build.ts
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
2
|
+
// Licensed under the MIT License.
|
|
3
|
+
|
|
4
|
+
import {spawnSync} from 'child_process';
|
|
5
|
+
import * as fs from 'fs-extra';
|
|
6
|
+
import minimist from 'minimist';
|
|
7
|
+
import * as os from 'os';
|
|
8
|
+
import * as path from 'path';
|
|
9
|
+
|
|
10
|
+
// command line flags
|
|
11
|
+
const buildArgs = minimist(process.argv.slice(2));
|
|
12
|
+
|
|
13
|
+
// --config=Debug|Release|RelWithDebInfo
|
|
14
|
+
const CONFIG: 'Debug'|'Release'|'RelWithDebInfo' =
|
|
15
|
+
buildArgs.config || (os.platform() === 'win32' ? 'RelWithDebInfo' : 'Release');
|
|
16
|
+
if (CONFIG !== 'Debug' && CONFIG !== 'Release' && CONFIG !== 'RelWithDebInfo') {
|
|
17
|
+
throw new Error(`unrecognized config: ${CONFIG}`);
|
|
18
|
+
}
|
|
19
|
+
// --arch=x64|ia32|arm64|arm
|
|
20
|
+
const ARCH: 'x64'|'ia32'|'arm64'|'arm' = buildArgs.arch || os.arch();
|
|
21
|
+
if (ARCH !== 'x64' && ARCH !== 'ia32' && ARCH !== 'arm64' && ARCH !== 'arm') {
|
|
22
|
+
throw new Error(`unrecognized architecture: ${ARCH}`);
|
|
23
|
+
}
|
|
24
|
+
// --onnxruntime-build-dir=
|
|
25
|
+
const ONNXRUNTIME_BUILD_DIR = buildArgs['onnxruntime-build-dir'];
|
|
26
|
+
// --rebuild
|
|
27
|
+
const REBUILD = !!buildArgs.rebuild;
|
|
28
|
+
// --use_dml
|
|
29
|
+
const USE_DML = !!buildArgs.use_dml;
|
|
30
|
+
// --use_cuda
|
|
31
|
+
const USE_CUDA = !!buildArgs.use_cuda;
|
|
32
|
+
// --use_tensorrt
|
|
33
|
+
const USE_TENSORRT = !!buildArgs.use_tensorrt;
|
|
34
|
+
// --use_coreml
|
|
35
|
+
const USE_COREML = !!buildArgs.use_coreml;
|
|
36
|
+
|
|
37
|
+
// build path
|
|
38
|
+
const ROOT_FOLDER = path.join(__dirname, '..');
|
|
39
|
+
const BIN_FOLDER = path.join(ROOT_FOLDER, 'bin');
|
|
40
|
+
const BUILD_FOLDER = path.join(ROOT_FOLDER, 'build');
|
|
41
|
+
|
|
42
|
+
// if rebuild, clean up the dist folders
|
|
43
|
+
if (REBUILD) {
|
|
44
|
+
fs.removeSync(BIN_FOLDER);
|
|
45
|
+
fs.removeSync(BUILD_FOLDER);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const args = [
|
|
49
|
+
'cmake-js',
|
|
50
|
+
(REBUILD ? 'reconfigure' : 'configure'),
|
|
51
|
+
`--arch=${ARCH}`,
|
|
52
|
+
'--CDnapi_build_version=6',
|
|
53
|
+
`--CDCMAKE_BUILD_TYPE=${CONFIG}`,
|
|
54
|
+
];
|
|
55
|
+
if (ONNXRUNTIME_BUILD_DIR && typeof ONNXRUNTIME_BUILD_DIR === 'string') {
|
|
56
|
+
args.push(`--CDONNXRUNTIME_BUILD_DIR=${ONNXRUNTIME_BUILD_DIR}`);
|
|
57
|
+
}
|
|
58
|
+
if (USE_DML) {
|
|
59
|
+
args.push('--CDUSE_DML=ON');
|
|
60
|
+
}
|
|
61
|
+
if (USE_CUDA) {
|
|
62
|
+
args.push('--CDUSE_CUDA=ON');
|
|
63
|
+
}
|
|
64
|
+
if (USE_TENSORRT) {
|
|
65
|
+
args.push('--CDUSE_TENSORRT=ON');
|
|
66
|
+
}
|
|
67
|
+
if (USE_COREML) {
|
|
68
|
+
args.push('--CDUSE_COREML=ON');
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// set CMAKE_OSX_ARCHITECTURES for macOS build
|
|
72
|
+
if (os.platform() === 'darwin') {
|
|
73
|
+
if (ARCH === 'x64') {
|
|
74
|
+
args.push('--CDCMAKE_OSX_ARCHITECTURES=x86_64');
|
|
75
|
+
} else if (ARCH === 'arm64') {
|
|
76
|
+
args.push('--CDCMAKE_OSX_ARCHITECTURES=arm64');
|
|
77
|
+
} else {
|
|
78
|
+
throw new Error(`architecture not supported for macOS build: ${ARCH}`);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// In Windows, "npx cmake-js configure" uses a powershell script to detect the Visual Studio installation.
|
|
83
|
+
// The script uses the environment variable LIB. If an invalid path is specified in LIB, the script will fail.
|
|
84
|
+
// So we override the LIB environment variable to remove invalid paths.
|
|
85
|
+
const envOverride = os.platform() === 'win32' && process.env.LIB ?
|
|
86
|
+
{...process.env, LIB: process.env.LIB.split(';').filter(fs.existsSync).join(';')} :
|
|
87
|
+
process.env;
|
|
88
|
+
|
|
89
|
+
// launch cmake-js configure
|
|
90
|
+
const procCmakejs = spawnSync('npx', args, {shell: true, stdio: 'inherit', cwd: ROOT_FOLDER, env: envOverride});
|
|
91
|
+
if (procCmakejs.status !== 0) {
|
|
92
|
+
if (procCmakejs.error) {
|
|
93
|
+
console.error(procCmakejs.error);
|
|
94
|
+
}
|
|
95
|
+
process.exit(procCmakejs.status === null ? undefined : procCmakejs.status);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// launch cmake to build
|
|
99
|
+
const procCmake =
|
|
100
|
+
spawnSync('cmake', ['--build', '.', '--config', CONFIG], {shell: true, stdio: 'inherit', cwd: BUILD_FOLDER});
|
|
101
|
+
if (procCmake.status !== 0) {
|
|
102
|
+
if (procCmake.error) {
|
|
103
|
+
console.error(procCmake.error);
|
|
104
|
+
}
|
|
105
|
+
process.exit(procCmake.status === null ? undefined : procCmake.status);
|
|
106
|
+
}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
2
|
+
// Licensed under the MIT License.
|
|
3
|
+
|
|
4
|
+
'use strict';
|
|
5
|
+
|
|
6
|
+
// This script is written in JavaScript. This is because it is used in "install" script in package.json, which is called
|
|
7
|
+
// when the package is installed either as a dependency or from "npm ci"/"npm install" without parameters. TypeScript is
|
|
8
|
+
// not always available.
|
|
9
|
+
|
|
10
|
+
// The purpose of this script is to download the required binaries for the platform and architecture.
|
|
11
|
+
// Currently, most of the binaries are already bundled in the package, except for the following:
|
|
12
|
+
// - Linux/x64/CUDA 11
|
|
13
|
+
// - Linux/x64/CUDA 12
|
|
14
|
+
//
|
|
15
|
+
// The CUDA binaries are not bundled because they are too large to be allowed in the npm registry. Instead, they are
|
|
16
|
+
// downloaded from the GitHub release page of ONNX Runtime. The script will download the binaries if they are not
|
|
17
|
+
// already present in the package.
|
|
18
|
+
|
|
19
|
+
// Step.1: Check if we should exit early
|
|
20
|
+
const os = require('os');
|
|
21
|
+
const fs = require('fs');
|
|
22
|
+
const path = require('path');
|
|
23
|
+
const tar = require('tar');
|
|
24
|
+
const {Readable} = require('stream');
|
|
25
|
+
|
|
26
|
+
// commandline flag:
|
|
27
|
+
// --onnxruntime-node-install-cuda Force install the CUDA EP binaries. Try to detect the CUDA version.
|
|
28
|
+
// --onnxruntime-node-install-cuda=v11 Force install the CUDA EP binaries for CUDA 11.
|
|
29
|
+
// --onnxruntime-node-install-cuda=v12 Force install the CUDA EP binaries for CUDA 12.
|
|
30
|
+
// --onnxruntime-node-install-cuda=skip Skip the installation of the CUDA EP binaries.
|
|
31
|
+
//
|
|
32
|
+
// Alternatively, use environment variable "ONNXRUNTIME_NODE_INSTALL_CUDA"
|
|
33
|
+
//
|
|
34
|
+
// If the flag is not provided, the script will only install the CUDA EP binaries when:
|
|
35
|
+
// - The platform is Linux/x64.
|
|
36
|
+
// - The binaries are not already present in the package.
|
|
37
|
+
// - The installation is not a local install (when used inside ONNX Runtime repo).
|
|
38
|
+
//
|
|
39
|
+
const INSTALL_CUDA_FLAG = parseInstallCudaFlag();
|
|
40
|
+
const NO_INSTALL = INSTALL_CUDA_FLAG === 'skip';
|
|
41
|
+
const FORCE_INSTALL = !NO_INSTALL && INSTALL_CUDA_FLAG;
|
|
42
|
+
|
|
43
|
+
const IS_LINUX_X64 = os.platform() === 'linux' && os.arch() === 'x64';
|
|
44
|
+
const BIN_FOLDER = path.join(__dirname, '..', 'bin/napi-v3/linux/x64');
|
|
45
|
+
const BIN_FOLDER_EXISTS = fs.existsSync(BIN_FOLDER);
|
|
46
|
+
const CUDA_DLL_EXISTS = fs.existsSync(path.join(BIN_FOLDER, 'libonnxruntime_providers_cuda.so'));
|
|
47
|
+
const ORT_VERSION = '1.17.3';
|
|
48
|
+
|
|
49
|
+
const npm_config_local_prefix = process.env.npm_config_local_prefix;
|
|
50
|
+
const npm_package_json = process.env.npm_package_json;
|
|
51
|
+
const SKIP_LOCAL_INSTALL =
|
|
52
|
+
npm_config_local_prefix && npm_package_json && path.dirname(npm_package_json) === npm_config_local_prefix;
|
|
53
|
+
|
|
54
|
+
const shouldInstall = FORCE_INSTALL || (!SKIP_LOCAL_INSTALL && IS_LINUX_X64 && BIN_FOLDER_EXISTS && !CUDA_DLL_EXISTS);
|
|
55
|
+
if (NO_INSTALL || !shouldInstall) {
|
|
56
|
+
process.exit(0);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// Step.2: Download the required binaries
|
|
60
|
+
const artifactUrl = {
|
|
61
|
+
11: `https://github.com/microsoft/onnxruntime/releases/download/v${ORT_VERSION}/onnxruntime-linux-x64-gpu-${
|
|
62
|
+
ORT_VERSION}.tgz`,
|
|
63
|
+
12: `https://github.com/microsoft/onnxruntime/releases/download/v${ORT_VERSION}/onnxruntime-linux-x64-gpu-cuda12-${
|
|
64
|
+
ORT_VERSION}.tgz`
|
|
65
|
+
}[INSTALL_CUDA_FLAG || tryGetCudaVersion()];
|
|
66
|
+
console.log(`Downloading "${artifactUrl}"...`);
|
|
67
|
+
fetch(artifactUrl).then(res => {
|
|
68
|
+
if (!res.ok) {
|
|
69
|
+
throw new Error(`Failed to download the binaries: ${res.status} ${res.statusText}.
|
|
70
|
+
|
|
71
|
+
Use "--onnxruntime-node-install-cuda=skip" to skip the installation. You will still be able to use ONNX Runtime, but the CUDA EP will not be available.`);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// Extract the binaries
|
|
75
|
+
|
|
76
|
+
const FILES = new Set([
|
|
77
|
+
'libonnxruntime_providers_tensorrt.so',
|
|
78
|
+
'libonnxruntime_providers_shared.so',
|
|
79
|
+
`libonnxruntime.so.${ORT_VERSION}`,
|
|
80
|
+
'libonnxruntime_providers_cuda.so',
|
|
81
|
+
]);
|
|
82
|
+
|
|
83
|
+
Readable.fromWeb(res.body)
|
|
84
|
+
.pipe(tar.t({
|
|
85
|
+
strict: true,
|
|
86
|
+
onentry: (entry) => {
|
|
87
|
+
const filename = path.basename(entry.path);
|
|
88
|
+
if (entry.type === 'File' && FILES.has(filename)) {
|
|
89
|
+
console.log(`Extracting "${filename}" to "${BIN_FOLDER}"...`);
|
|
90
|
+
entry.pipe(fs.createWriteStream(path.join(BIN_FOLDER, filename)));
|
|
91
|
+
entry.on('finish', () => {
|
|
92
|
+
console.log(`Finished extracting "${filename}".`);
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}))
|
|
97
|
+
.on('error', (err) => {
|
|
98
|
+
throw new Error(`Failed to extract the binaries: ${err.message}.
|
|
99
|
+
|
|
100
|
+
Use "--onnxruntime-node-install-cuda=skip" to skip the installation. You will still be able to use ONNX Runtime, but the CUDA EP will not be available.`);
|
|
101
|
+
});
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
function tryGetCudaVersion() {
|
|
106
|
+
// Should only return 11 or 12.
|
|
107
|
+
|
|
108
|
+
// TODO: try to get the CUDA version from the system ( `nvcc --version` )
|
|
109
|
+
|
|
110
|
+
return 11;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function parseInstallCudaFlag() {
|
|
114
|
+
let flag = process.env.ONNXRUNTIME_NODE_INSTALL_CUDA || process.env.npm_config_onnxruntime_node_install_cuda;
|
|
115
|
+
if (!flag) {
|
|
116
|
+
for (let i = 0; i < process.argv.length; i++) {
|
|
117
|
+
if (process.argv[i].startsWith('--onnxruntime-node-install-cuda=')) {
|
|
118
|
+
flag = process.argv[i].split('=')[1];
|
|
119
|
+
break;
|
|
120
|
+
} else if (process.argv[i] === '--onnxruntime-node-install-cuda') {
|
|
121
|
+
flag = 'true';
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
switch (flag) {
|
|
126
|
+
case 'true':
|
|
127
|
+
case '1':
|
|
128
|
+
case 'ON':
|
|
129
|
+
return tryGetCudaVersion();
|
|
130
|
+
case 'v11':
|
|
131
|
+
return 11;
|
|
132
|
+
case 'v12':
|
|
133
|
+
return 12;
|
|
134
|
+
case 'skip':
|
|
135
|
+
case undefined:
|
|
136
|
+
return flag;
|
|
137
|
+
default:
|
|
138
|
+
throw new Error(`Invalid value for --onnxruntime-node-install-cuda: ${flag}`);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
// Licensed under the MIT License.
|
|
4
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
5
|
+
if (k2 === undefined) k2 = k;
|
|
6
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
7
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
8
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
9
|
+
}
|
|
10
|
+
Object.defineProperty(o, k2, desc);
|
|
11
|
+
}) : (function(o, m, k, k2) {
|
|
12
|
+
if (k2 === undefined) k2 = k;
|
|
13
|
+
o[k2] = m[k];
|
|
14
|
+
}));
|
|
15
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
16
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
17
|
+
}) : function(o, v) {
|
|
18
|
+
o["default"] = v;
|
|
19
|
+
});
|
|
20
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
21
|
+
if (mod && mod.__esModule) return mod;
|
|
22
|
+
var result = {};
|
|
23
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
24
|
+
__setModuleDefault(result, mod);
|
|
25
|
+
return result;
|
|
26
|
+
};
|
|
27
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
28
|
+
const fs = __importStar(require("fs-extra"));
|
|
29
|
+
const path = __importStar(require("path"));
|
|
30
|
+
function updatePackageJson() {
|
|
31
|
+
const commonPackageJsonPath = path.join(__dirname, '..', '..', 'common', 'package.json');
|
|
32
|
+
const selfPackageJsonPath = path.join(__dirname, '..', 'package.json');
|
|
33
|
+
console.log(`=== start to update package.json: ${selfPackageJsonPath}`);
|
|
34
|
+
const packageCommon = fs.readJSONSync(commonPackageJsonPath);
|
|
35
|
+
const packageSelf = fs.readJSONSync(selfPackageJsonPath);
|
|
36
|
+
const version = packageCommon.version;
|
|
37
|
+
packageSelf.dependencies['onnxruntime-common'] = `${version}`;
|
|
38
|
+
fs.writeJSONSync(selfPackageJsonPath, packageSelf, { spaces: 2 });
|
|
39
|
+
console.log('=== finished updating package.json.');
|
|
40
|
+
}
|
|
41
|
+
// update version of dependency "onnxruntime-common" before packing
|
|
42
|
+
updatePackageJson();
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
2
|
+
// Licensed under the MIT License.
|
|
3
|
+
|
|
4
|
+
import * as fs from 'fs-extra';
|
|
5
|
+
import * as path from 'path';
|
|
6
|
+
|
|
7
|
+
function updatePackageJson() {
|
|
8
|
+
const commonPackageJsonPath = path.join(__dirname, '..', '..', 'common', 'package.json');
|
|
9
|
+
const selfPackageJsonPath = path.join(__dirname, '..', 'package.json');
|
|
10
|
+
console.log(`=== start to update package.json: ${selfPackageJsonPath}`);
|
|
11
|
+
const packageCommon = fs.readJSONSync(commonPackageJsonPath);
|
|
12
|
+
const packageSelf = fs.readJSONSync(selfPackageJsonPath);
|
|
13
|
+
const version = packageCommon.version;
|
|
14
|
+
packageSelf.dependencies['onnxruntime-common'] = `${version}`;
|
|
15
|
+
fs.writeJSONSync(selfPackageJsonPath, packageSelf, {spaces: 2});
|
|
16
|
+
console.log('=== finished updating package.json.');
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// update version of dependency "onnxruntime-common" before packing
|
|
20
|
+
updatePackageJson();
|
|
Binary file
|
|
Binary file
|