提交 c3d5b61f 编写于 作者: M Megvii Engine Team 提交者: Xinran Xu

feat(mgb/opr): add property params for python operator class

GitOrigin-RevId: af6da0e0ac18fa8d81c2415dfe982ae6ce71451a
上级 81915f6b
......@@ -880,6 +880,11 @@ SymbolVar SharedScalar::_as_sym_var(CompGraph &cg, mgb::CompNode &cn) {
ssprintf("SharedScalar@%p", m_val.get()));
}
/* =============== Operator =============== */
const std::unique_ptr<mgb::OprFootprint> Operator::sm_opr_footprint_ptr{
std::make_unique<mgb::OprFootprint>()};
/* ================= misc ================= */
SymbolVar fill_retain_dtype(SymbolVar var, PyObject *value) {
......
......@@ -17,6 +17,8 @@
#include "megbrain/graph.h"
#include "megbrain/opr/io.h"
#include "megbrain/plugin/opr_footprint.h"
#include <map>
#include <string>
......@@ -441,16 +443,24 @@ class SharedScalar {
*/
class Operator {
mgb::cg::OperatorNodeBase* m_operator_node;
std::string m_params;
static const std::unique_ptr<mgb::OprFootprint> sm_opr_footprint_ptr;
public:
Operator() : m_operator_node(nullptr){};
Operator(mgb::cg::OperatorNodeBase* operator_node)
: m_operator_node(operator_node) {}
: m_operator_node(operator_node),
m_params(std::move(
(sm_opr_footprint_ptr->calc_footprint(m_operator_node)).param->to_string()))
{}
size_t id() const { return m_operator_node->id(); }
const std::string& name() const { return m_operator_node->name(); }
const std::string& params() const { return m_params; }
const std::shared_ptr<mgb::ComputingGraph> get_owner_graph() const {
return m_operator_node->owner_graph()->shared_from_this();
}
......
......@@ -58,6 +58,10 @@ public:
return $self->name();
}
const std::string& _get_params() const {
return $self->params();
}
SymbolVarArray _get_inputs() {
return $self->inputs();
}
......
......@@ -19,6 +19,11 @@ def id(self):
def name(self):
return self._get_name()
@property
def params(self):
import json
return json.loads(self._get_params())
@property
def inputs(self):
return tuple(self._get_inputs())
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册