dag_view.h 1.7 KB
Newer Older
W
wangguibao 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
#ifndef BAIDU_PADDLE_SERVING_PREDICTOR_DAG_VIEW_H
#define BAIDU_PADDLE_SERVING_PREDICTOR_DAG_VIEW_H

#include "op/op.h"
#include "common/inner_common.h"
#include "framework/channel.h"
#include "framework/dag.h"

namespace baidu {
namespace paddle_serving {
namespace predictor {

class Op;

struct ViewNode {
  Op* op; // op->full_name == service_workflow_stageindex_opname
  DagNode* conf;
  void reset() {
    op = NULL;
    conf = NULL;
  }
};

struct ViewStage {
  std::vector<ViewNode*> nodes;
  std::string full_name; // service_workflow_stageindex
  std::string debug() {
    return "TOBE IMPLEMENTED!";
  }
};

class DagView {
public:
  DagView() : _bus(NULL) {
    _view.clear();
  }

  ~DagView() {}
  
  int init(Dag* dag, const std::string& service_name);

  int deinit();

  int execute(base::IOBufBuilder* debug_os);

  // The default execution strategy is in sequencing
  // You can derive a subclass to implement this func.
  // ParallelDagView maybe the one you want.
  virtual int execute_one_stage(ViewStage* vstage,
          base::IOBufBuilder* debug_os);

  int set_request_channel(Channel& request);

  const Channel* get_response_channel() const;

  const std::string& name() const {
    return _name;
  }

  const std::string& full_name() const {
    return _full_name;
  }

private:
  std::string _name;
  std::string _full_name;
  std::vector<ViewStage*> _view;
  Bus* _bus;
};

// The derived DagView supports parallel execution
// strategy, by implments the execute_one_stage().
class ParallelDagView : public DagView {
public:  
  int execute_one_stage(ViewStage* vstage, base::IOBufBuilder*) {
    return 0;
  }
};

} // predictor
} // paddle_serving
} // baidu

#endif // BAIDU_PADDLE_SERVING_PREDICTOR_DAG_VIEW_H