Skip to content

[NFC] meaningful naming for aggregate types#9347

Merged
peterbell10 merged 7 commits intotriton-lang:mainfrom
sjw36:sjw/codegen-names
Feb 11, 2026
Merged

[NFC] meaningful naming for aggregate types#9347
peterbell10 merged 7 commits intotriton-lang:mainfrom
sjw36:sjw/codegen-names

Conversation

@sjw36
Copy link
Copy Markdown
Contributor

@sjw36 sjw36 commented Jan 31, 2026

Generate <name>.<field> for aggregate fields, including <index> for tuples.

This change adds a _set_name method to base_value and all derived types.

NOTE: this could impact language extensions.

Copy link
Copy Markdown
Contributor

@peterbell10 peterbell10 left a comment

Choose a reason for hiding this comment

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

Looks really useful, could you add a test though?

Comment thread python/triton/language/core.py Outdated
return value, cursor

def _flatten_ir_types(self, builder: ir.builder, out: List[ir.type]) -> None:
## FOUND TENSOR DESCRIPTOR TYPE HERE
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.

?

Comment thread python/triton/language/core.py Outdated
)

def _set_name(self, builder: ir.builder, name: str) -> None:
self.handle.set_loc(builder.create_name_loc(name, self.handle.get_loc()))
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.

Can you do this in tensor_descriptor_base?

Comment thread python/triton/language/core.py Outdated

def _set_name(self, builder: ir.builder, name: str) -> None:
for i, v in enumerate(self.values):
v._set_name(builder, f"{name}.{i}")
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.

Can you use the field names for named tuples?

@sjw36
Copy link
Copy Markdown
Contributor Author

sjw36 commented Feb 4, 2026

Thanks @peterbell10 ! I think I have addressed your feedback. Let me know if you see anything else.

type: base_type

def _set_name(self, builder: ir.builder, name: str) -> None:
raise NotImplementedError
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.

Test failures are real. Might be worth having a default implementation?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Hmm, looks like the formatter added a line and threw off the line numbers.
I don't have an AMD gpu but thought I found all the derivations from base_value.. I'll track these down.

I could have the base_value implementation do what the old impl did, calling _flatten_ir.. That would be reasonable for any unknown derivations. But having the assert also forces those to think about naming.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

@sjw36
Copy link
Copy Markdown
Contributor Author

sjw36 commented Feb 9, 2026

Apparently, not entirely fixed.. investigating

@sjw36
Copy link
Copy Markdown
Contributor Author

sjw36 commented Feb 10, 2026

Tests cleaned up, no longer perturbs line numbers.

  • also disabled tensordesc for AMD since it flattens in triton-rewrite-tensor-descriptor-to-pointer

Generate `<name>.<field>` for aggregate fields, including `<index>` for tuples.
- address review feedback
- added test
- update test for line_num changes
- self-contained tests for tensordesc (only on cuda) and namedtuples
@sjw36 sjw36 force-pushed the sjw/codegen-names branch from 6b9ab39 to b8c4c56 Compare February 11, 2026 15:12
@sjw36
Copy link
Copy Markdown
Contributor Author

sjw36 commented Feb 11, 2026

Also disabled test for ampere.

@peterbell10 Is there a reason tensordesc codegen cannot be uniform across all architectures?

@peterbell10
Copy link
Copy Markdown
Contributor

tensordesc is backed by a hardware feature which not all devices have, so it has a fallback that decomposes it.

@peterbell10 peterbell10 enabled auto-merge (squash) February 11, 2026 16:39
@sjw36
Copy link
Copy Markdown
Contributor Author

sjw36 commented Feb 11, 2026

Right, I'm mostly wondering why the function params cannot uniformly be codegen'd to:

  • tensordesc
  • shape
  • strides

Then later architectures that do not support TDM could just convert the tensordesc to tt.ptr (and maybe add padding) and use the shape and strides as is.

Currently it generates the same fields anyway in triton-rewrite-tensor-descriptor-to-pointer, well, and also a padding field, and also 1 more that is not documented.

I guess there should be some way to associate all related params to a tensordesc as well, so that the runtime can programmatically specify the arguments. This could also lead to removing unused args. I can put up a PR to this effect if it makes sense.

@peterbell10 peterbell10 merged commit 2b1031d into triton-lang:main Feb 11, 2026
9 checks passed
ThomasRaoux added a commit that referenced this pull request Feb 12, 2026
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