* \brief Allocates size-number of bytes on the device system. * This memory must be freed with freeDevice(void*). * * Note that allocate zero bytes is perfectly fine. * That is also the only case in which this function might * return NULL. * Otherwise, always a valid pointer must be returned * or an exception is thrown. * * \param size the number of bytes to allocate * \return the adress
| 269 | * \return the adress of the new device memory |
| 270 | */ |
| 271 | void* mallocDevice(size_t size) |
| 272 | { |
| 273 | CUMAT_PROFILING_INC(DeviceMemAlloc); |
| 274 | //TODO: add a plugin-mechanism for custom allocators |
| 275 | if (size == 0) return nullptr; |
| 276 | #if CUMAT_CONTEXT_DEBUG_MEMORY==1 |
| 277 | allocationsDevice_++; |
| 278 | #endif |
| 279 | void* memory; |
| 280 | #if CUMAT_CONTEXT_USE_CUB_ALLOCATOR==1 |
| 281 | CUMAT_SAFE_CALL(getCubAllocator().DeviceAllocate(device_, &memory, size, stream_)); |
| 282 | #else |
| 283 | CUMAT_SAFE_CALL(cudaMalloc(&memory, size)); |
| 284 | #endif |
| 285 | return memory; |
| 286 | } |
| 287 | |
| 288 | /** |
| 289 | * \brief Frees memory previously allocated with allocateHost(size_t). |