Skip to content

Commit da1ec80

Browse files
authored
[REFACTOR] Consume standalone TIRx as a pinned dependency (#20803)
Consume Apache TIRx as a pinned submodule at `3rdparty/tvm-tirx`, replacing the owned TIRx source tree and retaining TVM's compiler and runtime extensions. Update native and Python builds, packaging, CI, development scripts, and documentation to use the standalone component and its recursive FFI dependency. Keep the parent distribution focused on TVM extensions while consuming TIRx through its installed interface.
1 parent b365abb commit da1ec80

1,035 files changed

Lines changed: 204 additions & 308698 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.agents/skills/tir-test/SKILL.md‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ name: tir-test
33
description: Run TVM's in-tree TIRx tests and tirx-kernels import and correctness checks.
44
---
55

6-
Run the compiler suite in `tirx/tests/python/tirx/`, using the `tvm_tirx` package
7-
in `tirx/python/`, together with the downstream correctness test in
6+
Run the compiler suite in `3rdparty/tvm-tirx/tests/python/tirx/`, using the `tvm_tirx` package
7+
in `3rdparty/tvm-tirx/python/`, together with the downstream correctness test in
88
`tests/python/tirx/test_tirx_kernels_registry_correctness.py`.
99

1010
Both tirx-kernels import gates and its correctness coverage are enabled by
@@ -25,9 +25,9 @@ Run all commands below in the same Bash shell from the TVM repository root.
2525
export TIR_TEST_XDIST_WORKERS="${TIR_TEST_XDIST_WORKERS:-16}"
2626
export TIR_TEST_WITH_KERNELS="${TIR_TEST_WITH_KERNELS:-1}"
2727

28-
[[ -d "$TIR_TEST_TVM_ROOT/tirx/python/tvm_tirx" &&
29-
-d "$TIR_TEST_TVM_ROOT/tirx/tests/python/tirx" ]] || {
30-
echo "run from the TVM repository root containing tirx/" >&2
28+
[[ -d "$TIR_TEST_TVM_ROOT/3rdparty/tvm-tirx/python/tvm_tirx" &&
29+
-d "$TIR_TEST_TVM_ROOT/3rdparty/tvm-tirx/tests/python/tirx" ]] || {
30+
echo "run from the TVM repository root containing 3rdparty/tvm-tirx/" >&2
3131
exit 2
3232
}
3333
[[ "$TIR_TEST_WITH_KERNELS" == 0 || "$TIR_TEST_WITH_KERNELS" == 1 ]] || {
@@ -89,7 +89,7 @@ Run all commands below in the same Bash shell from the TVM repository root.
8989
export CUDA_VISIBLE_DEVICES
9090
CUDA_VISIBLE_DEVICES="$(IFS=,; printf '%s' "${TIR_TEST_SELECTED_GPUS[*]}")"
9191
# Preserve reference packages and other paths supplied by branch-shell.
92-
export PYTHONPATH="${TIR_TEST_TVM_ROOT}/.local/python:${TIR_TEST_TVM_ROOT}/tirx/python:${TIR_TEST_TVM_ROOT}/python:${PYTHONPATH:-}"
92+
export PYTHONPATH="${TIR_TEST_TVM_ROOT}/.local/python:${TIR_TEST_TVM_ROOT}/3rdparty/tvm-tirx/python:${TIR_TEST_TVM_ROOT}/python:${PYTHONPATH:-}"
9393
export TVM_LIBRARY_PATH="${TIR_TEST_TVM_ROOT}/build/lib"
9494
export TVM_TIRX_LIBRARY_PATH="${TIR_TEST_TVM_ROOT}/build/lib"
9595

@@ -111,7 +111,7 @@ Run all commands below in the same Bash shell from the TVM repository root.
111111
from tvm_tirx.base import _LOADED_LIBS, _RUNTIME_ONLY
112112
113113
root = Path(os.environ["TIR_TEST_TVM_ROOT"])
114-
assert Path(tvm_tirx.__file__).resolve().is_relative_to(root / "tirx/python"), (
114+
assert Path(tvm_tirx.__file__).resolve().is_relative_to(root / "3rdparty/tvm-tirx/python"), (
115115
f"imported another TIRx worktree: {tvm_tirx.__file__}"
116116
)
117117
assert not _RUNTIME_ONLY, "build the TIRx compiler before running its tests"
@@ -147,14 +147,14 @@ Run all commands below in the same Bash shell from the TVM repository root.
147147
`TIR_TEST_NUM_GPUS=4` to cap the count or `TIR_TEST_GPUS=3,4,5,6` to override
148148
selection with exact physical IDs.
149149
150-
Use dependencies compatible with `tirx/pyproject.toml`. A non-editable FFI
150+
Use dependencies compatible with `3rdparty/tvm-tirx/pyproject.toml`. A non-editable FFI
151151
installation in `.local/python/` takes priority over the inherited environment.
152152
If native libraries are missing or stale, build this worktree with the same
153153
`PYTHONPATH` before testing.
154154
155155
2. Run downstream import gates and select the full test coverage:
156156
```bash
157-
TIR_TEST_PATHS=(tirx/tests/python/tirx/)
157+
TIR_TEST_PATHS=(3rdparty/tvm-tirx/tests/python/tirx/)
158158
if [[ "$TIR_TEST_WITH_KERNELS" == 1 ]]; then
159159
TIR_TEST_KERNELS_ROOT="${TIR_TEST_KERNELS_ROOT:-$(dirname "$TIR_TEST_TVM_ROOT")/tirx-kernels}"
160160
[[ -d "$TIR_TEST_KERNELS_ROOT/tirx_kernels" ]] || {
@@ -178,7 +178,7 @@ Run all commands below in the same Bash shell from the TVM repository root.
178178
"$PYTHON_BIN" -m pytest "${TIR_TEST_PATHS[@]}" -n "$TIR_TEST_XDIST_WORKERS" 2>&1 | tee "$TIR_TEST_LOG"
179179
```
180180
181-
`tirx/tests/python/tirx/conftest.py` uses `tvm_tirx.testing._pytest` to assign
181+
`3rdparty/tvm-tirx/tests/python/tirx/conftest.py` uses `tvm_tirx.testing._pytest` to assign
182182
each xdist worker's PyTorch current device round-robin across the visible
183183
GPUs. Tests that explicitly use `tvm_tirx.cuda(0)` still run on the first
184184
selected physical GPU.

‎.agents/skills/tirx-ptx-dialect/SKILL.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ Run from the TVM repo root with the workspace `PYTHONPATH` (see `tir-test`).
178178
codegen test, since certification does not enumerate those helpers;
179179
- only when the instruction belongs to the MegaMoE extracted-intrinsics
180180
surface → its kernel and mnemonic list in
181-
`tirx/tests/python/tirx/codegen/test_cuda.py::test_megamoe_extracted_intrinsics_codegen`
181+
`3rdparty/tvm-tirx/tests/python/tirx/codegen/test_cuda.py::test_megamoe_extracted_intrinsics_codegen`
182182
(that test covers one workload, not the dialect).
183183
3. **Regenerate the stub** — any change to a family's tokens or shapes makes
184184
`test_ptx_stub_up_to_date` fail until you do:
@@ -277,7 +277,7 @@ Do this as one commit series, in this order:
277277
made the first time this table changed versions.
278278
3. **Retarget the citations.** Update the module docstring's version
279279
statement and URL, then run the renumbering over `table.py`,
280-
`engine.py`, `render.py`, `tirx/tests/python/tirx/codegen/test_ptx_*.py` and
280+
`engine.py`, `render.py`, `3rdparty/tvm-tirx/tests/python/tirx/codegen/test_ptx_*.py` and
281281
`test_cuda.py`, skipping any block that already carries the new
282282
numbering (`_PTX_94_ENTRIES` was such a block for 9.3→9.4). Hand-fix the
283283
forms a regex cannot: ranges that span an insertion (`9.7.x.a-b`), brace

‎.github/actions/build-wheel-for-publish/action.yml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ runs:
110110
- name: Build and test TIRx core wheel
111111
uses: pypa/cibuildwheel@294735312765b09d24a2fbec22660ce817587d55 # v4.1.0
112112
with:
113-
package-dir: tirx
113+
package-dir: 3rdparty/tvm-tirx
114114
output-dir: wheelhouse
115115
env:
116116
CIBW_BUILD: ${{ inputs.build }}
@@ -139,7 +139,7 @@ runs:
139139
PATH="C:/opt/llvm/Library/bin;$PATH"
140140
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 }}"
141141
# Turns the wheel-specific assertions in
142-
# tirx/tests/python/runtime/test_validate_wheel_library.py
142+
# 3rdparty/tvm-tirx/tests/python/runtime/test_validate_wheel_library.py
143143
# ON (they skip unless these are set). Every published wheel is LLVM-enabled,
144144
# so TVM_WHEEL_EXPECT_LLVM is always "1"; the CUDA runtime is only bundled on
145145
# the CUDA wheels, so TVM_WHEEL_EXPECT_CUDA_RUNTIME is "0" for CPU wheels.

‎.github/actions/setup/action.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,4 @@ runs:
4444
- name: Install tvm-ffi pip package
4545
shell: bash -l {0}
4646
run: |
47-
pip install -v ./tirx/3rdparty/tvm-ffi
47+
pip install -v ./3rdparty/tvm-tirx/3rdparty/tvm-ffi

‎.github/workflows/main.yml‎

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -58,51 +58,40 @@ jobs:
5858
set -euxo pipefail
5959
pip install "scikit-build-core>=0.11" "setuptools-scm>=8"
6060
export CMAKE_ARGS="-DTVM_TIRX_USE_LLVM=ON -DTVM_TIRX_USE_METAL=ON -DTVM_TIRX_BUILD_TESTS=OFF"
61-
pip wheel --no-deps -w dist ./tirx -v
61+
pip wheel --no-deps -w dist ./3rdparty/tvm-tirx -v
6262
pip install --no-deps --force-reinstall dist/apache_tvm_tirx-*.whl
6363
export CMAKE_ARGS="-DBUILD_TESTING=OFF"
6464
pip wheel --no-deps --no-build-isolation -w dist . -v
6565
- name: Install TIRx and TVM from wheels
6666
shell: bash -l {0}
6767
run: |
6868
set -euxo pipefail
69-
export TVM_FFI_VERSION="$(python -c 'from importlib.metadata import version; print(version("apache-tvm-ffi"))')"
7069
pip install ml_dtypes
7170
# --no-deps: this package requires apache-tvm-ffi>=0.1.14.post1, and the source-built core
7271
# versions as 0.1.dev1+g<sha> from the shallow checkout, which is < 0.1.0 under PEP 440.
7372
# Without it pip replaces the source-matched core with a PyPI build.
7473
pip install --no-deps apache-tvm-ffi-orcjit==0.1.2
7574
# Keep the source-matched tvm-ffi installed by the setup action.
7675
pip install --no-deps dist/*.whl
77-
python - <<'PY'
78-
import os
79-
from importlib.metadata import requires, version
80-
81-
assert version("apache-tvm-ffi") == os.environ["TVM_FFI_VERSION"]
82-
assert version("apache-tvm-tirx") == "0.1.0a0"
83-
assert "apache-tvm-tirx==0.1.0a0" in requires("apache-tvm")
84-
assert "apache-tvm-ffi>=0.1.15rc0" in requires("apache-tvm-tirx")
85-
assert "apache-tvm-ffi-orcjit==0.1.2" in requires("apache-tvm-tirx")
86-
PY
8776
8877
- name: Test
8978
shell: bash -l {0}
9079
run: >-
91-
python -m pytest -v tirx/tests/python/codegen/llvm/test_minimal.py
92-
tirx/tests/python/runtime/test_validate_wheel_library.py tirx/tests/python/script
80+
python -m pytest -v 3rdparty/tvm-tirx/tests/python/codegen/llvm/test_minimal.py
81+
3rdparty/tvm-tirx/tests/python/runtime/test_validate_wheel_library.py 3rdparty/tvm-tirx/tests/python/script
9382
- name: Minimal Metal Compile-Only
9483
shell: bash -l {0}
9584
run: |
9685
set -euxo pipefail
97-
python -m pytest -v -s 'tirx/tests/python/codegen/gpu_common/test_allreduce.py::test_allreduce_sum_compile'
98-
python -m pytest -v -s 'tirx/tests/python/backend/metal/codegen/test_basic.py::test_func_with_trailing_pod_params'
86+
python -m pytest -v -s '3rdparty/tvm-tirx/tests/python/codegen/gpu_common/test_allreduce.py::test_allreduce_sum_compile'
87+
python -m pytest -v -s '3rdparty/tvm-tirx/tests/python/backend/metal/codegen/test_basic.py::test_func_with_trailing_pod_params'
9988
- name: Minimal Metal Compile-and-Run
10089
shell: bash -l {0}
10190
run: |
10291
set -euxo pipefail
103-
python -m pytest -v -s tirx/tests/python/backend/metal
104-
python -m pytest -v -s 'tirx/tests/python/codegen/gpu_common/test_intrinsics.py'
105-
python -m pytest -v -s 'tirx/tests/python/codegen/gpu_common/test_allreduce.py::test_allreduce_sum[dims0-metal]'
92+
python -m pytest -v -s 3rdparty/tvm-tirx/tests/python/backend/metal
93+
python -m pytest -v -s '3rdparty/tvm-tirx/tests/python/codegen/gpu_common/test_intrinsics.py'
94+
python -m pytest -v -s '3rdparty/tvm-tirx/tests/python/codegen/gpu_common/test_allreduce.py::test_allreduce_sum[dims0-metal]'
10695
10796
Windows:
10897
if: ${{ github.repository == 'apache/tvm' }}
@@ -123,7 +112,7 @@ jobs:
123112
run: |
124113
pip install "scikit-build-core>=0.11" "setuptools-scm>=8" || exit /b 1
125114
set CMAKE_ARGS=-DTVM_TIRX_USE_LLVM=ON -DTVM_TIRX_BUILD_TESTS=OFF
126-
pip wheel --no-deps -w dist ./tirx -v || exit /b 1
115+
pip wheel --no-deps -w dist ./3rdparty/tvm-tirx -v || exit /b 1
127116
for %%w in (dist\apache_tvm_tirx-*.whl) do (
128117
pip install --no-deps --force-reinstall "%%w" || exit /b 1
129118
)
@@ -142,5 +131,5 @@ jobs:
142131
- name: Test
143132
shell: cmd /C call {0}
144133
run: >-
145-
python -m pytest -v tirx/tests/python/codegen/llvm/test_minimal.py
146-
tirx/tests/python/runtime/test_validate_wheel_library.py tirx/tests/python/script
134+
python -m pytest -v 3rdparty/tvm-tirx/tests/python/codegen/llvm/test_minimal.py
135+
3rdparty/tvm-tirx/tests/python/runtime/test_validate_wheel_library.py 3rdparty/tvm-tirx/tests/python/script

‎.gitmodules‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@
77
[submodule "3rdparty/libflash_attn"]
88
path = 3rdparty/libflash_attn
99
url = https://github.com/tlc-pack/libflash_attn
10-
[submodule "3rdparty/tvm-ffi"]
11-
path = tirx/3rdparty/tvm-ffi
12-
url = https://github.com/apache/tvm-ffi
10+
[submodule "3rdparty/tvm-tirx"]
11+
path = 3rdparty/tvm-tirx
12+
url = https://github.com/apache/tvm-tirx.git

‎.pre-commit-config.yaml‎

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,6 @@ repos:
2323
# ---------- Local hooks ----------
2424
- repo: local
2525
hooks:
26-
- id: cuda-launch-generated
27-
name: check CUDA launch generated files
28-
entry: python tirx/python/tvm_tirx/backend/cuda/launch/generate.py --check
29-
language: python
30-
additional_dependencies: [ruff==0.12.3, clang-format==20.1.8]
31-
pass_filenames: false
32-
files: ^(tirx/python/tvm_tirx/backend/cuda/launch/|tirx/src/backend/cuda/launch/|docs/tirx/api/cuda_launch.rst)
3326
- id: check-asf-header
3427
name: check ASF Header
3528
entry: python tests/lint/check_asf_header.py --check
@@ -53,13 +46,13 @@ repos:
5346
- id: check-merge-conflict
5447
- id: check-symlinks
5548
- id: end-of-file-fixer
56-
exclude: ^(tirx/)?3rdparty/
49+
exclude: ^3rdparty/
5750
- id: mixed-line-ending
58-
exclude: ^(tirx/)?3rdparty/
51+
exclude: ^3rdparty/
5952
- id: requirements-txt-fixer
6053
exclude: ^docker/python/bootstrap
6154
- id: trailing-whitespace
62-
exclude: ^(tirx/)?3rdparty/
55+
exclude: ^3rdparty/
6356
- id: check-yaml
6457
- id: check-toml
6558

@@ -95,7 +88,7 @@ repos:
9588
hooks:
9689
- id: clang-format
9790
types_or: [c, c++, cuda, objective-c++]
98-
exclude: ^(tirx/)?3rdparty/
91+
exclude: ^3rdparty/
9992

10093
# ---------- Cython ----------
10194
- repo: https://github.com/MarcoGorelli/cython-lint

‎3rdparty/tvm-tirx‎

Submodule tvm-tirx added at 198a045

‎AGENTS.md‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ cmake --build build --parallel
6262
Development should use `PYTHONPATH`, not editable installs:
6363

6464
```bash
65-
export PYTHONPATH="$(pwd)/python:$(pwd)/.local/python"
65+
export PYTHONPATH="$(pwd)/python:$(pwd)/3rdparty/tvm-tirx/python:$(pwd)/.local/python"
66+
export TVM_TIRX_LIBRARY_PATH="$(pwd)/build/lib"
6667
```
6768

6869
Do not use `pip install -e` for TVM or `tvm-ffi`; editable installs can make
@@ -73,8 +74,8 @@ one worktree silently import another worktree's code.
7374
Run the smallest relevant test first, then broaden as needed. Common examples:
7475

7576
```bash
76-
python -m pytest tirx/tests/python/codegen/llvm/test_minimal.py -xvs
77-
python -m pytest tirx/tests/python/tirx/test_base.py -xvs
77+
python -m pytest 3rdparty/tvm-tirx/tests/python/codegen/llvm/test_minimal.py -xvs
78+
python -m pytest 3rdparty/tvm-tirx/tests/python/tirx/test_base.py -xvs
7879
./build/cpptest
7980
```
8081

‎CMakeLists.txt‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ set_property(CACHE TVM_USE_GTEST PROPERTY STRINGS AUTO ON OFF)
8585
# ######### Core dependencies ##########
8686

8787
set(_installed_tirx ON)
88-
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/tirx/CMakeLists.txt")
88+
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/tvm-tirx/CMakeLists.txt")
8989
set(_installed_tirx OFF)
9090
endif()
9191
option(TVM_USE_INSTALLED_TIRX "Build against an installed apache-tvm-tirx package" ${_installed_tirx})
@@ -149,8 +149,8 @@ if(TVM_USE_INSTALLED_TIRX)
149149
"TVM_OPENCL_DLL=__attribute__((visibility(\"default\")))")
150150
endif()
151151
endif()
152-
if(NOT TVM_TIRX_VERSION STREQUAL "0.1.0a0")
153-
message(FATAL_ERROR "TVM requires apache-tvm-tirx 0.1.0a0")
152+
if(NOT TVM_TIRX_VERSION STREQUAL "0.1.0a2")
153+
message(FATAL_ERROR "TVM requires apache-tvm-tirx 0.1.0a2")
154154
endif()
155155
else()
156156
# Keep source-built core libraries beside the parent libraries.
@@ -161,7 +161,7 @@ else()
161161
list(APPEND _tirx_output_defaults ${_kind})
162162
endif()
163163
endforeach()
164-
add_subdirectory(tirx)
164+
add_subdirectory(3rdparty/tvm-tirx)
165165
if(TARGET tirx_cpptest)
166166
set_target_properties(tirx_cpptest PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}")
167167
foreach(_config IN LISTS CMAKE_CONFIGURATION_TYPES)
@@ -234,7 +234,7 @@ add_library(tvm_runtime_extra_defs INTERFACE)
234234
target_link_libraries(tvm_runtime_extra_defs INTERFACE
235235
tvm_runtime::shared tvm_ffi::shared)
236236
target_include_directories(tvm_runtime_extra_defs SYSTEM INTERFACE
237-
"${CMAKE_CURRENT_SOURCE_DIR}/tirx/3rdparty/compiler-rt")
237+
"${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/tvm-tirx/3rdparty/compiler-rt")
238238
target_compile_definitions(tvm_runtime_extra_defs INTERFACE TVM_RUNTIME_EXTRA_EXPORTS TVM_FFI_EXPORTS)
239239
target_compile_features(tvm_runtime_extra_defs INTERFACE cxx_std_20)
240240
target_link_libraries(tvm_runtime_extra PRIVATE tvm_runtime_extra_defs)
@@ -304,7 +304,7 @@ endif()
304304
if(TARGET tvm_clml_objs)
305305
# CLML shares OpenCL implementation types; these are source inputs, not an
306306
# installed core interface. The parent sdist carries their bounded closure.
307-
target_include_directories(tvm_clml_objs PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/tirx/src")
307+
target_include_directories(tvm_clml_objs PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/tvm-tirx/src")
308308
endif()
309309
# Retain the upstream runtime-extra assembly module and its target composition.
310310
include(cmake/modules/RuntimeExtra.cmake)
@@ -313,7 +313,7 @@ target_sources(tvm_compiler PRIVATE ${COMPILER_SRCS})
313313
target_compile_definitions(tvm_compiler PRIVATE TVM_EXPORTS TVM_FFI_EXPORTS)
314314
target_link_libraries(tvm_compiler PUBLIC tvm_tirx_compiler::shared tvm_ffi::shared tvm_runtime_extra)
315315
target_include_directories(tvm_compiler SYSTEM PRIVATE
316-
"${CMAKE_CURRENT_SOURCE_DIR}/tirx/3rdparty/compiler-rt")
316+
"${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/tvm-tirx/3rdparty/compiler-rt")
317317
foreach(_target tvm_compiler tvm_runtime_extra)
318318
target_include_directories(${_target} PUBLIC
319319
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"

0 commit comments

Comments
 (0)