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

[aievec] to-llvm flow for i8xi8, i16xi16, bf16xbf16 elementwise multiplication #1139

Merged
merged 39 commits into from
Apr 3, 2024

Conversation

jamestcl-amd
Copy link
Collaborator

@jamestcl-amd jamestcl-amd commented Mar 19, 2024

This PR includes the e2e tests for i8xi8, i16xi16, bf16xbf16 elementwise multiplication going through the to-llvm flow.

Changes:

  • Add mul/srs/broadcast/concat/ext/undef intrinsics to XLLVM. The op names would need a better naming convention since more intrinsics are going to be added to the XLLVM.
  • Add aievec-to-llvm conversion pattern for the new intrinsics.
  • Add a FoldAIECastOps pattern in AIEVecToLLVM pass. This pattern folds all the aievec.cast ops that are introduced in the vector->aievec pass. Taking this shortcut, we do not need to conditionally introduce aievec.cast ops in the vector->aievec conversion patterns.
  • Add op folder to aievec.cast op, and remove the FoldAIECastOps pattern originally introduced in the AIEVecOptimizations pass.
  • Add i8xi8_mul_elem, i8xi8_mul_elem_2, i16xi16_mul_elem, i16xi16_mul_elem_2, bf16xbf16_mul_elem, bf16xbf16_mul_elem_2 e2e tests for the to-llvm flow. This includes updating the testbench.cc and the test script. These tests, like other to-cpp tests, go through the simulator to verify the numeric correctness.
  • Add aievec-to-llvm conversion tests for all the new XLLVM ops.
  • Add target llvm translation tests.

Copy link
Collaborator

@jsetoain jsetoain left a comment

Choose a reason for hiding this comment

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

Fantastic job so far, James. Thank you! 🙂

lib/Conversion/AIEVecToLLVM/AIEVecToLLVM.cpp Outdated Show resolved Hide resolved
lib/Dialect/AIEVec/Transforms/AIEVecOptimizations.cpp Outdated Show resolved Hide resolved
lib/Dialect/AIEVec/Transforms/AIEVecOptimizations.cpp Outdated Show resolved Hide resolved
include/aie/Dialect/XLLVM/IR/XLLVMAIE2IntrOps.td Outdated Show resolved Hide resolved
@jamestcl-amd jamestcl-amd changed the title [aievec] supporting to-llvm flow for aievec.mul_elem and aievec.srs ops [aievec] to-llvm flow for i8xi8, i16xi16, bf16xbf16 elementwise multiplication Apr 2, 2024
@jamestcl-amd jamestcl-amd requested a review from jsetoain April 2, 2024 04:49
@jamestcl-amd jamestcl-amd marked this pull request as ready for review April 2, 2024 04:49
@jamestcl-amd
Copy link
Collaborator Author

@david-vc @jsetoain this PR is ready for review. Thanks.

Copy link
Collaborator

@jsetoain jsetoain left a comment

Choose a reason for hiding this comment

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

In the future, you may want to split these into a bunch of separate patches, one per added intrinsic, for instance. Quicker turn-around, and it's easier to review.

It looks good to me, a lot of great work. Thanks, James!

Comment on lines 635 to 636
std::stringstream ss;
ss << "llvm.aie." << getVectorTypeString(resultType) << ".undef";
Copy link
Collaborator

Choose a reason for hiding this comment

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

This also needs to be replaced with an XLLVM intrinsic. In another patch, but this definitely needs clean-up.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Will clean up this in the next PR.

lib/Dialect/AIEVec/IR/AIEVecOps.cpp Outdated Show resolved Hide resolved
lib/Dialect/AIEVec/IR/AIEVecOps.cpp Outdated Show resolved Hide resolved
Copy link
Collaborator

@david-vc david-vc left a comment

Choose a reason for hiding this comment

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

LGTM

}

LogicalResult
matchAndRewrite(aievec::MulElemOp op, OpAdaptor adaptor,
Copy link
Collaborator

Choose a reason for hiding this comment

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

@jamestcl-amd , @jsetoain : This function is not doing any checking on the number of vector lanes or alternatively the total number of bits of the operands or result. Looking at

ParseResult parseMulFMAElemOp(OpAsmParser &parser, OperationState &result,
I see that this checks consistency, but not the actual number of lanes. So, which piece of are we relying on checking that the number of lanes is correct?

@jamestcl-amd
Copy link
Collaborator Author

New updates before merging this PR:

  • Separate the to-llvm and to-cpp tests into two mlir test files.
  • Add // REQUIRES: peano to the to-llvm tests. In this way, CI regression can correctly mark them unsupported (for now).
  • Address review comments on aievec.cast folder and update the test accordingly.
  • Address review comments to the testbench.cc

@jamestcl-amd jamestcl-amd merged commit 7f1b684 into Xilinx:main Apr 3, 2024
54 checks passed
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