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

Draft: Build OR shared libraries for PIP distribution #2311

Closed

Conversation

QuantamHD
Copy link
Collaborator

No description provided.

Signed-off-by: Ethan Mahintorabi <[email protected]>
set_property(SOURCE ${ARG_I_FILE}
PROPERTY USE_SWIG_DEPENDENCIES TRUE)
set_property(SOURCE ${ARG_I_FILE}
PROPERTY USE_TARGET_INCLUDE_DIRECTORIES true)


if (ARG_SHARED_LIBRARY)
Copy link
Contributor

Choose a reason for hiding this comment

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

https://cmake.org/cmake/help/latest/module/UseSWIG.html seems to have a USE_BUILD_SHARED_LIBS option to achieve something similar.

@@ -62,16 +62,29 @@ function(swig_lib)
-Werror
-w317,325,378,401,402,467,472,503,509)

set_property(SOURCE ${ARG_I_FILE}
Copy link
Contributor

Choose a reason for hiding this comment

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

should swig be able to infer this from the %module decl

from setuptools.command.build_ext import build_ext as build_ext_orig


class CMakeExtension(Extension):
Copy link
Contributor

Choose a reason for hiding this comment

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

${OPENROAD_TOOL_LIBS}
)

target_link_libraries(openroad
Copy link
Contributor

Choose a reason for hiding this comment

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

should this be libopenroad? (or removed)

Copy link
Contributor

Choose a reason for hiding this comment

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

ah my bad, that's for the executable.

@@ -293,6 +297,24 @@ target_link_libraries(openroad
${CMAKE_THREAD_LIBS_INIT}
)

add_library(libopenroad
Copy link
Contributor

Choose a reason for hiding this comment

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

should this also be linked against the optional import below (zlib, cudd, etc)

@@ -293,6 +297,24 @@ target_link_libraries(openroad
${CMAKE_THREAD_LIBS_INIT}
)

add_library(libopenroad
${OPENROAD_LIB_SRCS}
OpenRoad-py.cc
Copy link
Contributor

@proppy proppy Sep 27, 2022

Choose a reason for hiding this comment

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

curious if that could be a regular c++ library (i.e: drop the OpenRoad-py.cc dummy file) and have the main binary link against it rather than using OPENROAD_LIB_SRCS?

@proppy
Copy link
Contributor

proppy commented Sep 27, 2022

Thanks for working on this @QuantamHD! Made a few comments, let me know if you'd prefer me to do propose the change directly against your branch.

authors = [
{ name = "Matt Liberty", email = "[email protected]"}
]
description = "A production ready opensource physical design EDA toolkit"
Copy link
Collaborator

Choose a reason for hiding this comment

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

"production-ready open-source"

Also maybe drop "production-ready" to not convey a bug-free experience :)


[project]
name = "openroad"
version = "0.0.1"
Copy link
Collaborator

Choose a reason for hiding this comment

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

What parses the version number and is this going to break things when it doesn't match the source code version? Can this be generated by cmake?

Copy link

@Mizux Mizux Oct 26, 2023

Choose a reason for hiding this comment

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

using a pyproject.toml.in with some @CMAKE_VARIABLES@ or generator expression should be easy
e.g.
A "template" file (here setup.py.in but could be a toml.in file ;))
https://github.com/Mizux/python-native/blob/14648387a267b8ce65db0c0cdd47c1200c8cd7fb/python/setup.py.in#L16-L18
And the CMake stuff to auto-replace...
https://github.com/Mizux/python-native/blob/14648387a267b8ce65db0c0cdd47c1200c8cd7fb/cmake/python.cmake#L173-L181

Last step a custom_command to generate the python package (1 create a the package layout layout with all files in the build dir, 2) ask python to package wheel our stuff, 3) profit !)
https://github.com/Mizux/python-native/blob/14648387a267b8ce65db0c0cdd47c1200c8cd7fb/cmake/python.cmake#L197-L237

@maliberty
Copy link
Member

What needs to happen next here? This seems stalled

@QuantamHD
Copy link
Collaborator Author

We need to complete the librarification of the rest of the openroad modules.

@maliberty
Copy link
Member

We need to complete the librarification of the rest of the openroad modules.

It seems this could proceed in parallel.

@maliberty
Copy link
Member

@QuantamHD @proppy any further plans or close?

@proppy
Copy link
Contributor

proppy commented Oct 26, 2023

@maliberty I do have interest into landing something like this in the conda package for OpenROAD: https://github.com/hdl/conda-eda/tree/master/pnr/openroad to ease the usage from colab notebooks.

@maliberty
Copy link
Member

@proppy is there a timeline? As I said earlier "It seems this could proceed in parallel." so I think you are unblocked from progress.

@proppy
Copy link
Contributor

proppy commented Oct 26, 2023

Another pattern/reference here that we could reuse/take inspiration from is https://github.com/Mizux/cmake-swig (which I believe is what @Mizux uses for packaging https://github.com/google/or-tools).

@maliberty
Copy link
Member

@proppy we already have swig setup with cmake. The main point here is about pip packaging

@Mizux
Copy link

Mizux commented Oct 26, 2023

Another pattern/reference here that we could reuse/take inspiration from is https://github.com/Mizux/cmake-swig (which I believe is what @Mizux uses for packaging https://github.com/google/or-tools).

For python only I would look at:

@proppy
Copy link
Contributor

proppy commented Oct 26, 2023

@maliberty but my understanding is that what this PR (despite its title) is trying to address is more building the swig binding as a shared library importable from python #2308 rather than addressing the distribution on pypi #1424 (ultimately we need both, but one need to happen before the other)

@proppy
Copy link
Contributor

proppy commented Oct 26, 2023

@Mizux thanks for sharing, that's an awesome reference!

@maliberty
Copy link
Member

@maliberty but my understanding is that what this PR (despite its title) is trying to address is more building the swig binding as a shared library importable from python #2308 rather than addressing the distribution on pypi #1424 (ultimately we need both, but one need to happen before the other)

There is no question about how to build the python bindings and we've already done a lot of work in that direction and don't plan to change course. The only question is about building shared libraries.

This PR contains python/pyproject.toml which seems related to pip distribution.

If the title is wrong, please fix it.

@QuantamHD
Copy link
Collaborator Author

QuantamHD commented Oct 26, 2023

Yeah let me signal boost @maliberty. The bindings part is already solved we have a defined C++ public API that's SWIG'd. The only question is building the shared libraries such that they don't require the giant OpenROAD object that forces you to link the entire app for the library.

@cdleary and I did a bunch of work to separate libraries (gpl, grt, etc.) into library components which should make this easier. There's probably still challenges around logging, and cmake config to be solved.

@maliberty
Copy link
Member

Thanks @QuantamHD
Even if we have to "link the entire app for the library" it would be better than waiting for the perfect architecture in OR. This is >1year old so something non-ideal is better than nothing at all.

@QuantamHD
Copy link
Collaborator Author

QuantamHD commented Oct 26, 2023

There's actually a problem building it with the whole app. It won't link because it's pulling in main symbols which python will reject. The project is currently achieving python by linking a runtime in, and that's incompatible with pip who wants you to link into the user's arbitrary runtime.

@maliberty
Copy link
Member

There's actually a problem building it with the whole app. It won't link because it's pulling in main symbols which python will reject.

I didn't mean that quite so literally. I just meant making a single .so for everything but Main.cc is tolerable.

@QuantamHD
Copy link
Collaborator Author

QuantamHD commented Oct 26, 2023

A single .so is still the goal, it's just a question of actually getting one of those that actually works with pip that's the hard part. I was just pointing out one problem I ran into that stopped progress on this PR. Pulling out Main.cc wasn't as trivial as I expected it to be.

@maliberty
Copy link
Member

@QuantamHD I'm missing something here. The work you and Chris did was so you could use a single library in near isolation for unit testing. How does that relate to building a single .so? What are the issues with pulling out Main?

@QuantamHD
Copy link
Collaborator Author

QuantamHD commented Oct 26, 2023

It's all related @maliberty. I don't recall the exact details, but there's something in Main that the OpenROAD object depends on, and without it none of the logging builds.

@proppy
Copy link
Contributor

proppy commented Oct 27, 2023

which seems related to pip distribution

Sorry for the miss-understanding: I do agree all step to get there are inter-related, I just thought it would be beneficial to talk about them in isolation.
a/ writing the swig binding (done)
b/ building a python importable shared library (this PR)
c/ packaging this shared library as a platform wheel that works on most linux distro (a bit of this PR, but more is needed)
d/ automating the distribution on PyPi

@maliberty maliberty changed the title Draft: Adds python pip support Draft: Build OR shared libraries for PIP distribution Oct 27, 2023
@maliberty
Copy link
Member

It would be helpful if this PR were brought up to date.

Please give a clear statement of the specific issue to be solved is given. All I know is that "something in Main that the OpenROAD object depends on..." but that isn't enough to take any action.

@maliberty
Copy link
Member

Its also confusing that the title says Draft but this isn't actually a draft PR. Is this seeking help or just in progress?

@QuantamHD
Copy link
Collaborator Author

It was draft because it was broken. I don't really have time to work on it at the moment. So this is basically scaffolding that some can pick up, or if no one is interested then it can be closed, and I'll pick it up again when I have more time to focus on this.

@maliberty maliberty closed this Nov 29, 2023
@maliberty maliberty mentioned this pull request Dec 15, 2023
@maliberty maliberty added the py Python API label Dec 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
py Python API
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants