forked from beiwang2003/strip_clustering_gpu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
allocate_host.cc
26 lines (21 loc) · 846 Bytes
/
allocate_host.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
#include <limits>
#include "cuda_rt_call.h"
#include "getCachingHostAllocator.h"
namespace {
const size_t maxAllocationSize =
notcub::CachingDeviceAllocator::IntPow(cudautils::allocator::binGrowth, cudautils::allocator::maxBin);
}
namespace cudautils {
void *allocate_host(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::getCachingHostAllocator().HostAllocate(&ptr, nbytes, stream));
return ptr;
}
void free_host(void *ptr) {
CUDA_RT_CALL(cudautils::allocator::getCachingHostAllocator().HostFree(ptr));
}
} // namespace cudautils