Represents a compiled computation that can be executed given handles to device-allocated literals. Wraps one or more XLA LocalExecutables (one per partition, as specified by the build options).
| 248 | // device-allocated literals. Wraps one or more XLA LocalExecutables (one per |
| 249 | // partition, as specified by the build options). |
| 250 | class PyLocalExecutable { |
| 251 | public: |
| 252 | // Compiles a computation to an executable. |
| 253 | static StatusOr<std::unique_ptr<PyLocalExecutable>> CompileForDevices( |
| 254 | const XlaComputation& computation, |
| 255 | absl::optional<std::vector<Shape>> argument_layouts, |
| 256 | const ExecutableBuildOptions* build_options, |
| 257 | std::shared_ptr<PyLocalClient> client, |
| 258 | const std::vector<std::vector<std::shared_ptr<Device>>>& |
| 259 | device_assignment); |
| 260 | |
| 261 | // TODO(phawkins): Deprecated. Delete once all callers have been updated to |
| 262 | // use the newer form. |
| 263 | static StatusOr<std::unique_ptr<PyLocalExecutable>> Compile( |
| 264 | const XlaComputation& computation, |
| 265 | absl::optional<std::vector<Shape>> argument_layouts, |
| 266 | const ExecutableBuildOptions* build_options, |
| 267 | std::shared_ptr<PyLocalClient> client, |
| 268 | absl::optional<DeviceAssignment> device_assignment); |
| 269 | |
| 270 | PyLocalExecutable(std::vector<std::unique_ptr<LocalExecutable>> executables, |
| 271 | DeviceAssignment device_assignment, |
| 272 | std::shared_ptr<PyLocalClient> client); |
| 273 | |
| 274 | int num_replicas() const { |
| 275 | return executables_[0]->build_options().num_replicas(); |
| 276 | } |
| 277 | |
| 278 | int num_partitions() const { |
| 279 | return executables_[0]->build_options().num_partitions(); |
| 280 | } |
| 281 | |
| 282 | int64 SizeOfGeneratedCodeInBytes() const { |
| 283 | int64 size = 0; |
| 284 | for (auto& executable : executables_) { |
| 285 | size += executable->executable()->SizeOfGeneratedCodeInBytes(); |
| 286 | } |
| 287 | return size; |
| 288 | } |
| 289 | |
| 290 | const std::vector<std::shared_ptr<LocalExecutable>>& executables() const { |
| 291 | return executables_; |
| 292 | } |
| 293 | |
| 294 | const DeviceAssignment& device_assignment() const { |
| 295 | return *device_assignment_; |
| 296 | } |
| 297 | |
| 298 | const std::vector<std::pair<int, int>>& local_logical_device_ids() const { |
| 299 | return local_logical_device_ids_; |
| 300 | } |
| 301 | |
| 302 | const std::vector<std::shared_ptr<Device>>& local_devices() const { |
| 303 | return local_devices_; |
| 304 | } |
| 305 | |
| 306 | StatusOr<std::unique_ptr<PyLocalBuffer>> Execute( |
| 307 | absl::Span<PyLocalBuffer* const> argument_handles); |