Skip to content

Commit 61c8809

Browse files
committed
[mlir][interfaces] Add the TargetInfo attribute interface
This patch adds the TargetInfo attribute interface to the set of DLTI interfaces. Target information attributes provide essential information on the compilation target. This information includes the target triple identifier, the target chip identifier, and a string representation of the target features. This patch also adds this new interface to the NVVM and ROCDL GPU target attributes.
1 parent 66786a7 commit 61c8809

File tree

8 files changed

+61
-3
lines changed

8 files changed

+61
-3
lines changed

mlir/include/mlir/Dialect/LLVMIR/NVVMDialect.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "mlir/Dialect/LLVMIR/LLVMDialect.h"
2020
#include "mlir/IR/Dialect.h"
2121
#include "mlir/IR/OpDefinition.h"
22+
#include "mlir/Interfaces/DataLayoutInterfaces.h"
2223
#include "mlir/Interfaces/SideEffectInterfaces.h"
2324
#include "llvm/IR/IntrinsicsNVPTX.h"
2425

mlir/include/mlir/Dialect/LLVMIR/NVVMOps.td

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ include "mlir/IR/EnumAttr.td"
1717
include "mlir/Dialect/GPU/IR/CompilationAttrInterfaces.td"
1818
include "mlir/Dialect/LLVMIR/LLVMOpBase.td"
1919
include "mlir/Interfaces/SideEffectInterfaces.td"
20+
include "mlir/Interfaces/DataLayoutInterfaces.td"
2021
include "mlir/Dialect/LLVMIR/BasicPtxBuilderInterface.td"
2122

2223
def LLVM_PointerGlobal : LLVM_PointerInAddressSpace<1>;
@@ -1894,7 +1895,9 @@ def NVVM_WgmmaMmaAsyncOp : NVVM_Op<"wgmma.mma_async",
18941895
// NVVM target attribute.
18951896
//===----------------------------------------------------------------------===//
18961897

1897-
def NVVM_TargettAttr : NVVM_Attr<"NVVMTarget", "target"> {
1898+
def NVVM_TargettAttr : NVVM_Attr<"NVVMTarget", "target", [
1899+
DeclareAttrInterfaceMethods<TargetInfoAttrInterface>
1900+
]> {
18981901
let description = [{
18991902
GPU target attribute for controlling compilation of NVIDIA targets. All
19001903
parameters decay into default values if not present.

mlir/include/mlir/Dialect/LLVMIR/ROCDLDialect.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "mlir/Dialect/LLVMIR/LLVMDialect.h"
2727
#include "mlir/IR/Dialect.h"
2828
#include "mlir/IR/OpDefinition.h"
29+
#include "mlir/Interfaces/DataLayoutInterfaces.h"
2930
#include "mlir/Interfaces/SideEffectInterfaces.h"
3031

3132
///// Ops /////

mlir/include/mlir/Dialect/LLVMIR/ROCDLOps.td

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
include "mlir/Dialect/GPU/IR/CompilationAttrInterfaces.td"
1717
include "mlir/Dialect/LLVMIR/LLVMOpBase.td"
18+
include "mlir/Interfaces/DataLayoutInterfaces.td"
1819
include "mlir/Interfaces/SideEffectInterfaces.td"
1920

2021
//===----------------------------------------------------------------------===//
@@ -608,8 +609,9 @@ def ROCDL_CvtSrFp8F32Op :
608609
// ROCDL target attribute.
609610
//===----------------------------------------------------------------------===//
610611

611-
def ROCDL_TargettAttr :
612-
ROCDL_Attr<"ROCDLTarget", "target"> {
612+
def ROCDL_TargettAttr : ROCDL_Attr<"ROCDLTarget", "target", [
613+
DeclareAttrInterfaceMethods<TargetInfoAttrInterface>
614+
]> {
613615
let description = [{
614616
ROCDL target attribute for controlling compilation of AMDGPU targets. All
615617
parameters decay into default values if not present.

mlir/include/mlir/Interfaces/DataLayoutInterfaces.td

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,39 @@ def DataLayoutSpecInterface : AttrInterface<"DataLayoutSpecInterface"> {
188188
}];
189189
}
190190

191+
def TargetInfoAttrInterface : AttrInterface<"TargetInfoAttrInterface"> {
192+
let cppNamespace = "::mlir";
193+
194+
let description = [{
195+
Attribute interface describing target information.
196+
197+
Target information attributes provide essential information on the
198+
compilation target. This information includes the target triple identifier,
199+
the target chip identifier, and a string representation of the target features.
200+
}];
201+
202+
let methods = [
203+
InterfaceMethod<
204+
/*description=*/"Returns the target triple identifier.",
205+
/*retTy=*/"::mlir::StringRef",
206+
/*methodName=*/"getTargetTriple",
207+
/*args=*/(ins)
208+
>,
209+
InterfaceMethod<
210+
/*description=*/"Returns the target chip identifier.",
211+
/*retTy=*/"::mlir::StringRef",
212+
/*methodName=*/"getTargetChip",
213+
/*args=*/(ins)
214+
>,
215+
InterfaceMethod<
216+
/*description=*/"Returns the target features as a string.",
217+
/*retTy=*/"std::string",
218+
/*methodName=*/"getTargetFeatures",
219+
/*args=*/(ins)
220+
>
221+
];
222+
}
223+
191224
//===----------------------------------------------------------------------===//
192225
// Operation interface
193226
//===----------------------------------------------------------------------===//

mlir/lib/Dialect/LLVMIR/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ add_mlir_dialect_library(MLIRNVVMDialect
6161
LINK_LIBS PUBLIC
6262
MLIRIR
6363
MLIRLLVMDialect
64+
MLIRDataLayoutInterfaces
6465
MLIRSideEffectInterfaces
6566
)
6667

@@ -83,5 +84,6 @@ add_mlir_dialect_library(MLIRROCDLDialect
8384
LINK_LIBS PUBLIC
8485
MLIRIR
8586
MLIRLLVMDialect
87+
MLIRDataLayoutInterfaces
8688
MLIRSideEffectInterfaces
8789
)

mlir/lib/Dialect/LLVMIR/IR/NVVMDialect.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1106,6 +1106,14 @@ NVVMTargetAttr::verify(function_ref<InFlightDiagnostic()> emitError,
11061106
return success();
11071107
}
11081108

1109+
StringRef NVVMTargetAttr::getTargetTriple() const { return getTriple(); }
1110+
1111+
StringRef NVVMTargetAttr::getTargetChip() const { return getChip(); }
1112+
1113+
std::string NVVMTargetAttr::getTargetFeatures() const {
1114+
return getFeatures().str();
1115+
}
1116+
11091117
#define GET_OP_CLASSES
11101118
#include "mlir/Dialect/LLVMIR/NVVMOps.cpp.inc"
11111119

mlir/lib/Dialect/LLVMIR/IR/ROCDLDialect.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,14 @@ ROCDLTargetAttr::verify(function_ref<InFlightDiagnostic()> emitError,
295295
return success();
296296
}
297297

298+
StringRef ROCDLTargetAttr::getTargetTriple() const { return getTriple(); }
299+
300+
StringRef ROCDLTargetAttr::getTargetChip() const { return getChip(); }
301+
302+
std::string ROCDLTargetAttr::getTargetFeatures() const {
303+
return getFeatures().str();
304+
}
305+
298306
#define GET_OP_CLASSES
299307
#include "mlir/Dialect/LLVMIR/ROCDLOps.cpp.inc"
300308

0 commit comments

Comments
 (0)