|
| 1 | +# Licensed to the Apache Software Foundation (ASF) under one |
| 2 | +# or more contributor license agreements. See the NOTICE file |
| 3 | +# distributed with this work for additional information |
| 4 | +# regarding copyright ownership. The ASF licenses this file |
| 5 | +# to you under the Apache License, Version 2.0 (the |
| 6 | +# "License"); you may not use this file except in compliance |
| 7 | +# with the License. You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, |
| 12 | +# software distributed under the License is distributed on an |
| 13 | +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 | +# KIND, either express or implied. See the License for the |
| 15 | +# specific language governing permissions and limitations |
| 16 | +# under the License. |
| 17 | + |
| 18 | +name: Build TIRx Wheel |
| 19 | +description: > |
| 20 | + Build and test the standalone LLVM-enabled apache-tvm-tirx wheel for a given OS/architecture |
| 21 | + combination using cibuildwheel. |
| 22 | +
|
| 23 | +inputs: |
| 24 | + arch: |
| 25 | + description: "Target architecture for cibuildwheel (e.g., x86_64, aarch64, arm64, AMD64)" |
| 26 | + required: true |
| 27 | + build: |
| 28 | + description: "cibuildwheel build selector (e.g., cp310-manylinux_x86_64)" |
| 29 | + required: true |
| 30 | + cmake_defines: |
| 31 | + description: "Feature CMake defines that vary by wheel (e.g. -DTVM_TIRX_USE_METAL=ON on macOS)" |
| 32 | + required: false |
| 33 | + default: "" |
| 34 | + include_cuda_runtime: |
| 35 | + description: "Set to 1 to build and inject the CUDA runtime library (Linux only)" |
| 36 | + required: false |
| 37 | + default: "0" |
| 38 | + |
| 39 | +runs: |
| 40 | + using: "composite" |
| 41 | + steps: |
| 42 | + # Single source of truth for the LLVM toolchain version, shared by the cache |
| 43 | + # key and the conda install steps below. |
| 44 | + - name: Set LLVM version |
| 45 | + shell: bash |
| 46 | + run: echo "LLVM_VERSION=22.1.0" >> "$GITHUB_ENV" |
| 47 | + |
| 48 | + - name: Prepare LLVM cache path (Unix) |
| 49 | + if: runner.os != 'Windows' |
| 50 | + shell: bash |
| 51 | + run: | |
| 52 | + set -eux |
| 53 | + sudo mkdir -p /opt/llvm |
| 54 | + sudo chown -R "$(whoami)" /opt/llvm |
| 55 | +
|
| 56 | + # ---- Cache LLVM prefix ---- |
| 57 | + - name: Cache LLVM |
| 58 | + uses: actions/cache@v5.0.5 |
| 59 | + id: llvm-cache |
| 60 | + with: |
| 61 | + path: ${{ runner.os == 'Windows' && 'C:/opt/llvm' || '/opt/llvm' }} |
| 62 | + key: tirx-wheel-llvm-${{ env.LLVM_VERSION }}-${{ runner.os }}-${{ inputs.arch }}-v6 |
| 63 | + |
| 64 | + # ---- Install LLVM via conda (cache miss only) ---- |
| 65 | + - name: Setup conda |
| 66 | + if: steps.llvm-cache.outputs.cache-hit != 'true' |
| 67 | + uses: conda-incubator/setup-miniconda@v4.0.1 |
| 68 | + continue-on-error: true |
| 69 | + id: conda1 |
| 70 | + with: |
| 71 | + miniforge-version: latest |
| 72 | + conda-remove-defaults: true |
| 73 | + |
| 74 | + - name: Setup conda (retry with tar.bz2) |
| 75 | + if: steps.llvm-cache.outputs.cache-hit != 'true' && steps.conda1.outcome == 'failure' |
| 76 | + uses: conda-incubator/setup-miniconda@v4.0.1 |
| 77 | + with: |
| 78 | + miniforge-version: latest |
| 79 | + use-only-tar-bz2: true |
| 80 | + conda-remove-defaults: true |
| 81 | + |
| 82 | + - name: Install LLVM (Unix) |
| 83 | + if: steps.llvm-cache.outputs.cache-hit != 'true' && runner.os != 'Windows' |
| 84 | + shell: bash -l {0} |
| 85 | + run: | |
| 86 | + set -eux |
| 87 | + if [[ "${RUNNER_OS}" == "Linux" ]]; then |
| 88 | + sudo mkdir -p /opt/llvm |
| 89 | + sudo chown -R "$(whoami)" /opt/llvm |
| 90 | + fi |
| 91 | + conda create -q -p /opt/llvm -c conda-forge \ |
| 92 | + "llvmdev=${LLVM_VERSION}" "clangdev=${LLVM_VERSION}" "compiler-rt=${LLVM_VERSION}" zlib zstd-static libxml2-devel \ |
| 93 | + -y |
| 94 | +
|
| 95 | + - name: Install LLVM (Windows) |
| 96 | + if: steps.llvm-cache.outputs.cache-hit != 'true' && runner.os == 'Windows' |
| 97 | + shell: cmd /C call {0} |
| 98 | + run: | |
| 99 | + call conda create -q -p C:\opt\llvm -c conda-forge llvmdev=%LLVM_VERSION% zlib zstd-static libxml2-devel -y |
| 100 | +
|
| 101 | + # The {project} placeholder is not expanded inside CIBW_ENVIRONMENT values, so |
| 102 | + # compute the forward-slash host path here (the Windows analog of the Linux |
| 103 | + # /project hardcode). |
| 104 | + - name: Compute CUDA sidecar path (Windows) |
| 105 | + if: runner.os == 'Windows' && inputs.include_cuda_runtime == '1' |
| 106 | + shell: bash |
| 107 | + run: echo "TVM_CUDA_EXTRA_LIB=$(cygpath -m "$(pwd)")/build-wheel-cuda/lib/tvm_runtime_cuda.dll" >> "$GITHUB_ENV" |
| 108 | + |
| 109 | + # ---- Build and test wheels ---- |
| 110 | + - name: Build and test TIRx core wheel |
| 111 | + uses: pypa/cibuildwheel@294735312765b09d24a2fbec22660ce817587d55 # v4.1.0 |
| 112 | + with: |
| 113 | + package-dir: . |
| 114 | + output-dir: wheelhouse |
| 115 | + env: |
| 116 | + CIBW_BUILD: ${{ inputs.build }} |
| 117 | + CIBW_ARCHS_LINUX: ${{ inputs.arch }} |
| 118 | + CIBW_ARCHS_MACOS: ${{ inputs.arch }} |
| 119 | + CIBW_ARCHS_WINDOWS: ${{ inputs.arch }} |
| 120 | + # Linux builds run in cibuildwheel's default manylinux_2_28 container; |
| 121 | + # bind-mount the cached LLVM prefix into it. Ignored on macOS/Windows, |
| 122 | + # which build without a container. |
| 123 | + CIBW_CONTAINER_ENGINE: "docker; create_args: --volume /opt/llvm:/opt/llvm:ro" |
| 124 | + # Each per-OS block carries the toolchain location (conda LLVM prefix + |
| 125 | + # llvm-config path), the universal static-link policy (TVM_TIRX_USE_LLVM --link-static |
| 126 | + # and ZLIB_USE_STATIC_LIBS), and the CUDA sidecar. Feature defines that vary by |
| 127 | + # wheel (e.g. TVM_TIRX_USE_METAL on macOS) come from the matrix via inputs.cmake_defines. |
| 128 | + # One explicit block per build platform (macOS / Linux / Windows); cibuildwheel |
| 129 | + # env overrides replace rather than merge, so there is no shared base block. |
| 130 | + CIBW_ENVIRONMENT_MACOS: >- |
| 131 | + CMAKE_PREFIX_PATH="/opt/llvm" |
| 132 | + CMAKE_ARGS="-DTVM_TIRX_USE_LLVM='/opt/llvm/bin/llvm-config --link-static' -DZLIB_USE_STATIC_LIBS=ON -DCMAKE_PREFIX_PATH=/opt/llvm ${{ inputs.cmake_defines }}" |
| 133 | + CIBW_ENVIRONMENT_LINUX: >- |
| 134 | + CMAKE_PREFIX_PATH="/opt/llvm" |
| 135 | + LIBRARY_PATH="/opt/llvm/lib" |
| 136 | + CMAKE_ARGS="-DTVM_TIRX_USE_LLVM='/opt/llvm/bin/llvm-config --link-static' -DZLIB_USE_STATIC_LIBS=ON -DCMAKE_PREFIX_PATH=/opt/llvm ${{ inputs.cmake_defines }} -DTVM_TIRX_PACKAGE_EXTRA_LIBS=/project/build-wheel-cuda/lib/libtvm_runtime_cuda.so" |
| 137 | + CIBW_ENVIRONMENT_WINDOWS: >- |
| 138 | + CMAKE_PREFIX_PATH="C:/opt/llvm/Library" |
| 139 | + PATH="C:/opt/llvm/Library/bin;$PATH" |
| 140 | + CMAKE_ARGS="-DTVM_TIRX_USE_LLVM='C:/opt/llvm/Library/bin/llvm-config.exe --link-static' -DZLIB_USE_STATIC_LIBS=ON -DCMAKE_PREFIX_PATH=C:/opt/llvm/Library ${{ inputs.cmake_defines }} -DTVM_TIRX_PACKAGE_EXTRA_LIBS=${{ env.TVM_CUDA_EXTRA_LIB }}" |
| 141 | + # Turns the wheel-specific assertions in |
| 142 | + # tests/python/runtime/test_validate_wheel_library.py |
| 143 | + # ON (they skip unless these are set). Every published wheel is LLVM-enabled, |
| 144 | + # so TVM_WHEEL_EXPECT_LLVM is always "1"; the CUDA runtime is only bundled on |
| 145 | + # the CUDA wheels, so TVM_WHEEL_EXPECT_CUDA_RUNTIME is "0" for CPU wheels. |
| 146 | + CIBW_TEST_ENVIRONMENT: >- |
| 147 | + TVM_WHEEL_EXPECT_LLVM="1" |
| 148 | + TVM_WHEEL_EXPECT_CUDA_RUNTIME="${{ inputs.include_cuda_runtime }}" |
0 commit comments