This is an archive of the discontinued LLVM Phabricator instance.

[mlir][gpu] Add the GPU offloading handler attribute interface.
ClosedPublic

Authored by fmorac on Jun 29 2023, 9:43 AM.

Details

Summary

For an explanation of these patches see D154153.

Commit message:
This patch adds the OffloadingTranslationAttrTrait trait and the
GPUOffloadingLLVMTranslationAttrInterface attribute interface.

The interface indicates that an attribute is a GPU offloading translation
attribute. These kinds of attributes must implement an interface for handling
the translation of GPU offloading operations like gpu.binary & gpu.launch_func.

The interface is meant to be used as an opaque interface for embedding GPU
binaries into LLVM modules and launching GPU kernels.

Depends on D154129

Diff Detail

Event Timeline

fmorac created this revision.Jun 29 2023, 9:43 AM
fmorac edited the summary of this revision. (Show Details)Jun 29 2023, 6:18 PM
fmorac added a reviewer: mehdi_amini.
fmorac published this revision for review.Jun 30 2023, 6:29 AM
krzysz00 accepted this revision.Jul 13 2023, 12:27 PM
krzysz00 added a subscriber: krzysz00.

I'm going to assume this interface is sufficient.

This revision is now accepted and ready to land.Jul 13 2023, 12:27 PM
fmorac updated this revision to Diff 543182.Jul 22 2023, 7:03 AM

Rebasing.

mehdi_amini added inline comments.Jul 24 2023, 12:41 AM
mlir/include/mlir/Dialect/GPU/IR/CompilationAttrInterfaces.td
71

I think more context would be appreciated here about the role of the "manager" and the context where it is used (translation)

I'm not convinced that "ObjectManager" is expressive enough in terms of what this provides.

The name should likely include "Translation" somehow, GPUKernelOffloadingLLVMTranslationAttrInterface would the first thing I can come up with right now, thoughts?

87

The description say that this method launches a kernel: shall we say instead "Translate a gpu launch func operation to a LLVM IR target specific instructions sequence".

94

Shall we take a GPULaunchFuncOp instead of Operation* here? Same for the binaryOp being a GPUBinaryOp?

fmorac added inline comments.Jul 24 2023, 5:13 AM
mlir/include/mlir/Dialect/GPU/IR/CompilationAttrInterfaces.td
71

I'll add it.

I settled in ObjectManager because it can be used to implement many concepts for managing GPU objects, like fat binaries & fat bin launch. However I agree the name needs to reflect it's for LLVM translation, what about GPUBinaryHandlerLLVMTranslationAttrInterface

87

I'll change it.

94

The reason these are like this is I couldn't break C++ dependencies and have nvptx_target & amdgpu_target in gpu, as

nvptx_target depends on TargetAttrInterface that depends on the definitions of those operations that depends on attributes (fwd declarations didn't work).

If we move, gpu.nvptx_target to nvvm.target, then there are no issues and the above methods can use GPULaunchFuncOp & GPUBinaryOp.

mehdi_amini added inline comments.Jul 24 2023, 11:00 PM
mlir/include/mlir/Dialect/GPU/IR/CompilationAttrInterfaces.td
71

Works for me.

94

Is this the same discussion we're having in the parent about the location of the NVPTXTarget attribute?

fmorac updated this revision to Diff 546541.Aug 2 2023, 10:40 AM
fmorac marked 4 inline comments as done.
fmorac retitled this revision from [mlir][gpu] Add the GPU object manager attribute interface. to [mlir][gpu] Add the GPU binary handler attribute interface..
fmorac edited the summary of this revision. (Show Details)

Switched name from GPUObjectManagerAttrInterface to GPUBinaryHandlerLLVMTranslationAttrInterface.

fmorac updated this revision to Diff 546546.Aug 2 2023, 10:45 AM

Rebasing.

fmorac updated this revision to Diff 546548.Aug 2 2023, 10:49 AM

Remove remnants of the ObjectManager name.

LG!

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

I don't think this one was done? It still says Launches a kernel

fmorac updated this revision to Diff 547735.Aug 7 2023, 5:21 AM
fmorac retitled this revision from [mlir][gpu] Add the GPU binary handler attribute interface. to [mlir][gpu] Add the GPU offloading handler attribute interface..
fmorac edited the summary of this revision. (Show Details)

Improved docs & removed unnecessary tablegen code. Also switched the name from Binary Handler to Offloading Handler.

mehdi_amini added inline comments.Aug 8 2023, 10:15 PM
mlir/include/mlir/Dialect/GPU/IR/CompilationAttrInterfaces.td
68

Can we keep the TableGen name identical to the C++ name here? It got me confused on subsequence patches to read one and the other.

fmorac added inline comments.Aug 9 2023, 6:25 PM
mlir/include/mlir/Dialect/GPU/IR/CompilationAttrInterfaces.td
68

Yes, I'll change I just used the GPU prefix because I saw it was customary with other Ops & Attributes.

fmorac updated this revision to Diff 549328.Aug 11 2023, 4:04 AM
fmorac marked an inline comment as done.
fmorac edited the summary of this revision. (Show Details)

Add the OffloadingTranslationAttrTrait trait. This traits decouples gpu.binary op
from LLVM translation, making gpu.binary usable by other translation mechanisms like SPIRV.