forked from beiwang2003/strip_clustering_gpu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
allocate_device.cc
27 lines (22 loc) · 923 Bytes
/
allocate_device.cc
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
#include <limits>
#include "cuda_rt_call.h"
#include "allocate_device.h"
#include "getCachingDeviceAllocator.h"
namespace {
const size_t maxAllocationSize =
notcub::CachingDeviceAllocator::IntPow(cudautils::allocator::binGrowth, cudautils::allocator::maxBin);
}
namespace cudautils {
void *allocate_device(int dev, size_t nbytes, cudaStream_t stream) {
void *ptr = nullptr;
if (nbytes > maxAllocationSize) {
throw std::runtime_error("Tried to allocate " + std::to_string(nbytes) +
" bytes, but the allocator maximum is " + std::to_string(maxAllocationSize));
}
CUDA_RT_CALL(cudautils::allocator::getCachingDeviceAllocator().DeviceAllocate(dev, &ptr, nbytes, stream));
return ptr;
}
void free_device(int device, void *ptr) {
CUDA_RT_CALL(cudautils::allocator::getCachingDeviceAllocator().DeviceFree(device, ptr));
}
} // namespace cudautils