{"owner":"apache","repo":"tvm","hasSkills":true,"totalSkillsCount":3,"totalTokensCount":3495,"categories":["anthropic-skill","root-instruction"],"hasMcp":false,"mcpConfig":null,"found":[".agents/skills/tir-build/SKILL.md",".agents/skills/tir-test/SKILL.md","AGENTS.md"],"skills":{".agents/skills/tir-build/SKILL.md":"Build TVM from the current worktree.\n\n## Steps\n\n1. Check that `build/` directory exists. If not, run initial setup:\n   ```bash\n   mkdir -p build\n   cmake -S . -B build\n   cmake --build build --parallel\n   ```\n\n2. If `build/` already exists, run incremental build:\n   ```bash\n   cmake --build build --parallel\n   ```\n\n3. Report success/failure and build time.\n",".agents/skills/tir-test/SKILL.md":"---\nname: tir-test\ndescription: Run TVM's in-tree TIRx tests and tirx-kernels import and correctness checks.\n---\n\nRun the compiler suite in `3rdparty/tvm-tirx/tests/python/tirx/`, using the `tvm_tirx` package\nin `3rdparty/tvm-tirx/python/`, together with the downstream correctness test in\n`tests/python/tirx/test_tirx_kernels_registry_correctness.py`.\n\nBoth tirx-kernels import gates and its correctness coverage are enabled by\ndefault. Use `TIR_TEST_WITH_KERNELS=0` only for an explicitly requested\ncompiler-only run, and report that reduced coverage.\n\n## Steps\n\nRun all commands below in the same Bash shell from the TVM repository root.\n\n1. Point Python at this worktree and select every Blackwell GPU.\n   `TIR_TEST_GPUS` may explicitly provide physical GPU IDs, and\n   `TIR_TEST_NUM_GPUS` may optionally cap the automatically selected count. Otherwise,\n   selection uses all Blackwell GPUs, ordered by least memory in use.\n   ```bash\n   export TIR_TEST_TVM_ROOT=\"$(pwd -P)\"\n   export TIR_TEST_NUM_GPUS=\"${TIR_TEST_NUM_GPUS:-}\"\n   export TIR_TEST_XDIST_WORKERS=\"${TIR_TEST_XDIST_WORKERS:-16}\"\n   export TIR_TEST_WITH_KERNELS=\"${TIR_TEST_WITH_KERNELS:-1}\"\n\n   [[ -d \"$TIR_TEST_TVM_ROOT/3rdparty/tvm-tirx/python/tvm_tirx\" &&\n      -d \"$TIR_TEST_TVM_ROOT/3rdparty/tvm-tirx/tests/python/tirx\" ]] || {\n     echo \"run from the TVM repository root containing 3rdparty/tvm-tirx/\" >&2\n     exit 2\n   }\n   [[ \"$TIR_TEST_WITH_KERNELS\" == 0 || \"$TIR_TEST_WITH_KERNELS\" == 1 ]] || {\n     echo \"TIR_TEST_WITH_KERNELS must be 0 or 1\" >&2\n     exit 2\n   }\n\n   [[ -z \"$TIR_TEST_NUM_GPUS\" || \"$TIR_TEST_NUM_GPUS\" =~ ^[1-9][0-9]*$ ]] || {\n     echo \"TIR_TEST_NUM_GPUS must be empty or a positive integer\" >&2\n     exit 2\n   }\n   [[ \"$TIR_TEST_XDIST_WORKERS\" =~ ^[1-9][0-9]*$ ]] || {\n     echo \"TIR_TEST_XDIST_WORKERS must be a positive integer\" >&2\n     exit 2\n   }\n\n   if [[ -n \"${TIR_TEST_GPUS:-}\" ]]; then\n     IFS=, read -r -a TIR_TEST_SELECTED_GPUS <<< \"${TIR_TEST_GPUS// /}\"\n   else\n     mapfile -t TIR_TEST_SELECTED_GPUS < <(\n       nvidia-smi \\\n         --query-gpu=index,memory.used,compute_cap \\\n         --format=csv,noheader,nounits \\\n       | awk -F, '\n           {\n             for (i = 1; i <= 3; ++i) {\n               gsub(/^[[:space:]]+|[[:space:]]+$/, \"\", $i)\n             }\n             if (($3 + 0) >= 10) {\n               print $1, $2\n             }\n           }' \\\n       | sort -k2,2n -k1,1n \\\n       | awk '{print $1}'\n     )\n     if [[ -n \"$TIR_TEST_NUM_GPUS\" ]] && \\\n        (( ${#TIR_TEST_SELECTED_GPUS[@]} > TIR_TEST_NUM_GPUS )); then\n       TIR_TEST_SELECTED_GPUS=(\n         \"${TIR_TEST_SELECTED_GPUS[@]:0:TIR_TEST_NUM_GPUS}\"\n       )\n     fi\n   fi\n\n   (( ${#TIR_TEST_SELECTED_GPUS[@]} > 0 )) || {\n     echo \"no CUDA compute capability >= 10 GPU is available\" >&2\n     exit 1\n   }\n   for gpu in \"${TIR_TEST_SELECTED_GPUS[@]}\"; do\n     [[ \"$gpu\" =~ ^[0-9]+$ ]] || {\n       echo \"invalid physical GPU ID: $gpu\" >&2\n       exit 2\n     }\n   done\n   if [[ -z \"${TIR_TEST_GPUS:-}\" && -n \"$TIR_TEST_NUM_GPUS\" ]] && \\\n      (( ${#TIR_TEST_SELECTED_GPUS[@]} < TIR_TEST_NUM_GPUS )); then\n     echo \"warning: requested $TIR_TEST_NUM_GPUS GPUs, using ${#TIR_TEST_SELECTED_GPUS[@]}\"\n   fi\n\n   export CUDA_VISIBLE_DEVICES\n   CUDA_VISIBLE_DEVICES=\"$(IFS=,; printf '%s' \"${TIR_TEST_SELECTED_GPUS[*]}\")\"\n   # Preserve reference packages and other paths supplied by branch-shell.\n   export PYTHONPATH=\"${TIR_TEST_TVM_ROOT}/.local/python:${TIR_TEST_TVM_ROOT}/3rdparty/tvm-tirx/python:${TIR_TEST_TVM_ROOT}/python:${PYTHONPATH:-}\"\n   export TVM_LIBRARY_PATH=\"${TIR_TEST_TVM_ROOT}/build/lib\"\n   export TVM_TIRX_LIBRARY_PATH=\"${TIR_TEST_TVM_ROOT}/build/lib\"\n\n   PYTHON_BIN=\"${PYTHON_BIN:-$(command -v python || true)}\"\n   [[ -n \"$PYTHON_BIN\" && -x \"$PYTHON_BIN\" ]] || {\n     echo \"set PYTHON_BIN to the test environment's Python executable\" >&2\n     exit 1\n   }\n   export PATH=\"$(dirname \"$PYTHON_BIN\"):$PATH\"\n   \"$PYTHON_BIN\" - <<'PY'\n   import os\n   from pathlib import Path\n\n   import pytest\n   import torch\n   import tvm_ffi\n   import tvm_tirx\n   import xdist\n   from tvm_tirx.base import _LOADED_LIBS, _RUNTIME_ONLY\n\n   root = Path(os.environ[\"TIR_TEST_TVM_ROOT\"])\n   assert Path(tvm_tirx.__file__).resolve().is_relative_to(root / \"3rdparty/tvm-tirx/python\"), (\n       f\"imported another TIRx worktree: {tvm_tirx.__file__}\"\n   )\n   assert not _RUNTIME_ONLY, \"build the TIRx compiler before running its tests\"\n   for name, library in _LOADED_LIBS.items():\n       assert Path(library._name).resolve().is_relative_to(root / \"build/lib\"), (\n           f\"loaded another worktree's {name}: {library._name}\"\n       )\n   print(f\"tvm_tirx: {tvm_tirx.__file__}\")\n   print(f\"tvm_ffi: {tvm_ffi.__file__}\")\n   PY\n   if [[ $? -ne 0 ]]; then\n     echo \"PYTHON_BIN must provide pytest, xdist, torch and this worktree's TIRx build\" >&2\n     exit 1\n   fi\n   if ! command -v ninja >/dev/null; then\n     NINJA_BIN_DIR=\"$(\"$PYTHON_BIN\" -c 'import ninja; print(ninja.BIN_DIR)' 2>/dev/null || true)\"\n     if [[ -n \"$NINJA_BIN_DIR\" && -x \"$NINJA_BIN_DIR/ninja\" ]]; then\n       export PATH=\"$NINJA_BIN_DIR:$PATH\"\n     fi\n   fi\n   command -v ninja >/dev/null || {\n     echo \"ninja is required by kernel JIT setup but is not on PATH\" >&2\n     exit 1\n   }\n\n   echo \"selected physical GPUs: $CUDA_VISIBLE_DEVICES\"\n   for logical_id in \"${!TIR_TEST_SELECTED_GPUS[@]}\"; do\n     echo \"  cuda:$logical_id -> physical GPU ${TIR_TEST_SELECTED_GPUS[$logical_id]}\"\n   done\n   ```\n\n   Automatic selection uses every Blackwell device. Set\n   `TIR_TEST_NUM_GPUS=4` to cap the count or `TIR_TEST_GPUS=3,4,5,6` to override\n   selection with exact physical IDs.\n\n   Use dependencies compatible with `3rdparty/tvm-tirx/pyproject.toml`. A non-editable FFI\n   installation in `.local/python/` takes priority over the inherited environment.\n   If native libraries are missing or stale, build this worktree with the same\n   `PYTHONPATH` before testing.\n\n2. Run downstream import gates and select the full test coverage:\n   ```bash\n   TIR_TEST_PATHS=(3rdparty/tvm-tirx/tests/python/tirx/)\n   if [[ \"$TIR_TEST_WITH_KERNELS\" == 1 ]]; then\n     TIR_TEST_KERNELS_ROOT=\"${TIR_TEST_KERNELS_ROOT:-$(dirname \"$TIR_TEST_TVM_ROOT\")/tirx-kernels}\"\n     [[ -d \"$TIR_TEST_KERNELS_ROOT/tirx_kernels\" ]] || {\n       echo \"set TIR_TEST_KERNELS_ROOT to the tirx-kernels repository\" >&2\n       exit 2\n     }\n     export PYTHONPATH=\"${TIR_TEST_KERNELS_ROOT}:${PYTHONPATH:-}\"\n     \"$PYTHON_BIN\" -m tirx_kernels.bench_suite --check-imports || exit 1\n     \"$PYTHON_BIN\" -m tirx_kernels.registry --strict || exit 1\n     TIR_TEST_PATHS+=(tests/python/tirx/test_tirx_kernels_registry_correctness.py)\n     export TIRX_KERNEL_TEST_MIN_FREE_GB=\"${TIRX_KERNEL_TEST_MIN_FREE_GB:-0}\"\n   else\n     echo \"compiler-only run: tirx-kernels import and correctness checks disabled\"\n   fi\n   ```\n\n3. Run the selected test suites with xdist parallelism and save the full log:\n   ```bash\n   export TIR_TEST_LOG=\"${TIR_TEST_LOG:-/tmp/tir-test-$(date +%Y%m%d-%H%M%S).log}\"\n   set -o pipefail\n   \"$PYTHON_BIN\" -m pytest \"${TIR_TEST_PATHS[@]}\" -n \"$TIR_TEST_XDIST_WORKERS\" 2>&1 | tee \"$TIR_TEST_LOG\"\n   ```\n\n   `3rdparty/tvm-tirx/tests/python/tirx/conftest.py` uses `tvm_tirx.testing._pytest` to assign\n   each xdist worker's PyTorch current device round-robin across the visible\n   GPUs. Tests that explicitly use `tvm_tirx.cuda(0)` still run on the first\n   selected physical GPU.\n\n   Registry correctness tests take a per-device lock to serialize large workloads\n   on each GPU. MegaMoE remains skipped because it requires its dedicated\n   multi-process scheduler.\n\n4. Report results: selected physical GPUs, elapsed time, total passed, failed,\n   skipped, and errors, plus the full log path. Report both downstream gates as\n   passed, failed, or explicitly disabled; disabled integration checks are not\n   passes.\n\n## Failure triage rules\n\n**CRITICAL: Never pipe test output to `tail` or `grep` when diagnosing failures.\nAlways capture and read full logs.**\n\nClassify every failure into one of these categories:\n\n- **A - Environment/import error**: Module not found, missing dependency,\n  collection error. Check the source and native-library paths, FFI dependency,\n  and old `tvm` versus `tvm_tirx` namespaces before assigning a cause.\n- **B - Real kernel correctness regression**: Assertion failures (`cosine_sim`,\n  numerical diff), `CUDA: unspecified launch failure`, or wrong results. These\n  MUST be investigated and fixed if caused by current changes.\n- **C - Secondary xdist crash**: `KeyError: <WorkerController gwXX>` after a\n  worker abort. The KeyError itself is noise; find the underlying cause (usually\n  category B in another worker).\n\nNever dismiss a failure as pre-existing without evidence. If a test fails:\n\n1. Check whether the test touches code you changed.\n2. If unclear, verify on the parent commit before claiming it is pre-existing.\n3. Fix every failure caused by current changes; do not defer it.\n","AGENTS.md":"<!--\nLicensed to the Apache Software Foundation (ASF) under one\nor more contributor license agreements.  See the NOTICE file\ndistributed with this work for additional information\nregarding copyright ownership.  The ASF licenses this file\nto you under the Apache License, Version 2.0 (the\n\"License\"); you may not use this file except in compliance\nwith the License.  You may obtain a copy of the License at\n\n  http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing,\nsoftware distributed under the License is distributed on an\n\"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\nKIND, either express or implied.  See the License for the\nspecific language governing permissions and limitations\nunder the License.\n-->\n\n# AGENTS.md\n\nThis file provides vendor-neutral guidance for agentic coding tools working\nwith Apache TVM.\n\n## Repository Overview\n\nApache TVM is an open-source machine learning compiler stack. The repository\ncontains the C++ compiler/runtime, Python bindings, TIR/Relax IRs, scheduling\nand lowering passes, target code generators, runtime integrations, tests,\ndocumentation, and application examples.\n\n## Repository Structure\n\n- `include/tvm/` - public C++ headers\n- `src/` - C++ implementation\n- `python/tvm/` - Python package\n- `tests/` - C++, Python, integration, and lint tests\n- `cmake/` - CMake modules and default configuration\n- `3rdparty/` - vendored dependencies and submodules\n- `docs/` - documentation source\n- `apps/` - application examples\n- `.agents/skills/` - reusable agent workflows for this repository\n\n## Build\n\nUse an existing `build/` directory when present:\n\n```bash\ncmake --build build --parallel\n```\n\nFor a fresh checkout, initialize submodules and configure CMake first:\n\n```bash\ngit submodule update --init --recursive\nmkdir -p build\ncmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=RelWithDebInfo \\\n  -DTVM_TIRX_USE_LLVM=OFF -DTVM_TIRX_USE_CUDA=OFF\ncmake --build build --parallel\n```\n\nDevelopment should use `PYTHONPATH`, not editable installs:\n\n```bash\nexport PYTHONPATH=\"$(pwd)/python:$(pwd)/3rdparty/tvm-tirx/python:$(pwd)/.local/python\"\nexport TVM_TIRX_LIBRARY_PATH=\"$(pwd)/build/lib\"\n```\n\nDo not use `pip install -e` for TVM or `tvm-ffi`; editable installs can make\none worktree silently import another worktree's code.\n\n## Test And Lint\n\nRun the smallest relevant test first, then broaden as needed. Common examples:\n\n```bash\npython -m pytest 3rdparty/tvm-tirx/tests/python/codegen/llvm/test_minimal.py -xvs\npython -m pytest 3rdparty/tvm-tirx/tests/python/tirx/test_base.py -xvs\n./build/cpptest\n```\n\nFor lint validation on a pull request, run pre-commit on the files changed by\nthe branch instead of the whole repository:\n\n```bash\npre-commit run --files <changed-file>...\n```\n\nUse `python -m tirx_kernels.bench_suite` in the **tirx-kernels** repo\n(`tirx_kernels/bench_suite/`) when that workflow applies.\n\n## Coding Conventions\n\n- Follow the surrounding style before introducing new abstractions.\n- Keep changes scoped to the task and avoid unrelated cleanups.\n- Prefer explicit tests that show the IR or behavior being changed.\n- Use Apache TVM commit tags such as `[REFACTOR][IR]`, `[FIX][TIR]`, or\n  `[DOCS]` as appropriate.\n- Preserve Apache license headers in new source, script, and documentation\n  files when the surrounding tree uses them.\n"},"files":{".agents/skills/tir-build/SKILL.md":"Build TVM from the current worktree.\n\n## Steps\n\n1. Check that `build/` directory exists. If not, run initial setup:\n   ```bash\n   mkdir -p build\n   cmake -S . -B build\n   cmake --build build --parallel\n   ```\n\n2. If `build/` already exists, run incremental build:\n   ```bash\n   cmake --build build --parallel\n   ```\n\n3. Report success/failure and build time.\n",".agents/skills/tir-test/SKILL.md":"---\nname: tir-test\ndescription: Run TVM's in-tree TIRx tests and tirx-kernels import and correctness checks.\n---\n\nRun the compiler suite in `3rdparty/tvm-tirx/tests/python/tirx/`, using the `tvm_tirx` package\nin `3rdparty/tvm-tirx/python/`, together with the downstream correctness test in\n`tests/python/tirx/test_tirx_kernels_registry_correctness.py`.\n\nBoth tirx-kernels import gates and its correctness coverage are enabled by\ndefault. Use `TIR_TEST_WITH_KERNELS=0` only for an explicitly requested\ncompiler-only run, and report that reduced coverage.\n\n## Steps\n\nRun all commands below in the same Bash shell from the TVM repository root.\n\n1. Point Python at this worktree and select every Blackwell GPU.\n   `TIR_TEST_GPUS` may explicitly provide physical GPU IDs, and\n   `TIR_TEST_NUM_GPUS` may optionally cap the automatically selected count. Otherwise,\n   selection uses all Blackwell GPUs, ordered by least memory in use.\n   ```bash\n   export TIR_TEST_TVM_ROOT=\"$(pwd -P)\"\n   export TIR_TEST_NUM_GPUS=\"${TIR_TEST_NUM_GPUS:-}\"\n   export TIR_TEST_XDIST_WORKERS=\"${TIR_TEST_XDIST_WORKERS:-16}\"\n   export TIR_TEST_WITH_KERNELS=\"${TIR_TEST_WITH_KERNELS:-1}\"\n\n   [[ -d \"$TIR_TEST_TVM_ROOT/3rdparty/tvm-tirx/python/tvm_tirx\" &&\n      -d \"$TIR_TEST_TVM_ROOT/3rdparty/tvm-tirx/tests/python/tirx\" ]] || {\n     echo \"run from the TVM repository root containing 3rdparty/tvm-tirx/\" >&2\n     exit 2\n   }\n   [[ \"$TIR_TEST_WITH_KERNELS\" == 0 || \"$TIR_TEST_WITH_KERNELS\" == 1 ]] || {\n     echo \"TIR_TEST_WITH_KERNELS must be 0 or 1\" >&2\n     exit 2\n   }\n\n   [[ -z \"$TIR_TEST_NUM_GPUS\" || \"$TIR_TEST_NUM_GPUS\" =~ ^[1-9][0-9]*$ ]] || {\n     echo \"TIR_TEST_NUM_GPUS must be empty or a positive integer\" >&2\n     exit 2\n   }\n   [[ \"$TIR_TEST_XDIST_WORKERS\" =~ ^[1-9][0-9]*$ ]] || {\n     echo \"TIR_TEST_XDIST_WORKERS must be a positive integer\" >&2\n     exit 2\n   }\n\n   if [[ -n \"${TIR_TEST_GPUS:-}\" ]]; then\n     IFS=, read -r -a TIR_TEST_SELECTED_GPUS <<< \"${TIR_TEST_GPUS// /}\"\n   else\n     mapfile -t TIR_TEST_SELECTED_GPUS < <(\n       nvidia-smi \\\n         --query-gpu=index,memory.used,compute_cap \\\n         --format=csv,noheader,nounits \\\n       | awk -F, '\n           {\n             for (i = 1; i <= 3; ++i) {\n               gsub(/^[[:space:]]+|[[:space:]]+$/, \"\", $i)\n             }\n             if (($3 + 0) >= 10) {\n               print $1, $2\n             }\n           }' \\\n       | sort -k2,2n -k1,1n \\\n       | awk '{print $1}'\n     )\n     if [[ -n \"$TIR_TEST_NUM_GPUS\" ]] && \\\n        (( ${#TIR_TEST_SELECTED_GPUS[@]} > TIR_TEST_NUM_GPUS )); then\n       TIR_TEST_SELECTED_GPUS=(\n         \"${TIR_TEST_SELECTED_GPUS[@]:0:TIR_TEST_NUM_GPUS}\"\n       )\n     fi\n   fi\n\n   (( ${#TIR_TEST_SELECTED_GPUS[@]} > 0 )) || {\n     echo \"no CUDA compute capability >= 10 GPU is available\" >&2\n     exit 1\n   }\n   for gpu in \"${TIR_TEST_SELECTED_GPUS[@]}\"; do\n     [[ \"$gpu\" =~ ^[0-9]+$ ]] || {\n       echo \"invalid physical GPU ID: $gpu\" >&2\n       exit 2\n     }\n   done\n   if [[ -z \"${TIR_TEST_GPUS:-}\" && -n \"$TIR_TEST_NUM_GPUS\" ]] && \\\n      (( ${#TIR_TEST_SELECTED_GPUS[@]} < TIR_TEST_NUM_GPUS )); then\n     echo \"warning: requested $TIR_TEST_NUM_GPUS GPUs, using ${#TIR_TEST_SELECTED_GPUS[@]}\"\n   fi\n\n   export CUDA_VISIBLE_DEVICES\n   CUDA_VISIBLE_DEVICES=\"$(IFS=,; printf '%s' \"${TIR_TEST_SELECTED_GPUS[*]}\")\"\n   # Preserve reference packages and other paths supplied by branch-shell.\n   export PYTHONPATH=\"${TIR_TEST_TVM_ROOT}/.local/python:${TIR_TEST_TVM_ROOT}/3rdparty/tvm-tirx/python:${TIR_TEST_TVM_ROOT}/python:${PYTHONPATH:-}\"\n   export TVM_LIBRARY_PATH=\"${TIR_TEST_TVM_ROOT}/build/lib\"\n   export TVM_TIRX_LIBRARY_PATH=\"${TIR_TEST_TVM_ROOT}/build/lib\"\n\n   PYTHON_BIN=\"${PYTHON_BIN:-$(command -v python || true)}\"\n   [[ -n \"$PYTHON_BIN\" && -x \"$PYTHON_BIN\" ]] || {\n     echo \"set PYTHON_BIN to the test environment's Python executable\" >&2\n     exit 1\n   }\n   export PATH=\"$(dirname \"$PYTHON_BIN\"):$PATH\"\n   \"$PYTHON_BIN\" - <<'PY'\n   import os\n   from pathlib import Path\n\n   import pytest\n   import torch\n   import tvm_ffi\n   import tvm_tirx\n   import xdist\n   from tvm_tirx.base import _LOADED_LIBS, _RUNTIME_ONLY\n\n   root = Path(os.environ[\"TIR_TEST_TVM_ROOT\"])\n   assert Path(tvm_tirx.__file__).resolve().is_relative_to(root / \"3rdparty/tvm-tirx/python\"), (\n       f\"imported another TIRx worktree: {tvm_tirx.__file__}\"\n   )\n   assert not _RUNTIME_ONLY, \"build the TIRx compiler before running its tests\"\n   for name, library in _LOADED_LIBS.items():\n       assert Path(library._name).resolve().is_relative_to(root / \"build/lib\"), (\n           f\"loaded another worktree's {name}: {library._name}\"\n       )\n   print(f\"tvm_tirx: {tvm_tirx.__file__}\")\n   print(f\"tvm_ffi: {tvm_ffi.__file__}\")\n   PY\n   if [[ $? -ne 0 ]]; then\n     echo \"PYTHON_BIN must provide pytest, xdist, torch and this worktree's TIRx build\" >&2\n     exit 1\n   fi\n   if ! command -v ninja >/dev/null; then\n     NINJA_BIN_DIR=\"$(\"$PYTHON_BIN\" -c 'import ninja; print(ninja.BIN_DIR)' 2>/dev/null || true)\"\n     if [[ -n \"$NINJA_BIN_DIR\" && -x \"$NINJA_BIN_DIR/ninja\" ]]; then\n       export PATH=\"$NINJA_BIN_DIR:$PATH\"\n     fi\n   fi\n   command -v ninja >/dev/null || {\n     echo \"ninja is required by kernel JIT setup but is not on PATH\" >&2\n     exit 1\n   }\n\n   echo \"selected physical GPUs: $CUDA_VISIBLE_DEVICES\"\n   for logical_id in \"${!TIR_TEST_SELECTED_GPUS[@]}\"; do\n     echo \"  cuda:$logical_id -> physical GPU ${TIR_TEST_SELECTED_GPUS[$logical_id]}\"\n   done\n   ```\n\n   Automatic selection uses every Blackwell device. Set\n   `TIR_TEST_NUM_GPUS=4` to cap the count or `TIR_TEST_GPUS=3,4,5,6` to override\n   selection with exact physical IDs.\n\n   Use dependencies compatible with `3rdparty/tvm-tirx/pyproject.toml`. A non-editable FFI\n   installation in `.local/python/` takes priority over the inherited environment.\n   If native libraries are missing or stale, build this worktree with the same\n   `PYTHONPATH` before testing.\n\n2. Run downstream import gates and select the full test coverage:\n   ```bash\n   TIR_TEST_PATHS=(3rdparty/tvm-tirx/tests/python/tirx/)\n   if [[ \"$TIR_TEST_WITH_KERNELS\" == 1 ]]; then\n     TIR_TEST_KERNELS_ROOT=\"${TIR_TEST_KERNELS_ROOT:-$(dirname \"$TIR_TEST_TVM_ROOT\")/tirx-kernels}\"\n     [[ -d \"$TIR_TEST_KERNELS_ROOT/tirx_kernels\" ]] || {\n       echo \"set TIR_TEST_KERNELS_ROOT to the tirx-kernels repository\" >&2\n       exit 2\n     }\n     export PYTHONPATH=\"${TIR_TEST_KERNELS_ROOT}:${PYTHONPATH:-}\"\n     \"$PYTHON_BIN\" -m tirx_kernels.bench_suite --check-imports || exit 1\n     \"$PYTHON_BIN\" -m tirx_kernels.registry --strict || exit 1\n     TIR_TEST_PATHS+=(tests/python/tirx/test_tirx_kernels_registry_correctness.py)\n     export TIRX_KERNEL_TEST_MIN_FREE_GB=\"${TIRX_KERNEL_TEST_MIN_FREE_GB:-0}\"\n   else\n     echo \"compiler-only run: tirx-kernels import and correctness checks disabled\"\n   fi\n   ```\n\n3. Run the selected test suites with xdist parallelism and save the full log:\n   ```bash\n   export TIR_TEST_LOG=\"${TIR_TEST_LOG:-/tmp/tir-test-$(date +%Y%m%d-%H%M%S).log}\"\n   set -o pipefail\n   \"$PYTHON_BIN\" -m pytest \"${TIR_TEST_PATHS[@]}\" -n \"$TIR_TEST_XDIST_WORKERS\" 2>&1 | tee \"$TIR_TEST_LOG\"\n   ```\n\n   `3rdparty/tvm-tirx/tests/python/tirx/conftest.py` uses `tvm_tirx.testing._pytest` to assign\n   each xdist worker's PyTorch current device round-robin across the visible\n   GPUs. Tests that explicitly use `tvm_tirx.cuda(0)` still run on the first\n   selected physical GPU.\n\n   Registry correctness tests take a per-device lock to serialize large workloads\n   on each GPU. MegaMoE remains skipped because it requires its dedicated\n   multi-process scheduler.\n\n4. Report results: selected physical GPUs, elapsed time, total passed, failed,\n   skipped, and errors, plus the full log path. Report both downstream gates as\n   passed, failed, or explicitly disabled; disabled integration checks are not\n   passes.\n\n## Failure triage rules\n\n**CRITICAL: Never pipe test output to `tail` or `grep` when diagnosing failures.\nAlways capture and read full logs.**\n\nClassify every failure into one of these categories:\n\n- **A - Environment/import error**: Module not found, missing dependency,\n  collection error. Check the source and native-library paths, FFI dependency,\n  and old `tvm` versus `tvm_tirx` namespaces before assigning a cause.\n- **B - Real kernel correctness regression**: Assertion failures (`cosine_sim`,\n  numerical diff), `CUDA: unspecified launch failure`, or wrong results. These\n  MUST be investigated and fixed if caused by current changes.\n- **C - Secondary xdist crash**: `KeyError: <WorkerController gwXX>` after a\n  worker abort. The KeyError itself is noise; find the underlying cause (usually\n  category B in another worker).\n\nNever dismiss a failure as pre-existing without evidence. If a test fails:\n\n1. Check whether the test touches code you changed.\n2. If unclear, verify on the parent commit before claiming it is pre-existing.\n3. Fix every failure caused by current changes; do not defer it.\n","AGENTS.md":"<!--\nLicensed to the Apache Software Foundation (ASF) under one\nor more contributor license agreements.  See the NOTICE file\ndistributed with this work for additional information\nregarding copyright ownership.  The ASF licenses this file\nto you under the Apache License, Version 2.0 (the\n\"License\"); you may not use this file except in compliance\nwith the License.  You may obtain a copy of the License at\n\n  http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing,\nsoftware distributed under the License is distributed on an\n\"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\nKIND, either express or implied.  See the License for the\nspecific language governing permissions and limitations\nunder the License.\n-->\n\n# AGENTS.md\n\nThis file provides vendor-neutral guidance for agentic coding tools working\nwith Apache TVM.\n\n## Repository Overview\n\nApache TVM is an open-source machine learning compiler stack. The repository\ncontains the C++ compiler/runtime, Python bindings, TIR/Relax IRs, scheduling\nand lowering passes, target code generators, runtime integrations, tests,\ndocumentation, and application examples.\n\n## Repository Structure\n\n- `include/tvm/` - public C++ headers\n- `src/` - C++ implementation\n- `python/tvm/` - Python package\n- `tests/` - C++, Python, integration, and lint tests\n- `cmake/` - CMake modules and default configuration\n- `3rdparty/` - vendored dependencies and submodules\n- `docs/` - documentation source\n- `apps/` - application examples\n- `.agents/skills/` - reusable agent workflows for this repository\n\n## Build\n\nUse an existing `build/` directory when present:\n\n```bash\ncmake --build build --parallel\n```\n\nFor a fresh checkout, initialize submodules and configure CMake first:\n\n```bash\ngit submodule update --init --recursive\nmkdir -p build\ncmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=RelWithDebInfo \\\n  -DTVM_TIRX_USE_LLVM=OFF -DTVM_TIRX_USE_CUDA=OFF\ncmake --build build --parallel\n```\n\nDevelopment should use `PYTHONPATH`, not editable installs:\n\n```bash\nexport PYTHONPATH=\"$(pwd)/python:$(pwd)/3rdparty/tvm-tirx/python:$(pwd)/.local/python\"\nexport TVM_TIRX_LIBRARY_PATH=\"$(pwd)/build/lib\"\n```\n\nDo not use `pip install -e` for TVM or `tvm-ffi`; editable installs can make\none worktree silently import another worktree's code.\n\n## Test And Lint\n\nRun the smallest relevant test first, then broaden as needed. Common examples:\n\n```bash\npython -m pytest 3rdparty/tvm-tirx/tests/python/codegen/llvm/test_minimal.py -xvs\npython -m pytest 3rdparty/tvm-tirx/tests/python/tirx/test_base.py -xvs\n./build/cpptest\n```\n\nFor lint validation on a pull request, run pre-commit on the files changed by\nthe branch instead of the whole repository:\n\n```bash\npre-commit run --files <changed-file>...\n```\n\nUse `python -m tirx_kernels.bench_suite` in the **tirx-kernels** repo\n(`tirx_kernels/bench_suite/`) when that workflow applies.\n\n## Coding Conventions\n\n- Follow the surrounding style before introducing new abstractions.\n- Keep changes scoped to the task and avoid unrelated cleanups.\n- Prefer explicit tests that show the IR or behavior being changed.\n- Use Apache TVM commit tags such as `[REFACTOR][IR]`, `[FIX][TIR]`, or\n  `[DOCS]` as appropriate.\n- Preserve Apache license headers in new source, script, and documentation\n  files when the surrounding tree uses them.\n"},"items":[{"name":"AGENTS.md","path":"AGENTS.md","rawUrl":"https://raw.githubusercontent.com/apache/tvm/HEAD/AGENTS.md","title":"AI Agent Protocol & Instructions","category":"root-instruction","format":"markdown","content":"<!--\nLicensed to the Apache Software Foundation (ASF) under one\nor more contributor license agreements.  See the NOTICE file\ndistributed with this work for additional information\nregarding copyright ownership.  The ASF licenses this file\nto you under the Apache License, Version 2.0 (the\n\"License\"); you may not use this file except in compliance\nwith the License.  You may obtain a copy of the License at\n\n  http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing,\nsoftware distributed under the License is distributed on an\n\"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\nKIND, either express or implied.  See the License for the\nspecific language governing permissions and limitations\nunder the License.\n-->\n\n# AGENTS.md\n\nThis file provides vendor-neutral guidance for agentic coding tools working\nwith Apache TVM.\n\n## Repository Overview\n\nApache TVM is an open-source machine learning compiler stack. The repository\ncontains the C++ compiler/runtime, Python bindings, TIR/Relax IRs, scheduling\nand lowering passes, target code generators, runtime integrations, tests,\ndocumentation, and application examples.\n\n## Repository Structure\n\n- `include/tvm/` - public C++ headers\n- `src/` - C++ implementation\n- `python/tvm/` - Python package\n- `tests/` - C++, Python, integration, and lint tests\n- `cmake/` - CMake modules and default configuration\n- `3rdparty/` - vendored dependencies and submodules\n- `docs/` - documentation source\n- `apps/` - application examples\n- `.agents/skills/` - reusable agent workflows for this repository\n\n## Build\n\nUse an existing `build/` directory when present:\n\n```bash\ncmake --build build --parallel\n```\n\nFor a fresh checkout, initialize submodules and configure CMake first:\n\n```bash\ngit submodule update --init --recursive\nmkdir -p build\ncmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=RelWithDebInfo \\\n  -DTVM_TIRX_USE_LLVM=OFF -DTVM_TIRX_USE_CUDA=OFF\ncmake --build build --parallel\n```\n\nDevelopment should use `PYTHONPATH`, not editable installs:\n\n```bash\nexport PYTHONPATH=\"$(pwd)/python:$(pwd)/3rdparty/tvm-tirx/python:$(pwd)/.local/python\"\nexport TVM_TIRX_LIBRARY_PATH=\"$(pwd)/build/lib\"\n```\n\nDo not use `pip install -e` for TVM or `tvm-ffi`; editable installs can make\none worktree silently import another worktree's code.\n\n## Test And Lint\n\nRun the smallest relevant test first, then broaden as needed. Common examples:\n\n```bash\npython -m pytest 3rdparty/tvm-tirx/tests/python/codegen/llvm/test_minimal.py -xvs\npython -m pytest 3rdparty/tvm-tirx/tests/python/tirx/test_base.py -xvs\n./build/cpptest\n```\n\nFor lint validation on a pull request, run pre-commit on the files changed by\nthe branch instead of the whole repository:\n\n```bash\npre-commit run --files <changed-file>...\n```\n\nUse `python -m tirx_kernels.bench_suite` in the **tirx-kernels** repo\n(`tirx_kernels/bench_suite/`) when that workflow applies.\n\n## Coding Conventions\n\n- Follow the surrounding style before introducing new abstractions.\n- Keep changes scoped to the task and avoid unrelated cleanups.\n- Prefer explicit tests that show the IR or behavior being changed.\n- Use Apache TVM commit tags such as `[REFACTOR][IR]`, `[FIX][TIR]`, or\n  `[DOCS]` as appropriate.\n- Preserve Apache license headers in new source, script, and documentation\n  files when the surrounding tree uses them.\n","isInternal":false,"tokens":830,"sizeBytes":3346},{"name":"SKILL.md","path":".agents/skills/tir-build/SKILL.md","rawUrl":"https://raw.githubusercontent.com/apache/tvm/HEAD/.agents/skills/tir-build/SKILL.md","title":"tir-build","category":"anthropic-skill","format":"markdown","content":"Build TVM from the current worktree.\n\n## Steps\n\n1. Check that `build/` directory exists. If not, run initial setup:\n   ```bash\n   mkdir -p build\n   cmake -S . -B build\n   cmake --build build --parallel\n   ```\n\n2. If `build/` already exists, run incremental build:\n   ```bash\n   cmake --build build --parallel\n   ```\n\n3. Report success/failure and build time.\n","isInternal":false,"tokens":99,"sizeBytes":359},{"name":"SKILL.md","path":".agents/skills/tir-test/SKILL.md","rawUrl":"https://raw.githubusercontent.com/apache/tvm/HEAD/.agents/skills/tir-test/SKILL.md","title":"tir-test","category":"anthropic-skill","format":"markdown","content":"---\nname: tir-test\ndescription: Run TVM's in-tree TIRx tests and tirx-kernels import and correctness checks.\n---\n\nRun the compiler suite in `3rdparty/tvm-tirx/tests/python/tirx/`, using the `tvm_tirx` package\nin `3rdparty/tvm-tirx/python/`, together with the downstream correctness test in\n`tests/python/tirx/test_tirx_kernels_registry_correctness.py`.\n\nBoth tirx-kernels import gates and its correctness coverage are enabled by\ndefault. Use `TIR_TEST_WITH_KERNELS=0` only for an explicitly requested\ncompiler-only run, and report that reduced coverage.\n\n## Steps\n\nRun all commands below in the same Bash shell from the TVM repository root.\n\n1. Point Python at this worktree and select every Blackwell GPU.\n   `TIR_TEST_GPUS` may explicitly provide physical GPU IDs, and\n   `TIR_TEST_NUM_GPUS` may optionally cap the automatically selected count. Otherwise,\n   selection uses all Blackwell GPUs, ordered by least memory in use.\n   ```bash\n   export TIR_TEST_TVM_ROOT=\"$(pwd -P)\"\n   export TIR_TEST_NUM_GPUS=\"${TIR_TEST_NUM_GPUS:-}\"\n   export TIR_TEST_XDIST_WORKERS=\"${TIR_TEST_XDIST_WORKERS:-16}\"\n   export TIR_TEST_WITH_KERNELS=\"${TIR_TEST_WITH_KERNELS:-1}\"\n\n   [[ -d \"$TIR_TEST_TVM_ROOT/3rdparty/tvm-tirx/python/tvm_tirx\" &&\n      -d \"$TIR_TEST_TVM_ROOT/3rdparty/tvm-tirx/tests/python/tirx\" ]] || {\n     echo \"run from the TVM repository root containing 3rdparty/tvm-tirx/\" >&2\n     exit 2\n   }\n   [[ \"$TIR_TEST_WITH_KERNELS\" == 0 || \"$TIR_TEST_WITH_KERNELS\" == 1 ]] || {\n     echo \"TIR_TEST_WITH_KERNELS must be 0 or 1\" >&2\n     exit 2\n   }\n\n   [[ -z \"$TIR_TEST_NUM_GPUS\" || \"$TIR_TEST_NUM_GPUS\" =~ ^[1-9][0-9]*$ ]] || {\n     echo \"TIR_TEST_NUM_GPUS must be empty or a positive integer\" >&2\n     exit 2\n   }\n   [[ \"$TIR_TEST_XDIST_WORKERS\" =~ ^[1-9][0-9]*$ ]] || {\n     echo \"TIR_TEST_XDIST_WORKERS must be a positive integer\" >&2\n     exit 2\n   }\n\n   if [[ -n \"${TIR_TEST_GPUS:-}\" ]]; then\n     IFS=, read -r -a TIR_TEST_SELECTED_GPUS <<< \"${TIR_TEST_GPUS// /}\"\n   else\n     mapfile -t TIR_TEST_SELECTED_GPUS < <(\n       nvidia-smi \\\n         --query-gpu=index,memory.used,compute_cap \\\n         --format=csv,noheader,nounits \\\n       | awk -F, '\n           {\n             for (i = 1; i <= 3; ++i) {\n               gsub(/^[[:space:]]+|[[:space:]]+$/, \"\", $i)\n             }\n             if (($3 + 0) >= 10) {\n               print $1, $2\n             }\n           }' \\\n       | sort -k2,2n -k1,1n \\\n       | awk '{print $1}'\n     )\n     if [[ -n \"$TIR_TEST_NUM_GPUS\" ]] && \\\n        (( ${#TIR_TEST_SELECTED_GPUS[@]} > TIR_TEST_NUM_GPUS )); then\n       TIR_TEST_SELECTED_GPUS=(\n         \"${TIR_TEST_SELECTED_GPUS[@]:0:TIR_TEST_NUM_GPUS}\"\n       )\n     fi\n   fi\n\n   (( ${#TIR_TEST_SELECTED_GPUS[@]} > 0 )) || {\n     echo \"no CUDA compute capability >= 10 GPU is available\" >&2\n     exit 1\n   }\n   for gpu in \"${TIR_TEST_SELECTED_GPUS[@]}\"; do\n     [[ \"$gpu\" =~ ^[0-9]+$ ]] || {\n       echo \"invalid physical GPU ID: $gpu\" >&2\n       exit 2\n     }\n   done\n   if [[ -z \"${TIR_TEST_GPUS:-}\" && -n \"$TIR_TEST_NUM_GPUS\" ]] && \\\n      (( ${#TIR_TEST_SELECTED_GPUS[@]} < TIR_TEST_NUM_GPUS )); then\n     echo \"warning: requested $TIR_TEST_NUM_GPUS GPUs, using ${#TIR_TEST_SELECTED_GPUS[@]}\"\n   fi\n\n   export CUDA_VISIBLE_DEVICES\n   CUDA_VISIBLE_DEVICES=\"$(IFS=,; printf '%s' \"${TIR_TEST_SELECTED_GPUS[*]}\")\"\n   # Preserve reference packages and other paths supplied by branch-shell.\n   export PYTHONPATH=\"${TIR_TEST_TVM_ROOT}/.local/python:${TIR_TEST_TVM_ROOT}/3rdparty/tvm-tirx/python:${TIR_TEST_TVM_ROOT}/python:${PYTHONPATH:-}\"\n   export TVM_LIBRARY_PATH=\"${TIR_TEST_TVM_ROOT}/build/lib\"\n   export TVM_TIRX_LIBRARY_PATH=\"${TIR_TEST_TVM_ROOT}/build/lib\"\n\n   PYTHON_BIN=\"${PYTHON_BIN:-$(command -v python || true)}\"\n   [[ -n \"$PYTHON_BIN\" && -x \"$PYTHON_BIN\" ]] || {\n     echo \"set PYTHON_BIN to the test environment's Python executable\" >&2\n     exit 1\n   }\n   export PATH=\"$(dirname \"$PYTHON_BIN\"):$PATH\"\n   \"$PYTHON_BIN\" - <<'PY'\n   import os\n   from pathlib import Path\n\n   import pytest\n   import torch\n   import tvm_ffi\n   import tvm_tirx\n   import xdist\n   from tvm_tirx.base import _LOADED_LIBS, _RUNTIME_ONLY\n\n   root = Path(os.environ[\"TIR_TEST_TVM_ROOT\"])\n   assert Path(tvm_tirx.__file__).resolve().is_relative_to(root / \"3rdparty/tvm-tirx/python\"), (\n       f\"imported another TIRx worktree: {tvm_tirx.__file__}\"\n   )\n   assert not _RUNTIME_ONLY, \"build the TIRx compiler before running its tests\"\n   for name, library in _LOADED_LIBS.items():\n       assert Path(library._name).resolve().is_relative_to(root / \"build/lib\"), (\n           f\"loaded another worktree's {name}: {library._name}\"\n       )\n   print(f\"tvm_tirx: {tvm_tirx.__file__}\")\n   print(f\"tvm_ffi: {tvm_ffi.__file__}\")\n   PY\n   if [[ $? -ne 0 ]]; then\n     echo \"PYTHON_BIN must provide pytest, xdist, torch and this worktree's TIRx build\" >&2\n     exit 1\n   fi\n   if ! command -v ninja >/dev/null; then\n     NINJA_BIN_DIR=\"$(\"$PYTHON_BIN\" -c 'import ninja; print(ninja.BIN_DIR)' 2>/dev/null || true)\"\n     if [[ -n \"$NINJA_BIN_DIR\" && -x \"$NINJA_BIN_DIR/ninja\" ]]; then\n       export PATH=\"$NINJA_BIN_DIR:$PATH\"\n     fi\n   fi\n   command -v ninja >/dev/null || {\n     echo \"ninja is required by kernel JIT setup but is not on PATH\" >&2\n     exit 1\n   }\n\n   echo \"selected physical GPUs: $CUDA_VISIBLE_DEVICES\"\n   for logical_id in \"${!TIR_TEST_SELECTED_GPUS[@]}\"; do\n     echo \"  cuda:$logical_id -> physical GPU ${TIR_TEST_SELECTED_GPUS[$logical_id]}\"\n   done\n   ```\n\n   Automatic selection uses every Blackwell device. Set\n   `TIR_TEST_NUM_GPUS=4` to cap the count or `TIR_TEST_GPUS=3,4,5,6` to override\n   selection with exact physical IDs.\n\n   Use dependencies compatible with `3rdparty/tvm-tirx/pyproject.toml`. A non-editable FFI\n   installation in `.local/python/` takes priority over the inherited environment.\n   If native libraries are missing or stale, build this worktree with the same\n   `PYTHONPATH` before testing.\n\n2. Run downstream import gates and select the full test coverage:\n   ```bash\n   TIR_TEST_PATHS=(3rdparty/tvm-tirx/tests/python/tirx/)\n   if [[ \"$TIR_TEST_WITH_KERNELS\" == 1 ]]; then\n     TIR_TEST_KERNELS_ROOT=\"${TIR_TEST_KERNELS_ROOT:-$(dirname \"$TIR_TEST_TVM_ROOT\")/tirx-kernels}\"\n     [[ -d \"$TIR_TEST_KERNELS_ROOT/tirx_kernels\" ]] || {\n       echo \"set TIR_TEST_KERNELS_ROOT to the tirx-kernels repository\" >&2\n       exit 2\n     }\n     export PYTHONPATH=\"${TIR_TEST_KERNELS_ROOT}:${PYTHONPATH:-}\"\n     \"$PYTHON_BIN\" -m tirx_kernels.bench_suite --check-imports || exit 1\n     \"$PYTHON_BIN\" -m tirx_kernels.registry --strict || exit 1\n     TIR_TEST_PATHS+=(tests/python/tirx/test_tirx_kernels_registry_correctness.py)\n     export TIRX_KERNEL_TEST_MIN_FREE_GB=\"${TIRX_KERNEL_TEST_MIN_FREE_GB:-0}\"\n   else\n     echo \"compiler-only run: tirx-kernels import and correctness checks disabled\"\n   fi\n   ```\n\n3. Run the selected test suites with xdist parallelism and save the full log:\n   ```bash\n   export TIR_TEST_LOG=\"${TIR_TEST_LOG:-/tmp/tir-test-$(date +%Y%m%d-%H%M%S).log}\"\n   set -o pipefail\n   \"$PYTHON_BIN\" -m pytest \"${TIR_TEST_PATHS[@]}\" -n \"$TIR_TEST_XDIST_WORKERS\" 2>&1 | tee \"$TIR_TEST_LOG\"\n   ```\n\n   `3rdparty/tvm-tirx/tests/python/tirx/conftest.py` uses `tvm_tirx.testing._pytest` to assign\n   each xdist worker's PyTorch current device round-robin across the visible\n   GPUs. Tests that explicitly use `tvm_tirx.cuda(0)` still run on the first\n   selected physical GPU.\n\n   Registry correctness tests take a per-device lock to serialize large workloads\n   on each GPU. MegaMoE remains skipped because it requires its dedicated\n   multi-process scheduler.\n\n4. Report results: selected physical GPUs, elapsed time, total passed, failed,\n   skipped, and errors, plus the full log path. Report both downstream gates as\n   passed, failed, or explicitly disabled; disabled integration checks are not\n   passes.\n\n## Failure triage rules\n\n**CRITICAL: Never pipe test output to `tail` or `grep` when diagnosing failures.\nAlways capture and read full logs.**\n\nClassify every failure into one of these categories:\n\n- **A - Environment/import error**: Module not found, missing dependency,\n  collection error. Check the source and native-library paths, FFI dependency,\n  and old `tvm` versus `tvm_tirx` namespaces before assigning a cause.\n- **B - Real kernel correctness regression**: Assertion failures (`cosine_sim`,\n  numerical diff), `CUDA: unspecified launch failure`, or wrong results. These\n  MUST be investigated and fixed if caused by current changes.\n- **C - Secondary xdist crash**: `KeyError: <WorkerController gwXX>` after a\n  worker abort. The KeyError itself is noise; find the underlying cause (usually\n  category B in another worker).\n\nNever dismiss a failure as pre-existing without evidence. If a test fails:\n\n1. Check whether the test touches code you changed.\n2. If unclear, verify on the parent commit before claiming it is pre-existing.\n3. Fix every failure caused by current changes; do not defer it.\n","frontmatter":{"name":"tir-test","description":"Run TVM's in-tree TIRx tests and tirx-kernels import and correctness checks."},"isInternal":false,"tokens":2566,"sizeBytes":8929}],"systemPromptSnippet":"<yakaai_skills repo=\"apache/tvm\">\n<!-- File: AGENTS.md (Tokens: ~830 | Category: root-instruction) -->\n<!--\nLicensed to the Apache Software Foundation (ASF) under one\nor more contributor license agreements.  See the NOTICE file\ndistributed with this work for additional information\nregarding copyright ownership.  The ASF licenses this file\nto you under the Apache License, Version 2.0 (the\n\"License\"); you may not use this file except in compliance\nwith the License.  You may obtain a copy of the License at\n\n  http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing,\nsoftware distributed under the License is distributed on an\n\"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\nKIND, either express or implied.  See the License for the\nspecific language governing permissions and limitations\nunder the License.\n-->\n\n# AGENTS.md\n\nThis file provides vendor-neutral guidance for agentic coding tools working\nwith Apache TVM.\n\n## Repository Overview\n\nApache TVM is an open-source machine learning compiler stack. The repository\ncontains the C++ compiler/runtime, Python bindings, TIR/Relax IRs, scheduling\nand lowering passes, target code generators, runtime integrations, tests,\ndocumentation, and application examples.\n\n## Repository Structure\n\n- `include/tvm/` - public C++ headers\n- `src/` - C++ implementation\n- `python/tvm/` - Python package\n- `tests/` - C++, Python, integration, and lint tests\n- `cmake/` - CMake modules and default configuration\n- `3rdparty/` - vendored dependencies and submodules\n- `docs/` - documentation source\n- `apps/` - application examples\n- `.agents/skills/` - reusable agent workflows for this repository\n\n## Build\n\nUse an existing `build/` directory when present:\n\n```bash\ncmake --build build --parallel\n```\n\nFor a fresh checkout, initialize submodules and configure CMake first:\n\n```bash\ngit submodule update --init --recursive\nmkdir -p build\ncmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=RelWithDebInfo \\\n  -DTVM_TIRX_USE_LLVM=OFF -DTVM_TIRX_USE_CUDA=OFF\ncmake --build build --parallel\n```\n\nDevelopment should use `PYTHONPATH`, not editable installs:\n\n```bash\nexport PYTHONPATH=\"$(pwd)/python:$(pwd)/3rdparty/tvm-tirx/python:$(pwd)/.local/python\"\nexport TVM_TIRX_LIBRARY_PATH=\"$(pwd)/build/lib\"\n```\n\nDo not use `pip install -e` for TVM or `tvm-ffi`; editable installs can make\none worktree silently import another worktree's code.\n\n## Test And Lint\n\nRun the smallest relevant test first, then broaden as needed. Common examples:\n\n```bash\npython -m pytest 3rdparty/tvm-tirx/tests/python/codegen/llvm/test_minimal.py -xvs\npython -m pytest 3rdparty/tvm-tirx/tests/python/tirx/test_base.py -xvs\n./build/cpptest\n```\n\nFor lint validation on a pull request, run pre-commit on the files changed by\nthe branch instead of the whole repository:\n\n```bash\npre-commit run --files <changed-file>...\n```\n\nUse `python -m tirx_kernels.bench_suite` in the **tirx-kernels** repo\n(`tirx_kernels/bench_suite/`) when that workflow applies.\n\n## Coding Conventions\n\n- Follow the surrounding style before introducing new abstractions.\n- Keep changes scoped to the task and avoid unrelated cleanups.\n- Prefer explicit tests that show the IR or behavior being changed.\n- Use Apache TVM commit tags such as `[REFACTOR][IR]`, `[FIX][TIR]`, or\n  `[DOCS]` as appropriate.\n- Preserve Apache license headers in new source, script, and documentation\n  files when the surrounding tree uses them.\n\n<!-- File: .agents/skills/tir-build/SKILL.md (Tokens: ~99 | Category: anthropic-skill) -->\nBuild TVM from the current worktree.\n\n## Steps\n\n1. Check that `build/` directory exists. If not, run initial setup:\n   ```bash\n   mkdir -p build\n   cmake -S . -B build\n   cmake --build build --parallel\n   ```\n\n2. If `build/` already exists, run incremental build:\n   ```bash\n   cmake --build build --parallel\n   ```\n\n3. Report success/failure and build time.\n\n<!-- File: .agents/skills/tir-test/SKILL.md (Tokens: ~2566 | Category: anthropic-skill) -->\n---\nname: tir-test\ndescription: Run TVM's in-tree TIRx tests and tirx-kernels import and correctness checks.\n---\n\nRun the compiler suite in `3rdparty/tvm-tirx/tests/python/tirx/`, using the `tvm_tirx` package\nin `3rdparty/tvm-tirx/python/`, together with the downstream correctness test in\n`tests/python/tirx/test_tirx_kernels_registry_correctness.py`.\n\nBoth tirx-kernels import gates and its correctness coverage are enabled by\ndefault. Use `TIR_TEST_WITH_KERNELS=0` only for an explicitly requested\ncompiler-only run, and report that reduced coverage.\n\n## Steps\n\nRun all commands below in the same Bash shell from the TVM repository root.\n\n1. Point Python at this worktree and select every Blackwell GPU.\n   `TIR_TEST_GPUS` may explicitly provide physical GPU IDs, and\n   `TIR_TEST_NUM_GPUS` may optionally cap the automatically selected count. Otherwise,\n   selection uses all Blackwell GPUs, ordered by least memory in use.\n   ```bash\n   export TIR_TEST_TVM_ROOT=\"$(pwd -P)\"\n   export TIR_TEST_NUM_GPUS=\"${TIR_TEST_NUM_GPUS:-}\"\n   export TIR_TEST_XDIST_WORKERS=\"${TIR_TEST_XDIST_WORKERS:-16}\"\n   export TIR_TEST_WITH_KERNELS=\"${TIR_TEST_WITH_KERNELS:-1}\"\n\n   [[ -d \"$TIR_TEST_TVM_ROOT/3rdparty/tvm-tirx/python/tvm_tirx\" &&\n      -d \"$TIR_TEST_TVM_ROOT/3rdparty/tvm-tirx/tests/python/tirx\" ]] || {\n     echo \"run from the TVM repository root containing 3rdparty/tvm-tirx/\" >&2\n     exit 2\n   }\n   [[ \"$TIR_TEST_WITH_KERNELS\" == 0 || \"$TIR_TEST_WITH_KERNELS\" == 1 ]] || {\n     echo \"TIR_TEST_WITH_KERNELS must be 0 or 1\" >&2\n     exit 2\n   }\n\n   [[ -z \"$TIR_TEST_NUM_GPUS\" || \"$TIR_TEST_NUM_GPUS\" =~ ^[1-9][0-9]*$ ]] || {\n     echo \"TIR_TEST_NUM_GPUS must be empty or a positive integer\" >&2\n     exit 2\n   }\n   [[ \"$TIR_TEST_XDIST_WORKERS\" =~ ^[1-9][0-9]*$ ]] || {\n     echo \"TIR_TEST_XDIST_WORKERS must be a positive integer\" >&2\n     exit 2\n   }\n\n   if [[ -n \"${TIR_TEST_GPUS:-}\" ]]; then\n     IFS=, read -r -a TIR_TEST_SELECTED_GPUS <<< \"${TIR_TEST_GPUS// /}\"\n   else\n     mapfile -t TIR_TEST_SELECTED_GPUS < <(\n       nvidia-smi \\\n         --query-gpu=index,memory.used,compute_cap \\\n         --format=csv,noheader,nounits \\\n       | awk -F, '\n           {\n             for (i = 1; i <= 3; ++i) {\n               gsub(/^[[:space:]]+|[[:space:]]+$/, \"\", $i)\n             }\n             if (($3 + 0) >= 10) {\n               print $1, $2\n             }\n           }' \\\n       | sort -k2,2n -k1,1n \\\n       | awk '{print $1}'\n     )\n     if [[ -n \"$TIR_TEST_NUM_GPUS\" ]] && \\\n        (( ${#TIR_TEST_SELECTED_GPUS[@]} > TIR_TEST_NUM_GPUS )); then\n       TIR_TEST_SELECTED_GPUS=(\n         \"${TIR_TEST_SELECTED_GPUS[@]:0:TIR_TEST_NUM_GPUS}\"\n       )\n     fi\n   fi\n\n   (( ${#TIR_TEST_SELECTED_GPUS[@]} > 0 )) || {\n     echo \"no CUDA compute capability >= 10 GPU is available\" >&2\n     exit 1\n   }\n   for gpu in \"${TIR_TEST_SELECTED_GPUS[@]}\"; do\n     [[ \"$gpu\" =~ ^[0-9]+$ ]] || {\n       echo \"invalid physical GPU ID: $gpu\" >&2\n       exit 2\n     }\n   done\n   if [[ -z \"${TIR_TEST_GPUS:-}\" && -n \"$TIR_TEST_NUM_GPUS\" ]] && \\\n      (( ${#TIR_TEST_SELECTED_GPUS[@]} < TIR_TEST_NUM_GPUS )); then\n     echo \"warning: requested $TIR_TEST_NUM_GPUS GPUs, using ${#TIR_TEST_SELECTED_GPUS[@]}\"\n   fi\n\n   export CUDA_VISIBLE_DEVICES\n   CUDA_VISIBLE_DEVICES=\"$(IFS=,; printf '%s' \"${TIR_TEST_SELECTED_GPUS[*]}\")\"\n   # Preserve reference packages and other paths supplied by branch-shell.\n   export PYTHONPATH=\"${TIR_TEST_TVM_ROOT}/.local/python:${TIR_TEST_TVM_ROOT}/3rdparty/tvm-tirx/python:${TIR_TEST_TVM_ROOT}/python:${PYTHONPATH:-}\"\n   export TVM_LIBRARY_PATH=\"${TIR_TEST_TVM_ROOT}/build/lib\"\n   export TVM_TIRX_LIBRARY_PATH=\"${TIR_TEST_TVM_ROOT}/build/lib\"\n\n   PYTHON_BIN=\"${PYTHON_BIN:-$(command -v python || true)}\"\n   [[ -n \"$PYTHON_BIN\" && -x \"$PYTHON_BIN\" ]] || {\n     echo \"set PYTHON_BIN to the test environment's Python executable\" >&2\n     exit 1\n   }\n   export PATH=\"$(dirname \"$PYTHON_BIN\"):$PATH\"\n   \"$PYTHON_BIN\" - <<'PY'\n   import os\n   from pathlib import Path\n\n   import pytest\n   import torch\n   import tvm_ffi\n   import tvm_tirx\n   import xdist\n   from tvm_tirx.base import _LOADED_LIBS, _RUNTIME_ONLY\n\n   root = Path(os.environ[\"TIR_TEST_TVM_ROOT\"])\n   assert Path(tvm_tirx.__file__).resolve().is_relative_to(root / \"3rdparty/tvm-tirx/python\"), (\n       f\"imported another TIRx worktree: {tvm_tirx.__file__}\"\n   )\n   assert not _RUNTIME_ONLY, \"build the TIRx compiler before running its tests\"\n   for name, library in _LOADED_LIBS.items():\n       assert Path(library._name).resolve().is_relative_to(root / \"build/lib\"), (\n           f\"loaded another worktree's {name}: {library._name}\"\n       )\n   print(f\"tvm_tirx: {tvm_tirx.__file__}\")\n   print(f\"tvm_ffi: {tvm_ffi.__file__}\")\n   PY\n   if [[ $? -ne 0 ]]; then\n     echo \"PYTHON_BIN must provide pytest, xdist, torch and this worktree's TIRx build\" >&2\n     exit 1\n   fi\n   if ! command -v ninja >/dev/null; then\n     NINJA_BIN_DIR=\"$(\"$PYTHON_BIN\" -c 'import ninja; print(ninja.BIN_DIR)' 2>/dev/null || true)\"\n     if [[ -n \"$NINJA_BIN_DIR\" && -x \"$NINJA_BIN_DIR/ninja\" ]]; then\n       export PATH=\"$NINJA_BIN_DIR:$PATH\"\n     fi\n   fi\n   command -v ninja >/dev/null || {\n     echo \"ninja is required by kernel JIT setup but is not on PATH\" >&2\n     exit 1\n   }\n\n   echo \"selected physical GPUs: $CUDA_VISIBLE_DEVICES\"\n   for logical_id in \"${!TIR_TEST_SELECTED_GPUS[@]}\"; do\n     echo \"  cuda:$logical_id -> physical GPU ${TIR_TEST_SELECTED_GPUS[$logical_id]}\"\n   done\n   ```\n\n   Automatic selection uses every Blackwell device. Set\n   `TIR_TEST_NUM_GPUS=4` to cap the count or `TIR_TEST_GPUS=3,4,5,6` to override\n   selection with exact physical IDs.\n\n   Use dependencies compatible with `3rdparty/tvm-tirx/pyproject.toml`. A non-editable FFI\n   installation in `.local/python/` takes priority over the inherited environment.\n   If native libraries are missing or stale, build this worktree with the same\n   `PYTHONPATH` before testing.\n\n2. Run downstream import gates and select the full test coverage:\n   ```bash\n   TIR_TEST_PATHS=(3rdparty/tvm-tirx/tests/python/tirx/)\n   if [[ \"$TIR_TEST_WITH_KERNELS\" == 1 ]]; then\n     TIR_TEST_KERNELS_ROOT=\"${TIR_TEST_KERNELS_ROOT:-$(dirname \"$TIR_TEST_TVM_ROOT\")/tirx-kernels}\"\n     [[ -d \"$TIR_TEST_KERNELS_ROOT/tirx_kernels\" ]] || {\n       echo \"set TIR_TEST_KERNELS_ROOT to the tirx-kernels repository\" >&2\n       exit 2\n     }\n     export PYTHONPATH=\"${TIR_TEST_KERNELS_ROOT}:${PYTHONPATH:-}\"\n     \"$PYTHON_BIN\" -m tirx_kernels.bench_suite --check-imports || exit 1\n     \"$PYTHON_BIN\" -m tirx_kernels.registry --strict || exit 1\n     TIR_TEST_PATHS+=(tests/python/tirx/test_tirx_kernels_registry_correctness.py)\n     export TIRX_KERNEL_TEST_MIN_FREE_GB=\"${TIRX_KERNEL_TEST_MIN_FREE_GB:-0}\"\n   else\n     echo \"compiler-only run: tirx-kernels import and correctness checks disabled\"\n   fi\n   ```\n\n3. Run the selected test suites with xdist parallelism and save the full log:\n   ```bash\n   export TIR_TEST_LOG=\"${TIR_TEST_LOG:-/tmp/tir-test-$(date +%Y%m%d-%H%M%S).log}\"\n   set -o pipefail\n   \"$PYTHON_BIN\" -m pytest \"${TIR_TEST_PATHS[@]}\" -n \"$TIR_TEST_XDIST_WORKERS\" 2>&1 | tee \"$TIR_TEST_LOG\"\n   ```\n\n   `3rdparty/tvm-tirx/tests/python/tirx/conftest.py` uses `tvm_tirx.testing._pytest` to assign\n   each xdist worker's PyTorch current device round-robin across the visible\n   GPUs. Tests that explicitly use `tvm_tirx.cuda(0)` still run on the first\n   selected physical GPU.\n\n   Registry correctness tests take a per-device lock to serialize large workloads\n   on each GPU. MegaMoE remains skipped because it requires its dedicated\n   multi-process scheduler.\n\n4. Report results: selected physical GPUs, elapsed time, total passed, failed,\n   skipped, and errors, plus the full log path. Report both downstream gates as\n   passed, failed, or explicitly disabled; disabled integration checks are not\n   passes.\n\n## Failure triage rules\n\n**CRITICAL: Never pipe test output to `tail` or `grep` when diagnosing failures.\nAlways capture and read full logs.**\n\nClassify every failure into one of these categories:\n\n- **A - Environment/import error**: Module not found, missing dependency,\n  collection error. Check the source and native-library paths, FFI dependency,\n  and old `tvm` versus `tvm_tirx` namespaces before assigning a cause.\n- **B - Real kernel correctness regression**: Assertion failures (`cosine_sim`,\n  numerical diff), `CUDA: unspecified launch failure`, or wrong results. These\n  MUST be investigated and fixed if caused by current changes.\n- **C - Secondary xdist crash**: `KeyError: <WorkerController gwXX>` after a\n  worker abort. The KeyError itself is noise; find the underlying cause (usually\n  category B in another worker).\n\nNever dismiss a failure as pre-existing without evidence. If a test fails:\n\n1. Check whether the test touches code you changed.\n2. If unclear, verify on the parent commit before claiming it is pre-existing.\n3. Fix every failure caused by current changes; do not defer it.\n</yakaai_skills>"}