static */
| 780 | } |
| 781 | |
| 782 | /* static */ void* GpuDriver::DeviceAllocate(GpuContext* context, |
| 783 | uint64 bytes) { |
| 784 | if (bytes == 0) { |
| 785 | return nullptr; |
| 786 | } |
| 787 | |
| 788 | ScopedActivateContext activated{context}; |
| 789 | CUdeviceptr result = 0; |
| 790 | CUresult res = cuMemAlloc(&result, bytes); |
| 791 | if (res != CUDA_SUCCESS) { |
| 792 | // LOG(INFO) because this isn't always important to users (e.g. BFCAllocator |
| 793 | // implements a retry if the first allocation fails). |
| 794 | LOG(INFO) << "failed to allocate " |
| 795 | << port::HumanReadableNumBytes::ToString(bytes) << " (" << bytes |
| 796 | << " bytes) from device: " << ToString(res); |
| 797 | return nullptr; |
| 798 | } |
| 799 | void* ptr = reinterpret_cast<void*>(result); |
| 800 | VLOG(2) << "allocated " << ptr << " for context " << context->context() |
| 801 | << " of " << bytes << " bytes"; |
| 802 | return ptr; |
| 803 | } |
| 804 | |
| 805 | /* static */ void GpuDriver::DeviceDeallocate(GpuContext* context, |
| 806 | void* location) { |