未验证 提交 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)
: stack_(other.stack_), visited_(other.visited_) {}
Node &NodesDFSIterator::operator*() {
PADDLE_ENFORCE(!stack_.empty());
PADDLE_ENFORCE_EQ(stack_.empty(), false, platform::errors::OutOfRange(
"The iterator exceeds range."));
return *stack_.top();
}
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());
auto *cur = stack_.top();
stack_.pop();
......@@ -73,11 +75,18 @@ inline bool CheckNodeIndegreeEquals(const Node &node, size_t n) {
}
NodesTSIterator::NodesTSIterator(const std::vector<Node *> &source) {
PADDLE_ENFORCE(!source.empty(),
"Start points of topological sorting should not be empty!");
PADDLE_ENFORCE_EQ(
source.empty(), false,
platform::errors::InvalidArgument(
"Start points of topological sorting should not be empty!"));
// CHECK all the inputs' in-degree is 0
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()};
......@@ -106,7 +115,11 @@ NodesTSIterator::NodesTSIterator(const NodesTSIterator &other)
: sorted_(other.sorted_), cursor_(other.cursor_) {}
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_];
}
......@@ -128,7 +141,11 @@ bool NodesTSIterator::operator==(const NodesTSIterator &other) {
}
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_];
}
......
......@@ -15,6 +15,8 @@
#pragma once
#include <stack>
#include <unordered_set>
#include <utility>
#include <vector>
#include "paddle/fluid/framework/ir/graph.h"
......@@ -66,7 +68,7 @@ struct NodesDFSIterator
struct NodesTSIterator
: public std::iterator<std::forward_iterator_tag, Node *> {
NodesTSIterator() = default;
NodesTSIterator(const std::vector<Node *> &source);
explicit NodesTSIterator(const std::vector<Node *> &source);
NodesTSIterator(NodesTSIterator &&other)
: sorted_(std::move(other.sorted_)), cursor_(other.cursor_) {
other.cursor_ = 0;
......@@ -104,7 +106,10 @@ struct GraphTraits {
static iterator_range<NodesTSIterator> TS(const Graph &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);
return iterator_range<NodesTSIterator>(NodesTSIterator(start_points),
NodesTSIterator());
......
......@@ -42,7 +42,10 @@ void GraphVizPass::ApplyImpl(ir::Graph* graph) const {
const std::string& graph_viz_path = Get<std::string>(kGraphvizPath);
VLOG(3) << "draw IR graph viz to " << 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::unordered_map<const ir::Node*, std::string> node2dot;
......
......@@ -64,7 +64,11 @@ void IdentityScaleOpCleanPass::ApplyImpl(ir::Graph* graph) const {
for (auto& parameter : *pre_op_desc->Proto()->mutable_outputs()) {
auto* arguments = parameter.mutable_arguments();
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;
}
......
......@@ -85,7 +85,9 @@ void BatchMergePass::ApplyImpl(ir::Graph* graph) const {
// 1. record op nodes of different roles
for (auto node : nodes) {
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, node->Op()->GetAttr(
framework::OpProtoAndCheckerMaker::OpRoleAttrName()));
......@@ -108,7 +110,9 @@ void BatchMergePass::ApplyImpl(ir::Graph* graph) const {
} else if (op_role & static_cast<int>(framework::OpRole::kLRSched)) {
lr_ops.push_back(node);
} 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.
先完成此消息的编辑!
想要评论请 注册