Reallocate the memory space */
| 106 | |
| 107 | /** Reallocate the memory space */ |
| 108 | void reallocate(Index _capacity) { |
| 109 | if (capacity && !--(*refer_count)) { |
| 110 | delete refer_count; |
| 111 | #ifdef PINNED_MEMORY |
| 112 | CUDA_CHECK(cudaFreeHost(host_ptr)); |
| 113 | #else |
| 114 | delete [] host_ptr; |
| 115 | #endif |
| 116 | if (device_id != -1) { |
| 117 | CUDA_CHECK(cudaSetDevice(device_id)); |
| 118 | CUDA_CHECK(cudaFree(device_ptr)); |
| 119 | } |
| 120 | } |
| 121 | capacity = _capacity; |
| 122 | if (capacity) { |
| 123 | refer_count = new int(1); |
| 124 | #ifdef PINNED_MEMORY |
| 125 | CUDA_CHECK(cudaMallocHost(&host_ptr, capacity * sizeof(Data))); |
| 126 | #else |
| 127 | host_ptr = new Data[capacity]; |
| 128 | #endif |
| 129 | if (device_id != -1) { |
| 130 | CUDA_CHECK(cudaSetDevice(device_id)); |
| 131 | CUDA_CHECK(cudaMalloc(&device_ptr, capacity * sizeof(Data))); |
| 132 | } |
| 133 | } |
| 134 | } |
| 135 | |
| 136 | /** Resize the memory space. Reallocate only if the capacity is not enough. */ |
| 137 | void resize(Index _count) { |