kuiperInfer学习笔记
kuiperInfer使用的模型格式是PNNX(PyTorch Neural Network Exchange)
PNNX由图结构(Graph)、运算符(Operator)和操作数(Operand)这三种结构组成。
1. Graph 图结构
Graph是管理计算图中的运算符(Operator)和操作数(Operand)。
class Graph
{Operator* new_operator(const std::string& type, const std::string& name);Operator* new_operator_before(const std::string& type, const std::string& name, const Operator* cur);Operand* new_operand(const torch::jit::Value* v);Operand* new_operand(const std::string& name);Operand* get_operand(const std::string& name);std::vector<Operator*> ops;std::vector<Operand*> operands;
};
2. Operator 运算符结构
class Operator
{
public:std::vector<Operand*> inputs;std::vector<Operand*> outputs;std::string type;std::string name;std::vector<std::string> inputnames;std::map<std::string, Parameter> params;std::map<std::string, Attribute> attrs;
};
3. Operand 操作数结构
class Operand
{
public:void remove_consumer(const Operator* c);Operator* producer;std::vector<Operator*> consumers;int type;std::vector<int> shape;std::string name;std::map<std::string, Parameter> params;
};