From e9a33543818e49e8911477d86f2fb7009bb1800b Mon Sep 17 00:00:00 2001 From: Teja Alaghari Date: Fri, 11 Oct 2024 10:38:28 +0800 Subject: [PATCH] Created separate ipex yaml rule file --- clang/include/clang/DPCT/DPCTOptions.inc | 3 +- clang/lib/DPCT/DPCT.cpp | 7 +++-- clang/lib/DPCT/Rules.cpp | 2 +- clang/lib/DPCT/Rules.h | 4 +-- .../case_001/case_001_framework.cpp | 2 +- .../case_001/expected.py | 3 +- .../case_002/case_002_import_torch_ext.cpp | 2 +- .../case_002/expected.py | 3 +- .../case_003/case_003_torch_classes.cpp | 2 +- .../case_004/case_004_cuda_src_ext.cpp | 2 +- .../case_005/case_005_setup.cpp | 2 +- clang/tools/dpct/DpctOptRules/CMakeLists.txt | 2 +- ...hon_setup_script_migration_rule_ipex.yaml} | 29 ++++++++++--------- 13 files changed, 34 insertions(+), 29 deletions(-) rename clang/tools/dpct/DpctOptRules/{python_setup_script_migration_rule.yaml => python_setup_script_migration_rule_ipex.yaml} (88%) diff --git a/clang/include/clang/DPCT/DPCTOptions.inc b/clang/include/clang/DPCT/DPCTOptions.inc index 3262b3d52000..7e06e1ad57ff 100644 --- a/clang/include/clang/DPCT/DPCTOptions.inc +++ b/clang/include/clang/DPCT/DPCTOptions.inc @@ -470,7 +470,8 @@ DPCT_ENUM_OPTION( DPCT_OPTION_ENUM_VALUE("CMake", int(BuildScriptKind::BS_Cmake), "Migrate the CMake file(s).", false), DPCT_OPTION_ENUM_VALUE("Python_Setup", int(BuildScriptKind::BS_PySetup), - "Migrate the python setup build file(s).", + "Migrate the python setup build file(s) of " + "PyTorch based project", false)), llvm::cl::desc("EXPERIMENTAL: Migrate build script(s).\n"), llvm::cl::init(BuildScriptKind::BS_None), llvm::cl::value_desc("value"), diff --git a/clang/lib/DPCT/DPCT.cpp b/clang/lib/DPCT/DPCT.cpp index 43bd6c542072..0067c6ef1f2b 100644 --- a/clang/lib/DPCT/DPCT.cpp +++ b/clang/lib/DPCT/DPCT.cpp @@ -1105,9 +1105,10 @@ int runDPCT(int argc, const char **argv) { DpctGlobalInfo::getBuildScript() == BuildScriptKind::BS_PySetup) { SmallString<128> PythonSetupRuleFilePath( DpctInstallPath.getCanonicalPath()); - llvm::sys::path::append(PythonSetupRuleFilePath, - Twine("extensions/python_setup_rules/" - "python_setup_script_migration_rule.yaml")); + llvm::sys::path::append( + PythonSetupRuleFilePath, + Twine("extensions/python_setup_rules/" + "python_setup_script_migration_rule_ipex.yaml")); if (llvm::sys::fs::exists(PythonSetupRuleFilePath)) { std::vector PythonSetupRuleFiles{ PythonSetupRuleFilePath}; diff --git a/clang/lib/DPCT/Rules.cpp b/clang/lib/DPCT/Rules.cpp index 77297446ecac..b6107f911776 100644 --- a/clang/lib/DPCT/Rules.cpp +++ b/clang/lib/DPCT/Rules.cpp @@ -366,7 +366,7 @@ void importRules(std::vector &RuleFiles) { case (RuleKind::CMakeRule): registerCmakeMigrationRule(*r); break; - case (RuleKind::PySetupRule): + case (RuleKind::PythonSetupRule): registerPythonSetupMigrationRule(*r); break; default: diff --git a/clang/lib/DPCT/Rules.h b/clang/lib/DPCT/Rules.h index 06ee0550786a..cd4147f3a604 100644 --- a/clang/lib/DPCT/Rules.h +++ b/clang/lib/DPCT/Rules.h @@ -25,7 +25,7 @@ enum RuleKind { DisableAPIMigration, PatternRewriter, CMakeRule, - PySetupRule + PythonSetupRule }; enum RulePriority { Takeover, Default, Fallback }; @@ -210,7 +210,7 @@ template <> struct llvm::yaml::ScalarEnumerationTraits { Io.enumCase(Value, "DisableAPIMigration", RuleKind::DisableAPIMigration); Io.enumCase(Value, "PatternRewriter", RuleKind::PatternRewriter); Io.enumCase(Value, "CMakeRule", RuleKind::CMakeRule); - Io.enumCase(Value, "PySetupRule", RuleKind::PySetupRule); + Io.enumCase(Value, "PythonSetupRule", RuleKind::PythonSetupRule); } }; diff --git a/clang/test/dpct/python_setup_migration/case_001/case_001_framework.cpp b/clang/test/dpct/python_setup_migration/case_001/case_001_framework.cpp index 9acb55ca2f6b..0a5bcb88532a 100644 --- a/clang/test/dpct/python_setup_migration/case_001/case_001_framework.cpp +++ b/clang/test/dpct/python_setup_migration/case_001/case_001_framework.cpp @@ -18,7 +18,7 @@ // CHECK: begin // CHECK-NEXT: end -// RUN: dpct -in-root ./ -out-root out --cuda-include-path="%cuda-path/include" -migrate-build-script=Python_Setup -p ./ +// RUN: dpct -in-root ./ -out-root out --cuda-include-path="%cuda-path/include" -migrate-build-script=Python_Setup --rule-file=%T/../../../../../../../extensions/python_setup_rules/python_setup_script_migration_rule_ipex.yaml -p ./ // RUN: echo "begin" > %T/diff_3.txt // RUN: diff --strip-trailing-cr %S/src/expected.cpp.txt %T/out/input.dp.cpp >> %T/diff_3.txt // RUN: echo "end" >> %T/diff_3.txt diff --git a/clang/test/dpct/python_setup_migration/case_001/expected.py b/clang/test/dpct/python_setup_migration/case_001/expected.py index 92ef0b057454..59c8706a1229 100644 --- a/clang/test/dpct/python_setup_migration/case_001/expected.py +++ b/clang/test/dpct/python_setup_migration/case_001/expected.py @@ -2,7 +2,8 @@ import torch import intel_extension_for_pytorch -SYCL_HOME = True +import os +SYCL_HOME = os.environ.get('CMPLR_ROOT') from intel_extension_for_pytorch.xpu import cpp_extension from intel_extension_for_pytorch.xpu.cpp_extension import ( diff --git a/clang/test/dpct/python_setup_migration/case_002/case_002_import_torch_ext.cpp b/clang/test/dpct/python_setup_migration/case_002/case_002_import_torch_ext.cpp index cbd0ddb9c747..4d890b482b46 100644 --- a/clang/test/dpct/python_setup_migration/case_002/case_002_import_torch_ext.cpp +++ b/clang/test/dpct/python_setup_migration/case_002/case_002_import_torch_ext.cpp @@ -1,7 +1,7 @@ // RUN: rm -rf %T && mkdir -p %T // RUN: cd %T // RUN: cp %S/input.py ./input.py -// RUN: dpct -in-root ./ -out-root out ./input.py --migrate-build-script-only +// RUN: dpct -in-root ./ -out-root out ./input.py --migrate-build-script-only --rule-file=%T/../../../../../../../extensions/python_setup_rules/python_setup_script_migration_rule_ipex.yaml // RUN: echo "begin" > %T/diff.txt // RUN: diff --strip-trailing-cr %S/expected.py %T/out/input.py >> %T/diff.txt // RUN: echo "end" >> %T/diff.txt diff --git a/clang/test/dpct/python_setup_migration/case_002/expected.py b/clang/test/dpct/python_setup_migration/case_002/expected.py index 92ef0b057454..59c8706a1229 100644 --- a/clang/test/dpct/python_setup_migration/case_002/expected.py +++ b/clang/test/dpct/python_setup_migration/case_002/expected.py @@ -2,7 +2,8 @@ import torch import intel_extension_for_pytorch -SYCL_HOME = True +import os +SYCL_HOME = os.environ.get('CMPLR_ROOT') from intel_extension_for_pytorch.xpu import cpp_extension from intel_extension_for_pytorch.xpu.cpp_extension import ( diff --git a/clang/test/dpct/python_setup_migration/case_003/case_003_torch_classes.cpp b/clang/test/dpct/python_setup_migration/case_003/case_003_torch_classes.cpp index cbd0ddb9c747..4d890b482b46 100644 --- a/clang/test/dpct/python_setup_migration/case_003/case_003_torch_classes.cpp +++ b/clang/test/dpct/python_setup_migration/case_003/case_003_torch_classes.cpp @@ -1,7 +1,7 @@ // RUN: rm -rf %T && mkdir -p %T // RUN: cd %T // RUN: cp %S/input.py ./input.py -// RUN: dpct -in-root ./ -out-root out ./input.py --migrate-build-script-only +// RUN: dpct -in-root ./ -out-root out ./input.py --migrate-build-script-only --rule-file=%T/../../../../../../../extensions/python_setup_rules/python_setup_script_migration_rule_ipex.yaml // RUN: echo "begin" > %T/diff.txt // RUN: diff --strip-trailing-cr %S/expected.py %T/out/input.py >> %T/diff.txt // RUN: echo "end" >> %T/diff.txt diff --git a/clang/test/dpct/python_setup_migration/case_004/case_004_cuda_src_ext.cpp b/clang/test/dpct/python_setup_migration/case_004/case_004_cuda_src_ext.cpp index cbd0ddb9c747..4d890b482b46 100644 --- a/clang/test/dpct/python_setup_migration/case_004/case_004_cuda_src_ext.cpp +++ b/clang/test/dpct/python_setup_migration/case_004/case_004_cuda_src_ext.cpp @@ -1,7 +1,7 @@ // RUN: rm -rf %T && mkdir -p %T // RUN: cd %T // RUN: cp %S/input.py ./input.py -// RUN: dpct -in-root ./ -out-root out ./input.py --migrate-build-script-only +// RUN: dpct -in-root ./ -out-root out ./input.py --migrate-build-script-only --rule-file=%T/../../../../../../../extensions/python_setup_rules/python_setup_script_migration_rule_ipex.yaml // RUN: echo "begin" > %T/diff.txt // RUN: diff --strip-trailing-cr %S/expected.py %T/out/input.py >> %T/diff.txt // RUN: echo "end" >> %T/diff.txt diff --git a/clang/test/dpct/python_setup_migration/case_005/case_005_setup.cpp b/clang/test/dpct/python_setup_migration/case_005/case_005_setup.cpp index cbd0ddb9c747..4d890b482b46 100644 --- a/clang/test/dpct/python_setup_migration/case_005/case_005_setup.cpp +++ b/clang/test/dpct/python_setup_migration/case_005/case_005_setup.cpp @@ -1,7 +1,7 @@ // RUN: rm -rf %T && mkdir -p %T // RUN: cd %T // RUN: cp %S/input.py ./input.py -// RUN: dpct -in-root ./ -out-root out ./input.py --migrate-build-script-only +// RUN: dpct -in-root ./ -out-root out ./input.py --migrate-build-script-only --rule-file=%T/../../../../../../../extensions/python_setup_rules/python_setup_script_migration_rule_ipex.yaml // RUN: echo "begin" > %T/diff.txt // RUN: diff --strip-trailing-cr %S/expected.py %T/out/input.py >> %T/diff.txt // RUN: echo "end" >> %T/diff.txt diff --git a/clang/tools/dpct/DpctOptRules/CMakeLists.txt b/clang/tools/dpct/DpctOptRules/CMakeLists.txt index 0f1dd578d45c..fe989b4995bb 100644 --- a/clang/tools/dpct/DpctOptRules/CMakeLists.txt +++ b/clang/tools/dpct/DpctOptRules/CMakeLists.txt @@ -9,7 +9,7 @@ set(dpct_cmake_rule_files ) set(dpct_python_setup_rule_files - ${CMAKE_SOURCE_DIR}/../clang/tools/dpct/DpctOptRules/python_setup_script_migration_rule.yaml + ${CMAKE_SOURCE_DIR}/../clang/tools/dpct/DpctOptRules/python_setup_script_migration_rule_ipex.yaml ) install( diff --git a/clang/tools/dpct/DpctOptRules/python_setup_script_migration_rule.yaml b/clang/tools/dpct/DpctOptRules/python_setup_script_migration_rule_ipex.yaml similarity index 88% rename from clang/tools/dpct/DpctOptRules/python_setup_script_migration_rule.yaml rename to clang/tools/dpct/DpctOptRules/python_setup_script_migration_rule_ipex.yaml index e54f478ccde0..11ca1ce6dfe5 100644 --- a/clang/tools/dpct/DpctOptRules/python_setup_script_migration_rule.yaml +++ b/clang/tools/dpct/DpctOptRules/python_setup_script_migration_rule_ipex.yaml @@ -5,10 +5,10 @@ # This file will be installed to folder: # {dpct_install_folder}/extensions/opt_rules. # The rule specified in this file can be imported with commandline option: -# --rule-file={dpct_install_folder}/extensions/opt_rules/setup_rules/setup_script_migration_rule.yaml +# --rule-file={dpct_install_folder}/extensions/opt_rules/setup_rules/python_setup_script_migration_rule_ipex.yaml - Rule: rule_import_torch - Kind: PySetupRule + Kind: PythonSetupRule Priority: Fallback MatchMode: Partial PythonSyntax: import_torch @@ -16,10 +16,11 @@ Out: | import torch import intel_extension_for_pytorch - SYCL_HOME = True + import os + SYCL_HOME = os.environ.get('CMPLR_ROOT') - Rule: rule_from_torch_utils_import_cpp_extension_only - Kind: PySetupRule + Kind: PythonSetupRule Priority: Fallback MatchMode: Partial PythonSyntax: from_torch_utils_import_cpp_extension_only @@ -27,7 +28,7 @@ Out: from intel_extension_for_pytorch.xpu import cpp_extension - Rule: rule_torch_utils_cpp_extension - Kind: PySetupRule + Kind: PythonSetupRule Priority: Fallback MatchMode: Partial PythonSyntax: torch_utils_cpp_extension @@ -35,7 +36,7 @@ Out: intel_extension_for_pytorch.xpu.cpp_extension - Rule: rule_utils_cpp_extension - Kind: PySetupRule + Kind: PythonSetupRule Priority: Fallback MatchMode: Partial PythonSyntax: utils_cpp_extension @@ -43,7 +44,7 @@ Out: intel_extension_for_pytorch.xpu.cpp_extension - Rule: rule_cpp_extension_import_CppExtension - Kind: PySetupRule + Kind: PythonSetupRule Priority: Fallback MatchMode: Partial PythonSyntax: cpp_extension_import_CppExtension @@ -53,7 +54,7 @@ from torch.utils.cpp_extension import CppExtension - Rule: rule_CUDA_HOME - Kind: PySetupRule + Kind: PythonSetupRule Priority: Fallback MatchMode: Partial PythonSyntax: CUDA_HOME @@ -61,7 +62,7 @@ Out: SYCL_HOME - Rule: rule_cpp_extension_import_SYCL_HOME - Kind: PySetupRule + Kind: PythonSetupRule Priority: Fallback MatchMode: Partial PythonSyntax: cpp_extension_import_SYCL_HOME @@ -69,7 +70,7 @@ Out: from ${mod_prefix}cpp_extension import${ws}(${class_prefix}${class_suffix}) - Rule: rule_CUDAExtension - Kind: PySetupRule + Kind: PythonSetupRule Priority: Fallback MatchMode: Partial PythonSyntax: CUDAExtension @@ -77,7 +78,7 @@ Out: DPCPPExtension - Rule: rule_cuda_is_available - Kind: PySetupRule + Kind: PythonSetupRule Priority: Fallback MatchMode: Partial PythonSyntax: cuda_is_available @@ -85,7 +86,7 @@ Out: xpu.is_available - Rule: rule_include_dirs - Kind: PySetupRule + Kind: PythonSetupRule Priority: Fallback MatchMode: Partial PythonSyntax: include_dirs @@ -93,7 +94,7 @@ Out: DPCPPExtension(${args}, include_dirs=cpp_extension.include_paths(),) - Rule: rule_BuildExtension - Kind: PySetupRule + Kind: PythonSetupRule Priority: Fallback MatchMode: Partial PythonSyntax: BuildExtension @@ -101,7 +102,7 @@ Out: DpcppBuildExtension - Rule: rule_cu_file - Kind: PySetupRule + Kind: PythonSetupRule Priority: Fallback MatchMode: Partial PythonSyntax: cu_file