10 LSLAB_HOST device_allocator<T>::device_allocator(
size_t stack_size_) : stack_size(stack_size_) {
11 gpuErrchk(cudaMalloc(&loc,
sizeof(cuda::std::atomic<uint64_t>)));
12 gpuErrchk(cudaMemset(loc, 0,
sizeof(cuda::std::atomic<uint64_t>)));
13 gpuErrchk(cudaMalloc(&mempool,
sizeof(T) * stack_size));
17 LSLAB_HOST_DEVICE device_allocator<T>::device_allocator(
const device_allocator<T>&
self) : stack_size(self.stack_size), loc(self.loc), mempool(self.mempool) {}
20 LSLAB_HOST_DEVICE device_allocator<T>::device_allocator(device_allocator&& other) {
21 stack_size = other.stack_size;
23 mempool = other.mempool;
26 other.mempool =
nullptr;
30 LSLAB_HOST_DEVICE device_allocator<T>& device_allocator<T>::operator=(device_allocator<T>&& other) {
31 #if defined(__CUDA_ARCH__)
32 if(loc !=
nullptr || mempool !=
nullptr)
36 gpuErrchk(cudaFree(loc));
37 if(mempool !=
nullptr)
38 gpuErrchk(cudaFree(mempool));
41 stack_size = other.stack_size;
43 mempool = other.mempool;
46 other.mempool =
nullptr;
50 LSLAB_HOST_DEVICE device_allocator<T>::~device_allocator() {
63 LSLAB_DEVICE T* device_allocator<T>::allocate(
size_t n) {
64 auto idx = loc->fetch_add(n);
65 if(idx >= stack_size) {
66 printf(
"At idx %llu\n", idx);
73 LSLAB_HOST_DEVICE
void device_allocator<T>::deallocate(T* ptr,
size_t n) {}