9 #include <cuda_runtime.h>
18 CUDAScopedDevice scoped_device(device);
21 if (device.IsCUDA()) {
22 #if CUDART_VERSION >= 11020
25 static_cast<void**
>(&ptr), byte_size, cuda::GetStream()));
28 cudaMalloc(
static_cast<void**
>(&ptr), byte_size));
32 cudaMalloc(
static_cast<void**
>(&ptr), byte_size));
42 CUDAScopedDevice scoped_device(device);
44 if (device.IsCUDA()) {
45 if (ptr && IsCUDAPointer(ptr, device)) {
46 #if CUDART_VERSION >= 11020
62 void MemoryManagerCUDA::Memcpy(
void* dst_ptr,
63 const Device& dst_device,
65 const Device& src_device,
67 if (dst_device.IsCUDA() && src_device.IsCPU()) {
68 if (!IsCUDAPointer(dst_ptr, dst_device)) {
71 CUDAScopedDevice scoped_device(dst_device);
73 cudaMemcpyHostToDevice,
75 }
else if (dst_device.IsCPU() && src_device.IsCUDA()) {
76 if (!IsCUDAPointer(src_ptr, src_device)) {
79 CUDAScopedDevice scoped_device(src_device);
81 cudaMemcpyDeviceToHost,
83 }
else if (dst_device.IsCUDA() && src_device.IsCUDA()) {
84 if (!IsCUDAPointer(dst_ptr, dst_device)) {
87 if (!IsCUDAPointer(src_ptr, src_device)) {
91 if (dst_device == src_device) {
92 CUDAScopedDevice scoped_device(src_device);
94 cudaMemcpyDeviceToDevice,
97 dst_device.GetID())) {
99 dst_ptr, dst_device.GetID(), src_ptr, src_device.GetID(),
100 num_bytes, cuda::GetStream()));
104 CUDAScopedDevice scoped_device(src_device);
106 cpu_buf, src_ptr, num_bytes, cudaMemcpyDeviceToHost,
110 CUDAScopedDevice scoped_device(dst_device);
112 dst_ptr, cpu_buf, num_bytes, cudaMemcpyHostToDevice,
122 bool MemoryManagerCUDA::IsCUDAPointer(
const void* ptr,
const Device& device) {
123 CUDAScopedDevice scoped_device(device);
125 cudaPointerAttributes attributes;
126 cudaPointerGetAttributes(&attributes, ptr);
127 return attributes.devicePointer !=
nullptr ? true :
false;
#define CLOUDVIEWER_CUDA_CHECK(err)
static void * Malloc(size_t byte_size, const Device &device)
static void Free(void *ptr, const Device &device)
Frees previously allocated memory at address ptr on device device.
ccGuiPythonInstance * GetInstance() noexcept
bool SupportsMemoryPools(const Device &device)
void Free(benchmark::State &state, int size, const Device &device, const MemoryManagerBackend &backend)
void Malloc(benchmark::State &state, int size, const Device &device, const MemoryManagerBackend &backend)
Generic file read and write utility for python interface.