我想打PAC队的第一次评注 #16
|
|
@ -126,6 +126,10 @@ bool ConstInputToAttrInfoRegistry::GetRegisterByOpName(const std::string &op_nam
|
|||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* @brief If the input of cnode is a const tensor, and the index of input is in the input_attrs,
|
||||
* then set the const tensor to attr of cnode.
|
||||
*/
|
||||
void ConstInputToAttr(const CNodePtr &cnode, const mindspore::HashSet<size_t> &input_attrs) {
|
||||
MS_EXCEPTION_IF_NULL(cnode);
|
||||
std::vector<AnfNodePtr> new_inputs;
|
||||
|
|
@ -148,6 +152,7 @@ void ConstInputToAttr(const CNodePtr &cnode, const mindspore::HashSet<size_t> &i
|
|||
input_node = AnfUtils::VisitKernel(input_node, 0).first;
|
||||
}
|
||||
if (input_attrs.find(i) != input_attrs.end() && input_node->isa<ValueNode>() && !HasAbstractMonad(input_node)) {
|
||||
// set const input to primitive attr and erase original const input
|
||||
auto value_node = input_node->cast<ValueNodePtr>();
|
||||
MS_EXCEPTION_IF_NULL(value_node);
|
||||
MS_LOG(DEBUG) << "start erase input[" << i << "] of cnode[" + cnode->DebugString() + "]";
|
||||
|
|
|
|||
|
|
@ -24,6 +24,11 @@
|
|||
|
||||
namespace mindspore {
|
||||
namespace opt {
|
||||
/*
|
||||
* @brief Convert const input of cnode to attr.
|
||||
*
|
||||
* @param node The node which has const input.
|
||||
*/
|
||||
const AnfNodePtr ConvertConstInputToAttr::Process(const FuncGraphPtr &, const AnfNodePtr &node,
|
||||
const EquivPtr &) const {
|
||||
if (node == nullptr || !AnfUtils::IsRealCNodeKernel(node)) {
|
||||
|
|
|
|||
|
|
@ -27,6 +27,8 @@
|
|||
namespace mindspore {
|
||||
namespace opt {
|
||||
namespace {
|
||||
|
||||
// get the real previous cnode; skipping virtual nodes
|
||||
CNodePtr GetRealPrevCNode(const AnfNodePtr &node, size_t index, std::vector<KernelWithIndex> *pass_vector) {
|
||||
MS_EXCEPTION_IF_NULL(pass_vector);
|
||||
if (node == nullptr || !node->isa<CNode>()) {
|
||||
|
|
@ -79,6 +81,7 @@ bool TransDataOpEliminateCondition(const CNodePtr &node1, const CNodePtr &node2)
|
|||
}
|
||||
} // namespace
|
||||
|
||||
// eliminate redundant op when matching conditions
|
||||
const AnfNodePtr EliminateRedundantOp::ProcessMatchedNodes(const FuncGraphPtr &func_graph, const CNodePtr &cnode,
|
||||
const CNodePtr &prev_cnode,
|
||||
std::vector<KernelWithIndex> *pass_vector) const {
|
||||
|
|
@ -158,7 +161,7 @@ const AnfNodePtr EliminateRedundantOp::DoEliminate(const FuncGraphPtr &func_grap
|
|||
if (name2 != it->second.first) {
|
||||
return nullptr;
|
||||
}
|
||||
// match condition
|
||||
// match eliminate condition
|
||||
auto condition_func = it->second.second;
|
||||
if (condition_func == nullptr) {
|
||||
return nullptr;
|
||||
|
|
@ -167,6 +170,7 @@ const AnfNodePtr EliminateRedundantOp::DoEliminate(const FuncGraphPtr &func_grap
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
// perform elimination
|
||||
return ProcessMatchedNodes(func_graph, cnode, prev_cnode, &pass_vector);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue