Skip to content

Commit 70b50ac

Browse files
Address code review comments.
1 parent db2ba72 commit 70b50ac

File tree

2 files changed

+19
-9
lines changed

2 files changed

+19
-9
lines changed

mlir/lib/Dialect/Rock/Tuning/GridwiseGemmParams.cpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,17 @@ class ParamLookupTable {
129129
return relatives;
130130
}
131131

132-
// Find the lexicographically closest relative
132+
// Finds the lexicographically closest architecture variant when the exact
133+
// target key is not found in the lookup table.
134+
//
135+
// A "relative" entry must have:
136+
// - Same suffix (operation + data type, e.g., "_gemm_f16")
137+
// - Same architecture prefix (e.g., "gfx9" for gfx908, gfx90a, gfx942)
138+
//
139+
// Example: If target "gfx1151_gemm_f16" is missing but "gfx1101_gemm_f16"
140+
// and "gfx1201_gemm_f16" exist, this picks the lexicographically closest one
141+
// (gfx1101_gemm_f16). This enables graceful fallback between similar GPU
142+
// architectures.
133143
static std::string findFallback(const std::string &target) {
134144
const auto relatives = getRelatives(target);
135145
if (relatives.empty())
@@ -319,8 +329,8 @@ PopulateParams::populateDerived(const InitParamsNonAccel &params) {
319329
LogicalResult res = calculateBlockGemmPerformanceParameters(params);
320330

321331
if (failed(res)) {
322-
LLVM_DEBUG(llvm::dbgs() << "Incoherent blockGemm tuning parameter "
323-
<< " size.\n");
332+
LLVM_DEBUG(llvm::dbgs()
333+
<< "Incoherent blockGemm tuning parameter " << " size.\n");
324334
return failure();
325335
}
326336

mlir/utils/performance/analysis/quickTuningGen.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def replace_section(self, file_path, ifdef_guard, begin_marker, end_marker, new_
4545
with open(file_path, 'r') as file:
4646
content = file.read()
4747

48-
pattern = re.compile(f'{begin_marker}.*?{end_marker}', re.DOTALL)
48+
pattern = re.compile(f'{re.escape(begin_marker)}.*?{re.escape(end_marker)}', re.DOTALL)
4949
if not pattern.search(content):
5050
ifdef_match = re.search(rf'{re.escape(ifdef_guard)}(.*?)(?=#endif)', content, re.DOTALL)
5151
if (ifdef_match):
@@ -55,8 +55,8 @@ def replace_section(self, file_path, ifdef_guard, begin_marker, end_marker, new_
5555
else:
5656
raise ValueError(f"Cannot find {ifdef_guard} in {file_path}")
5757

58-
replacment = f'{begin_marker}\n{new_content}\n{end_marker}'
59-
content = pattern.sub(replacment, content)
58+
replacement = f'{begin_marker}\n{new_content}\n{end_marker}'
59+
content = pattern.sub(replacement, content)
6060

6161
with open(file_path, 'w') as file:
6262
file.write(content)
@@ -68,7 +68,7 @@ def update_lookup_table(self, file_path, ifdef_guard, mapping):
6868
with open(file_path, 'r') as file:
6969
content = file.read()
7070

71-
pattern = re.compile(f'{mapping}', re.DOTALL)
71+
pattern = re.compile(f'{re.escape(mapping)}', re.DOTALL)
7272
if not pattern.search(content):
7373
ifdef_match = re.search(rf'{re.escape(ifdef_guard)}(.*?)(?=#endif)', content, re.DOTALL)
7474
if (ifdef_match):
@@ -373,7 +373,7 @@ def print_results(result):
373373
def main(args=None):
374374
"""
375375
usage: quickTunerGen.py [-h] --input-dir INPUT_DIR --op {gemm,conv} [--th TH] --arch ARCH [--update] [--no-splitk]
376-
usage exsample: python3 quickTuningGen.py --input-dir tunedData --op conv --arch gfx90a --update --no-splitk
376+
usage example: python3 quickTuningGen.py --input-dir tunedData --op conv --arch gfx90a --update --no-splitk
377377
"""
378378
if args is None:
379379
args = sys.argv[1:]
@@ -393,7 +393,7 @@ def main(args=None):
393393
parser.add_argument('--no-splitk',
394394
default=False,
395395
action='store_true',
396-
help='Removing the Split-K factor from the generated list')
396+
help='Remove the Split-K factor from the generated list')
397397

398398
pargs = parser.parse_args()
399399

0 commit comments

Comments
 (0)