Skip to content

Commit

Permalink
Do not use ICHECK in nnvm (apache#7255)
Browse files Browse the repository at this point in the history
  • Loading branch information
ptrendx authored and trevor-m committed Jan 21, 2021
1 parent 91b7630 commit 1b74f54
Show file tree
Hide file tree
Showing 18 changed files with 102 additions and 102 deletions.
4 changes: 2 additions & 2 deletions nnvm/include/nnvm/graph.h
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ inline void DFSVisit(const std::vector<NodeEntry>& heads, FVisit fvisit);
template <typename T>
inline const T& Graph::GetAttr(const std::string& attr_name) const {
auto it = attrs.find(attr_name);
ICHECK(it != attrs.end()) << "Cannot find attribute " << attr_name << " in the graph";
CHECK(it != attrs.end()) << "Cannot find attribute " << attr_name << " in the graph";
return nnvm::unsafe_get<T>(*it->second);
}

Expand All @@ -241,7 +241,7 @@ inline bool Graph::HasAttr(const std::string& attr_name) const {
template <typename T>
inline T Graph::MoveCopyAttr(const std::string& attr_name) {
auto it = attrs.find(attr_name);
ICHECK(it != attrs.end()) << "Cannot find attribute " << attr_name << " in the graph";
CHECK(it != attrs.end()) << "Cannot find attribute " << attr_name << " in the graph";
std::shared_ptr<any> sptr = it->second;
attrs.erase(it);
if (sptr.unique()) {
Expand Down
40 changes: 20 additions & 20 deletions nnvm/include/nnvm/layout.h
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ class Layout {
for (size_t i = pos; i < pos + len; ++i) {
if (is_subdim(layout_simplified_[i])) {
auto block_size = this->subsizeof(layout_simplified_[i]);
ICHECK_GT(block_size, 0);
CHECK_GT(block_size, 0);
new_layout << block_size;
}
new_layout << layout_simplified_[i];
Expand All @@ -235,7 +235,7 @@ class Layout {
for (int64_t i = this->ndim() - 1; i >= 0; --i) {
if (is_subdim(layout_simplified_[i])) {
auto block_size = this->subsizeof(layout_simplified_[i]);
ICHECK_GT(block_size, 0);
CHECK_GT(block_size, 0);
new_layout << block_size;
}
new_layout << layout_simplified_[i];
Expand All @@ -251,13 +251,13 @@ class Layout {
* \return A newly constructed Layout object.
*/
inline Layout split(LayoutDim dim, size_t target_pos, uint32_t size) const {
ICHECK(target_pos <= this->ndim())
CHECK(target_pos <= this->ndim())
<< "Invalid split position " << target_pos << " for layout " << name_;
ICHECK(is_superdim(dim)) << "Cannot split a sub-dimension " << dim;
ICHECK(this->contains(dim)) << "Axis " << dim << " does not exist in " << name_;
ICHECK(!this->contains(to_subdim(dim)))
CHECK(is_superdim(dim)) << "Cannot split a sub-dimension " << dim;
CHECK(this->contains(dim)) << "Axis " << dim << " does not exist in " << name_;
CHECK(!this->contains(to_subdim(dim)))
<< "Dimension " << dim << " has already been split in " << name_;
ICHECK(size > 0) << "Invalid split size " << size;
CHECK(size > 0) << "Invalid split size " << size;
std::ostringstream new_layout;
for (size_t i = 0; i <= this->ndim(); ++i) {
if (i == target_pos) {
Expand Down Expand Up @@ -293,11 +293,11 @@ class Layout {
* \return the description of the dimension.
*/
inline std::string at(size_t i) const {
ICHECK_LT(i, this->ndim()) << "position " << i << " exceeds ndim=" << this->ndim();
CHECK_LT(i, this->ndim()) << "position " << i << " exceeds ndim=" << this->ndim();
std::ostringstream repr;
if (is_subdim(layout_simplified_[i])) {
auto factor = subsizeof(layout_simplified_[i]);
ICHECK_GT(factor, 0);
CHECK_GT(factor, 0);
repr << factor;
}
repr << layout_simplified_[i];
Expand Down Expand Up @@ -328,7 +328,7 @@ class Layout {
* Return -1 if \p dim is not in the layout or the layout is undefined.
*/
inline int64_t subsizeof(LayoutDim dim) const {
ICHECK(is_superdim(dim) || is_subdim(dim)) << "Invalid dim " << dim;
CHECK(is_superdim(dim) || is_subdim(dim)) << "Invalid dim " << dim;
if (!this->defined() || !this->contains(to_subdim(dim))) {
return -1;
}
Expand Down Expand Up @@ -409,34 +409,34 @@ class Layout {
const LayoutDim c = layout.at(i);
if (is_superdim(c)) {
int pos = c - 'A';
ICHECK_EQ(factor, 0) << "Invalid layout " << layout << ": invalid factor size " << factor
<< " before dimension " << c;
ICHECK_EQ(superdim_pos_[pos], -1)
CHECK_EQ(factor, 0) << "Invalid layout " << layout << ": invalid factor size " << factor
<< " before dimension " << c;
CHECK_EQ(superdim_pos_[pos], -1)
<< "Invalid layout " << layout << ": duplicate dimension " << c;
superdim_pos_[pos] = curr++;
layout_simplified_.push_back(c);
} else if (is_subdim(c)) {
int pos = c - 'a';
ICHECK_GT(factor, 0) << "Invalid layout " << layout << ": invalid factor size " << factor
<< " for dimension " << c;
ICHECK_EQ(subdim_pos_[pos], -1)
CHECK_GT(factor, 0) << "Invalid layout " << layout << ": invalid factor size " << factor
<< " for dimension " << c;
CHECK_EQ(subdim_pos_[pos], -1)
<< "Invalid layout " << layout << ": duplicate dimension " << c;
ICHECK_EQ(subdim_size_[pos], -1)
CHECK_EQ(subdim_size_[pos], -1)
<< "Invalid layout " << layout << ": duplicate dimension " << c;
subdim_pos_[pos] = curr++;
subdim_size_[pos] = factor;
layout_simplified_.push_back(c);
factor = 0;
} else if (c >= '0' && c <= '9') {
ICHECK(factor >= 0) << "Invalid layout " << layout << ": _ is adjacent to a number.";
CHECK(factor >= 0) << "Invalid layout " << layout << ": _ is adjacent to a number.";
factor = factor * 10 + c - '0';
} else {
LOG(FATAL) << "Invalid layout " << layout;
}
}
ICHECK(!layout_simplified_.empty()) << "Invalid layout " << layout;
CHECK(!layout_simplified_.empty()) << "Invalid layout " << layout;
for (LayoutDim dim : layout_simplified_) {
ICHECK(is_superdim(dim) || superdim_pos_[dim - 'a'] >= 0)
CHECK(is_superdim(dim) || superdim_pos_[dim - 'a'] >= 0)
<< "Invalid layout " << layout << ": missing axis " << static_cast<char>(dim - 'a' + 'A');
}
}
Expand Down
12 changes: 6 additions & 6 deletions nnvm/include/nnvm/op.h
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ inline const OpMap<ValueType>& Op::GetAttr(const std::string& key) {
template <typename ValueType>
inline Op& Op::set_attr( // NOLINT(*)
const std::string& attr_name, const ValueType& value, int plevel) {
ICHECK_GT(plevel, 0) << "plevel in set_attr must be greater than 0";
CHECK_GT(plevel, 0) << "plevel in set_attr must be greater than 0";
// update the attribute map of the key by creating new empty if needed.
UpdateAttrMap(attr_name, [this, attr_name, value, plevel](any* pmap) {
// the callback is in lockscope so is threadsafe.
Expand All @@ -476,7 +476,7 @@ inline Op& Op::set_attr( // NOLINT(*)
pm.attr_name_ = attr_name;
*pmap = std::move(pm);
}
ICHECK(pmap->type() == typeid(OpMap<ValueType>))
CHECK(pmap->type() == typeid(OpMap<ValueType>))
<< "Attribute " << attr_name << " of operator " << this->name
<< " is registered as inconsistent types"
<< " previously " << pmap->type().name() << " current " << typeid(OpMap<ValueType>).name();
Expand All @@ -486,8 +486,8 @@ inline Op& Op::set_attr( // NOLINT(*)
vec.resize(index_ + 1, std::make_pair(ValueType(), 0));
}
std::pair<ValueType, int>& p = vec[index_];
ICHECK(p.second != plevel) << "Attribute " << attr_name << " of operator " << this->name
<< " is already registered with same plevel=" << plevel;
CHECK(p.second != plevel) << "Attribute " << attr_name << " of operator " << this->name
<< " is already registered with same plevel=" << plevel;
if (p.second < plevel) {
vec[index_] = std::make_pair(value, plevel);
}
Expand Down Expand Up @@ -562,9 +562,9 @@ inline bool OpMap<ValueType>::contains(const Op* op) const {

template <typename ValueType>
inline const ValueType& OpMap<ValueType>::operator[](const Op* op) const {
ICHECK(op != nullptr);
CHECK(op != nullptr);
const uint32_t idx = op->index_;
ICHECK(idx < data_.size() && data_[idx].second)
CHECK(idx < data_.size() && data_[idx].second)
<< "Attribute " << attr_name_ << " has not been registered for Operator " << op->name;
return data_[idx].first;
}
Expand Down
4 changes: 2 additions & 2 deletions nnvm/include/nnvm/tuple.h
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ class TShape : public Tuple<dim_t> {
*/
template <int dim>
inline mshadow::Shape<dim> get() const {
ICHECK_EQ(dim, static_cast<int>(ndim()))
CHECK_EQ(dim, static_cast<int>(ndim()))
<< "dimension do not match target dimension " << dim << " vs " << ndim();
const dim_t* d = this->data();
mshadow::Shape<dim> s;
Expand Down Expand Up @@ -467,7 +467,7 @@ class TShape : public Tuple<dim_t> {
* \return the flat 3d shape
*/
inline mshadow::Shape<3> FlatTo3D(size_t axis_begin, size_t axis_end) const {
ICHECK(axis_end >= axis_begin);
CHECK(axis_end >= axis_begin);
mshadow::Shape<3> s;
if (ndim() == 0) return mshadow::Shape3(0, 0, 0);
const dim_t* d = this->data();
Expand Down
10 changes: 5 additions & 5 deletions nnvm/src/core/graph.cc
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ static void SubgraphSanityCheck(const std::vector<std::shared_ptr<Symbol>>& subg
nnvm::Node* node = n.get();
// if the node is visited, but on a different level, then check failed
// if check failed here or before, we stop doing anything, but raise an error
ICHECK(!node2level.count(node) || node2level[node] == level)
CHECK(!node2level.count(node) || node2level[node] == level)
<< "A subgraph should not depend on the outputs of nodes on higher levels";
// otherwise, this node belongs to the current level
node2level[node] = level;
Expand All @@ -76,9 +76,9 @@ IndexedGraph::IndexedGraph(const Graph& g) {
DFSVisit(g.outputs, [this, &inputs_rptr, &control_rptr, &subgraphs](const ObjectPtr& n) {
const auto& is_ghost = Op::GetAttr<TIsGhost>("TIsGhost");
if (!n->is_variable() && is_ghost.get(n->op(), false)) return;
ICHECK_LT(nodes_.size(), std::numeric_limits<uint32_t>::max());
CHECK_LT(nodes_.size(), std::numeric_limits<uint32_t>::max());
uint32_t nid = static_cast<uint32_t>(nodes_.size());
ICHECK(n);
CHECK(n);
for (const auto& subgraph : n->attrs.subgraphs) subgraphs.push_back(subgraph);
// nodes_
IndexedGraph::Node new_node;
Expand All @@ -96,15 +96,15 @@ IndexedGraph::IndexedGraph(const Graph& g) {
// input entries
for (const auto& e : n->inputs) {
auto it = node2index_.find(e.node.get());
ICHECK(it != node2index_.end() && it->first == e.node.get());
CHECK(it != node2index_.end() && it->first == e.node.get());
input_entries_.emplace_back(NodeEntry{it->second, e.index, e.version});
}
inputs_rptr.push_back(input_entries_.size());
// control deps
for (const auto& nptr : n->control_deps) {
if (!nptr->is_variable() && is_ghost.get(nptr->op(), false)) continue;
auto it = node2index_.find(nptr.get());
ICHECK(it != node2index_.end()) << "control dep not found in graph";
CHECK(it != node2index_.end()) << "control dep not found in graph";
control_deps_.push_back(it->second);
}
control_rptr.push_back(control_deps_.size());
Expand Down
2 changes: 1 addition & 1 deletion nnvm/src/core/op.cc
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ Op& Op::add_alias(const std::string& alias) { // NOLINT(*)
// find operator by name
const Op* Op::Get(const std::string& name) {
const Op* op = dmlc::Registry<Op>::Find(name);
ICHECK(op != nullptr) << "Operator " << name << " is not registered";
CHECK(op != nullptr) << "Operator " << name << " is not registered";
return op;
}

Expand Down
2 changes: 1 addition & 1 deletion nnvm/src/core/pass.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ Graph ApplyPasses(Graph g, const std::vector<std::string>& pass) {
std::vector<const PassFunctionReg*> fpass;
for (auto& name : pass) {
auto* reg = dmlc::Registry<PassFunctionReg>::Find(name);
ICHECK(reg != nullptr) << "Cannot find pass " << name << " in the registry";
CHECK(reg != nullptr) << "Cannot find pass " << name << " in the registry";
fpass.push_back(reg);
}

Expand Down
22 changes: 11 additions & 11 deletions nnvm/src/core/symbolic.cc
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ inline void UpdateNodeVersion(Node* n) {
if (fmutate_inputs.count(n->op()) != 0) {
for (uint32_t i : fmutate_inputs[n->op()](n->attrs)) {
NodeEntry& e = n->inputs[i];
ICHECK(e.node->is_variable()) << "Mutation target can only be Variable";
CHECK(e.node->is_variable()) << "Mutation target can only be Variable";
// increase the version of the variable.
e.version = ++nnvm::get<VariableParam>(e.node->attrs.parsed).version;
}
Expand Down Expand Up @@ -186,7 +186,7 @@ void Symbol::Print(std::ostream& os) const {

Symbol Symbol::operator[](size_t index) const {
size_t nreturn = outputs.size();
ICHECK_LT(index, nreturn) << "Symbol only accept nonnegative index";
CHECK_LT(index, nreturn) << "Symbol only accept nonnegative index";
if (nreturn == 1) {
return *this;
} else {
Expand Down Expand Up @@ -298,13 +298,13 @@ void Symbol::Compose(const array_view<const Symbol*>& args,
for (size_t i = 0; i < args.size(); ++i) {
// If the argument isn't a graph, it should have only one output.
if (garg_idx.empty() || std::find(garg_idx.begin(), garg_idx.end(), i) == garg_idx.end())
ICHECK_EQ(args[i]->outputs.size(), 1U)
CHECK_EQ(args[i]->outputs.size(), 1U)
<< "Argument " << i << " is a tuple, single value is required";
}
for (const auto& kv : kwargs) {
if (garg_names.empty() ||
std::find(garg_names.begin(), garg_names.end(), kv.first) == garg_names.end())
ICHECK_EQ(kv.second->outputs.size(), 1U)
CHECK_EQ(kv.second->outputs.size(), 1U)
<< "Keyword Argument " << kv.first << " is a tuple, single value is required";
}
// assign new name
Expand All @@ -325,7 +325,7 @@ void Symbol::Compose(const array_view<const Symbol*>& args,
sym = arg_vec[idx];
} else {
auto it = kwarg_map.find(arg_names[idx]);
ICHECK(it != kwarg_map.end());
CHECK(it != kwarg_map.end());
sym = it->second;
kwarg_map.erase(it);
}
Expand All @@ -346,7 +346,7 @@ void Symbol::Compose(const array_view<const Symbol*>& args,

if (n_req != kVarg) {
n->inputs.resize(n_req);
ICHECK_LE(arg_vec.size(), n_req)
CHECK_LE(arg_vec.size(), n_req)
<< "Incorrect number of arguments, requires " << n_req << ", provided " << arg_vec.size();
for (size_t i = 0; i < arg_vec.size(); ++i) {
n->inputs[i] = arg_vec[i]->outputs[0];
Expand Down Expand Up @@ -378,7 +378,7 @@ void Symbol::Compose(const array_view<const Symbol*>& args,
}
}
} else {
ICHECK_EQ(kwarg_map.size(), 0U) << "Variable length function do not accept kwargs";
CHECK_EQ(kwarg_map.size(), 0U) << "Variable length function do not accept kwargs";
n->inputs.reserve(arg_vec.size());
for (const Symbol* s : arg_vec) {
n->inputs.push_back(s->outputs[0]);
Expand All @@ -396,7 +396,7 @@ void Symbol::Compose(const array_view<const Symbol*>& args,
}
} else {
// general composition
ICHECK_EQ(args.size(), 0U) << "General composition only support kwargs for now";
CHECK_EQ(args.size(), 0U) << "General composition only support kwargs for now";
size_t nmatched = 0;
size_t arg_counter = 0;
std::unordered_map<Node*, const NodeEntry*> replace_map;
Expand Down Expand Up @@ -456,7 +456,7 @@ void Symbol::Compose(const array_view<const Symbol*>& args,
// update outputs in case the composed variable is part of outputs.
for (size_t i = 0; i < outputs.size(); ++i) {
if (outputs[i].node->is_variable()) {
ICHECK_EQ(args.size(), 0) << "Variable composition only supports keyword arguments";
CHECK_EQ(args.size(), 0) << "Variable composition only supports keyword arguments";
const auto it = kwargs.find(outputs[i].node->attrs.name);
if (it != kwargs.end()) outputs[i] = it->second->outputs[0];
}
Expand All @@ -473,7 +473,7 @@ Symbol Symbol::operator()(const array_view<const Symbol*>& args,
}

void Symbol::AddControlDeps(const Symbol& src) {
ICHECK_EQ(outputs.size(), 1U) << "AddControlDeps only works for nongrouped symbol";
CHECK_EQ(outputs.size(), 1U) << "AddControlDeps only works for nongrouped symbol";
Node* n = outputs[0].node.get();
for (const NodeEntry& sp : src.outputs) {
n->control_deps.push_back(sp.node);
Expand Down Expand Up @@ -517,7 +517,7 @@ Symbol Symbol::GetChildren() const {
void Symbol::SetAttrs(const std::vector<std::pair<std::string, std::string> >& attrs) {
Node* node = outputs[0].node.get();
for (const NodeEntry& e : outputs) {
ICHECK(node == e.node.get()) << "Symbol.SetAttrs only works for non-grouped symbol";
CHECK(node == e.node.get()) << "Symbol.SetAttrs only works for non-grouped symbol";
}
for (const auto& kv : attrs) {
if (kv.first == "name") {
Expand Down
12 changes: 6 additions & 6 deletions nnvm/src/pass/correct_layout.cc
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ nnvm::Graph CorrectLayout(nnvm::Graph src) {
if (new_node->is_variable()) {
// Variable node. No operator. Only one output entry.
auto input_iter = std::find(idx.input_nodes().cbegin(), idx.input_nodes().cend(), nid);
ICHECK(input_iter != idx.input_nodes().cend());
CHECK(input_iter != idx.input_nodes().cend());
int64_t input_id = std::distance(idx.input_nodes().cbegin(), input_iter);
if (src.HasAttr("layout_inputs")) {
new_layouts[new_node.get()] = {
Expand All @@ -83,11 +83,11 @@ nnvm::Graph CorrectLayout(nnvm::Graph src) {
for (size_t i = 0; i < num_inputs; ++i) {
const IndexedGraph::NodeEntry& input_entry = inode.inputs[i];
const ObjectPtr& new_input_node = mirror_vec[input_entry.node_id];
ICHECK(new_input_node != nullptr);
CHECK(new_input_node != nullptr);

// fill inputs by previous node (DFS order) inferred layouts.
const auto& layouts_iter = new_layouts.find(new_input_node.get());
ICHECK(layouts_iter != new_layouts.end());
CHECK(layouts_iter != new_layouts.end());
request_ilayouts[i] = layouts_iter->second[input_entry.index];
}
// layouts produced by previous node.
Expand All @@ -108,10 +108,10 @@ nnvm::Graph CorrectLayout(nnvm::Graph src) {

if (op_correct_layout.count(new_node->op())) {
const auto& flayout = op_correct_layout[new_node->op()];
ICHECK(flayout(new_node->attrs, &request_ilayouts, &last_request_ilayouts, &produce_olayouts))
CHECK(flayout(new_node->attrs, &request_ilayouts, &last_request_ilayouts, &produce_olayouts))
<< "Layout infer fail";
ICHECK_EQ(request_ilayouts.size(), num_inputs);
ICHECK_EQ(produce_olayouts.size(), num_outputs);
CHECK_EQ(request_ilayouts.size(), num_inputs);
CHECK_EQ(produce_olayouts.size(), num_outputs);
}

// update new layouts
Expand Down
Loading

0 comments on commit 1b74f54

Please sign in to comment.