// Copyright (c) 2020 PaddlePaddle 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 = "proto2";
package paddle.distributed;
option cc_generic_services = true;
option cc_enable_arenas = true;

enum PsCmdID {
  PS_PULL_DENSE_TABLE = 0;
  PS_PUSH_DENSE_TABLE = 1;
  PS_PULL_SPARSE_TABLE = 2;
  PS_PUSH_SPARSE_TABLE = 3;
  PS_SHRINK_TABLE = 4;
  PS_SAVE_ONE_TABLE = 5;
  PS_SAVE_ALL_TABLE = 6;
  PS_LOAD_ONE_TABLE = 7;
  PS_LOAD_ALL_TABLE = 8;
  PS_CLEAR_ONE_TABLE = 9;
  PS_CLEAR_ALL_TABLE = 10;
  PS_PUSH_DENSE_PARAM = 11;
  PS_STOP_SERVER = 12;
  PS_SAVE_ONE_CACHE_TABLE = 13;
  PS_GET_CACHE_THRESHOLD = 14;
  PS_CACHE_SHUFFLE = 15;
  PS_COPY_TABLE = 16;
  PS_COPY_TABLE_BY_FEASIGN = 17;
  PS_PULL_SPARSE_TABLE_WITH_DEPENDENCY = 18;
  PS_PUSH_SPARSE_TABLE_WITH_DEPENDENCY = 19;
  PS_PRINT_TABLE_STAT = 20;
  PS_SAVE_ONE_TABLE_PREFIX = 21;
  PS_SAVE_ONE_TABLE_WITH_WHITELIST = 22;
  PS_LOAD_ONE_TABLE_WITH_WHITELIST = 23;
  PS_PULL_GEO_PARAM = 24;
  PS_BARRIER = 25;
  PS_PUSH_SPARSE_PARAM = 26;
  PS_START_PROFILER = 27;
  PS_STOP_PROFILER = 28;
  PS_PUSH_GLOBAL_STEP = 29;
  PS_PULL_GRAPH_LIST = 30;
  PS_GRAPH_SAMPLE_NEIGHBOORS = 31;
  PS_GRAPH_SAMPLE_NODES = 32;
  PS_GRAPH_GET_NODE_FEAT = 33;
  PS_GRAPH_CLEAR = 34;
  PS_GRAPH_ADD_GRAPH_NODE = 35;
  PS_GRAPH_REMOVE_GRAPH_NODE = 36;
}

message PsRequestMessage {
  required uint32 cmd_id = 1;
  optional uint32 table_id = 2;
  repeated bytes params = 3;
  optional int32 client_id = 4;
  optional bytes data = 5;
};

message PsResponseMessage {
  required int32 err_code = 1 [ default = 0 ];
  required string err_msg = 2 [ default = "" ];
  optional bytes data = 3;
};

enum VarType {
  LOD_TENSOR = 0;
  SELECTED_ROWS = 1;
}

message VariableMessage {
  enum Type {
    // Pod Types
    BOOL = 0;
    INT16 = 1;
    INT32 = 2;
    INT64 = 3;
    FP16 = 4;
    FP32 = 5;
    FP64 = 6;
  }

  message LodData { repeated int64 lod_data = 1; }
  optional string varname = 1;
  // TODO(Yancey1989): reference framework::proto::VarDesc::VarType
  optional VarType type = 2;
  // bool persistable is not needed for sending.
  // tensor info:
  optional Type data_type = 3;
  repeated int64 dims = 4;

  // lod details:
  optional int64 lod_level = 5;
  repeated LodData lod = 6;
  // selected_rows height, aka. original dim0
  optional int64 slr_height = 7;
  // tensor data
  optional bytes data = 8;
}

// for SendAndRecv RPC method
message MultiVariableMessage {
  // message flags
  required string message_name = 1;
  repeated string send_var_names = 2;
  repeated string recv_var_names = 3;
  repeated VariableMessage var_messages = 4;
};

service PsService {
  rpc service(PsRequestMessage) returns (PsResponseMessage);
  rpc SendAndRecvVariable(MultiVariableMessage) returns (MultiVariableMessage);
};
