diff --git a/.github/workflows/amd-aie-clean-nightly-releases.yml b/.github/workflows/amd-aie-clean-nightly-releases.yml new file mode 100644 index 000000000000..d730f3ee66d8 --- /dev/null +++ b/.github/workflows/amd-aie-clean-nightly-releases.yml @@ -0,0 +1,35 @@ +name: AMD AIE Clean up old releases + +on: + workflow_dispatch: + branches: + - main + schedule: + # At minute 0 past hour 6. (see https://crontab.guru) + - cron: '00 06 * * *' + +jobs: + + delete_releases: + + runs-on: ubuntu-latest + + permissions: + id-token: write + contents: write + + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Setup Python + uses: actions/setup-python@v4 + with: + python-version: "3.10" + + - name: Delete from here + shell: bash + run: | + + pip install PyGithub + GITHUB_TOKEN=${{ secrets.DELETE_RELEASES_TOKEN }} python scripts/gh_releases.py diff --git a/.github/workflows/amd-aie-distro.yml b/.github/workflows/amd-aie-distro.yml new file mode 100644 index 000000000000..217becd09080 --- /dev/null +++ b/.github/workflows/amd-aie-distro.yml @@ -0,0 +1,342 @@ +name: AMD AIE Distro + +on: + workflow_dispatch: + inputs: + DEBUG_ENABLED: + description: 'Run the build with tmate debugging enabled (https://github.com/marketplace/actions/debugging-with-tmate)' + type: boolean + required: false + default: false + DEBUG_OS: + description: 'which runner os to run the tmate action in (if the tmate action is run)' + type: string + default: 'windows-2019' + required: false + DEBUG_ARCH: + description: 'which runner arch to run the tmate action in (if the tmate action is run)' + type: string + default: 'x86_64' + required: false + DEBUG_DETACHED: + description: 'whether to launch tmate in detached mode (if the tmate action is run)' + type: boolean + required: false + default: true + LLVM_AIE_COMMIT: + description: 'llvm-aie commit to build' + type: string + required: false + default: '' + APPLY_PATCHES: + description: 'whether to apply patches to source' + type: string + required: false + default: 'true' + RUN_TESTS: + description: 'whether to run llvm tests after build' + type: string + required: false + default: 'false' + + pull_request: + release: + types: + - published + + schedule: + # At minute 0 past hour 1. (see https://crontab.guru) + # this is the actual nightly + - cron: '00 01 * * *' + # At minute 0 past every 4th hour. (see https://crontab.guru) + # this job is to keep the ccache cache warm + - cron: '0 */4 * * *' + +jobs: + + get_llvm_aie_project_commit: + + name: Get latest LLVM-AIE commit + + runs-on: ubuntu-latest + + outputs: + LLVM_AIE_PROJECT_COMMIT: ${{ steps.get_llvm_aie_project_commit.outputs.LLVM_AIE_PROJECT_COMMIT }} + DATETIME: ${{ steps.get_llvm_aie_project_commit.outputs.DATETIME }} + + steps: + # have to do this until repo is public + - name: Checkout actions + uses: actions/checkout@v3 + with: + ref: ${{ github.head_ref || github.ref_name }} + # check out anything + sparse-checkout: .github/workflows/amd_aie_releases + sparse-checkout-cone-mode: false + + - name: Get llvm-aie commit + id: get_llvm_aie_project_commit + run: | + + if [ x"${{ inputs.LLVM_AIE_COMMIT }}" == x"" ]; then + LLVM_AIE_PROJECT_COMMIT=$(git rev-parse ${{ github.head_ref || github.ref_name }}) + LLVM_AIE_PROJECT_COMMIT=${LLVM_AIE_PROJECT_COMMIT:0:8} + else + LLVM_AIE_PROJECT_COMMIT="${{ inputs.LLVM_AIE_COMMIT }}" + fi + echo "LLVM_AIE_PROJECT_COMMIT=${LLVM_AIE_PROJECT_COMMIT}" | tee -a $GITHUB_OUTPUT + DATETIME=$(date +"%Y%m%d%H") + echo "DATETIME=${DATETIME}" | tee -a $GITHUB_OUTPUT + + build: + + needs: get_llvm_aie_project_commit + + name: ${{ matrix.OS }} ${{ matrix.ARCH }} + + continue-on-error: true + + runs-on: ${{ matrix.OS }} + + outputs: + LLVM_AIE_WHEEL_VERSION: ${{ steps.get_wheel_version.outputs.LLVM_AIE_WHEEL_VERSION }} + + strategy: + fail-fast: false + matrix: + include: + - OS: ubuntu-20.04 + ARCH: x86_64 + + - OS: ubuntu-20.04 + ARCH: aarch64 + + - OS: windows-2019 + ARCH: AMD64 + + - OS: macos-12 + ARCH: x86_64 + + - OS: macos-12 + ARCH: arm64 + + defaults: + run: + shell: bash + + steps: + + - uses: makslevental/mlir-wheels/actions/setup_base@54495f0f8fea29747d85daad4da0f815d8b3d5a4 + id: setup_base + with: + # optional + DEBUG_ENABLED: ${{ inputs.DEBUG_ENABLED }} + DEBUG_OS: ${{ inputs.DEBUG_OS }} + DEBUG_ARCH: ${{ inputs.DEBUG_ARCH }} + DEBUG_DETACHED: ${{ inputs.DEBUG_DETACHED }} + # required + MATRIX_OS: ${{ matrix.OS }} + MATRIX_ARCH: ${{ matrix.ARCH }} + + - uses: makslevental/mlir-wheels/actions/setup_ccache@54495f0f8fea29747d85daad4da0f815d8b3d5a4 + id: setup_ccache + with: + MATRIX_OS: ${{ matrix.OS }} + MATRIX_ARCH: ${{ matrix.ARCH }} + WORKSPACE_ROOT: ${{ steps.setup_base.outputs.WORKSPACE_ROOT }} + + - name: Checkout actions + uses: actions/checkout@v3 + with: + sparse-checkout: .github/workflows/amd_aie_releases + # Turning off cone mode ensures that files in the project root are not included during checkout + sparse-checkout-cone-mode: false + + # This step is needed because action/checkout does not support paths. + - name: Move release utils app to workspace_root + run: | + + shopt -s dotglob + + WORKSPACE_ROOT="${{ steps.setup_base.outputs.WORKSPACE_ROOT }}" + if [[ ${{ matrix.OS }} == *"windows"* ]]; then + WORKSPACE_ROOT=$(echo "/$WORKSPACE_ROOT" | sed -e 's/\\/\//g' -e 's/://') + fi + + ls -lah + mv .github/workflows/amd_aie_releases/* "$WORKSPACE_ROOT" + ls -lah "$WORKSPACE_ROOT" + + - name: Get LLVM-AIE + working-directory: ${{ steps.setup_base.outputs.WORKSPACE_ROOT }} + run: | + + curl -s https://codeload.github.com/Xilinx/llvm-aie/zip/${{ needs.get_llvm_aie_project_commit.outputs.LLVM_AIE_PROJECT_COMMIT }} -o llvm-aie.zip + unzip -q llvm-aie.zip + rm -rf llvm-aie.zip + LLVM_AIE_PROJECT_COMMIT=${{ needs.get_llvm_aie_project_commit.outputs.LLVM_AIE_PROJECT_COMMIT }} + mv llvm-aie-$LLVM_AIE_PROJECT_COMMIT llvm-aie + + # build + + - name: cibuildwheel + # you need the parens here because of the != and something about yaml??? + if: (!contains(matrix.OS, 'ubuntu') || matrix.ARCH != 'aarch64') + working-directory: ${{ steps.setup_base.outputs.WORKSPACE_ROOT }} + run: | + + APPLY_PATCHES=${{ inputs.APPLY_PATCHES == '' && 'true' || inputs.APPLY_PATCHES }} \ + RUN_TESTS=${{ inputs.RUN_TESTS == '' && 'false' || inputs.RUN_TESTS }} \ + CIBW_ARCHS=${{ matrix.ARCH }} \ + CMAKE_GENERATOR=Ninja \ + DATETIME=${{ needs.get_llvm_aie_project_commit.outputs.DATETIME }} \ + HOST_CCACHE_DIR=${{ steps.setup_ccache.outputs.HOST_CCACHE_DIR }} \ + LLVM_AIE_PROJECT_COMMIT=${{ needs.get_llvm_aie_project_commit.outputs.LLVM_AIE_PROJECT_COMMIT }} \ + MATRIX_OS=${{ matrix.OS }} \ + PARALLEL_LEVEL=2 \ + cibuildwheel --output-dir wheelhouse + + - name: build aarch ubuntu wheel + if: contains(matrix.OS, 'ubuntu') && matrix.ARCH == 'aarch64' + working-directory: ${{ steps.setup_base.outputs.WORKSPACE_ROOT }} + run: | + + export APPLY_PATCHES=${{ inputs.APPLY_PATCHES == '' && 'true' || inputs.APPLY_PATCHES }} + ./scripts/apply_patches.sh + + CIBW_ARCHS=${{ matrix.ARCH }} \ + CMAKE_GENERATOR=Ninja \ + DATETIME=${{ needs.get_llvm_aie_project_commit.outputs.DATETIME }} \ + LLVM_AIE_PROJECT_COMMIT=${{ needs.get_llvm_aie_project_commit.outputs.LLVM_AIE_PROJECT_COMMIT }} \ + MATRIX_OS=${{ matrix.OS }} \ + PARALLEL_LEVEL=2 \ + PIP_FIND_LINKS="https://github.com/makslevental/llvm-aie-wheels/releases/expanded_assets/latest" \ + pip wheel . -v -w wheelhouse + + - name: Download cache from container ubuntu + if: contains(matrix.OS, 'ubuntu') && contains(matrix.ARCH, 'x86_64') && (success() || failure()) + working-directory: ${{ steps.setup_base.outputs.WORKSPACE_ROOT }} + run: | + + ccache -s + HOST_CCACHE_DIR="$(ccache --get-config cache_dir)" + rm -rf $HOST_CCACHE_DIR + mv ./wheelhouse/.ccache $HOST_CCACHE_DIR + ls -la $HOST_CCACHE_DIR + ccache -s + + - name: Reset datetime ccache + working-directory: ${{ steps.setup_base.outputs.WORKSPACE_ROOT }} + run: | + + ccache --print-stats + HOST_CCACHE_DIR="$(ccache --get-config cache_dir)" + find $HOST_CCACHE_DIR -exec touch -a -m -t "${{ needs.get_llvm_aie_project_commit.outputs.DATETIME }}00" {} \; + + - name: Clean llvm-aie + working-directory: ${{ steps.setup_base.outputs.WORKSPACE_ROOT }} + run: | + + rm -rf llvm-aie + rm -rf build + + - name: Docker prune + if: contains(matrix.OS, 'ubuntu') + run: | + docker system prune -a -f + + - name: Get wheel version + id: get_wheel_version + working-directory: ${{ steps.setup_base.outputs.WORKSPACE_ROOT }} + run: | + pip install pkginfo + WHL=$(ls wheelhouse/llvm-aie-*whl) + echo "LLVM_AIE_WHEEL_VERSION=$(python -c "import pkginfo; w = pkginfo.Wheel('$WHL'); print(w.version.split('+')[0] + '+' + w.version.split('+')[1].rsplit('.', 1)[-1])")" | tee -a $GITHUB_OUTPUT + + - name: rename non-windows + if: contains(matrix.OS, 'ubuntu') || contains(matrix.OS, 'macos') + working-directory: ${{ steps.setup_base.outputs.WORKSPACE_ROOT }} + run: | + + rename 's/cp310-cp310/py3-none/' wheelhouse/llvm-aie-*whl + rename 's/cp311-cp311/py3-none/' wheelhouse/llvm-aie-*whl + + if [[ ${{ matrix.OS }} == *"ubuntu"* ]] && [ x"${{ matrix.ARCH }}" == x"aarch64" ]; then + rename 's/x86_64/aarch64/' wheelhouse/llvm-aie-*whl + fi + + - name: rename windows + if: contains(matrix.OS, 'windows') + working-directory: ${{ steps.setup_base.outputs.WORKSPACE_ROOT }} + run: | + ls wheelhouse/llvm-aie-*whl | Rename-Item -NewName {$_ -replace 'cp310-cp310', 'py3-none' } + ls wheelhouse/llvm-aie-*whl | Rename-Item -NewName {$_ -replace 'cp311-cp311', 'py3-none' } + + - name: Build native_tools wheel + working-directory: ${{ steps.setup_base.outputs.WORKSPACE_ROOT }} + id: build_native_tools_wheel + run: | + + for TOOL in "llvm-tblgen" "llvm-aie-tblgen" "llvm-aie-linalg-ods-yaml-gen" "llvm-aie-pdll" "llvm-config" "FileCheck"; do + if [[ ${{ matrix.OS }} == *"windows"* ]]; then + TOOL="$TOOL.exe" + fi + unzip -j wheelhouse/llvm-aie-*whl "llvm_aie/bin/$TOOL" -d native_tools/ + done + + if [[ ${{ matrix.OS }} == *"ubuntu"* ]]; then + PLAT="linux" + elif [[ ${{ matrix.OS }} == *"macos"* ]]; then + PLAT="macosx_12_0" + elif [[ ${{ matrix.OS }} == *"windows"* ]]; then + PLAT="win" + fi + + PLAT=${PLAT}_$(echo ${{ matrix.ARCH }} | tr '[:upper:]' '[:lower:]') + pushd native_tools + + LLVM_AIE_WHEEL_VERSION=${{ steps.get_wheel_version.outputs.LLVM_AIE_WHEEL_VERSION }} \ + python setup.py bdist_wheel --dist-dir ../wheelhouse --plat $PLAT + + popd + + # done + + - name: Upload wheels + if: success() || failure() + uses: actions/upload-artifact@v3 + with: + path: ${{ steps.setup_base.outputs.WORKSPACE_ROOT }}/wheelhouse/*.whl + name: build_artifact + + upload_distro_wheels: + + if: github.event.schedule != '0 */4 * * *' + + needs: build + + runs-on: ubuntu-latest + + permissions: + id-token: write + contents: write + + steps: + - uses: actions/download-artifact@v3 + with: + # unpacks default artifact into dist/ + # if `name: artifact` is omitted, the action will create extra parent dir + name: build_artifact + path: dist + + - name: Release current commit + uses: ncipollo/release-action@v1.12.0 + with: + artifacts: "dist/*.whl,dist/*.tar.xz" + token: "${{ secrets.GITHUB_TOKEN }}" + tag: "nightly" + name: "nightly" + removeArtifacts: false + allowUpdates: true + replacesArtifacts: true + makeLatest: true diff --git a/.github/workflows/amd_aie_releases/native_tools/setup.py b/.github/workflows/amd_aie_releases/native_tools/setup.py new file mode 100644 index 000000000000..3370bf691880 --- /dev/null +++ b/.github/workflows/amd_aie_releases/native_tools/setup.py @@ -0,0 +1,36 @@ +# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +# See https://llvm.org/LICENSE.txt for license information. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +import os +import platform + +from setuptools import setup + + +def get_exe_suffix(): + if platform.system() == "Windows": + suffix = ".exe" + else: + suffix = "" + return suffix + + +version = os.environ.get("LLVM_AIE_WHEEL_VERSION", "0.0.0+DEADBEEF") + +data_files = [] +for bin in [ + "llvm-tblgen", + "mlir-tblgen", + "mlir-linalg-ods-yaml-gen", + "mlir-pdll", + "llvm-config", + "FileCheck", +]: + data_files.append(bin + get_exe_suffix()) + +setup( + version=version, + name="llvm-aie-native-tools", + include_package_data=True, + data_files=[("bin", data_files)], +) diff --git a/.github/workflows/amd_aie_releases/patches/mscv.patch b/.github/workflows/amd_aie_releases/patches/mscv.patch new file mode 100644 index 000000000000..7c3833945f4c --- /dev/null +++ b/.github/workflows/amd_aie_releases/patches/mscv.patch @@ -0,0 +1,15 @@ +diff --git a/cmake/Modules/CMakePolicy.cmake b/cmake/Modules/CMakePolicy.cmake +index 1c18c1810dae..a13f4ad1fcb2 100644 +--- a/cmake/Modules/CMakePolicy.cmake ++++ b/cmake/Modules/CMakePolicy.cmake +@@ -11,6 +11,10 @@ if(POLICY CMP0116) + cmake_policy(SET CMP0116 OLD) + endif() + ++if(POLICY CMP0091) ++ cmake_policy(SET CMP0091 NEW) ++endif() ++ + # MSVC debug information format flags are selected via + # CMAKE_MSVC_DEBUG_INFORMATION_FORMAT, instead of + # embedding flags in e.g. CMAKE_CXX_FLAGS_RELEASE. diff --git a/.github/workflows/amd_aie_releases/pyproject.toml b/.github/workflows/amd_aie_releases/pyproject.toml new file mode 100644 index 000000000000..0071a51da38a --- /dev/null +++ b/.github/workflows/amd_aie_releases/pyproject.toml @@ -0,0 +1,62 @@ +[build-system] +requires = [ + "setuptools>=42", + "wheel", + "ninja", + "cmake>=3.12", + "pybind11[global]>=2.10.4", + "numpy", + "dataclasses", + "aie-native-tools", + "PyYAML", +] +build-backend = "setuptools.build_meta" + +[tool.cibuildwheel] +build-verbosity = 3 +build = "cp310-*" +skip = ["*-manylinux_i686", "*-musllinux*"] +manylinux-aarch64-image = "manylinux_2_28" +manylinux-x86_64-image = "manylinux_2_28" + +[tool.cibuildwheel.linux] +environment = { PATH = "/usr/lib/ccache:/usr/lib64/ccache:/usr/lib/ccache/bin:$PATH", PIP_FIND_LINKS = "https://github.com/Xilinx/llvm-aie/releases/expanded_assets/nightly" } +before-build = [ + "{project}/scripts/docker_prepare_ccache.sh", + "{project}/scripts/apply_patches.sh", +] +before-test = "ccache --show-stats" +environment-pass = [ + "APPLY_PATCHES", + "CIBW_ARCHS", + "CMAKE_ARGS", + "CMAKE_GENERATOR", + "DATETIME", + "HOST_CCACHE_DIR", + "LLVM_AIE_PROJECT_COMMIT", + "MATRIX_OS", + "PARALLEL_LEVEL", + "PIP_FIND_LINKS", + "PIP_NO_BUILD_ISOLATION", + "RUN_TESTS", + "MLIR_LIT_PYTHONPATH", +] +repair-wheel-command = [ + "auditwheel repair -w {dest_dir} {wheel}" +] + +[tool.cibuildwheel.macos] +environment = { PATH = "/usr/local/opt/ccache/libexec:$PATH", PIP_FIND_LINKS = "https://github.com/Xilinx/llvm-aie/releases/expanded_assets/nightly" } +before-build = [ + "{project}/scripts/apply_patches.sh", +] +repair-wheel-command = [ + "delocate-wheel --require-archs {delocate_archs} -w {dest_dir} -v {wheel} --ignore-missing-dependencies" +] + +[tool.cibuildwheel.windows] +environment = { PIP_FIND_LINKS = "https://github.com/Xilinx/llvm-aie/releases/expanded_assets/nightly" } +before-build = [ + "pip install delvewheel", + "bash {project}\\scripts\\apply_patches.sh", +] diff --git a/.github/workflows/amd_aie_releases/scripts/apply_patches.sh b/.github/workflows/amd_aie_releases/scripts/apply_patches.sh new file mode 100755 index 000000000000..436c4b6e68dd --- /dev/null +++ b/.github/workflows/amd_aie_releases/scripts/apply_patches.sh @@ -0,0 +1,22 @@ +#!/usr/bin/env bash +set -uxo pipefail + +# note that space before slash is important +PATCHES="\ +mscv \ +" + +if [[ x"${APPLY_PATCHES:-true}" == x"true" ]]; then + for PATCH in $PATCHES; do + echo "applying $PATCH" + git apply --quiet --ignore-space-change --ignore-whitespace --directory llvm-aie patches/$PATCH.patch + ERROR=$? + if [ $ERROR != 0 ]; then + git apply --ignore-space-change --ignore-whitespace --verbose --directory llvm-aie patches/$PATCH.patch -R --check + ERROR=$? + if [ $ERROR != 0 ]; then + exit $ERROR + fi + fi + done +fi diff --git a/.github/workflows/amd_aie_releases/scripts/build_local.sh b/.github/workflows/amd_aie_releases/scripts/build_local.sh new file mode 100755 index 000000000000..7c60419df9d9 --- /dev/null +++ b/.github/workflows/amd_aie_releases/scripts/build_local.sh @@ -0,0 +1,77 @@ +#!/usr/bin/env bash +set -xe +HERE=$(dirname "$(realpath "$0")") + +unameOut="$(uname -s)" +case "${unameOut}" in + Linux*) machine=linux;; + Darwin*) machine=macos;; + CYGWIN*) machine=windows;; + MINGW*) machine=windows;; + MSYS_NT*) machine=windows;; + *) machine="UNKNOWN:${unameOut}" +esac +echo "${machine}" + +# rsync -avpP --exclude .git --exclude cmake-build-debug --exclude cmake-build-release ../../llvm/* llvm-aie/ + +export APPLY_PATCHES=true + +if [ "$machine" == "linux" ]; then + export MATRIX_OS=ubuntu-20.04 + export CIBW_ARCHS=x86_64 + export CIBW_BUILD=cp311-manylinux_x86_64 + export ARCH=x86_64 + export PARALLEL_LEVEL=15 +elif [ "$machine" == "macos" ]; then + export MATRIX_OS=macos-12 + export CIBW_ARCHS=arm64 + export CIBW_BUILD=cp311-macosx_arm64 + export ARCH=arm64 + export PARALLEL_LEVEL=32 +else + export MATRIX_OS=windows-2019 + export CIBW_ARCHS=AMD64 + export CIBW_BUILD=cp311-win_amd64 + export ARCH=AMD64 +fi + +ccache --show-stats +ccache --print-stats +ccache --show-config + +export HOST_CCACHE_DIR="$(ccache --get-config cache_dir)" +cibuildwheel "$HERE"/.. --platform "$machine" + +rename 's/cp311-cp311/py3-none/' "$HERE/../wheelhouse/"llvm-aie-*whl + +if [ -d "$HERE/../wheelhouse/.ccache" ]; then + cp -R "$HERE/../wheelhouse/.ccache/"* "$HOST_CCACHE_DIR/" +fi + +for TOOL in "llvm-tblgen" "mlir-tblgen" "mlir-linalg-ods-yaml-gen" "mlir-pdll" "llvm-config" "FileCheck"; do + if [ x"$MATRIX_OS" == x"windows-2019" ]; then + TOOL="$TOOL.exe" + fi + unzip -j "$HERE/../wheelhouse/"llvm-aie-*whl "mlir/bin/$TOOL" -d "$HERE/../native_tools/" +done + +if [ x"$MATRIX_OS" == x"ubuntu-20.04" ]; then + PLAT="manylinux_2_17" +elif [ x"$MATRIX_OS" == x"macos-12" ]; then + PLAT="macosx_12_0" +elif [ x"$MATRIX_OS" == x"windows-2019" ]; then + PLAT="win" +fi + +PLAT=${PLAT}_$(echo $ARCH | tr '[:upper:]' '[:lower:]') +pushd "$HERE/../native_tools" +python setup.py bdist_wheel --dist-dir ../wheelhouse --plat "$PLAT" +popd + +cp -R "$HERE/../scripts" "$HERE/../python_bindings" +cp -R "$HERE/../wheelhouse" "$HERE/../python_bindings" + +pushd "$HERE/../python_bindings" + +cibuildwheel --platform "$machine" --output-dir ../wheelhouse diff --git a/.github/workflows/amd_aie_releases/scripts/docker_prepare_ccache.sh b/.github/workflows/amd_aie_releases/scripts/docker_prepare_ccache.sh new file mode 100755 index 000000000000..3b91f9d91e84 --- /dev/null +++ b/.github/workflows/amd_aie_releases/scripts/docker_prepare_ccache.sh @@ -0,0 +1,51 @@ +#!/usr/bin/env bash +set -xe + +REPO_NAME=llvm-aie + +# manylinux prep +if [[ -f "/etc/centos-release" ]]; then + yum install -y epel-release + # sometimes the epel server is down. retry 5 times + for i in $(seq 1 5); do + yum install -y zlib-devel curl-devel expat-devel libpng-devel ccache wget ninja-build git && s=0 && break || s=$? && sleep 15 + done + + [ $s -eq 0 ] || exit $s + + if [[ -d "/usr/lib64/ccache" ]]; then + [ ! -f "/usr/lib64/ccache/c++" ] && ln -s /usr/bin/ccache /usr/lib64/ccache/c++ + [ ! -f "/usr/lib64/ccache/cc" ] && ln -s /usr/bin/ccache /usr/lib64/ccache/cc + [ ! -f "/usr/lib64/ccache/gcc" ] && ln -s /usr/bin/ccache /usr/lib64/ccache/gcc + [ ! -f "/usr/lib64/ccache/g++" ] && ln -s /usr/bin/ccache /usr/lib64/ccache/g++ + export PATH="/usr/lib64/ccache:$PATH" + elif [[ -d "/usr/lib/ccache" ]]; then + [ ! -f "/usr/lib/ccache/c++" ] && ln -s /usr/bin/ccache /usr/lib/ccache/c++ + [ ! -f "/usr/lib/ccache/cc" ] && ln -s /usr/bin/ccache /usr/lib/ccache/cc + [ ! -f "/usr/lib/ccache/gcc" ] && ln -s /usr/bin/ccache /usr/lib/ccache/gcc + [ ! -f "/usr/lib/ccache/g++" ] && ln -s /usr/bin/ccache /usr/lib/ccache/g++ + export PATH="/usr/lib/ccache:$PATH" + fi + +elif [[ -f "/etc/alpine-release" ]]; then + # musllinux prep + # ccache already present + apk add curl-dev expat-dev zlib-dev libpng-dev ccache + export PATH="/usr/lib/ccache/bin:$PATH" +fi + +# hack until https://github.com/pypa/cibuildwheel/issues/1030 is fixed +# Place ccache folder in /outputs +HOST_CCACHE_DIR="/host${HOST_CCACHE_DIR:-/home/runner/work/$REPO_NAME/$REPO_NAME/.ccache}" +if [ -d "$HOST_CCACHE_DIR" ]; then + ls -l "$HOST_CCACHE_DIR" + mkdir -p /output + mv $HOST_CCACHE_DIR /output/.ccache + ls -la /output/.ccache +fi + +ccache -o cache_dir="/output/.ccache" +ccache -M 5 G # set cache size to 5 G +# Show ccache stats +echo "Cache stats:" +ccache --show-stats diff --git a/.github/workflows/amd_aie_releases/scripts/gh_releases.py b/.github/workflows/amd_aie_releases/scripts/gh_releases.py new file mode 100644 index 000000000000..1394e1f9c3fd --- /dev/null +++ b/.github/workflows/amd_aie_releases/scripts/gh_releases.py @@ -0,0 +1,42 @@ +import os +import time + +from github import Github +import datetime + +# Authentication is defined via github.Auth +from github import Auth + +# using an access token +auth = Auth.Token(os.environ["GITHUB_TOKEN"]) + +twomonthsago = datetime.date.today() - datetime.timedelta(days=30) + +# should be an env variable... +REPO_NAME = "Xilinx/llvm-aie" +# get like this https://stackoverflow.com/a/72132792/9045206 +RELEASE_ID = 153575086 + +# First create a Github instance: + +# Public Web Github +g = Github(auth=auth) + +n_deleted = 0 +for _ in range(100): + n_deleted = 0 + repo = g.get_repo(REPO_NAME) + release = repo.get_release(RELEASE_ID) + assets = release.get_assets() + for ass in assets: + if ass.created_at.date() < twomonthsago: + print(ass.name) + assert ass.delete_asset() + n_deleted += 1 + + if n_deleted == 0: + break + time.sleep(5) + +if n_deleted > 0: + raise Exception("missed some") diff --git a/.github/workflows/amd_aie_releases/setup.py b/.github/workflows/amd_aie_releases/setup.py new file mode 100644 index 000000000000..77f758636869 --- /dev/null +++ b/.github/workflows/amd_aie_releases/setup.py @@ -0,0 +1,282 @@ +import shutil +from datetime import datetime +import os +import platform +import re +import subprocess +import sys +from pathlib import Path, PureWindowsPath +from pprint import pprint + +from setuptools import Extension, setup +from setuptools.command.build_ext import build_ext + + +class CMakeExtension(Extension): + def __init__(self, name: str, sourcedir: str = "") -> None: + super().__init__(name, sources=[]) + self.sourcedir = os.fspath(Path(sourcedir).resolve()) + + +def get_cross_cmake_args(): + cmake_args = {} + + def native_tools(): + nonlocal cmake_args + + native_tools_dir = Path(sys.prefix).absolute() / "bin" + assert native_tools_dir is not None, "native_tools_dir missing" + assert os.path.exists(native_tools_dir), "native_tools_dir doesn't exist" + cmake_args["LLVM_USE_HOST_TOOLS"] = "ON" + cmake_args["LLVM_NATIVE_TOOL_DIR"] = str(native_tools_dir) + + CIBW_ARCHS = os.environ.get("CIBW_ARCHS") + if CIBW_ARCHS in {"arm64", "aarch64", "ARM64"}: + ARCH = cmake_args["LLVM_TARGETS_TO_BUILD"] = "AArch64" + elif CIBW_ARCHS in {"x86_64", "AMD64"}: + ARCH = cmake_args["LLVM_TARGETS_TO_BUILD"] = "X86" + else: + raise ValueError(f"unknown CIBW_ARCHS={CIBW_ARCHS}") + if CIBW_ARCHS != platform.machine(): + cmake_args["CMAKE_SYSTEM_NAME"] = platform.system() + + if platform.system() == "Darwin": + if ARCH == "AArch64": + cmake_args["CMAKE_OSX_ARCHITECTURES"] = "arm64" + cmake_args["LLVM_DEFAULT_TARGET_TRIPLE"] = "arm64-apple-darwin21.6.0" + cmake_args["LLVM_HOST_TRIPLE"] = "arm64-apple-darwin21.6.0" + elif ARCH == "X86": + cmake_args["CMAKE_OSX_ARCHITECTURES"] = "x86_64" + cmake_args["LLVM_DEFAULT_TARGET_TRIPLE"] = "x86_64-apple-darwin" + cmake_args["LLVM_HOST_TRIPLE"] = "x86_64-apple-darwin" + elif platform.system() == "Linux": + if ARCH == "AArch64": + cmake_args["LLVM_DEFAULT_TARGET_TRIPLE"] = "aarch64-linux-gnu" + cmake_args["LLVM_HOST_TRIPLE"] = "aarch64-linux-gnu" + cmake_args["CMAKE_C_COMPILER"] = "aarch64-linux-gnu-gcc" + cmake_args["CMAKE_CXX_COMPILER"] = "aarch64-linux-gnu-g++" + cmake_args["CMAKE_CXX_FLAGS"] = "-static-libgcc -static-libstdc++" + native_tools() + elif ARCH == "X86": + cmake_args["LLVM_DEFAULT_TARGET_TRIPLE"] = "x86_64-unknown-linux-gnu" + cmake_args["LLVM_HOST_TRIPLE"] = "x86_64-unknown-linux-gnu" + + cmake_args["LLVM_TARGET_ARCH"] = ARCH + + return cmake_args + + +def get_exe_suffix(): + if platform.system() == "Windows": + suffix = ".exe" + else: + suffix = "" + return suffix + + +class CMakeBuild(build_ext): + def build_extension(self, ext: CMakeExtension) -> None: + ext_fullpath = Path.cwd() / self.get_ext_fullpath(ext.name) + extdir = ext_fullpath.parent.resolve() + install_dir = extdir / "llvm-aie" + cfg = "Release" + + cmake_generator = os.environ.get("CMAKE_GENERATOR", "Ninja") + + RUN_TESTS = 1 if check_env("RUN_TESTS") else 0 + # make windows happy + PYTHON_EXECUTABLE = str(Path(sys.executable)) + if platform.system() == "Windows": + PYTHON_EXECUTABLE = PYTHON_EXECUTABLE.replace("\\", "\\\\") + + cmake_args = [ + f"-B{build_temp}", + f"-G {cmake_generator}", + "-DBUILD_SHARED_LIBS=OFF", + "-DLLVM_BUILD_BENCHMARKS=OFF", + "-DLLVM_BUILD_EXAMPLES=OFF", + "-DLLVM_BUILD_RUNTIMES=OFF", + f"-DLLVM_BUILD_TESTS={RUN_TESTS}", + "-DLLVM_BUILD_TOOLS=ON", + "-DLLVM_BUILD_UTILS=ON", + "-DLLVM_CCACHE_BUILD=ON", + "-DLLVM_ENABLE_ASSERTIONS=ON", + "-DLLVM_ENABLE_RTTI=ON", + "-DLLVM_ENABLE_ZSTD=OFF", + "-DLLVM_INCLUDE_BENCHMARKS=OFF", + "-DLLVM_INCLUDE_EXAMPLES=OFF", + "-DLLVM_INCLUDE_RUNTIMES=OFF", + f"-DLLVM_INCLUDE_TESTS={RUN_TESTS}", + "-DLLVM_INCLUDE_TOOLS=ON", + "-DLLVM_INCLUDE_UTILS=ON", + "-DLLVM_INSTALL_UTILS=ON", + "-DLLVM_ENABLE_WARNINGS=ON", + "-DMLIR_BUILD_MLIR_C_DYLIB=1", + "-DMLIR_ENABLE_BINDINGS_PYTHON=ON", + "-DMLIR_ENABLE_EXECUTION_ENGINE=ON", + "-DMLIR_ENABLE_SPIRV_CPU_RUNNER=ON", + f"MLIR_INCLUDE_INTEGRATION_TESTS={RUN_TESTS}", + f"MLIR_INCLUDE_TESTS={RUN_TESTS}", + # get rid of that annoying af git on the end of .17git + "-DLLVM_VERSION_SUFFIX=", + # Disables generation of "version soname" (i.e. libFoo.so.), which + # causes pure duplication of various shlibs for Python wheels. + "-DCMAKE_PLATFORM_NO_VERSIONED_SONAME=ON", + f"-DCMAKE_INSTALL_PREFIX={install_dir}", + f"-DCMAKE_LIBRARY_OUTPUT_DIRECTORY={extdir}{os.sep}", + f"-DPython3_EXECUTABLE={PYTHON_EXECUTABLE}", + f"-DCMAKE_BUILD_TYPE={cfg}", # not used on MSVC, but no harm + # prevent symbol collision that leads to multiple pass registration and such + "-DCMAKE_VISIBILITY_INLINES_HIDDEN=ON", + "-DCMAKE_C_VISIBILITY_PRESET=hidden", + "-DCMAKE_CXX_VISIBILITY_PRESET=hidden", + # AIE specific + "-DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD=AIE", + "-DLIBC_ENABLE_USE_BY_CLANG=ON", + "-DLLVM_ENABLE_RUNTIMES=compiler-rt;libc", + "-DLLVM_BUILTIN_TARGETS=aie2-none-unknown-elf;aie-none-unknown-elf", + "-DLLVM_RUNTIME_TARGETS=aie-none-unknown-elf;aie2-none-unknown-elf", + "-DBUILTINS_aie-none-unknown-elf_LLVM_USE_LINKER=lld", + "-DBUILTINS_aie-none-unknown-elf_CMAKE_BUILD_TYPE=Release", + "-DRUNTIMES_aie-none-unknown-elf_LLVM_USE_LINKER=lld", + "-DRUNTIMES_aie-none-unknown-elf_CMAKE_BUILD_TYPE=Release", + "-DBUILTINS_aie2-none-unknown-elf_LLVM_USE_LINKER=lld", + "-DBUILTINS_aie2-none-unknown-elf_CMAKE_BUILD_TYPE=Release", + "-DRUNTIMES_aie2-none-unknown-elf_LLVM_USE_LINKER=lld", + "-DRUNTIMES_aie2-none-unknown-elf_CMAKE_BUILD_TYPE=Release", + "-DLLVM_LIBC_FULL_BUILD=ON", + ] + if platform.system() == "Windows": + cmake_args += [ + "-DCMAKE_C_COMPILER=cl", + "-DCMAKE_CXX_COMPILER=cl", + "-DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded", + "-DCMAKE_C_FLAGS=/MT", + "-DCMAKE_CXX_FLAGS=/MT", + "-DLLVM_USE_CRT_MINSIZEREL=MT", + "-DLLVM_USE_CRT_RELEASE=MT", + ] + + cmake_args_dict = get_cross_cmake_args() + cmake_args += [f"-D{k}={v}" for k, v in cmake_args_dict.items()] + cmake_args += [f"-DLLVM_ENABLE_PROJECTS=llvm;mlir;clang"] + + if "CMAKE_ARGS" in os.environ: + cmake_args += [item for item in os.environ["CMAKE_ARGS"].split(" ") if item] + + build_args = [] + if self.compiler.compiler_type != "msvc": + if not cmake_generator or cmake_generator == "Ninja": + try: + import ninja + + ninja_executable_path = Path(ninja.BIN_DIR) / "ninja" + cmake_args += [ + "-GNinja", + f"-DCMAKE_MAKE_PROGRAM:FILEPATH={ninja_executable_path}", + ] + except ImportError: + pass + + else: + single_config = any(x in cmake_generator for x in {"NMake", "Ninja"}) + contains_arch = any(x in cmake_generator for x in {"ARM", "Win64"}) + if not single_config and not contains_arch: + PLAT_TO_CMAKE = { + "win32": "Win32", + "win-amd64": "x64", + "win-arm32": "ARM", + "win-arm64": "ARM64", + } + cmake_args += ["-A", PLAT_TO_CMAKE[self.plat_name]] + if not single_config: + cmake_args += [ + f"-DCMAKE_LIBRARY_OUTPUT_DIRECTORY_{cfg.upper()}={extdir}" + ] + build_args += ["--config", cfg] + + if sys.platform.startswith("darwin"): + osx_version = os.getenv("OSX_VERSION", "11.6") + cmake_args += [f"-DCMAKE_OSX_DEPLOYMENT_TARGET={osx_version}"] + # Cross-compile support for macOS - respect ARCHFLAGS if set + archs = re.findall(r"-arch (\S+)", os.environ.get("ARCHFLAGS", "")) + if archs: + cmake_args += ["-DCMAKE_OSX_ARCHITECTURES={}".format(";".join(archs))] + + if "PARALLEL_LEVEL" not in os.environ: + build_args += [f"-j{str(2 * os.cpu_count())}"] + else: + build_args += [f"-j{os.environ.get('PARALLEL_LEVEL')}"] + + print("ENV", pprint(os.environ), file=sys.stderr) + print("CMAKE_ARGS", cmake_args, file=sys.stderr) + + subprocess.run( + ["cmake", ext.sourcedir, *cmake_args], cwd=build_temp, check=True + ) + subprocess.run( + ["cmake", "--build", ".", "--target", "install", *build_args], + cwd=build_temp, + check=True, + ) + if RUN_TESTS: + env = os.environ.copy() + # PYTHONPATH needs to be set to find build deps like numpy + # https://github.com/llvm/llvm-project/pull/89296 + env["MLIR_LIT_PYTHONPATH"] = os.pathsep.join(sys.path) + subprocess.run( + ["cmake", "--build", ".", "--target", "check-all", *build_args], + cwd=build_temp, + env=env, + check=False, + ) + shutil.rmtree(install_dir / "python_packages", ignore_errors=True) + + +def check_env(build): + return os.environ.get(build, 0) in {"1", "true", "True", "ON", "YES"} + + +cmake_txt = open("llvm-aie/cmake/Modules/LLVMVersion.cmake").read() +llvm_version = [] +for v in ["LLVM_VERSION_MAJOR", "LLVM_VERSION_MINOR", "LLVM_VERSION_PATCH"]: + vn = re.findall(rf"set\({v} (\d+)\)", cmake_txt) + assert vn, f"couldn't find {v} in cmake txt" + llvm_version.append(vn[0]) + +commit_hash = os.environ.get("LLVM_AIE_PROJECT_COMMIT", "DEADBEEF") + +now = datetime.now() +llvm_datetime = os.environ.get( + "DATETIME", f"{now.year}{now.month:02}{now.day:02}{now.hour:02}" +) + +version = f"{llvm_version[0]}.{llvm_version[1]}.{llvm_version[2]}.{llvm_datetime}+" +version += commit_hash +llvm_url = f"https://github.com/Xilinx/llvm-aie/commit/{commit_hash}" + +build_temp = Path.cwd() / "build" / "temp" +if not build_temp.exists(): + build_temp.mkdir(parents=True) + +EXE_EXT = ".exe" if platform.system() == "Windows" else "" +exes = [ + "mlir-cpu-runner", + "mlir-opt", + "mlir-translate", +] +data_files = [("bin", [str(build_temp / "bin" / x) + EXE_EXT for x in exes])] + + +setup( + name="llvm-aie", + version=version, + description=f"LLVM-AIE distribution as wheel. Created at {now} build of {llvm_url}", + long_description=f"LLVM-AIE distribution as wheel. Created at {now} build of [Xilinx/llvm-aie/{commit_hash}]({llvm_url})", + long_description_content_type="text/markdown", + ext_modules=[CMakeExtension("llvm-aie", sourcedir="llvm-aie/llvm")], + cmdclass={"build_ext": CMakeBuild}, + zip_safe=False, + download_url=llvm_url, + data_files=data_files, +)