| 46 | } |
| 47 | |
| 48 | phi::Allocation* CustomAllocator::AllocateImpl(size_t size) { |
| 49 | std::call_once(once_flag_, [this] { phi::DeviceManager::SetDevice(place_); }); |
| 50 | |
| 51 | void* ptr = |
| 52 | phi::DeviceManager::GetDeviceWithPlace(place_)->MemoryAllocate(size); |
| 53 | if (LIKELY(ptr)) { |
| 54 | DEVICE_MEMORY_STAT_UPDATE(Reserved, place_.GetDeviceId(), size); |
| 55 | platform::RecordMemEvent( |
| 56 | ptr, place_, size, phi::TracerMemEventType::ReservedAllocate); |
| 57 | return new Allocation(ptr, size, place_); |
| 58 | } |
| 59 | |
| 60 | size_t avail, total; |
| 61 | phi::DeviceManager::MemoryStats(place_, &total, &avail); |
| 62 | |
| 63 | auto dev_type = phi::PlaceHelper::GetDeviceType(place_); |
| 64 | auto dev_id = phi::PlaceHelper::GetDeviceId(place_); |
| 65 | |
| 66 | PADDLE_THROW_BAD_ALLOC(common::errors::ResourceExhausted( |
| 67 | "\n\nOut of memory error on %s:%d. " |
| 68 | "Cannot allocate %s memory on %s:%d, " |
| 69 | "available memory is only %s.\n\n" |
| 70 | "Please check whether there is any other process using %s:%d.\n" |
| 71 | "1. If yes, please stop them, or start PaddlePaddle on another %s.\n" |
| 72 | "2. If no, please decrease the batch size of your model.\n\n", |
| 73 | dev_type, |
| 74 | dev_id, |
| 75 | string::HumanReadableSize(size), |
| 76 | dev_type, |
| 77 | dev_id, |
| 78 | string::HumanReadableSize(avail), |
| 79 | dev_type, |
| 80 | dev_id, |
| 81 | dev_type)); |
| 82 | } |
| 83 | |
| 84 | } // namespace allocation |
| 85 | } // namespace memory |
nothing calls this directly
no test coverage detected