If CUDA is available and in GPU mode, host memory will be allocated pinned, using cudaMallocHost. It avoids dynamic pinning for transfers (DMA). The improvement in performance seems negligible in the single GPU case, but might be more significant for parallel training. Most importantly, it improved stability for large models on many GPUs.
| 13 | // but might be more significant for parallel training. Most importantly, |
| 14 | // it improved stability for large models on many GPUs. |
| 15 | inline void CaffeMallocHost(void** ptr, size_t size, bool* use_cuda) { |
| 16 | #ifndef CPU_ONLY |
| 17 | if (Caffe::mode() == Caffe::GPU) { |
| 18 | CUDA_CHECK(cudaMallocHost(ptr, size)); |
| 19 | *use_cuda = true; |
| 20 | return; |
| 21 | } |
| 22 | #endif |
| 23 | *ptr = malloc(size); |
| 24 | *use_cuda = false; |
| 25 | CHECK(*ptr) << "host allocation of size " << size << " failed"; |
| 26 | } |
| 27 | |
| 28 | inline void CaffeFreeHost(void* ptr, bool use_cuda) { |
| 29 | #ifndef CPU_ONLY |