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

Shared lib for tt-forge #257

Merged
merged 5 commits into from
Aug 7, 2024
Merged

Shared lib for tt-forge #257

merged 5 commits into from
Aug 7, 2024

Conversation

mtopalovicTT
Copy link
Contributor

In tt-forge we manually add each library from tt-mlir, which is error prone. This PR adds TTMLIRSO.so shared lib which will be only lib used by tt-forge.

Notes:

  • This won't solve RTTI issue
  • --whole-archive is needed to pull all symbols into shard lib

In `tt-forge` we manually add each library from `tt-mlir`, which is
error prone. This PR adds `TTMLIRSO.so` shared lib which will be only
lib used by `tt-forge`.

Notes:
* This won't solve `RTTI` issue
* `--whole-archive` is needed to pull all symbols into shard lib
lib/SharedLib/CMakeLists.txt Outdated Show resolved Hide resolved
lib/SharedLib/CMakeLists.txt Outdated Show resolved Hide resolved
lib/SharedLib/CMakeLists.txt Outdated Show resolved Hide resolved
lib/CMakeLists.txt Outdated Show resolved Hide resolved
TTRuntime
TTRuntimeTTNN
# MLIR libraries
-Wl,--no-whole-archive
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of passing these linker flags we should change the target_link_libraries, PRIVATE to PUBLIC, which should export the symbols of these static libraries.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think this work because tt-mlir is built in separate project and its targets are not visible to tt-forge, hence adding public wouldn't change anything.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think PUBLIC implies -Wl,--no-whole-archive, would you mind trying?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You mean PUBLIC implies -Wl,--whole-archive?
Btw, I tried PUBLIC initially, thats how I've ended up with whole-archive. Just to confirm I tried it again today and same issue. But I will try again to be triple sure :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Confirmed

image

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok I don't want to block the review because we should get this in. But something else must be messed up somewhere in the cmake tree, this is what PUBLIC means so I'm not sure why it would be hiding the symbols.

* Removing repeating libs
* Adding `DEVICE_LIBRARY` target
* Fixing library ordering in `third_party` `CMakeLists.txt`
${TTNN_LIBS}
)

target_link_libraries(TTMLIR PRIVATE
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be PUBLIC, all of the symbols from TTMLIR_LIBS should be made available to front ends. We can drop the -Wl,--whole-archive below. See docs: https://cmake.org/cmake/help/latest/command/target_link_libraries.html#libraries-for-a-target-and-or-its-dependents

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I left comment above with screen shot but I will write here again. Adding PUBLIC would work if tt-forge and tt-mlir was built as one single project.

target_link_libraries(TTMLIR PUBLIC SomeStaticLib)
If you have above this implies:

  • Link SomeStaticLib to TTMLIR
  • Link SomeStaticLib to any lib which links against TTMLIR directly (translative property of PUBLIC)

So if I have some third lib inside the project say TTMLIR2 and I link against TTMLIR cmake is going to inline all libs from TTMLIR to TTMLIR2.

All above works for all libs inside cmake project which means it wont work between tt-forge and tt-mlir since they are compiled separately (i.e targets from mlir are not visible to forge)

If you are not convinced ping me offline we can discuss :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@nsmithtt Ping on this :)

Copy link
Contributor

Choose a reason for hiding this comment

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

It shouldn't matter, TTMLIR target is a final executable, the static libs linked into it if marked PUBLIC means to export their symbols into the dylib. I think there must be something somewhere else in the cmake tree that's messing with this. Anyway, we can revisit, let's get this in as is :)

@mtopalovicTT mtopalovicTT requested a review from nsmithtt August 2, 2024 06:41
@mtopalovicTT mtopalovicTT merged commit ad7da1c into main Aug 7, 2024
6 checks passed
@mtopalovicTT mtopalovicTT deleted the milant/mlir_shared_lib branch December 31, 2024 08:45
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.

4 participants