Skip to content

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

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

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

Conversation

keryell
Copy link
Contributor

@keryell keryell commented Nov 12, 2024

This is a huge WIP for now and far from review.
Some context and documentation is given in https://github.com/keryell/mlir-aie/blob/clangir/docs/CIR.md
It requires a specific branch of ClangIR llvm/clangir#1334 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.
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
Contributor 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.
Execute this script with the right path according to your environment, for
example with:
PATH=$LLVM_DIR/build/bin:$MLIR_AIE_HOME/build/bin:$PATH $MLIR_AIE_HOME/utils/aie++-compile.sh example.cpp
This requires on-going implementation of
annotate("cir.aie.replace_by","...")
and
annotate("cir.aie.label", "...")
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