diff --git a/mlir/include/mlir/Dialect/GPU/IR/CompilationAttrInterfaces.td b/mlir/include/mlir/Dialect/GPU/IR/CompilationAttrInterfaces.td --- a/mlir/include/mlir/Dialect/GPU/IR/CompilationAttrInterfaces.td +++ b/mlir/include/mlir/Dialect/GPU/IR/CompilationAttrInterfaces.td @@ -6,7 +6,8 @@ // //===----------------------------------------------------------------------===// // -// This file defines interfaces for GPU target attributes. +// This file defines interfaces for GPU target attributes & GPU object manager +// attributes. // //===----------------------------------------------------------------------===// @@ -61,4 +62,55 @@ def GPUNonEmptyTargetArrayAttr : ConfinedAttr]>; +//===----------------------------------------------------------------------===// +// GPU object manager attribute interface. +//===----------------------------------------------------------------------===// + +def GPUObjectManagerAttrInterface : + AttrInterface<"ObjectManagerAttrInterface"> { + let description = [{ + Interface for GPU object manager attributes. Attributes implementing this + interface manage the interaction between GPU objects and host IR. + }]; + let cppNamespace = "::mlir::gpu"; + let methods = [ + InterfaceMethod<[{ + Embeds a GPU object into a host LLVM module. The operation expected by + this method must be a GPU BinaryOp. + + All attributes implementing this interface must implement this method. + If the method fails then it must return `failure`. + }], + "LogicalResult", "embedBinary", + (ins "Operation*":$binaryOp, "llvm::IRBuilderBase&":$hostBuilder, + "LLVM::ModuleTranslation&":$hostModuleTranslation) + >, + InterfaceMethod<[{ + Launches a kernel inside a binary. The first argument must be a GPU + LaunchFuncOp, while the second one a GPU BinaryOp. + + All attributes implementing this interface must implement this method. + If the method fails then it must return `failure`. + }], + "LogicalResult", "launchKernel", + (ins "Operation*":$launchFunc, "Operation*":$binaryOp, + "llvm::IRBuilderBase&":$hostBuilder, + "LLVM::ModuleTranslation&":$hostModuleTranslation) + > + ]; +} + +def ImplementsObjectManagerAttrInterface : AttrConstraint< + CPred<"$_self.hasTrait<::mlir::gpu::ObjectManagerAttrInterface::Trait>()">, + "Attribute implementing the `ObjectManagerAttrInterface` interface." +>; + +def GPUObjectManagerAttr : + ConfinedAttr { + let description = [{ + Generic compilation attribute implementing the `ObjectManagerAttrInterface` + interface. + }]; +} + #endif // GPU_COMPILATIONATTRINTERFACES diff --git a/mlir/include/mlir/Dialect/GPU/IR/GPUDialect.h b/mlir/include/mlir/Dialect/GPU/IR/GPUDialect.h --- a/mlir/include/mlir/Dialect/GPU/IR/GPUDialect.h +++ b/mlir/include/mlir/Dialect/GPU/IR/GPUDialect.h @@ -28,7 +28,14 @@ #include "mlir/Interfaces/SideEffectInterfaces.h" #include "llvm/ADT/STLExtras.h" +namespace llvm { +class IRBuilderBase; +} + namespace mlir { +namespace LLVM { +class ModuleTranslation; +} namespace gpu { /// Utility class for the GPU dialect to represent triples of `Value`s