Исходный код СУБД RuDB — свободной СУБД с открытым исходным кодом на базе PostgreSQL
rudb
3 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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
 
#include "test/autoep/test_autoep_utils.h"
 
#include <algorithm>
#include <gtest/gtest.h>
 
#include "core/session/onnxruntime_cxx_api.h"
#include "test/util/include/api_asserts.h"
#include "test/util/include/file_util.h"
 
#if defined(_WIN32)
#include <windows.h>
#else
#include <dlfcn.h>
#endif
 
namespace onnxruntime {
namespace test {
 
Utils::ExamplePluginInfo::ExamplePluginInfo(std::filesystem::path lib_path, const char* reg_name, const char* ep_name)
    : library_path(std::move(lib_path)), registration_name(reg_name), ep_name(ep_name) {}
 
const Utils::ExamplePluginInfo Utils::example_ep_info(
    GetSharedLibraryFileName(ORT_TSTR("example_plugin_ep")),
    // The example_plugin_ep always uses the registration name as the EP name.
    "example_ep",
    "example_ep");
 
const Utils::ExamplePluginInfo Utils::example_ep_virt_gpu_info(
    GetSharedLibraryFileName(ORT_TSTR("example_plugin_ep_virt_gpu")),
    "example_plugin_ep_virt_gpu.virtual",  // Ends in ".virtual" to allow creation of virtual devices.
    // This EP's name is hardcoded to the following
    "EpVirtualGpu");
 
const Utils::ExamplePluginInfo Utils::example_ep_kernel_registry_info(
    GetSharedLibraryFileName(ORT_TSTR("example_plugin_ep_kernel_registry")),
    "example_plugin_ep_kernel_registry",
    "ExampleKernelEp");
 
void Utils::GetEp(Ort::Env& env, const std::string& ep_name, const OrtEpDevice*& ep_device) {
  const OrtApi& c_api = Ort::GetApi();
  const OrtEpDevice* const* ep_devices = nullptr;
  size_t num_devices;
  ASSERT_ORTSTATUS_OK(c_api.GetEpDevices(env, &ep_devices, &num_devices));
 
  auto it = std::find_if(ep_devices, ep_devices + num_devices,
                         [&c_api, &ep_name](const OrtEpDevice* ep_device) {
                           // example ep uses registration name as ep name
                           return c_api.EpDevice_EpName(ep_device) == ep_name;
                         });
 
  if (it == ep_devices + num_devices) {
    ep_device = nullptr;
  } else {
    ep_device = *it;
  }
}
 
void Utils::RegisterAndGetExampleEp(Ort::Env& env, const ExamplePluginInfo& ep_info,
                                    RegisteredEpDeviceUniquePtr& registered_ep) {
  const OrtApi& c_api = Ort::GetApi();
  // this should load the library and create OrtEpDevice
  ASSERT_ORTSTATUS_OK(c_api.RegisterExecutionProviderLibrary(env,
                                                             ep_info.registration_name.c_str(),
                                                             ep_info.library_path.c_str()));
  const OrtEpDevice* example_ep = nullptr;
  GetEp(env, ep_info.ep_name, example_ep);
  ASSERT_NE(example_ep, nullptr);
 
  registered_ep = RegisteredEpDeviceUniquePtr(example_ep, [&env, &ep_info, c_api](const OrtEpDevice* /*ep*/) {
    Ort::Status ignored{c_api.UnregisterExecutionProviderLibrary(env, ep_info.registration_name.c_str())};
  });
}
 
void Utils::LoadExampleEpHooks(const ExamplePluginInfo& ep_info,
                               LoadExampleEpHooksPtr& example_ep_hooks) {
  ExampleEpHooks hooks{};
#if defined(_WIN32)
  HMODULE lib = LoadLibraryW(ep_info.library_path.wstring().c_str());
  ASSERT_NE(lib, nullptr);
 
  hooks.reset_sync_count = reinterpret_cast<ExampleEpHooks::ResetSyncCountFn>(
      GetProcAddress(lib, "ExampleEpTestHooks_ResetSyncCount"));
  hooks.get_sync_count = reinterpret_cast<ExampleEpHooks::GetSyncCountFn>(
      GetProcAddress(lib, "ExampleEpTestHooks_GetSyncCount"));
  hooks.reset_preallocated_output_query = reinterpret_cast<ExampleEpHooks::ResetPreallocatedOutputQueryFn>(
      GetProcAddress(lib, "ExampleEpTestHooks_ResetPreallocatedOutputQuery"));
  hooks.get_preallocated_output_query_result = reinterpret_cast<ExampleEpHooks::GetPreallocatedOutputQueryResultFn>(
      GetProcAddress(lib, "ExampleEpTestHooks_GetPreallocatedOutputQueryResult"));
  hooks.get_preallocated_output_bad_index_rejected =
      reinterpret_cast<ExampleEpHooks::GetPreallocatedOutputBadIndexRejectedFn>(
          GetProcAddress(lib, "ExampleEpTestHooks_GetPreallocatedOutputBadIndexRejected"));
  hooks.set_create_data_transfer_failure = reinterpret_cast<ExampleEpHooks::SetCreateDataTransferFailureFn>(
      GetProcAddress(lib, "ExampleEpTestHooks_SetCreateDataTransferFailure"));
#else
  void* lib = dlopen(ep_info.library_path.c_str(), RTLD_LAZY | RTLD_LOCAL);
  ASSERT_NE(lib, nullptr);
 
  hooks.reset_sync_count = reinterpret_cast<Utils::ExampleEpHooks::ResetSyncCountFn>(
      dlsym(lib, "ExampleEpTestHooks_ResetSyncCount"));
  hooks.get_sync_count = reinterpret_cast<Utils::ExampleEpHooks::GetSyncCountFn>(
      dlsym(lib, "ExampleEpTestHooks_GetSyncCount"));
  hooks.reset_preallocated_output_query = reinterpret_cast<Utils::ExampleEpHooks::ResetPreallocatedOutputQueryFn>(
      dlsym(lib, "ExampleEpTestHooks_ResetPreallocatedOutputQuery"));
  hooks.get_preallocated_output_query_result =
      reinterpret_cast<Utils::ExampleEpHooks::GetPreallocatedOutputQueryResultFn>(
          dlsym(lib, "ExampleEpTestHooks_GetPreallocatedOutputQueryResult"));
  hooks.get_preallocated_output_bad_index_rejected =
      reinterpret_cast<Utils::ExampleEpHooks::GetPreallocatedOutputBadIndexRejectedFn>(
          dlsym(lib, "ExampleEpTestHooks_GetPreallocatedOutputBadIndexRejected"));
  hooks.set_create_data_transfer_failure = reinterpret_cast<Utils::ExampleEpHooks::SetCreateDataTransferFailureFn>(
      dlsym(lib, "ExampleEpTestHooks_SetCreateDataTransferFailure"));
#endif
 
  example_ep_hooks = LoadExampleEpHooksPtr(
      new ExampleEpHooks(std::move(hooks)),
      [lib](Utils::ExampleEpHooks* hook) {
        delete hook;
#if defined(_WIN32)
        FreeLibrary(lib);
#else
        dlclose(lib);
#endif
      });
}
 
}  // namespace test
}  // namespace onnxruntime