已合并
[v2.10.0][bugfix]CI error:acl header missing fix #36837
Dring创建于 5月27日
[v2.10.0][bugfix]CI error:acl header missing fix #36837
已合并
共 4 个文件变更+70-25
| @@ -6,6 +6,7 @@ import subprocess | |||
| 6 | import threading | 6 | import threading |
| 7 | import queue | 7 | import queue |
| 8 | import argparse | 8 | import argparse |
| 9 | +import shutil | ||
| 9 | from pathlib import Path | 10 | from pathlib import Path |
| 10 | import random | 11 | import random |
| 11 | import psutil | 12 | import psutil |
| @@ -15,6 +16,56 @@ from access_control import ( | |||
| 15 | ) | 16 | ) |
| 16 | 17 | ||
| 17 | 18 | ||
| 19 | +def fetch_acl_headers(): | ||
| 20 | + acl_dest = BASE_DIR / 'third_party' / 'acl' / 'inc' / 'acl' | ||
| 21 | + acl_src = BASE_DIR / 'third_party' / 'acl_src' | ||
| 22 | + | ||
| 23 | + print(" --- Fetching ACL headers...") | ||
| 24 | + | ||
| 25 | + copied_from_submodule = False | ||
| 26 | + | ||
| 27 | + # 1. Try submodule source | ||
| 28 | + runtime_acl = acl_src / 'runtime' / 'include' / 'external' / 'acl' | ||
| 29 | + if runtime_acl.is_dir(): | ||
| 30 | + acl_dest.mkdir(parents=True, exist_ok=True) | ||
| 31 | + shutil.copytree(str(runtime_acl), str(acl_dest), dirs_exist_ok=True) | ||
| 32 | + print(" --- Copied runtime acl headers") | ||
| 33 | + copied_from_submodule = True | ||
| 34 | + | ||
| 35 | + ge_acl = acl_src / 'ge' / 'inc' / 'external' / 'acl' | ||
| 36 | + if ge_acl.is_dir(): | ||
| 37 | + acl_dest.mkdir(parents=True, exist_ok=True) | ||
| 38 | + shutil.copytree(str(ge_acl), str(acl_dest), dirs_exist_ok=True) | ||
| 39 | + print(" --- Copied ge acl headers") | ||
| 40 | + copied_from_submodule = True | ||
| 41 | + | ||
| 42 | + super_kernel_src = acl_src / 'graph-autofusion' / 'super_kernel' / 'include' / 'super_kernel' / 'super_kernel.h' | ||
| 43 | + if super_kernel_src.is_file(): | ||
| 44 | + acl_dest.mkdir(parents=True, exist_ok=True) | ||
| 45 | + shutil.copy2(str(super_kernel_src), str(acl_dest / 'super_kernel.h')) | ||
| 46 | + print(" --- Copied super_kernel.h") | ||
| 47 | + copied_from_submodule = True | ||
| 48 | + | ||
| 49 | + if copied_from_submodule: | ||
| 50 | + if acl_src.is_dir(): | ||
| 51 | + shutil.rmtree(str(acl_src)) | ||
| 52 | + print(" --- Cleaned up acl_src submodule directories") | ||
| 53 | + else: | ||
| 54 | + # 2. Fallback: copy from installed torch_npu | ||
| 55 | + try: | ||
| 56 | + import torch_npu | ||
| 57 | + installed_acl = Path( | ||
| 58 | + torch_npu.__file__).resolve().parent / 'include' / 'third_party' / 'acl' / 'inc' / 'acl' | ||
| 59 | + if installed_acl.is_dir(): | ||
| 60 | + acl_dest.mkdir(parents=True, exist_ok=True) | ||
| 61 | + shutil.copytree(str(installed_acl), str(acl_dest), dirs_exist_ok=True) | ||
| 62 | + print(" --- Fallback: copied acl headers from installed torch_npu") | ||
| 63 | + except Exception as e: | ||
| 64 | + print(f" --- Fallback failed: {e}") | ||
| 65 | + | ||
| 66 | + print(" --- ACL headers fetched successfully") | ||
| 67 | + | ||
| 68 | + | ||
| 18 | def exec_ut(files): | 69 | def exec_ut(files): |
| 19 | """ | 70 | """ |
| 20 | 执行单元测试文件,其中存在失败,则标识异常并打印相关信息 | 71 | 执行单元测试文件,其中存在失败,则标识异常并打印相关信息 |
| @@ -124,6 +175,7 @@ if __name__ == "__main__": | |||
| 124 | parser.add_argument('--network_ops', action="store_true", help='Run network_ops testcases in the op-plugin repo') | 175 | parser.add_argument('--network_ops', action="store_true", help='Run network_ops testcases in the op-plugin repo') |
| 125 | options = parser.parse_args() | 176 | options = parser.parse_args() |
| 126 | print(f"options: {options}") | 177 | print(f"options: {options}") |
| 178 | + fetch_acl_headers() | ||
| 127 | cur_modify_files = str(BASE_DIR / 'modify_files.txt') | 179 | cur_modify_files = str(BASE_DIR / 'modify_files.txt') |
| 128 | test_mgr = TestMgr() | 180 | test_mgr = TestMgr() |
| 129 | 181 | ||
| @@ -3,7 +3,6 @@ import sys | |||
| 3 | import shutil | 3 | import shutil |
| 4 | import subprocess | 4 | import subprocess |
| 5 | import ctypes | 5 | import ctypes |
| 6 | -import unittest | ||
| 7 | import torch | 6 | import torch |
| 8 | import torch.utils.cpp_extension | 7 | import torch.utils.cpp_extension |
| 9 | 8 | ||
| @@ -27,10 +26,6 @@ def build_stub(base_dir): | |||
| 27 | raise RuntimeError('Failed to build stub: {}'.format(build_stub_cmd)) | 26 | raise RuntimeError('Failed to build stub: {}'.format(build_stub_cmd)) |
| 28 | 27 | ||
| 29 | 28 | ||
| 30 | - | ||
| 31 | - "Skip: pre-existing CI environment issue, " | ||
| 32 | - "acl/acl_base_rt.h header missing on ARM CI" | ||
| 33 | -) | ||
| 34 | class TestPluggableAllocator(TestCase): | 29 | class TestPluggableAllocator(TestCase): |
| 35 | module = None | 30 | module = None |
| 36 | new_alloc = None | 31 | new_alloc = None |
| @@ -39,7 +34,9 @@ class TestPluggableAllocator(TestCase): | |||
| 39 | 34 | ||
| 40 | def setUpClass(cls): | 35 | def setUpClass(cls): |
| 41 | # Build Extension | 36 | # Build Extension |
| 42 | - BASE_DIR = os.path.abspath("./../") | 37 | + TEST_FILE_DIR = os.path.dirname(os.path.abspath(__file__)) |
| 38 | + TEST_DIR = os.path.dirname(TEST_FILE_DIR) | ||
| 39 | + BASE_DIR = os.path.dirname(TEST_DIR) | ||
| 43 | build_stub(BASE_DIR) | 40 | build_stub(BASE_DIR) |
| 44 | create_build_path(cls.build_directory) | 41 | create_build_path(cls.build_directory) |
| 45 | CANN_LIB_PATH = os.path.join(BASE_DIR, 'third_party/acl/libs') | 42 | CANN_LIB_PATH = os.path.join(BASE_DIR, 'third_party/acl/libs') |
| @@ -48,13 +45,14 @@ class TestPluggableAllocator(TestCase): | |||
| 48 | extra_ldflags.append(f"-L{CANN_LIB_PATH}") | 45 | extra_ldflags.append(f"-L{CANN_LIB_PATH}") |
| 49 | extra_ldflags.append("-lc10") | 46 | extra_ldflags.append("-lc10") |
| 50 | extra_ldflags.append(f"-L{PYTORCH_INSTALL_PATH}") | 47 | extra_ldflags.append(f"-L{PYTORCH_INSTALL_PATH}") |
| 51 | - extra_include_paths = ["cpp_extensions"] | 48 | + extra_include_paths = [os.path.join(TEST_DIR, "cpp_extensions")] |
| 52 | extra_include_paths.append(os.path.join(PYTORCH_NPU_INSTALL_PATH, 'include')) | 49 | extra_include_paths.append(os.path.join(PYTORCH_NPU_INSTALL_PATH, 'include')) |
| 50 | + extra_include_paths.append(os.path.join(PYTORCH_NPU_INSTALL_PATH, 'include', 'third_party', 'acl', 'inc')) | ||
| 53 | 51 | ||
| 54 | cls.module = torch.utils.cpp_extension.load( | 52 | cls.module = torch.utils.cpp_extension.load( |
| 55 | name="pluggable_allocator_extensions", | 53 | name="pluggable_allocator_extensions", |
| 56 | sources=[ | 54 | sources=[ |
| 57 | - "cpp_extensions/pluggable_allocator_extensions.cpp" | 55 | + os.path.join(TEST_DIR, "cpp_extensions", "pluggable_allocator_extensions.cpp") |
| 58 | ], | 56 | ], |
| 59 | extra_include_paths=extra_include_paths, | 57 | extra_include_paths=extra_include_paths, |
| 60 | extra_cflags=["-g"], | 58 | extra_cflags=["-g"], |
| @@ -2,7 +2,6 @@ import os | |||
| 2 | import gc | 2 | import gc |
| 3 | import shutil | 3 | import shutil |
| 4 | import threading | 4 | import threading |
| 5 | -import unittest | ||
| 6 | import subprocess | 5 | import subprocess |
| 7 | 6 | ||
| 8 | import torch | 7 | import torch |
| @@ -29,10 +28,6 @@ def build_stub(base_dir): | |||
| 29 | raise RuntimeError('Failed to build stub: {}'.format(build_stub_cmd)) | 28 | raise RuntimeError('Failed to build stub: {}'.format(build_stub_cmd)) |
| 30 | 29 | ||
| 31 | 30 | ||
| 32 | - | ||
| 33 | - "Skip: pre-existing CI environment issue, " | ||
| 34 | - "acl/acl_base_rt.h header missing on ARM CI" | ||
| 35 | -) | ||
| 36 | class TestPluggableAllocator(TestCase): | 31 | class TestPluggableAllocator(TestCase): |
| 37 | torch.npu.memory._set_allocator_settings("expandable_segments:True") | 32 | torch.npu.memory._set_allocator_settings("expandable_segments:True") |
| 38 | module = None | 33 | module = None |
| @@ -49,7 +44,8 @@ class TestPluggableAllocator(TestCase): | |||
| 49 | return | 44 | return |
| 50 | 45 | ||
| 51 | # Build Extension | 46 | # Build Extension |
| 52 | - BASE_DIR = os.path.abspath("./../") | 47 | + TEST_DIR = os.path.dirname(os.path.abspath(__file__)) |
| 48 | + BASE_DIR = os.path.dirname(TEST_DIR) | ||
| 53 | build_stub(BASE_DIR) | 49 | build_stub(BASE_DIR) |
| 54 | create_build_path(cls.build_directory) | 50 | create_build_path(cls.build_directory) |
| 55 | CANN_LIB_PATH = os.path.join(BASE_DIR, 'third_party/acl/libs') | 51 | CANN_LIB_PATH = os.path.join(BASE_DIR, 'third_party/acl/libs') |
| @@ -58,13 +54,14 @@ class TestPluggableAllocator(TestCase): | |||
| 58 | extra_ldflags.append(f"-L{CANN_LIB_PATH}") | 54 | extra_ldflags.append(f"-L{CANN_LIB_PATH}") |
| 59 | extra_ldflags.append("-lc10") | 55 | extra_ldflags.append("-lc10") |
| 60 | extra_ldflags.append(f"-L{PYTORCH_INSTALL_PATH}") | 56 | extra_ldflags.append(f"-L{PYTORCH_INSTALL_PATH}") |
| 61 | - extra_include_paths = ["cpp_extensions"] | 57 | + extra_include_paths = [os.path.join(TEST_DIR, "cpp_extensions")] |
| 62 | - extra_include_paths.append(os.path.join(PYTORCH_NPU_INSTALL_PATH, 'include')) | 58 | + extra_include_paths.append(os.path.join(PYTORCH_NPU_INSTALL_PATH, "include")) |
| 59 | + extra_include_paths.append(os.path.join(PYTORCH_NPU_INSTALL_PATH, 'include', 'third_party', 'acl', 'inc')) | ||
| 63 | 60 | ||
| 64 | cls.module = torch.utils.cpp_extension.load( | 61 | cls.module = torch.utils.cpp_extension.load( |
| 65 | name="pluggable_allocator_extensions", | 62 | name="pluggable_allocator_extensions", |
| 66 | sources=[ | 63 | sources=[ |
| 67 | - "cpp_extensions/pluggable_allocator_extensions.cpp" | 64 | + os.path.join(TEST_DIR, "cpp_extensions", "pluggable_allocator_extensions.cpp") |
| 68 | ], | 65 | ], |
| 69 | extra_include_paths=extra_include_paths, | 66 | extra_include_paths=extra_include_paths, |
| 70 | extra_cflags=["-g"], | 67 | extra_cflags=["-g"], |
| @@ -60,10 +60,6 @@ def reset_sanitizer(): | |||
| 60 | sanitizer.npu_sanitizer.enabled = False | 60 | sanitizer.npu_sanitizer.enabled = False |
| 61 | 61 | ||
| 62 | 62 | ||
| 63 | - | ||
| 64 | - "Skip: pre-existing CI environment issue, " | ||
| 65 | - "acl/acl_base_rt.h header missing on ARM CI" | ||
| 66 | -) | ||
| 67 | 63 | ||
| 68 | class TestSanitizerPluggableAllocator(TestCase): | 64 | class TestSanitizerPluggableAllocator(TestCase): |
| 69 | module = None | 65 | module = None |
| @@ -71,7 +67,8 @@ class TestSanitizerPluggableAllocator(TestCase): | |||
| 71 | 67 | ||
| 72 | 68 | ||
| 73 | def setUpClass(cls): | 69 | def setUpClass(cls): |
| 74 | - BASE_DIR = os.path.abspath("./../") | 70 | + TEST_DIR = os.path.dirname(os.path.abspath(__file__)) |
| 71 | + BASE_DIR = os.path.dirname(TEST_DIR) | ||
| 75 | build_stub(BASE_DIR) | 72 | build_stub(BASE_DIR) |
| 76 | create_build_path(cls.build_directory) | 73 | create_build_path(cls.build_directory) |
| 77 | CANN_LIB_PATH = os.path.join(BASE_DIR, "third_party/acl/libs") | 74 | CANN_LIB_PATH = os.path.join(BASE_DIR, "third_party/acl/libs") |
| @@ -80,12 +77,13 @@ class TestSanitizerPluggableAllocator(TestCase): | |||
| 80 | extra_ldflags.append(f"-L{CANN_LIB_PATH}") | 77 | extra_ldflags.append(f"-L{CANN_LIB_PATH}") |
| 81 | extra_ldflags.append("-lc10") | 78 | extra_ldflags.append("-lc10") |
| 82 | extra_ldflags.append(f"-L{PYTORCH_INSTALL_PATH}") | 79 | extra_ldflags.append(f"-L{PYTORCH_INSTALL_PATH}") |
| 83 | - extra_include_paths = ["cpp_extensions"] | 80 | + extra_include_paths = [os.path.join(TEST_DIR, "cpp_extensions")] |
| 84 | - extra_include_paths.append(os.path.join(PYTORCH_NPU_INSTALL_PATH, "include")) | 81 | + extra_include_paths.append(os.path.join(PYTORCH_NPU_INSTALL_PATH, 'include')) |
| 82 | + extra_include_paths.append(os.path.join(PYTORCH_NPU_INSTALL_PATH, 'include', 'third_party', 'acl', 'inc')) | ||
| 85 | 83 | ||
| 86 | cls.module = torch.utils.cpp_extension.load( | 84 | cls.module = torch.utils.cpp_extension.load( |
| 87 | name="sanitizer_pluggable_allocator_extensions", | 85 | name="sanitizer_pluggable_allocator_extensions", |
| 88 | - sources=["cpp_extensions/pluggable_allocator_extensions.cpp"], | 86 | + sources=[os.path.join(TEST_DIR, "cpp_extensions", "pluggable_allocator_extensions.cpp")], |
| 89 | extra_include_paths=extra_include_paths, | 87 | extra_include_paths=extra_include_paths, |
| 90 | extra_cflags=["-g"], | 88 | extra_cflags=["-g"], |
| 91 | extra_ldflags=extra_ldflags, | 89 | extra_ldflags=extra_ldflags, |