onnxruntime-node 1.22.0-dev.20250415-c18e06d5e3 → 1.22.0
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 +19 -14
- package/bin/{napi-v3 → napi-v6}/darwin/arm64/libonnxruntime.1.22.0.dylib +0 -0
- package/bin/napi-v6/darwin/arm64/onnxruntime_binding.node +0 -0
- package/bin/{napi-v3 → napi-v6}/darwin/x64/libonnxruntime.1.22.0.dylib +0 -0
- package/bin/napi-v6/darwin/x64/onnxruntime_binding.node +0 -0
- package/bin/{napi-v3 → napi-v6}/linux/arm64/libonnxruntime.so.1 +0 -0
- package/bin/napi-v6/linux/arm64/onnxruntime_binding.node +0 -0
- package/bin/{napi-v3 → napi-v6}/linux/x64/libonnxruntime.so.1 +0 -0
- package/bin/napi-v6/linux/x64/onnxruntime_binding.node +0 -0
- package/bin/{napi-v3 → napi-v6}/win32/arm64/DirectML.dll +0 -0
- package/bin/{napi-v3 → napi-v6}/win32/arm64/dxcompiler.dll +0 -0
- package/bin/{napi-v3 → napi-v6}/win32/arm64/dxil.dll +0 -0
- package/bin/{napi-v3 → napi-v6}/win32/arm64/onnxruntime.dll +0 -0
- package/bin/napi-v6/win32/arm64/onnxruntime_binding.node +0 -0
- package/bin/{napi-v3 → napi-v6}/win32/x64/DirectML.dll +0 -0
- package/bin/{napi-v3 → napi-v6}/win32/x64/dxcompiler.dll +0 -0
- package/bin/{napi-v3 → napi-v6}/win32/x64/dxil.dll +0 -0
- package/bin/{napi-v3 → napi-v6}/win32/x64/onnxruntime.dll +0 -0
- package/bin/napi-v6/win32/x64/onnxruntime_binding.node +0 -0
- package/dist/binding.js +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/version.js.map +1 -1
- package/lib/binding.ts +1 -1
- package/lib/version.ts +1 -1
- package/package.json +4 -6
- package/script/build.js +69 -92
- package/script/install-metadata-versions.js +7 -0
- package/script/install-metadata.js +58 -0
- package/script/install-utils.js +306 -0
- package/script/install.js +94 -158
- package/script/prepack.js +32 -49
- package/__commit.txt +0 -1
- package/bin/napi-v3/darwin/arm64/onnxruntime_binding.node +0 -0
- package/bin/napi-v3/darwin/x64/onnxruntime_binding.node +0 -0
- package/bin/napi-v3/linux/arm64/onnxruntime_binding.node +0 -0
- package/bin/napi-v3/linux/x64/onnxruntime_binding.node +0 -0
- package/bin/napi-v3/win32/arm64/onnxruntime_binding.node +0 -0
- package/bin/napi-v3/win32/x64/onnxruntime_binding.node +0 -0
package/README.md
CHANGED
|
@@ -10,6 +10,12 @@ Install the latest stable version:
|
|
|
10
10
|
npm install onnxruntime-node
|
|
11
11
|
```
|
|
12
12
|
|
|
13
|
+
Install the nightly version:
|
|
14
|
+
|
|
15
|
+
```
|
|
16
|
+
npm install onnxruntime-node@dev
|
|
17
|
+
```
|
|
18
|
+
|
|
13
19
|
Refer to [ONNX Runtime JavaScript examples](https://github.com/microsoft/onnxruntime-inference-examples/tree/main/js) for samples and tutorials.
|
|
14
20
|
|
|
15
21
|
## Requirements
|
|
@@ -18,33 +24,32 @@ ONNXRuntime works on Node.js v16.x+ (recommend v20.x+) or Electron v15.x+ (recom
|
|
|
18
24
|
|
|
19
25
|
The following table lists the supported versions of ONNX Runtime Node.js binding provided with pre-built binaries.
|
|
20
26
|
|
|
21
|
-
| EPs/Platforms | Windows x64
|
|
22
|
-
| ------------- |
|
|
23
|
-
| CPU | ✔️
|
|
24
|
-
|
|
|
25
|
-
|
|
|
27
|
+
| EPs/Platforms | Windows x64 | Windows arm64 | Linux x64 | Linux arm64 | MacOS x64 | MacOS arm64 |
|
|
28
|
+
| ------------- | ------------------ | ------------------ | ------------------ | ------------------ | ------------------ | ------------------ |
|
|
29
|
+
| CPU | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ |
|
|
30
|
+
| WebGPU | ✔️ <sup>\[1]</sup> | ✔️ <sup>\[1]</sup> | ✔️ <sup>\[1]</sup> | ✔️ <sup>\[1]</sup> | ✔️ <sup>\[1]</sup> | ✔️ <sup>\[1]</sup> |
|
|
31
|
+
| DirectML | ✔️ | ✔️ | ❌ | ❌ | ❌ | ❌ |
|
|
32
|
+
| CUDA | ❌ | ❌ | ✔️<sup>\[2]</sup> | ❌ | ❌ | ❌ |
|
|
33
|
+
| CoreML | ❌ | ❌ | ❌ | ❌ | ✔️ | ✔️ |
|
|
26
34
|
|
|
27
|
-
- \[1]:
|
|
35
|
+
- \[1]: WebGPU support is currently experimental.
|
|
36
|
+
- \[2]: CUDA v12. See [CUDA EP Installation](#cuda-ep-installation) for details.
|
|
28
37
|
|
|
29
38
|
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.
|
|
30
39
|
|
|
31
40
|
# GPU Support
|
|
32
41
|
|
|
33
|
-
Right now, the Windows version supports
|
|
42
|
+
Right now, the Windows version supports WebGPU execution provider and DML execution provider. Linux x64 can use CUDA and TensorRT.
|
|
34
43
|
|
|
35
44
|
## CUDA EP Installation
|
|
36
45
|
|
|
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
|
|
46
|
+
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=skip` flag to the installation command.
|
|
38
47
|
|
|
39
48
|
```
|
|
40
|
-
npm install onnxruntime-node --onnxruntime-node-install
|
|
49
|
+
npm install onnxruntime-node --onnxruntime-node-install=skip
|
|
41
50
|
```
|
|
42
51
|
|
|
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
|
-
```
|
|
52
|
+
~~You can also use this flag to specify the version of the CUDA: (v11 or v12)~~ CUDA v11 is no longer supported since v1.22.
|
|
48
53
|
|
|
49
54
|
## License
|
|
50
55
|
|
|
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
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/dist/binding.js
CHANGED
|
@@ -7,7 +7,7 @@ const onnxruntime_common_1 = require("onnxruntime-common");
|
|
|
7
7
|
// export native binding
|
|
8
8
|
exports.binding =
|
|
9
9
|
// eslint-disable-next-line @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires
|
|
10
|
-
require(`../bin/napi-
|
|
10
|
+
require(`../bin/napi-v6/${process.platform}/${process.arch}/onnxruntime_binding.node`);
|
|
11
11
|
let ortInitialized = false;
|
|
12
12
|
const initOrt = () => {
|
|
13
13
|
if (!ortInitialized) {
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const version = "1.22.0
|
|
1
|
+
export declare const version = "1.22.0";
|
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.22.0
|
|
8
|
+
exports.version = '1.22.0';
|
|
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,QAAQ,CAAC"}
|
package/lib/binding.ts
CHANGED
|
@@ -53,7 +53,7 @@ export declare namespace Binding {
|
|
|
53
53
|
// export native binding
|
|
54
54
|
export const binding =
|
|
55
55
|
// eslint-disable-next-line @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires
|
|
56
|
-
require(`../bin/napi-
|
|
56
|
+
require(`../bin/napi-v6/${process.platform}/${process.arch}/onnxruntime_binding.node`) as {
|
|
57
57
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
58
58
|
InferenceSession: Binding.InferenceSessionConstructor;
|
|
59
59
|
listSupportedBackends: () => Binding.SupportedBackend[];
|
package/lib/version.ts
CHANGED
package/package.json
CHANGED
|
@@ -7,17 +7,15 @@
|
|
|
7
7
|
},
|
|
8
8
|
"author": "fs-eire",
|
|
9
9
|
"binary": {
|
|
10
|
-
"module_path": "./bin",
|
|
11
|
-
"host": "https://onnxruntimetestdata.blob.core.windows.net/onnxruntime-node-prebuild/",
|
|
12
10
|
"napi_versions": [
|
|
13
|
-
|
|
11
|
+
6
|
|
14
12
|
]
|
|
15
13
|
},
|
|
16
|
-
"version": "1.22.0
|
|
14
|
+
"version": "1.22.0",
|
|
17
15
|
"dependencies": {
|
|
16
|
+
"adm-zip": "^0.5.16",
|
|
18
17
|
"global-agent": "^3.0.0",
|
|
19
|
-
"onnxruntime-common": "1.22.0
|
|
20
|
-
"tar": "^7.0.1"
|
|
18
|
+
"onnxruntime-common": "1.22.0"
|
|
21
19
|
},
|
|
22
20
|
"scripts": {
|
|
23
21
|
"postinstall": "node ./script/install",
|
package/script/build.js
CHANGED
|
@@ -1,68 +1,49 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
2
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
3
|
// Licensed under the MIT License.
|
|
4
|
-
var __createBinding =
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
if (k2 === undefined) k2 = k;
|
|
22
|
-
o[k2] = m[k];
|
|
23
|
-
});
|
|
24
|
-
var __setModuleDefault =
|
|
25
|
-
(this && this.__setModuleDefault) ||
|
|
26
|
-
(Object.create
|
|
27
|
-
? function (o, v) {
|
|
28
|
-
Object.defineProperty(o, 'default', { enumerable: true, value: v });
|
|
29
|
-
}
|
|
30
|
-
: function (o, v) {
|
|
31
|
-
o['default'] = v;
|
|
32
|
-
});
|
|
33
|
-
var __importStar =
|
|
34
|
-
(this && this.__importStar) ||
|
|
35
|
-
function (mod) {
|
|
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) {
|
|
36
21
|
if (mod && mod.__esModule) return mod;
|
|
37
22
|
var result = {};
|
|
38
|
-
if (mod != null)
|
|
39
|
-
for (var k in mod)
|
|
40
|
-
if (k !== 'default' && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
23
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
41
24
|
__setModuleDefault(result, mod);
|
|
42
25
|
return result;
|
|
43
|
-
|
|
44
|
-
var __importDefault =
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
const
|
|
51
|
-
const
|
|
52
|
-
const
|
|
53
|
-
const os = __importStar(require('os'));
|
|
54
|
-
const path = __importStar(require('path'));
|
|
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"));
|
|
55
36
|
// command line flags
|
|
56
37
|
const buildArgs = (0, minimist_1.default)(process.argv.slice(2));
|
|
57
38
|
// --config=Debug|Release|RelWithDebInfo
|
|
58
39
|
const CONFIG = buildArgs.config || (os.platform() === 'win32' ? 'RelWithDebInfo' : 'Release');
|
|
59
40
|
if (CONFIG !== 'Debug' && CONFIG !== 'Release' && CONFIG !== 'RelWithDebInfo') {
|
|
60
|
-
|
|
41
|
+
throw new Error(`unrecognized config: ${CONFIG}`);
|
|
61
42
|
}
|
|
62
43
|
// --arch=x64|ia32|arm64|arm
|
|
63
44
|
const ARCH = buildArgs.arch || os.arch();
|
|
64
45
|
if (ARCH !== 'x64' && ARCH !== 'ia32' && ARCH !== 'arm64' && ARCH !== 'arm') {
|
|
65
|
-
|
|
46
|
+
throw new Error(`unrecognized architecture: ${ARCH}`);
|
|
66
47
|
}
|
|
67
48
|
// --onnxruntime-build-dir=
|
|
68
49
|
const ONNXRUNTIME_BUILD_DIR = buildArgs['onnxruntime-build-dir'];
|
|
@@ -90,82 +71,78 @@ const BIN_FOLDER = path.join(ROOT_FOLDER, 'bin');
|
|
|
90
71
|
const BUILD_FOLDER = path.join(ROOT_FOLDER, 'build');
|
|
91
72
|
// if rebuild, clean up the dist folders
|
|
92
73
|
if (REBUILD) {
|
|
93
|
-
|
|
94
|
-
|
|
74
|
+
fs.removeSync(BIN_FOLDER);
|
|
75
|
+
fs.removeSync(BUILD_FOLDER);
|
|
95
76
|
}
|
|
96
77
|
const args = [
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
78
|
+
'cmake-js',
|
|
79
|
+
REBUILD ? 'reconfigure' : 'configure',
|
|
80
|
+
`--arch=${ARCH}`,
|
|
81
|
+
'--CDnapi_build_version=6',
|
|
82
|
+
`--CDCMAKE_BUILD_TYPE=${CONFIG}`,
|
|
102
83
|
];
|
|
103
84
|
if (ONNXRUNTIME_BUILD_DIR && typeof ONNXRUNTIME_BUILD_DIR === 'string') {
|
|
104
|
-
|
|
85
|
+
args.push(`--CDONNXRUNTIME_BUILD_DIR=${ONNXRUNTIME_BUILD_DIR}`);
|
|
105
86
|
}
|
|
106
87
|
if (ONNXRUNTIME_GENERATOR && typeof ONNXRUNTIME_GENERATOR === 'string') {
|
|
107
|
-
|
|
88
|
+
args.push(`--CDONNXRUNTIME_GENERATOR=${ONNXRUNTIME_GENERATOR}`);
|
|
108
89
|
}
|
|
109
90
|
if (USE_DML) {
|
|
110
|
-
|
|
91
|
+
args.push('--CDUSE_DML=ON');
|
|
111
92
|
}
|
|
112
93
|
if (USE_WEBGPU) {
|
|
113
|
-
|
|
94
|
+
args.push('--CDUSE_WEBGPU=ON');
|
|
114
95
|
}
|
|
115
96
|
if (USE_CUDA) {
|
|
116
|
-
|
|
97
|
+
args.push('--CDUSE_CUDA=ON');
|
|
117
98
|
}
|
|
118
99
|
if (USE_TENSORRT) {
|
|
119
|
-
|
|
100
|
+
args.push('--CDUSE_TENSORRT=ON');
|
|
120
101
|
}
|
|
121
102
|
if (USE_COREML) {
|
|
122
|
-
|
|
103
|
+
args.push('--CDUSE_COREML=ON');
|
|
123
104
|
}
|
|
124
105
|
if (USE_QNN) {
|
|
125
|
-
|
|
106
|
+
args.push('--CDUSE_QNN=ON');
|
|
126
107
|
}
|
|
127
108
|
if (DLL_DEPS) {
|
|
128
|
-
|
|
109
|
+
args.push(`--CDORT_NODEJS_DLL_DEPS=${DLL_DEPS}`);
|
|
129
110
|
}
|
|
130
111
|
// set CMAKE_OSX_ARCHITECTURES for macOS build
|
|
131
112
|
if (os.platform() === 'darwin') {
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
113
|
+
if (ARCH === 'x64') {
|
|
114
|
+
args.push('--CDCMAKE_OSX_ARCHITECTURES=x86_64');
|
|
115
|
+
}
|
|
116
|
+
else if (ARCH === 'arm64') {
|
|
117
|
+
args.push('--CDCMAKE_OSX_ARCHITECTURES=arm64');
|
|
118
|
+
}
|
|
119
|
+
else {
|
|
120
|
+
throw new Error(`architecture not supported for macOS build: ${ARCH}`);
|
|
121
|
+
}
|
|
139
122
|
}
|
|
140
123
|
// In Windows, "npx cmake-js configure" uses a powershell script to detect the Visual Studio installation.
|
|
141
124
|
// The script uses the environment variable LIB. If an invalid path is specified in LIB, the script will fail.
|
|
142
125
|
// So we override the LIB environment variable to remove invalid paths.
|
|
143
|
-
const envOverride =
|
|
144
|
-
os.platform() === 'win32' && process.env.LIB
|
|
126
|
+
const envOverride = os.platform() === 'win32' && process.env.LIB
|
|
145
127
|
? { ...process.env, LIB: process.env.LIB.split(';').filter(fs.existsSync).join(';') }
|
|
146
128
|
: process.env;
|
|
147
129
|
// launch cmake-js configure
|
|
148
|
-
const procCmakejs = (0, child_process_1.spawnSync)('npx', args, {
|
|
149
|
-
shell: true,
|
|
150
|
-
stdio: 'inherit',
|
|
151
|
-
cwd: ROOT_FOLDER,
|
|
152
|
-
env: envOverride,
|
|
153
|
-
});
|
|
130
|
+
const procCmakejs = (0, child_process_1.spawnSync)('npx', args, { shell: true, stdio: 'inherit', cwd: ROOT_FOLDER, env: envOverride });
|
|
154
131
|
if (procCmakejs.status !== 0) {
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
132
|
+
if (procCmakejs.error) {
|
|
133
|
+
console.error(procCmakejs.error);
|
|
134
|
+
}
|
|
135
|
+
process.exit(procCmakejs.status === null ? undefined : procCmakejs.status);
|
|
159
136
|
}
|
|
160
137
|
// launch cmake to build
|
|
161
138
|
const procCmake = (0, child_process_1.spawnSync)('cmake', ['--build', '.', '--config', CONFIG], {
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
139
|
+
shell: true,
|
|
140
|
+
stdio: 'inherit',
|
|
141
|
+
cwd: BUILD_FOLDER,
|
|
165
142
|
});
|
|
166
143
|
if (procCmake.status !== 0) {
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
144
|
+
if (procCmake.error) {
|
|
145
|
+
console.error(procCmake.error);
|
|
146
|
+
}
|
|
147
|
+
process.exit(procCmake.status === null ? undefined : procCmake.status);
|
|
171
148
|
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
2
|
+
// Licensed under the MIT License.
|
|
3
|
+
|
|
4
|
+
// This file is generated by /js/scripts/update-version.ts
|
|
5
|
+
// Do not modify file content manually.
|
|
6
|
+
|
|
7
|
+
module.exports = { nuget: [{ feed: 'nuget', version: '1.22.0' }] };
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
2
|
+
// Licensed under the MIT License.
|
|
3
|
+
|
|
4
|
+
'use strict';
|
|
5
|
+
|
|
6
|
+
const metadataVersions = require('./install-metadata-versions.js');
|
|
7
|
+
|
|
8
|
+
const metadata = {
|
|
9
|
+
// Requirements defines a list of manifest to install for a specific platform/architecture combination.
|
|
10
|
+
requirements: {
|
|
11
|
+
'win32/x64': [],
|
|
12
|
+
'win32/arm64': [],
|
|
13
|
+
'linux/x64': ['cuda12'],
|
|
14
|
+
'linux/arm64': [],
|
|
15
|
+
'darwin/x64': [],
|
|
16
|
+
'darwin/arm64': [],
|
|
17
|
+
},
|
|
18
|
+
// Each manifest defines a list of files to install
|
|
19
|
+
manifests: {
|
|
20
|
+
'linux/x64:cuda12': {
|
|
21
|
+
'./libonnxruntime_providers_cuda.so': {
|
|
22
|
+
package: 'nuget:linux/x64:cuda12',
|
|
23
|
+
path: 'runtimes/win-x64/native/libonnxruntime_providers_cuda.so',
|
|
24
|
+
},
|
|
25
|
+
'./libonnxruntime_providers_shared.so': {
|
|
26
|
+
package: 'nuget:linux/x64:cuda12',
|
|
27
|
+
path: 'runtimes/win-x64/native/libonnxruntime_providers_shared.so',
|
|
28
|
+
},
|
|
29
|
+
'./libonnxruntime_providers_tensorrt.so': {
|
|
30
|
+
package: 'nuget:linux/x64:cuda12',
|
|
31
|
+
path: 'runtimes/win-x64/native/libonnxruntime_providers_tensorrt.so',
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
// Each package defines a list of package metadata. The first available package will be used.
|
|
36
|
+
packages: {
|
|
37
|
+
'nuget:win32/x64:cuda12': {
|
|
38
|
+
name: 'Microsoft.ML.OnnxRuntime.Gpu.Windows',
|
|
39
|
+
versions: metadataVersions.nuget,
|
|
40
|
+
},
|
|
41
|
+
'nuget:linux/x64:cuda12': {
|
|
42
|
+
name: 'Microsoft.ML.OnnxRuntime.Gpu.Linux',
|
|
43
|
+
versions: metadataVersions.nuget,
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
feeds: {
|
|
47
|
+
nuget: {
|
|
48
|
+
type: 'nuget',
|
|
49
|
+
index: 'https://api.nuget.org/v3/index.json',
|
|
50
|
+
},
|
|
51
|
+
nuget_nightly: {
|
|
52
|
+
type: 'nuget',
|
|
53
|
+
index: 'https://aiinfra.pkgs.visualstudio.com/PublicPackages/_packaging/ORT-Nightly/nuget/v3/index.json',
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
module.exports = metadata;
|
|
@@ -0,0 +1,306 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
2
|
+
// Licensed under the MIT License.
|
|
3
|
+
|
|
4
|
+
'use strict';
|
|
5
|
+
|
|
6
|
+
const fs = require('fs');
|
|
7
|
+
const https = require('https');
|
|
8
|
+
const { execFileSync } = require('child_process');
|
|
9
|
+
const path = require('path');
|
|
10
|
+
const os = require('os');
|
|
11
|
+
const AdmZip = require('adm-zip'); // Use adm-zip instead of spawn
|
|
12
|
+
|
|
13
|
+
async function downloadFile(url, dest) {
|
|
14
|
+
return new Promise((resolve, reject) => {
|
|
15
|
+
const file = fs.createWriteStream(dest);
|
|
16
|
+
https
|
|
17
|
+
.get(url, (res) => {
|
|
18
|
+
if (res.statusCode !== 200) {
|
|
19
|
+
file.close();
|
|
20
|
+
fs.unlinkSync(dest);
|
|
21
|
+
reject(new Error(`Failed to download from ${url}. HTTP status code = ${res.statusCode}`));
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
res.pipe(file);
|
|
26
|
+
file.on('finish', () => {
|
|
27
|
+
file.close();
|
|
28
|
+
resolve();
|
|
29
|
+
});
|
|
30
|
+
file.on('error', (err) => {
|
|
31
|
+
fs.unlinkSync(dest);
|
|
32
|
+
reject(err);
|
|
33
|
+
});
|
|
34
|
+
})
|
|
35
|
+
.on('error', (err) => {
|
|
36
|
+
fs.unlinkSync(dest);
|
|
37
|
+
reject(err);
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
async function downloadJson(url) {
|
|
43
|
+
return new Promise((resolve, reject) => {
|
|
44
|
+
https
|
|
45
|
+
.get(url, (res) => {
|
|
46
|
+
const { statusCode } = res;
|
|
47
|
+
const contentType = res.headers['content-type'];
|
|
48
|
+
|
|
49
|
+
if (!statusCode) {
|
|
50
|
+
reject(new Error('No response statud code from server.'));
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
if (statusCode >= 400 && statusCode < 500) {
|
|
54
|
+
resolve(null);
|
|
55
|
+
return;
|
|
56
|
+
} else if (statusCode !== 200) {
|
|
57
|
+
reject(new Error(`Failed to download build list. HTTP status code = ${statusCode}`));
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
if (!contentType || !/^application\/json/.test(contentType)) {
|
|
61
|
+
reject(new Error(`unexpected content type: ${contentType}`));
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
res.setEncoding('utf8');
|
|
65
|
+
let rawData = '';
|
|
66
|
+
res.on('data', (chunk) => {
|
|
67
|
+
rawData += chunk;
|
|
68
|
+
});
|
|
69
|
+
res.on('end', () => {
|
|
70
|
+
try {
|
|
71
|
+
resolve(JSON.parse(rawData));
|
|
72
|
+
} catch (e) {
|
|
73
|
+
reject(e);
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
res.on('error', (err) => {
|
|
77
|
+
reject(err);
|
|
78
|
+
});
|
|
79
|
+
})
|
|
80
|
+
.on('error', (err) => {
|
|
81
|
+
reject(err);
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
async function installPackages(packages, manifests, feeds) {
|
|
87
|
+
// Step.1: resolve packages
|
|
88
|
+
const resolvedPackages = new Map();
|
|
89
|
+
for (const packageCandidates of packages) {
|
|
90
|
+
// iterate all candidates from packagesInfo and try to find the first one that exists
|
|
91
|
+
for (const { feed, version } of packageCandidates.versions) {
|
|
92
|
+
const { type, index } = feeds[feed];
|
|
93
|
+
const pkg = await resolvePackage(type, index, packageCandidates.name, version);
|
|
94
|
+
if (pkg) {
|
|
95
|
+
resolvedPackages.set(packageCandidates, pkg);
|
|
96
|
+
break;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
if (!resolvedPackages.has(packageCandidates)) {
|
|
100
|
+
throw new Error(`Failed to resolve package. No package exists for: ${JSON.stringify(packageCandidates)}`);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// Step.2: download packages
|
|
105
|
+
for (const [pkgInfo, pkg] of resolvedPackages) {
|
|
106
|
+
const manifestsForPackage = manifests.filter((x) => x.packagesInfo === pkgInfo);
|
|
107
|
+
await pkg.download(manifestsForPackage);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
async function resolvePackage(type, index, packageName, version) {
|
|
112
|
+
// https://learn.microsoft.com/en-us/nuget/api/overview
|
|
113
|
+
const nugetPackageUrlResolver = async (index, packageName, version) => {
|
|
114
|
+
// STEP.1 - get Nuget package index
|
|
115
|
+
const nugetIndex = await downloadJson(index);
|
|
116
|
+
if (!nugetIndex) {
|
|
117
|
+
throw new Error(`Failed to download Nuget index from ${index}`);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// STEP.2 - get the base url of "PackageBaseAddress/3.0.0"
|
|
121
|
+
const packageBaseUrl = nugetIndex.resources.find((x) => x['@type'] === 'PackageBaseAddress/3.0.0')?.['@id'];
|
|
122
|
+
if (!packageBaseUrl) {
|
|
123
|
+
throw new Error(`Failed to find PackageBaseAddress in Nuget index`);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// STEP.3 - get the package version info
|
|
127
|
+
const packageInfo = await downloadJson(`${packageBaseUrl}${packageName.toLowerCase()}/index.json`);
|
|
128
|
+
if (!packageInfo.versions.includes(version.toLowerCase())) {
|
|
129
|
+
throw new Error(`Failed to find specific package versions for ${packageName} in ${index}`);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// STEP.4 - generate the package URL
|
|
133
|
+
const packageUrl = `${packageBaseUrl}${packageName.toLowerCase()}/${version.toLowerCase()}/${packageName.toLowerCase()}.${version.toLowerCase()}.nupkg`;
|
|
134
|
+
const packageFileName = `${packageName.toLowerCase()}.${version.toLowerCase()}.nupkg`;
|
|
135
|
+
|
|
136
|
+
return {
|
|
137
|
+
download: async (manifests) => {
|
|
138
|
+
if (manifests.length === 0) {
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// Create a temporary directory
|
|
143
|
+
const tempDir = path.join(os.tmpdir(), `onnxruntime-node-pkgs_${Date.now()}`);
|
|
144
|
+
fs.mkdirSync(tempDir, { recursive: true });
|
|
145
|
+
|
|
146
|
+
try {
|
|
147
|
+
const packageFilePath = path.join(tempDir, packageFileName);
|
|
148
|
+
|
|
149
|
+
// Download the NuGet package
|
|
150
|
+
console.log(`Downloading ${packageUrl}`);
|
|
151
|
+
await downloadFile(packageUrl, packageFilePath);
|
|
152
|
+
|
|
153
|
+
// Load the NuGet package (which is a ZIP file)
|
|
154
|
+
let zip;
|
|
155
|
+
try {
|
|
156
|
+
zip = new AdmZip(packageFilePath);
|
|
157
|
+
} catch (err) {
|
|
158
|
+
throw new Error(`Failed to open NuGet package: ${err.message}`);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
// Extract only the needed files from the package
|
|
162
|
+
const extractDir = path.join(tempDir, 'extracted');
|
|
163
|
+
fs.mkdirSync(extractDir, { recursive: true });
|
|
164
|
+
|
|
165
|
+
// Process each manifest and extract/copy files to their destinations
|
|
166
|
+
for (const manifest of manifests) {
|
|
167
|
+
const { filepath, pathInPackage } = manifest;
|
|
168
|
+
|
|
169
|
+
// Create directory for the target file
|
|
170
|
+
const targetDir = path.dirname(filepath);
|
|
171
|
+
fs.mkdirSync(targetDir, { recursive: true });
|
|
172
|
+
|
|
173
|
+
// Check if the file exists directly in the zip
|
|
174
|
+
const zipEntry = zip.getEntry(pathInPackage);
|
|
175
|
+
if (!zipEntry) {
|
|
176
|
+
throw new Error(`Failed to find ${pathInPackage} in NuGet package`);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
console.log(`Extracting ${pathInPackage} to ${filepath}`);
|
|
180
|
+
|
|
181
|
+
// Extract just this entry to a temporary location
|
|
182
|
+
const extractedFilePath = path.join(extractDir, path.basename(pathInPackage));
|
|
183
|
+
zip.extractEntryTo(zipEntry, extractDir, false, true);
|
|
184
|
+
|
|
185
|
+
// Copy to the final destination
|
|
186
|
+
fs.copyFileSync(extractedFilePath, filepath);
|
|
187
|
+
}
|
|
188
|
+
} finally {
|
|
189
|
+
// Clean up the temporary directory - always runs even if an error occurs
|
|
190
|
+
try {
|
|
191
|
+
fs.rmSync(tempDir, { recursive: true });
|
|
192
|
+
} catch (e) {
|
|
193
|
+
console.warn(`Failed to clean up temporary directory: ${tempDir}`, e);
|
|
194
|
+
// Don't rethrow this error as it would mask the original error
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
},
|
|
198
|
+
};
|
|
199
|
+
};
|
|
200
|
+
|
|
201
|
+
switch (type) {
|
|
202
|
+
case 'nuget':
|
|
203
|
+
return await nugetPackageUrlResolver(index, packageName, version);
|
|
204
|
+
default:
|
|
205
|
+
throw new Error(`Unsupported package type: ${type}`);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
function tryGetCudaVersion() {
|
|
210
|
+
// Should only return 11 or 12.
|
|
211
|
+
|
|
212
|
+
// try to get the CUDA version from the system ( `nvcc --version` )
|
|
213
|
+
let ver = 12;
|
|
214
|
+
try {
|
|
215
|
+
const nvccVersion = execFileSync('nvcc', ['--version'], { encoding: 'utf8' });
|
|
216
|
+
const match = nvccVersion.match(/release (\d+)/);
|
|
217
|
+
if (match) {
|
|
218
|
+
ver = parseInt(match[1]);
|
|
219
|
+
if (ver !== 11 && ver !== 12) {
|
|
220
|
+
throw new Error(`Unsupported CUDA version: ${ver}`);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
} catch (e) {
|
|
224
|
+
if (e?.code === 'ENOENT') {
|
|
225
|
+
console.warn('`nvcc` not found. Assuming CUDA 12.');
|
|
226
|
+
} else {
|
|
227
|
+
console.warn('Failed to detect CUDA version from `nvcc --version`:', e.message);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
// assume CUDA 12 if failed to detect
|
|
232
|
+
return ver;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
function parseInstallFlag() {
|
|
236
|
+
let flag = process.env.ONNXRUNTIME_NODE_INSTALL || process.env.npm_config_onnxruntime_node_install;
|
|
237
|
+
if (!flag) {
|
|
238
|
+
for (let i = 0; i < process.argv.length; i++) {
|
|
239
|
+
if (process.argv[i].startsWith('--onnxruntime-node-install=')) {
|
|
240
|
+
flag = process.argv[i].split('=')[1];
|
|
241
|
+
break;
|
|
242
|
+
} else if (process.argv[i] === '--onnxruntime-node-install') {
|
|
243
|
+
flag = 'true';
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
switch (flag) {
|
|
248
|
+
case 'true':
|
|
249
|
+
case '1':
|
|
250
|
+
case 'ON':
|
|
251
|
+
return true;
|
|
252
|
+
case 'skip':
|
|
253
|
+
return false;
|
|
254
|
+
case undefined: {
|
|
255
|
+
flag = parseInstallCudaFlag();
|
|
256
|
+
if (flag === 'skip') {
|
|
257
|
+
return false;
|
|
258
|
+
}
|
|
259
|
+
if (flag === 11) {
|
|
260
|
+
throw new Error('CUDA 11 is no longer supported. Please consider using CPU or upgrade to CUDA 12.');
|
|
261
|
+
}
|
|
262
|
+
if (flag === 12) {
|
|
263
|
+
return 'cuda12';
|
|
264
|
+
}
|
|
265
|
+
return undefined;
|
|
266
|
+
}
|
|
267
|
+
default:
|
|
268
|
+
if (!flag || typeof flag !== 'string') {
|
|
269
|
+
throw new Error(`Invalid value for --onnxruntime-node-install: ${flag}`);
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
function parseInstallCudaFlag() {
|
|
275
|
+
let flag = process.env.ONNXRUNTIME_NODE_INSTALL_CUDA || process.env.npm_config_onnxruntime_node_install_cuda;
|
|
276
|
+
if (!flag) {
|
|
277
|
+
for (let i = 0; i < process.argv.length; i++) {
|
|
278
|
+
if (process.argv[i].startsWith('--onnxruntime-node-install-cuda=')) {
|
|
279
|
+
flag = process.argv[i].split('=')[1];
|
|
280
|
+
break;
|
|
281
|
+
} else if (process.argv[i] === '--onnxruntime-node-install-cuda') {
|
|
282
|
+
flag = 'true';
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
switch (flag) {
|
|
287
|
+
case 'true':
|
|
288
|
+
case '1':
|
|
289
|
+
case 'ON':
|
|
290
|
+
return tryGetCudaVersion();
|
|
291
|
+
case 'v11':
|
|
292
|
+
return 11;
|
|
293
|
+
case 'v12':
|
|
294
|
+
return 12;
|
|
295
|
+
case 'skip':
|
|
296
|
+
case undefined:
|
|
297
|
+
return flag;
|
|
298
|
+
default:
|
|
299
|
+
throw new Error(`Invalid value for --onnxruntime-node-install-cuda: ${flag}`);
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
module.exports = {
|
|
304
|
+
installPackages,
|
|
305
|
+
parseInstallFlag,
|
|
306
|
+
};
|
package/script/install.js
CHANGED
|
@@ -8,21 +8,20 @@
|
|
|
8
8
|
// not always available.
|
|
9
9
|
|
|
10
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
|
|
12
|
-
// -
|
|
11
|
+
// Currently, most of the binaries are already bundled in the package, except for the files that described in the file
|
|
12
|
+
// install-metadata.js.
|
|
13
13
|
//
|
|
14
|
-
//
|
|
15
|
-
// downloaded from the
|
|
16
|
-
//
|
|
14
|
+
// Some files (eg. the CUDA EP binaries) are not bundled because they are too large to be allowed in the npm registry.
|
|
15
|
+
// Instead, they are downloaded from the Nuget feed. The script will download the binaries if they are not already
|
|
16
|
+
// present in the NPM package.
|
|
17
17
|
|
|
18
18
|
// Step.1: Check if we should exit early
|
|
19
19
|
const os = require('os');
|
|
20
|
-
const fs = require('fs');
|
|
21
|
-
const https = require('https');
|
|
22
20
|
const path = require('path');
|
|
23
|
-
const tar = require('tar');
|
|
24
|
-
const { execFileSync } = require('child_process');
|
|
25
21
|
const { bootstrap: globalAgentBootstrap } = require('global-agent');
|
|
22
|
+
const { installPackages, parseInstallFlag } = require('./install-utils.js');
|
|
23
|
+
|
|
24
|
+
const INSTALL_METADATA = require('./install-metadata.js');
|
|
26
25
|
|
|
27
26
|
// Bootstrap global-agent to honor the proxy settings in
|
|
28
27
|
// environment variables, e.g. GLOBAL_AGENT_HTTPS_PROXY.
|
|
@@ -30,169 +29,106 @@ const { bootstrap: globalAgentBootstrap } = require('global-agent');
|
|
|
30
29
|
globalAgentBootstrap();
|
|
31
30
|
|
|
32
31
|
// commandline flag:
|
|
33
|
-
//
|
|
34
|
-
// --onnxruntime-node-install
|
|
35
|
-
//
|
|
32
|
+
//
|
|
33
|
+
// --onnxruntime-node-install Force install the files that are not bundled in the package.
|
|
34
|
+
//
|
|
35
|
+
// --onnxruntime-node-install=skip Skip the installation of the files that are not bundled in the package.
|
|
36
|
+
//
|
|
37
|
+
// --onnxruntime-node-install=cuda12 Force install the CUDA EP binaries for CUDA 12.
|
|
38
|
+
//
|
|
39
|
+
// --onnxruntime-node-install-cuda Force install the CUDA EP binaries.
|
|
40
|
+
// (deprecated, use --onnxruntime-node-install=cuda12)
|
|
41
|
+
//
|
|
36
42
|
// --onnxruntime-node-install-cuda=skip Skip the installation of the CUDA EP binaries.
|
|
43
|
+
// (deprecated, use --onnxruntime-node-install=skip)
|
|
37
44
|
//
|
|
38
|
-
// Alternatively, use environment variable "ONNXRUNTIME_NODE_INSTALL_CUDA"
|
|
39
45
|
//
|
|
40
|
-
//
|
|
41
|
-
// - The platform is Linux/x64.
|
|
42
|
-
// - The binaries are not already present in the package.
|
|
43
|
-
// - The installation is not a local install (when used inside ONNX Runtime repo).
|
|
46
|
+
// Alternatively, use environment variable "ONNXRUNTIME_NODE_INSTALL" or "ONNXRUNTIME_NODE_INSTALL_CUDA" (deprecated).
|
|
44
47
|
//
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
48
|
+
// If the flag is not provided, the script will look up the metadata file to determine the manifest.
|
|
49
|
+
//
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Possible values:
|
|
53
|
+
* - undefined: the default behavior. This is the value when no installation flag is specified.
|
|
54
|
+
*
|
|
55
|
+
* - false: skip installation. This is the value when the installation flag is set to "skip":
|
|
56
|
+
* --onnxruntime-node-install=skip
|
|
57
|
+
*
|
|
58
|
+
* - true: force installation. This is the value when the installation flag is set with no value:
|
|
59
|
+
* --onnxruntime-node-install
|
|
60
|
+
*
|
|
61
|
+
* - string: the installation flag is set to a specific value:
|
|
62
|
+
* --onnxruntime-node-install=cuda12
|
|
63
|
+
*/
|
|
64
|
+
const INSTALL_FLAG = parseInstallFlag();
|
|
65
|
+
|
|
66
|
+
// if installation is skipped, exit early
|
|
67
|
+
if (INSTALL_FLAG === false) {
|
|
62
68
|
process.exit(0);
|
|
63
69
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
const
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
1. Use "--onnxruntime-node-install-cuda=skip" to skip the auto installation.
|
|
74
|
-
2. Navigate to https://aiinfra.visualstudio.com/PublicPackages/_artifacts/feed/onnxruntime-cuda-11
|
|
75
|
-
3. Download the binaries for your platform and architecture
|
|
76
|
-
4. Extract the following binaries to "node_modules/onnxruntime-node/bin/napi-v3/linux/x64:
|
|
77
|
-
- libonnxruntime_providers_tensorrt.so
|
|
78
|
-
- libonnxruntime_providers_shared.so
|
|
79
|
-
- libonnxruntime.so.${ORT_VERSION}
|
|
80
|
-
- libonnxruntime_providers_cuda.so
|
|
81
|
-
`);
|
|
82
|
-
},
|
|
83
|
-
12: `https://github.com/microsoft/onnxruntime/releases/download/v${ORT_VERSION}/onnxruntime-linux-x64-gpu-${
|
|
84
|
-
ORT_VERSION
|
|
85
|
-
}.tgz`,
|
|
86
|
-
}[INSTALL_CUDA_FLAG || tryGetCudaVersion()];
|
|
87
|
-
console.log(`Downloading "${artifactUrl}"...`);
|
|
88
|
-
|
|
89
|
-
const FILES = new Set([
|
|
90
|
-
'libonnxruntime_providers_tensorrt.so',
|
|
91
|
-
'libonnxruntime_providers_shared.so',
|
|
92
|
-
`libonnxruntime.so.${ORT_VERSION}`,
|
|
93
|
-
'libonnxruntime_providers_cuda.so',
|
|
94
|
-
]);
|
|
95
|
-
|
|
96
|
-
downloadAndExtract(artifactUrl, BIN_FOLDER, FILES);
|
|
97
|
-
|
|
98
|
-
async function downloadAndExtract(url, dest, files) {
|
|
99
|
-
return new Promise((resolve, reject) => {
|
|
100
|
-
https.get(url, (res) => {
|
|
101
|
-
const { statusCode } = res;
|
|
102
|
-
const contentType = res.headers['content-type'];
|
|
103
|
-
|
|
104
|
-
if (statusCode === 301 || statusCode === 302) {
|
|
105
|
-
downloadAndExtract(res.headers.location, dest, files).then(
|
|
106
|
-
(value) => resolve(value),
|
|
107
|
-
(reason) => reject(reason),
|
|
108
|
-
);
|
|
109
|
-
return;
|
|
110
|
-
} else if (statusCode !== 200) {
|
|
111
|
-
throw new Error(`Failed to download the binaries: ${res.statusCode} ${res.statusMessage}.
|
|
112
|
-
|
|
113
|
-
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.`);
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
if (!contentType || !/^application\/octet-stream/.test(contentType)) {
|
|
117
|
-
throw new Error(`unexpected content type: ${contentType}`);
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
res
|
|
121
|
-
.pipe(
|
|
122
|
-
tar.t({
|
|
123
|
-
strict: true,
|
|
124
|
-
onentry: (entry) => {
|
|
125
|
-
const filename = path.basename(entry.path);
|
|
126
|
-
if (entry.type === 'File' && files.has(filename)) {
|
|
127
|
-
console.log(`Extracting "${filename}" to "${dest}"...`);
|
|
128
|
-
entry.pipe(fs.createWriteStream(path.join(dest, filename)));
|
|
129
|
-
entry.on('finish', () => {
|
|
130
|
-
console.log(`Finished extracting "${filename}".`);
|
|
131
|
-
});
|
|
132
|
-
}
|
|
133
|
-
},
|
|
134
|
-
}),
|
|
135
|
-
)
|
|
136
|
-
.on('error', (err) => {
|
|
137
|
-
throw new Error(`Failed to extract the binaries: ${err.message}.
|
|
138
|
-
|
|
139
|
-
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.`);
|
|
140
|
-
});
|
|
141
|
-
});
|
|
142
|
-
});
|
|
70
|
+
// if installation is not specified, exit early when the installation is local (e.g. `npm ci` in <ORT_ROOT>/js/node/)
|
|
71
|
+
if (INSTALL_FLAG === undefined) {
|
|
72
|
+
const npm_config_local_prefix = process.env.npm_config_local_prefix;
|
|
73
|
+
const npm_package_json = process.env.npm_package_json;
|
|
74
|
+
const IS_LOCAL_INSTALL =
|
|
75
|
+
npm_config_local_prefix && npm_package_json && path.dirname(npm_package_json) === npm_config_local_prefix;
|
|
76
|
+
if (IS_LOCAL_INSTALL) {
|
|
77
|
+
process.exit(0);
|
|
78
|
+
}
|
|
143
79
|
}
|
|
144
80
|
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
ver = parseInt(match[1]);
|
|
155
|
-
if (ver !== 11 && ver !== 12) {
|
|
156
|
-
throw new Error(`Unsupported CUDA version: ${ver}`);
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
} catch (e) {
|
|
160
|
-
if (e?.code === 'ENOENT') {
|
|
161
|
-
console.warn('`nvcc` not found. Assuming CUDA 12.');
|
|
162
|
-
} else {
|
|
163
|
-
console.warn('Failed to detect CUDA version from `nvcc --version`:', e.message);
|
|
81
|
+
const PLATFORM = `${os.platform()}/${os.arch()}`;
|
|
82
|
+
let INSTALL_MANIFEST_NAMES = INSTALL_METADATA.requirements[PLATFORM] ?? [];
|
|
83
|
+
|
|
84
|
+
// if installation is specified explicitly, validate the manifest
|
|
85
|
+
if (typeof INSTALL_FLAG === 'string') {
|
|
86
|
+
const installations = INSTALL_FLAG.split(',').map((x) => x.trim());
|
|
87
|
+
for (const installation of installations) {
|
|
88
|
+
if (INSTALL_MANIFEST_NAMES.indexOf(installation) === -1) {
|
|
89
|
+
throw new Error(`Invalid installation: ${installation} for platform: ${PLATFORM}`);
|
|
164
90
|
}
|
|
165
91
|
}
|
|
92
|
+
INSTALL_MANIFEST_NAMES = installations;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const BIN_FOLDER = path.join(__dirname, '..', 'bin/napi-v6', PLATFORM);
|
|
96
|
+
const INSTALL_MANIFESTS = [];
|
|
97
|
+
|
|
98
|
+
const PACKAGES = new Set();
|
|
99
|
+
for (const name of INSTALL_MANIFEST_NAMES) {
|
|
100
|
+
const manifest = INSTALL_METADATA.manifests[`${PLATFORM}:${name}`];
|
|
101
|
+
if (!manifest) {
|
|
102
|
+
throw new Error(`Manifest not found: ${name} for platform: ${PLATFORM}`);
|
|
103
|
+
}
|
|
166
104
|
|
|
167
|
-
|
|
168
|
-
|
|
105
|
+
for (const [filename, { package: pkg, path: pathInPackage }] of Object.entries(manifest)) {
|
|
106
|
+
const packageCandidates = INSTALL_METADATA.packages[pkg];
|
|
107
|
+
if (!packageCandidates) {
|
|
108
|
+
throw new Error(`Package information not found: ${pkg}`);
|
|
109
|
+
}
|
|
110
|
+
PACKAGES.add(packageCandidates);
|
|
111
|
+
|
|
112
|
+
INSTALL_MANIFESTS.push({
|
|
113
|
+
filepath: path.normalize(path.join(BIN_FOLDER, filename)),
|
|
114
|
+
packagesInfo: packageCandidates,
|
|
115
|
+
pathInPackage,
|
|
116
|
+
});
|
|
117
|
+
}
|
|
169
118
|
}
|
|
170
119
|
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
} else if (process.argv[i] === '--onnxruntime-node-install-cuda') {
|
|
179
|
-
flag = 'true';
|
|
180
|
-
}
|
|
120
|
+
// If the installation flag is not specified, we do a check to see if the files are already installed.
|
|
121
|
+
if (INSTALL_FLAG === undefined) {
|
|
122
|
+
let hasMissingFiles = false;
|
|
123
|
+
for (const { filepath } of INSTALL_MANIFESTS) {
|
|
124
|
+
if (!require('fs').existsSync(filepath)) {
|
|
125
|
+
hasMissingFiles = true;
|
|
126
|
+
break;
|
|
181
127
|
}
|
|
182
128
|
}
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
case '1':
|
|
186
|
-
case 'ON':
|
|
187
|
-
return tryGetCudaVersion();
|
|
188
|
-
case 'v11':
|
|
189
|
-
return 11;
|
|
190
|
-
case 'v12':
|
|
191
|
-
return 12;
|
|
192
|
-
case 'skip':
|
|
193
|
-
case undefined:
|
|
194
|
-
return flag;
|
|
195
|
-
default:
|
|
196
|
-
throw new Error(`Invalid value for --onnxruntime-node-install-cuda: ${flag}`);
|
|
129
|
+
if (!hasMissingFiles) {
|
|
130
|
+
process.exit(0);
|
|
197
131
|
}
|
|
198
132
|
}
|
|
133
|
+
|
|
134
|
+
void installPackages(PACKAGES, INSTALL_MANIFESTS, INSTALL_METADATA.feeds);
|
package/script/prepack.js
CHANGED
|
@@ -1,59 +1,42 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
2
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
3
|
// Licensed under the MIT License.
|
|
4
|
-
var __createBinding =
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
if (k2 === undefined) k2 = k;
|
|
22
|
-
o[k2] = m[k];
|
|
23
|
-
});
|
|
24
|
-
var __setModuleDefault =
|
|
25
|
-
(this && this.__setModuleDefault) ||
|
|
26
|
-
(Object.create
|
|
27
|
-
? function (o, v) {
|
|
28
|
-
Object.defineProperty(o, 'default', { enumerable: true, value: v });
|
|
29
|
-
}
|
|
30
|
-
: function (o, v) {
|
|
31
|
-
o['default'] = v;
|
|
32
|
-
});
|
|
33
|
-
var __importStar =
|
|
34
|
-
(this && this.__importStar) ||
|
|
35
|
-
function (mod) {
|
|
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) {
|
|
36
21
|
if (mod && mod.__esModule) return mod;
|
|
37
22
|
var result = {};
|
|
38
|
-
if (mod != null)
|
|
39
|
-
for (var k in mod)
|
|
40
|
-
if (k !== 'default' && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
23
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
41
24
|
__setModuleDefault(result, mod);
|
|
42
25
|
return result;
|
|
43
|
-
|
|
44
|
-
Object.defineProperty(exports,
|
|
45
|
-
const fs = __importStar(require(
|
|
46
|
-
const path = __importStar(require(
|
|
26
|
+
};
|
|
27
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
28
|
+
const fs = __importStar(require("fs-extra"));
|
|
29
|
+
const path = __importStar(require("path"));
|
|
47
30
|
function updatePackageJson() {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
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.');
|
|
57
40
|
}
|
|
58
41
|
// update version of dependency "onnxruntime-common" before packing
|
|
59
42
|
updatePackageJson();
|
package/__commit.txt
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
c18e06d5e38e732600e214ba451049cec2435b06
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|