From 467f47136b308571fe390beb88ec95885bf31fbb Mon Sep 17 00:00:00 2001 From: atalman Date: Tue, 15 Oct 2024 15:23:59 -0700 Subject: [PATCH 1/3] llvm build --- .github/workflows/build-llvm.yml | 224 ++++++++++++++++++ .../workflows/llvm-build/almalinux.Dockerfile | 0 2 files changed, 224 insertions(+) create mode 100644 .github/workflows/build-llvm.yml create mode 100644 .github/workflows/llvm-build/almalinux.Dockerfile diff --git a/.github/workflows/build-llvm.yml b/.github/workflows/build-llvm.yml new file mode 100644 index 000000000..f6e4ede88 --- /dev/null +++ b/.github/workflows/build-llvm.yml @@ -0,0 +1,224 @@ +name: LLVM Build + +on: + workflow_dispatch: + +env: + SCCACHE_DIR: ${{ github.workspace }}/sccache + + +jobs: + + build: + name: Build on ${{ matrix.config.runner }} + runs-on: ${{ matrix.config.runs_on }} + timeout-minutes: 240 # 4 hours + + strategy: + fail-fast: true + matrix: + config: + - {runner: 'AlmaLinux 8', runs_on: 'linux.arm64.2xlarge', target-os: 'almalinux', arch: 'arm64'} + + + steps: + + - name: Checkout Repo + uses: actions/checkout@v4 + with: + path: llvm-build + + - name: Fetch LLVM Commit Hash + shell: bash + run: | + LLVM_COMMIT_HASH="$(cat llvm-build/cmake/llvm-hash.txt)" + echo "Found LLVM commit hash: ${LLVM_COMMIT_HASH}" + echo "llvm_commit_hash=${LLVM_COMMIT_HASH}" >> ${GITHUB_ENV} + + SHORT_LLVM_COMMIT_HASH="${LLVM_COMMIT_HASH:0:8}" + echo "Short LLVM commit hash: ${SHORT_LLVM_COMMIT_HASH}" + echo "short_llvm_commit_hash=${SHORT_LLVM_COMMIT_HASH}" >> ${GITHUB_ENV} + + INSTALL_DIR="llvm-${SHORT_LLVM_COMMIT_HASH}-${{ matrix.config.target-os }}-${{ matrix.config.arch }}" + echo "LLVM installation directory name: ${INSTALL_DIR}" + echo "llvm_install_dir=${INSTALL_DIR}" >> ${GITHUB_ENV} + + - name: Checkout LLVM + uses: actions/checkout@v4 + with: + repository: llvm/llvm-project + path: llvm-project + ref: ${{ env.llvm_commit_hash }} + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: 3.11 + + + - name: Install Prerequisites + shell: bash + run: | + python3 -m pip install cmake ninja sccache + mkdir -p ${{ env.SCCACHE_DIR }} + rm -rf ${{ env.SCCACHE_DIR }}/* + + - name: Enable Cache + uses: actions/cache@v4 + with: + path: ${{ env.SCCACHE_DIR }} + key: ${{ matrix.config.target-os }}-${{ matrix.config.arch }}-${{ env.short_llvm_commit_hash }} + restore-keys: ${{ matrix.config.target-os }}-${{ matrix.config.arch }}- + + + - name: Configure, Build, and Install LLVM (ubuntu arm64) + if: matrix.config.arch == 'arm64' && matrix.config.target-os == 'ubuntu' + run: | + python3 -m pip install -r llvm-project/mlir/python/requirements.txt + mkdir arm-sysroot + mkdir -p llvm-project/host-tools + cd llvm-project/host-tools + cmake -GNinja ../llvm -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_PROJECTS="mlir;llvm;clang" + ninja mlir-tblgen + ninja llvm-tblgen + ninja clang-tblgen + cd ../.. + mv ./llvm-project/host-tools/bin ./host-tools + HOST_TOOLS="$(pwd)/host-tools" + rm -rf llvm-project/host-tools + sudo apt-get update + sudo apt-get install gcc-arm-linux-gnueabihf g++-arm-linux-gnueabihf qemu-user-static gcc-aarch64-linux-gnu g++-aarch64-linux-gnu + cp -r /usr/aarch64-linux-gnu/lib ./arm-sysroot + cp -r /usr/aarch64-linux-gnu/include ./arm-sysroot + LINKER=$(pwd)/arm-sysroot/lib/ld-linux-aarch64.so.1 + wget http://ftp.de.debian.org/debian/pool/main/g/gcc-defaults/gcc-aarch64-linux-gnu_14.1.0-2_amd64.deb + dpkg-deb -x gcc-aarch64-linux-gnu_14.1.0-2_amd64.deb ./arm-sysroot + export LD_LIBRARY_PATH=$(pwd)/arm-sysroot/lib:$LD_LIBRARY_PATH + sudo ln -s $LINKER /lib/ld-linux-aarch64.so.1 + SYSROOT="$(pwd)/arm-sysroot" + echo $SYSROOT + echo $LINKER + cmake -GNinja -Bllvm-project/build \ + -DCMAKE_BUILD_TYPE=Release \ + -DLLVM_ENABLE_PROJECTS="mlir;llvm" \ + -DLLVM_BUILD_UTILS=ON \ + -DLLVM_TABLEGEN=$HOST_TOOLS/llvm-tblgen \ + -DMLIR_TABLEGEN=$HOST_TOOLS/mlir-tblgen \ + -DCLANG_TABLEGEN=$HOST_TOOLS/clang-tblgen \ + -DLLVM_ENABLE_ASSERTIONS=ON \ + -DCMAKE_LINKER=$LINKER \ + -DMLIR_ENABLE_BINDINGS_PYTHON=ON \ + -DLLVM_ENABLE_ZSTD=OFF \ + -DLLVM_ABI_BREAKING_CHECKS=FORCE_OFF \ + -DLLVM_INSTALL_UTILS=ON \ + -DCMAKE_INSTALL_PREFIX="${{ env.llvm_install_dir }}" \ + -DLLVM_TARGETS_TO_BUILD="AArch64;NVPTX;AMDGPU" \ + -DCMAKE_CROSSCOMPILING=True \ + -DLLVM_TARGET_ARCH=AArch64 \ + -DLLVM_DEFAULT_TARGET_TRIPLE=aarch64-linux-gnu \ + -DLLVM_USE_HOST_TOOLS=OFF \ + -DCMAKE_C_COMPILER="/usr/bin/aarch64-linux-gnu-gcc" \ + -DCMAKE_CXX_COMPILER="/usr/bin/aarch64-linux-gnu-g++" \ + -DCMAKE_ASM_COMPILER="/usr/bin/aarch64-linux-gnu-as" \ + -DCMAKE_AR="/usr/bin/aarch64-linux-gnu-ar" \ + -DCMAKE_NM="/usr/bin/aarch64-linux-gnu-nm" \ + -DCMAKE_OBJCOPY="/usr/bin/aarch64-linux-gnu-objcopy" \ + -DCMAKE_OBJDUMP="/usr/bin/aarch64-linux-gnu-objdump" \ + -DCMAKE_RANLIB="/usr/bin/aarch64-linux-gnu-ranlib" \ + -DCMAKE_STRIP="/usr/bin/aarch64-linux-gnu-strip" \ + -DCMAKE_SYSROOT=$SYSROOT \ + -DLLVM_ENABLE_TERMINFO=OFF \ + llvm-project/llvm + ninja -C llvm-project/build install + CURR_PWD="$(pwd)" + cd "${{ env.llvm_install_dir }}/python_packages/mlir_core/mlir/_mlir_libs/" + for file in *x86_64*; do + mv "$file" "${file/x86_64/aarch64}" + done + cd $CURR_PWD + tar czf "${{ env.llvm_install_dir }}.tar.gz" "${{ env.llvm_install_dir }}" + + - name: Configure, Build, and Install LLVM (macOS arm64) + if: matrix.config.arch == 'arm64' && matrix.config.target-os == 'macos' + run: > + python3 -m pip install -r llvm-project/mlir/python/requirements.txt + + cmake -GNinja -Bllvm-project/build + -DCMAKE_BUILD_TYPE=Release + -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ + -DCMAKE_C_COMPILER_LAUNCHER=sccache -DCMAKE_CXX_COMPILER_LAUNCHER=sccache + -DCMAKE_INSTALL_PREFIX="${{ env.llvm_install_dir }}" + -DCMAKE_LINKER=lld + -DCMAKE_OSX_ARCHITECTURES=arm64 + -DLLVM_BUILD_UTILS=ON + -DLLVM_BUILD_TOOLS=ON + -DLLVM_ENABLE_ASSERTIONS=ON + -DMLIR_ENABLE_BINDINGS_PYTHON=ON + -DLLVM_ENABLE_PROJECTS=mlir + -DLLVM_ENABLE_ZSTD=OFF + -DLLVM_INSTALL_UTILS=ON + -DLLVM_TARGETS_TO_BUILD="AArch64;NVPTX;AMDGPU" + -DLLVM_USE_HOST_TOOLS=ON + -DLLVM_ENABLE_TERMINFO=OFF + -DLLVM_ABI_BREAKING_CHECKS=FORCE_OFF + llvm-project/llvm + + ninja -C llvm-project/build install + + tar czf "${{ env.llvm_install_dir }}.tar.gz" "${{ env.llvm_install_dir }}" + + - name: Configure, Build, Test, and Install LLVM (AlmaLinux) + if: matrix.config.target-os == 'almalinux' + run: | + # if this step crashes, it can leave behind a stale docker container + docker container prune -f + docker rmi -f $(docker images -q) + + docker build --tag llvm-build --build-arg llvm_dir=llvm-project \ + -f llvm-build/.github/workflows/llvm-build/almalinux.Dockerfile . + + # Create temporary container to copy cache and installed artifacts. + CONTAINER_ID=$(docker create llvm-build) + docker cp "${CONTAINER_ID}:/install" "${{ env.llvm_install_dir }}" + tar czf "${{ env.llvm_install_dir }}.tar.gz" "${{ env.llvm_install_dir }}" + + # We remove the existing directory, otherwise docker will + # create a subdirectory inside the existing directory. + rm -rf "${{ env.SCCACHE_DIR }}" + docker cp "${CONTAINER_ID}:/sccache" "${{ env.SCCACHE_DIR }}" + sudo chown -R "$(id -u -n):$(id -g -n)" "${{ env.SCCACHE_DIR }}" + + docker rm "${CONTAINER_ID}" + + - name: Upload Build Artifacts + uses: actions/upload-artifact@v4 + with: + name: llvm-${{ matrix.config.target-os }}-${{ matrix.config.arch }} + path: | + ${{ github.workspace }}/llvm-*-${{ matrix.config.target-os }}-${{ matrix.config.arch }}.tar.gz + + - name: Azure Login + if: ${{ (github.repository == 'triton-lang/triton') }} + uses: azure/login@v2 + with: + client-id: ${{ secrets.AZURE_CLIENT_ID }} + tenant-id: ${{ secrets.AZURE_TENANT_ID }} + subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }} + + - name: Upload LLVM Artifacts to Azure + if: ${{ (github.repository == 'triton-lang/triton') }} + run: | + az storage blob upload --account-name oaitriton --auth-mode login --container-name public --file "${{ env.llvm_install_dir }}.tar.gz" --name "llvm-builds/${{ env.llvm_install_dir }}.tar.gz" --overwrite + + URL=$(az storage blob url --account-name oaitriton --auth-mode login --container-name public --name "llvm-builds/${{ env.llvm_install_dir }}.tar.gz") + echo "Blob URL: ${URL}" + + - name: Azure Logout + if: ${{ (github.repository == 'triton-lang/triton') }} + run: | + az logout + az cache purge + az account clear + + - name: Dump Sccache Statistics + run: sccache --show-stats diff --git a/.github/workflows/llvm-build/almalinux.Dockerfile b/.github/workflows/llvm-build/almalinux.Dockerfile new file mode 100644 index 000000000..e69de29bb From 598f2d4a3976e0b06f1afa27ef5f04a9aed0a72f Mon Sep 17 00:00:00 2001 From: atalman Date: Tue, 15 Oct 2024 15:26:16 -0700 Subject: [PATCH 2/3] test --- .github/workflows/build-llvm.yml | 26 -------------------------- 1 file changed, 26 deletions(-) diff --git a/.github/workflows/build-llvm.yml b/.github/workflows/build-llvm.yml index f6e4ede88..6c3ca2506 100644 --- a/.github/workflows/build-llvm.yml +++ b/.github/workflows/build-llvm.yml @@ -196,29 +196,3 @@ jobs: name: llvm-${{ matrix.config.target-os }}-${{ matrix.config.arch }} path: | ${{ github.workspace }}/llvm-*-${{ matrix.config.target-os }}-${{ matrix.config.arch }}.tar.gz - - - name: Azure Login - if: ${{ (github.repository == 'triton-lang/triton') }} - uses: azure/login@v2 - with: - client-id: ${{ secrets.AZURE_CLIENT_ID }} - tenant-id: ${{ secrets.AZURE_TENANT_ID }} - subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }} - - - name: Upload LLVM Artifacts to Azure - if: ${{ (github.repository == 'triton-lang/triton') }} - run: | - az storage blob upload --account-name oaitriton --auth-mode login --container-name public --file "${{ env.llvm_install_dir }}.tar.gz" --name "llvm-builds/${{ env.llvm_install_dir }}.tar.gz" --overwrite - - URL=$(az storage blob url --account-name oaitriton --auth-mode login --container-name public --name "llvm-builds/${{ env.llvm_install_dir }}.tar.gz") - echo "Blob URL: ${URL}" - - - name: Azure Logout - if: ${{ (github.repository == 'triton-lang/triton') }} - run: | - az logout - az cache purge - az account clear - - - name: Dump Sccache Statistics - run: sccache --show-stats From 2af54b850b76fe25d9ca8ae6c004cb5808c184f3 Mon Sep 17 00:00:00 2001 From: atalman Date: Tue, 15 Oct 2024 15:30:32 -0700 Subject: [PATCH 3/3] test --- .github/workflows/build-llvm.yml | 29 -------------- .../workflows/llvm-build/almalinux.Dockerfile | 40 +++++++++++++++++++ 2 files changed, 40 insertions(+), 29 deletions(-) diff --git a/.github/workflows/build-llvm.yml b/.github/workflows/build-llvm.yml index 6c3ca2506..23eecbb94 100644 --- a/.github/workflows/build-llvm.yml +++ b/.github/workflows/build-llvm.yml @@ -138,35 +138,6 @@ jobs: cd $CURR_PWD tar czf "${{ env.llvm_install_dir }}.tar.gz" "${{ env.llvm_install_dir }}" - - name: Configure, Build, and Install LLVM (macOS arm64) - if: matrix.config.arch == 'arm64' && matrix.config.target-os == 'macos' - run: > - python3 -m pip install -r llvm-project/mlir/python/requirements.txt - - cmake -GNinja -Bllvm-project/build - -DCMAKE_BUILD_TYPE=Release - -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ - -DCMAKE_C_COMPILER_LAUNCHER=sccache -DCMAKE_CXX_COMPILER_LAUNCHER=sccache - -DCMAKE_INSTALL_PREFIX="${{ env.llvm_install_dir }}" - -DCMAKE_LINKER=lld - -DCMAKE_OSX_ARCHITECTURES=arm64 - -DLLVM_BUILD_UTILS=ON - -DLLVM_BUILD_TOOLS=ON - -DLLVM_ENABLE_ASSERTIONS=ON - -DMLIR_ENABLE_BINDINGS_PYTHON=ON - -DLLVM_ENABLE_PROJECTS=mlir - -DLLVM_ENABLE_ZSTD=OFF - -DLLVM_INSTALL_UTILS=ON - -DLLVM_TARGETS_TO_BUILD="AArch64;NVPTX;AMDGPU" - -DLLVM_USE_HOST_TOOLS=ON - -DLLVM_ENABLE_TERMINFO=OFF - -DLLVM_ABI_BREAKING_CHECKS=FORCE_OFF - llvm-project/llvm - - ninja -C llvm-project/build install - - tar czf "${{ env.llvm_install_dir }}.tar.gz" "${{ env.llvm_install_dir }}" - - name: Configure, Build, Test, and Install LLVM (AlmaLinux) if: matrix.config.target-os == 'almalinux' run: | diff --git a/.github/workflows/llvm-build/almalinux.Dockerfile b/.github/workflows/llvm-build/almalinux.Dockerfile index e69de29bb..f48fbabd7 100644 --- a/.github/workflows/llvm-build/almalinux.Dockerfile +++ b/.github/workflows/llvm-build/almalinux.Dockerfile @@ -0,0 +1,40 @@ +FROM almalinux:8 +ARG llvm_dir=llvm-project +# Add the cache artifacts and the LLVM source tree to the container +ADD sccache /sccache +ADD "${llvm_dir}" /source/llvm-project +ENV SCCACHE_DIR="/sccache" +ENV SCCACHE_CACHE_SIZE="2G" + +RUN dnf install --assumeyes llvm-toolset +RUN dnf install --assumeyes python38-pip python38-devel git + +RUN python3 -m pip install --upgrade pip +RUN python3 -m pip install --upgrade cmake ninja sccache lit + +# Install MLIR's Python Dependencies +RUN python3 -m pip install -r /source/llvm-project/mlir/python/requirements.txt + +# Configure, Build, Test, and Install LLVM +RUN cmake -GNinja -Bbuild \ + -DCMAKE_BUILD_TYPE=Release \ + -DCMAKE_C_COMPILER=clang \ + -DCMAKE_CXX_COMPILER=clang++ \ + -DCMAKE_ASM_COMPILER=clang \ + -DCMAKE_C_COMPILER_LAUNCHER=sccache \ + -DCMAKE_CXX_COMPILER_LAUNCHER=sccache \ + -DCMAKE_CXX_FLAGS="-Wno-everything" \ + -DCMAKE_LINKER=lld \ + -DCMAKE_INSTALL_PREFIX="/install" \ + -DLLVM_BUILD_UTILS=ON \ + -DLLVM_BUILD_TOOLS=ON \ + -DLLVM_ENABLE_ASSERTIONS=ON \ + -DMLIR_ENABLE_BINDINGS_PYTHON=ON \ + -DLLVM_ENABLE_PROJECTS=mlir \ + -DLLVM_ENABLE_TERMINFO=OFF \ + -DLLVM_INSTALL_UTILS=ON \ + -DLLVM_TARGET_ARCH=AArch64 \ + -DLLVM_TARGETS_TO_BUILD="host;NVPTX;AMDGPU" \ + /source/llvm-project/llvm + +RUN ninja -C build install