Skip to content

Commit 3e2421f

Browse files
committed
fix comment
1 parent 1731525 commit 3e2421f

File tree

4 files changed

+46
-77
lines changed

4 files changed

+46
-77
lines changed

include/gc/Analysis/TargetDescriptionAnalysis.h

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,16 +71,13 @@ class CPUTargetDescriptionAnalysis : public TargetDescriptionAnalysisBase {
7171
static constexpr StringLiteral kNumThreads = "num_threads";
7272

7373
// get runtime OMP_NUM_THREADS
74-
size_t getNumThreads();
74+
unsigned getNumThreads();
7575

7676
// get cache size by cacheLevel
77-
size_t getCacheSize(uint8_t cacheLevel);
77+
unsigned getCacheSize(uint8_t cacheLevel);
7878

7979
// get the maximum vector length in bits
80-
size_t getMaxVectorWidth();
81-
82-
// get the default value map(attr key, default value)
83-
static llvm::DenseMap<StringRef, int64_t> CPUTargetDeafultValueMap;
80+
unsigned getMaxVectorWidth();
8481

8582
CPUTargetDescriptionAnalysis(Operation *op)
8683
: TargetDescriptionAnalysisBase(op, DeviceType::CPU) {}

lib/gc/Analysis/TargetDescriptionAnalysis.cpp

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,6 @@ llvm::DenseMap<DeviceType, std::string>
2121
{CPU, "CPU"},
2222
};
2323

24-
// default values for properties
25-
llvm::DenseMap<StringRef, int64_t>
26-
CPUTargetDescriptionAnalysis::CPUTargetDeafultValueMap = {
27-
{CPUTargetDescriptionAnalysis::kNumThreads, 1},
28-
{CPUTargetDescriptionAnalysis::kL1CacheSize, 32 * 1024},
29-
{CPUTargetDescriptionAnalysis::kL2CacheSize, 1024 * 1024},
30-
{CPUTargetDescriptionAnalysis::kL3CacheSize, 32 * 1024 * 1024},
31-
{CPUTargetDescriptionAnalysis::kMaxVectorWidth, 512},
32-
};
33-
3424
template <typename T>
3525
void TargetDescriptionAnalysisBase::emitNotFoundWarning(Location loc,
3626
StringRef key,
@@ -66,18 +56,23 @@ TargetDescriptionAnalysisBase::getPropertyValue(StringRef key) {
6656
Builder(getContext()).getStringAttr(key));
6757
}
6858

69-
size_t CPUTargetDescriptionAnalysis::getNumThreads() {
59+
unsigned CPUTargetDescriptionAnalysis::getNumThreads() {
60+
static const unsigned defaultNumThreads = 1;
7061
std::optional<Attribute> numThreads = getPropertyValue(kNumThreads);
7162

7263
if (numThreads)
7364
return getIntFromAttribute(*numThreads);
74-
emitNotFoundWarning(getLocation(), kNumThreads,
75-
CPUTargetDeafultValueMap[kNumThreads]);
76-
return CPUTargetDeafultValueMap[kNumThreads];
65+
emitNotFoundWarning(getLocation(), kNumThreads, defaultNumThreads);
66+
return defaultNumThreads;
7767
}
7868

79-
size_t CPUTargetDescriptionAnalysis::getCacheSize(uint8_t cacheLevel) {
69+
unsigned CPUTargetDescriptionAnalysis::getCacheSize(uint8_t cacheLevel) {
8070
assert(cacheLevel > 0 && cacheLevel < 4 && "Invalid cache level");
71+
llvm::DenseMap<StringRef, unsigned> CPUTargetCacheSizeValueMap = {
72+
{CPUTargetDescriptionAnalysis::kL1CacheSize, 32 * 1024},
73+
{CPUTargetDescriptionAnalysis::kL2CacheSize, 1024 * 1024},
74+
{CPUTargetDescriptionAnalysis::kL3CacheSize, 32 * 1024 * 1024},
75+
};
8176
StringLiteral key = "";
8277
if (cacheLevel == 1)
8378
key = kL1CacheSize;
@@ -90,17 +85,17 @@ size_t CPUTargetDescriptionAnalysis::getCacheSize(uint8_t cacheLevel) {
9085
if (cacheSize)
9186
return getIntFromAttribute(*cacheSize);
9287

93-
emitNotFoundWarning(getLocation(), key, CPUTargetDeafultValueMap[key]);
94-
return CPUTargetDeafultValueMap[key];
88+
emitNotFoundWarning(getLocation(), key, CPUTargetCacheSizeValueMap[key]);
89+
return CPUTargetCacheSizeValueMap[key];
9590
}
9691

97-
size_t CPUTargetDescriptionAnalysis::getMaxVectorWidth() {
92+
unsigned CPUTargetDescriptionAnalysis::getMaxVectorWidth() {
93+
static const unsigned defaultMaxVectorWidth = 512;
9894
std::optional<Attribute> maxVectorWidth = getPropertyValue(kMaxVectorWidth);
9995
if (maxVectorWidth)
10096
return getIntFromAttribute(*maxVectorWidth);
101-
emitNotFoundWarning(getLocation(), kMaxVectorWidth,
102-
CPUTargetDeafultValueMap[kMaxVectorWidth]);
103-
return CPUTargetDeafultValueMap[kMaxVectorWidth];
97+
emitNotFoundWarning(getLocation(), kMaxVectorWidth, defaultMaxVectorWidth);
98+
return defaultMaxVectorWidth;
10499
}
105100

106101
} // namespace gc

lib/gc/Transforms/Pipeline.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@ void populateLLVMPasses(mlir::OpPassManager &pm) {
133133
}
134134

135135
void populateCPUPipeline(mlir::OpPassManager &pm) {
136+
// verify the target description attribute
137+
pm.addNestedPass<func::FuncOp>(createVerifyTargetDescription());
136138
// front-end, oneDNN graph dialect
137139
populateFrontendPasses(pm);
138140
// middle-end, LinalgX/Linalg/tensor dialects

lib/gc/Transforms/VerifyTargetDescription.cpp

Lines changed: 25 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -27,68 +27,43 @@ static LogicalResult verifyCPUTargetDescription(RewriterBase &rewriter,
2727
Location loc = op->getLoc();
2828

2929
// Check if the num_threads is existed and greater than 0
30-
std::optional<Attribute> numThreadsAttr =
31-
cpuTargetDesc.getPropertyValue(CPUTargetDescriptionAnalysis::kNumThreads);
32-
if (numThreadsAttr) {
33-
if (!isa<IntegerAttr>(*numThreadsAttr) ||
34-
cpuTargetDesc.getNumThreads() < 1) {
35-
mlir::emitError(loc)
36-
<< "num_threads must be a greater than 0 integer, but get "
37-
<< *numThreadsAttr;
38-
return failure();
39-
}
30+
if (cpuTargetDesc.getNumThreads() < 1) {
31+
mlir::emitError(loc)
32+
<< "num_threads must be a greater than 0 integer, but get "
33+
<< cpuTargetDesc.getNumThreads();
34+
return failure();
4035
}
4136

4237
// Check if the L1 cache size is existed and greater than 0
43-
std::optional<Attribute> l1CacheSizeAttr = cpuTargetDesc.getPropertyValue(
44-
CPUTargetDescriptionAnalysis::kL1CacheSize);
45-
if (l1CacheSizeAttr) {
46-
if (!isa<IntegerAttr>(*l1CacheSizeAttr) ||
47-
cpuTargetDesc.getCacheSize(1) < 1) {
48-
mlir::emitError(loc)
49-
<< "L1_cache_size_in_bytes must be a greater than 0 integer, but get "
50-
<< *l1CacheSizeAttr;
51-
return failure();
52-
}
38+
if (cpuTargetDesc.getCacheSize(1) < 1) {
39+
mlir::emitError(loc)
40+
<< "L1_cache_size_in_bytes must be a greater than 0 integer, but get "
41+
<< cpuTargetDesc.getCacheSize(1);
42+
return failure();
5343
}
5444

5545
// Check if the L2 cache size is existed and greater than 0
56-
std::optional<Attribute> l2CacheSizeAttr = cpuTargetDesc.getPropertyValue(
57-
CPUTargetDescriptionAnalysis::kL2CacheSize);
58-
if (l2CacheSizeAttr) {
59-
if (!isa<IntegerAttr>(*l2CacheSizeAttr) ||
60-
cpuTargetDesc.getCacheSize(2) < 1) {
61-
mlir::emitError(loc)
62-
<< "L2_cache_size_in_bytes must be a greater than 0 integer, but get "
63-
<< *l2CacheSizeAttr;
64-
return failure();
65-
}
46+
if (cpuTargetDesc.getCacheSize(2) < 1) {
47+
mlir::emitError(loc)
48+
<< "L2_cache_size_in_bytes must be a greater than 0 integer, but get "
49+
<< cpuTargetDesc.getCacheSize(2);
50+
return failure();
6651
}
6752

6853
// Check if the L3 cache size is existed and greater than 0
69-
std::optional<Attribute> l3CacheSizeAttr = cpuTargetDesc.getPropertyValue(
70-
CPUTargetDescriptionAnalysis::kL3CacheSize);
71-
if (l3CacheSizeAttr) {
72-
if (!isa<IntegerAttr>(*l3CacheSizeAttr) ||
73-
cpuTargetDesc.getCacheSize(3) < 1) {
74-
mlir::emitError(loc)
75-
<< "L3_cache_size_in_bytes must be a greater than 0 integer, but get "
76-
<< *l3CacheSizeAttr;
77-
return failure();
78-
}
54+
if (cpuTargetDesc.getCacheSize(3) < 1) {
55+
mlir::emitError(loc)
56+
<< "L3_cache_size_in_bytes must be a greater than 0 integer, but get "
57+
<< cpuTargetDesc.getCacheSize(3);
58+
return failure();
7959
}
8060

8161
// Check if the max_vector_width is existed and greater than 0
82-
std::optional<Attribute> maxVectorWidthAttr = cpuTargetDesc.getPropertyValue(
83-
CPUTargetDescriptionAnalysis::kMaxVectorWidth);
84-
if (maxVectorWidthAttr) {
85-
if (!isa<IntegerAttr>(*maxVectorWidthAttr) ||
86-
cpuTargetDesc.getMaxVectorWidth() < 1) {
87-
mlir::emitError(loc)
88-
<< "max_vector_width must be a greater than 0 integer, but get "
89-
<< *maxVectorWidthAttr;
90-
return failure();
91-
}
62+
if (cpuTargetDesc.getMaxVectorWidth() < 1) {
63+
mlir::emitError(loc)
64+
<< "max_vector_width must be a greater than 0 integer, but get "
65+
<< cpuTargetDesc.getMaxVectorWidth();
66+
return failure();
9267
}
9368
return success();
9469
}

0 commit comments

Comments
 (0)