-
Notifications
You must be signed in to change notification settings - Fork 38
Python wheel packaging for ptoas, in manylinux docker image #1
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
1174c8e
fix cmake build settings for manylinux
dbeec45
fix ptoas path
8de48e9
dockerfile to compile ptoas in manylinux base img
bde2c74
minimum wheel setup
5c6431e
fix missing so by audirwheel tool
7e9bfb8
e2e test
5f44992
run ptoas in local dir, otherwise get path error
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| FROM quay.io/pypa/manylinux_2_34_x86_64 | ||
|
|
||
| # NOTE: change $PY_VER for different Python versions (3.8 - 3.14 available) | ||
| ARG PY_VER=cp312-cp312 | ||
| ARG LLVM_TAG=llvmorg-19.1.7 | ||
|
|
||
| ## -- usually no need to change below -- | ||
|
|
||
| ENV PY_PATH="/opt/python/${PY_VER}" | ||
| ENV PATH="${PY_PATH}/bin:${PATH}" | ||
|
|
||
| # dependency | ||
| RUN dnf install -y ninja-build cmake git ccache gcc-c++ lld && dnf clean all | ||
| RUN pip install --no-cache-dir numpy pybind11 nanobind | ||
|
|
||
| # setting build directories | ||
| ENV WORKSPACE_DIR=/llvm-workspace | ||
| ENV LLVM_SOURCE_DIR=$WORKSPACE_DIR/llvm-project | ||
| ENV LLVM_BUILD_DIR=$LLVM_SOURCE_DIR/build-shared | ||
|
|
||
| ENV PTO_SOURCE_DIR=$WORKSPACE_DIR/PTOAS | ||
| ENV PTO_INSTALL_DIR=$PTO_SOURCE_DIR/install | ||
|
|
||
| # build LLVM | ||
| WORKDIR $WORKSPACE_DIR | ||
| RUN git clone --depth 1 --branch ${LLVM_TAG} https://github.com/llvm/llvm-project.git | ||
|
|
||
| WORKDIR $LLVM_SOURCE_DIR | ||
| RUN cmake -G Ninja -S llvm -B $LLVM_BUILD_DIR \ | ||
| -DLLVM_ENABLE_PROJECTS="mlir;clang" \ | ||
| -DBUILD_SHARED_LIBS=ON \ | ||
| -DMLIR_ENABLE_BINDINGS_PYTHON=ON \ | ||
| -DPython3_EXECUTABLE=${PY_PATH}/bin/python \ | ||
| -DCMAKE_BUILD_TYPE=Release \ | ||
| -DLLVM_TARGETS_TO_BUILD="host" | ||
|
|
||
| RUN ninja -C $LLVM_BUILD_DIR | ||
|
|
||
| # build ptoas | ||
| WORKDIR $WORKSPACE_DIR | ||
| RUN git clone -b wheel https://github.com/learning-chip/PTOAS.git | ||
| # TODO: tag git commit of PTOAS repo | ||
|
|
||
| WORKDIR $PTO_SOURCE_DIR | ||
| RUN cmake -G Ninja \ | ||
| -S . \ | ||
| -B build \ | ||
| -DLLVM_DIR=$LLVM_BUILD_DIR/lib/cmake/llvm \ | ||
| -DMLIR_DIR=$LLVM_BUILD_DIR/lib/cmake/mlir \ | ||
| -DPython3_ROOT_DIR=${PY_PATH} \ | ||
| -DPython3_EXECUTABLE=${PY_PATH}/bin/python \ | ||
| -DPython3_FIND_STRATEGY=LOCATION \ | ||
| -Dpybind11_DIR=$(python -m pybind11 --cmakedir) \ | ||
| -DMLIR_PYTHON_PACKAGE_DIR=${LLVM_BUILD_DIR}/tools/mlir/python_packages/mlir_core \ | ||
| -DCMAKE_INSTALL_PREFIX=${PTO_INSTALL_DIR} | ||
|
|
||
| RUN ninja -C build && ninja -C build install | ||
|
|
||
| # test ptoas cli | ||
| ENV PATH=$PTO_SOURCE_DIR/build/tools/ptoas:$PATH | ||
| RUN which ptoas | ||
|
|
||
| # create python wheel | ||
| ENV PY_PACKAGE_DIR=$LLVM_BUILD_DIR/tools/mlir/python_packages/mlir_core/ | ||
|
|
||
| # copy pto.py, _pto_ops_gen.py | ||
| RUN cp $PTO_INSTALL_DIR/mlir/dialects/*.py $PY_PACKAGE_DIR/mlir/dialects/ | ||
|
|
||
| COPY ./setup.py $PY_PACKAGE_DIR/ | ||
|
|
||
| WORKDIR $PY_PACKAGE_DIR | ||
| RUN pip install --no-cache-dir setuptools wheel auditwheel | ||
| RUN python setup.py bdist_wheel | ||
|
|
||
| # fix missing so | ||
| RUN export LD_LIBRARY_PATH=$LLVM_BUILD_DIR/lib:$PTO_INSTALL_DIR/lib:$LD_LIBRARY_PATH \ | ||
| && auditwheel repair dist/ptoas*.whl | ||
|
|
||
| RUN pip install wheelhouse/ptoas*.whl | ||
|
|
||
| # test import without adjusting $PYTHONPATH and $LD_LIBRARY_PATH, in some irrelevant dir | ||
| WORKDIR /test | ||
| RUN python -c "import mlir.ir" | ||
| RUN python -c "from mlir.dialects import pto" | ||
|
|
||
| WORKDIR $PTO_SOURCE_DIR/test/samples/MatMul/ | ||
| RUN python ./tmatmulk.py > ./tmatmulk.pto | ||
| RUN ptoas ./tmatmulk.pto -o ./tmatmulk.cpp | ||
| # TODO: test compilation of the cpp file using `bisheng` | ||
| # TODO: also test `ptoas --enable-insert-sync` | ||
|
|
||
| # show the built wheel by default | ||
| WORKDIR $PY_PACKAGE_DIR/dist | ||
|
|
||
| CMD ["/bin/bash"] | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| Build: | ||
|
|
||
| ```bash | ||
| docker build . -t ptoas:py3.12 | ||
|
|
||
| # optional, to change python version | ||
| docker build . -t ptoas:py3.11 --build-arg PY_VER=cp311-cp311 | ||
| ``` | ||
|
|
||
| Use: | ||
|
|
||
| ```bash | ||
| docker run --rm -it ptoas:py3.12 /bin/bash | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| from setuptools import setup, find_namespace_packages | ||
|
|
||
| setup( | ||
| name="ptoas", | ||
| version="0.1.0", | ||
| description="PTO Assembler & Optimizer", | ||
| # NOTE: find_namespace_packages detects folders even without __init__.py | ||
| packages=find_namespace_packages(), | ||
| # NOTE: The * at the end captures .so.22, .so.22.1, etc. | ||
| package_data={ | ||
| "mlir": [ | ||
| "**/*.so*", | ||
| "**/*.pyd", | ||
| "**/*.py", | ||
| "_mlir_libs/*.so*", | ||
| ], | ||
| }, | ||
| include_package_data=True, | ||
| zip_safe=False, | ||
| python_requires=">=3.9", | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you do
auditwheel repair --plat manylinux_2_34_x86_64 dist/ptoas*.whl?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
next PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Opened PR here: https://github.com/zhangstevenunity/PTOAS/pull/2