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

Broadcasting for ewBinary codegen #920

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

AlexRTer
Copy link
Collaborator

This PR changes the existing ewBinaryOp codegen to broadcast rhs if possible.
So far, the ewBinary codegen only accepted scalars, matrices of equal shape or combinations of lhs being a matrix and rhs being either a scalar or singleton.
Now rhs can also be given as a matching (equal to lhs in one dimension and size 1 in the other) row or column vector.

An example script (--explain mlir_codegen is optional to show the generated IR):

// RUN: ./bin/daphne --select-matrix-repr --mlir-codegen --explain mlir_codegen ./fileName.daphne

lhsMat = [1, 2, 3, 4, 5, 6](2,);

rhsMat = [10, 20, 30, 40, 50, 60](2,);
rhsRowMat = [10, 20, 30](1,);
rhsColMat = [10, 20](,1);
rhsScalar = 10;
rhsSingleton = [10];

print(lhsMat + rhsMat);
print(lhsMat + rhsRowMat);
print(lhsMat + rhsColMat);
print(lhsMat + rhsScalar);
print(lhsMat + rhsSingleton); // not supported outside of codegen yet

A more thorough description will be given once some tests have been added.

- changed index map for rhs in existing linalg genericOp to allow broadcasting of row/column vectors
- added shape checks to ensure matching dimensions when rhs is broadcast
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.

1 participant