return true;
}
+bool Node::hasSideEffects() const {
+ switch (kind_) {
+ case prim::PythonOp:
+ case prim::Print:
+ case prim::RaiseException:
+ case aten::warn:
+ return true;
+ }
+ return false;
+}
+
// Assign this node a topological position, to facilitate fast isBefore() and
// isAfter() queries. Must be called right after a node is inserted into the
// node list.
}
TORCH_API bool isNondeterministic() const;
+ TORCH_API bool hasSideEffects () const;
// Graphs
std::unordered_set<Node*, HashNode, EqualNode> subexprs;
for (auto it = block->nodes().begin(); it != block->nodes().end(); ++ it) {
auto node = *it;
- if (node->kind() == prim::PythonOp || node->kind() == prim::Print ||
- node->kind() == aten::warn || node->isNondeterministic() ||
+ if (node->hasSideEffects() || node->isNondeterministic() ||
aliasDb.hasWriters(node) || aliasDb.hasWildcard(node)) {
// Do NOT have enough information to do CSE on these nodes.
continue;
std::unordered_set<Symbol> skip_list = {
prim::If,
prim::Loop, //TODO: handle Loop
- prim::Print,
- prim::RaiseException,
- aten::warn,
- prim::PythonOp, //may have side effects
prim::Constant,
prim::Undefined,
prim::NoneGenerator,
return v->node()->kind() == prim::Constant;
});
bool supported_node = !n->kind().is_onnx() &&
- skip_list.count(n->kind()) == 0 && !n->isNondeterministic() &&
+ skip_list.count(n->kind()) == 0 && !n->isNondeterministic() && !n->hasSideEffects() &&
!aliasDb.hasWriters(n) && !aliasDb.hasWildcard(n);
auto run_blocks = [&]() {
if (recurse) {
auto it = memo_.find(node);
if (it != memo_.end())
return it->second;
- bool has_side_effects = node->kind() == prim::Print ||
- node->kind() == aten::warn || node->kind() == prim::RaiseException ||
- node->kind() == prim::PythonOp ||
+ bool has_side_effects = node->hasSideEffects() ||
std::any_of(node->blocks().begin(),
node->blocks().end(),
[&](Block* b) {
}
return;
}
- case prim::PythonOp:
- case prim::Print:
- case prim::RaiseException:
- case aten::warn:
case prim::Undefined: {
setUnshapedType(node);
return;
default:
break; // fall-through
}
+
+ if (node->hasSideEffects()) {
+ return;
+ }
+
if (node->matches("aten::cat(Tensor[] tensors, int dim) -> Tensor")
|| node->kind() == prim::FusedConcat) {
return PropagateCatShape(node);