Исходный код СУБД RuDB — свободной СУБД с открытым исходным кодом на базе PostgreSQL
rudb
2 days ago bd039d1e92813358c5c5a1e346b49074baf513f2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
// 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 inference session object wrap.
 *
 * `loadModel()` returns a Promise. A session that registers a synchronous JavaScript callback is
 * constructed on a worker thread so that the event loop remains available to service that callback.
 */
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): Promise<void>;
    loadModel(buffer: ArrayBuffer, byteOffset: number, byteLength: number, options: SessionOptions): Promise<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;
    /** @internal Native callback bridge used by binding tests, not a supported API. */
    // eslint-disable-next-line @typescript-eslint/naming-convention
    __testEpContextDataReadCallback: (
      callback: (name: string) => unknown,
      maxDataSize: number,
      name: string,
    ) => Promise<Buffer>;
  };
 
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);
  }
};