Take work from the work queue.
(self)
| 358 | lambda: create_with_prompt) |
| 359 | |
| 360 | def take(self): |
| 361 | """Take work from the work queue.""" |
| 362 | def remote_take(): |
| 363 | """Take work from remote worker.""" |
| 364 | with ops.name_scope(self.name): |
| 365 | with ops.device(self._remote_device): |
| 366 | taken = gen_work_queue_ops.work_queue_take( |
| 367 | self._handle, |
| 368 | num_clients=self.num_clients) |
| 369 | |
| 370 | work_bak = control_flow_ops.no_op() |
| 371 | if self._local_work_mgr: |
| 372 | work_bak = gen_work_queue_ops.save_local_work( |
| 373 | taken, |
| 374 | job_name=self._local_work_mgr.job_name, |
| 375 | task_index=self._local_work_mgr.task_index, |
| 376 | restore_works_dir=self._local_work_mgr.restore_works_dir) |
| 377 | with ops.control_dependencies([work_bak]): |
| 378 | with ops.device(self._local_device): |
| 379 | local_work = array_ops.identity(taken) |
| 380 | return local_work |
| 381 | |
| 382 | def local_take(): |
| 383 | """Take work from local worker.""" |
| 384 | assert self._local_work_mgr, 'local_work_mgr should not be None.' |
| 385 | return self._local_work_mgr.take() |
| 386 | |
| 387 | if self._local_work_mgr: |
| 388 | with ops.name_scope(self.name): |
| 389 | with ops.device(self._local_device): |
| 390 | with ops.device('/cpu:0'): |
| 391 | local_workqueue_empty = self._local_work_mgr.local_workqueue_empty() |
| 392 | local_work = control_flow_ops.cond( |
| 393 | local_workqueue_empty, remote_take, local_take) |
| 394 | else: |
| 395 | local_work = remote_take() |
| 396 | |
| 397 | if self._prefix is None: |
| 398 | return local_work |
| 399 | return string_ops.string_join([self._prefix, local_work]) |
| 400 | |
| 401 | def input_producer(self): |
| 402 | """Returns a FIFOQueue as input producer. |