-
Notifications
You must be signed in to change notification settings - Fork 71
Expand file tree
/
Copy pathCCUDADevice.h
More file actions
121 lines (95 loc) · 3.76 KB
/
CCUDADevice.h
File metadata and controls
121 lines (95 loc) · 3.76 KB
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
// Copyright (C) 2018-2020 - DevSH Graphics Programming Sp. z O.O.
// This file is part of the "Nabla Engine".
// For conditions of distribution and use, see copyright notice in nabla.h
#ifndef _NBL_VIDEO_C_CUDA_DEVICE_H_
#define _NBL_VIDEO_C_CUDA_DEVICE_H_
#include "nbl/video/IPhysicalDevice.h"
#include "nbl/video/CCUDAExportableMemory.h"
#include "nbl/video/CCUDAImportedMemory.h"
#include "nbl/video/CCUDAImportedSemaphore.h"
#ifdef _NBL_COMPILE_WITH_CUDA_
#include "cuda.h"
#include "nvrtc.h"
#if CUDA_VERSION < 9000
#error "Need CUDA 9.0 SDK or higher."
#endif
// useful includes in the future
//#include "cudaEGL.h"
//#include "cudaVDPAU.h"
namespace nbl::video
{
class CCUDAHandler;
class NBL_API2 CCUDADevice : public core::IReferenceCounted
{
public:
#ifdef _WIN32
static constexpr IDeviceMemoryAllocation::E_EXTERNAL_HANDLE_TYPE EXTERNAL_MEMORY_HANDLE_TYPE = IDeviceMemoryAllocation::EHT_OPAQUE_WIN32;
static constexpr CUmemAllocationHandleType ALLOCATION_HANDLE_TYPE = CU_MEM_HANDLE_TYPE_WIN32;
#else
static constexpr IDeviceMemoryAllocation::E_EXTERNAL_HANDLE_TYPE EXTERNAL_MEMORY_HANDLE_TYPE = IDeviceMemoryAllocation::EHT_OPAQUE_FD;
static constexpr CUmemAllocationHandleType ALLOCATION_HANDLE_TYPE = CU_MEM_HANDLE_TYPE_POSIX_FILE_DESCRIPTOR;
#endif
enum E_VIRTUAL_ARCHITECTURE
{
EVA_30,
EVA_32,
EVA_35,
EVA_37,
EVA_50,
EVA_52,
EVA_53,
EVA_60,
EVA_61,
EVA_62,
EVA_70,
EVA_72,
EVA_75,
EVA_80,
EVA_COUNT
};
static inline constexpr const char* virtualArchCompileOption[] = {
"-arch=compute_30",
"-arch=compute_32",
"-arch=compute_35",
"-arch=compute_37",
"-arch=compute_50",
"-arch=compute_52",
"-arch=compute_53",
"-arch=compute_60",
"-arch=compute_61",
"-arch=compute_62",
"-arch=compute_70",
"-arch=compute_72",
"-arch=compute_75",
"-arch=compute_80"
};
inline E_VIRTUAL_ARCHITECTURE getVirtualArchitecture() {return m_virtualArchitecture;}
CCUDADevice(core::smart_refctd_ptr<CVulkanConnection>&& vulkanConnection, IPhysicalDevice* const vulkanDevice, const E_VIRTUAL_ARCHITECTURE virtualArchitecture, CUdevice device, core::smart_refctd_ptr<CCUDAHandler>&& handler);
~CCUDADevice();
inline core::SRange<const char* const> geDefaultCompileOptions() const
{
return {m_defaultCompileOptions.data(),m_defaultCompileOptions.data()+m_defaultCompileOptions.size()};
}
CUdevice getInternalObject() const { return m_handle; }
const CCUDAHandler* getHandler() const { return m_handler.get(); }
bool isMatchingDevice(const IPhysicalDevice* device) { return device && !memcmp(device->getProperties().deviceUUID, m_physicalDevice->getProperties().deviceUUID, 16); }
size_t roundToGranularity(CUmemLocationType location, size_t size) const;
core::smart_refctd_ptr<CCUDAExportableMemory> createExportableMemory(CCUDAExportableMemory::SCreationParams&& inParams);
core::smart_refctd_ptr<CCUDAImportedMemory> importExternalMemory(core::smart_refctd_ptr<IDeviceMemoryAllocation>&& mem);
core::smart_refctd_ptr<CCUDAImportedSemaphore> importExternalSemaphore(core::smart_refctd_ptr<ISemaphore>&& sem);
private:
CUresult reserveAddressAndMapMemory(CUdeviceptr* outPtr, size_t size, size_t alignment, CUmemLocationType location, CUmemGenericAllocationHandle memory) const;
static constexpr auto CudaMemoryLocationCount = 5;
const system::logger_opt_ptr m_logger;
std::vector<const char*> m_defaultCompileOptions;
core::smart_refctd_ptr<CVulkanConnection> m_vulkanConnection;
IPhysicalDevice* const m_physicalDevice;
E_VIRTUAL_ARCHITECTURE m_virtualArchitecture;
core::smart_refctd_ptr<CCUDAHandler> m_handler;
CUdevice m_handle;
CUcontext m_context;
std::array<size_t, CudaMemoryLocationCount> m_allocationGranularity;
};
}
#endif // _NBL_COMPILE_WITH_CUDA_
#endif