未验证 提交 9b46fe04 编写于 作者: W wanghuancoder 提交者: GitHub

fix some errmsg report,in framework/ir/, about 5 files (#25539)

* fix error msg report in ir/, about 5 files, test=develop

* fix error msg report in ir/, about 5 files, test=develop

* fix error msg report in ir/, about 5 files, test=develop
上级 f8ec5f0f
...@@ -37,12 +37,14 @@ NodesDFSIterator::NodesDFSIterator(const NodesDFSIterator &other) ...@@ -37,12 +37,14 @@ NodesDFSIterator::NodesDFSIterator(const NodesDFSIterator &other)
: stack_(other.stack_), visited_(other.visited_) {} : stack_(other.stack_), visited_(other.visited_) {}
Node &NodesDFSIterator::operator*() { Node &NodesDFSIterator::operator*() {
PADDLE_ENFORCE(!stack_.empty()); PADDLE_ENFORCE_EQ(stack_.empty(), false, platform::errors::OutOfRange(
"The iterator exceeds range."));
return *stack_.top(); return *stack_.top();
} }
NodesDFSIterator &NodesDFSIterator::operator++() { NodesDFSIterator &NodesDFSIterator::operator++() {
PADDLE_ENFORCE(!stack_.empty(), "the iterator exceeds range"); PADDLE_ENFORCE_EQ(stack_.empty(), false, platform::errors::OutOfRange(
"The iterator exceeds range."));
visited_.insert(stack_.top()); visited_.insert(stack_.top());
auto *cur = stack_.top(); auto *cur = stack_.top();
stack_.pop(); stack_.pop();
...@@ -73,11 +75,18 @@ inline bool CheckNodeIndegreeEquals(const Node &node, size_t n) { ...@@ -73,11 +75,18 @@ inline bool CheckNodeIndegreeEquals(const Node &node, size_t n) {
} }
NodesTSIterator::NodesTSIterator(const std::vector<Node *> &source) { NodesTSIterator::NodesTSIterator(const std::vector<Node *> &source) {
PADDLE_ENFORCE(!source.empty(), PADDLE_ENFORCE_EQ(
"Start points of topological sorting should not be empty!"); source.empty(), false,
platform::errors::InvalidArgument(
"Start points of topological sorting should not be empty!"));
// CHECK all the inputs' in-degree is 0 // CHECK all the inputs' in-degree is 0
for (auto *node : source) { for (auto *node : source) {
PADDLE_ENFORCE(CheckNodeIndegreeEquals(*node, 0)); PADDLE_ENFORCE_EQ(
CheckNodeIndegreeEquals(*node, 0), true,
platform::errors::InvalidArgument(
"In start points of topological sorting, the indegree of each "
"point should be 0. Node(%s)'s indegree is not 0.",
node->Name()));
} }
std::set<Node *> to_visit{source.begin(), source.end()}; std::set<Node *> to_visit{source.begin(), source.end()};
...@@ -106,7 +115,11 @@ NodesTSIterator::NodesTSIterator(const NodesTSIterator &other) ...@@ -106,7 +115,11 @@ NodesTSIterator::NodesTSIterator(const NodesTSIterator &other)
: sorted_(other.sorted_), cursor_(other.cursor_) {} : sorted_(other.sorted_), cursor_(other.cursor_) {}
Node &NodesTSIterator::operator*() { Node &NodesTSIterator::operator*() {
PADDLE_ENFORCE_LT(cursor_, sorted_.size()); PADDLE_ENFORCE_LT(
cursor_, sorted_.size(),
platform::errors::OutOfRange(
"The iterator exceeds range. Container size is %d, but index is %d.",
sorted_.size(), cursor_));
return *sorted_[cursor_]; return *sorted_[cursor_];
} }
...@@ -128,7 +141,11 @@ bool NodesTSIterator::operator==(const NodesTSIterator &other) { ...@@ -128,7 +141,11 @@ bool NodesTSIterator::operator==(const NodesTSIterator &other) {
} }
Node *NodesTSIterator::operator->() { Node *NodesTSIterator::operator->() {
PADDLE_ENFORCE_LT(cursor_, sorted_.size()); PADDLE_ENFORCE_LT(
cursor_, sorted_.size(),
platform::errors::OutOfRange(
"The iterator exceeds range. Container size is %d, but index is %d.",
sorted_.size(), cursor_));
return sorted_[cursor_]; return sorted_[cursor_];
} }
......
...@@ -15,6 +15,8 @@ ...@@ -15,6 +15,8 @@
#pragma once #pragma once
#include <stack> #include <stack>
#include <unordered_set>
#include <utility>
#include <vector> #include <vector>
#include "paddle/fluid/framework/ir/graph.h" #include "paddle/fluid/framework/ir/graph.h"
...@@ -66,7 +68,7 @@ struct NodesDFSIterator ...@@ -66,7 +68,7 @@ struct NodesDFSIterator
struct NodesTSIterator struct NodesTSIterator
: public std::iterator<std::forward_iterator_tag, Node *> { : public std::iterator<std::forward_iterator_tag, Node *> {
NodesTSIterator() = default; NodesTSIterator() = default;
NodesTSIterator(const std::vector<Node *> &source); explicit NodesTSIterator(const std::vector<Node *> &source);
NodesTSIterator(NodesTSIterator &&other) NodesTSIterator(NodesTSIterator &&other)
: sorted_(std::move(other.sorted_)), cursor_(other.cursor_) { : sorted_(std::move(other.sorted_)), cursor_(other.cursor_) {
other.cursor_ = 0; other.cursor_ = 0;
...@@ -104,7 +106,10 @@ struct GraphTraits { ...@@ -104,7 +106,10 @@ struct GraphTraits {
static iterator_range<NodesTSIterator> TS(const Graph &g) { static iterator_range<NodesTSIterator> TS(const Graph &g) {
auto start_points = ExtractStartPoints(g); auto start_points = ExtractStartPoints(g);
PADDLE_ENFORCE(!start_points.empty()); PADDLE_ENFORCE_EQ(
start_points.empty(), false,
platform::errors::InvalidArgument(
"Start points of topological sorting should not be empty!"));
NodesTSIterator x(start_points); NodesTSIterator x(start_points);
return iterator_range<NodesTSIterator>(NodesTSIterator(start_points), return iterator_range<NodesTSIterator>(NodesTSIterator(start_points),
NodesTSIterator()); NodesTSIterator());
......
...@@ -42,7 +42,10 @@ void GraphVizPass::ApplyImpl(ir::Graph* graph) const { ...@@ -42,7 +42,10 @@ void GraphVizPass::ApplyImpl(ir::Graph* graph) const {
const std::string& graph_viz_path = Get<std::string>(kGraphvizPath); const std::string& graph_viz_path = Get<std::string>(kGraphvizPath);
VLOG(3) << "draw IR graph viz to " << graph_viz_path; VLOG(3) << "draw IR graph viz to " << graph_viz_path;
std::unique_ptr<std::ostream> fout(new std::ofstream(graph_viz_path)); std::unique_ptr<std::ostream> fout(new std::ofstream(graph_viz_path));
PADDLE_ENFORCE(fout->good()); PADDLE_ENFORCE_EQ(
fout->good(), true,
platform::errors::Unavailable(
"Can not open file %s for printing the graph.", graph_viz_path));
std::ostream& sout = *fout; std::ostream& sout = *fout;
std::unordered_map<const ir::Node*, std::string> node2dot; std::unordered_map<const ir::Node*, std::string> node2dot;
......
...@@ -64,7 +64,11 @@ void IdentityScaleOpCleanPass::ApplyImpl(ir::Graph* graph) const { ...@@ -64,7 +64,11 @@ void IdentityScaleOpCleanPass::ApplyImpl(ir::Graph* graph) const {
for (auto& parameter : *pre_op_desc->Proto()->mutable_outputs()) { for (auto& parameter : *pre_op_desc->Proto()->mutable_outputs()) {
auto* arguments = parameter.mutable_arguments(); auto* arguments = parameter.mutable_arguments();
auto it = std::find(arguments->begin(), arguments->end(), scale_in_name); auto it = std::find(arguments->begin(), arguments->end(), scale_in_name);
PADDLE_ENFORCE(it != arguments->end()); PADDLE_ENFORCE_NE(
it, arguments->end(),
platform::errors::NotFound(
"Can not find input variable(%s) from scale op(%s).",
scale_in_name, pre_op_desc->Type()));
*it = scale_out_name; *it = scale_out_name;
} }
......
...@@ -85,7 +85,9 @@ void BatchMergePass::ApplyImpl(ir::Graph* graph) const { ...@@ -85,7 +85,9 @@ void BatchMergePass::ApplyImpl(ir::Graph* graph) const {
// 1. record op nodes of different roles // 1. record op nodes of different roles
for (auto node : nodes) { for (auto node : nodes) {
if (!node->IsOp()) continue; if (!node->IsOp()) continue;
PADDLE_ENFORCE(node->Op(), "must find opdesc"); PADDLE_ENFORCE_NOT_NULL(
node->Op(), platform::errors::InvalidArgument(
"Node(%s) must hold op description.", node->Name()));
int op_role = BOOST_GET_CONST( int op_role = BOOST_GET_CONST(
int, node->Op()->GetAttr( int, node->Op()->GetAttr(
framework::OpProtoAndCheckerMaker::OpRoleAttrName())); framework::OpProtoAndCheckerMaker::OpRoleAttrName()));
...@@ -108,7 +110,9 @@ void BatchMergePass::ApplyImpl(ir::Graph* graph) const { ...@@ -108,7 +110,9 @@ void BatchMergePass::ApplyImpl(ir::Graph* graph) const {
} else if (op_role & static_cast<int>(framework::OpRole::kLRSched)) { } else if (op_role & static_cast<int>(framework::OpRole::kLRSched)) {
lr_ops.push_back(node); lr_ops.push_back(node);
} else { // NOLINT } else { // NOLINT
PADDLE_THROW("Invalid op_role: %d", static_cast<int>(op_role)); PADDLE_THROW(platform::errors::InvalidArgument(
"Invalid op role(%d), in node(%s).", static_cast<int>(op_role),
node->Name()));
} }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册