Skip to content

[DataType] Update to use explicit Bool Type Aligning with DLPack#18453

Merged
tlopex merged 1 commit into
apache:mainfrom
tqchen:tvm-ffi-bringup
Nov 15, 2025
Merged

[DataType] Update to use explicit Bool Type Aligning with DLPack#18453
tlopex merged 1 commit into
apache:mainfrom
tqchen:tvm-ffi-bringup

Conversation

@tqchen

@tqchen tqchen commented Nov 14, 2025

Copy link
Copy Markdown
Member

This PR updates the project to use explicit bool type which helps us to align with dlpack. It will also streamline explicit use of bool types.

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @tqchen, 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 introduces a significant refactoring of how boolean data types are handled within the project. By transitioning from an implicit representation (1-bit unsigned integers) to an explicit kDLBool type, the project enhances its alignment with the DLPack standard. This change streamlines the definition, checking, and processing of boolean types across the runtime, TIR, and code generation components, ensuring more robust and explicit type handling throughout the system.

Highlights

  • Explicit Boolean Type Introduction: The project now uses an explicit kDLBool type to represent booleans, aligning with the DLPack standard. Previously, booleans were implicitly represented as 1-bit unsigned integers (kUInt with bits=1).
  • DataType Class Updates: The DataType class in include/tvm/runtime/data_type.h has been updated to include kBool in its TypeCode enum. The is_bool() method now directly checks for kBool, and a new is_predicate_dtype() method has been added to handle both kBool and 1-bit unsigned integers for predicate expressions. The DataType::Bool() constructor now explicitly creates a kDLBool type with 8 bits.
  • TIR Operations and Constant Folding: TIR operations like const_true() and const_false() now leverage the new explicit DataType::Bool(). Constant folding logic for comparison and bitwise operators has been updated to return DataType::Bool() results. Additionally, MakeConstScalar and various type-checking functions for bitwise operations now explicitly support the is_bool() type.
  • Code Generation Updates: LLVM and SPIRV code generation backends have been adapted to recognize and correctly handle the new explicit boolean type. This includes mapping kDLBool to LLVM's 1-bit integer type (t_int1_), and updating type declarations, casting rules, and comparison operations in SPIRV to use DataType::Bool().
  • Python Bindings and Tests: Python bindings and various test cases across arith, relax, and tir modules have been modified to reflect the change, using dtype='bool' instead of dtype='uint1' where appropriate, ensuring consistency with the new explicit boolean type.
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.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

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.

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

Copy link
Copy Markdown
Contributor

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 introduces an explicit bool type to align with DLPack, replacing the previous uint1 representation. The changes are extensive and consistently applied across the codebase, including data type definitions, operator implementations, constant folding, and tests. The introduction of is_predicate_dtype is a good way to maintain backward compatibility during this transition.

I've found a couple of minor issues:

  1. A copy-pasted Doxygen comment in data_type.h.
  2. Inconsistent use of DataType::Bool() and DataType::Bool(1) in const_fold.h.

Overall, this is a solid refactoring that improves type safety and clarity. My review comments provide suggestions to address the minor issues.

Comment thread include/tvm/runtime/data_type.h
Comment thread src/arith/const_fold.h Outdated
Comment thread src/arith/const_fold.h Outdated
Comment thread src/arith/const_fold.h Outdated
This PR updates the project to use explicit bool type which helps
us to align with dlpack. It will also streamline explicit use of bool types.
@tlopex tlopex merged commit b6ac072 into apache:main Nov 15, 2025
13 checks passed
LeiWang1999 pushed a commit to tile-ai/tvm that referenced this pull request Nov 19, 2025
…che#18453)

This PR updates the project to use explicit bool type which helps us to
align with dlpack. It will also streamline explicit use of bool types.
LeiWang1999 added a commit to tile-ai/tvm that referenced this pull request Nov 19, 2025
LeiWang1999 added a commit to tile-ai/tvm that referenced this pull request Nov 20, 2025
LeiWang1999 added a commit to tile-ai/tvm that referenced this pull request Nov 20, 2025
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