Skip to content

Commit b17c7b7

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 90c845f commit b17c7b7

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/InferIntRangeInterface.h"
2324
#include "mlir/Interfaces/SideEffectInterfaces.h"
2425
#include "mlir/Target/LLVMIR/ModuleTranslation.h"

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
include "mlir/Interfaces/InferIntRangeInterface.td"
2223
include "mlir/Dialect/LLVMIR/LLVMTypes.td"
@@ -3246,7 +3247,9 @@ def NVVM_Tcgen05StOp : NVVM_Op<"tcgen05.st"> {
32463247
// NVVM target attribute.
32473248
//===----------------------------------------------------------------------===//
32483249

3249-
def NVVM_TargettAttr : NVVM_Attr<"NVVMTarget", "target"> {
3250+
def NVVM_TargettAttr : NVVM_Attr<"NVVMTarget", "target", [
3251+
DeclareAttrInterfaceMethods<TargetInfoAttrInterface>
3252+
]> {
32503253
let description = [{
32513254
GPU target attribute for controlling compilation of NVIDIA targets. All
32523255
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
//===----------------------------------------------------------------------===//
@@ -1116,8 +1117,9 @@ def ROCDL_CvtSrFp8F32Op :
11161117
// ROCDL target attribute.
11171118
//===----------------------------------------------------------------------===//
11181119

1119-
def ROCDL_TargetAttr :
1120-
ROCDL_Attr<"ROCDLTarget", "target"> {
1120+
def ROCDL_TargettAttr : ROCDL_Attr<"ROCDLTarget", "target", [
1121+
DeclareAttrInterfaceMethods<TargetInfoAttrInterface>
1122+
]> {
11211123
let description = [{
11221124
ROCDL target attribute for controlling compilation of AMDGPU targets. All
11231125
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
@@ -354,6 +354,39 @@ def TargetSystemSpecInterface : AttrInterface<"TargetSystemSpecInterface", [DLTI
354354
}];
355355
}
356356

357+
def TargetInfoAttrInterface : AttrInterface<"TargetInfoAttrInterface"> {
358+
let cppNamespace = "::mlir";
359+
360+
let description = [{
361+
Attribute interface describing target information.
362+
363+
Target information attributes provide essential information on the
364+
compilation target. This information includes the target triple identifier,
365+
the target chip identifier, and a string representation of the target features.
366+
}];
367+
368+
let methods = [
369+
InterfaceMethod<
370+
/*description=*/"Returns the target triple identifier.",
371+
/*retTy=*/"::mlir::StringRef",
372+
/*methodName=*/"getTargetTriple",
373+
/*args=*/(ins)
374+
>,
375+
InterfaceMethod<
376+
/*description=*/"Returns the target chip identifier.",
377+
/*retTy=*/"::mlir::StringRef",
378+
/*methodName=*/"getTargetChip",
379+
/*args=*/(ins)
380+
>,
381+
InterfaceMethod<
382+
/*description=*/"Returns the target features as a string.",
383+
/*retTy=*/"std::string",
384+
/*methodName=*/"getTargetFeatures",
385+
/*args=*/(ins)
386+
>
387+
];
388+
}
389+
357390
//===----------------------------------------------------------------------===//
358391
// Operation interface
359392
//===----------------------------------------------------------------------===//

mlir/lib/Dialect/LLVMIR/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ add_mlir_dialect_library(MLIRNVVMDialect
6060
LINK_LIBS PUBLIC
6161
MLIRIR
6262
MLIRLLVMDialect
63+
MLIRDataLayoutInterfaces
6364
MLIRSideEffectInterfaces
6465
MLIRInferIntRangeInterface
6566
)
@@ -83,6 +84,7 @@ add_mlir_dialect_library(MLIRROCDLDialect
8384
LINK_LIBS PUBLIC
8485
MLIRIR
8586
MLIRLLVMDialect
87+
MLIRDataLayoutInterfaces
8688
MLIRSideEffectInterfaces
8789
)
8890

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

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

1574+
StringRef NVVMTargetAttr::getTargetTriple() const { return getTriple(); }
1575+
1576+
StringRef NVVMTargetAttr::getTargetChip() const { return getChip(); }
1577+
1578+
std::string NVVMTargetAttr::getTargetFeatures() const {
1579+
return getFeatures().str();
1580+
}
1581+
15741582
#define GET_OP_CLASSES
15751583
#include "mlir/Dialect/LLVMIR/NVVMOps.cpp.inc"
15761584

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

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

250+
StringRef ROCDLTargetAttr::getTargetTriple() const { return getTriple(); }
251+
252+
StringRef ROCDLTargetAttr::getTargetChip() const { return getChip(); }
253+
254+
std::string ROCDLTargetAttr::getTargetFeatures() const {
255+
return getFeatures().str();
256+
}
257+
250258
#define GET_OP_CLASSES
251259
#include "mlir/Dialect/LLVMIR/ROCDLOps.cpp.inc"
252260

0 commit comments

Comments
 (0)