This is an automated email from the ASF dual-hosted git repository.
tqchen pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tvm.git
The following commit(s) were added to refs/heads/main by this push:
new 8a43b6708c [BUILD] Enable LLVM and automatic CUDA in standalone TIRx
(#20755)
8a43b6708c is described below
commit 8a43b6708c8aabaa051dd9cbb1c23197c1869c5a
Author: Tianqi Chen <[email protected]>
AuthorDate: Fri Oct 16 09:39:26 2026 -0400
[BUILD] Enable LLVM and automatic CUDA in standalone TIRx (#20755)
Standalone TIRx builds now enable LLVM by default and detect CUDA when a
complete toolkit is available. Preserve explicit backend and toolchain
overrides, explain missing LLVM development dependencies, and use the
same defaults for normal Python package installation.
---
docs/tirx/install.rst | 24 +++++++++++++++++++++---
tirx/CMakeLists.txt | 6 ++++--
tirx/cmake/modules/CUDA.cmake | 24 ++++++++++++++++--------
tirx/cmake/utils/FindLLVM.cmake | 11 ++++++++++-
tirx/pyproject.toml | 3 ---
tirx/src/sym/rewrite_simplify.cc | 2 +-
6 files changed, 52 insertions(+), 18 deletions(-)
diff --git a/docs/tirx/install.rst b/docs/tirx/install.rst
index 95e917b523..592aa0a4eb 100644
--- a/docs/tirx/install.rst
+++ b/docs/tirx/install.rst
@@ -97,7 +97,7 @@ its bundled FFI dependency, then use native CMake options
(CMake 3.26 or newer):
git submodule update --init --recursive tirx/3rdparty/tvm-ffi
cmake -S tirx -B tirx/build -G Ninja -DCMAKE_BUILD_TYPE=Release \
- -DTVM_TIRX_USE_LLVM=ON -DTVM_TIRX_BUILD_TESTS=ON
+ -DTVM_TIRX_BUILD_TESTS=ON
cmake --build tirx/build
ctest --test-dir tirx/build
cmake --install tirx/build --prefix /path/to/install
@@ -106,11 +106,29 @@ Core feature options use the ``TVM_TIRX_USE_`` prefix.
SDK selectors such as
``TVM_TIRX_USE_CUDA`` and ``TVM_TIRX_USE_LLVM`` also accept an SDK path or
``llvm-config`` command. Compiler caches, linkers, and toolchain flags use
standard CMake settings. The standalone core does not read ``config.cmake``.
+
+LLVM is enabled by default and requires LLVM 15 or newer with development
+headers and libraries. Install ``llvm-dev`` on Debian/Ubuntu, ``llvm-devel``
+on Fedora, or ``llvmdev`` from conda-forge. Explicitly set
+``TVM_TIRX_USE_LLVM=OFF`` to omit LLVM support.
+
+CUDA defaults to ``AUTO``: a usable toolkit, including its compiler, runtime,
+and driver library or stub, enables CUDA; otherwise the build continues
+without CUDA.
+
C++ tests are off by default; enabling them supplies GTest in the test subtree.
Installation includes public headers, libraries, and CMake package targets.
-For a Python core package build, pass these options through the ``CMAKE_ARGS``
-environment variable. Quote values containing spaces inside the variable::
+With the dependencies above installed and the FFI submodule initialized,
+build and install the Python core package using the same defaults::
+
+ python -m pip install ./tirx
+ python -c "import tvm_tirx"
+
+This installs the ``apache-tvm-tirx`` distribution and its Python dependencies.
+To override the defaults, pass CMake options through ``CMAKE_ARGS`` or pip's
+``--config-settings=cmake.define.<OPTION>=<VALUE>``. Quote values containing
+spaces inside ``CMAKE_ARGS``::
CMAKE_ARGS='-DTVM_TIRX_USE_LLVM="llvm-config --link-static"' \
python -m pip install -v ./tirx
diff --git a/tirx/CMakeLists.txt b/tirx/CMakeLists.txt
index 234f0d4776..efe2deee46 100644
--- a/tirx/CMakeLists.txt
+++ b/tirx/CMakeLists.txt
@@ -42,7 +42,7 @@ tvm_tirx_option(TVM_TIRX_USE_CUSTOM_LOGGING BOOL OFF "Use
user-defined logging i
# ######### LLVM ##########
-tvm_tirx_option(TVM_TIRX_USE_LLVM STRING OFF "Build with LLVM (OFF, ON, or
llvm-config command)")
+tvm_tirx_option(TVM_TIRX_USE_LLVM STRING ON "Build with LLVM (OFF, ON, or
llvm-config command)")
# ######### Z3 ##########
@@ -51,7 +51,7 @@ set_property(CACHE TVM_TIRX_USE_Z3 PROPERTY STRINGS OFF ON
AUTO)
# ######### CUDA ##########
-tvm_tirx_option(TVM_TIRX_USE_CUDA STRING OFF "Build with CUDA (OFF, ON, or SDK
path)")
+tvm_tirx_option(TVM_TIRX_USE_CUDA STRING AUTO "Build with CUDA (OFF, ON, AUTO,
or SDK path)")
# ######### Other device runtimes ##########
@@ -323,6 +323,8 @@ if(NOT PROJECT_IS_TOP_LEVEL)
# The parent checks the core version and reuses its dependency finders.
set(TVM_TIRX_VERSION "${TVM_TIRX_VERSION}" PARENT_SCOPE)
set(TVM_TIRX_CMAKE_DIR "${TVM_TIRX_CMAKE_DIR}" PARENT_SCOPE)
+ # Parent runtime extensions must use the resolved AUTO selection, not the
cache.
+ set(TVM_TIRX_USE_CUDA "${TVM_TIRX_USE_CUDA}" PARENT_SCOPE)
return()
endif()
diff --git a/tirx/cmake/modules/CUDA.cmake b/tirx/cmake/modules/CUDA.cmake
index 68525b7d87..c98527092e 100644
--- a/tirx/cmake/modules/CUDA.cmake
+++ b/tirx/cmake/modules/CUDA.cmake
@@ -16,7 +16,20 @@
# under the License.
# CUDA Module
-find_cuda(${TVM_TIRX_USE_CUDA} OFF)
+if("${TVM_TIRX_USE_CUDA}" MATCHES "^[Aa][Uu][Tt][Oo]$")
+ find_cuda(ON OFF)
+ # Keep AUTO in the cache, but resolve it before any backend build guards.
+ # FindCUDA requires nvcc and headers, but may accept only static cudart.
+ # Our runtime needs shared cudart and the driver library (or its toolkit
stub).
+ if(CUDA_FOUND AND CUDA_CUDART_LIBRARY AND CUDA_CUDA_LIBRARY)
+ set(TVM_TIRX_USE_CUDA ON)
+ else()
+ set(TVM_TIRX_USE_CUDA OFF)
+ message(STATUS "CUDA AUTO: usable toolkit not found; building without
CUDA")
+ endif()
+else()
+ find_cuda(${TVM_TIRX_USE_CUDA} OFF)
+endif()
if(CUDA_FOUND)
# always set the includedir when CUDA is available
@@ -48,13 +61,8 @@ if(TVM_TIRX_USE_CUDA)
# [0] https://github.com/Kitware/CMake/commit/6377a438
set(CMAKE_CUDA_USE_RESPONSE_FILE_FOR_INCLUDES 0)
- if(NOT DEFINED CMAKE_CUDA_ARCHITECTURES)
- if(CMAKE_VERSION VERSION_LESS "3.24")
- message(FATAL_ERROR "CMAKE_CUDA_ARCHITECTURES not set. Please upgrade
CMake to 3.24 to use native, or set CMAKE_CUDA_ARCHITECTURES manually")
- endif()
- message(STATUS "CMAKE_CUDA_ARCHITECTURES not set, using native")
- set(CMAKE_CUDA_ARCHITECTURES native)
- endif()
+ # Use CMake's compiler-selected architectures unless the user overrides them.
+ # Unlike 'native', this also works on build hosts without a visible GPU.
endif(TVM_TIRX_USE_CUDA)
if(TVM_TIRX_USE_CUDA)
diff --git a/tirx/cmake/utils/FindLLVM.cmake b/tirx/cmake/utils/FindLLVM.cmake
index e249de8b01..de5fb324ca 100644
--- a/tirx/cmake/utils/FindLLVM.cmake
+++ b/tirx/cmake/utils/FindLLVM.cmake
@@ -75,7 +75,16 @@ macro(find_llvm use_llvm)
# [1] https://github.com/llvm/llvm-project/pull/83807
include(GNUInstallDirs)
- find_package(LLVM ${llvm_version_required} REQUIRED CONFIG)
+ 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 "
+ "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()
llvm_map_components_to_libnames(LLVM_LIBS "all")
if (NOT LLVM_LIBS)
message(STATUS "Not found - LLVM_LIBS")
diff --git a/tirx/pyproject.toml b/tirx/pyproject.toml
index 98afc68828..9043a5163e 100644
--- a/tirx/pyproject.toml
+++ b/tirx/pyproject.toml
@@ -122,9 +122,6 @@ logging.level = "INFO"
[tool.scikit-build.cmake.define]
TVM_TIRX_BUILD_PYTHON_MODULE = "ON"
-TVM_TIRX_USE_CUDA = "OFF"
-# Statically link Z3 from the mlc-z3-static build dependency by default.
-TVM_TIRX_USE_Z3 = "AUTO"
TVM_TIRX_BUILD_TESTS = "OFF"
[tool.pytest.ini_options]
diff --git a/tirx/src/sym/rewrite_simplify.cc b/tirx/src/sym/rewrite_simplify.cc
index 68f1a29734..716832d266 100644
--- a/tirx/src/sym/rewrite_simplify.cc
+++ b/tirx/src/sym/rewrite_simplify.cc
@@ -429,7 +429,7 @@ UnchangedOr<PrimExpr>
RewriteSimplifier::Impl::Mutate_(const prim::SubNode* op,
// mul co-efficient folding: pefer co-effiicent to stay at rhs
TVM_TRY_REWRITE(x - x, ZeroWithTypeLike(x));
TVM_TRY_REWRITE(matches_one_of(x * y - x, y * x - x), (y - 1) * x);
- TVM_TRY_REWRITE(matches_one_of(x - y * x, x - x * y), (1 - y) * x);
+ TVM_TRY_REWRITE(matches_one_of(x - x * y, x - y * x), (1 - y) * x);
TVM_TRY_REWRITE(matches_one_of(x * y - x * z, y * x - x * z, x * y - z *
x, y * x - z * x),
(y - z) * x);