This is an automated email from the ASF dual-hosted git repository.

tqchen pushed a commit to branch tirx-standalone-root
in repository https://gitbox.apache.org/repos/asf/tvm.git

commit 96e7e85dc7c6ee779da1fef6215824d9cc9d960f
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.
---
 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 +-
 5 files changed, 31 insertions(+), 15 deletions(-)

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);
 

Reply via email to