// Copyright (c) 2019 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 baidu.paddle_serving.configure;

message EngineDesc {
  required string name = 1;
  required string type = 2;
  required string reloadable_meta = 3;
  required string reloadable_type = 4;
  required string model_dir = 5;
  required int32 runtime_thread_num = 6;
  required int32 batch_infer_size = 7;
  required int32 enable_batch_align = 8;
  optional string version_file = 9;
  optional string version_type = 10;

  /*
   * Sparse Parameter Service type. Valid types are:
   * "None": not use sparse parameter service
   * "Local": Use local kv service (rocksdb library & API)
   * "Remote": Use remote kv service (cube)
   */
  enum SparseParamServiceType {
    NONE = 0;
    LOCAL = 1;
    REMOTE = 2;
  }
  optional SparseParamServiceType sparse_param_service_type = 11;
  optional string sparse_param_service_table_name = 12;
  optional bool enable_memory_optimization = 13;
  optional bool enable_ir_optimization = 14;
  optional bool use_trt = 15;
  optional bool use_lite = 16;
  optional bool use_xpu = 17;
  optional bool use_gpu = 18;
  optional bool combined_model = 19;
  optional bool encrypted_model = 20;
};

// model_toolkit conf
message ModelToolkitConf { repeated EngineDesc engines = 1; };

// reource conf
message ResourceConf {
  repeated string model_toolkit_path = 1;
  repeated string model_toolkit_file = 2;
  repeated string general_model_path = 3;
  repeated string general_model_file = 4;
  optional string cube_config_path = 5;
  optional string cube_config_file = 6;
  optional int32 cube_quant_bits = 7; // set 0 if no quant.
  optional string auth_product_name = 8;
  optional string auth_container_id = 9;
};

// DAG node depency info
message DAGNodeDependency {
  required string name = 1;
  required string mode = 2;
};

// DAG Node
message DAGNode {
  required string name = 1;
  required string type = 2;
  repeated DAGNodeDependency dependencies = 3;
};

// workflow entry
message Workflow {
  required string name = 1;
  required string workflow_type = 2;
  repeated DAGNode nodes = 3;
};

// Workflow conf
message WorkflowConf { repeated Workflow workflows = 1; }

// request_field_key: specifies use which request field as mapping key (see
// request_field_key in InferService below)
//
// If the value of the user request field specified by `request_field_key`
// matches the value of `request_field_value` in one of the
// ValueMappedWorkflows, the request will be directed to the workflow specified
// in the `workflow` field of that ValueMappedWorkflow
//
message ValueMappedWorkflow {
  required string request_field_value = 1;
  required string workflow = 2;
};

message InferService {
  required string name = 1;
  optional string merger = 2;

  optional bool enable_map_request_to_workflow = 3 [ default = false ];

  // If enable_map_request_to_workfow = true
  //
  // Each request will be mapped to a workflow according to the value in
  // in user request field specified by `request_field_key` (see the
  // comments for ValueMappedWorkflow above)
  optional string request_field_key = 4;
  repeated ValueMappedWorkflow value_mapped_workflows = 5;

  // If enable_map_request_to_workflow = false
  repeated string workflows = 6;
};

// InferService conf
message InferServiceConf {
  optional uint32 port = 1;
  repeated InferService services = 2;
};
