[FIX][TIRx] Preserve pointer expression types - #20070
Merged
spectrometerHBH merged 1 commit intoJul 29, 2026
Merged
Conversation
Bind unannotated pointer expressions as immutable pointer Vars instead of trying to materialize them as local scalars. Keep buffer element types on address_of, accept PrimType inputs in pointer helpers, and pass TMA descriptor dtypes as strings to packed host initialization.
Contributor
|
Caution The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased. |
jinhongyii
marked this pull request as draft
July 29, 2026 05:01
jinhongyii
marked this pull request as ready for review
July 29, 2026 05:12
Contributor
|
Caution The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased. |
spectrometerHBH
approved these changes
Jul 29, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation and context
A TIRx pointer carries two pieces of information that later lowering needs: the pointee element type and the storage scope. Both must survive when a pointer-producing expression is assigned to a Python name and then used as the backing storage of a buffer.
A concrete example is accessing an mbarrier in another CTA through distributed shared memory:
map_shared_rankreturns the rawuint64address produced by PTXmapa, andreinterpretgives that address the intendedPointerType(uint64, shared). Becausedecl_buffer(data=...)requires a pointerVar, assigning the expression toremote_ptrshould create an immutable typed pointer binding.Before this PR, an unannotated assignment such as
remote_ptr = <pointer expression>followed the same parser path as a numeric assignment. That path allocates a mutable local scalar and therefore cannot represent aPointerType. The pointer expression could not be carried as a correctly typedVarintodecl_bufferand CUDA lowering.This PR makes an unannotated pointer-valued assignment emit a TIRx
Bind. The boundVarhas exactly the type of the right-hand side, including its element type and storage scope. Pointer bindings are immutable, so reassignment in the same scope is diagnosed; shadowing a name supplied throughextra_varsremains valid. Numeric assignments keep their existing mutable-local behavior.Type propagation fixes
The parser fix exposed several other boundaries where pointer type information must remain consistent:
Bindwith the RHSPointerTypeaddress_of(buffer)/buffer.ptr_to(...)buffer.dtypewhile preserving the backing pointer storage scopetvm_access_ptr/ptr_byte_offsetPrimTypeobject directlyPrimTypeand produces the corresponding typed pointerT.ptx.mapacallThe
address_ofdistinction matters for typed views over byte-addressed storage. For example, if afloat32buffer is backed by auint8*allocation inshared.dyn, the address of a buffer element must bePointerType(float32, shared.dyn), notPointerType(uint8, shared.dyn).With these changes, the DSMEM example above round-trips through TVMScript and CUDA codegen declares the remote buffer pointer as
uint64_t*.TMA dtype normalization
This PR also contains a small, separate type-representation fix in TMA descriptor construction.
TmaPlan.elem_dtypeis a string consumed by the host-sideruntime.cuTensorMapEncodeTiledpacked call, but_assemble_planstoredg_buf.dtype, which is aPrimType. Converting it withstr(g_buf.dtype)ensures that the generated packed-call argument isStringImm("float16")rather than an IR type object. This does not change the pointer-binding semantics described above.Testing
BindwhoseVartype matches the RHS type.extra_varsname is allowed.T.ptx.mapacall.address_ofuses the logical buffer element type and preserves the storage scope for byte-backed buffer views.tvm_access_ptrandptr_byte_offsetacceptPrimTypeinputs.map_shared_rankexample through the CUDA TIRx pipeline and check for a typeduint64_t*remote buffer pointer.StringImm.