Исходный код СУБД 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
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
 
#include "core/platform/device_discovery.h"
 
#include "gtest/gtest.h"
 
#if !defined(ORT_MINIMAL_BUILD) && !defined(_GAMING_XBOX)
namespace onnxruntime::test {
namespace {
 
std::vector<OrtHardwareDevice> GetDevicesByType(OrtHardwareDeviceType device_type) {
  std::vector<OrtHardwareDevice> result{};
  const auto& devices = DeviceDiscovery::GetDevices();
  std::copy_if(devices.begin(), devices.end(), std::back_inserter(result),
               [device_type](const OrtHardwareDevice& device) {
                 return device.type == device_type;
               });
  return result;
}
 
}  // namespace
 
TEST(DeviceDiscoveryTest, HasCpuDevice) {
  const auto cpu_devices = GetDevicesByType(OrtHardwareDeviceType_CPU);
  ASSERT_GT(cpu_devices.size(), 0);
 
  ASSERT_FALSE(cpu_devices[0].vendor.empty());
}
 
TEST(DeviceDiscoveryTest, GpuDevicesHaveValidProperties) {
  const auto gpu_devices = GetDevicesByType(OrtHardwareDeviceType_GPU);
 
  // GPU detection should not crash. If GPUs are present, validate their properties.
  for (const auto& gpu_device : gpu_devices) {
#if !defined(__wasm__)
    EXPECT_NE(gpu_device.vendor_id, 0u);
#else
    // WASM GPU device discovery is limited so vendor ID is unknown.
    EXPECT_EQ(gpu_device.vendor_id, 0u);
#endif
    // Note: gpu_device.device_id may be 0 on some platforms (e.g., Apple Silicon) where it is not populated.
  }
}
 
#ifdef _WIN32
TEST(DeviceDiscoveryTest, ExcludesMicrosoftBasicRenderDriver) {
  const auto gpu_devices = GetDevicesByType(OrtHardwareDeviceType_GPU);
 
  for (const auto& gpu_device : gpu_devices) {
    EXPECT_FALSE(gpu_device.vendor_id == 0x1414 && gpu_device.device_id == 0x008c);
  }
}
#endif
 
}  // namespace onnxruntime::test
#endif  // !defined(ORT_MINIMAL_BUILD) && !defined(_GAMING_XBOX)