Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RELAY]impose a max op limit to the op fusion pass #4002

Merged
merged 2 commits into from
Sep 25, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/relay/pass/fuse_ops.cc
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ namespace relay {
using common::LinkNode;
using common::LinkedList;

constexpr uint32_t kMaxFusedOps = 256;

/*!
* \brief Indexed data flow graph in forward direction.
* This is a temporary data structure used for operator fusion analysis.
Expand Down Expand Up @@ -544,6 +546,11 @@ class GraphPartitioner {
}
return root;
}

/*!
* \brief The number of nodes belonging to this group
*/
uint num_nodes{1};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

uint is not really a cross platform data type, use uint32_t or uint64_t

};
/*!
* \brief Partition a graph.
Expand Down Expand Up @@ -616,6 +623,9 @@ class GraphPartitioner {
* \param parent The parent group.
*/
void MergeFromTo(Group* child, Group* parent) {
// refuse the fusion if too many ops are fused together
if (parent->num_nodes > kMaxFusedOps) return;
parent->num_nodes += child->num_nodes;
child = child->FindRoot();
parent = parent->FindRoot();
if (child == parent) return;
Expand Down