Skip to content

Commit

Permalink
Created separate ipex yaml rule file
Browse files Browse the repository at this point in the history
  • Loading branch information
TejaX-Alaghari committed Oct 11, 2024
1 parent 89bda7d commit e9a3354
Show file tree
Hide file tree
Showing 13 changed files with 34 additions and 29 deletions.
3 changes: 2 additions & 1 deletion clang/include/clang/DPCT/DPCTOptions.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
7 changes: 4 additions & 3 deletions clang/lib/DPCT/DPCT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<clang::tooling::UnifiedPath> PythonSetupRuleFiles{
PythonSetupRuleFilePath};
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/DPCT/Rules.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ void importRules(std::vector<clang::tooling::UnifiedPath> &RuleFiles) {
case (RuleKind::CMakeRule):
registerCmakeMigrationRule(*r);
break;
case (RuleKind::PySetupRule):
case (RuleKind::PythonSetupRule):
registerPythonSetupMigrationRule(*r);
break;
default:
Expand Down
4 changes: 2 additions & 2 deletions clang/lib/DPCT/Rules.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ enum RuleKind {
DisableAPIMigration,
PatternRewriter,
CMakeRule,
PySetupRule
PythonSetupRule
};

enum RulePriority { Takeover, Default, Fallback };
Expand Down Expand Up @@ -210,7 +210,7 @@ template <> struct llvm::yaml::ScalarEnumerationTraits<RuleKind> {
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);
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion clang/test/dpct/python_setup_migration/case_001/expected.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
3 changes: 2 additions & 1 deletion clang/test/dpct/python_setup_migration/case_002/expected.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion clang/tools/dpct/DpctOptRules/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,45 +5,46 @@
# 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
In: import torch
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
In: from torch.utils import cpp_extension
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
In: torch.utils.cpp_extension
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
In: utils.cpp_extension
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
Expand All @@ -53,55 +54,55 @@
from torch.utils.cpp_extension import CppExtension
- Rule: rule_CUDA_HOME
Kind: PySetupRule
Kind: PythonSetupRule
Priority: Fallback
MatchMode: Partial
PythonSyntax: CUDA_HOME
In: CUDA_HOME
Out: SYCL_HOME

- Rule: rule_cpp_extension_import_SYCL_HOME
Kind: PySetupRule
Kind: PythonSetupRule
Priority: Fallback
MatchMode: Partial
PythonSyntax: cpp_extension_import_SYCL_HOME
In: from ${mod_prefix}cpp_extension import${ws}(${class_prefix}SYCL_HOME,${class_suffix})
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
In: CUDAExtension
Out: DPCPPExtension

- Rule: rule_cuda_is_available
Kind: PySetupRule
Kind: PythonSetupRule
Priority: Fallback
MatchMode: Partial
PythonSyntax: cuda_is_available
In: cuda.is_available
Out: xpu.is_available

- Rule: rule_include_dirs
Kind: PySetupRule
Kind: PythonSetupRule
Priority: Fallback
MatchMode: Partial
PythonSyntax: include_dirs
In: DPCPPExtension(${args})
Out: DPCPPExtension(${args}, include_dirs=cpp_extension.include_paths(),)

- Rule: rule_BuildExtension
Kind: PySetupRule
Kind: PythonSetupRule
Priority: Fallback
MatchMode: Partial
PythonSyntax: BuildExtension
In: BuildExtension
Out: DpcppBuildExtension

- Rule: rule_cu_file
Kind: PySetupRule
Kind: PythonSetupRule
Priority: Fallback
MatchMode: Partial
PythonSyntax: cu_file
Expand Down

0 comments on commit e9a3354

Please sign in to comment.