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

TargetModel in python bindings #1500

Merged
merged 7 commits into from
May 21, 2024
Merged

TargetModel in python bindings #1500

merged 7 commits into from
May 21, 2024

Conversation

fifield
Copy link
Collaborator

@fifield fifield commented May 17, 2024

I thought it would be useful to query TargetModel from python, for things like L1 size and number of columns.

>>> from aie.dialects.aie import AIEDevice, get_target_model
>>> get_target_model(AIEDevice.npu1_3col).columns()
3

@makslevental this has some overlap with PybindTypes.cpp used in the python pass stuff, so ultimately maybe there is a better way to do this. But this is one way I found to make it work.

Copy link
Collaborator

@stephenneuendorffer stephenneuendorffer left a comment

Choose a reason for hiding this comment

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

Awesome! I've been wanting this!

@makslevental
Copy link
Collaborator

makslevental commented May 18, 2024

You can't do this. Well you can't do this and not run afoul of the RTTI constraints imposed by IREE and such - namely that there be no RTTI anywhere except the bindings modules. Lest you imagine that that is what you have here, I encourage you to try to build in no_rtti mode as we do here https://github.com/Xilinx/mlir-aie/blob/main/.github/workflows/mlirAIEDistro.yml#L103.

You also can't do this because you're not actually linking the dialect libs and either getting lucky that the right code ends up in the AggregateCAPI lib or not (currently the tests fail).

Much more information here and here.

In summary: there's a reason why the PybindTypes stuff is behind a build flag and also the CMake around there is "black magic".

EDIT:

Indeed the fails are due to missing symbols

ImportError: /home/runner/work/mlir-aie/mlir-aie/build_assert/python/aie/_mlir_libs/_aie.cpython-38-x86_64-linux-gnu.so:
 undefined symbol: _ZTVN6xilinx3AIE14AIETargetModelE
FileCheck error: '<stdin>' is empty.

@jgmelber
Copy link
Collaborator

You can't do this. Well you can't do this and not run afoul of the RTTI constraints imposed by IREE and such - namely that there be no RTTI anywhere except the bindings modules. Lest you imagine that that is what you have here, I encourage you to try to build in no_rtti mode as we do here https://github.com/Xilinx/mlir-aie/blob/main/.github/workflows/mlirAIEDistro.yml#L103.

You also can't do this because you're not actually linking the dialect libs and either getting lucky that the right code ends up in the AggregateCAPI lib or not (currently the tests fail).

Much more information here and here.

In summary: there's a reason why the PybindTypes stuff is behind a build flag and also the CMake around there is "black magic".

EDIT:

Indeed the fails are due to missing symbols

ImportError: /home/runner/work/mlir-aie/mlir-aie/build_assert/python/aie/_mlir_libs/_aie.cpython-38-x86_64-linux-gnu.so:
 undefined symbol: _ZTVN6xilinx3AIE14AIETargetModelE
FileCheck error: '<stdin>' is empty.

Is there a better way to do this that you can suggest @makslevental ?

@fifield fifield force-pushed the py_target_model branch 2 times, most recently from 8adf5af to c827a7d Compare May 20, 2024 19:07
@makslevental
Copy link
Collaborator

Is there a better way to do this that you can suggest @makslevental ?

Jeff got it - you just have to plumb everything through a C API.

@fifield fifield enabled auto-merge May 21, 2024 02:59
@fifield fifield added this pull request to the merge queue May 21, 2024
Merged via the queue into Xilinx:main with commit 66e642b May 21, 2024
51 checks passed
@fifield fifield deleted the py_target_model branch May 21, 2024 03:49
@@ -54,7 +54,7 @@ using TileID = struct TileID {

class AIETargetModel {
public:
AIETargetModel() = default;
AIETargetModel(AIEDevice device) : device(device) {}
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this is not a good idea... My intention with the TargetModel is that it's a singleton pattern, which is independent of the MLIR. an AIEDevice is the device of a particular design. And a Device is not actually necessary, only a container object that implements the right interface. It's unclear to me why you need to walk from the TargetModel back to a device anyway?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It was convenient for wrapping/unwrapping to keep only the enum around, and this helped with that. https://github.com/Xilinx/mlir-aie/pull/1500/files#diff-3f51e6951752378031f1f22e2616b9d3c77de3a54fcbb31cdc6ab6bd34d109dbR18-R24. But I can probably refactor to avoid the change to TargetModel

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.

None yet

4 participants