Skip to content

Commit 5212eae

Browse files
committed
[SYCLomatic][CMake] Fix bug that implicit rules cannot be replaced by user-definded rules
Signed-off-by: chenwei.sun <chenwei.sun@intel.com>
1 parent 7fc89af commit 5212eae

6 files changed

Lines changed: 76 additions & 2 deletions

File tree

clang/lib/DPCT/MigrateScript/MigrateCmakeScript.cpp

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -583,7 +583,22 @@ static void reserveImplicitMigrationRules() {
583583
for (const auto &Rule : ImplicitMigrationRules) {
584584
MetaRuleObject::PatternRewriter PrePR;
585585
PrePR.BuildScriptSyntax = Rule;
586-
CmakeBuildInRules[PrePR.BuildScriptSyntax] = PrePR;
586+
PrePR.RuleId = "implicit_rule_" + Rule;
587+
588+
auto Iter = CmakeBuildInRules.find(PrePR.BuildScriptSyntax);
589+
if (Iter != CmakeBuildInRules.end()) {
590+
if (PrePR.Priority == RulePriority::Takeover &&
591+
Iter->second.Priority > PrePR.Priority) {
592+
CmakeBuildInRules[PrePR.BuildScriptSyntax] = PrePR;
593+
} else {
594+
llvm::outs() << "[Warning]: Two migration rules (Rule:" << PrePR.RuleId
595+
<< ", Rule:" << Iter->second.RuleId
596+
<< ") are duplicated, the migration rule (Rule:"
597+
<< PrePR.RuleId << ") is ignored.\n";
598+
}
599+
} else {
600+
CmakeBuildInRules[PrePR.BuildScriptSyntax] = PrePR;
601+
}
587602
}
588603
}
589604

@@ -610,7 +625,7 @@ void registerCmakeMigrationRule(MetaRuleObject &R) {
610625
Iter->second.Priority > PR.Priority) {
611626
CmakeBuildInRules[PR.BuildScriptSyntax] = PR;
612627
} else {
613-
llvm::outs() << "[Warnning]: Two migration rules (Rule:" << R.RuleId
628+
llvm::outs() << "[Warning]: Two migration rules (Rule:" << R.RuleId
614629
<< ", Rule:" << Iter->second.RuleId
615630
<< ") are duplicated, the migration rule (Rule:" << R.RuleId
616631
<< ") is ignored.\n";
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// RUN: rm -rf %T && mkdir -p %T
2+
// RUN: cd %T
3+
// RUN: cp %S/input.cmake ./input.cmake
4+
// RUN: dpct -in-root ./ -out-root out ./input.cmake --migrate-build-script-only --rule-file=%S/local_replace_implicit_migration_rule.yaml > migration.log 2>&1
5+
// RUN: diff --strip-trailing-cr %S/expected.txt %T/out/input.cmake >> %T/diff.txt
6+
7+
// RUN: cat %S/migration_ref.log > %T/check_migration_check.log
8+
// RUN: cat %T/migration.log >>%T/check_migration_check.log
9+
// RUN: FileCheck --match-full-lines --input-file %T/check_migration_check.log %T/check_migration_check.log
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
## execute_process is commented in the CMakeLists.txt file
2+
set(AOT_GENERATE_COMMAND
3+
${Python3_EXECUTABLE} -m aot_build_utils.generate --path
4+
${GENERATED_SOURCE_DIR} --head_dims ${HEAD_DIMS} --pos_encoding_modes
5+
${POS_ENCODING_MODES} --use_fp16_qk_reductions ${USE_FP16_QK_REDUCTIONS}
6+
--mask_modes ${MASK_MODES} --enable_f16 ${FLASHINFER_ENABLE_F16}
7+
--enable_bf16 ${FLASHINFER_ENABLE_BF16} --enable_fp8_e4m3
8+
${FLASHINFER_ENABLE_FP8_E4M3} --enable_fp8_e5m2
9+
${FLASHINFER_ENABLE_FP8_E5M2})
10+
11+
set(AOT_GENERATE_DISPATCH_INC_COMMAND
12+
${Python3_EXECUTABLE} -m aot_build_utils.generate_dispatch_inc --path
13+
"${GENERATED_SOURCE_DIR}/dispatch.inc" --head_dims ${HEAD_DIMS}
14+
--head_dims_sm90 ${HEAD_DIMS_SM90} --pos_encoding_modes
15+
${POS_ENCODING_MODES} --use_fp16_qk_reductions ${USE_FP16_QK_REDUCTIONS}
16+
--mask_modes ${MASK_MODES})
17+
18+
#execute_process(COMMAND ${AOT_GENERATE_COMMAND} WORKING_DIRECTORY ${PROJECT_SOURCE_DIR})
19+
#execute_process(COMMAND ${AOT_GENERATE_DISPATCH_INC_COMMAND} WORKING_DIRECTORY ${PROJECT_SOURCE_DIR})
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
## execute_process is commented in the CMakeLists.txt file
2+
set(AOT_GENERATE_COMMAND
3+
${Python3_EXECUTABLE} -m aot_build_utils.generate --path
4+
${GENERATED_SOURCE_DIR} --head_dims ${HEAD_DIMS} --pos_encoding_modes
5+
${POS_ENCODING_MODES} --use_fp16_qk_reductions ${USE_FP16_QK_REDUCTIONS}
6+
--mask_modes ${MASK_MODES} --enable_f16 ${FLASHINFER_ENABLE_F16}
7+
--enable_bf16 ${FLASHINFER_ENABLE_BF16} --enable_fp8_e4m3
8+
${FLASHINFER_ENABLE_FP8_E4M3} --enable_fp8_e5m2
9+
${FLASHINFER_ENABLE_FP8_E5M2})
10+
11+
set(AOT_GENERATE_DISPATCH_INC_COMMAND
12+
${Python3_EXECUTABLE} -m aot_build_utils.generate_dispatch_inc --path
13+
"${GENERATED_SOURCE_DIR}/dispatch.inc" --head_dims ${HEAD_DIMS}
14+
--head_dims_sm90 ${HEAD_DIMS_SM90} --pos_encoding_modes
15+
${POS_ENCODING_MODES} --use_fp16_qk_reductions ${USE_FP16_QK_REDUCTIONS}
16+
--mask_modes ${MASK_MODES})
17+
18+
execute_process(COMMAND ${AOT_GENERATE_COMMAND}
19+
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR})
20+
execute_process(COMMAND ${AOT_GENERATE_DISPATCH_INC_COMMAND}
21+
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR})
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
- Rule: rule_execute_process
2+
Kind: CMakeRule
3+
Priority: Takeover
4+
CmakeSyntax: execute_process
5+
In: execute_process(${args1} ${args2} ${args3})
6+
Out: "#execute_process(${args1} ${args2} ${args3})"
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// CHECK: Warning: Only CMake scripts will be migrated as no --migrate-build-script option is provided.
2+
// CHECK: dpct exited with code: 4 (Migration of build script(s) completed.)
3+
// CHECK: [Warning]: Two migration rules (Rule:implicit_rule_execute_process, Rule:rule_execute_process) are duplicated, the migration rule (Rule:implicit_rule_execute_process) is ignored.
4+
// CHECK: Processing: {{(.+)}}/cmake_migration/case_068/Output/out/input.cmake

0 commit comments

Comments
 (0)