This is an archive of the discontinued LLVM Phabricator instance.

[mlir][gpu] Add the GPU Target Attr trait.
Needs ReviewPublic

Authored by fmorac on Aug 18 2023, 6:53 AM.

Details

Summary

The TargetAttrTrait indicates that an attribute implements or promises to implement
the TargetAttrInterface interface.

This trait is needed to avoid IR verification failures caused by not registering the
TargetAttrInterface in places where the implmentation is not needed. For example,
mlir-translate doesn't uses the interface, so there's no need to register them.

Diff Detail

Event Timeline

fmorac created this revision.Aug 18 2023, 6:53 AM
Herald added a reviewer: dcaballe. · View Herald Transcript
Herald added a project: Restricted Project. · View Herald Transcript
fmorac published this revision for review.Aug 18 2023, 9:29 AM

This patch also solves the need to add registration calls for Target Attributes in Translation registration, see D157703.

mehdi_amini added inline comments.Aug 18 2023, 2:04 PM
mlir/include/mlir/Dialect/GPU/IR/CompilationAttrInterfaces.td
58

How is it enforced? Is it just a "convention"?

fmorac added inline comments.Aug 18 2023, 2:11 PM
mlir/include/mlir/Dialect/GPU/IR/CompilationAttrInterfaces.td
58

Right now it's just a convention, i think there's no proper way to enforce it yet.

I'm thinking proposing an extension to the promised interface mechanism, where this decoupling of the trait and the interfaces is made automatically by tablegen, with the trait verifying there's an implementation or a promise.

I'm not sure what does the trait provides right now? If you just remove the verifier for ObjectAttr and remove the trait, don't you get basically the same properties?

I'm not sure what does the trait provides right now? If you just remove the verifier for ObjectAttr and remove the trait, don't you get basically the same properties?

If I remove the verifier and let #gpu.object hold any target attribute instead of constraining it to the trait or the interface, then yes, the issue is solved. The trait only removes the need for registering the interface in instances where is not needed, for example registering the NVVMTarget interface in mlir-translate.

bondhugula added inline comments.Aug 20 2023, 7:13 AM
mlir/include/mlir/Dialect/GPU/IR/CompilationAttrInterfaces.td
23

The 'description` field needs to document what this is.

mlir/lib/Dialect/GPU/IR/GPUDialect.cpp
1966

No full stops at the end of emit message. The diagnostic continues beyond this.

1985

Likewise.

fmorac updated this revision to Diff 552158.Aug 21 2023, 4:02 PM
fmorac marked 2 inline comments as done.

Addressed comments. If this patch D158464 gets through, this diff will be repurposed to use the changes in the aforementioned diff.

mlir/include/mlir/Dialect/GPU/IR/CompilationAttrInterfaces.td
23

AFAIK NativeTrait doesn't have a description field, or at least is not in the class definition. Is there another way to add it?

mlir/lib/Dialect/GPU/IR/GPUDialect.cpp
1966

changed.

1985

changed.