Browse Source

fix codex

tags/v1.2.0
huangbingjian 5 years ago
parent
commit
ca7f5dc58e
2 changed files with 25 additions and 17 deletions
  1. +22
    -17
      mindspore/ccsrc/frontend/optimizer/opt.cc
  2. +3
    -0
      mindspore/ccsrc/frontend/optimizer/opt.h

+ 22
- 17
mindspore/ccsrc/frontend/optimizer/opt.cc View File

@@ -103,8 +103,8 @@ static bool isTraversable(const AnfNodePtr &node) {
return false;
}

static inline AnfNodePtr DoTransform(const OptimizerPtr &optimizer, const AnfNodePtr &node,
const SubstitutionPtr &substitution) {
static AnfNodePtr DoTransform(const OptimizerPtr &optimizer, const AnfNodePtr &node,
const SubstitutionPtr &substitution) {
auto manager = optimizer->manager();
bool is_match = substitution->predicate_(node);
if (is_match) {
@@ -126,8 +126,8 @@ static inline AnfNodePtr DoTransform(const OptimizerPtr &optimizer, const AnfNod
return nullptr;
}

static inline void UpdateTransformingList(const OptimizerPtr &optimizer, const AnfNodePtr &node,
std::deque<AnfNodePtr> *todo, bool change, size_t seen) {
static void UpdateTransformingList(const OptimizerPtr &optimizer, const AnfNodePtr &node, std::deque<AnfNodePtr> *todo,
bool change, size_t seen) {
if (IsValueNode<FuncGraph>(node)) {
(*todo).emplace_back(GetValueNode<FuncGraphPtr>(node)->output());
}
@@ -238,6 +238,23 @@ bool SubstitutionList::ApplySubstitutionToIR(const OptimizerPtr &optimizer, cons
return changes;
}

void SubstitutionList::DisplayStatusOfSubstitution(const std::unordered_map<std::string, std::vector<bool>> &status,
const OptimizerPtr &optimizer, size_t space) const {
std::stringstream ss;
ss << std::endl
<< "Pass: " << optimizer->name() << "(" << optimizer->CurPass_.counter << ")_" << optimizer->CurPass_.name
<< std::endl;
for (size_t i = 0; i < list_.size(); i++) {
auto name = list_[i]->name_;
ss << std::left << std::setw(space + 4) << name << "\t";
for (auto change : status.at(name + std::to_string(i))) {
ss << change << " ";
}
ss << std::endl;
}
MS_LOG(DEBUG) << ss.str();
}

bool SubstitutionList::ApplySubstitutionsToIR(const OptimizerPtr &optimizer, const FuncGraphPtr &func_graph) const {
// Add for substitution status counting
size_t space = 0;
@@ -282,19 +299,7 @@ bool SubstitutionList::ApplySubstitutionsToIR(const OptimizerPtr &optimizer, con

// Display the status of each substitution
if (optimizer->is_on_debug_) {
std::stringstream ss;
ss << std::endl
<< "Pass: " << optimizer->name() << "(" << optimizer->CurPass_.counter << ")_" << optimizer->CurPass_.name
<< std::endl;
for (size_t i = 0; i < list_.size(); i++) {
auto name = list_[i]->name_;
ss << std::left << std::setw(space + 4) << name << "\t";
for (auto change : status[name + std::to_string(i)]) {
ss << change << " ";
}
ss << std::endl;
}
MS_LOG(DEBUG) << ss.str();
DisplayStatusOfSubstitution(status, optimizer, space);
}
return changes;
}


+ 3
- 0
mindspore/ccsrc/frontend/optimizer/opt.h View File

@@ -20,6 +20,7 @@
#include <memory>
#include <string>
#include <vector>
#include <unordered_map>

#include "ir/anf.h"
#include "ir/func_graph.h"
@@ -74,6 +75,8 @@ class SubstitutionList {
bool ApplyIRToSubstitutions(const OptimizerPtr &optimizer, const FuncGraphPtr &func_graph) const;
bool ApplySubstitutionToIR(const OptimizerPtr &optimizer, const AnfNodePtr &node, const SubstitutionPtr &sub) const;
bool ApplySubstitutionsToIR(const OptimizerPtr &optimizer, const FuncGraphPtr &func_graph) const;
void DisplayStatusOfSubstitution(const std::unordered_map<std::string, std::vector<bool>> &status,
const OptimizerPtr &optimizer, size_t space) const;

std::vector<SubstitutionPtr> list_;
// a flag to mark this list of Substitution can only be executed only once


Loading…
Cancel
Save