| 112 | } |
| 113 | |
| 114 | PyLocalClient::PyLocalClient( |
| 115 | std::string platform_name, LocalClient* client, |
| 116 | std::vector<std::shared_ptr<Device>> devices, int host_id, |
| 117 | std::unique_ptr<se::DeviceMemoryAllocator> allocator, |
| 118 | std::unique_ptr<tensorflow::Allocator> host_memory_allocator) |
| 119 | : platform_name_(std::move(platform_name)), |
| 120 | client_(client), |
| 121 | devices_(std::move(devices)), |
| 122 | host_id_(host_id), |
| 123 | owned_allocator_(std::move(allocator)), |
| 124 | host_memory_allocator_(std::move(host_memory_allocator)), |
| 125 | h2d_transfer_pool_(tensorflow::Env::Default(), "py_xla_h2d_transfer", |
| 126 | client->device_count()) { |
| 127 | if (owned_allocator_ != nullptr) { |
| 128 | allocator_ = owned_allocator_.get(); |
| 129 | } else { |
| 130 | allocator_ = client_->backend().memory_allocator(); |
| 131 | } |
| 132 | |
| 133 | for (const std::shared_ptr<Device>& device : devices_) { |
| 134 | CHECK(id_to_device_.insert({device->id(), device}).second) |
| 135 | << "Duplicate device id: " << device->id(); |
| 136 | |
| 137 | if (device->local_device_state()) { |
| 138 | int idx = device->local_device_state()->device_ordinal(); |
| 139 | if (idx >= local_devices_.size()) { |
| 140 | local_devices_.resize(idx + 1); |
| 141 | } |
| 142 | CHECK(local_devices_[idx] == nullptr) << idx; |
| 143 | local_devices_[idx] = device; |
| 144 | } |
| 145 | } |
| 146 | for (int idx = 0; idx < local_devices_.size(); ++idx) { |
| 147 | CHECK(local_devices_[idx] != nullptr) << idx; |
| 148 | } |
| 149 | } |
| 150 | |
| 151 | StatusOr<DeviceAssignment> PyLocalClient::GetDefaultDeviceAssignment( |
| 152 | int num_replicas, int num_partitions) const { |
nothing calls this directly
no test coverage detected