Skip to content

Commit 0364aa8

Browse files
authored
Remove redundant attributes from Rock ops (#1910)
* Remove arch and num_cu * Remove comment * Fallback to checking mod if arch not found on func * Fall back to arch info for minNumCU * Small fixes for LIT tests * Update LIT tests for removal of arch and num_cu * Remove additional whitespace * Initial changes for making the features attribute optional * Fix LIT errors with optional features attribute * Update determination of types * More fixes uncovered during LIT tests * Updates to remove 'features' where possible from LIT tests * Fix for review comments * Add recursive type check to AmdArchDb.cpp * More review changes * Create GetRockInfo header and add 'features' attribute to funcs * Fix compile issues * More fixes for LIT tests * Remove features from unnecessary ops * Update additional LIT tests to remove 'features' * Clang format * Fix minor nitpicks * clang-format * Add 'getGemmFeaturesAttr()' * Update assert to check for all features being the same * clang-format AffixTuningParameters * Move templated code to its own header * Investigate tuna script issue * Fixes for running out of heap space on Windows * Revert "Investigate tuna script issue" This reverts commit 9638f09. * Fix small typos
1 parent 140f6fd commit 0364aa8

File tree

153 files changed

+1273
-1119
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

153 files changed

+1273
-1119
lines changed

mlir/include/mlir/Dialect/Rock/utility/AmdArchDb.h renamed to mlir/include/mlir/Dialect/Rock/IR/AmdArchDb.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
#ifndef MLIR_DIALECT_ROCK_UTILITY_AMDARCHDB_H
10-
#define MLIR_DIALECT_ROCK_UTILITY_AMDARCHDB_H
9+
#ifndef MLIR_DIALECT_ROCK_IR_AMDARCHDB_H
10+
#define MLIR_DIALECT_ROCK_IR_AMDARCHDB_H
1111

1212
#include "mlir/Dialect/Rock/IR/Rock.h"
1313
#include "mlir/Support/LLVM.h"
@@ -51,4 +51,4 @@ AmdArchInfo lookupArchInfo(StringRef arch);
5151
} // namespace rock
5252
} // namespace mlir
5353

54-
#endif // MLIR_DIALECT_ROCK_UTILITY_AMDARCHDB_H
54+
#endif // MLIR_DIALECT_ROCK_IR_AMDARCHDB_H
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
//===- GetRockInfo.h - functions used to calculate information about Rock ops
2+
//---------------===//
3+
//
4+
// Part of the MLIR Project, under the Apache License v2.0 with LLVM Exceptions.
5+
// See https://llvm.org/LICENSE.txt for license information.
6+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7+
//
8+
//===----------------------------------------------------------------------===//
9+
#ifndef MLIR_DIALECT_ROCK_IR_GETROCKINFO_H
10+
#define MLIR_DIALECT_ROCK_IR_GETROCKINFO_H
11+
12+
#include "mlir/Dialect/GPU/IR/GPUDialect.h"
13+
#include "mlir/Dialect/Rock/IR/Rock.h"
14+
#include "mlir/IR/BuiltinAttributes.h"
15+
#include "mlir/IR/Matchers.h"
16+
#include "mlir/IR/Value.h"
17+
#include "mlir/Support/LLVM.h"
18+
#include "llvm/ADT/TypeSwitch.h"
19+
#include "llvm/Support/Casting.h"
20+
#include "llvm/Support/ErrorHandling.h"
21+
22+
namespace mlir {
23+
class Operation;
24+
class Type;
25+
26+
namespace rock {
27+
28+
// This function returns the func or gpu.func of a given op
29+
Operation *getParentFuncOp(Operation *op);
30+
31+
// Return a boolean if the features contain accel properties
32+
bool isAccel(rock::GemmFeatures features);
33+
34+
// Get the arch from the op
35+
FailureOr<StringAttr> getArch(Operation *op);
36+
37+
// Get the arch from the op and error out if it cannot be found
38+
StringAttr getArchValue(Operation *op);
39+
40+
// Get the num_cu from the op
41+
FailureOr<int64_t> getNumCU(Operation *op);
42+
43+
// Get the num_cu from the op, and error out if it cannot be found
44+
int64_t getNumCUValue(Operation *op);
45+
46+
inline rock::GemmFeatures intersectGemmFeatures(rock::GemmFeatures a,
47+
rock::GemmFeatures b) {
48+
return a & b;
49+
}
50+
51+
// Get the features enabled for the specified op. These will be dependent on
52+
// the architecture being used, and the type of the op.
53+
rock::GemmFeatures getFeatures(Operation *op);
54+
55+
// This function returns a boolean value if the underlying op has support for
56+
// an optional 'GemmFeatures' attribute
57+
bool opHasOptionalFeature(Operation *op);
58+
59+
} // End namespace rock
60+
} // End namespace mlir
61+
#endif // MLIR_DIALECT_ROCK_IR_GETROCKINFO_H

mlir/include/mlir/Dialect/Rock/IR/RockConvInterface.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def RockConvInterface : OpInterface<"RockConvInterface"> {
6666
/*defaultImplementation=*/[{ return $_op.getDilations(); }]>,
6767
InterfaceMethod<
6868
/*desc=*/[{Return features attr values.}],
69-
/*retType=*/"GemmFeatures",
69+
/*retType=*/"std::optional<GemmFeatures>",
7070
/*methodName=*/"getFeatures",
7171
/*args=*/(ins),
7272
/*methodBody=*/"",

mlir/include/mlir/Dialect/Rock/IR/RockGemmGemmWrapperInterface.td

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,20 @@ def RockGemmGemmWrapperInterface : OpInterface<"RockGemmGemmWrapperInterface"> {
3232
let methods = [
3333
InterfaceMethod<
3434
/*desc=*/[{
35-
Return the KernelType of this op
35+
Return the type from this op that is needed to calculate GemmFeatures
3636
}],
37-
/*retType=*/"::mlir::rock::KernelType",
38-
/*methodName=*/"getKernelType",
37+
/*retType=*/"SmallVector<::mlir::Type>",
38+
/*methodName=*/"getTypesForFeature",
3939
/*args=*/(ins),
40-
/*methodBody=*/"",
40+
/*methodBody=*/"return {$_op.getAType(), $_op.getCType()};",
4141
/*defaultImplementation=*/""
4242
>,
4343
InterfaceMethod<
4444
/*desc=*/[{
45-
Return the arch string of this op
45+
Return the KernelType of this op
4646
}],
47-
/*retType=*/"StringRef",
48-
/*methodName=*/"getArch",
47+
/*retType=*/"::mlir::rock::KernelType",
48+
/*methodName=*/"getKernelType",
4949
/*args=*/(ins),
5050
/*methodBody=*/"",
5151
/*defaultImplementation=*/""
@@ -154,9 +154,9 @@ def RockGemmGemmWrapperInterface : OpInterface<"RockGemmGemmWrapperInterface"> {
154154
>,
155155
InterfaceMethod<
156156
/*desc=*/[{
157-
Return the features attribute of this op.
157+
Return the optional features attribute of this op.
158158
}],
159-
/*retType=*/"::mlir::rock::GemmFeatures",
159+
/*retType=*/"std::optional<::mlir::rock::GemmFeatures>",
160160
/*methodName=*/"getGemmFeatures",
161161
/*args=*/(ins),
162162
/*methodBody=*/"",
@@ -166,13 +166,15 @@ def RockGemmGemmWrapperInterface : OpInterface<"RockGemmGemmWrapperInterface"> {
166166
>,
167167
InterfaceMethod<
168168
/*desc=*/[{
169-
Return the optional number of Compute Units the GPU provides.
169+
Return the features attribute of this op.
170170
}],
171-
/*retType=*/"std::optional<uint32_t>",
172-
/*methodName=*/"getNumCU",
171+
/*retType=*/"::mlir::rock::GemmFeaturesAttr",
172+
/*methodName=*/"getGemmFeaturesAttr",
173173
/*args=*/(ins),
174174
/*methodBody=*/"",
175-
/*defaultImplementation=*/ ""
175+
/*defaultImplementation=*/[{
176+
return $_op.getFeaturesAttr();
177+
}]
176178
>,
177179

178180
InterfaceMethod<

mlir/include/mlir/Dialect/Rock/IR/RockGemmWrapperInterface.td

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,20 +30,20 @@ def RockGemmWrapperInterface : OpInterface<"RockGemmWrapperInterface"> {
3030
let methods = [
3131
InterfaceMethod<
3232
/*desc=*/[{
33-
Return the KernelType of this op
33+
Return the type from this op that is needed to calculate GemmFeatures
3434
}],
35-
/*retType=*/"::mlir::rock::KernelType",
36-
/*methodName=*/"getKernelType",
35+
/*retType=*/"SmallVector<::mlir::Type>",
36+
/*methodName=*/"getTypesForFeature",
3737
/*args=*/(ins),
38-
/*methodBody=*/"",
38+
/*methodBody=*/"return {$_op.getAType()};",
3939
/*defaultImplementation=*/""
4040
>,
4141
InterfaceMethod<
4242
/*desc=*/[{
43-
Return the arch string of this op
43+
Return the KernelType of this op
4444
}],
45-
/*retType=*/"StringRef",
46-
/*methodName=*/"getArch",
45+
/*retType=*/"::mlir::rock::KernelType",
46+
/*methodName=*/"getKernelType",
4747
/*args=*/(ins),
4848
/*methodBody=*/"",
4949
/*defaultImplementation=*/""
@@ -102,9 +102,9 @@ def RockGemmWrapperInterface : OpInterface<"RockGemmWrapperInterface"> {
102102
>,
103103
InterfaceMethod<
104104
/*desc=*/[{
105-
Return the features attribute of this op.
105+
Return the optional features attribute of this op.
106106
}],
107-
/*retType=*/"::mlir::rock::GemmFeatures",
107+
/*retType=*/"std::optional<::mlir::rock::GemmFeatures>",
108108
/*methodName=*/"getGemmFeatures",
109109
/*args=*/(ins),
110110
/*methodBody=*/"",
@@ -114,13 +114,15 @@ def RockGemmWrapperInterface : OpInterface<"RockGemmWrapperInterface"> {
114114
>,
115115
InterfaceMethod<
116116
/*desc=*/[{
117-
Return the optional number of Compute Units the GPU provides.
117+
Return the features attribute of this op.
118118
}],
119-
/*retType=*/"std::optional<uint32_t>",
120-
/*methodName=*/"getNumCU",
119+
/*retType=*/"::mlir::rock::GemmFeaturesAttr",
120+
/*methodName=*/"getGemmFeaturesAttr",
121121
/*args=*/(ins),
122122
/*methodBody=*/"",
123-
/*defaultImplementation=*/ ""
123+
/*defaultImplementation=*/[{
124+
return $_op.getFeaturesAttr();
125+
}]
124126
>,
125127

126128
/// Setters for tuning-related data

0 commit comments

Comments
 (0)