Исходный код СУБД 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
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
 
#ifdef USE_CUDA
#include "cuda_tool.h"
// CUDA
#include "cuda.h"
#include "cuda_runtime.h"
#if defined(_WIN32) || defined(WIN32) || defined(__CYGWIN__) || defined(__MINGW32__) || defined(__BORLANDC__)
#include "nvtx3/nvToolsExt.h"
#else
#include "nvToolsExt.h"
#endif
// Pytorch
#include <ATen/cuda/CUDAContext.h>
// ORT
#include "core/providers/cuda/cuda_provider_options.h"
#include "core/providers/provider_factory_creators.h"
#include "orttraining/python/orttraining_pybind_common.h"
 
namespace onnxruntime {
namespace lazytensor {
 
NvtxRange::NvtxRange(const char* name) {
  nvtxRangePush(name);
}
NvtxRange::NvtxRange(const std::string& name) {
  nvtxRangePush(name.c_str());
}
NvtxRange::~NvtxRange() {
  nvtxRangePop();
}
 
// Wrapper of memory allocation function.
void* CudaAllocDelegate(size_t nbytes) {
  auto allocator = at::cuda::getCUDADeviceAllocator();
  return allocator->raw_allocate(nbytes);
}
 
// Wrapper of memory de-allocation function.
void CudaFreeDelegate(void* ptr) {
  auto allocator = at::cuda::getCUDADeviceAllocator();
  allocator->raw_deallocate(ptr);
}
 
void CUDAExecutionProviderPool::Initialize() {
  int device_count = 0;
  cudaGetDeviceCount(&device_count);
  for (int i = 0; i < device_count; ++i) {
    onnxruntime::ProviderOptions options;
    options["device_id"] = std::to_string(i);
    options["do_copy_in_default_stream"] = "true";
    options["gpu_external_alloc"] = std::to_string(reinterpret_cast<size_t>(&CudaAllocDelegate));
    options["gpu_external_free"] = std::to_string(reinterpret_cast<size_t>(&CudaFreeDelegate));
 
    ProviderInfo_CUDA* cuda_provider_info = TryGetProviderInfo_CUDA();
    CUDAExecutionProviderInfo info;
    cuda_provider_info->CUDAExecutionProviderInfo__FromProviderOptions(options, info);
    cuda_execution_providers_.emplace_back(std::move(cuda_provider_info->CreateExecutionProviderFactory(info)->CreateProvider()));
  }
}
 
}  // namespace lazytensor
}  // namespace onnxruntime
#endif