tensorflow/c/eager/parallel_device/parallel_device.cc
// For TFE_CustomDevice::copy_tensor_from_device in the parallel device
// registration.
//
// Currently this is an error, and un-packing ParallelTensors must be performed
// explicitly by running a TPUReplicatedOutput operation on the parallel device.
//
// TODO(allenl): There are some use-cases that are only supported by copying to
// host at the moment (e.g. debug print on a tensor, .numpy(), etc.). We either
// need to return something here or address these use-cases one by one.
For TFE_CustomDevice::copy_tensor_from_device in the parallel device
registration.

Currently this is an error, and un-packing ParallelTensors must be performed
explicitly by running a TPUReplicatedOutput operation on the parallel device.

There are some use-cases that are only supported by copying to
host at the moment , etc.). We either
need to return something here or address these use-cases one by one.
For TFE_CustomDevice :: copy_tensor_from_device in the parallel device registration . Currently this is an error and un - packing ParallelTensors must be performed explicitly by running a TPUReplicatedOutput operation on the parallel device . There are some use - cases that are only supported by copying to host at the moment etc . ) . We either need to return something here or address these use - cases one by one .
TFE_TensorHandle* CopyTensorFromParallelDevice(TFE_Context* context,
                                               TFE_TensorHandle* tensor,
                                               const char* target_device_name,
                                               TF_Status* status,
                                               void* device_info) {
  ParallelTensor* parallel_tensor = reinterpret_cast<ParallelTensor*>(
      TFE_TensorHandleDevicePointer(tensor, status));
  if (TF_GetCode(status) != TF_OK) return nullptr;
  if (parallel_tensor->num_tensors() == 1) {
    return TFE_TensorHandleCopySharingTensor(parallel_tensor->tensor(0),
                                             status);
  } else {
    TF_SetStatus(
        status, TF_UNIMPLEMENTED,
        absl::StrCat(
            "Trying to copy a tensor out of a parallel device. Since there "
            "are multiple components to parallel tensors, they must be "
            "unpacked explicitly.\n",
            tensorflow::unwrap(tensor)->DebugString())
            .c_str());
    return nullptr;
  }
}
TFE_TensorHandle * CopyTensorFromParallelDevice ( TFE_Context * context , TFE_TensorHandle * tensor , const char * target_device_name , TF_Status * status , void * device_info ) { ParallelTensor * parallel_tensor = reinterpret_cast < ParallelTensor * > ( TFE_TensorHandleDevicePointer ( tensor , status ) ) ; if ( TF_GetCode ( status ) != TF_OK ) return nullptr ; if ( parallel_tensor -> num_tensors ( ) == 1 ) { return TFE_TensorHandleCopySharingTensor ( parallel_tensor -> tensor ( 0 ) , status ) ; } else { TF_SetStatus ( status , TF_UNIMPLEMENTED , absl :: StrCat ( " " " " " \n " , tensorflow :: unwrap ( tensor ) -> DebugString ( ) ) . c_str ( ) ) ; return nullptr ; } }
For TFE_CustomDevice::copy_tensor_from_device in the parallel device
registration.
For TFE_CustomDevice :: copy_tensor_from_device in the parallel device registration .
// Copy-off for single-device tensors is allowed to make debugging dynamic // control flow easier.