docs: add quixzoom-auth-core product to AAMOS

- Product documentation in docs/products/
- Updated MEMORY.md with product info
- quiXzoom Auth Core as AAMOS Identity product
This commit is contained in:
Bernt
2026-07-14 09:58:53 +00:00
parent 58ca4e68db
commit 48ea61cdcc
2730 changed files with 293827 additions and 7213 deletions
+57
View File
@@ -0,0 +1,57 @@
# ONNX Runtime Node.js Binding
ONNX Runtime Node.js binding enables Node.js applications to run ONNX model inference.
## Usage
Install the latest stable version:
```
npm install onnxruntime-node
```
Install the nightly version:
```
npm install onnxruntime-node@dev
```
Refer to [ONNX Runtime JavaScript examples](https://github.com/microsoft/onnxruntime-inference-examples/tree/main/js) for samples and tutorials.
## Requirements
ONNXRuntime works on Node.js v16.x+ (recommend v20.x+) or Electron v15.x+ (recommend v28.x+).
The following table lists the supported versions of ONNX Runtime Node.js binding provided with pre-built binaries.
| EPs/Platforms | Windows x64 | Windows arm64 | Linux x64 | Linux arm64 | MacOS x64 | MacOS arm64 |
| ------------- | ------------------ | ------------------ | ------------------ | ------------------ | ------------------ | ------------------ |
| CPU | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ |
| WebGPU | ✔️ <sup>\[1]</sup> | ✔️ <sup>\[1]</sup> | ✔️ <sup>\[1]</sup> | ❌ <sup>\[2]</sup> | ✔️ <sup>\[1]</sup> | ✔️ <sup>\[1]</sup> |
| DirectML | ✔️ | ✔️ | ❌ | ❌ | ❌ | ❌ |
| CUDA | ❌ | ❌ | ✔️<sup>\[3]</sup> | ❌ | ❌ | ❌ |
| CoreML | ❌ | ❌ | ❌ | ❌ | ✔️ | ✔️ |
- \[1]: WebGPU support is currently experimental.
- \[2]: WebGPU support is not available on Linux arm64 yet in the pre-built binaries.
- \[3]: CUDA v12. See [CUDA EP Installation](#cuda-ep-installation) for details.
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.
# GPU Support
Right now, the Windows version supports WebGPU execution provider and DML execution provider. Linux x64 can use CUDA and TensorRT.
## CUDA EP Installation
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.
```
npm install onnxruntime-node --onnxruntime-node-install=skip
```
~~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.
## License
License information can be found [here](https://github.com/microsoft/onnxruntime/blob/main/README.md#license).
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+9
View File
@@ -0,0 +1,9 @@
import { Backend, InferenceSession, InferenceSessionHandler } from 'onnxruntime-common';
import { Binding } from './binding';
declare class OnnxruntimeBackend implements Backend {
init(): Promise<void>;
createInferenceSessionHandler(pathOrBuffer: string | Uint8Array, options?: InferenceSession.SessionOptions): Promise<InferenceSessionHandler>;
}
export declare const onnxruntimeBackend: OnnxruntimeBackend;
export declare const listSupportedBackends: () => Binding.SupportedBackend[];
export {};
+148
View File
@@ -0,0 +1,148 @@
"use strict";
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
if (kind === "m") throw new TypeError("Private method is not writable");
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
};
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
};
var _OnnxruntimeSessionHandler_inferenceSession;
Object.defineProperty(exports, "__esModule", { value: true });
exports.listSupportedBackends = exports.onnxruntimeBackend = void 0;
const binding_1 = require("./binding");
const dataTypeStrings = [
undefined, // 0
'float32',
'uint8',
'int8',
'uint16',
'int16',
'int32',
'int64',
'string',
'bool',
'float16',
'float64',
'uint32',
'uint64',
undefined, // 14
undefined, // 15
undefined, // 16
undefined, // 17
undefined, // 18
undefined, // 19
undefined, // 20
'uint4',
'int4',
];
class OnnxruntimeSessionHandler {
constructor(pathOrBuffer, options) {
_OnnxruntimeSessionHandler_inferenceSession.set(this, void 0);
(0, binding_1.initOrt)();
__classPrivateFieldSet(this, _OnnxruntimeSessionHandler_inferenceSession, new binding_1.binding.InferenceSession(), "f");
if (typeof pathOrBuffer === 'string') {
__classPrivateFieldGet(this, _OnnxruntimeSessionHandler_inferenceSession, "f").loadModel(pathOrBuffer, options);
}
else {
__classPrivateFieldGet(this, _OnnxruntimeSessionHandler_inferenceSession, "f").loadModel(pathOrBuffer.buffer, pathOrBuffer.byteOffset, pathOrBuffer.byteLength, options);
}
// prepare input/output names and metadata
this.inputNames = [];
this.outputNames = [];
this.inputMetadata = [];
this.outputMetadata = [];
// this function takes raw metadata from binding and returns a tuple of the following 2 items:
// - an array of string representing names
// - an array of converted InferenceSession.ValueMetadata
const fillNamesAndMetadata = (rawMetadata) => {
const names = [];
const metadata = [];
for (const m of rawMetadata) {
names.push(m.name);
if (!m.isTensor) {
metadata.push({ name: m.name, isTensor: false });
}
else {
const type = dataTypeStrings[m.type];
if (type === undefined) {
throw new Error(`Unsupported data type: ${m.type}`);
}
const shape = [];
for (let i = 0; i < m.shape.length; ++i) {
const dim = m.shape[i];
if (dim === -1) {
shape.push(m.symbolicDimensions[i]);
}
else if (dim >= 0) {
shape.push(dim);
}
else {
throw new Error(`Invalid dimension: ${dim}`);
}
}
metadata.push({
name: m.name,
isTensor: m.isTensor,
type,
shape,
});
}
}
return [names, metadata];
};
[this.inputNames, this.inputMetadata] = fillNamesAndMetadata(__classPrivateFieldGet(this, _OnnxruntimeSessionHandler_inferenceSession, "f").inputMetadata);
[this.outputNames, this.outputMetadata] = fillNamesAndMetadata(__classPrivateFieldGet(this, _OnnxruntimeSessionHandler_inferenceSession, "f").outputMetadata);
}
async dispose() {
__classPrivateFieldGet(this, _OnnxruntimeSessionHandler_inferenceSession, "f").dispose();
}
startProfiling() {
// startProfiling is a no-op.
//
// if sessionOptions.enableProfiling is true, profiling will be enabled when the model is loaded.
}
endProfiling() {
__classPrivateFieldGet(this, _OnnxruntimeSessionHandler_inferenceSession, "f").endProfiling();
}
async run(feeds, fetches, options) {
return new Promise((resolve, reject) => {
setImmediate(() => {
try {
resolve(__classPrivateFieldGet(this, _OnnxruntimeSessionHandler_inferenceSession, "f").run(feeds, fetches, options));
}
catch (e) {
// reject if any error is thrown
reject(e);
}
});
});
}
}
_OnnxruntimeSessionHandler_inferenceSession = new WeakMap();
class OnnxruntimeBackend {
async init() {
return Promise.resolve();
}
async createInferenceSessionHandler(pathOrBuffer, options) {
return new Promise((resolve, reject) => {
setImmediate(() => {
try {
resolve(new OnnxruntimeSessionHandler(pathOrBuffer, options || {}));
}
catch (e) {
// reject if any error is thrown
reject(e);
}
});
});
}
}
exports.onnxruntimeBackend = new OnnxruntimeBackend();
exports.listSupportedBackends = binding_1.binding.listSupportedBackends;
//# sourceMappingURL=backend.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"backend.js","sourceRoot":"","sources":["../lib/backend.ts"],"names":[],"mappings":";AAAA,4DAA4D;AAC5D,kCAAkC;;;;;;;;;;;;;;;AAIlC,uCAAsD;AAEtD,MAAM,eAAe,GAAG;IACtB,SAAS,EAAE,IAAI;IACf,SAAS;IACT,OAAO;IACP,MAAM;IACN,QAAQ;IACR,OAAO;IACP,OAAO;IACP,OAAO;IACP,QAAQ;IACR,MAAM;IACN,SAAS;IACT,SAAS;IACT,QAAQ;IACR,QAAQ;IACR,SAA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;oBAChC,MAAM,CAAC,CAAC,CAAC,CAAC;gBACZ,CAAC;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"}
+47
View File
@@ -0,0 +1,47 @@
import { InferenceSession, OnnxValue, TensorConstructor } from 'onnxruntime-common';
type SessionOptions = InferenceSession.SessionOptions;
type FeedsType = {
[name: string]: OnnxValue;
};
type FetchesType = {
[name: string]: OnnxValue | null;
};
type ReturnType = {
[name: string]: OnnxValue;
};
type RunOptions = InferenceSession.RunOptions;
/**
* Binding exports a simple synchronized inference session object wrap.
*/
export declare namespace Binding {
interface ValueMetadata {
name: string;
isTensor: boolean;
symbolicDimensions: string[];
shape: number[];
type: number;
}
interface InferenceSession {
loadModel(modelPath: string, options: SessionOptions): void;
loadModel(buffer: ArrayBuffer, byteOffset: number, byteLength: number, options: SessionOptions): void;
readonly inputMetadata: ValueMetadata[];
readonly outputMetadata: ValueMetadata[];
run(feeds: FeedsType, fetches: FetchesType, options: RunOptions): ReturnType;
endProfiling(): void;
dispose(): void;
}
interface InferenceSessionConstructor {
new (): InferenceSession;
}
interface SupportedBackend {
name: string;
bundled: boolean;
}
}
export declare const binding: {
InferenceSession: Binding.InferenceSessionConstructor;
listSupportedBackends: () => Binding.SupportedBackend[];
initOrtOnce: (logLevel: number, tensorConstructor: TensorConstructor, isMainThread: boolean) => void;
};
export declare const initOrt: () => void;
export {};
+42
View File
@@ -0,0 +1,42 @@
"use strict";
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
Object.defineProperty(exports, "__esModule", { value: true });
exports.initOrt = exports.binding = void 0;
const worker_threads_1 = require("worker_threads");
const onnxruntime_common_1 = require("onnxruntime-common");
// export native binding
exports.binding =
// eslint-disable-next-line @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires
require(`../bin/napi-v6/${process.platform}/${process.arch}/onnxruntime_binding.node`);
let ortInitialized = false;
const initOrt = () => {
if (!ortInitialized) {
ortInitialized = true;
let logLevel = 2;
if (onnxruntime_common_1.env.logLevel) {
switch (onnxruntime_common_1.env.logLevel) {
case 'verbose':
logLevel = 0;
break;
case 'info':
logLevel = 1;
break;
case 'warning':
logLevel = 2;
break;
case 'error':
logLevel = 3;
break;
case 'fatal':
logLevel = 4;
break;
default:
throw new Error(`Unsupported log level: ${onnxruntime_common_1.env.logLevel}`);
}
}
exports.binding.initOrtOnce(logLevel, onnxruntime_common_1.Tensor, worker_threads_1.isMainThread);
}
};
exports.initOrt = initOrt;
//# sourceMappingURL=binding.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"binding.js","sourceRoot":"","sources":["../lib/binding.ts"],"names":[],"mappings":";AAAA,4DAA4D;AAC5D,kCAAkC;;;AAElC,mDAA8C;AAE9C,2DAAiG;AAiDjG,wBAAwB;AACX,QAAA,OAAO;AAClB,qGAAqG;AACrG,OAAO,CAAC,kBAAkB,OAAO,CAAC,QAAQ,IAAI,OAAO,CAAC,IAAI,2BAA2B,CAKpF,CAAC;AAEJ,IAAI,cAAc,GAAG,KAAK,CAAC;AACpB,MAAM,OAAO,GAAG,GAAS,EAAE;IAChC,IAAI,CAAC,cAAc,EAAE,CAAC;QACpB,cAAc,GAAG,IAAI,CAAC;QACtB,IAAI,QAAQ,GAAG,CAAC,CAAC;QACjB,IAAI,wBAAG,CAAC,QAAQ,EAAE,CAAC;YACjB,QAAQ,wBAAG,CAAC,QAAQ,EAAE,CAAC;gBACrB,KAAK,SAAS;oBACZ,QAAQ,GAAG,CAAC,CAAC;oBACb,MAAM;gBACR,KAAK,MAAM;oBACT,QAAQ,GAAG,CAAC,CAAC;oBACb,MAAM;gBACR,KAAK,SAAS;oBACZ,QAAQ,GAAG,CAAC,CAAC;oBACb,MAAM;gBACR,KAAK,OAAO;oBACV,QAAQ,GAAG,CAAC,CAAC;oBACb,MAAM;gBACR,KAAK,OAAO;oBACV,QAAQ,GAAG,CAAC,CAAC;oBACb,MAAM;gBACR;oBACE,MAAM,IAAI,KAAK,CAAC,0BAA0B,wBAAG,CAAC,QAAQ,EAAE,CAAC,CAAC;YAC9D,CAAC;QACH,CAAC;QACD,eAAO,CAAC,WAAW,CAAC,QAAQ,EAAE,2BAAM,EAAE,6BAAY,CAAC,CAAC;IACtD,CAAC;AACH,CAAC,CAAC;AA3BW,QAAA,OAAO,WA2BlB"}
+2
View File
@@ -0,0 +1,2 @@
export * from 'onnxruntime-common';
export { listSupportedBackends } from './backend';
+31
View File
@@ -0,0 +1,31 @@
"use strict";
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.listSupportedBackends = void 0;
__exportStar(require("onnxruntime-common"), exports);
var backend_1 = require("./backend");
Object.defineProperty(exports, "listSupportedBackends", { enumerable: true, get: function () { return backend_1.listSupportedBackends; } });
const onnxruntime_common_1 = require("onnxruntime-common");
const version_1 = require("./version");
const backend_2 = require("./backend");
const backends = (0, backend_2.listSupportedBackends)();
for (const backend of backends) {
(0, onnxruntime_common_1.registerBackend)(backend.name, backend_2.onnxruntimeBackend, 100);
}
Object.defineProperty(onnxruntime_common_1.env.versions, 'node', { value: version_1.version, enumerable: true });
//# sourceMappingURL=index.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../lib/index.ts"],"names":[],"mappings":";AAAA,4DAA4D;AAC5D,kCAAkC;;;;;;;;;;;;;;;;;AAElC,qDAAmC;AACnC,qCAAkD;AAAzC,gHAAA,qBAAqB,OAAA;AAC9B,2DAA0D;AAC1D,uCAAoC;AACpC,uCAAsE;AAEtE,MAAM,QAAQ,GAAG,IAAA,+BAAqB,GAAE,CAAC;AACzC,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE,CAAC;IAC/B,IAAA,oCAAe,EAAC,OAAO,CAAC,IAAI,EAAE,4BAAkB,EAAE,GAAG,CAAC,CAAC;AACzD,CAAC;AAED,MAAM,CAAC,cAAc,CAAC,wBAAG,CAAC,QAAQ,EAAE,MAAM,EAAE,EAAE,KAAK,EAAE,iBAAO,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC,CAAC"}
+1
View File
@@ -0,0 +1 @@
export declare const version = "1.27.0";
+9
View File
@@ -0,0 +1,9 @@
"use strict";
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
Object.defineProperty(exports, "__esModule", { value: true });
exports.version = void 0;
// This file is generated by /js/scripts/update-version.ts
// Do not modify file content manually.
exports.version = '1.27.0';
//# sourceMappingURL=version.js.map
+1
View File
@@ -0,0 +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"}
+163
View File
@@ -0,0 +1,163 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
import { Backend, InferenceSession, InferenceSessionHandler, SessionHandler } from 'onnxruntime-common';
import { Binding, binding, initOrt } from './binding';
const dataTypeStrings = [
undefined, // 0
'float32',
'uint8',
'int8',
'uint16',
'int16',
'int32',
'int64',
'string',
'bool',
'float16',
'float64',
'uint32',
'uint64',
undefined, // 14
undefined, // 15
undefined, // 16
undefined, // 17
undefined, // 18
undefined, // 19
undefined, // 20
'uint4',
'int4',
] as const;
class OnnxruntimeSessionHandler implements InferenceSessionHandler {
#inferenceSession: Binding.InferenceSession;
constructor(pathOrBuffer: string | Uint8Array, options: InferenceSession.SessionOptions) {
initOrt();
this.#inferenceSession = new binding.InferenceSession();
if (typeof pathOrBuffer === 'string') {
this.#inferenceSession.loadModel(pathOrBuffer, options);
} else {
this.#inferenceSession.loadModel(
pathOrBuffer.buffer as ArrayBuffer,
pathOrBuffer.byteOffset,
pathOrBuffer.byteLength,
options,
);
}
// prepare input/output names and metadata
this.inputNames = [];
this.outputNames = [];
this.inputMetadata = [];
this.outputMetadata = [];
// this function takes raw metadata from binding and returns a tuple of the following 2 items:
// - an array of string representing names
// - an array of converted InferenceSession.ValueMetadata
const fillNamesAndMetadata = (
rawMetadata: readonly Binding.ValueMetadata[],
): [names: string[], metadata: InferenceSession.ValueMetadata[]] => {
const names: string[] = [];
const metadata: InferenceSession.ValueMetadata[] = [];
for (const m of rawMetadata) {
names.push(m.name);
if (!m.isTensor) {
metadata.push({ name: m.name, isTensor: false });
} else {
const type = dataTypeStrings[m.type];
if (type === undefined) {
throw new Error(`Unsupported data type: ${m.type}`);
}
const shape: Array<number | string> = [];
for (let i = 0; i < m.shape.length; ++i) {
const dim = m.shape[i];
if (dim === -1) {
shape.push(m.symbolicDimensions[i]);
} else if (dim >= 0) {
shape.push(dim);
} else {
throw new Error(`Invalid dimension: ${dim}`);
}
}
metadata.push({
name: m.name,
isTensor: m.isTensor,
type,
shape,
});
}
}
return [names, metadata];
};
[this.inputNames, this.inputMetadata] = fillNamesAndMetadata(this.#inferenceSession.inputMetadata);
[this.outputNames, this.outputMetadata] = fillNamesAndMetadata(this.#inferenceSession.outputMetadata);
}
async dispose(): Promise<void> {
this.#inferenceSession.dispose();
}
readonly inputNames: string[];
readonly outputNames: string[];
readonly inputMetadata: InferenceSession.ValueMetadata[];
readonly outputMetadata: InferenceSession.ValueMetadata[];
startProfiling(): void {
// startProfiling is a no-op.
//
// if sessionOptions.enableProfiling is true, profiling will be enabled when the model is loaded.
}
endProfiling(): void {
this.#inferenceSession.endProfiling();
}
async run(
feeds: SessionHandler.FeedsType,
fetches: SessionHandler.FetchesType,
options: InferenceSession.RunOptions,
): Promise<SessionHandler.ReturnType> {
return new Promise((resolve, reject) => {
setImmediate(() => {
try {
resolve(this.#inferenceSession.run(feeds, fetches, options));
} catch (e) {
// reject if any error is thrown
reject(e);
}
});
});
}
}
class OnnxruntimeBackend implements Backend {
async init(): Promise<void> {
return Promise.resolve();
}
async createInferenceSessionHandler(
pathOrBuffer: string | Uint8Array,
options?: InferenceSession.SessionOptions,
): Promise<InferenceSessionHandler> {
return new Promise((resolve, reject) => {
setImmediate(() => {
try {
resolve(new OnnxruntimeSessionHandler(pathOrBuffer, options || {}));
} catch (e) {
// reject if any error is thrown
reject(e);
}
});
});
}
}
export const onnxruntimeBackend = new OnnxruntimeBackend();
export const listSupportedBackends = binding.listSupportedBackends;
+93
View File
@@ -0,0 +1,93 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
import { isMainThread } from 'worker_threads';
import { InferenceSession, OnnxValue, Tensor, TensorConstructor, env } from 'onnxruntime-common';
type SessionOptions = InferenceSession.SessionOptions;
type FeedsType = {
[name: string]: OnnxValue;
};
type FetchesType = {
[name: string]: OnnxValue | null;
};
type ReturnType = {
[name: string]: OnnxValue;
};
type RunOptions = InferenceSession.RunOptions;
/**
* Binding exports a simple synchronized inference session object wrap.
*/
export declare namespace Binding {
export interface ValueMetadata {
name: string;
isTensor: boolean;
symbolicDimensions: string[];
shape: number[];
type: number;
}
export interface InferenceSession {
loadModel(modelPath: string, options: SessionOptions): void;
loadModel(buffer: ArrayBuffer, byteOffset: number, byteLength: number, options: SessionOptions): void;
readonly inputMetadata: ValueMetadata[];
readonly outputMetadata: ValueMetadata[];
run(feeds: FeedsType, fetches: FetchesType, options: RunOptions): ReturnType;
endProfiling(): void;
dispose(): void;
}
export interface InferenceSessionConstructor {
new (): InferenceSession;
}
export interface SupportedBackend {
name: string;
bundled: boolean;
}
}
// export native binding
export const binding =
// eslint-disable-next-line @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires
require(`../bin/napi-v6/${process.platform}/${process.arch}/onnxruntime_binding.node`) as {
// eslint-disable-next-line @typescript-eslint/naming-convention
InferenceSession: Binding.InferenceSessionConstructor;
listSupportedBackends: () => Binding.SupportedBackend[];
initOrtOnce: (logLevel: number, tensorConstructor: TensorConstructor, isMainThread: boolean) => void;
};
let ortInitialized = false;
export const initOrt = (): void => {
if (!ortInitialized) {
ortInitialized = true;
let logLevel = 2;
if (env.logLevel) {
switch (env.logLevel) {
case 'verbose':
logLevel = 0;
break;
case 'info':
logLevel = 1;
break;
case 'warning':
logLevel = 2;
break;
case 'error':
logLevel = 3;
break;
case 'fatal':
logLevel = 4;
break;
default:
throw new Error(`Unsupported log level: ${env.logLevel}`);
}
}
binding.initOrtOnce(logLevel, Tensor, isMainThread);
}
};
+15
View File
@@ -0,0 +1,15 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
export * from 'onnxruntime-common';
export { listSupportedBackends } from './backend';
import { registerBackend, env } from 'onnxruntime-common';
import { version } from './version';
import { onnxruntimeBackend, listSupportedBackends } from './backend';
const backends = listSupportedBackends();
for (const backend of backends) {
registerBackend(backend.name, onnxruntimeBackend, 100);
}
Object.defineProperty(env.versions, 'node', { value: version, enumerable: true });
+7
View File
@@ -0,0 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
// This file is generated by /js/scripts/update-version.ts
// Do not modify file content manually.
export const version = '1.27.0';
+55
View File
@@ -0,0 +1,55 @@
{
"license": "MIT",
"name": "onnxruntime-node",
"repository": {
"url": "https://github.com/Microsoft/onnxruntime.git",
"type": "git"
},
"author": "fs-eire",
"binary": {
"napi_versions": [
6
]
},
"version": "1.27.0",
"dependencies": {
"adm-zip": "^0.5.16",
"global-agent": "^4.1.3",
"onnxruntime-common": "1.27.0"
},
"scripts": {
"postinstall": "node ./script/install",
"buildr": "tsc && node ./script/build --config=RelWithDebInfo",
"preprepare": "node -e \"require('node:fs').copyFileSync('./node_modules/long/index.d.ts', './node_modules/long/umd/index.d.ts')\"",
"prepare": "tsc --build script test .",
"rebuild": "tsc && node ./script/build --rebuild",
"rebuildd": "tsc && node ./script/build --rebuild --config=Debug",
"buildd": "tsc && node ./script/build --config=Debug",
"build": "tsc && node ./script/build",
"test": "tsc --build ../scripts && node ../scripts/prepare-onnx-node-tests && mocha ./test/test-main",
"prepack": "node ./script/prepack",
"rebuildr": "tsc && node ./script/build --rebuild --config=RelWithDebInfo"
},
"keywords": [
"ONNX",
"ONNXRuntime",
"ONNX Runtime"
],
"devDependencies": {
"@types/minimist": "^1.2.2",
"@types/node": "^20.10.0",
"cmake-js": "^8.0.0",
"jsonc": "^2.0.0",
"minimist": "^1.2.8",
"node-addon-api": "^6.0.0",
"protobufjs": "^7.2.4"
},
"main": "dist/index.js",
"os": [
"win32",
"darwin",
"linux"
],
"types": "dist/index.d.ts",
"description": "ONNXRuntime Node.js binding"
}
+158
View File
@@ -0,0 +1,158 @@
"use strict";
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const child_process_1 = require("child_process");
const fs = __importStar(require("fs-extra"));
const minimist_1 = __importDefault(require("minimist"));
const os = __importStar(require("os"));
const path = __importStar(require("path"));
// command line flags
const buildArgs = (0, minimist_1.default)(process.argv.slice(2));
// --config=Debug|Release|RelWithDebInfo
const CONFIG = buildArgs.config || (os.platform() === 'win32' ? 'RelWithDebInfo' : 'Release');
if (CONFIG !== 'Debug' && CONFIG !== 'Release' && CONFIG !== 'RelWithDebInfo') {
throw new Error(`unrecognized config: ${CONFIG}`);
}
// --arch=x64|ia32|arm64|arm
const ARCH = buildArgs.arch || os.arch();
if (ARCH !== 'x64' && ARCH !== 'ia32' && ARCH !== 'arm64' && ARCH !== 'arm') {
throw new Error(`unrecognized architecture: ${ARCH}`);
}
// --onnxruntime-build-dir=
const ONNXRUNTIME_BUILD_DIR = buildArgs['onnxruntime-build-dir'];
// --onnxruntime-generator=
const ONNXRUNTIME_GENERATOR = buildArgs['onnxruntime-generator'];
// --rebuild
const REBUILD = !!buildArgs.rebuild;
// --use_dml
const USE_DML = !!buildArgs.use_dml;
// --use_webgpu
const USE_WEBGPU = !!buildArgs.use_webgpu;
// --use_cuda
const USE_CUDA = !!buildArgs.use_cuda;
// --use_tensorrt
const USE_TENSORRT = !!buildArgs.use_tensorrt;
// --use_coreml
const USE_COREML = !!buildArgs.use_coreml;
// --use_qnn
const USE_QNN = !!buildArgs.use_qnn;
// --dll_deps=
const DLL_DEPS = buildArgs.dll_deps;
// build path
const ROOT_FOLDER = path.join(__dirname, '..');
const BIN_FOLDER = path.join(ROOT_FOLDER, 'bin');
const BUILD_FOLDER = path.join(ROOT_FOLDER, 'build');
// if rebuild, clean up the dist folders
if (REBUILD) {
fs.removeSync(BIN_FOLDER);
fs.removeSync(BUILD_FOLDER);
}
const args = [
'cmake-js',
REBUILD ? 'reconfigure' : 'configure',
`--arch=${ARCH}`,
'--CDnapi_build_version=6',
`--CDCMAKE_BUILD_TYPE=${CONFIG}`,
];
if (ONNXRUNTIME_BUILD_DIR && typeof ONNXRUNTIME_BUILD_DIR === 'string') {
args.push(`--CDONNXRUNTIME_BUILD_DIR=${ONNXRUNTIME_BUILD_DIR}`);
}
if (ONNXRUNTIME_GENERATOR && typeof ONNXRUNTIME_GENERATOR === 'string') {
args.push(`--CDONNXRUNTIME_GENERATOR=${ONNXRUNTIME_GENERATOR}`);
}
if (USE_DML) {
args.push('--CDUSE_DML=ON');
}
if (USE_WEBGPU) {
args.push('--CDUSE_WEBGPU=ON');
}
if (USE_CUDA) {
args.push('--CDUSE_CUDA=ON');
}
if (USE_TENSORRT) {
args.push('--CDUSE_TENSORRT=ON');
}
if (USE_COREML) {
args.push('--CDUSE_COREML=ON');
}
if (USE_QNN) {
args.push('--CDUSE_QNN=ON');
}
if (DLL_DEPS) {
args.push(`--CDORT_NODEJS_DLL_DEPS=${DLL_DEPS}`);
}
// set CMAKE_OSX_ARCHITECTURES for macOS build
if (os.platform() === 'darwin') {
if (ARCH === 'x64') {
args.push('--CDCMAKE_OSX_ARCHITECTURES=x86_64');
}
else if (ARCH === 'arm64') {
args.push('--CDCMAKE_OSX_ARCHITECTURES=arm64');
}
else {
throw new Error(`architecture not supported for macOS build: ${ARCH}`);
}
}
// In Windows, "npx cmake-js configure" uses a powershell script to detect the Visual Studio installation.
// The script uses the environment variable LIB. If an invalid path is specified in LIB, the script will fail.
// So we override the LIB environment variable to remove invalid paths.
const envOverride = os.platform() === 'win32' && process.env.LIB
? { ...process.env, LIB: process.env.LIB.split(';').filter(fs.existsSync).join(';') }
: process.env;
// launch cmake-js configure
const procCmakejs = (0, child_process_1.spawnSync)('npx', args, { shell: true, stdio: 'inherit', cwd: ROOT_FOLDER, env: envOverride });
if (procCmakejs.status !== 0) {
if (procCmakejs.error) {
console.error(procCmakejs.error);
}
process.exit(procCmakejs.status === null ? undefined : procCmakejs.status);
}
// launch cmake to build
const procCmake = (0, child_process_1.spawnSync)('cmake', ['--build', '.', '--config', CONFIG], {
shell: true,
stdio: 'inherit',
cwd: BUILD_FOLDER,
});
if (procCmake.status !== 0) {
if (procCmake.error) {
console.error(procCmake.error);
}
process.exit(procCmake.status === null ? undefined : procCmake.status);
}
+130
View File
@@ -0,0 +1,130 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
import { spawnSync } from 'child_process';
import * as fs from 'fs-extra';
import minimist from 'minimist';
import * as os from 'os';
import * as path from 'path';
// command line flags
const buildArgs = minimist(process.argv.slice(2));
// --config=Debug|Release|RelWithDebInfo
const CONFIG: 'Debug' | 'Release' | 'RelWithDebInfo' =
buildArgs.config || (os.platform() === 'win32' ? 'RelWithDebInfo' : 'Release');
if (CONFIG !== 'Debug' && CONFIG !== 'Release' && CONFIG !== 'RelWithDebInfo') {
throw new Error(`unrecognized config: ${CONFIG}`);
}
// --arch=x64|ia32|arm64|arm
const ARCH: 'x64' | 'ia32' | 'arm64' | 'arm' = buildArgs.arch || os.arch();
if (ARCH !== 'x64' && ARCH !== 'ia32' && ARCH !== 'arm64' && ARCH !== 'arm') {
throw new Error(`unrecognized architecture: ${ARCH}`);
}
// --onnxruntime-build-dir=
const ONNXRUNTIME_BUILD_DIR = buildArgs['onnxruntime-build-dir'];
// --onnxruntime-generator=
const ONNXRUNTIME_GENERATOR = buildArgs['onnxruntime-generator'];
// --rebuild
const REBUILD = !!buildArgs.rebuild;
// --use_dml
const USE_DML = !!buildArgs.use_dml;
// --use_webgpu
const USE_WEBGPU = !!buildArgs.use_webgpu;
// --use_cuda
const USE_CUDA = !!buildArgs.use_cuda;
// --use_tensorrt
const USE_TENSORRT = !!buildArgs.use_tensorrt;
// --use_coreml
const USE_COREML = !!buildArgs.use_coreml;
// --use_qnn
const USE_QNN = !!buildArgs.use_qnn;
// --dll_deps=
const DLL_DEPS = buildArgs.dll_deps;
// build path
const ROOT_FOLDER = path.join(__dirname, '..');
const BIN_FOLDER = path.join(ROOT_FOLDER, 'bin');
const BUILD_FOLDER = path.join(ROOT_FOLDER, 'build');
// if rebuild, clean up the dist folders
if (REBUILD) {
fs.removeSync(BIN_FOLDER);
fs.removeSync(BUILD_FOLDER);
}
const args = [
'cmake-js',
REBUILD ? 'reconfigure' : 'configure',
`--arch=${ARCH}`,
'--CDnapi_build_version=6',
`--CDCMAKE_BUILD_TYPE=${CONFIG}`,
];
if (ONNXRUNTIME_BUILD_DIR && typeof ONNXRUNTIME_BUILD_DIR === 'string') {
args.push(`--CDONNXRUNTIME_BUILD_DIR=${ONNXRUNTIME_BUILD_DIR}`);
}
if (ONNXRUNTIME_GENERATOR && typeof ONNXRUNTIME_GENERATOR === 'string') {
args.push(`--CDONNXRUNTIME_GENERATOR=${ONNXRUNTIME_GENERATOR}`);
}
if (USE_DML) {
args.push('--CDUSE_DML=ON');
}
if (USE_WEBGPU) {
args.push('--CDUSE_WEBGPU=ON');
}
if (USE_CUDA) {
args.push('--CDUSE_CUDA=ON');
}
if (USE_TENSORRT) {
args.push('--CDUSE_TENSORRT=ON');
}
if (USE_COREML) {
args.push('--CDUSE_COREML=ON');
}
if (USE_QNN) {
args.push('--CDUSE_QNN=ON');
}
if (DLL_DEPS) {
args.push(`--CDORT_NODEJS_DLL_DEPS=${DLL_DEPS}`);
}
// set CMAKE_OSX_ARCHITECTURES for macOS build
if (os.platform() === 'darwin') {
if (ARCH === 'x64') {
args.push('--CDCMAKE_OSX_ARCHITECTURES=x86_64');
} else if (ARCH === 'arm64') {
args.push('--CDCMAKE_OSX_ARCHITECTURES=arm64');
} else {
throw new Error(`architecture not supported for macOS build: ${ARCH}`);
}
}
// In Windows, "npx cmake-js configure" uses a powershell script to detect the Visual Studio installation.
// The script uses the environment variable LIB. If an invalid path is specified in LIB, the script will fail.
// So we override the LIB environment variable to remove invalid paths.
const envOverride =
os.platform() === 'win32' && process.env.LIB
? { ...process.env, LIB: process.env.LIB.split(';').filter(fs.existsSync).join(';') }
: process.env;
// launch cmake-js configure
const procCmakejs = spawnSync('npx', args, { shell: true, stdio: 'inherit', cwd: ROOT_FOLDER, env: envOverride });
if (procCmakejs.status !== 0) {
if (procCmakejs.error) {
console.error(procCmakejs.error);
}
process.exit(procCmakejs.status === null ? undefined : procCmakejs.status);
}
// launch cmake to build
const procCmake = spawnSync('cmake', ['--build', '.', '--config', CONFIG], {
shell: true,
stdio: 'inherit',
cwd: BUILD_FOLDER,
});
if (procCmake.status !== 0) {
if (procCmake.error) {
console.error(procCmake.error);
}
process.exit(procCmake.status === null ? undefined : procCmake.status);
}
@@ -0,0 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
// This file is generated by /js/scripts/update-version.ts
// Do not modify file content manually.
module.exports = { nuget: [{ feed: 'nuget', version: '1.27.0' }] };
+58
View File
@@ -0,0 +1,58 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
'use strict';
const metadataVersions = require('./install-metadata-versions.js');
const metadata = {
// Requirements defines a list of manifest to install for a specific platform/architecture combination.
requirements: {
'win32/x64': [],
'win32/arm64': [],
'linux/x64': ['cuda12'],
'linux/arm64': [],
'darwin/x64': [],
'darwin/arm64': [],
},
// Each manifest defines a list of files to install
manifests: {
'linux/x64:cuda12': {
'./libonnxruntime_providers_cuda.so': {
package: 'nuget:linux/x64:cuda12',
path: 'runtimes/linux-x64/native/libonnxruntime_providers_cuda.so',
},
'./libonnxruntime_providers_shared.so': {
package: 'nuget:linux/x64:cuda12',
path: 'runtimes/linux-x64/native/libonnxruntime_providers_shared.so',
},
'./libonnxruntime_providers_tensorrt.so': {
package: 'nuget:linux/x64:cuda12',
path: 'runtimes/linux-x64/native/libonnxruntime_providers_tensorrt.so',
},
},
},
// Each package defines a list of package metadata. The first available package will be used.
packages: {
'nuget:win32/x64:cuda12': {
name: 'Microsoft.ML.OnnxRuntime.Gpu.Windows',
versions: metadataVersions.nuget,
},
'nuget:linux/x64:cuda12': {
name: 'Microsoft.ML.OnnxRuntime.Gpu.Linux',
versions: metadataVersions.nuget,
},
},
feeds: {
nuget: {
type: 'nuget',
index: 'https://api.nuget.org/v3/index.json',
},
nuget_nightly: {
type: 'nuget',
index: 'https://aiinfra.pkgs.visualstudio.com/PublicPackages/_packaging/ORT-Nightly/nuget/v3/index.json',
},
},
};
module.exports = metadata;
+306
View File
@@ -0,0 +1,306 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
'use strict';
const fs = require('fs');
const https = require('https');
const { execFileSync } = require('child_process');
const path = require('path');
const os = require('os');
const AdmZip = require('adm-zip'); // Use adm-zip instead of spawn
async function downloadFile(url, dest) {
return new Promise((resolve, reject) => {
const file = fs.createWriteStream(dest);
https
.get(url, (res) => {
if (res.statusCode !== 200) {
file.close();
fs.unlinkSync(dest);
reject(new Error(`Failed to download from ${url}. HTTP status code = ${res.statusCode}`));
return;
}
res.pipe(file);
file.on('finish', () => {
file.close();
resolve();
});
file.on('error', (err) => {
fs.unlinkSync(dest);
reject(err);
});
})
.on('error', (err) => {
fs.unlinkSync(dest);
reject(err);
});
});
}
async function downloadJson(url) {
return new Promise((resolve, reject) => {
https
.get(url, (res) => {
const { statusCode } = res;
const contentType = res.headers['content-type'];
if (!statusCode) {
reject(new Error('No response statud code from server.'));
return;
}
if (statusCode >= 400 && statusCode < 500) {
resolve(null);
return;
} else if (statusCode !== 200) {
reject(new Error(`Failed to download build list. HTTP status code = ${statusCode}`));
return;
}
if (!contentType || !/^application\/json/.test(contentType)) {
reject(new Error(`unexpected content type: ${contentType}`));
return;
}
res.setEncoding('utf8');
let rawData = '';
res.on('data', (chunk) => {
rawData += chunk;
});
res.on('end', () => {
try {
resolve(JSON.parse(rawData));
} catch (e) {
reject(e);
}
});
res.on('error', (err) => {
reject(err);
});
})
.on('error', (err) => {
reject(err);
});
});
}
async function installPackages(packages, manifests, feeds) {
// Step.1: resolve packages
const resolvedPackages = new Map();
for (const packageCandidates of packages) {
// iterate all candidates from packagesInfo and try to find the first one that exists
for (const { feed, version } of packageCandidates.versions) {
const { type, index } = feeds[feed];
const pkg = await resolvePackage(type, index, packageCandidates.name, version);
if (pkg) {
resolvedPackages.set(packageCandidates, pkg);
break;
}
}
if (!resolvedPackages.has(packageCandidates)) {
throw new Error(`Failed to resolve package. No package exists for: ${JSON.stringify(packageCandidates)}`);
}
}
// Step.2: download packages
for (const [pkgInfo, pkg] of resolvedPackages) {
const manifestsForPackage = manifests.filter((x) => x.packagesInfo === pkgInfo);
await pkg.download(manifestsForPackage);
}
}
async function resolvePackage(type, index, packageName, version) {
// https://learn.microsoft.com/en-us/nuget/api/overview
const nugetPackageUrlResolver = async (index, packageName, version) => {
// STEP.1 - get Nuget package index
const nugetIndex = await downloadJson(index);
if (!nugetIndex) {
throw new Error(`Failed to download Nuget index from ${index}`);
}
// STEP.2 - get the base url of "PackageBaseAddress/3.0.0"
const packageBaseUrl = nugetIndex.resources.find((x) => x['@type'] === 'PackageBaseAddress/3.0.0')?.['@id'];
if (!packageBaseUrl) {
throw new Error(`Failed to find PackageBaseAddress in Nuget index`);
}
// STEP.3 - get the package version info
const packageInfo = await downloadJson(`${packageBaseUrl}${packageName.toLowerCase()}/index.json`);
if (!packageInfo.versions.includes(version.toLowerCase())) {
throw new Error(`Failed to find specific package versions for ${packageName} in ${index}`);
}
// STEP.4 - generate the package URL
const packageUrl = `${packageBaseUrl}${packageName.toLowerCase()}/${version.toLowerCase()}/${packageName.toLowerCase()}.${version.toLowerCase()}.nupkg`;
const packageFileName = `${packageName.toLowerCase()}.${version.toLowerCase()}.nupkg`;
return {
download: async (manifests) => {
if (manifests.length === 0) {
return;
}
// Create a temporary directory
const tempDir = path.join(os.tmpdir(), `onnxruntime-node-pkgs_${Date.now()}`);
fs.mkdirSync(tempDir, { recursive: true });
try {
const packageFilePath = path.join(tempDir, packageFileName);
// Download the NuGet package
console.log(`Downloading ${packageUrl}`);
await downloadFile(packageUrl, packageFilePath);
// Load the NuGet package (which is a ZIP file)
let zip;
try {
zip = new AdmZip(packageFilePath);
} catch (err) {
throw new Error(`Failed to open NuGet package: ${err.message}`);
}
// Extract only the needed files from the package
const extractDir = path.join(tempDir, 'extracted');
fs.mkdirSync(extractDir, { recursive: true });
// Process each manifest and extract/copy files to their destinations
for (const manifest of manifests) {
const { filepath, pathInPackage } = manifest;
// Create directory for the target file
const targetDir = path.dirname(filepath);
fs.mkdirSync(targetDir, { recursive: true });
// Check if the file exists directly in the zip
const zipEntry = zip.getEntry(pathInPackage);
if (!zipEntry) {
throw new Error(`Failed to find ${pathInPackage} in NuGet package`);
}
console.log(`Extracting ${pathInPackage} to ${filepath}`);
// Extract just this entry to a temporary location
const extractedFilePath = path.join(extractDir, path.basename(pathInPackage));
zip.extractEntryTo(zipEntry, extractDir, false, true);
// Copy to the final destination
fs.copyFileSync(extractedFilePath, filepath);
}
} finally {
// Clean up the temporary directory - always runs even if an error occurs
try {
fs.rmSync(tempDir, { recursive: true });
} catch (e) {
console.warn(`Failed to clean up temporary directory: ${tempDir}`, e);
// Don't rethrow this error as it would mask the original error
}
}
},
};
};
switch (type) {
case 'nuget':
return await nugetPackageUrlResolver(index, packageName, version);
default:
throw new Error(`Unsupported package type: ${type}`);
}
}
function tryGetCudaVersion() {
// Should only return 11 or 12.
// try to get the CUDA version from the system ( `nvcc --version` )
let ver = 12;
try {
const nvccVersion = execFileSync('nvcc', ['--version'], { encoding: 'utf8' });
const match = nvccVersion.match(/release (\d+)/);
if (match) {
ver = parseInt(match[1]);
if (ver !== 11 && ver !== 12) {
throw new Error(`Unsupported CUDA version: ${ver}`);
}
}
} catch (e) {
if (e?.code === 'ENOENT') {
console.warn('`nvcc` not found. Assuming CUDA 12.');
} else {
console.warn('Failed to detect CUDA version from `nvcc --version`:', e.message);
}
}
// assume CUDA 12 if failed to detect
return ver;
}
function parseInstallFlag() {
let flag = process.env.ONNXRUNTIME_NODE_INSTALL || process.env.npm_config_onnxruntime_node_install;
if (!flag) {
for (let i = 0; i < process.argv.length; i++) {
if (process.argv[i].startsWith('--onnxruntime-node-install=')) {
flag = process.argv[i].split('=')[1];
break;
} else if (process.argv[i] === '--onnxruntime-node-install') {
flag = 'true';
}
}
}
switch (flag) {
case 'true':
case '1':
case 'ON':
return true;
case 'skip':
return false;
case undefined: {
flag = parseInstallCudaFlag();
if (flag === 'skip') {
return false;
}
if (flag === 11) {
throw new Error('CUDA 11 is no longer supported. Please consider using CPU or upgrade to CUDA 12.');
}
if (flag === 12) {
return 'cuda12';
}
return undefined;
}
default:
if (!flag || typeof flag !== 'string') {
throw new Error(`Invalid value for --onnxruntime-node-install: ${flag}`);
}
}
}
function parseInstallCudaFlag() {
let flag = process.env.ONNXRUNTIME_NODE_INSTALL_CUDA || process.env.npm_config_onnxruntime_node_install_cuda;
if (!flag) {
for (let i = 0; i < process.argv.length; i++) {
if (process.argv[i].startsWith('--onnxruntime-node-install-cuda=')) {
flag = process.argv[i].split('=')[1];
break;
} else if (process.argv[i] === '--onnxruntime-node-install-cuda') {
flag = 'true';
}
}
}
switch (flag) {
case 'true':
case '1':
case 'ON':
return tryGetCudaVersion();
case 'v11':
return 11;
case 'v12':
return 12;
case 'skip':
case undefined:
return flag;
default:
throw new Error(`Invalid value for --onnxruntime-node-install-cuda: ${flag}`);
}
}
module.exports = {
installPackages,
parseInstallFlag,
};
+134
View File
@@ -0,0 +1,134 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
'use strict';
// This script is written in JavaScript. This is because it is used in "install" script in package.json, which is called
// when the package is installed either as a dependency or from "npm ci"/"npm install" without parameters. TypeScript is
// not always available.
// The purpose of this script is to download the required binaries for the platform and architecture.
// Currently, most of the binaries are already bundled in the package, except for the files that described in the file
// install-metadata.js.
//
// Some files (eg. the CUDA EP binaries) are not bundled because they are too large to be allowed in the npm registry.
// Instead, they are downloaded from the Nuget feed. The script will download the binaries if they are not already
// present in the NPM package.
// Step.1: Check if we should exit early
const os = require('os');
const path = require('path');
const { bootstrap: globalAgentBootstrap } = require('global-agent');
const { installPackages, parseInstallFlag } = require('./install-utils.js');
const INSTALL_METADATA = require('./install-metadata.js');
// Bootstrap global-agent to honor the proxy settings in
// environment variables, e.g. GLOBAL_AGENT_HTTPS_PROXY.
// See the https://github.com/gajus/global-agent ReadMe.md regarding environment variables.
globalAgentBootstrap();
// commandline flag:
//
// --onnxruntime-node-install Force install the files that are not bundled in the package.
//
// --onnxruntime-node-install=skip Skip the installation of the files that are not bundled in the package.
//
// --onnxruntime-node-install=cuda12 Force install the CUDA EP binaries for CUDA 12.
//
// --onnxruntime-node-install-cuda Force install the CUDA EP binaries.
// (deprecated, use --onnxruntime-node-install=cuda12)
//
// --onnxruntime-node-install-cuda=skip Skip the installation of the CUDA EP binaries.
// (deprecated, use --onnxruntime-node-install=skip)
//
//
// Alternatively, use environment variable "ONNXRUNTIME_NODE_INSTALL" or "ONNXRUNTIME_NODE_INSTALL_CUDA" (deprecated).
//
// If the flag is not provided, the script will look up the metadata file to determine the manifest.
//
/**
* Possible values:
* - undefined: the default behavior. This is the value when no installation flag is specified.
*
* - false: skip installation. This is the value when the installation flag is set to "skip":
* --onnxruntime-node-install=skip
*
* - true: force installation. This is the value when the installation flag is set with no value:
* --onnxruntime-node-install
*
* - string: the installation flag is set to a specific value:
* --onnxruntime-node-install=cuda12
*/
const INSTALL_FLAG = parseInstallFlag();
// if installation is skipped, exit early
if (INSTALL_FLAG === false) {
process.exit(0);
}
// if installation is not specified, exit early when the installation is local (e.g. `npm ci` in <ORT_ROOT>/js/node/)
if (INSTALL_FLAG === undefined) {
const npm_config_local_prefix = process.env.npm_config_local_prefix;
const npm_package_json = process.env.npm_package_json;
const IS_LOCAL_INSTALL =
npm_config_local_prefix && npm_package_json && path.dirname(npm_package_json) === npm_config_local_prefix;
if (IS_LOCAL_INSTALL) {
process.exit(0);
}
}
const PLATFORM = `${os.platform()}/${os.arch()}`;
let INSTALL_MANIFEST_NAMES = INSTALL_METADATA.requirements[PLATFORM] ?? [];
// if installation is specified explicitly, validate the manifest
if (typeof INSTALL_FLAG === 'string') {
const installations = INSTALL_FLAG.split(',').map((x) => x.trim());
for (const installation of installations) {
if (INSTALL_MANIFEST_NAMES.indexOf(installation) === -1) {
throw new Error(`Invalid installation: ${installation} for platform: ${PLATFORM}`);
}
}
INSTALL_MANIFEST_NAMES = installations;
}
const BIN_FOLDER = path.join(__dirname, '..', 'bin/napi-v6', PLATFORM);
const INSTALL_MANIFESTS = [];
const PACKAGES = new Set();
for (const name of INSTALL_MANIFEST_NAMES) {
const manifest = INSTALL_METADATA.manifests[`${PLATFORM}:${name}`];
if (!manifest) {
throw new Error(`Manifest not found: ${name} for platform: ${PLATFORM}`);
}
for (const [filename, { package: pkg, path: pathInPackage }] of Object.entries(manifest)) {
const packageCandidates = INSTALL_METADATA.packages[pkg];
if (!packageCandidates) {
throw new Error(`Package information not found: ${pkg}`);
}
PACKAGES.add(packageCandidates);
INSTALL_MANIFESTS.push({
filepath: path.normalize(path.join(BIN_FOLDER, filename)),
packagesInfo: packageCandidates,
pathInPackage,
});
}
}
// If the installation flag is not specified, we do a check to see if the files are already installed.
if (INSTALL_FLAG === undefined) {
let hasMissingFiles = false;
for (const { filepath } of INSTALL_MANIFESTS) {
if (!require('fs').existsSync(filepath)) {
hasMissingFiles = true;
break;
}
}
if (!hasMissingFiles) {
process.exit(0);
}
}
void installPackages(PACKAGES, INSTALL_MANIFESTS, INSTALL_METADATA.feeds);
+52
View File
@@ -0,0 +1,52 @@
"use strict";
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
const fs = __importStar(require("fs-extra"));
const path = __importStar(require("path"));
function updatePackageJson() {
const commonPackageJsonPath = path.join(__dirname, '..', '..', 'common', 'package.json');
const selfPackageJsonPath = path.join(__dirname, '..', 'package.json');
console.log(`=== start to update package.json: ${selfPackageJsonPath}`);
const packageCommon = fs.readJSONSync(commonPackageJsonPath);
const packageSelf = fs.readJSONSync(selfPackageJsonPath);
const version = packageCommon.version;
packageSelf.dependencies['onnxruntime-common'] = `${version}`;
fs.writeJSONSync(selfPackageJsonPath, packageSelf, { spaces: 2 });
console.log('=== finished updating package.json.');
}
// update version of dependency "onnxruntime-common" before packing
updatePackageJson();
+20
View File
@@ -0,0 +1,20 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
import * as fs from 'fs-extra';
import * as path from 'path';
function updatePackageJson() {
const commonPackageJsonPath = path.join(__dirname, '..', '..', 'common', 'package.json');
const selfPackageJsonPath = path.join(__dirname, '..', 'package.json');
console.log(`=== start to update package.json: ${selfPackageJsonPath}`);
const packageCommon = fs.readJSONSync(commonPackageJsonPath);
const packageSelf = fs.readJSONSync(selfPackageJsonPath);
const version = packageCommon.version;
packageSelf.dependencies['onnxruntime-common'] = `${version}`;
fs.writeJSONSync(selfPackageJsonPath, packageSelf, { spaces: 2 });
console.log('=== finished updating package.json.');
}
// update version of dependency "onnxruntime-common" before packing
updatePackageJson();