MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / ExecuteOnLocalDevices

Method ExecuteOnLocalDevices

tensorflow/compiler/xla/python/local_client.cc:740–841  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

738}
739
740StatusOr<std::vector<std::unique_ptr<PyLocalBuffer>>>
741PyLocalExecutable::ExecuteOnLocalDevices(
742 absl::Span<const std::vector<PyLocalBuffer*>> argument_handles) {
743 tensorflow::profiler::TraceMe traceme(
744 "LocalExecutable::ExecuteOnLocalDevices");
745
746 const int num_local_devices = local_devices_.size();
747
748 if (argument_handles.size() != num_local_devices) {
749 return InvalidArgument(
750 "Attempted to execute with %d argument lists when local device "
751 "count is %d (total replica count: %d, partition count: %d)",
752 argument_handles.size(), num_local_devices, num_replicas(),
753 num_partitions());
754 }
755
756 VLOG(1) << "Executing computation " << name()
757 << "; num_replicas=" << num_replicas()
758 << " num_partitions=" << num_partitions()
759 << " num_local_devices=" << num_local_devices;
760 std::vector<StatusOr<std::unique_ptr<PyLocalBuffer>>> results(
761 num_local_devices);
762 if (num_local_devices == 1) {
763 // Fast-path if there is only one device — run the computation on the
764 // current thread.
765 const int replica = local_logical_device_ids_[0].first;
766 const int partition = local_logical_device_ids_[0].second;
767 results[0] =
768 ExecuteHelper(argument_handles[0], replica, partition, RunId());
769 } else {
770 RunId run_id;
771 absl::Mutex mu;
772 int running = num_local_devices;
773 int failed = 0;
774 Status first_failure_status;
775
776 for (int i = 0; i < num_local_devices; ++i) {
777 const int replica = local_logical_device_ids_[i].first;
778 const int partition = local_logical_device_ids_[i].second;
779 std::shared_ptr<Device> device = local_devices_[i];
780 const LocalDeviceState& device_state = *device->local_device_state();
781 device_state.execute_thread()->Schedule([&, replica, partition, i] {
782 results[i] =
783 ExecuteHelper(argument_handles[i], replica, partition, run_id);
784
785 absl::MutexLock lock(&mu);
786 --running;
787 if (!results[i].ok()) {
788 if (failed == 0) {
789 first_failure_status = results[i].status();
790 }
791 ++failed;
792 }
793 });
794 }
795
796 auto done_running_or_failed = [&]() {
797 mu.AssertHeld();

Callers

nothing calls this directly

Calls 13

InvalidArgumentFunction · 0.85
nameFunction · 0.85
RunIdClass · 0.85
ConditionClass · 0.85
AppendStatusFunction · 0.85
local_device_stateMethod · 0.80
execute_threadMethod · 0.80
sizeMethod · 0.45
ScheduleMethod · 0.45
okMethod · 0.45
statusMethod · 0.45
AwaitMethod · 0.45

Tested by

no test coverage detected