aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar HyoukJoong Lee <hyouklee@google.com>2018-04-30 12:49:33 -0700
committerGravatar TensorFlower Gardener <gardener@tensorflow.org>2018-04-30 12:53:12 -0700
commit5cdcb47361e9923c418c16fee6510a472a928427 (patch)
tree3954662bd0c2ee98b5e2a8584ecc9590d6bafcb4
parent6e9d8abcdc44552a53475405f6cf0fdbffb40613 (diff)
Fix device assignment in xla/service/service.cc to build the assignment based on
the provided device handles rather than using the default assignment. PiperOrigin-RevId: 194829761
-rw-r--r--tensorflow/compiler/xla/service/hlo_module_group_metadata.cc7
-rw-r--r--tensorflow/compiler/xla/service/hlo_module_group_metadata.h3
-rw-r--r--tensorflow/compiler/xla/service/service.cc13
3 files changed, 20 insertions, 3 deletions
diff --git a/tensorflow/compiler/xla/service/hlo_module_group_metadata.cc b/tensorflow/compiler/xla/service/hlo_module_group_metadata.cc
index 54c34ce116..3367d76ded 100644
--- a/tensorflow/compiler/xla/service/hlo_module_group_metadata.cc
+++ b/tensorflow/compiler/xla/service/hlo_module_group_metadata.cc
@@ -194,6 +194,13 @@ int64 HloModuleGroupMetadata::GetModuleId(const HloModule* module) const {
LOG(FATAL) << "unknown module";
}
+int64 HloModuleGroupMetadata::GetDeviceModulesCount() const {
+ return std::count_if(modules_.begin(), modules_.end(),
+ [](const HloModule* module) {
+ return !module->config().is_host_module();
+ });
+}
+
Status HloModuleGroupMetadata::RecordInstructions() {
const auto visitor = [this](HloInstruction* hlo) -> Status {
if (hlo->opcode() == HloOpcode::kWhile) {
diff --git a/tensorflow/compiler/xla/service/hlo_module_group_metadata.h b/tensorflow/compiler/xla/service/hlo_module_group_metadata.h
index c48a7ab0b5..d619082616 100644
--- a/tensorflow/compiler/xla/service/hlo_module_group_metadata.h
+++ b/tensorflow/compiler/xla/service/hlo_module_group_metadata.h
@@ -147,6 +147,9 @@ class HloModuleGroupMetadata {
// the module in the module vector.
int64 GetModuleId(const HloModule* module) const;
+ // Returns the number of modules for devices (excluding the host module).
+ int64 GetDeviceModulesCount() const;
+
// Returns the companion instructions for the given instruction.
//
// Precondition: IsCompanionWhile(instruction) is true.
diff --git a/tensorflow/compiler/xla/service/service.cc b/tensorflow/compiler/xla/service/service.cc
index 6e0d07a12f..849488f4f9 100644
--- a/tensorflow/compiler/xla/service/service.cc
+++ b/tensorflow/compiler/xla/service/service.cc
@@ -542,9 +542,16 @@ Service::ExecuteParallelAndRegisterResult(
// profiled.
std::map<int64, se::Stream*> index_to_profiled_streams;
- TF_ASSIGN_OR_RETURN(DeviceAssignment device_assignment,
- backend->computation_placer()->AssignDevices(
- options_.number_of_replicas(), executables.size()));
+ // Build DeviceAssignment for all cores based on the provided device handles.
+ DeviceAssignment device_assignment(options_.number_of_replicas(),
+ executables.size());
+ for (int64 i = 0; i < executables.size(); i++) {
+ TF_ASSIGN_OR_RETURN(auto replicas, Replicas(*backend, device_handles[i]));
+ CHECK_EQ(replicas.size(), arguments[i].size());
+ for (int64 replica = 0; replica < replicas.size(); ++replica) {
+ device_assignment(replica, i) = replicas[replica]->device_ordinal();
+ }
+ }
for (int64 i = 0; i < executables.size(); i++) {
// Stream executors for the replicas of the current computation.