Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[ABI] Add begin_index to TypeAttrColumn#471

Merged
yongwww merged 1 commit into
apache:mainfrom
tqchen:typeattr-column-begin-index
Feb 22, 2026
Merged

[ABI] Add begin_index to TypeAttrColumn#471
yongwww merged 1 commit into
apache:mainfrom
tqchen:typeattr-column-begin-index

Conversation

@tqchen
Copy link
Copy Markdown
Member

@tqchen tqchen commented Feb 22, 2026

This PR adds a begin_index field to TypeAttrColumn. The begin_index enables the type attributes to store narrowly a range of type indices which can be useful when type attribute is narrowed to specific subscope where objects are allocated continuously so we can optimize for space and locality.

As of now the accessor of the TypeAttrColumn is limited to extra/cc so impact is limited. To be careful, we begin_index is set to 0 for next few versions and will migrate to nonzero size in 1.0 (so i64 platform size is compatible)

@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 begin_index field to the TypeAttrColumn structure, allowing for more efficient and sparse storage of type attributes. This enhancement optimizes memory usage and locality by enabling attributes to be stored for specific ranges of type indices. The changes are designed to be ABI backward-compatible, ensuring seamless integration and functionality with existing systems.

Highlights

  • Introduced begin_index to TVMFFITypeAttrColumn: A new begin_index field was added to the TVMFFITypeAttrColumn struct, enabling sparse storage of type attributes and improving memory locality and space efficiency.
  • ABI-compatible size field change: The size field in TVMFFITypeAttrColumn was changed from size_t to int32_t to maintain ABI backward compatibility with the introduction of begin_index.
  • Updated attribute lookup logic: The attribute lookup mechanisms in C++ (AnyHash, AnyEqual, TypeAttrColumn::operator[]), Python (Cython's _lookup_type_attr), and Rust FFI were updated to correctly use the begin_index for calculating data offsets.
  • Dynamic TypeAttrColumn management: The TypeTable implementation was enhanced to dynamically manage TypeAttrColumnData, including initializing begin_index, handling resizing (prepending or appending elements), and ensuring correct attribute assignment based on the new offset logic.
  • New test case for begin_index: A new C++ test (TypeAttrColumnBeginIndex) was added to verify the correct functionality and behavior of TypeAttrColumn with the newly introduced begin_index.

🧠 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.

Changelog
  • include/tvm/ffi/any.h
    • Updated AnyHash and AnyEqual to use begin_index for calculating the correct offset when looking up custom type attributes.
  • include/tvm/ffi/c_api.h
    • Modified the TVMFFITypeAttrColumn struct by adding begin_index and changing size from size_t to int32_t.
    • Updated documentation for TVMFFITypeAttrColumn to reflect the new fields and lookup mechanism.
  • include/tvm/ffi/reflection/accessor.h
    • Adjusted the TypeAttrColumn::operator[] to calculate the data offset using the new begin_index.
  • python/tvm_ffi/cython/base.pxi
    • Synchronized the Cython definition of TVMFFITypeAttrColumn with the C++ changes, adding begin_index and updating size to int32_t.
  • python/tvm_ffi/cython/object.pxi
    • Modified the _lookup_type_attr function to correctly use begin_index for accessing type attributes.
  • rust/tvm-ffi-sys/src/c_api.rs
    • Updated the Rust FFI binding for TVMFFITypeAttrColumn to reflect the addition of begin_index and the type change of size.
  • src/ffi/object.cc
    • Implemented the core logic for managing TypeAttrColumnData, including initializing begin_index.
    • Added logic to handle dynamic resizing (extending front or back) of the attribute data based on type_index relative to begin_index.
    • Ensured correct attribute assignment based on the new offset calculation.
  • tests/cpp/test_reflection.cc
    • Added a new test TypeAttrColumnBeginIndex to verify the correct behavior of attribute lookup with the begin_index in place.
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.

Copy link
Copy Markdown
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 introduces a begin_index to TypeAttrColumn to optimize for space and locality by allowing type attributes to cover a narrow range of type indices. The changes are propagated through C++, Python, and Rust FFI layers, and a new test case is added to verify the functionality.

While the changes are generally well-implemented, I've identified a critical ABI compatibility issue with the modification of the TVMFFITypeAttrColumn struct. I've also suggested a performance and readability improvement for the vector manipulation logic in src/ffi/object.cc. Please see my detailed comments.

Comment thread include/tvm/ffi/c_api.h
Comment thread src/ffi/object.cc Outdated
@tqchen tqchen force-pushed the typeattr-column-begin-index branch 2 times, most recently from ac9cf9f to 777318e Compare February 22, 2026 15:54
@tqchen
Copy link
Copy Markdown
Member Author

tqchen commented Feb 22, 2026

/gemini review

Copy link
Copy Markdown
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 introduces a begin_index field to the TVMFFITypeAttrColumn structure, enabling sparse storage of type attributes by specifying a range of type indices. The changes include updates to the C API, C++ accessors, and language bindings for Python and Rust. While the logic for indexing and bounds checking is sound, the claim of ABI compatibility is limited to 64-bit little-endian systems and does not hold for 32-bit or big-endian platforms. Additionally, there is some redundancy in the internal TypeAttrColumnData structure that should be addressed for better maintainability.

Comment thread include/tvm/ffi/c_api.h
Comment thread src/ffi/object.cc
Comment thread src/ffi/object.cc
Comment thread src/ffi/object.cc Outdated
Comment thread src/ffi/object.cc Outdated
@tqchen tqchen force-pushed the typeattr-column-begin-index branch from 777318e to f7ee338 Compare February 22, 2026 16:01
@yongwww yongwww merged commit c85fd42 into apache:main Feb 22, 2026
8 checks passed
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