| 43 | } |
| 44 | |
| 45 | const phi::DeviceContext* DeviceContextPool::Get(const Place& place) { |
| 46 | auto it = context_map_.find(place); |
| 47 | if (it == context_map_.end()) { |
| 48 | if (!phi::DeviceContextPool::IsInitialized()) { |
| 49 | phi::memory_utils::InitDevices(); |
| 50 | } |
| 51 | // only when we need the specific DeviceContext, get and cache it |
| 52 | auto* dev_ctx = phi::DeviceContextPool::Instance().Get(place); |
| 53 | { |
| 54 | std::lock_guard<std::mutex> lock(mutex_); |
| 55 | context_map_[place] = dev_ctx; |
| 56 | } |
| 57 | return dev_ctx; |
| 58 | } |
| 59 | return it->second; |
| 60 | } |
| 61 | |
| 62 | phi::DeviceContext* DeviceContextPool::GetMutable(const Place& place) { |
| 63 | return const_cast<phi::DeviceContext*>(Get(place)); // NOLINT |
no test coverage detected