Исходный код СУБД 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
#pragma once
 
#include "Env.h"
#include "EpContextDataReadCallback.h"
#include "JsiHelper.h"
#include <jsi/jsi.h>
#include <memory>
#include "onnxruntime_cxx_api.h"
#include <vector>
 
using namespace facebook::jsi;
 
namespace onnxruntimejsi {
 
class InferenceSessionHostObject
    : public HostObjectHelper,
      public std::enable_shared_from_this<InferenceSessionHostObject> {
 public:
  InferenceSessionHostObject(std::shared_ptr<Env> env) : HostObjectHelper({
                                                                              METHOD_INFO(InferenceSessionHostObject, loadModel, 2),
                                                                              METHOD_INFO(InferenceSessionHostObject, run, 2),
                                                                              METHOD_INFO(InferenceSessionHostObject, dispose, 0),
                                                                              METHOD_INFO(InferenceSessionHostObject, endProfiling, 0),
                                                                          },
                                                                          {
                                                                              GETTER_INFO(InferenceSessionHostObject, inputMetadata),
                                                                              GETTER_INFO(InferenceSessionHostObject, outputMetadata),
                                                                          }),
                                                         env_(env) {}
 
  static inline facebook::jsi::Value
  constructor(std::shared_ptr<Env> env, facebook::jsi::Runtime& runtime,
              const facebook::jsi::Value& thisValue,
              const facebook::jsi::Value* arguments, size_t count) {
    return facebook::jsi::Object::createFromHostObject(
        runtime, std::make_shared<InferenceSessionHostObject>(env));
  }
 
 protected:
  class LoadModelAsyncWorker;
  class RunAsyncWorker;
 
 private:
  std::shared_ptr<Env> env_;
  // Declared before session_ so the session is destroyed first: ONNX Runtime may call back into
  // the callback state for as long as the session exists.
  std::shared_ptr<EpContextDataReadCallback> epContextDataRead_;
  std::shared_ptr<Ort::Session> session_;
 
  DEFINE_METHOD(loadModel);
  DEFINE_METHOD(run);
  DEFINE_METHOD(dispose);
  DEFINE_METHOD(endProfiling);
 
  DEFINE_GETTER(inputMetadata);
  DEFINE_GETTER(outputMetadata);
};
 
}  // namespace onnxruntimejsi