Skip to content

Modify Dispatch region creation to only fuse Matmuls with compatible ops. - #4040

Merged
MaheshRavishankar merged 3 commits into
iree-org:mainfrom
MaheshRavishankar:mobilebert
Dec 2, 2020
Merged

MaheshRavishankar merged 3 commits into
iree-org:mainfrom
MaheshRavishankar:mobilebert

Conversation

@MaheshRavishankar

Copy link
Copy Markdown
Collaborator

The fusion of Matmul/BatchMatmul with element-wise operations only works
for consumers where the output shape is compatible with the output of the
op. Adapt the dispatch region creation logic to account for that.

Also make reshape always fused with its producers or consumers.

Note that these enhancements to dispatch region creation are mostly
temporary and just to tide over things as the underlying codegeneration
gets more features.

}
// CHECK: EXEC @matmul_add_large
// CHECK: 16x48xf32=
// CHECK-SAME: [196 196 196 196 196 196 196 196 196 196 196 196

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

feels suspicious - is there something more useful we can use to ensure this is producing the correct results without transposition/etc?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

The answer is right. Each element is (2.0 * 3.0) * 32 + 4.0 = 196

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Tried to do something more robust (though I think what is there is fine). Tried to take the output of the following numpy program

import numpy as np

np.set_printoptions(threshold=8192, precision=6)
a = np.arange(0.0, 1.0, 1.0/(16*32), np.float32).reshape((16, 32))
b = np.arange(0.0, 1.0, 1.0/(32*48), np.float32).reshape((32, 48))
c = np.arange(0.0, 1.0, 1.0/(16*48), np.float32).reshape((16, 48))
d = np.matmul(a, b) + c
print (repr(a))
print (repr(b))
print (repr(c))
print (d)

But the iree-run-mlir doesnt have the check dialect. So testing the output becomes almost impossible

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Moved the test to structural/... to use the check.* dialect for correctness.

MaheshRavishankar added 3 commits December 1, 2020 14:29
…ops.

The fusion of Matmul with element-wise operations only works for
consumers where the output shape is compatible with the output of the
dot. Adapt the dispatch region creation logic to account for that.

Also make reshape always fused with its producers or consumers.
Comment on lines +61 to +63
if (!lhsType || !rhsType || lhsType != rhsType) {
return false;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[optional] if (!lhsType || lhsType != rhsType) is enough, but I think maybe the current way is easier to understand?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

True. But as you said, this is easier to understand the condition,

@MaheshRavishankar
MaheshRavishankar merged commit 1617b07 into iree-org:main Dec 2, 2020
@MaheshRavishankar
MaheshRavishankar deleted the mobilebert branch December 2, 2020 19:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants