Skip to content

Commit 44d48e4

Browse files
authored
[SYCLomatic] Add a new rule file pytorch_api.yaml to migrate PyTroch API(#2438)
Signed-off-by: Jiang, Zhiwei <[email protected]>
1 parent 5b2257f commit 44d48e4

File tree

6 files changed

+99
-24
lines changed

6 files changed

+99
-24
lines changed

clang/CMakeLists.txt

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -953,9 +953,7 @@ if (NOT CLANG_BUILT_STANDALONE)
953953
install-dpct-headers
954954
install-clang-resource-headers
955955
install-dpct-binary
956-
install-dpct-opt-rules
957-
install-dpct-cmake-rules
958-
install-dpct-python-rules
956+
install-dpct-rules
959957
install-dpct-cmake-file
960958
install-dpct-codepin-report
961959
)
@@ -968,9 +966,7 @@ if (NOT CLANG_BUILT_STANDALONE)
968966
install-dpct-binary
969967
install-dpct-autocomplete
970968
install-dpct-setvars
971-
install-dpct-opt-rules
972-
install-dpct-cmake-rules
973-
install-dpct-python-rules
969+
install-dpct-rules
974970
install-dpct-cmake-file
975971
install-dpct-codepin-report
976972
)

clang/tools/dpct/DpctOptRules/CMakeLists.txt

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,41 +13,48 @@ set(dpct_python_rule_files
1313
${CMAKE_SOURCE_DIR}/../clang/tools/dpct/DpctOptRules/python_build_script_migration_rule_ipex.yaml
1414
)
1515

16+
set(dpct_pytorch_api_rule_files
17+
${CMAKE_SOURCE_DIR}/../clang/tools/dpct/DpctOptRules/pytorch_api.yaml
18+
)
19+
1620
install(
1721
FILES ${dpct_opt_rule_files}
18-
COMPONENT dpct-opt-rules
22+
COMPONENT dpct-rules
1923
PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ
2024
DESTINATION ./extensions/opt_rules)
2125

2226
install(
2327
FILES ${dpct_cmake_rule_files}
24-
COMPONENT dpct-cmake-rules
28+
COMPONENT dpct-rules
2529
PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ
2630
DESTINATION ./extensions/cmake_rules)
2731

2832
install(
29-
FILES ${dpct_cmake_rule_files}
30-
COMPONENT dpct-cmake-rules
33+
FILES ${dpct_python_rule_files}
34+
COMPONENT dpct-rules
3135
PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ
32-
DESTINATION ${CMAKE_BINARY_DIR}/extensions/cmake_rules)
36+
DESTINATION ./extensions/python_rules)
3337

3438
install(
35-
FILES ${dpct_python_rule_files}
36-
COMPONENT dpct-python-rules
39+
FILES ${dpct_pytorch_api_rule_files}
40+
COMPONENT dpct-rules
3741
PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ
38-
DESTINATION ./extensions/python_rules)
42+
DESTINATION ./extensions/pytorch_api_rule_rules)
3943

44+
# Below two install commands are copying those files into some location under
45+
# the build folder, which need be accessed during the LIT.
46+
install(
47+
FILES ${dpct_cmake_rule_files}
48+
COMPONENT dpct-rules
49+
PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ
50+
DESTINATION ${CMAKE_BINARY_DIR}/extensions/cmake_rules)
4051
install(
4152
FILES ${dpct_python_rule_files}
42-
COMPONENT dpct-python-rules
53+
COMPONENT dpct-rules
4354
PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ
4455
DESTINATION ${CMAKE_BINARY_DIR}/extensions/python_rules)
4556

4657
if (NOT CMAKE_CONFIGURATION_TYPES) # don't add this for IDE's.
47-
add_llvm_install_targets(install-dpct-opt-rules
48-
COMPONENT dpct-opt-rules)
49-
add_llvm_install_targets(install-dpct-cmake-rules
50-
COMPONENT dpct-cmake-rules)
51-
add_llvm_install_targets(install-dpct-python-rules
52-
COMPONENT dpct-python-rules)
58+
add_llvm_install_targets(install-dpct-rules
59+
COMPONENT dpct-rules)
5360
endif()

clang/tools/dpct/DpctOptRules/python_build_script_migration_rule_ipex.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
# See https://llvm.org/LICENSE.txt for license information.
44

55
# This file will be installed to folder:
6-
# {dpct_install_folder}/extensions/opt_rules.
6+
# {dpct_install_folder}/extensions/python_rules.
77
# The rule specified in this file can be imported with commandline option:
8-
# --rule-file={dpct_install_folder}/extensions/opt_rules/setup_rules/python_build_script_migration_rule_ipex.yaml
8+
# --rule-file={dpct_install_folder}/extensions/python_rules/python_build_script_migration_rule_ipex.yaml
99

1010
- Rule: rule_import_torch
1111
Kind: PythonRule
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Copyright (C) Intel Corporation
2+
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3+
# See https://llvm.org/LICENSE.txt for license information.
4+
5+
# This file will be installed to folder:
6+
# {dpct_install_folder}/extensions/pytorch_api_rules.
7+
# The rule specified in this file can be imported with commandline option:
8+
# --rule-file={dpct_install_folder}/extensions/pytorch_api_rules/pytorch_api.yaml
9+
---
10+
- Rule: rule_CUDAGuard_h
11+
Kind: Header
12+
Priority: Takeover
13+
In: c10/cuda/CUDAGuard.h
14+
Out: c10/core/DeviceGuard.h
15+
Includes: []
16+
17+
- Rule: rule_OptionalCUDAGuard
18+
Kind: Type
19+
Priority: Takeover
20+
In: c10::cuda::OptionalCUDAGuard
21+
Out: c10::OptionalDeviceGuard
22+
Includes: []
23+
24+
- Rule: rule_CUDAStream_h
25+
Kind: Header
26+
Priority: Takeover
27+
In: c10/cuda/CUDAStream.h
28+
Out: c10/xpu/XPUStream.h
29+
Includes: []
30+
31+
- Rule: rule_CUDATensorMethods_cuh
32+
Kind: Header
33+
Priority: Takeover
34+
In: ATen/cuda/CUDATensorMethods.cuh
35+
Out: c10/util/Half.h
36+
Includes: ["ATen/Tensor.h"]
37+
38+
- Rule: rule_default_queue
39+
Kind: HelperFunction
40+
Priority: Takeover
41+
In: get_in_order_queue
42+
Out: static_cast<sycl::queue&>(c10::xpu::getCurrentXPUStream())

clang/tools/dpct/RuleTemplates/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@ set(dpct_rule_template_files
77
${CMAKE_SOURCE_DIR}/../clang/tools/dpct/RuleTemplates/macro_rule.yaml
88
${CMAKE_SOURCE_DIR}/../clang/tools/dpct/RuleTemplates/pattern_rewrite_rule.yaml
99
${CMAKE_SOURCE_DIR}/../clang/tools/dpct/RuleTemplates/type_rule.yaml
10+
${CMAKE_SOURCE_DIR}/../clang/tools/dpct/RuleTemplates/helper_function_rule.yaml
1011
)
1112

1213
install(
1314
FILES ${dpct_rule_template_files}
14-
COMPONENT dpct-opt-rules
15+
COMPONENT dpct-rules
1516
PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ
1617
DESTINATION ./extensions/rule_templates)
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Copyright (C) Intel Corporation
2+
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3+
# See https://llvm.org/LICENSE.txt for license information.
4+
5+
# The rule specified in this file can be imported with commandline option:
6+
# --rule-file={dpct_install_folder}/extensions/rule_templates/helper_function_rule.yaml
7+
---
8+
- Rule: rule_default_queue
9+
Kind: HelperFunction
10+
Priority: Takeover
11+
In: get_in_order_queue
12+
Out: getUserDefinedQueue()
13+
14+
# Following are the original CUDA source code and the migrated SYCL source code after applying the above rule.
15+
# example.cu:
16+
# ---------------------------------
17+
# int *a;
18+
# cudaMalloc(&a, sizeof(int));
19+
# ---------------------------------
20+
#
21+
# example.dp.cpp:
22+
# Generated by: dpct example.cu --rule-file={dpct_install_folder}/extensions/rule_templates/helper_function_rule.yaml
23+
# ---------------------------------
24+
# int *a;
25+
# a = sycl::malloc_device<int>(1, getUserDefinedQueue());
26+
# ---------------------------------
27+
28+
# Migration Rules section of Intel® DPC++ Compatibility Tool Developer Guide and Reference in
29+
# https://www.intel.com/content/www/us/en/developer/tools/oneapi/dpc-compatibility-tool-documentation.html

0 commit comments

Comments
 (0)