mirror of
https://github.com/saymrwulf/onnxruntime.git
synced 2026-06-06 00:03:22 +00:00
### Description
Use esbuild to accelerate bundle build.
This change uses esbuild to replace webpack for onnxruntime-web. Bundle
build time reduced from ~20sec to ~0.6sec on my windows dev box.
A few changes applied:
- import nodejs modules using "node:" prefix
- remove enum declaration inside namespace (EncoderUsage)
- use "fs/promise" to replace the old promisify from "util"
- separate ort-web and test-runner. Previously they are bundled
together, now they are built into 2 files.
- optimize karma runner launch time
- remove unnecessary sourcemap preprocessor. sourcemaps are handled
inside esbuild
- remove unnecessary proxies (because ort-web and test-runner are
separated now, the path are correctly inferred)
- remove file watcher for test data
- optimize special handling as esbuild plugins:
- polyfill dummy imports for node.js modules when targetting browser.
- load as content string for ort-wasm-*.worker.js
- load as content string for ./proxy-worker/main.ts
- a source patch to ort-wasm*-threaded*.js (see details in comments in
code)
- updated debug configurations for sourcemap mapping to ensure
out-of-box good dev experience
77 lines
2.4 KiB
TypeScript
77 lines
2.4 KiB
TypeScript
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
// Licensed under the MIT License.
|
|
|
|
import type {Env, InferenceSession, Tensor} from 'onnxruntime-common';
|
|
|
|
export type SerializableTensorMetadata =
|
|
[dataType: Tensor.Type, dims: readonly number[], data: Tensor.DataType, location: 'cpu'];
|
|
|
|
export type GpuBufferMetadata = {
|
|
gpuBuffer: Tensor.GpuBufferType;
|
|
download?: () => Promise<Tensor.DataTypeMap[Tensor.GpuBufferDataTypes]>;
|
|
dispose?: () => void;
|
|
};
|
|
|
|
export type UnserializableTensorMetadata =
|
|
[dataType: Tensor.Type, dims: readonly number[], data: GpuBufferMetadata, location: 'gpu-buffer']|
|
|
[dataType: Tensor.Type, dims: readonly number[], data: Tensor.DataType, location: 'cpu-pinned'];
|
|
|
|
export type TensorMetadata = SerializableTensorMetadata|UnserializableTensorMetadata;
|
|
|
|
export type SerializableSessionMetadata = [sessionHandle: number, inputNames: string[], outputNames: string[]];
|
|
|
|
export type SerializableModeldata = [modelDataOffset: number, modelDataLength: number];
|
|
|
|
interface MessageError {
|
|
err?: string;
|
|
}
|
|
|
|
interface MessageInitWasm extends MessageError {
|
|
type: 'init-wasm';
|
|
in ?: Env.WebAssemblyFlags;
|
|
}
|
|
|
|
interface MessageInitOrt extends MessageError {
|
|
type: 'init-ort';
|
|
in ?: Env;
|
|
}
|
|
|
|
interface MessageCreateSessionAllocate extends MessageError {
|
|
type: 'create_allocate';
|
|
in ?: {model: Uint8Array};
|
|
out?: SerializableModeldata;
|
|
}
|
|
|
|
interface MessageCreateSessionFinalize extends MessageError {
|
|
type: 'create_finalize';
|
|
in ?: {modeldata: SerializableModeldata; options?: InferenceSession.SessionOptions};
|
|
out?: SerializableSessionMetadata;
|
|
}
|
|
|
|
interface MessageCreateSession extends MessageError {
|
|
type: 'create';
|
|
in ?: {model: Uint8Array; options?: InferenceSession.SessionOptions};
|
|
out?: SerializableSessionMetadata;
|
|
}
|
|
|
|
interface MessageReleaseSession extends MessageError {
|
|
type: 'release';
|
|
in ?: number;
|
|
}
|
|
|
|
interface MessageRun extends MessageError {
|
|
type: 'run';
|
|
in ?: {
|
|
sessionId: number; inputIndices: number[]; inputs: SerializableTensorMetadata[]; outputIndices: number[];
|
|
options: InferenceSession.RunOptions;
|
|
};
|
|
out?: SerializableTensorMetadata[];
|
|
}
|
|
|
|
interface MesssageEndProfiling extends MessageError {
|
|
type: 'end-profiling';
|
|
in ?: number;
|
|
}
|
|
|
|
export type OrtWasmMessage = MessageInitWasm|MessageInitOrt|MessageCreateSessionAllocate|MessageCreateSessionFinalize|
|
|
MessageCreateSession|MessageReleaseSession|MessageRun|MesssageEndProfiling;
|