Repository navigation
Modify Dispatch region creation to only fuse Matmuls with compatible ops. - #4040
Conversation
| } | ||
| // CHECK: EXEC @matmul_add_large | ||
| // CHECK: 16x48xf32= | ||
| // CHECK-SAME: [196 196 196 196 196 196 196 196 196 196 196 196 |
There was a problem hiding this comment.
feels suspicious - is there something more useful we can use to ensure this is producing the correct results without transposition/etc?
There was a problem hiding this comment.
The answer is right. Each element is (2.0 * 3.0) * 32 + 4.0 = 196
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Moved the test to structural/... to use the check.* dialect for correctness.
…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.
2fd3208 to
79fa7d1
Compare
| if (!lhsType || !rhsType || lhsType != rhsType) { | ||
| return false; | ||
| } |
There was a problem hiding this comment.
[optional] if (!lhsType || lhsType != rhsType) is enough, but I think maybe the current way is easier to understand?
There was a problem hiding this comment.
True. But as you said, this is easier to understand the condition,
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.