This is an automated email from the ASF dual-hosted git repository. tqchen pushed a commit to branch pinned-build-sdks-835 in repository https://gitbox.apache.org/repos/asf/tvm-tirx.git
commit 2e89c2713fe1b4c9ea94ef4a1ca21eae1aab3bdd Author: Tianqi Chen <[email protected]> AuthorDate: Sat Oct 24 21:31:55 2026 +0000 [BUILD] Use pinned Python LLVM and Z3 development SDKs --- .github/actions/build-wheel-for-publish/action.yml | 84 ++-------------------- .github/actions/setup/action.yml | 57 ++++----------- .github/workflows/main.yml | 11 +-- AGENTS.md | 9 ++- ci/wheel/build-environment.yaml | 42 ----------- ci/wheel/windows_build_libtvm_runtime_cuda.bat | 4 +- cmake/modules/contrib/Z3.cmake | 2 +- cmake/utils/FindLLVM.cmake | 34 ++++++++- docs/README.md | 5 +- docs/dev/ci_cd.rst | 12 ++-- docs/dev/doc_build.rst | 10 +-- docs/dev/source_build.rst | 58 ++++++++------- pyproject.toml | 8 ++- src/codegen/llvm/llvm_instance.h | 2 +- tests/python/codegen/llvm/test_aarch64.py | 17 +++++ tests/scripts/task_build_arm.sh | 2 +- tests/scripts/task_build_cpu.sh | 2 +- tests/scripts/task_build_gpu.sh | 2 +- tests/scripts/task_build_gpu_other.sh | 4 +- tests/scripts/task_install_build_dependencies.sh | 2 +- 20 files changed, 144 insertions(+), 223 deletions(-) diff --git a/.github/actions/build-wheel-for-publish/action.yml b/.github/actions/build-wheel-for-publish/action.yml index 8ff8cc979..e19878a74 100644 --- a/.github/actions/build-wheel-for-publish/action.yml +++ b/.github/actions/build-wheel-for-publish/action.yml @@ -39,66 +39,6 @@ inputs: runs: using: "composite" steps: - # Single source of truth for the LLVM toolchain version, shared by the cache - # key and the conda install steps below. - - name: Set LLVM version - shell: bash - run: echo "LLVM_VERSION=22.1.0" >> "$GITHUB_ENV" - - - name: Prepare LLVM cache path (Unix) - if: runner.os != 'Windows' - shell: bash - run: | - set -eux - sudo mkdir -p /opt/llvm - sudo chown -R "$(whoami)" /opt/llvm - - # ---- Cache LLVM prefix ---- - - name: Cache LLVM - uses: actions/[email protected] - id: llvm-cache - with: - path: ${{ runner.os == 'Windows' && 'C:/opt/llvm' || '/opt/llvm' }} - key: tirx-wheel-llvm-${{ env.LLVM_VERSION }}-${{ runner.os }}-${{ inputs.arch }}-v6 - - # ---- Install LLVM via conda (cache miss only) ---- - - name: Setup conda - if: steps.llvm-cache.outputs.cache-hit != 'true' - uses: conda-incubator/[email protected] - continue-on-error: true - id: conda1 - with: - # Miniforge 26.9.4-0 fails `conda init --all` on Windows; see IntelPython/dpnp#3119. - miniforge-version: "26.7.2-1" - conda-remove-defaults: true - - - name: Setup conda (retry with tar.bz2) - if: steps.llvm-cache.outputs.cache-hit != 'true' && steps.conda1.outcome == 'failure' - uses: conda-incubator/[email protected] - with: - miniforge-version: "26.7.2-1" - use-only-tar-bz2: true - conda-remove-defaults: true - - - name: Install LLVM (Unix) - if: steps.llvm-cache.outputs.cache-hit != 'true' && runner.os != 'Windows' - shell: bash -l {0} - run: | - set -eux - if [[ "${RUNNER_OS}" == "Linux" ]]; then - sudo mkdir -p /opt/llvm - sudo chown -R "$(whoami)" /opt/llvm - fi - conda create -q -p /opt/llvm -c conda-forge \ - "llvmdev=${LLVM_VERSION}" "clangdev=${LLVM_VERSION}" "compiler-rt=${LLVM_VERSION}" zlib zstd-static libxml2-devel \ - -y - - - name: Install LLVM (Windows) - if: steps.llvm-cache.outputs.cache-hit != 'true' && runner.os == 'Windows' - shell: cmd /C call {0} - run: | - call conda create -q -p C:\opt\llvm -c conda-forge llvmdev=%LLVM_VERSION% zlib zstd-static libxml2-devel -y - # The {project} placeholder is not expanded inside CIBW_ENVIRONMENT values, so # compute the forward-slash host path here (the Windows analog of the Linux # /project hardcode). @@ -118,27 +58,15 @@ runs: CIBW_ARCHS_LINUX: ${{ inputs.arch }} CIBW_ARCHS_MACOS: ${{ inputs.arch }} CIBW_ARCHS_WINDOWS: ${{ inputs.arch }} - # Linux builds run in cibuildwheel's default manylinux_2_28 container; - # bind-mount the cached LLVM prefix into it. Ignored on macOS/Windows, - # which build without a container. - CIBW_CONTAINER_ENGINE: "docker; create_args: --volume /opt/llvm:/opt/llvm:ro" - # Each per-OS block carries the toolchain location (conda LLVM prefix + - # llvm-config path), the universal static-link policy (TVM_TIRX_USE_LLVM --link-static - # and ZLIB_USE_STATIC_LIBS), and the CUDA sidecar. Feature defines that vary by - # wheel (e.g. TVM_TIRX_USE_METAL on macOS) come from the matrix via inputs.cmake_defines. - # One explicit block per build platform (macOS / Linux / Windows); cibuildwheel - # env overrides replace rather than merge, so there is no shared base block. + # Isolated builds install the pinned LLVM/Z3 SDKs from pyproject.toml. + # Keep per-platform feature settings and the CUDA runtime sidecar. CIBW_ENVIRONMENT_MACOS: >- - CMAKE_PREFIX_PATH="/opt/llvm" - 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 }}" + MACOSX_DEPLOYMENT_TARGET="14.0" + CMAKE_ARGS="-DTVM_TIRX_USE_LLVM=ON ${{ inputs.cmake_defines }}" CIBW_ENVIRONMENT_LINUX: >- - CMAKE_PREFIX_PATH="/opt/llvm" - LIBRARY_PATH="/opt/llvm/lib" - 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" + CMAKE_ARGS="-DTVM_TIRX_USE_LLVM=ON ${{ inputs.cmake_defines }} -DTVM_TIRX_PACKAGE_EXTRA_LIBS=/project/build-wheel-cuda/lib/libtvm_runtime_cuda.so" CIBW_ENVIRONMENT_WINDOWS: >- - CMAKE_PREFIX_PATH="C:/opt/llvm/Library" - PATH="C:/opt/llvm/Library/bin;$PATH" - 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 }}" + CMAKE_ARGS="-DTVM_TIRX_USE_LLVM=ON ${{ inputs.cmake_defines }} -DTVM_TIRX_PACKAGE_EXTRA_LIBS=${{ env.TVM_CUDA_EXTRA_LIB }}" # Turns the wheel-specific assertions in # tests/python/runtime/test_validate_wheel_library.py # ON (they skip unless these are set). Every published wheel is LLVM-enabled, diff --git a/.github/actions/setup/action.yml b/.github/actions/setup/action.yml index 7005e82b1..4f71bf8b7 100644 --- a/.github/actions/setup/action.yml +++ b/.github/actions/setup/action.yml @@ -16,48 +16,19 @@ # under the License. name: Setup TVM CI environment -description: Set up the cached conda build environment and install tvm-ffi. +description: Set up Python build tools and install tvm-ffi. runs: - using: "composite" - steps: - - uses: actions/[email protected] - env: - CACHE_NUMBER: 2 - with: - path: ~/conda_pkgs_dir - key: ${{ runner.os }}-conda-${{ env.CACHE_NUMBER }}-${{ hashFiles('ci/wheel/build-environment.yaml') }} - - uses: conda-incubator/[email protected] - continue-on-error: true - id: conda1 - with: - activate-environment: tvm-build - channel-priority: strict - environment-file: ci/wheel/build-environment.yaml - auto-activate-base: false - # Miniforge 26.9.4-0 fails `conda init --all` on Windows; see IntelPython/dpnp#3119. - miniforge-version: "26.7.2-1" - python-version: "3.10" - conda-remove-defaults: true - - uses: conda-incubator/[email protected] - if: steps.conda1.outcome == 'failure' - with: - activate-environment: tvm-build - channel-priority: strict - environment-file: ci/wheel/build-environment.yaml - auto-activate-base: false - miniforge-version: "26.7.2-1" - use-only-tar-bz2: true - python-version: "3.10" - conda-remove-defaults: true - - name: Conda info - shell: pwsh - run: | - mamba info - mamba list - mamba info --envs - mamba list --name base - - name: Install tvm-ffi pip package - shell: bash -l {0} - run: | - pip install -v ./3rdparty/tvm-ffi + using: "composite" + steps: + - uses: actions/[email protected] + with: + python-version: "3.12" + cache: pip + cache-dependency-path: pyproject.toml + - name: Install build and test tools + shell: bash + run: python -m pip install "cmake>=3.26" ninja pytest numpy scipy cython + - name: Install tvm-ffi pip package + shell: bash + run: python -m pip install -v ./3rdparty/tvm-ffi diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 603cfcbe0..8c8641942 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -53,8 +53,9 @@ jobs: id: env_vars uses: ./.github/actions/detect-env-vars - name: Build TIRx wheels - shell: bash -l {0} + shell: bash env: + MACOSX_DEPLOYMENT_TARGET: "14.0" CMAKE_BUILD_PARALLEL_LEVEL: ${{ steps.env_vars.outputs.cpu_count }} run: | set -euxo pipefail @@ -63,7 +64,7 @@ jobs: pip wheel --no-deps -w dist . -v pip install --no-deps --force-reinstall dist/apache_tvm_tirx-*.whl - name: Install TIRx from wheels - shell: bash -l {0} + shell: bash run: | set -euxo pipefail pip install psutil cloudpickle ml_dtypes numpy packaging scipy typing_extensions @@ -75,18 +76,18 @@ jobs: pip install --no-deps dist/*.whl - name: Test - shell: bash -l {0} + shell: bash run: >- python -m pytest -v tests/python/codegen/llvm/test_minimal.py tests/python/runtime/test_validate_wheel_library.py tests/python/script - name: Minimal Metal Compile-Only - shell: bash -l {0} + shell: bash run: | set -euxo pipefail python -m pytest -v -s 'tests/python/codegen/gpu_common/test_allreduce.py::test_allreduce_sum_compile' python -m pytest -v -s 'tests/python/backend/metal/codegen/test_basic.py::test_func_with_trailing_pod_params' - name: Minimal Metal Compile-and-Run - shell: bash -l {0} + shell: bash run: | set -euxo pipefail python -m pytest -v -s tests/python/backend/metal diff --git a/AGENTS.md b/AGENTS.md index 291a9ae3b..24cbe7d4c 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -55,7 +55,9 @@ the repository root; the default virtual environment is `.venv`. ### Prerequisites - Python 3.10+, a C++20 compiler, CMake 3.26+, and Ninja. -- LLVM development libraries and `llvm-config` for the default LLVM backend. +- The pinned LLVM/Z3 static SDKs are installed as Python build dependencies. + No Conda environment or system LLVM is needed; the LLVM SDK supports Linux + x86_64/aarch64, Windows AMD64/ARM64, and macOS arm64 14+. - Initialize dependencies: `git submodule update --init --recursive`. - Install the relevant device SDK when enabling a device runtime. @@ -84,8 +86,9 @@ runtimes such as Metal, ROCm, Vulkan, and OpenCL have their own ### C++-only build ```bash -cmake -S . -B build_cpp -DCMAKE_BUILD_TYPE=RelWithDebInfo -cmake --build build_cpp --parallel --config RelWithDebInfo --target tvm_tirx_compiler +uv pip install cmake ninja "mlc-llvm-static[all]==23.1.1" "mlc-z3-static==5.3.1.post0" +uv run --no-sync cmake -S . -B build_cpp -DCMAKE_BUILD_TYPE=RelWithDebInfo +uv run --no-sync cmake --build build_cpp --parallel --config RelWithDebInfo --target tvm_tirx_compiler ``` The `runtime` target builds the core runtime and enabled device runtimes. diff --git a/ci/wheel/build-environment.yaml b/ci/wheel/build-environment.yaml deleted file mode 100644 index 3b2c4dd16..000000000 --- a/ci/wheel/build-environment.yaml +++ /dev/null @@ -1,42 +0,0 @@ -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the specific -# language governing permissions and limitations under the License. - -# Build environment for TVM wheel building. -# This environment provides the necessary dependencies for building TVM wheels. -name: tvm-wheel-build - -# The conda channels to lookup the dependencies -channels: - - conda-forge - -# The packages to install to the environment -dependencies: - # Core build tools - - cmake >=3.24 - - ninja - - make - - llvmdev >=11 - - python >=3.10 - - pip - - git - - bzip2 - - zlib - - zstd-static - - pytest - - numpy - - scipy - - cython - - libxml2-devel diff --git a/ci/wheel/windows_build_libtvm_runtime_cuda.bat b/ci/wheel/windows_build_libtvm_runtime_cuda.bat index 8b3b2204c..061a5518a 100644 --- a/ci/wheel/windows_build_libtvm_runtime_cuda.bat +++ b/ci/wheel/windows_build_libtvm_runtime_cuda.bat @@ -35,8 +35,8 @@ rem on PATH in this shell. set "conda_exe=conda" where conda >nul 2>nul || set "conda_exe=%CONDA%\Scripts\conda.exe" -rem Install the pinned CUDA toolkit via conda from the nvidia channel, mirroring the -rem LLVM-via-conda install used elsewhere. The win-64 channel caps at 13.0.x, so this +rem Install the pinned CUDA toolkit via conda from the nvidia channel. +rem The win-64 channel caps at 13.0.x, so this rem pins 13.0.2 -- slightly behind the Linux image's CUDA 13.1, which is harmless: the rem sidecar has no device code and links the CUDA runtime by soname only. The nvidia rem CDN occasionally returns a transient HTTP 5xx, so retry once; a half-finished first diff --git a/cmake/modules/contrib/Z3.cmake b/cmake/modules/contrib/Z3.cmake index 37c37f74c..d7e14e862 100644 --- a/cmake/modules/contrib/Z3.cmake +++ b/cmake/modules/contrib/Z3.cmake @@ -85,7 +85,7 @@ else() if(TVM_Z3_REQUIRED) message(FATAL_ERROR "TVM_TIRX_USE_Z3 is ON, but Z3 was not found. Install the static Z3 development " - "package with `pip install 'mlc-z3-static>=4.16.0'`, or point " + "package with `uv pip install 'mlc-z3-static==5.3.1.post0'`, or point " "Z3_DIR/CMAKE_PREFIX_PATH at a Z3 installation.") endif() message(STATUS "Build without Z3 SMT solver support") diff --git a/cmake/utils/FindLLVM.cmake b/cmake/utils/FindLLVM.cmake index de5fb324c..5091af0df 100644 --- a/cmake/utils/FindLLVM.cmake +++ b/cmake/utils/FindLLVM.cmake @@ -44,7 +44,7 @@ endfunction() # Usage: # find_llvm(${USE_LLVM} [${LLVM_VERSION}]) # -# - When USE_LLVM=ON, use auto search +# - When USE_LLVM=ON, prefer the Python mlc-llvm-static SDK, then auto search # - When USE_LLVM=/path/to/llvm-config, use corresponding config # - The optional LLVM_VERSION=<required version> which will find a matching version # If LLVM_VERSION=10 then it will find 10.X.X, any version of 10 @@ -66,6 +66,33 @@ macro(find_llvm use_llvm) endif() if(${LLVM_CONFIG} MATCHES ${IS_TRUE_PATTERN}) + # Match Z3 discovery: prefer the build Python's static SDK unless an + # explicit LLVM_DIR selects an external installation. + if(NOT LLVM_DIR) + find_package(Python3 COMPONENTS Interpreter QUIET) + if(Python3_EXECUTABLE) + execute_process( + COMMAND "${Python3_EXECUTABLE}" -m mlc_llvm_static.config --cmake-dir + OUTPUT_VARIABLE LLVM_STATIC_CMAKE_DIR + OUTPUT_STRIP_TRAILING_WHITESPACE + ERROR_QUIET + RESULT_VARIABLE LLVM_STATIC_RESULT + ) + if(LLVM_STATIC_RESULT EQUAL 0 AND EXISTS "${LLVM_STATIC_CMAKE_DIR}") + set(LLVM_DIR "${LLVM_STATIC_CMAKE_DIR}") + get_filename_component(LLVM_STATIC_PREFIX "${LLVM_DIR}/../../.." ABSOLUTE) + list(PREPEND CMAKE_PREFIX_PATH "${LLVM_STATIC_PREFIX}") + set(ZLIB_USE_STATIC_LIBS ON) + # This provider supplies imported static targets, including its + # transitive dependencies; never select an ambient LLVM dylib. + set(LLVM_LINK_LLVM_DYLIB OFF) + if(TVM_TIRX_BUILD_PYTHON_MODULE) + install(DIRECTORY "${LLVM_STATIC_PREFIX}/../licenses/" + DESTINATION licenses COMPONENT tvm_tirx FILES_MATCHING PATTERN "*.txt") + endif() + endif() + endif() + endif() # This is a workaround for an upstream LLVM issue [0], in which # the `CMAKE_INSTALL_LIBDIR` variable is used before definition. # While there is an LLVM PR to resolve this fix [1], as of @@ -78,13 +105,16 @@ macro(find_llvm use_llvm) find_package(LLVM ${llvm_version_required} QUIET CONFIG) if(NOT LLVM_FOUND) message(FATAL_ERROR - "LLVM development files were not found. Install LLVM 15 or newer, including " + "LLVM development files were not found. Install the pinned build SDK with " + "`uv pip install 'mlc-llvm-static[all]==23.1.1'`, or install LLVM 15 or newer, including " "its development headers and libraries (for example, llvm-dev on Debian/Ubuntu " "or llvm-devel on Fedora). Set LLVM_DIR to the directory containing " "LLVMConfig.cmake, add the LLVM installation to CMAKE_PREFIX_PATH, or set " "TVM_TIRX_USE_LLVM to the full path to llvm-config. To build without LLVM, " "explicitly set TVM_TIRX_USE_LLVM=OFF.") endif() + # LLVMConfig.cmake exports command-line flags as one space-separated string. + separate_arguments(LLVM_DEFINITIONS NATIVE_COMMAND "${LLVM_DEFINITIONS}") llvm_map_components_to_libnames(LLVM_LIBS "all") if (NOT LLVM_LIBS) message(STATUS "Not found - LLVM_LIBS") diff --git a/docs/README.md b/docs/README.md index f963e32ff..6f3ab3675 100644 --- a/docs/README.md +++ b/docs/README.md @@ -17,13 +17,12 @@ # TIRx Documentation -See [Build from Source](dev/source_build.rst) for the Miniforge/mamba and uv -environment. After building TIRx, install the documentation dependencies and build from the +See [Build from Source](dev/source_build.rst) for the uv virtual environment. After building TIRx, install the documentation dependencies and build from the repository root: ```bash uv pip install --group docs -uv run python -m sphinx -b html -W docs docs/_build/html +uv run --no-sync python -m sphinx -b html -W docs docs/_build/html ``` Set `BUILD_CPP_DOCS=1` to also generate the C++ API reference; this requires Doxygen. diff --git a/docs/dev/ci_cd.rst b/docs/dev/ci_cd.rst index f18a90e97..573613f73 100644 --- a/docs/dev/ci_cd.rst +++ b/docs/dev/ci_cd.rst @@ -91,7 +91,7 @@ Reproduce locally with: uv pip install --reinstall --verbose --group test -e . # Run the CPU tests - uv run pytest -vvs tests/python -m "not gpu" + uv run --no-sync pytest -vvs tests/python -m "not gpu" Use ``-m gpu`` for device tests with the matching backend, SDK, and hardware. Pass a test file or directory to focus on the component you changed. @@ -101,10 +101,12 @@ Build Python Wheels CI builds wheels using `cibuildwheel <https://cibuildwheel.pypa.io/>`__ on Linux (x86_64, aarch64), Windows (AMD64), and macOS (arm64). Wheel configuration -lives in ``[tool.cibuildwheel]`` in ``pyproject.toml``. Configure the platform's -LLVM toolchain as in the `wheel build action -<https://github.com/apache/tvm-tirx/blob/main/.github/actions/build-wheel-for-publish/action.yml>`__; -Linux builds also require Docker and the LLVM prefix mounted into the build image. +lives in ``[tool.cibuildwheel]`` in ``pyproject.toml``. Isolated builds install +the exact LLVM/Z3 SDK pins from ``[build-system].requires``; no separate LLVM +prefix or Conda environment is needed. Linux builds require Docker. macOS arm64 +wheels require ``MACOSX_DEPLOYMENT_TARGET=14.0``, matching the pinned SDK. +The separate Windows CUDA runtime sidecar still uses its existing Conda CUDA +toolkit installer; that is independent of LLVM/Z3 discovery. To build wheels locally: diff --git a/docs/dev/doc_build.rst b/docs/dev/doc_build.rst index 874bfbc0a..198b24dbc 100644 --- a/docs/dev/doc_build.rst +++ b/docs/dev/doc_build.rst @@ -25,7 +25,7 @@ Building the docs requires the Python package to be installed first; see .. admonition:: Prerequisite :class: hint - - Use the activated mamba environment from :doc:`source_build`. + - Use the virtual environment from :doc:`source_build`. - Run commands from the repository root. - Install the documentation tools with ``uv pip install --group docs``. - Optional: install ``Doxygen`` if you plan to generate the C++ API @@ -38,7 +38,7 @@ Rebuild and serve the documentation locally with live reload: .. code-block:: bash - uv run sphinx-autobuild docs docs/_build/html \ + uv run --no-sync sphinx-autobuild docs docs/_build/html \ --ignore docs/reference/python/generated --ignore docs/reference/cpp/generated Open ``http://127.0.0.1:8000`` after the initial build completes. @@ -50,7 +50,7 @@ Generate the HTML documentation once, with warnings treated as errors: .. code-block:: bash - uv run python -m sphinx -b html -W docs docs/_build/html + uv run --no-sync python -m sphinx -b html -W docs docs/_build/html Open ``docs/_build/html/index.html`` to browse the result. @@ -71,12 +71,12 @@ Set ``BUILD_CPP_DOCS=1`` on the desired build command to enable the extra step: .. code-block:: bash # Interactive build with auto-rebuild on C++ header changes - BUILD_CPP_DOCS=1 uv run sphinx-autobuild docs docs/_build/html \ + BUILD_CPP_DOCS=1 uv run --no-sync sphinx-autobuild docs docs/_build/html \ --ignore docs/reference/python/generated --ignore docs/reference/cpp/generated \ --watch include # One-off build - BUILD_CPP_DOCS=1 uv run python -m sphinx -b html -W docs docs/_build/html + BUILD_CPP_DOCS=1 uv run --no-sync python -m sphinx -b html -W docs docs/_build/html Cleanup ------- diff --git a/docs/dev/source_build.rst b/docs/dev/source_build.rst index 23ed8301a..68ed1554e 100644 --- a/docs/dev/source_build.rst +++ b/docs/dev/source_build.rst @@ -26,24 +26,11 @@ This guide provides instructions on how to build the TIRx package from source. - Python: 3.10 or newer. - Compiler: a C++20-capable GCC, Clang, or MSVC toolchain. - Build tools: Git, CMake 3.26+, and uv. - - LLVM: development libraries and ``llvm-config`` from LLVM 15 or newer. - - On most platforms, you can get LLVM and the build dependencies through - `Miniforge <https://github.com/conda-forge/miniforge>`__: - - .. code-block:: bash - - mamba create -n tirx-dev -c conda-forge python=3.12 llvmdev cmake git uv - mamba activate tirx-dev - llvm-config --version - - Use this mamba environment for all commands. Keep ``uv run`` in the same - environment without resynchronizing the packages installed by ``uv pip``: - - .. code-block:: bash - - export UV_PROJECT_ENVIRONMENT="$CONDA_PREFIX" - export UV_NO_SYNC=1 + - The pinned ``mlc-llvm-static[all]`` and ``mlc-z3-static`` development SDKs + are installed automatically as isolated Python build dependencies. + LLVM and Z3 are linked statically; they are not runtime Python requirements. + - The pinned LLVM SDK supports Linux x86_64/aarch64 (glibc 2.28+), + Windows AMD64/ARM64, and macOS arm64 (14+). Build the Python Package ------------------------ @@ -54,6 +41,7 @@ Download the source via: git clone --recursive https://github.com/apache/tvm-tirx cd tvm-tirx + uv venv .. note:: @@ -85,7 +73,8 @@ automatically switched on when available): Available CMake options (see `CMakeLists.txt <https://github.com/apache/tvm-tirx/blob/main/CMakeLists.txt>`__) include: -- ``TVM_TIRX_USE_LLVM`` -- Enable LLVM, or select an ``llvm-config`` command (default: ``ON``). +- ``TVM_TIRX_USE_LLVM`` -- Prefer the build Python's static LLVM SDK, or select an + explicit ``LLVM_DIR`` / ``llvm-config`` command (default: ``ON``). ``OFF`` disables LLVM. - ``TVM_TIRX_USE_CUDA`` -- Enable the CUDA runtime (default: ``AUTO``). - ``TVM_TIRX_USE_METAL`` -- Enable the Metal runtime on macOS (default: ``OFF``). - ``TVM_TIRX_USE_Z3`` -- Enable the Z3 solver (default: ``AUTO``). @@ -98,8 +87,8 @@ Verify the installation: .. code-block:: bash - uv run python -c "import tvm_tirx; print(tvm_tirx.__version__)" - uv run tvm-tirx-config -h + uv run --no-sync python -c "import tvm_tirx; print(tvm_tirx.__version__)" + uv run --no-sync tvm-tirx-config -h .. tip:: @@ -122,14 +111,31 @@ Verify the installation: Build Wheels with Static LLVM ----------------------------- -When shipping wheels, link LLVM statically so users do not need the same shared -LLVM library installed. Install its development dependencies and export the -static-link setting before building the wheel: +The default isolated wheel build installs the pinned SDKs and links LLVM and Z3 +statically. No Conda environment or system LLVM installation is needed: .. code-block:: bash - mamba install -c conda-forge zlib zstd-static libxml2-devel - export CMAKE_ARGS="-DTVM_TIRX_USE_LLVM='llvm-config --link-static' -DZLIB_USE_STATIC_LIBS=ON" + uv build --wheel + +For a direct CMake build or a build without Python build isolation, install the +same SDK pins and build tools into the virtual environment first: + +.. code-block:: bash + + uv pip install cmake ninja "mlc-llvm-static[all]==23.1.1" "mlc-z3-static==5.3.1.post0" + uv run --no-sync cmake -S . -B build_cpp -G Ninja -DCMAKE_BUILD_TYPE=Release + uv run --no-sync cmake --build build_cpp --parallel + +``TVM_TIRX_USE_LLVM=ON`` probes that Python environment before generic LLVM +search. The SDK includes static zlib/zstd; its LLVM build disables XML2. +An explicit ``LLVM_DIR`` or ``TVM_TIRX_USE_LLVM=/path/to/llvm-config`` still +selects an external LLVM installation, whose dependencies must be supplied +separately. Use ``TVM_TIRX_USE_LLVM=OFF`` to build without LLVM. + +When distributing macOS wheels built with this SDK, set +``MACOSX_DEPLOYMENT_TARGET=14.0`` so the wheel records the SDK's minimum OS +version. The wheel CI sets this explicitly. See :doc:`ci_cd` for wheel builds and the publication toolchain configuration. diff --git a/pyproject.toml b/pyproject.toml index 3be000989..4519998c1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -88,8 +88,12 @@ docs = [ tvm-tirx-config = "tvm_tirx.config:__main__" [build-system] -# mlc-z3-static ships the PIC static libz3 + headers consumed by TVM_TIRX_USE_Z3=ON. -requires = ["scikit-build-core>=0.11", "mlc-z3-static>=4.16.0"] +# Static development SDKs are build requirements, not runtime dependencies. +requires = [ + "scikit-build-core>=0.11", + "mlc-llvm-static[all]==23.1.1", + "mlc-z3-static==5.3.1.post0", +] build-backend = "scikit_build_core.build" [tool.scikit-build] diff --git a/src/codegen/llvm/llvm_instance.h b/src/codegen/llvm/llvm_instance.h index 425490a2a..7424d175a 100644 --- a/src/codegen/llvm/llvm_instance.h +++ b/src/codegen/llvm/llvm_instance.h @@ -42,7 +42,7 @@ // LLVM compatibility macro #if TVM_LLVM_VERSION >= 200 -#define llvmGetPointerTo(arg, offset) (llvm::PointerType::get((arg), (offset))) +#define llvmGetPointerTo(arg, offset) (llvm::PointerType::get((arg)->getContext(), (offset))) #else #define llvmGetPointerTo(arg, offset) (arg->getPointerTo(offset)) #endif diff --git a/tests/python/codegen/llvm/test_aarch64.py b/tests/python/codegen/llvm/test_aarch64.py index 1db9d6540..6e0649236 100644 --- a/tests/python/codegen/llvm/test_aarch64.py +++ b/tests/python/codegen/llvm/test_aarch64.py @@ -385,6 +385,11 @@ def test_eq(dtype): r"cm(p)?eq\tp[0-9].[shdb],( p[0-9]/[zm],)? z[0-9].[shdb], z[0-9].[shdb]", assembly ) + if llvm.version_major() >= 23 and dtype in ("float", "float16"): + # LLVM 23 can use NEON for both the main loop and the epilogue. + loads += re.findall(r"ld[rp]\tq[0-9]+", assembly) + matches += re.findall(r"fcmeq\tv[0-9]+\.[0-9]+[hs]", assembly) + assert len(loads) > 1 # The number of SVE compares depends on the LLVM cost model: LLVM <= 17 # interleaves the scalable loop by two, while LLVM 20 emits a fixed-width @@ -426,6 +431,12 @@ def test_neq(dtype): r"cm(p)?(gt|ne)\tp[0-9].[shdb],( p[0-9]/[zm],)? z[0-9].[shdb], z[0-9].[shdb]", assembly ) + if llvm.version_major() >= 23 and dtype in ("float", "float16"): + # LLVM 23 can use NEON for both the main loop and the epilogue. + loads += re.findall(r"ld[rp]\tq[0-9]+", assembly) + matches += re.findall(r"fcmgt\tv[0-9]+\.[0-9]+[hs]", assembly) + assert re.search(r"orr\tv[0-9]+\.16b", assembly) + assert len(loads) > 1 # The number of SVE compares depends on the LLVM cost model: LLVM <= 17 # interleaves the scalable loop by two, while LLVM 20 emits a fixed-width @@ -536,6 +547,12 @@ def test_not(dtype): r"eor\tz[0-9].[shdb],( p[0-9]/[zm],)? z[0-9].[shdb], z[0-9].[shdb]", assembly ) + if llvm.version_major() >= 23: + # Full-vector loads need no predicate. LLVM also represents bytewise + # complement as 255 - x, which is identical to xor with all ones. + loads += re.findall(r"ldr\tz[0-9]+,", assembly) + matches += re.findall(r"subr\tz[0-9]+\.b, z[0-9]+\.b, #255", assembly) + assert len(loads) > 1 assert len(matches) > 1 diff --git a/tests/scripts/task_build_arm.sh b/tests/scripts/task_build_arm.sh index 576687813..0527a86bc 100755 --- a/tests/scripts/task_build_arm.sh +++ b/tests/scripts/task_build_arm.sh @@ -20,7 +20,7 @@ set -euxo pipefail export CMAKE_ARGS=" -DTVM_TIRX_BUILD_TESTS=ON - -DTVM_TIRX_USE_LLVM=llvm-config-17 + -DTVM_TIRX_USE_LLVM=ON -DCMAKE_CXX_FLAGS=-Werror " uv build --wheel --no-build-isolation --offline --python python3 --out-dir dist . diff --git a/tests/scripts/task_build_cpu.sh b/tests/scripts/task_build_cpu.sh index 2e5e54009..7e1f31c01 100755 --- a/tests/scripts/task_build_cpu.sh +++ b/tests/scripts/task_build_cpu.sh @@ -20,7 +20,7 @@ set -euxo pipefail export CMAKE_ARGS=" -DTVM_TIRX_BUILD_TESTS=ON - -DTVM_TIRX_USE_LLVM='/usr/bin/llvm-config-17 --link-static' + -DTVM_TIRX_USE_LLVM=ON -DCMAKE_CXX_FLAGS='-Wno-error=range-loop-construct -Wno-error=comment' " uv build --wheel --no-build-isolation --offline --python python3 --out-dir dist . diff --git a/tests/scripts/task_build_gpu.sh b/tests/scripts/task_build_gpu.sh index d58c23324..aafb66281 100755 --- a/tests/scripts/task_build_gpu.sh +++ b/tests/scripts/task_build_gpu.sh @@ -23,7 +23,7 @@ export CMAKE_ARGS=" -DTVM_TIRX_USE_CUDA=ON -DTVM_TIRX_USE_VULKAN=OFF -DTVM_TIRX_USE_OPENCL=OFF - -DTVM_TIRX_USE_LLVM='/usr/bin/llvm-config-15 --link-static' + -DTVM_TIRX_USE_LLVM=ON -DCMAKE_CXX_FLAGS=-Werror -DCMAKE_CUDA_ARCHITECTURES=75 " diff --git a/tests/scripts/task_build_gpu_other.sh b/tests/scripts/task_build_gpu_other.sh index 98bb57df1..88392f0f9 100755 --- a/tests/scripts/task_build_gpu_other.sh +++ b/tests/scripts/task_build_gpu_other.sh @@ -21,8 +21,10 @@ set -euxo pipefail # Keep these libraries separate from the published GPU wheel artifacts. uv pip install --python python3 --no-deps --target build/python ./3rdparty/tvm-ffi +uv pip install --python python3 --target build/python \ + "mlc-llvm-static[all]==23.1.1" "mlc-z3-static==5.3.1.post0" export PYTHONPATH="$PWD/build/python" cmake -S . -B build -GNinja -DCMAKE_BUILD_TYPE=RelWithDebInfo \ -DTVM_TIRX_USE_OPENCL=ON -DTVM_TIRX_USE_VULKAN=ON -DTVM_TIRX_USE_ROCM=ON \ - -DTVM_TIRX_USE_LLVM='/usr/bin/llvm-config-15 --link-static' -DCMAKE_CXX_FLAGS=-Werror + -DTVM_TIRX_USE_LLVM=ON -DCMAKE_CXX_FLAGS=-Werror cmake --build build --target tvm_tirx_compiler tvm_runtime_opencl tvm_runtime_vulkan tvm_runtime_rocm diff --git a/tests/scripts/task_install_build_dependencies.sh b/tests/scripts/task_install_build_dependencies.sh index 2b84c57c7..8391ed048 100755 --- a/tests/scripts/task_install_build_dependencies.sh +++ b/tests/scripts/task_install_build_dependencies.sh @@ -20,7 +20,7 @@ set -euxo pipefail rm -rf dist uv pip install --python python3 --target .local/python \ - "scikit-build-core>=0.11,!=1.1.0" "setuptools-scm>=8" "cython>=3.2.8" "mlc-z3-static>=4.16.0" + "scikit-build-core>=0.11,!=1.1.0" "setuptools-scm>=8" "cython>=3.2.8" "mlc-llvm-static[all]==23.1.1" "mlc-z3-static==5.3.1.post0" export PYTHONPATH="$PWD/.local/python" uv build --wheel --no-build-isolation --offline --python python3 --out-dir dist ./3rdparty/tvm-ffi
