-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathallocate_device.cc
29 lines (24 loc) · 1009 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
28
29
#include <limits>
#include "cuda_rt_call.h"
#include "allocate_device.h"
#include "getCachingDeviceAllocator.h"
#include <iostream>
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) {
std::cout<<"at stream"<<stream<<std::endl;
throw std::runtime_error("alloate_device : 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