/* Copyright 2016 The TensorFlow Authors. All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/

syntax = "proto3";

package tensorflow.contrib.mpi_collectives;

import "tensorflow/core/framework/tensor_shape.proto";
import "tensorflow/core/framework/types.proto";

// An MPIRequest is a message sent from a rank greater than zero to the
// coordinator (rank zero), informing the coordinator of an operation that
// the rank wants to do and the tensor that it wants to apply the operation to.
message MPIRequest {
  enum RequestType {
    ALLREDUCE = 0;
    ALLGATHER = 1;
  }

  // The request rank is necessary to create a consistent ordering of results,
  // for example in the allgather where the order of outputs should be sorted
  // by rank.
  int32 request_rank = 1;
  RequestType request_type = 2;
  DataType tensor_type = 3;
  string tensor_name = 4;
  TensorShapeProto tensor_shape = 5;
};

// An MPIResponse is a message sent from the coordinator (rank zero) to a rank
// greater than zero, informing the rank of an operation should be performed
// now. If the operation requested would result in an error (for example, due
// to a type or shape mismatch), then the MPIResponse can contain an error and
// an error message instead. Finally, an MPIResponse can be a DONE message (if
// there are no more tensors to reduce on this tick of the background loop) or
// SHUTDOWN if all MPI processes should shut down.
message MPIResponse {
  enum ResponseType {
    ALLREDUCE = 0;
    ALLGATHER = 1;
    ERROR = 2;
    DONE = 3;
    SHUTDOWN = 4;
  }

  // Empty if the type is DONE or SHUTDOWN.
  ResponseType response_type = 1;
  string tensor_name = 2;

  // Empty unless response_type is ERROR.
  string error_message = 3;
};
