Skip to content

[Refactor] Bring up tirx namespace#18913

Open
tqchen wants to merge 3 commits intoapache:mainfrom
tqchen:refactor-and-rename-tir-namespace-to-tirx
Open

[Refactor] Bring up tirx namespace#18913
tqchen wants to merge 3 commits intoapache:mainfrom
tqchen:refactor-and-rename-tir-namespace-to-tirx

Conversation

@tqchen
Copy link
Member

@tqchen tqchen commented Mar 19, 2026

This PR brings up the tirx namespace. We have been spliting out the original tir namespace to include high-level component s_tir and this PR updates the remaining low-level part as tirx namespace

tqchen added 2 commits March 19, 2026 03:34
This PR renames the tir namespace to tirx across the codebase:
- include/tvm/tir/ → include/tvm/tirx/
- src/tir/ → src/tirx/
- python/tvm/tir/ → python/tvm/tirx/
- C++ namespace tvm::tir → tvm::tirx
- All FFI strings, op registrations, and type keys updated
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request implements a significant refactoring of the TensorIR (TIR) infrastructure by introducing a new tirx namespace for its low-level components. This change clarifies the architectural separation between different layers of the TVM compiler stack, improving modularity and maintainability. The update involves renaming the namespace, adjusting file paths, and updating all internal and external references to reflect the new naming convention.

Highlights

  • Namespace Renaming: The core TensorIR (TIR) namespace has been systematically renamed from tir to tirx across the entire codebase. This refactoring aims to clearly delineate low-level TIR components from higher-level s_tir components.
  • Codebase-Wide Updates: All references to the tir namespace in C++ headers, Python modules, build configurations (CMakeLists.txt), and documentation files (.rst, .md, .py) have been updated to tirx.
  • File Structure Adjustment: Several files and directories related to the TensorIR implementation and its documentation have been renamed to align with the new tirx namespace, ensuring consistency in the project structure.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request is a large-scale refactoring to rename the tir namespace to tirx. The changes are extensive, touching code, documentation, and configuration files. The modifications appear to be mostly correct and consistent with the refactoring goal. I've identified a few minor inconsistencies in the documentation that should be updated for clarity and consistency.

tirx transformations contain a collection of passes that apply to tirx functions. There are two major types of transformations:

- **TensorIR schedule**: TensorIR schedules are designed to optimize the TensorIR functions for a specific target, with user-guided instructions and control how the target code is generated.
For CPU targets, TIR PrimFunc can generate valid code and execute on the target device without schedule but with very-low performance. However, for GPU targets, the schedule is essential
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

For consistency with other parts of the document (e.g., line 67 which uses tirx::PrimFunc), TIR PrimFunc should be updated to tirx::PrimFunc.

Suggested change
For CPU targets, TIR PrimFunc can generate valid code and execute on the target device without schedule but with very-low performance. However, for GPU targets, the schedule is essential
For CPU targets, tirx::PrimFunc can generate valid code and execute on the target device without schedule but with very-low performance. However, for GPU targets, the schedule is essential

for generating valid code with thread bindings. For more details, please refer to the :ref:`TensorIR Transformation <tir-transform>` section. Additionally, we provides ``MetaSchedule`` to
for generating valid code with thread bindings. For more details, please refer to the :ref:`TensorIR Transformation <tirx-transform>` section. Additionally, we provides ``MetaSchedule`` to
automate the search of TensorIR schedule.
- **Lowering Passes**: These passes usually perform after the schedule is applied, transforming a TIR PrimFunc into another functionally equivalent PrimFunc, but closer to the
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

For consistency with other parts of the document, a TIR PrimFunc should be updated to a tirx::PrimFunc.

Suggested change
- **Lowering Passes**: These passes usually perform after the schedule is applied, transforming a TIR PrimFunc into another functionally equivalent PrimFunc, but closer to the
- **Lowering Passes**: These passes usually perform after the schedule is applied, transforming a tirx::PrimFunc into another functionally equivalent PrimFunc, but closer to the

Apache TVM enables cross-level optimization of end-to-end models. As the IRModule includes both relax and tirx functions, the cross-level transformations are designed to mutate
the IRModule by applying different transformations to these two types of functions.

For example, ``relax.LegalizeOps`` pass mutates the IRModule by lowering relax operators, adding corresponding TIR PrimFunc into the IRModule, and replacing the relax operators
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

For consistency, TIR PrimFunc should be updated to tirx::PrimFunc.

Suggested change
For example, ``relax.LegalizeOps`` pass mutates the IRModule by lowering relax operators, adding corresponding TIR PrimFunc into the IRModule, and replacing the relax operators
For example, ``relax.LegalizeOps`` pass mutates the IRModule by lowering relax operators, adding corresponding tirx::PrimFunc into the IRModule, and replacing the relax operators

Comment on lines +310 to +316
TIR contains the definition of the low-level program representations. We use `tirx::PrimFunc` to represent functions that can be transformed by TIR passes.
Besides the IR data structures, the tirx module also includes:

- A set of schedule primitives to control the generated code in ``tir/schedule``.
- A set of builtin intrinsics in ``tir/tensor_intrin``.
- A set of analysis passes to analyze the TIR functions in ``tir/analysis``.
- A set of transformation passes to lower or optimize the TIR functions in ``tir/transform``.
- A set of schedule primitives to control the generated code in ``tirx/schedule``.
- A set of builtin intrinsics in ``tirx/tensor_intrin``.
- A set of analysis passes to analyze the TIR functions in ``tirx/analysis``.
- A set of transformation passes to lower or optimize the TIR functions in ``tirx/transform``.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

For consistency with the rest of the refactoring, TIR passes should be tirx passes, and TIR functions should be tirx functions.

Suggested change
TIR contains the definition of the low-level program representations. We use `tirx::PrimFunc` to represent functions that can be transformed by TIR passes.
Besides the IR data structures, the tirx module also includes:
- A set of schedule primitives to control the generated code in ``tir/schedule``.
- A set of builtin intrinsics in ``tir/tensor_intrin``.
- A set of analysis passes to analyze the TIR functions in ``tir/analysis``.
- A set of transformation passes to lower or optimize the TIR functions in ``tir/transform``.
- A set of schedule primitives to control the generated code in ``tirx/schedule``.
- A set of builtin intrinsics in ``tirx/tensor_intrin``.
- A set of analysis passes to analyze the TIR functions in ``tirx/analysis``.
- A set of transformation passes to lower or optimize the TIR functions in ``tirx/transform``.
TIR contains the definition of the low-level program representations. We use `tirx::PrimFunc` to represent functions that can be transformed by tirx passes.
Besides the IR data structures, the tirx module also includes:
- A set of schedule primitives to control the generated code in ``tirx/schedule``.
- A set of builtin intrinsics in ``tirx/tensor_intrin``.
- A set of analysis passes to analyze the tirx functions in ``tirx/analysis``.
- A set of transformation passes to lower or optimize the tirx functions in ``tirx/transform``.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants