Исходный код СУБД 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
104
105
106
107
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
 
#include "testPch.h"
#include "RawApiTests.h"
#include "RawApiHelpers.h"
 
#include <fstream>
 
#include <roapi.h>
 
namespace ml = Microsoft::AI::MachineLearning;
 
auto CreateModelAsBuffer(const wchar_t* model_path) {
  std::ifstream input_stream(model_path, std::ios::binary | std::ios::ate);
  std::streamsize size = input_stream.tellg();
  input_stream.seekg(0, std::ios::beg);
 
  std::vector<char> buffer(static_cast<std::vector<char>::size_type>(size));
  input_stream.read(buffer.data(), size);
 
  return std::make_pair(buffer, size);
}
 
static void RawApiTestsApiTestsClassSetup() {
  WINML_EXPECT_HRESULT_SUCCEEDED(RoInitialize(RO_INIT_TYPE::RO_INIT_MULTITHREADED));
}
 
static void CreateModelFromFilePath() {
  std::wstring model_path = L"model.onnx";
  std::unique_ptr<ml::learning_model> model = nullptr;
  WINML_EXPECT_NO_THROW(model = std::make_unique<ml::learning_model>(model_path.c_str(), model_path.size()));
  WINML_EXPECT_NO_THROW(model.reset());
}
 
static void CreateCpuDevice() {
  std::unique_ptr<ml::learning_model_device> device = nullptr;
  WINML_EXPECT_NO_THROW(device = std::make_unique<ml::learning_model_device>());
}
 
static void Evaluate() {
  std::wstring model_path = L"model.onnx";
  std::unique_ptr<ml::learning_model> model = nullptr;
  WINML_EXPECT_NO_THROW(model = std::make_unique<ml::learning_model>(model_path.c_str(), model_path.size()));
 
  std::unique_ptr<ml::learning_model_device> device = nullptr;
  WINML_EXPECT_NO_THROW(device = std::make_unique<ml::learning_model_device>());
 
  RunOnDevice(*model.get(), *device.get(), InputStrategy::CopyInputs);
 
  WINML_EXPECT_NO_THROW(model.reset());
}
 
static void EvaluateNoInputCopy() {
  std::wstring model_path = L"model.onnx";
  std::unique_ptr<ml::learning_model> model = nullptr;
  WINML_EXPECT_NO_THROW(model = std::make_unique<ml::learning_model>(model_path.c_str(), model_path.size()));
 
  std::unique_ptr<ml::learning_model_device> device = nullptr;
  WINML_EXPECT_NO_THROW(device = std::make_unique<ml::learning_model_device>());
 
  RunOnDevice(*model.get(), *device.get(), InputStrategy::BindAsReference);
 
  WINML_EXPECT_NO_THROW(model.reset());
}
 
static void EvaluateManyBuffers() {
  std::wstring model_path = L"model.onnx";
  std::unique_ptr<ml::learning_model> model = nullptr;
  WINML_EXPECT_NO_THROW(model = std::make_unique<ml::learning_model>(model_path.c_str(), model_path.size()));
 
  std::unique_ptr<ml::learning_model_device> device = nullptr;
  WINML_EXPECT_NO_THROW(device = std::make_unique<ml::learning_model_device>());
 
  RunOnDevice(*model.get(), *device.get(), InputStrategy::BindWithMultipleReferences);
 
  WINML_EXPECT_NO_THROW(model.reset());
}
 
static void EvaluateFromModelFromBuffer() {
  std::wstring model_path = L"model.onnx";
 
  auto [buffer, size] = CreateModelAsBuffer(model_path.c_str());
 
  std::unique_ptr<ml::learning_model> model = nullptr;
  WINML_EXPECT_NO_THROW(model = std::make_unique<ml::learning_model>(buffer.data(), static_cast<size_t>(size)));
 
  std::unique_ptr<ml::learning_model_device> device = nullptr;
  WINML_EXPECT_NO_THROW(device = std::make_unique<ml::learning_model_device>());
 
  RunOnDevice(*model.get(), *device.get(), InputStrategy::CopyInputs);
 
  WINML_EXPECT_NO_THROW(model.reset());
}
 
const RawApiTestsApi& getapi() {
  static constexpr RawApiTestsApi api = {
    RawApiTestsApiTestsClassSetup,
    CreateModelFromFilePath,
    CreateCpuDevice,
    Evaluate,
    EvaluateNoInputCopy,
    EvaluateManyBuffers,
    EvaluateFromModelFromBuffer,
  };
  return api;
}