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

[WIP][CIR] Single-source C++ lowering with ClangIR MLIR CIR #1913

Draft
wants to merge 72 commits into
base: main
Choose a base branch
from

Conversation

keryell
Copy link
Member

@keryell keryell commented Nov 12, 2024

This is a huge WIP for now and far from review.
It requires a specific branch of ClangIR instead of the usual Clang/LLVM/MLIR and it is not clear how to have this in current CI.

Extend conflicting --mlir-to-llvmir option.
This avoids choking on some remaining CIR attributes like:
Unable to parse module assembly:
error: "-":1:101: #"cir"<"lang<cxx>"> : 'none' attribute created with unregistered dialect. If this is intended, please call allowUnregisteredDialects() on the MLIRContext, or use -allow-unregistered-dialect with the MLIR opt tool used

This is simpler than adding the CIR dialect itself to the Python infrastructure
which is quite complex.
Allow aie.device to appear anywhere.
For example to allow simpler transformations in a single-source framework.
Start the new CIR infrastructure in some separate CIR directories for a cleaner
organization.
It is unclear how to pass information to a Pattern::matchAndRewrite.
Add a "aie.device" attribute with the device name to make things clearer.
To do: integrate this into CMake infrastructure.
Also simplify some type names by removing some `_t`.
Also updated to new types in aie++.hpp header.
Generate things like:
    %2 = builtin.unrealized_conversion_cast %1 : !cir.ptr<!ty_aie3A3Adevice3Caie3A3Anpu13E> to !cir.ptr<!ty_aie3A3Atile3C12C_43E> {"aie::tile" = ["1", "4"]}
For now only --cir-to-aie-prepare does something.
Generate also aie.tile and WIP hard-coded aie.buffer.
The problem was that at some point, the lowering was iterating along some
mlir::Operation::getUsers() which were not in C++ program order, breaking some
inter-operation dependencies.
So now just use a single top-level walk<mlir::WalkOrder::PreOrder>.
Just lower to the aie.device operations for now.
For example use
aie-opt --debug-only=cir-to-aie --cir-to-aie ...
to print the debug messages with a Debug build.
Improve also analysis and debug output.
During operation cloning, mlir::IRMapping is used to remap some leaf input
operands but cannot remap some internal ones. In some case, ClangIR lower some
lambda captures with aie::tile or with aie::device (). Having the aie::device is
problematic since it is remapped to the aie.device output which leads to 2
issues for the verifyer:

- this use is inside the device operation itself

- the aie.device region is isolated from above.

Since this aie::device is used only by an aie::tile, just remove the aie::device
part.
Previously, the mapping from an aie++ type to its lowered AIE operation was
constructed lazily during the lowering itself, preventing another pass running
later to have access to its information.
Now CIRToAIETypesAnalysis can reconstruct this mapping if the lowering has
already been done.
For now only inline the first call of the call chain..
Require a specific version of ClangIR to cope with inlining and the fact that
CIR functions returning !cir.void do not actually return anything.
Optimize out the lambda capture leftover in aie.core.
Disable this option for now to keep the old behavior without any ClangIR MLIR
C++ front-end feature.
Returning a handle was too disruptive to the MLIR AIE unit tests.
Controlling a specific aie.device by the runtime can be done later without using
the result as a handler.
All the AIE operations which are created have now a "cir.type" type attribute
for any later introspection.
@keryell
Copy link
Member Author

keryell commented Dec 4, 2024

This relies on llvm/clangir#1203 and llvm/clangir#1164

Extract the aie.device operation as the top-module operation.
Anything else is removed.
For now just keep the first aie.device.
The CIR lowering passes are aware of AIE dialects when going to LLVM dialect or
MLIR standard dialects from aie-opt or aie-translate.
Also expose the --cir-to-llvm pass to aie-opt.
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