static */
| 817 | } |
| 818 | |
| 819 | /* static */ void* GpuDriver::UnifiedMemoryAllocate(GpuContext* context, |
| 820 | uint64 bytes) { |
| 821 | ScopedActivateContext activation(context); |
| 822 | CUdeviceptr result = 0; |
| 823 | // "Portable" memory is visible to all CUDA contexts. Safe for our use model. |
| 824 | CUresult res = cuMemAllocManaged(&result, bytes, CU_MEM_ATTACH_GLOBAL); |
| 825 | if (res != CUDA_SUCCESS) { |
| 826 | LOG(ERROR) << "failed to alloc " << bytes |
| 827 | << " bytes unified memory; result: " << ToString(res); |
| 828 | return nullptr; |
| 829 | } |
| 830 | void* ptr = reinterpret_cast<void*>(result); |
| 831 | VLOG(2) << "allocated " << ptr << " for context " << context->context() |
| 832 | << " of " << bytes << " bytes in unified memory"; |
| 833 | return ptr; |
| 834 | } |
| 835 | |
| 836 | /* static */ void GpuDriver::UnifiedMemoryDeallocate(GpuContext* context, |
| 837 | void* location) { |