tensorflow/compiler/mlir/tensorflow/utils/tpu_rewrite_device_util.cc
// Determines execution devices when topology and device assignment are not
// defined. This is a special case where a single core computation is replicated
// to every core in the mesh. TPU devices are simply added to
// `execution_devices` of one replica. `num_replicas` must be 1 or the total
// number of TPU devices available, and `num_cores_per_replica` must be 1.
Determines execution devices when topology and device assignment are not
defined. This is a special case where a single core computation is replicated
to every core in the mesh. TPU devices are simply added to
`execution_devices` of one replica. `num_replicas` must be 1 or the total
number of TPU devices available, and `num_cores_per_replica` must be 1.
Determines execution devices when topology and device assignment are not defined . This is a special case where a single core computation is replicated to every core in the mesh . TPU devices are simply added to ` execution_devices ` of one replica . ` num_replicas ` must be 1 or the total number of TPU devices available and ` num_cores_per_replica ` must be 1 .
StatusOr<TPUDevicesAndHosts> GetFullMeshTPUExecutionDeviceAssignment(
    int num_replicas, int num_cores_per_replica,
    llvm::ArrayRef<llvm::SmallVector<Device, 8>> tpu_devices) {
  const int num_tasks = tpu_devices.size();
  const int num_tpus_per_task = tpu_devices[0].size();
  const int num_tpu_devices = num_tasks * num_tpus_per_task;
  if (num_replicas != 1 && num_replicas != num_tpu_devices)
    return errors::InvalidArgument("'num_replicas' must be equal to 1 or ",
                                   num_tpu_devices, ", got ", num_replicas);
  if (num_cores_per_replica != 1)
    return errors::InvalidArgument(
        "'num_cores_per_replica' must be equal to 1, got ",
        num_cores_per_replica);
  TPUDevicesAndHosts devices_and_hosts;
  devices_and_hosts.reserve(num_replicas);
  for (int i = 0; i < num_replicas; ++i) {
    const int task = i / num_tpus_per_task;
    const int device = i % num_tpus_per_task;
    const auto& tpu_device = tpu_devices[task][device];
    devices_and_hosts.push_back({TPUDeviceAndHost(
        tensorflow::DeviceNameUtils::ParsedNameToString(tpu_device),
        GetCPUHostDeviceForTPUDevice(tpu_device))});
  }
  return devices_and_hosts;
}
StatusOr < TPUDevicesAndHosts > GetFullMeshTPUExecutionDeviceAssignment ( int num_replicas , int num_cores_per_replica , llvm :: ArrayRef < llvm :: SmallVector < Device , 8 > > tpu_devices ) { const int num_tasks = tpu_devices . size ( ) ; const int num_tpus_per_task = tpu_devices [ 0 ] . size ( ) ; const int num_tpu_devices = num_tasks * num_tpus_per_task ; if ( num_replicas != 1 && num_replicas != num_tpu_devices ) return errors :: InvalidArgument ( " " , num_tpu_devices , " " , num_replicas ) ; if ( num_cores_per_replica != 1 ) return errors :: InvalidArgument ( " " , num_cores_per_replica ) ; TPUDevicesAndHosts devices_and_hosts ; devices_and_hosts . reserve ( num_replicas ) ; for ( int i = 0 ; i < num_replicas ; ++ i ) { const int task = i / num_tpus_per_task ; const int device = i % num_tpus_per_task ; const auto & tpu_device = tpu_devices [ task ] [ device ] ; devices_and_hosts . push_back ( { TPUDeviceAndHost ( tensorflow :: DeviceNameUtils :: ParsedNameToString ( tpu_device ) , GetCPUHostDeviceForTPUDevice ( tpu_device ) ) } ) ; } return devices_and_hosts ; }
Determines execution devices when topology and device assignment are not
defined.
Determines execution devices when topology and device assignment are not defined .
/*device=*/ /*host=*/