Исходный код СУБД 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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
 
#if !defined(ORT_MINIMAL_BUILD) && defined(ORT_UNIT_TEST_HAS_CUDA_PLUGIN_EP)
 
#include "core/framework/execution_provider.h"
#include "test/unittest_util/test_dynamic_plugin_ep.h"
 
#include <limits>
#include <string>
 
#include "test/util/include/asserts.h"
 
#if defined(USE_CUDA) && defined(ORT_USE_EP_API_ADAPTERS)
#include "contrib_ops/cpu/bert/attention_common.h"
#include "core/providers/cuda/plugin/cuda_kernel_adapter.h"
#endif
 
namespace onnxruntime::test {
 
namespace dynamic_plugin_ep_test_infra = onnxruntime::test::dynamic_plugin_ep_infra;
 
TEST(DynamicPluginEpInfraTest, ParseInitializationConfigParsesOptionalFields) {
  constexpr std::string_view kConfigJson = R"json(
{
  "ep_library_registration_name": "CUDAExecutionProvider",
  "ep_library_path": "/tmp/libonnxruntime_providers_cuda.so",
  "selected_ep_device_indices": [0, 2],
  "default_ep_options": {
    "ep.cuda.use_tf32": "1",
    "ep.cuda.prefer_nhwc_layout": "1"
  },
  "tests_to_skip": [
    "CudaTests.SkipMe",
    "GraphTests.SkipMeToo"
  ]
}
)json";
 
  dynamic_plugin_ep_test_infra::InitializationConfig config{};
  ASSERT_STATUS_OK(dynamic_plugin_ep_test_infra::ParseInitializationConfig(kConfigJson, config));
 
  EXPECT_EQ(config.ep_library_registration_name, "CUDAExecutionProvider");
  EXPECT_EQ(config.ep_library_path, "/tmp/libonnxruntime_providers_cuda.so");
  EXPECT_TRUE(config.selected_ep_name.empty());
  EXPECT_THAT(config.selected_ep_device_indices, ::testing::ElementsAre(0u, 2u));
  EXPECT_THAT(config.default_ep_options,
              ::testing::UnorderedElementsAre(
                  ::testing::Pair("ep.cuda.prefer_nhwc_layout", "1"),
                  ::testing::Pair("ep.cuda.use_tf32", "1")));
  EXPECT_THAT(config.tests_to_skip,
              ::testing::ElementsAre("CudaTests.SkipMe", "GraphTests.SkipMeToo"));
}
 
TEST(DynamicPluginEpInfraTest, ParseInitializationConfigDefaultsUnsetOptionalFields) {
  constexpr std::string_view kConfigJson = R"json(
{
  "ep_library_registration_name": "ExamplePluginEP",
  "ep_library_path": "/tmp/libexample_plugin_ep.so",
  "selected_ep_name": "ExampleExecutionProvider"
}
)json";
 
  dynamic_plugin_ep_test_infra::InitializationConfig config{};
  ASSERT_STATUS_OK(dynamic_plugin_ep_test_infra::ParseInitializationConfig(kConfigJson, config));
 
  EXPECT_EQ(config.ep_library_registration_name, "ExamplePluginEP");
  EXPECT_EQ(config.ep_library_path, "/tmp/libexample_plugin_ep.so");
  EXPECT_EQ(config.selected_ep_name, "ExampleExecutionProvider");
  EXPECT_TRUE(config.selected_ep_device_indices.empty());
  EXPECT_TRUE(config.default_ep_options.empty());
  EXPECT_TRUE(config.tests_to_skip.empty());
}
 
TEST(DynamicPluginEpInfraTest, ParseInitializationConfigAllowsMissingEpLibraryPath) {
  // `ep_library_path` may be omitted when the EP library is already registered, e.g. a statically linked plugin EP.
  constexpr std::string_view kConfigJson = R"json(
{
  "ep_library_registration_name": "WebGpuExecutionProvider",
  "selected_ep_name": "WebGpuExecutionProvider"
}
)json";
 
  dynamic_plugin_ep_test_infra::InitializationConfig config{};
  ASSERT_STATUS_OK(dynamic_plugin_ep_test_infra::ParseInitializationConfig(kConfigJson, config));
 
  EXPECT_EQ(config.ep_library_registration_name, "WebGpuExecutionProvider");
  EXPECT_TRUE(config.ep_library_path.empty());
  EXPECT_EQ(config.selected_ep_name, "WebGpuExecutionProvider");
}
 
TEST(DynamicPluginEpInfraTest, ParseInitializationConfigRejectsMissingRequiredFields) {
  constexpr std::string_view kConfigJson = R"json(
{
  "ep_library_path": "/tmp/libonnxruntime_providers_cuda.so"
}
)json";
 
  dynamic_plugin_ep_test_infra::InitializationConfig config{};
  ASSERT_STATUS_NOT_OK_AND_HAS_SUBSTR(dynamic_plugin_ep_test_infra::ParseInitializationConfig(kConfigJson, config),
                                      "JSON parse error");
}
 
TEST(DynamicPluginEpInfraTest, UninitializedStateReturnsSafeDefaults) {
  // Use RunWithTemporaryShutdownForTesting so that shutting the infrastructure down here does not
  // leave the shared global infrastructure uninitialized for subsequent tests. Unit test main may have
  // initialized it (e.g. to route CUDA to the plugin EP), and tearing it down permanently would cause
  // later tests that rely on DefaultCudaExecutionProvider() to receive a null provider and crash.
  dynamic_plugin_ep_test_infra::RunWithTemporaryShutdownForTesting([]() {
    dynamic_plugin_ep_test_infra::Shutdown();
 
    EXPECT_FALSE(dynamic_plugin_ep_test_infra::IsInitialized());
    EXPECT_EQ(dynamic_plugin_ep_test_infra::MakeEp(), nullptr);
    EXPECT_FALSE(dynamic_plugin_ep_test_infra::GetEpName().has_value());
    EXPECT_TRUE(dynamic_plugin_ep_test_infra::GetTestsToSkip().empty());
 
    dynamic_plugin_ep_test_infra::Shutdown();
 
    EXPECT_FALSE(dynamic_plugin_ep_test_infra::IsInitialized());
    EXPECT_FALSE(dynamic_plugin_ep_test_infra::GetEpName().has_value());
    EXPECT_TRUE(dynamic_plugin_ep_test_infra::GetTestsToSkip().empty());
  });
}
 
#if defined(USE_CUDA) && defined(ORT_USE_EP_API_ADAPTERS)
TEST(DynamicPluginEpInfraTest, CudaKernelAdapterRuntimeConfigExposesFuseConvBiasAndSdpaKernel) {
  onnxruntime::CUDAExecutionProvider provider{"CUDAExecutionProvider"};
  auto config = onnxruntime::cuda::detail::GetCudaKernelAdapterRuntimeConfigForProvider(&provider);
  config->fuse_conv_bias = true;
  config->sdpa_kernel = static_cast<int>(onnxruntime::contrib::attention::AttentionBackend::MATH);
 
  EXPECT_TRUE(provider.IsFuseConvBias());
 
  const auto* attention_kernel_options = provider.GetAttentionKernelOptions();
  EXPECT_TRUE(attention_kernel_options->UseUnfusedAttention());
  EXPECT_FALSE(attention_kernel_options->UseFlashAttention());
  EXPECT_FALSE(attention_kernel_options->UseEfficientAttention());
  EXPECT_FALSE(attention_kernel_options->UseCudnnFlashAttention());
}
 
TEST(DynamicPluginEpInfraTest, CudaKernelAdapterRuntimeConfigExposesDoCopyInDefaultStream) {
  onnxruntime::CUDAExecutionProvider provider{"CUDAExecutionProvider"};
  auto config = onnxruntime::cuda::detail::GetCudaKernelAdapterRuntimeConfigForProvider(&provider);
 
  // Default should be true
  EXPECT_TRUE(provider.DoCopyOnDefaultStream());
 
  config->do_copy_in_default_stream = false;
  EXPECT_FALSE(provider.DoCopyOnDefaultStream());
 
  config->do_copy_in_default_stream = true;
  EXPECT_TRUE(provider.DoCopyOnDefaultStream());
}
 
TEST(DynamicPluginEpInfraTest, CudaKernelAdapterTryBytesForCountDetectsOverflow) {
  size_t bytes = 0;
  EXPECT_FALSE(onnxruntime::cuda::detail::TryBytesForCount(std::numeric_limits<size_t>::max(), 2, bytes));
}
 
TEST(DynamicPluginEpInfraTest, CudaKernelAdapterTryBytesForCountPreservesRawByteCounts) {
  size_t bytes = 0;
  ASSERT_TRUE(onnxruntime::cuda::detail::TryBytesForCount(123, 0, bytes));
  EXPECT_EQ(bytes, size_t{123});
}
 
TEST(DynamicPluginEpInfraTest, CudaKernelAdapterTryBytesForCountNormalCase) {
  size_t bytes = 0;
  ASSERT_TRUE(onnxruntime::cuda::detail::TryBytesForCount(10, 4, bytes));
  EXPECT_EQ(bytes, size_t{40});
}
 
TEST(DynamicPluginEpInfraTest, CudaKernelAdapterRetainsGraphCaptureHostBuffer) {
  std::weak_ptr<int> retained_buffer;
  {
    onnxruntime::cuda::detail::CudaKernelAdapterRuntimeConfig config;
    auto buffer = std::make_shared<int>(42);
    retained_buffer = buffer;
    config.RetainBufferForGraphCapture(std::move(buffer));
    EXPECT_FALSE(retained_buffer.expired());
  }
  EXPECT_TRUE(retained_buffer.expired());
}
#endif
 
}  // namespace onnxruntime::test
 
#endif  // !defined(ORT_MINIMAL_BUILD) && defined(ORT_UNIT_TEST_HAS_CUDA_PLUGIN_EP)