dag.h 2.2 KB
Newer Older
W
wangguibao 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
// 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.

#pragma once
#include <string>
#include <vector>
W
wangguibao 已提交
18 19 20 21 22 23
#include "common/inner_common.h"

namespace baidu {
namespace paddle_serving {
namespace predictor {

W
wangguibao 已提交
24
enum EdgeMode { RO = 0, RW = 1, UNKNOWN };
W
wangguibao 已提交
25 26

struct DagNode {
W
wangguibao 已提交
27 28 29 30 31 32 33
  uint32_t id;
  uint32_t stage;
  std::string name;       // opname
  std::string full_name;  // workflow_stageindex_opname
  std::string type;
  void* conf;
  boost::unordered_map<std::string, EdgeMode> depends;
W
wangguibao 已提交
34 35 36
};

struct DagStage {
W
wangguibao 已提交
37 38 39
  std::vector<DagNode*> nodes;
  std::string name;       // stageindex
  std::string full_name;  // workflow_stageindex
W
wangguibao 已提交
40 41 42
};

class Dag {
W
wangguibao 已提交
43 44
 public:
  Dag();
W
wangguibao 已提交
45

W
wangguibao 已提交
46
  virtual ~Dag();
W
wangguibao 已提交
47

W
wangguibao 已提交
48
  EdgeMode parse_mode(std::string& mode);  // NOLINT
W
wangguibao 已提交
49

W
wangguibao 已提交
50
  int init(const char* path, const char* file, const std::string& name);
W
wangguibao 已提交
51

W
wangguibao 已提交
52
  int init(const configure::Workflow& conf, const std::string& name);
W
wangguibao 已提交
53

W
wangguibao 已提交
54
  int deinit();
W
wangguibao 已提交
55

W
wangguibao 已提交
56
  uint32_t nodes_size();
W
wangguibao 已提交
57

W
wangguibao 已提交
58
  const DagNode* node_by_id(uint32_t id);
W
wangguibao 已提交
59

W
wangguibao 已提交
60
  const DagNode* node_by_id(uint32_t id) const;
W
wangguibao 已提交
61

W
wangguibao 已提交
62
  const DagNode* node_by_name(std::string& name);  // NOLINT
W
wangguibao 已提交
63

W
wangguibao 已提交
64
  const DagNode* node_by_name(const std::string& name) const;
W
wangguibao 已提交
65

W
wangguibao 已提交
66
  uint32_t stage_size();
W
wangguibao 已提交
67

W
wangguibao 已提交
68
  const DagStage* stage_by_index(uint32_t index);
W
wangguibao 已提交
69

W
wangguibao 已提交
70
  const std::string& name() const { return _dag_name; }
W
wangguibao 已提交
71

W
wangguibao 已提交
72
  const std::string& full_name() const { return _dag_name; }
W
wangguibao 已提交
73

W
wangguibao 已提交
74 75 76 77 78 79 80 81 82 83 84
  void regist_metric(const std::string& service_name);

 private:
  int topo_sort();

 private:
  std::string _dag_name;
  boost::unordered_map<std::string, DagNode*> _name_nodes;
  std::vector<DagNode*> _index_nodes;
  std::vector<DagStage*> _stages;
};
W
wangguibao 已提交
85

W
wangguibao 已提交
86 87 88
}  // namespace predictor
}  // namespace paddle_serving
}  // namespace baidu