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

Reorganize wheels #1646

Draft
wants to merge 10 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions .github/workflows/buildRyzenWheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,16 @@ jobs:
export XRT_ROOT=/opt/xilinx/xrt
export AIE_PROJECT_COMMIT=$(git rev-parse --short HEAD)
export DATETIME=$(date +"%Y%m%d%H")
export REQUIRED_LLVM_WHEEL_VERSION=$VERSION \

pushd utils/mlir_aie_wheels
pushd utils/packaging/mlir_aie_wheels

pip install wheel auditwheel patchelf importlib_metadata
CIBW_ARCHS=x86_64 pip wheel . -v -w $WHEELHOUSE_DIR --no-build-isolation
CIBW_ARCHS=x86_64 \
pip wheel . -v -w $WHEELHOUSE_DIR --no-build-isolation \
-f https://github.com/Xilinx/mlir-aie/releases/expanded_assets/mlir-distro/ \
-f https://github.com/makslevental/mlir-python-extras/releases/expanded_assets/0.0.6


popd

Expand Down Expand Up @@ -169,9 +174,9 @@ jobs:
export AIE_PROJECT_COMMIT=$(git rev-parse --short HEAD)
export DATETIME=$(date +"%Y%m%d%H")

cp python/requirements.txt utils/mlir_aie_wheels/python_bindings
cp python/requirements.txt utils/packaging/mlir_aie_wheels/python_bindings

pushd utils/mlir_aie_wheels/python_bindings
pushd utils/packaging/mlir_aie_wheels/python_bindings

pip install wheel auditwheel patchelf
CIBW_ARCHS=x86_64 pip wheel . -v -w $WHEELHOUSE_DIR --no-build-isolation
Expand Down
36 changes: 33 additions & 3 deletions .github/workflows/mlirAIEDistro.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,39 @@ jobs:
echo "AIE_PROJECT_COMMIT=${AIE_PROJECT_COMMIT}" | tee -a $GITHUB_OUTPUT
DATETIME=$(date +"%Y%m%d%H")
echo "DATETIME=${DATETIME}" | tee -a $GITHUB_OUTPUT

get_required_llvm_wheel_version:

build_distro_wheels:
name: Idenitfy which version of LLVM is required to build MLIR-AIE at the given commit

needs: get_aie_project_commit

runs-on: ubuntu-latest

outputs:
REQUIRED_LLVM_WHEEL_VERSION: ${{ steps.get_required_llvm_wheel_version.outputs.LLVM_VERSION }}

steps:
- name: Run `./utils/clone-llvm.sh --get-wheel-version`
id: get_required_llvm_wheel_version:
shell: bash
run: |
git clone --recursive https://github.com/${{ github.repository }}.git
pushd mlir-aie
git reset --hard ${{ needs.get_aie_project_commit.outputs.AIE_PROJECT_COMMIT }}
LLVM_VERSION=$(./utils/clone-llvm.sh --get-wheel-version)
if [[ ! $LLVM_VERSION ]]; then
echo "::error::Unable to determine required LLVM version at commit " ${{ needs.get_aie_project_commit.outputs.AIE_PROJECT_COMMIT }}
fi
echo "LLVM_VERSION=${LLVM_VERSION}" >> $GITHUB_OUTPUT
popd

build_distro_wheels:

needs:
- get_aie_project_commit
- get_required_llvm_wheel_version

name: ${{ matrix.OS }} ${{ matrix.ARCH }} rtti=${{ matrix.ENABLE_RTTI }}

continue-on-error: true
Expand Down Expand Up @@ -175,9 +203,9 @@ jobs:
ls "${{ steps.setup_base.outputs.WORKSPACE_ROOT }}"

if [ x"${{ matrix.OS }}" == x"windows-2019" ]; then
WORKSPACE_ROOT="${{ steps.setup_base.outputs.WORKSPACE_ROOT }}\utils\mlir_aie_wheels"
WORKSPACE_ROOT="${{ steps.setup_base.outputs.WORKSPACE_ROOT }}\utils\packaging\mlir_aie_wheels"
else
WORKSPACE_ROOT="${{ steps.setup_base.outputs.WORKSPACE_ROOT }}/utils/mlir_aie_wheels"
WORKSPACE_ROOT="${{ steps.setup_base.outputs.WORKSPACE_ROOT }}/utils/packaging/mlir_aie_wheels"
fi

echo "WORKSPACE_ROOT=$WORKSPACE_ROOT" | tee -a $GITHUB_OUTPUT
Expand Down Expand Up @@ -209,6 +237,7 @@ jobs:
DATETIME=${{ needs.get_aie_project_commit.outputs.DATETIME }} \
HOST_CCACHE_DIR=${{ steps.setup_ccache.outputs.HOST_CCACHE_DIR }} \
AIE_PROJECT_COMMIT=${{ needs.get_aie_project_commit.outputs.AIE_PROJECT_COMMIT }} \
REQUIRED_LLVM_WHEEL_VERSION=${{ needs.get_required_llvm_wheel_version.outputs.REQUIRED_LLVM_WHEEL_VERSION }} \
MATRIX_OS=${{ matrix.OS }} \
PARALLEL_LEVEL=2 \
cibuildwheel --output-dir wheelhouse
Expand All @@ -233,6 +262,7 @@ jobs:
CMAKE_GENERATOR=Ninja \
DATETIME=${{ needs.get_aie_project_commit.outputs.DATETIME }} \
AIE_PROJECT_COMMIT=${{ needs.get_aie_project_commit.outputs.AIE_PROJECT_COMMIT }} \
REQUIRED_LLVM_WHEEL_VERSION=${{ needs.get_required_llvm_wheel_version.outputs.REQUIRED_LLVM_WHEEL_VERSION }} \
MATRIX_OS=${{ matrix.OS }} \
PARALLEL_LEVEL=2 \
pip wheel . -v -w wheelhouse
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/mlirDistro.yml
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ jobs:
EXTRA_KEY: mlir-distro-enable-rtti-${{ matrix.ENABLE_RTTI }}

# default workspace is repo root but we're not build mlir-aie here, we're building llvm+mlir
# and thus llvm-project needs to be adjacent to utils/mlir_wheels/setup.py
# and thus llvm-project needs to be adjacent to utils/packaging/mlir_wheels/setup.py
- name: Shift workspace root
id: workspace_root
shell: bash
Expand All @@ -185,9 +185,9 @@ jobs:
ls "${{ steps.setup_base.outputs.WORKSPACE_ROOT }}"

if [ x"${{ matrix.OS }}" == x"windows-2019" ]; then
WORKSPACE_ROOT="${{ steps.setup_base.outputs.WORKSPACE_ROOT }}\utils\mlir_wheels"
WORKSPACE_ROOT="${{ steps.setup_base.outputs.WORKSPACE_ROOT }}\utils\packaging\mlir_wheels"
else
WORKSPACE_ROOT="${{ steps.setup_base.outputs.WORKSPACE_ROOT }}/utils/mlir_wheels"
WORKSPACE_ROOT="${{ steps.setup_base.outputs.WORKSPACE_ROOT }}/utils/packaging/mlir_wheels"
fi

echo "WORKSPACE_ROOT=$WORKSPACE_ROOT" | tee -a $GITHUB_OUTPUT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ environment-pass = [
"DATETIME",
"HOST_CCACHE_DIR",
"AIE_PROJECT_COMMIT",
"REQUIRED_LLVM_WHEEL_VERSION",
"MATRIX_OS",
"PARALLEL_LEVEL",
"PIP_FIND_LINKS",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,28 @@
import shutil
import subprocess
import sys
import site
import pdb
import glob
import shutil
from datetime import datetime
from pathlib import Path
from pprint import pprint
from textwrap import dedent
from typing import Union

from importlib_metadata import files
from setuptools import Extension, setup
import setuptools
from setuptools.command.build_ext import build_ext
from setuptools.command.install_scripts import install_scripts, log
from setuptools.command.easy_install import chmod, current_umask


def check_env(build, default=0):
return os.getenv(build, str(default)) in {"1", "true", "True", "ON", "YES"}
# --------------------------------------------------------------------------
# Utilities


class CMakeExtension(Extension):
def __init__(self, name: str, sourcedir: Union[str, Path] = "") -> None:
super().__init__(name, sources=[])
self.sourcedir = os.fspath(Path(sourcedir).resolve())
def check_env(build, default=0):
return os.getenv(build, str(default)).lower() in {"1", "true", "true", "on", "yes"}


def get_exe_suffix():
Expand All @@ -33,6 +36,100 @@ def get_exe_suffix():
return suffix


# --------------------------------------------------------------------------
# InstallBin command -- overwrites "install_scripts" stage of "install" cmd
# Copy files into the <packagename>.data/data/scripts directory.
# The wheel package format prescribes that files in <packagename>.data/scripts be added to the PATH on install.
# So whatever is added here will end up in the virtualenv's bin directory upon install.
class InstallBin(install_scripts):

# The subdirectory of the wheel directory in which binaries can be found.
# Everything globbed from this directory will be copied into an executable path.
built_bin_dir = "bin"

# The subdirectory of the wheel in which the Python modules can be found.
# This will be copied into an import-able path.
built_python_modules_dir = "python"

def run(self):
# Copy the built binaries back into the source directory.
# This is needed so that the setup(data_files = [(scripts, ...)]) argument below can
# pick them up.

# Not a super clean way of doing this, but:
# 1. `build_ext`` will call CMake to build mlir_aie in <temp_build_dir>/lib.linux-x86_64.../mlir_aie
# 2. then, `install_lib`` will copy everything in there to <wheelhouse>/mlir_aie
# 3. then, this runs -- `install_scripts`, and it will be configured with self.install_dir == <wheelhouse>/<pkgname>.data/scripts
# therefore, we can get our hands on the binaries moved into the wheelhouse root by looking at the grandparent dir
bin_install_dir = Path(self.install_dir)
wheel_root = bin_install_dir.parent.parent.resolve()
python_module_install_dir = wheel_root

built_bin_dir = wheel_root / InstallBin.built_bin_dir
built_python_modules_dir = wheel_root / InstallBin.built_python_modules_dir

if not bin_install_dir.exists():
bin_install_dir.mkdir(parents=True)

mask = current_umask()
for bin in built_bin_dir.glob("*"):
dest = str(bin_install_dir / bin.name)
log.info(f"Copying binary {bin} -> {dest}")
shutil.copyfile(bin, dest)
# The pip wheel installer will only copy files marked executable into the bin dir
chmod(dest, 0o777 - mask)

if not python_module_install_dir.exists():
python_module_install_dir.mkdir(parents=True)

for mod in built_python_modules_dir.glob("*"):
dest = str(python_module_install_dir / mod.name)
log.info(f"Copying Python file {mod} -> {dest}")
if mod.is_dir():
shutil.copytree(mod, dest)
else:
shutil.copyfile(mod, dest)


# --------------------------------------------------------------------------
# Configuration environment variables

commit_hash = os.environ.get("AIE_PROJECT_COMMIT", "deadbeef")
release_version = "0.0.1"
now = datetime.now()
datetime = os.environ.get(
"DATETIME", f"{now.year}{now.month:02}{now.day:02}{now.hour:02}"
)
version = f"{release_version}.{datetime}+{commit_hash}"

MLIR_AIE_SOURCE_DIR = Path(
os.getenv(
"MLIR_AIE_SOURCE_DIR",
Path(__file__).parent / "mlir-aie",
)
).absolute()

REQUIRED_LLVM_WHEEL_VERSION = os.environ["REQUIRED_LLVM_WHEEL_VERSION"]
mlir_prereq = "mlir" if check_env("ENABLE_RTTI", 1) else "mlir-no-rtti"

# A wheel containing precompiled LLVM and MLIR should be installed before running this script, using
# pip install --user mlir
# You can also use the MLIR_INSTALL_ABS_PATH environment variable to specify where it should be found.
default_mlir_install_path = Path(site.getsitepackages()[0]) / mlir_prereq
env_mlir_install_path = os.getenv("MLIR_INSTALL_ABS_PATH", default_mlir_install_path)
MLIR_INSTALL_ABS_PATH = Path(env_mlir_install_path).absolute()


# --------------------------------------------------------------------------
# CMake Build Extension for setuptools build process


class CMakeExtension(setuptools.Extension):
def __init__(self, name: str, sourcedir: Union[str, Path] = "") -> None:
super().__init__(name, sources=[])
self.sourcedir = os.fspath(Path(sourcedir).resolve())


def get_cross_cmake_args():
cmake_args = {}

Expand Down Expand Up @@ -98,8 +195,19 @@ def native_tools():
return cmake_args


# --------------------------------------------------------------------------
# CMakeBuild command - overwrites "build_ext" stage of "build" command


class CMakeBuild(build_ext):
def build_extension(self, ext: CMakeExtension) -> None:
global MLIR_INSTALL_ABS_PATH, env_mlir_install_path, default_mlir_install_path

if not os.path.isdir(MLIR_INSTALL_ABS_PATH):
raise RuntimeError(
f"Could not find required LLVM/MLIR build prerequisite. Looked in `{env_mlir_install_path}` and `{default_mlir_install_path}`."
)

ext_fullpath = Path.cwd() / self.get_ext_fullpath(ext.name)
extdir = ext_fullpath.parent.resolve()
install_dir = extdir / (
Expand All @@ -109,14 +217,6 @@ def build_extension(self, ext: CMakeExtension) -> None:

cmake_generator = os.getenv("CMAKE_GENERATOR", "Ninja")

MLIR_INSTALL_ABS_PATH = Path(
os.getenv(
"MLIR_INSTALL_ABS_PATH",
Path(__file__).parent
/ ("mlir" if check_env("ENABLE_RTTI", 1) else "mlir_no_rtti"),
)
).absolute()

if platform.system() == "Windows":
# fatal error LNK1170: line in command file contains 131071 or more characters
if not Path("/tmp/m").exists():
Expand Down Expand Up @@ -231,22 +331,13 @@ def build_extension(self, ext: CMakeExtension) -> None:
)


commit_hash = os.environ.get("AIE_PROJECT_COMMIT", "deadbeef")
release_version = "0.0.1"
now = datetime.now()
datetime = os.environ.get(
"DATETIME", f"{now.year}{now.month:02}{now.day:02}{now.hour:02}"
)
version = f"{release_version}.{datetime}+{commit_hash}"
# --------------------------------------------------------------------------
# Setuptools package configuration

MLIR_AIE_SOURCE_DIR = Path(
os.getenv(
"MLIR_AIE_SOURCE_DIR",
Path(__file__).parent / "mlir-aie",
)
).absolute()
InstallBin.built_bin_dir = Path("mlir_aie") / "bin"
InstallBin.built_python_modules_dir = Path("mlir_aie") / "python"

setup(
setuptools.setup(
version=version,
author="",
name="mlir-aie" if check_env("ENABLE_RTTI", 1) else "mlir-aie-no-rtti",
Expand All @@ -264,10 +355,41 @@ def build_extension(self, ext: CMakeExtension) -> None:
"""
),
long_description_content_type="text/markdown",
# cmdclass overwrites/defines the Command objects that will be created and called for the named commands as part of the wheel build.
# We overwrite "build_ext" to customize our CMake build, and "install_scripts" to be able to copy our binaries to the bin directory in the PATH.
cmdclass={"build_ext": CMakeBuild, "install_scripts": InstallBin},
# note the name here isn't relevant because it's the install (CMake install target) directory that'll be used to
# actually build the wheel.
ext_modules=[CMakeExtension("_mlir_aie", sourcedir=MLIR_AIE_SOURCE_DIR)],
cmdclass={"build_ext": CMakeBuild},
zip_safe=False,
python_requires=">=3.8",
setup_requires=[
f"{mlir_prereq}=={REQUIRED_LLVM_WHEEL_VERSION}"
# @ https://github.com/Xilinx/mlir-aie/releases/expanded_assets/latest-wheels/",
],
install_requires=[
f"{mlir_prereq}=={REQUIRED_LLVM_WHEEL_VERSION}",
# @ https://github.com/Xilinx/mlir-aie/releases/expanded_assets/latest-wheels/"
"mlir-python-utils",
# @ https://github.com/makslevental/mlir-python-extras/releases/expanded_assets/0.0.6
#PyYAML>=5.3.1, <=6.0.1,
"aiofiles",
#cmake==3.27.9,
#dataclasses>=0.6, <=0.8
#filelock==3.13.1
#lit
"numpy>=1.19.5,<=1.26",
#pandas
#psutil
"pybind11>=2.9.0,<=2.10.3",
"rich",
#setuptools
#wheel
],
extras_require={
"peano": [
"llvm-aie @ https://github.com/Xilinx/llvm-aie/releases/expanded_assets/nightly"
# TODO: Might want to set a fixed a version for llvm-aie here
]
},
)
File renamed without changes.
Loading
Loading