Исходный код СУБД 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
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
 
#include <iostream>
 
#if defined(USE_CUDA) || defined(USE_NV)
#include "cuda_runtime_api.h"
#endif
 
namespace onnxruntime {
namespace test {
 
int GetCudaArchitecture() {
  // This will cache the result so we only call cudaGetDeviceProperties once.
  // Usually, we test on a single GPU or multiple GPUs of same architecture, so it's fine to cache the result.
  static int cuda_arch = -1;
 
#if defined(USE_CUDA) || defined(USE_NV)
  if (cuda_arch == -1) {
    int current_device_id = 0;
    cudaGetDevice(&current_device_id);
    // must wait GPU idle, otherwise cudaGetDeviceProperties might fail
    cudaDeviceSynchronize();
    cudaDeviceProp prop;
 
    // When cudaGetDeviceProperties fails, just return -1 and no error is raised.
    // If cuda device has issue, test will fail anyway so no need to raise error here.
    if (cudaSuccess == cudaGetDeviceProperties(&prop, current_device_id)) {
      cuda_arch = prop.major * 100 + prop.minor * 10;
    }
 
    // Log GPU compute capability
    if (cuda_arch == -1) {
      std::cout << "WARNING: CUDA is not available or failed to initialize" << std::endl;
    } else {
      std::cout << "GPU Compute Capability: SM "
                << cuda_arch / 100 << "." << (cuda_arch % 100) / 10
                << " (value: " << cuda_arch << ")" << std::endl;
    }
  }
#endif
 
  return cuda_arch;
}
 
}  // namespace test
}  // namespace onnxruntime