dag.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_H
#define BAIDU_PADDLE_SERVING_PREDICTOR_DAG_H

#include "common/inner_common.h"

namespace baidu {
namespace paddle_serving {
namespace predictor {

enum EdgeMode {
    RO = 0, 
    RW = 1,
    UNKNOWN
};

struct DagNode {
    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;
};

struct DagStage {
    std::vector<DagNode*> nodes;
    std::string name; // stageindex
    std::string full_name; // workflow_stageindex
};

class Dag {
public:
    Dag();

    virtual ~Dag();

    EdgeMode parse_mode(std::string& mode);
    
    int init(const char* path, const char* file, const std::string& name);

    int init(const comcfg::Configure& conf, const std::string& name);
    
    int deinit();

    uint32_t nodes_size();

    const DagNode* node_by_id(uint32_t id);

    const DagNode* node_by_id(uint32_t id) const;

    const DagNode* node_by_name(std::string& name);

    const DagNode* node_by_name(const std::string& name) const;

    uint32_t stage_size();

    const DagStage* stage_by_index(uint32_t index);

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

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

    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;
};

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

#endif // BAIDU_PADDLE_SERVING_PREDICTOR_DAG_H