已合并
[master][bugfix]cann and pta header mixing bulid bugfix #44990
Dring创建于 8月20日
[master][bugfix]cann and pta header mixing bulid bugfix #44990
已合并
共 82 个文件变更+1465-1596
| @@ -242,8 +242,6 @@ def copy_hpp(): | |||
| 242 | "torch_npu/csrc/inductor/**/*.h", | 242 | "torch_npu/csrc/inductor/**/*.h", |
| 243 | "torch_npu/csrc/distributed/*.h", | 243 | "torch_npu/csrc/distributed/*.h", |
| 244 | "torch_npu/csrc/distributed/*.hpp", | 244 | "torch_npu/csrc/distributed/*.hpp", |
| 245 | - "third_party/acl/inc/*/*.h", | ||
| 246 | - "third_party/acl/inc/*/*/*.h", | ||
| 247 | "third_party/hccl/inc/*/*.h", | 245 | "third_party/hccl/inc/*/*.h", |
| 248 | ] | 246 | ] |
| 249 | glob_header_files = [] | 247 | glob_header_files = [] |
| @@ -257,6 +255,39 @@ def copy_hpp(): | |||
| 257 | os.makedirs(os.path.dirname(dst), exist_ok=True) | 255 | os.makedirs(os.path.dirname(dst), exist_ok=True) |
| 258 | ret.append((src, dst)) | 256 | ret.append((src, dst)) |
| 259 | 257 | ||
| 258 | + acl_include_root = os.path.join(BASE_DIR, "third_party", "acl", "inc") | ||
| 259 | + acl_header_files = glob.glob( | ||
| 260 | + os.path.join(acl_include_root, "**", "*.h"), | ||
| 261 | + recursive=True, | ||
| 262 | + ) | ||
| 263 | + for src in acl_header_files: | ||
| 264 | + relative_header = os.path.relpath(src, acl_include_root) | ||
| 265 | + dst = os.path.join( | ||
| 266 | + BASE_DIR, | ||
| 267 | + "libtorch_npu/include", | ||
| 268 | + relative_header, | ||
| 269 | + ) | ||
| 270 | + os.makedirs(os.path.dirname(dst), exist_ok=True) | ||
| 271 | + ret.append((src, dst)) | ||
| 272 | + | ||
| 273 | + # Preserve legacy include paths with forwarding headers, not duplicate ACL headers. | ||
| 274 | + compatibility_src = os.path.join( | ||
| 275 | + BASE_DIR, | ||
| 276 | + "build/acl_compat_headers", | ||
| 277 | + relative_header, | ||
| 278 | + ) | ||
| 279 | + os.makedirs(os.path.dirname(compatibility_src), exist_ok=True) | ||
| 280 | + compatibility_include = relative_header.replace(os.sep, "/") | ||
| 281 | + with open(compatibility_src, "w", encoding="utf-8", newline="\n") as compatibility_header: | ||
| 282 | + compatibility_header.write(f"#pragma once\n#include <{compatibility_include}>\n") | ||
| 283 | + compatibility_dst = os.path.join( | ||
| 284 | + BASE_DIR, | ||
| 285 | + "libtorch_npu/include/third_party/acl/inc", | ||
| 286 | + relative_header, | ||
| 287 | + ) | ||
| 288 | + os.makedirs(os.path.dirname(compatibility_dst), exist_ok=True) | ||
| 289 | + ret.append((compatibility_src, compatibility_dst)) | ||
| 290 | + | ||
| 260 | return ret | 291 | return ret |
| 261 | ret = get_src_py_and_dst() | 292 | ret = get_src_py_and_dst() |
| 262 | for src, dst in ret: | 293 | for src, dst in ret: |
| @@ -61,7 +61,7 @@ def fetch_acl_headers(): | |||
| 61 | try: | 61 | try: |
| 62 | import torch_npu | 62 | import torch_npu |
| 63 | installed_acl = Path( | 63 | installed_acl = Path( |
| 64 | - torch_npu.__file__).resolve().parent / 'include' / 'third_party' / 'acl' / 'inc' / 'acl' | 64 | + torch_npu.__file__).resolve().parent / 'include' / 'acl' |
| 65 | if installed_acl.is_dir(): | 65 | if installed_acl.is_dir(): |
| 66 | acl_dest.mkdir(parents=True, exist_ok=True) | 66 | acl_dest.mkdir(parents=True, exist_ok=True) |
| 67 | shutil.copytree(str(installed_acl), str(acl_dest), dirs_exist_ok=True) | 67 | shutil.copytree(str(installed_acl), str(acl_dest), dirs_exist_ok=True) |
| @@ -477,9 +477,7 @@ def get_src_py_and_dst(): | |||
| 477 | "torch_npu/csrc/*/*/*.h", | 477 | "torch_npu/csrc/*/*/*.h", |
| 478 | "torch_npu/csrc/*/*/*/*.h", | 478 | "torch_npu/csrc/*/*/*/*.h", |
| 479 | "torch_npu/csrc/*/*/*/*/*.h", | 479 | "torch_npu/csrc/*/*/*/*/*.h", |
| 480 | - "third_party/acl/inc/*/*.h", | ||
| 481 | "third_party/hccl/inc/*/*.h", | 480 | "third_party/hccl/inc/*/*.h", |
| 482 | - "third_party/acl/inc/*/*/*.h", | ||
| 483 | "torch_npu/csrc/distributed/HCCLUtils.hpp", | 481 | "torch_npu/csrc/distributed/HCCLUtils.hpp", |
| 484 | "torch_npu/csrc/distributed/ProcessGroupHCCL.hpp" | 482 | "torch_npu/csrc/distributed/ProcessGroupHCCL.hpp" |
| 485 | ] | 483 | ] |
| @@ -495,6 +493,39 @@ def get_src_py_and_dst(): | |||
| 495 | os.makedirs(os.path.dirname(dst), exist_ok=True) | 493 | os.makedirs(os.path.dirname(dst), exist_ok=True) |
| 496 | ret.append((src, dst)) | 494 | ret.append((src, dst)) |
| 497 | 495 | ||
| 496 | + acl_include_root = os.path.join(BASE_DIR, "third_party", "acl", "inc") | ||
| 497 | + acl_header_files = glob.glob( | ||
| 498 | + os.path.join(acl_include_root, "**", "*.h"), | ||
| 499 | + recursive=True, | ||
| 500 | + ) | ||
| 501 | + for src in acl_header_files: | ||
| 502 | + relative_header = os.path.relpath(src, acl_include_root) | ||
| 503 | + dst = os.path.join( | ||
| 504 | + BASE_DIR, | ||
| 505 | + "build/packages/torch_npu/include", | ||
| 506 | + relative_header, | ||
| 507 | + ) | ||
| 508 | + os.makedirs(os.path.dirname(dst), exist_ok=True) | ||
| 509 | + ret.append((src, dst)) | ||
| 510 | + | ||
| 511 | + # Preserve legacy include paths with forwarding headers, not duplicate ACL headers. | ||
| 512 | + compatibility_src = os.path.join( | ||
| 513 | + BASE_DIR, | ||
| 514 | + "build/acl_compat_headers", | ||
| 515 | + relative_header, | ||
| 516 | + ) | ||
| 517 | + os.makedirs(os.path.dirname(compatibility_src), exist_ok=True) | ||
| 518 | + compatibility_include = relative_header.replace(os.sep, "/") | ||
| 519 | + with open(compatibility_src, "w", encoding="utf-8", newline="\n") as compatibility_header: | ||
| 520 | + compatibility_header.write(f"#pragma once\n#include <{compatibility_include}>\n") | ||
| 521 | + compatibility_dst = os.path.join( | ||
| 522 | + BASE_DIR, | ||
| 523 | + "build/packages/torch_npu/include/third_party/acl/inc", | ||
| 524 | + relative_header, | ||
| 525 | + ) | ||
| 526 | + os.makedirs(os.path.dirname(compatibility_dst), exist_ok=True) | ||
| 527 | + ret.append((compatibility_src, compatibility_dst)) | ||
| 528 | + | ||
| 498 | torch_header_files = [ | 529 | torch_header_files = [ |
| 499 | "*/*.h", | 530 | "*/*.h", |
| 500 | "*/*/*.h", | 531 | "*/*/*.h", |
| @@ -1,5 +1,4 @@ | |||
| 1 | import os | 1 | import os |
| 2 | -import sys | ||
| 3 | import shutil | 2 | import shutil |
| 4 | import subprocess | 3 | import subprocess |
| 5 | import ctypes | 4 | import ctypes |
| @@ -21,7 +20,12 @@ def create_build_path(build_directory): | |||
| 21 | 20 | ||
| 22 | 21 | ||
| 23 | def build_stub(base_dir): | 22 | def build_stub(base_dir): |
| 24 | - build_stub_cmd = ["sh", os.path.join(base_dir, 'third_party/acl/libs/build_stub.sh')] | 23 | + build_stub_cmd = [ |
| 24 | + "sh", | ||
| 25 | + os.path.join(base_dir, 'third_party/acl/libs/build_stub.sh'), | ||
| 26 | + # Build the stub and Extension against the same installed header root. | ||
| 27 | + os.path.join(PYTORCH_NPU_INSTALL_PATH, 'include'), | ||
| 28 | + ] | ||
| 25 | if subprocess.call(build_stub_cmd) != 0: | 29 | if subprocess.call(build_stub_cmd) != 0: |
| 26 | raise RuntimeError('Failed to build stub: {}'.format(build_stub_cmd)) | 30 | raise RuntimeError('Failed to build stub: {}'.format(build_stub_cmd)) |
| 27 | 31 | ||
| @@ -47,7 +51,6 @@ class TestPluggableAllocator(TestCase): | |||
| 47 | extra_ldflags.append(f"-L{PYTORCH_INSTALL_PATH}") | 51 | extra_ldflags.append(f"-L{PYTORCH_INSTALL_PATH}") |
| 48 | extra_include_paths = [os.path.join(TEST_DIR, "cpp_extensions")] | 52 | extra_include_paths = [os.path.join(TEST_DIR, "cpp_extensions")] |
| 49 | extra_include_paths.append(os.path.join(PYTORCH_NPU_INSTALL_PATH, 'include')) | 53 | 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')) | ||
| 51 | 54 | ||
| 52 | cls.module = torch.utils.cpp_extension.load( | 55 | cls.module = torch.utils.cpp_extension.load( |
| 53 | name="pluggable_allocator_extensions", | 56 | name="pluggable_allocator_extensions", |
| @@ -77,7 +80,7 @@ class TestPluggableAllocator(TestCase): | |||
| 77 | def test_set_get_device_stats_fn(self): | 80 | def test_set_get_device_stats_fn(self): |
| 78 | os_path = os.path.join(TestPluggableAllocator.build_directory, 'pluggable_allocator_extensions.so') | 81 | os_path = os.path.join(TestPluggableAllocator.build_directory, 'pluggable_allocator_extensions.so') |
| 79 | myallocator = ctypes.CDLL(os_path) | 82 | myallocator = ctypes.CDLL(os_path) |
| 80 | - get_device_stats_fn = ctypes.cast(getattr(myallocator, "my_get_device_stats"), ctypes.c_void_p).value | 83 | + get_device_stats_fn = ctypes.cast(myallocator.my_get_device_stats, ctypes.c_void_p).value |
| 81 | 84 | ||
| 82 | TestPluggableAllocator.new_alloc.allocator().set_get_device_stats_fn(get_device_stats_fn) | 85 | TestPluggableAllocator.new_alloc.allocator().set_get_device_stats_fn(get_device_stats_fn) |
| 83 | self.assertEqual(torch.npu.memory_stats_as_nested_dict()["num_alloc_retries"], 0) | 86 | self.assertEqual(torch.npu.memory_stats_as_nested_dict()["num_alloc_retries"], 0) |
| @@ -85,7 +88,7 @@ class TestPluggableAllocator(TestCase): | |||
| 85 | def test_set_reset_peak_status_fn(self): | 88 | def test_set_reset_peak_status_fn(self): |
| 86 | os_path = os.path.join(TestPluggableAllocator.build_directory, 'pluggable_allocator_extensions.so') | 89 | os_path = os.path.join(TestPluggableAllocator.build_directory, 'pluggable_allocator_extensions.so') |
| 87 | myallocator = ctypes.CDLL(os_path) | 90 | myallocator = ctypes.CDLL(os_path) |
| 88 | - reset_peak_status_fn = ctypes.cast(getattr(myallocator, "my_reset_peak_status"), ctypes.c_void_p).value | 91 | + reset_peak_status_fn = ctypes.cast(myallocator.my_reset_peak_status, ctypes.c_void_p).value |
| 89 | 92 | ||
| 90 | TestPluggableAllocator.new_alloc.allocator().set_reset_peak_status_fn(reset_peak_status_fn) | 93 | TestPluggableAllocator.new_alloc.allocator().set_reset_peak_status_fn(reset_peak_status_fn) |
| 91 | torch.npu.reset_peak_memory_stats() | 94 | torch.npu.reset_peak_memory_stats() |
| @@ -3,8 +3,8 @@ | |||
| 3 | 3 | ||
| 4 | 4 | ||
| 5 | 5 | ||
| 6 | -#include "third_party/acl/inc/acl/acl_base.h" | 6 | +#include <acl/acl_base.h> |
| 7 | -#include "third_party/acl/inc/acl/acl_rt.h" | 7 | +#include <acl/acl_rt.h> |
| 8 | 8 | ||
| 9 | 9 | ||
| 10 | extern "C" { | 10 | extern "C" { |
| @@ -3,16 +3,14 @@ import time | |||
| 3 | import unittest | 3 | import unittest |
| 4 | import warnings | 4 | import warnings |
| 5 | import torch | 5 | import torch |
| 6 | -import torch.distributed as dist | ||
| 7 | import torch.distributed.autograd as dist_autograd | 6 | import torch.distributed.autograd as dist_autograd |
| 8 | import torch.distributed.rpc as rpc | 7 | import torch.distributed.rpc as rpc |
| 9 | from torch import multiprocessing as mp | 8 | from torch import multiprocessing as mp |
| 10 | -from torch import nn, Tensor | 9 | +from torch import nn |
| 11 | from torch.distributed.nn.api.remote_module import RemoteModule | 10 | from torch.distributed.nn.api.remote_module import RemoteModule |
| 12 | -from torch.distributed.rpc import WorkerInfo, PyRRef | 11 | +from torch.distributed.rpc import WorkerInfo |
| 13 | from torch._C import _get_privateuse1_backend_name | 12 | from torch._C import _get_privateuse1_backend_name |
| 14 | 13 | ||
| 15 | -import torch_npu | ||
| 16 | from torch_npu.distributed.rpc.options import NPUTensorPipeRpcBackendOptions | 14 | from torch_npu.distributed.rpc.options import NPUTensorPipeRpcBackendOptions |
| 17 | from torch_npu.testing.common_distributed import skipIfUnsupportMultiNPU | 15 | from torch_npu.testing.common_distributed import skipIfUnsupportMultiNPU |
| 18 | from torch_npu.testing.testcase import TestCase, run_tests | 16 | from torch_npu.testing.testcase import TestCase, run_tests |
| @@ -335,7 +333,7 @@ class TestRpc(TestCase): | |||
| 335 | 333 | ||
| 336 | 334 | ||
| 337 | def test_async_call_for_cpu(self): | 335 | def test_async_call_for_cpu(self): |
| 338 | - inputs = [torch.rand(1024, 1024).cpu(), torch.rand(1024, 1024, 1024).cpu()] | 336 | + inputs = [torch.rand(1024, 1024).cpu(), torch.rand(1024, 1024, 4).cpu()] |
| 339 | self._test_multiprocess(TestRpc._test_async_call_for_cpu, inputs, self.world_size_2p) | 337 | self._test_multiprocess(TestRpc._test_async_call_for_cpu, inputs, self.world_size_2p) |
| 340 | 338 | ||
| 341 | 339 | ||
| @@ -23,7 +23,11 @@ def create_build_path(build_directory): | |||
| 23 | 23 | ||
| 24 | 24 | ||
| 25 | def build_stub(base_dir): | 25 | def build_stub(base_dir): |
| 26 | - build_stub_cmd = ["sh", os.path.join(base_dir, "third_party/acl/libs/build_stub.sh")] | 26 | + build_stub_cmd = [ |
| 27 | + "sh", | ||
| 28 | + os.path.join(base_dir, "third_party/acl/libs/build_stub.sh"), | ||
| 29 | + os.path.join(PYTORCH_NPU_INSTALL_PATH, "include"), | ||
| 30 | + ] | ||
| 27 | if subprocess.call(build_stub_cmd) != 0: | 31 | if subprocess.call(build_stub_cmd) != 0: |
| 28 | raise RuntimeError(f"Failed to build stub: {build_stub_cmd}") | 32 | raise RuntimeError(f"Failed to build stub: {build_stub_cmd}") |
| 29 | 33 | ||
| @@ -41,10 +45,7 @@ class TestAllocatorTraceTracker(TestCase): | |||
| 41 | 45 | ||
| 42 | cann_lib_path = os.path.join(REPO_ROOT, "third_party", "acl", "libs") | 46 | cann_lib_path = os.path.join(REPO_ROOT, "third_party", "acl", "libs") |
| 43 | torch_npu_lib_path = os.path.join(PYTORCH_NPU_INSTALL_PATH, "lib") | 47 | torch_npu_lib_path = os.path.join(PYTORCH_NPU_INSTALL_PATH, "lib") |
| 44 | - extra_include_paths = [ | 48 | + extra_include_paths = [os.path.join(PYTORCH_NPU_INSTALL_PATH, "include")] |
| 45 | - os.path.join(PYTORCH_NPU_INSTALL_PATH, "include"), | ||
| 46 | - os.path.join(PYTORCH_NPU_INSTALL_PATH, "include", "third_party", "acl", "inc"), | ||
| 47 | - ] | ||
| 48 | extra_ldflags = [ | 49 | extra_ldflags = [ |
| 49 | f"-L{cann_lib_path}", | 50 | f"-L{cann_lib_path}", |
| 50 | "-lascendcl", | 51 | "-lascendcl", |
| @@ -22,7 +22,11 @@ def create_build_path(build_directory): | |||
| 22 | 22 | ||
| 23 | 23 | ||
| 24 | def build_stub(base_dir): | 24 | def build_stub(base_dir): |
| 25 | - build_stub_cmd = ["sh", os.path.join(base_dir, 'third_party/acl/libs/build_stub.sh')] | 25 | + build_stub_cmd = [ |
| 26 | + "sh", | ||
| 27 | + os.path.join(base_dir, 'third_party/acl/libs/build_stub.sh'), | ||
| 28 | + os.path.join(PYTORCH_NPU_INSTALL_PATH, 'include'), | ||
| 29 | + ] | ||
| 26 | if subprocess.call(build_stub_cmd) != 0: | 30 | if subprocess.call(build_stub_cmd) != 0: |
| 27 | raise RuntimeError('Failed to build stub: {}'.format(build_stub_cmd)) | 31 | raise RuntimeError('Failed to build stub: {}'.format(build_stub_cmd)) |
| 28 | 32 | ||
| @@ -69,7 +73,6 @@ def get_pluggable_allocator(): | |||
| 69 | extra_ldflags.append(f"-L{PYTORCH_INSTALL_PATH}") | 73 | extra_ldflags.append(f"-L{PYTORCH_INSTALL_PATH}") |
| 70 | extra_include_paths = [os.path.join(TEST_DIR, "cpp_extensions")] | 74 | extra_include_paths = [os.path.join(TEST_DIR, "cpp_extensions")] |
| 71 | extra_include_paths.append(os.path.join(PYTORCH_NPU_INSTALL_PATH, 'include')) | 75 | extra_include_paths.append(os.path.join(PYTORCH_NPU_INSTALL_PATH, 'include')) |
| 72 | - extra_include_paths.append(os.path.join(PYTORCH_NPU_INSTALL_PATH, 'include', 'third_party', 'acl', 'inc')) | ||
| 73 | module = torch.utils.cpp_extension.load( | 76 | module = torch.utils.cpp_extension.load( |
| 74 | name="pluggable_allocator_extensions", | 77 | name="pluggable_allocator_extensions", |
| 75 | sources=[ | 78 | sources=[ |
| @@ -41,6 +41,7 @@ def build_stub(base_dir): | |||
| 41 | build_stub_cmd = [ | 41 | build_stub_cmd = [ |
| 42 | "sh", | 42 | "sh", |
| 43 | os.path.join(base_dir, "third_party/acl/libs/build_stub.sh"), | 43 | os.path.join(base_dir, "third_party/acl/libs/build_stub.sh"), |
| 44 | + os.path.join(PYTORCH_NPU_INSTALL_PATH, "include"), | ||
| 44 | ] | 45 | ] |
| 45 | if subprocess.call(build_stub_cmd) != 0: | 46 | if subprocess.call(build_stub_cmd) != 0: |
| 46 | raise RuntimeError(f"Failed to build stub: {build_stub_cmd}") | 47 | raise RuntimeError(f"Failed to build stub: {build_stub_cmd}") |
| @@ -79,7 +80,6 @@ class TestSanitizerPluggableAllocator(TestCase): | |||
| 79 | extra_ldflags.append(f"-L{PYTORCH_INSTALL_PATH}") | 80 | extra_ldflags.append(f"-L{PYTORCH_INSTALL_PATH}") |
| 80 | extra_include_paths = [os.path.join(TEST_DIR, "cpp_extensions")] | 81 | extra_include_paths = [os.path.join(TEST_DIR, "cpp_extensions")] |
| 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")) |
| 82 | - extra_include_paths.append(os.path.join(PYTORCH_NPU_INSTALL_PATH, 'include', 'third_party', 'acl', 'inc')) | ||
| 83 | 83 | ||
| 84 | cls.module = torch.utils.cpp_extension.load( | 84 | cls.module = torch.utils.cpp_extension.load( |
| 85 | name="sanitizer_pluggable_allocator_extensions", | 85 | name="sanitizer_pluggable_allocator_extensions", |
| @@ -9,6 +9,8 @@ from torch_npu.testing.common_utils import create_common_tensor, check_operators | |||
| 9 | 9 | ||
| 10 | os.environ["COMBINED_ENABLE"] = "1" # Open combined-view cases optimization | 10 | os.environ["COMBINED_ENABLE"] = "1" # Open combined-view cases optimization |
| 11 | 11 | ||
| 12 | +SKIP_REASON = "Temporarily skipped; see https://gitcode.com/Ascend/pytorch/issues/4356" | ||
| 13 | + | ||
| 12 | # Optimized view Ops contains Transpose, permute, narrow, strideslice, select, unfold | 14 | # Optimized view Ops contains Transpose, permute, narrow, strideslice, select, unfold |
| 13 | 15 | ||
| 14 | # The test case is a continuous optimization test case for aclop | 16 | # The test case is a continuous optimization test case for aclop |
| @@ -19,6 +21,7 @@ os.environ["COMBINED_ENABLE"] = "1" # Open combined-view cases optimization | |||
| 19 | 21 | ||
| 20 | 22 | ||
| 21 | class SingleViewCopyToContiguous(TestCase): | 23 | class SingleViewCopyToContiguous(TestCase): |
| 24 | + | ||
| 22 | def test_view_copy(self, device="npu"): | 25 | def test_view_copy(self, device="npu"): |
| 23 | dtype_list1 = [np.float16, np.float32] | 26 | dtype_list1 = [np.float16, np.float32] |
| 24 | format_list1 = [0, 3, 29] | 27 | format_list1 = [0, 3, 29] |
| @@ -66,6 +69,7 @@ class SingleViewCopyToContiguous(TestCase): | |||
| 66 | cpu_out2 = cpu_input.view(1, 6, cpu_input.size(2) * cpu_input.size(3), 1).clone() | 69 | cpu_out2 = cpu_input.view(1, 6, cpu_input.size(2) * cpu_input.size(3), 1).clone() |
| 67 | self.assertRtolEqual(npu_out2.to("cpu").numpy(), cpu_out2.numpy()) | 70 | self.assertRtolEqual(npu_out2.to("cpu").numpy(), cpu_out2.numpy()) |
| 68 | 71 | ||
| 72 | + | ||
| 69 | def test_unsqueeze_copy(self, device="npu"): | 73 | def test_unsqueeze_copy(self, device="npu"): |
| 70 | dtype_list2 = [np.float16, np.float32] | 74 | dtype_list2 = [np.float16, np.float32] |
| 71 | format_list2 = [2, 3, 29] | 75 | format_list2 = [2, 3, 29] |
| @@ -89,15 +93,16 @@ class SingleViewCopyToContiguous(TestCase): | |||
| 89 | npu_out = npu_input.unsqueeze(i).clone() | 93 | npu_out = npu_input.unsqueeze(i).clone() |
| 90 | if match_case1 or match_case2: | 94 | if match_case1 or match_case2: |
| 91 | self.assertEqual(check_operators_in_prof(['contiguous_d_Reshape'], prof) or | 95 | self.assertEqual(check_operators_in_prof(['contiguous_d_Reshape'], prof) or |
| 92 | - check_operators_in_prof(['aclnnInplaceCopy'], prof), | 96 | + check_operators_in_prof(['aclnnInplaceCopy'], prof), |
| 93 | True, message="contiguous_d_Reshape or aclnnInplaceCopy is not called!") | 97 | True, message="contiguous_d_Reshape or aclnnInplaceCopy is not called!") |
| 94 | else: | 98 | else: |
| 95 | self.assertEqual(check_operators_in_prof(['d2dCopyAsync'], prof) or | 99 | self.assertEqual(check_operators_in_prof(['d2dCopyAsync'], prof) or |
| 96 | - check_operators_in_prof(['aclnnInplaceCopy'], prof), | 100 | + check_operators_in_prof(['aclnnInplaceCopy'], prof), |
| 97 | True, message="d2dCopyAsync or aclnnInplaceCopy is not called!") | 101 | True, message="d2dCopyAsync or aclnnInplaceCopy is not called!") |
| 98 | cpu_out = cpu_input.unsqueeze(i).clone() | 102 | cpu_out = cpu_input.unsqueeze(i).clone() |
| 99 | self.assertRtolEqual(npu_out.to("cpu").numpy(), cpu_out.numpy()) | 103 | self.assertRtolEqual(npu_out.to("cpu").numpy(), cpu_out.numpy()) |
| 100 | 104 | ||
| 105 | + | ||
| 101 | def test_flatten_copy(self, device="npu"): | 106 | def test_flatten_copy(self, device="npu"): |
| 102 | dtype_list3 = [np.float16, np.float32] | 107 | dtype_list3 = [np.float16, np.float32] |
| 103 | format_list3 = [0, 3, 29] | 108 | format_list3 = [0, 3, 29] |
| @@ -127,6 +132,7 @@ class SingleViewCopyToContiguous(TestCase): | |||
| 127 | cpu_out = torch.flatten(cpu_input, 0, 1).clone() | 132 | cpu_out = torch.flatten(cpu_input, 0, 1).clone() |
| 128 | self.assertRtolEqual(npu_out.to("cpu").numpy(), cpu_out.numpy()) | 133 | self.assertRtolEqual(npu_out.to("cpu").numpy(), cpu_out.numpy()) |
| 129 | 134 | ||
| 135 | + | ||
| 130 | def test_narrow_at_first_axis_copy(self, device="npu"): | 136 | def test_narrow_at_first_axis_copy(self, device="npu"): |
| 131 | # this case: slice at the first dim, tensor with offset remains contiguous | 137 | # this case: slice at the first dim, tensor with offset remains contiguous |
| 132 | dtype_list4 = [np.float16, np.float32] | 138 | dtype_list4 = [np.float16, np.float32] |
| @@ -1,20 +1,23 @@ | |||
| 1 | #!/bin/bash | 1 | #!/bin/bash |
| 2 | 2 | ||
| 3 | +set -e | ||
| 4 | + | ||
| 3 | CDIR="$(cd "$(dirname "$0")" ; pwd -P)" | 5 | CDIR="$(cd "$(dirname "$0")" ; pwd -P)" |
| 4 | 6 | ||
| 5 | cd ${CDIR} | 7 | cd ${CDIR} |
| 6 | 8 | ||
| 7 | gcc -fPIC -shared -o libhccl.so -I./ hccl.cpp | 9 | gcc -fPIC -shared -o libhccl.so -I./ hccl.cpp |
| 8 | 10 | ||
| 9 | -gcc -fPIC -shared -o libascendcl.so -I../inc acl.cpp | 11 | +ACL_INCLUDE_DIR="${1:-../inc}" |
| 10 | 12 | ||
| 11 | -gcc -fPIC -shared -o libacl_op_compiler.so -I../inc acl_op_compiler.cpp | 13 | +gcc -fPIC -shared -o libascendcl.so -I"${ACL_INCLUDE_DIR}" acl.cpp |
| 12 | 14 | ||
| 13 | -gcc -fPIC -shared -o libge_runner.so -I../inc ge_runner.cpp ge_api.cpp | 15 | +gcc -fPIC -shared -o libacl_op_compiler.so -I"${ACL_INCLUDE_DIR}" acl_op_compiler.cpp |
| 14 | 16 | ||
| 15 | -gcc -fPIC -shared -o libgraph.so -I../inc graph.cpp operator_factory.cpp operator.cpp tensor.cpp | 17 | +gcc -fPIC -shared -o libge_runner.so -I"${ACL_INCLUDE_DIR}" ge_runner.cpp ge_api.cpp |
| 16 | 18 | ||
| 17 | -gcc -fPIC -shared -o libacl_tdt_channel.so -I../inc acl_tdt.cpp | 19 | +gcc -fPIC -shared -o libgraph.so -I"${ACL_INCLUDE_DIR}" graph.cpp operator_factory.cpp operator.cpp tensor.cpp |
| 18 | 20 | ||
| 19 | -gcc -fPIC -shared -o libascend_ml.so -I../inc aml_fwk_detect.cpp | 21 | +gcc -fPIC -shared -o libacl_tdt_channel.so -I"${ACL_INCLUDE_DIR}" acl_tdt.cpp |
| 20 | 22 | ||
| 23 | +gcc -fPIC -shared -o libascend_ml.so -I"${ACL_INCLUDE_DIR}" aml_fwk_detect.cpp | ||
| @@ -12,7 +12,7 @@ | |||
| 12 | 12 | ||
| 13 | 13 | ||
| 14 | 14 | ||
| 15 | -#include "third_party/acl/inc/acl/acl.h" | 15 | +#include <acl/acl.h> |
| 16 | 16 | ||
| 17 | 17 | ||
| 18 | extern "C" { | 18 | extern "C" { |
| @@ -85,13 +85,11 @@ def _build_npu_ext(obj_name: str, src_path, src_dir) -> str: | |||
| 85 | 85 | ||
| 86 | torch_npu_dir = torch_npu_root / "include" | 86 | torch_npu_dir = torch_npu_root / "include" |
| 87 | torch_npu_lib_dir = torch_npu_root / "lib" | 87 | torch_npu_lib_dir = torch_npu_root / "lib" |
| 88 | - acl_inc_dir = torch_npu_dir / "third_party" / "acl" / "inc" | ||
| 89 | 88 | ||
| 90 | cc_cmd += [ | 89 | cc_cmd += [ |
| 91 | f"-I{torch_npu_dir}", | 90 | f"-I{torch_npu_dir}", |
| 92 | f"-I{cpp_common_dir}", | 91 | f"-I{cpp_common_dir}", |
| 93 | f"-L{torch_npu_lib_dir}", | 92 | f"-L{torch_npu_lib_dir}", |
| 94 | - f"-I{acl_inc_dir}", | ||
| 95 | "-ltorch_npu", | 93 | "-ltorch_npu", |
| 96 | "-Wl,-rpath", | 94 | "-Wl,-rpath", |
| 97 | "-std=c++17", | 95 | "-std=c++17", |
| @@ -43,7 +43,7 @@ def include_paths(npu: bool = False) -> List[str]: | |||
| 43 | os.path.join(lib_include, 'TH'), | 43 | os.path.join(lib_include, 'TH'), |
| 44 | os.path.join(lib_include, 'THC') | 44 | os.path.join(lib_include, 'THC') |
| 45 | ] | 45 | ] |
| 46 | - include_path = os.path.join(PYTORCH_NPU_INSTALL_PATH, "include", "third_party", "acl", "inc") | 46 | + include_path = os.path.join(PYTORCH_NPU_INSTALL_PATH, "include") |
| 47 | paths.extend([include_path]) | 47 | paths.extend([include_path]) |
| 48 | if npu: | 48 | if npu: |
| 49 | ASCEND_HOME = get_ascend_home() | 49 | ASCEND_HOME = get_ascend_home() |
| @@ -55,7 +55,6 @@ def include_paths(npu: bool = False) -> List[str]: | |||
| 55 | os.path.join(ASCEND_HOME, "include/experiment/msprof"), | 55 | os.path.join(ASCEND_HOME, "include/experiment/msprof"), |
| 56 | ]) | 56 | ]) |
| 57 | 57 | ||
| 58 | - paths.append(os.path.join(PYTORCH_NPU_INSTALL_PATH, "include")) | ||
| 59 | return paths | 58 | return paths |
| 60 | 59 | ||
| 61 | 60 | ||
| @@ -8,7 +8,7 @@ | |||
| 8 | 8 | ||
| 9 | 9 | ||
| 10 | 10 | ||
| 11 | -#include "third_party/acl/inc/acl/acl.h" | 11 | +#include <acl/acl.h> |
| 12 | 12 | ||
| 13 | namespace at_npu { | 13 | namespace at_npu { |
| 14 | namespace native { | 14 | namespace native { |
| @@ -3,7 +3,7 @@ | |||
| 3 | 3 | ||
| 4 | 4 | ||
| 5 | 5 | ||
| 6 | -#include "third_party/acl/inc/acl/acl_base.h" | 6 | +#include <acl/acl_base.h> |
| 7 | 7 | ||
| 8 | namespace at_npu { | 8 | namespace at_npu { |
| 9 | namespace native { | 9 | namespace native { |
| @@ -2,8 +2,8 @@ | |||
| 2 | 2 | ||
| 3 | 3 | ||
| 4 | 4 | ||
| 5 | -#include "third_party/acl/inc/acl/acl_base.h" | 5 | +#include <acl/acl_base.h> |
| 6 | -#include "third_party/acl/inc/acl/acl_rt.h" | 6 | +#include <acl/acl_rt.h> |
| 7 | 7 | ||
| 8 | 8 | ||
| 9 | 9 | ||
| @@ -13,8 +13,7 @@ namespace native { | |||
| 13 | 13 | ||
| 14 | c10::Scalar NPUNativeFunctions::_local_scalar_dense(const at::Tensor& self) { | 14 | c10::Scalar NPUNativeFunctions::_local_scalar_dense(const at::Tensor& self) { |
| 15 | c10::Scalar r; | 15 | c10::Scalar r; |
| 16 | - TORCH_CHECK( | 16 | + TORCH_CHECK(self.numel() > 0, "_local_scalar_dense(): Empty tensor not supported"); |
| 17 | - self.numel() > 0, "_local_scalar_dense(): Empty tensor not supported"); | ||
| 18 | AT_DISPATCH_V2( | 17 | AT_DISPATCH_V2( |
| 19 | self.scalar_type(), | 18 | self.scalar_type(), |
| 20 | "_local_scalar_dense_npu", | 19 | "_local_scalar_dense_npu", |
| @@ -22,15 +21,12 @@ c10::Scalar NPUNativeFunctions::_local_scalar_dense(const at::Tensor& self) { | |||
| 22 | scalar_t value = 0; | 21 | scalar_t value = 0; |
| 23 | c10_npu::NPUStream copy_stream = c10_npu::getCurrentNPUStream(); | 22 | c10_npu::NPUStream copy_stream = c10_npu::getCurrentNPUStream(); |
| 24 | // Synchronous copy after stream synchronization | 23 | // Synchronous copy after stream synchronization |
| 25 | - NPU_CHECK_ERROR( | 24 | + NPU_CHECK_ERROR(c10_npu::acl::AclrtSynchronizeStreamWithTimeout(copy_stream)); |
| 26 | - c10_npu::acl::AclrtSynchronizeStreamWithTimeout(copy_stream)); | ||
| 27 | 25 | ||
| 28 | NPU_CHECK_ERROR(CalcuOpUtil::AclrtMemcpyWithModeSwitch( | 26 | NPU_CHECK_ERROR(CalcuOpUtil::AclrtMemcpyWithModeSwitch( |
| 29 | &value, | 27 | &value, |
| 30 | sizeof(scalar_t), | 28 | sizeof(scalar_t), |
| 31 | - std::make_pair( | 29 | + std::make_pair(self.storage().unsafeGetStorageImpl(), self.storage_offset() * self.itemsize()), |
| 32 | - self.storage().unsafeGetStorageImpl(), | ||
| 33 | - self.storage_offset() * self.itemsize()), | ||
| 34 | sizeof(scalar_t), | 30 | sizeof(scalar_t), |
| 35 | ACL_MEMCPY_DEVICE_TO_HOST)); | 31 | ACL_MEMCPY_DEVICE_TO_HOST)); |
| 36 | r = c10::Scalar(value); | 32 | r = c10::Scalar(value); |
| @@ -22,7 +22,7 @@ | |||
| 22 | 22 | ||
| 23 | 23 | ||
| 24 | 24 | ||
| 25 | -#include "third_party/acl/inc/acl/acl_base.h" | 25 | +#include <acl/acl_base.h> |
| 26 | 26 | ||
| 27 | 27 | ||
| 28 | namespace { | 28 | namespace { |
| @@ -3,7 +3,7 @@ | |||
| 3 | 3 | ||
| 4 | 4 | ||
| 5 | 5 | ||
| 6 | -#include "third_party/acl/inc/acl/acl_base.h" | 6 | +#include <acl/acl_base.h> |
| 7 | 7 | ||
| 8 | 8 | ||
| 9 | namespace torch_npu { | 9 | namespace torch_npu { |
| @@ -8,8 +8,8 @@ | |||
| 8 | 8 | ||
| 9 | 9 | ||
| 10 | 10 | ||
| 11 | -#include "third_party/acl/inc/acl/acl_rt.h" | 11 | +#include <acl/acl_rt.h> |
| 12 | -#include "third_party/acl/inc/acl/acl_base.h" | 12 | +#include <acl/acl_base.h> |
| 13 | 13 | ||
| 14 | namespace torch_npu { | 14 | namespace torch_npu { |
| 15 | 15 | ||
| @@ -5,7 +5,7 @@ | |||
| 5 | 5 | ||
| 6 | 6 | ||
| 7 | 7 | ||
| 8 | -#include "third_party/acl/inc/acl/acl_rt.h" | 8 | +#include <acl/acl_rt.h> |
| 9 | 9 | ||
| 10 | 10 | ||
| 11 | namespace torch_npu { | 11 | namespace torch_npu { |
| @@ -6,8 +6,8 @@ | |||
| 6 | 6 | ||
| 7 | 7 | ||
| 8 | 8 | ||
| 9 | -#include <third_party/acl/inc/acl/acl.h> | 9 | +#include <acl/acl.h> |
| 10 | -#include <third_party/acl/inc/acl/acl_rt.h> | 10 | +#include <acl/acl_rt.h> |
| 11 | 11 | ||
| 12 | 12 | ||
| 13 | 13 | ||
| @@ -9,7 +9,7 @@ | |||
| 9 | 9 | ||
| 10 | 10 | ||
| 11 | 11 | ||
| 12 | -#include "third_party/acl/inc/acl/acl.h" | 12 | +#include <acl/acl.h> |
| 13 | 13 | ||
| 14 | constexpr size_t kVersionIndex1 = 1; | 14 | constexpr size_t kVersionIndex1 = 1; |
| 15 | constexpr size_t kVersionIndex2 = 2; | 15 | constexpr size_t kVersionIndex2 = 2; |
| @@ -9,7 +9,7 @@ | |||
| 9 | 9 | ||
| 10 | 10 | ||
| 11 | 11 | ||
| 12 | -#include "third_party/acl/inc/acl/acl_base.h" | 12 | +#include <acl/acl_base.h> |
| 13 | 13 | ||
| 14 | 14 | ||
| 15 | 15 | ||
| @@ -18,8 +18,8 @@ | |||
| 18 | 18 | ||
| 19 | 19 | ||
| 20 | 20 | ||
| 21 | -#include "third_party/acl/inc/acl/acl_base.h" | 21 | +#include <acl/acl_base.h> |
| 22 | -#include "third_party/acl/inc/acl/acl_rt.h" | 22 | +#include <acl/acl_rt.h> |
| 23 | 23 | ||
| 24 | 24 | ||
| 25 | 25 | ||
| @@ -4,7 +4,7 @@ | |||
| 4 | 4 | ||
| 5 | 5 | ||
| 6 | 6 | ||
| 7 | -#include "third_party/acl/inc/acl/acl.h" | 7 | +#include <acl/acl.h> |
| 8 | 8 | ||
| 9 | 9 | ||
| 10 | 10 | ||
| @@ -5,7 +5,7 @@ | |||
| 5 | 5 | ||
| 6 | 6 | ||
| 7 | 7 | ||
| 8 | -#include <third_party/acl/inc/acl/acl.h> | 8 | +#include <acl/acl.h> |
| 9 | 9 | ||
| 10 | 10 | ||
| 11 | 11 | ||
| @@ -15,7 +15,7 @@ | |||
| 15 | 15 | ||
| 16 | 16 | ||
| 17 | 17 | ||
| 18 | -#include <third_party/acl/inc/acl/acl_base.h> | 18 | +#include <acl/acl_base.h> |
| 19 | 19 | ||
| 20 | 20 | ||
| 21 | 21 | ||
| @@ -11,7 +11,7 @@ | |||
| 11 | 11 | ||
| 12 | 12 | ||
| 13 | 13 | ||
| 14 | -#include "third_party/acl/inc/acl/acl_rt.h" | 14 | +#include <acl/acl_rt.h> |
| 15 | 15 | ||
| 16 | 16 | ||
| 17 | 17 | ||
| @@ -44,9 +44,7 @@ struct DeterministicLevel3VersionCheck { | |||
| 44 | std::vector<DeterministicVersionFailure> failures; | 44 | std::vector<DeterministicVersionFailure> failures; |
| 45 | }; | 45 | }; |
| 46 | 46 | ||
| 47 | -bool IsModuleVersionGt( | 47 | +bool IsModuleVersionGt(const std::string& module, const std::string& required_version) { |
| 48 | - const std::string& module, | ||
| 49 | - const std::string& required_version) { | ||
| 50 | return IsGteCANNVersion(required_version, module); | 48 | return IsGteCANNVersion(required_version, module); |
| 51 | } | 49 | } |
| 52 | 50 | ||
| @@ -73,8 +71,7 @@ bool CheckVersionGroup( | |||
| 73 | DeterministicLevel3VersionCheck CheckDeterministicLevel3Version() { | 71 | DeterministicLevel3VersionCheck CheckDeterministicLevel3Version() { |
| 74 | DeterministicLevel3VersionCheck check; | 72 | DeterministicLevel3VersionCheck check; |
| 75 | std::vector<DeterministicVersionFailure> runtime_failures; | 73 | std::vector<DeterministicVersionFailure> runtime_failures; |
| 76 | - const bool runtime_supported = CheckVersionGroup( | 74 | + const bool runtime_supported = CheckVersionGroup({{"RUNTIME", kLevel3MinRuntimeVersion}}, runtime_failures); |
| 77 | - {{"RUNTIME", kLevel3MinRuntimeVersion}}, runtime_failures); | ||
| 78 | 75 | ||
| 79 | std::vector<DeterministicVersionFailure> legacy_pkg_failures; | 76 | std::vector<DeterministicVersionFailure> legacy_pkg_failures; |
| 80 | const bool legacy_pkg_supported = CheckVersionGroup( | 77 | const bool legacy_pkg_supported = CheckVersionGroup( |
| @@ -95,30 +92,21 @@ DeterministicLevel3VersionCheck CheckDeterministicLevel3Version() { | |||
| 95 | }, | 92 | }, |
| 96 | split_pkg_failures); | 93 | split_pkg_failures); |
| 97 | 94 | ||
| 98 | - check.supported = | 95 | + check.supported = runtime_supported && (legacy_pkg_supported || split_pkg_supported); |
| 99 | - runtime_supported && (legacy_pkg_supported || split_pkg_supported); | ||
| 100 | if (check.supported) { | 96 | if (check.supported) { |
| 101 | return check; | 97 | return check; |
| 102 | } | 98 | } |
| 103 | 99 | ||
| 104 | - check.failures.insert( | 100 | + check.failures.insert(check.failures.end(), runtime_failures.begin(), runtime_failures.end()); |
| 105 | - check.failures.end(), runtime_failures.begin(), runtime_failures.end()); | ||
| 106 | if (!legacy_pkg_supported && !split_pkg_supported) { | 101 | if (!legacy_pkg_supported && !split_pkg_supported) { |
| 107 | - check.failures.insert( | 102 | + check.failures.insert(check.failures.end(), legacy_pkg_failures.begin(), legacy_pkg_failures.end()); |
| 108 | - check.failures.end(), | 103 | + check.failures.insert(check.failures.end(), split_pkg_failures.begin(), split_pkg_failures.end()); |
| 109 | - legacy_pkg_failures.begin(), | ||
| 110 | - legacy_pkg_failures.end()); | ||
| 111 | - check.failures.insert( | ||
| 112 | - check.failures.end(), | ||
| 113 | - split_pkg_failures.begin(), | ||
| 114 | - split_pkg_failures.end()); | ||
| 115 | } | 104 | } |
| 116 | return check; | 105 | return check; |
| 117 | } | 106 | } |
| 118 | 107 | ||
| 119 | const DeterministicLevel3VersionCheck& GetDeterministicLevel3VersionCheck() { | 108 | const DeterministicLevel3VersionCheck& GetDeterministicLevel3VersionCheck() { |
| 120 | - static const DeterministicLevel3VersionCheck check = | 109 | + static const DeterministicLevel3VersionCheck check = CheckDeterministicLevel3Version(); |
| 121 | - CheckDeterministicLevel3Version(); | ||
| 122 | return check; | 110 | return check; |
| 123 | } | 111 | } |
| 124 | 112 | ||
| @@ -130,10 +118,9 @@ void ThrowLevel3UnsupportedError() { | |||
| 130 | if (!check.failures.empty()) { | 118 | if (!check.failures.empty()) { |
| 131 | oss << " Unsatisfied versions:"; | 119 | oss << " Unsatisfied versions:"; |
| 132 | for (const auto& failure : check.failures) { | 120 | for (const auto& failure : check.failures) { |
| 133 | - oss << " " << failure.module << "(current=" | 121 | + oss << " " << failure.module |
| 134 | - << (failure.current_version.empty() ? "unavailable" | 122 | + << "(current=" << (failure.current_version.empty() ? "unavailable" : failure.current_version) << ", required>" |
| 135 | - : failure.current_version) | 123 | + << failure.required_version << ");"; |
| 136 | - << ", required>" << failure.required_version << ");"; | ||
| 137 | } | 124 | } |
| 138 | } | 125 | } |
| 139 | TORCH_CHECK(false, oss.str(), PTA_ERROR(ErrCode::VALUE)); | 126 | TORCH_CHECK(false, oss.str(), PTA_ERROR(ErrCode::VALUE)); |
| @@ -179,8 +166,7 @@ bool hasPrimaryContext(c10::DeviceIndex device_index) { | |||
| 179 | device_index, | 166 | device_index, |
| 180 | PTA_ERROR(ErrCode::VALUE)); | 167 | PTA_ERROR(ErrCode::VALUE)); |
| 181 | int32_t ctx_is_active = 0; | 168 | int32_t ctx_is_active = 0; |
| 182 | - NPU_CHECK_ERROR_WITHOUT_UCE( | 169 | + NPU_CHECK_ERROR_WITHOUT_UCE(acl::AclrtGetPrimaryCtxState(device_index, nullptr, &ctx_is_active)); |
| 183 | - acl::AclrtGetPrimaryCtxState(device_index, nullptr, &ctx_is_active)); | ||
| 184 | return ctx_is_active == 1; | 170 | return ctx_is_active == 1; |
| 185 | } | 171 | } |
| 186 | 172 | ||
| @@ -248,8 +234,7 @@ aclError GetDeviceWithoutSet(int32_t* device) { | |||
| 248 | } | 234 | } |
| 249 | 235 | ||
| 250 | aclError SetDevice(c10::DeviceIndex device) { | 236 | aclError SetDevice(c10::DeviceIndex device) { |
| 251 | - TORCH_CHECK( | 237 | + TORCH_CHECK(device >= 0, "device id must be positive!", PTA_ERROR(ErrCode::VALUE)); |
| 252 | - device >= 0, "device id must be positive!", PTA_ERROR(ErrCode::VALUE)); | ||
| 253 | targetDeviceIndex = -1; | 238 | targetDeviceIndex = -1; |
| 254 | if (local_device == device) { | 239 | if (local_device == device) { |
| 255 | return ACL_ERROR_NONE; | 240 | return ACL_ERROR_NONE; |
| @@ -264,8 +249,7 @@ aclError SetDevice(c10::DeviceIndex device) { | |||
| 264 | local_device = device; | 249 | local_device = device; |
| 265 | std::lock_guard<std::recursive_mutex> lock(mtx); | 250 | std::lock_guard<std::recursive_mutex> lock(mtx); |
| 266 | if (used_devices.find(local_device) == used_devices.end()) { | 251 | if (used_devices.find(local_device) == used_devices.end()) { |
| 267 | - NPU_CHECK_ERROR_WITHOUT_UCE( | 252 | + NPU_CHECK_ERROR_WITHOUT_UCE(aclrtGetCurrentContext(&used_devices[local_device])); |
| 268 | - aclrtGetCurrentContext(&used_devices[local_device])); | ||
| 269 | } | 253 | } |
| 270 | } | 254 | } |
| 271 | return err; | 255 | return err; |
| @@ -275,9 +259,7 @@ aclError MaybeSetDevice(c10::DeviceIndex device) { | |||
| 275 | if (isDeviceCtxActive(device)) { | 259 | if (isDeviceCtxActive(device)) { |
| 276 | NPU_CHECK_ERROR_WITHOUT_UCE(SetDevice(device)); | 260 | NPU_CHECK_ERROR_WITHOUT_UCE(SetDevice(device)); |
| 277 | } else { | 261 | } else { |
| 278 | - ASCEND_LOGI( | 262 | + ASCEND_LOGI("MaybeSetDevice: NPU device %d has not been initialized! We will set targetDeviceIndex.", device); |
| 279 | - "MaybeSetDevice: NPU device %d has not been initialized! We will set targetDeviceIndex.", | ||
| 280 | - device); | ||
| 281 | targetDeviceIndex = device; | 263 | targetDeviceIndex = device; |
| 282 | } | 264 | } |
| 283 | return ACL_ERROR_NONE; | 265 | return ACL_ERROR_NONE; |
| @@ -334,8 +316,7 @@ aclError SynchronizeUsedDevices() { | |||
| 334 | return acl_ret; | 316 | return acl_ret; |
| 335 | } | 317 | } |
| 336 | 318 | ||
| 337 | - const c10_npu::impl::PyCallbackTrigger* trigger = | 319 | + const c10_npu::impl::PyCallbackTrigger* trigger = c10_npu::impl::NPUTrace::getTrace(); |
| 338 | - c10_npu::impl::NPUTrace::getTrace(); | ||
| 339 | if (C10_UNLIKELY(trigger)) { | 320 | if (C10_UNLIKELY(trigger)) { |
| 340 | trigger->traceNpuDeviceSynchronization(); | 321 | trigger->traceNpuDeviceSynchronization(); |
| 341 | } | 322 | } |
| @@ -348,8 +329,7 @@ aclError SynchronizeUsedDevices() { | |||
| 348 | aclrtContext GetDeviceContext(int32_t device) { | 329 | aclrtContext GetDeviceContext(int32_t device) { |
| 349 | std::lock_guard<std::recursive_mutex> lock(mtx); | 330 | std::lock_guard<std::recursive_mutex> lock(mtx); |
| 350 | if (used_devices.find(device) == used_devices.end()) { | 331 | if (used_devices.find(device) == used_devices.end()) { |
| 351 | - ASCEND_LOGE( | 332 | + ASCEND_LOGE("NPU device %d has not been initialized! Can not get context", device); |
| 352 | - "NPU device %d has not been initialized! Can not get context", device); | ||
| 353 | return nullptr; | 333 | return nullptr; |
| 354 | } | 334 | } |
| 355 | return used_devices[device]; | 335 | return used_devices[device]; |
| @@ -396,11 +376,9 @@ void set_device(c10::DeviceIndex device) { | |||
| 396 | } | 376 | } |
| 397 | 377 | ||
| 398 | void device_synchronize() { | 378 | void device_synchronize() { |
| 399 | - NPU_CHECK_ERROR_WITHOUT_UCE( | 379 | + NPU_CHECK_ERROR_WITHOUT_UCE(c10_npu::acl::AclrtSynchronizeDeviceWithTimeout()); |
| 400 | - c10_npu::acl::AclrtSynchronizeDeviceWithTimeout()); | ||
| 401 | 380 | ||
| 402 | - const c10_npu::impl::PyCallbackTrigger* trigger = | 381 | + const c10_npu::impl::PyCallbackTrigger* trigger = c10_npu::impl::NPUTrace::getTrace(); |
| 403 | - c10_npu::impl::NPUTrace::getTrace(); | ||
| 404 | if (C10_UNLIKELY(trigger)) { | 382 | if (C10_UNLIKELY(trigger)) { |
| 405 | trigger->traceNpuDeviceSynchronization(); | 383 | trigger->traceNpuDeviceSynchronization(); |
| 406 | } | 384 | } |
| @@ -423,9 +401,7 @@ int MaybeExchangeDevice(int to_device) { | |||
| 423 | if (isDeviceCtxActive(to_device)) { | 401 | if (isDeviceCtxActive(to_device)) { |
| 424 | NPU_CHECK_ERROR_WITHOUT_UCE(SetDevice(to_device)); | 402 | NPU_CHECK_ERROR_WITHOUT_UCE(SetDevice(to_device)); |
| 425 | } else { | 403 | } else { |
| 426 | - ASCEND_LOGI( | 404 | + ASCEND_LOGI("NPU device %d has not been initialized! We will set targetDeviceIndex.", to_device); |
| 427 | - "NPU device %d has not been initialized! We will set targetDeviceIndex.", | ||
| 428 | - to_device); | ||
| 429 | targetDeviceIndex = to_device; | 405 | targetDeviceIndex = to_device; |
| 430 | } | 406 | } |
| 431 | return cur_device; | 407 | return cur_device; |
| @@ -471,8 +447,7 @@ void LazySetDevice(c10::DeviceIndex device) { | |||
| 471 | local_device = device; | 447 | local_device = device; |
| 472 | std::lock_guard<std::recursive_mutex> lock(mtx); | 448 | std::lock_guard<std::recursive_mutex> lock(mtx); |
| 473 | if (used_devices.find(local_device) == used_devices.end()) { | 449 | if (used_devices.find(local_device) == used_devices.end()) { |
| 474 | - NPU_CHECK_ERROR_WITHOUT_UCE( | 450 | + NPU_CHECK_ERROR_WITHOUT_UCE(aclrtGetCurrentContext(&used_devices[local_device])); |
| 475 | - aclrtGetCurrentContext(&used_devices[local_device])); | ||
| 476 | } | 451 | } |
| 477 | } | 452 | } |
| 478 | NPU_CHECK_ERROR_WITHOUT_UCE(err); | 453 | NPU_CHECK_ERROR_WITHOUT_UCE(err); |
| @@ -481,21 +456,18 @@ void LazySetDevice(c10::DeviceIndex device) { | |||
| 481 | 456 | ||
| 482 | void warn_or_error_on_sync() { | 457 | void warn_or_error_on_sync() { |
| 483 | if (warning_state().get_sync_debug_mode() == SyncDebugMode::L_ERROR) { | 458 | if (warning_state().get_sync_debug_mode() == SyncDebugMode::L_ERROR) { |
| 484 | - TORCH_CHECK( | 459 | + TORCH_CHECK(false, "called a synchronizing NPU operation", PTA_ERROR(ErrCode::ACL)); |
| 485 | - false, "called a synchronizing NPU operation", PTA_ERROR(ErrCode::ACL)); | ||
| 486 | } else if (warning_state().get_sync_debug_mode() == SyncDebugMode::L_WARN) { | 460 | } else if (warning_state().get_sync_debug_mode() == SyncDebugMode::L_WARN) { |
| 487 | TORCH_NPU_WARN("called a synchronizing NPU operation"); | 461 | TORCH_NPU_WARN("called a synchronizing NPU operation"); |
| 488 | } | 462 | } |
| 489 | } | 463 | } |
| 490 | 464 | ||
| 491 | void stream_synchronize(aclrtStream stream) { | 465 | void stream_synchronize(aclrtStream stream) { |
| 492 | - if (C10_UNLIKELY( | 466 | + if (C10_UNLIKELY(warning_state().get_sync_debug_mode() != SyncDebugMode::L_DISABLED)) { |
| 493 | - warning_state().get_sync_debug_mode() != SyncDebugMode::L_DISABLED)) { | ||
| 494 | warn_or_error_on_sync(); | 467 | warn_or_error_on_sync(); |
| 495 | } | 468 | } |
| 496 | 469 | ||
| 497 | - const c10_npu::impl::PyCallbackTrigger* trigger = | 470 | + const c10_npu::impl::PyCallbackTrigger* trigger = c10_npu::impl::NPUTrace::getTrace(); |
| 498 | - c10_npu::impl::NPUTrace::getTrace(); | ||
| 499 | if (C10_UNLIKELY(trigger)) { | 471 | if (C10_UNLIKELY(trigger)) { |
| 500 | trigger->traceNpuStreamSynchronization(reinterpret_cast<uintptr_t>(stream)); | 472 | trigger->traceNpuStreamSynchronization(reinterpret_cast<uintptr_t>(stream)); |
| 501 | } | 473 | } |
| @@ -506,16 +478,10 @@ void stream_synchronize(aclrtStream stream) { | |||
| 506 | aclError SetDeviceResLimit(int32_t device, int32_t type, uint32_t value) { | 478 | aclError SetDeviceResLimit(int32_t device, int32_t type, uint32_t value) { |
| 507 | std::lock_guard<std::recursive_mutex> lock(mtx); | 479 | std::lock_guard<std::recursive_mutex> lock(mtx); |
| 508 | if (used_devices.find(device) == used_devices.end()) { | 480 | if (used_devices.find(device) == used_devices.end()) { |
| 509 | - TORCH_CHECK( | 481 | + TORCH_CHECK(false, "NPU device ", device, " has not been initialized! Can not get device resource limit"); |
| 510 | - false, | ||
| 511 | - "NPU device ", | ||
| 512 | - device, | ||
| 513 | - " has not been initialized! Can not get device resource limit"); | ||
| 514 | } | 482 | } |
| 515 | - TORCH_CHECK( | 483 | + TORCH_CHECK(device >= 0, "device id must be positive!", PTA_ERROR(ErrCode::VALUE)); |
| 516 | - device >= 0, "device id must be positive!", PTA_ERROR(ErrCode::VALUE)); | 484 | + c10_npu::acl::aclrtDevResLimitType restype = static_cast<c10_npu::acl::aclrtDevResLimitType>(type); |
| 517 | - c10_npu::acl::aclrtDevResLimitType restype = | ||
| 518 | - static_cast<c10_npu::acl::aclrtDevResLimitType>(type); | ||
| 519 | aclError err = c10_npu::acl::AclrtSetDeviceResLimit(device, restype, value); | 485 | aclError err = c10_npu::acl::AclrtSetDeviceResLimit(device, restype, value); |
| 520 | NPU_CHECK_ERROR(err); | 486 | NPU_CHECK_ERROR(err); |
| 521 | return err; | 487 | return err; |
| @@ -524,43 +490,29 @@ aclError SetDeviceResLimit(int32_t device, int32_t type, uint32_t value) { | |||
| 524 | uint32_t GetDeviceResLimit(int32_t device, int32_t type) { | 490 | uint32_t GetDeviceResLimit(int32_t device, int32_t type) { |
| 525 | std::lock_guard<std::recursive_mutex> lock(mtx); | 491 | std::lock_guard<std::recursive_mutex> lock(mtx); |
| 526 | if (used_devices.find(device) == used_devices.end()) { | 492 | if (used_devices.find(device) == used_devices.end()) { |
| 527 | - TORCH_CHECK( | 493 | + TORCH_CHECK(false, "NPU device ", device, " has not been initialized! Can not get device resource limit"); |
| 528 | - false, | ||
| 529 | - "NPU device ", | ||
| 530 | - device, | ||
| 531 | - " has not been initialized! Can not get device resource limit"); | ||
| 532 | } | 494 | } |
| 533 | - TORCH_CHECK( | 495 | + TORCH_CHECK(device >= 0, "device id must be positive!", PTA_ERROR(ErrCode::VALUE)); |
| 534 | - device >= 0, "device id must be positive!", PTA_ERROR(ErrCode::VALUE)); | 496 | + c10_npu::acl::aclrtDevResLimitType restype = static_cast<c10_npu::acl::aclrtDevResLimitType>(type); |
| 535 | - c10_npu::acl::aclrtDevResLimitType restype = | ||
| 536 | - static_cast<c10_npu::acl::aclrtDevResLimitType>(type); | ||
| 537 | uint32_t value; | 497 | uint32_t value; |
| 538 | - NPU_CHECK_ERROR( | 498 | + NPU_CHECK_ERROR(c10_npu::acl::AclrtGetDeviceResLimit(device, restype, &value)); |
| 539 | - c10_npu::acl::AclrtGetDeviceResLimit(device, restype, &value)); | ||
| 540 | return value; | 499 | return value; |
| 541 | } | 500 | } |
| 542 | 501 | ||
| 543 | aclError ResetDeviceResLimit(int32_t device) { | 502 | aclError ResetDeviceResLimit(int32_t device) { |
| 544 | std::lock_guard<std::recursive_mutex> lock(mtx); | 503 | std::lock_guard<std::recursive_mutex> lock(mtx); |
| 545 | if (used_devices.find(device) == used_devices.end()) { | 504 | if (used_devices.find(device) == used_devices.end()) { |
| 546 | - TORCH_CHECK( | 505 | + TORCH_CHECK(false, "NPU device ", device, " has not been initialized! Can not reset device resource limit"); |
| 547 | - false, | ||
| 548 | - "NPU device ", | ||
| 549 | - device, | ||
| 550 | - " has not been initialized! Can not reset device resource limit"); | ||
| 551 | } | 506 | } |
| 552 | - TORCH_CHECK( | 507 | + TORCH_CHECK(device >= 0, "device id must be positive!", PTA_ERROR(ErrCode::VALUE)); |
| 553 | - device >= 0, "device id must be positive!", PTA_ERROR(ErrCode::VALUE)); | ||
| 554 | aclError err = c10_npu::acl::AclrtResetDeviceResLimit(device); | 508 | aclError err = c10_npu::acl::AclrtResetDeviceResLimit(device); |
| 555 | NPU_CHECK_ERROR(err); | 509 | NPU_CHECK_ERROR(err); |
| 556 | return err; | 510 | return err; |
| 557 | } | 511 | } |
| 558 | 512 | ||
| 559 | aclError SetStreamResLimit(NPUStream npu_stream, int32_t type, uint32_t value) { | 513 | aclError SetStreamResLimit(NPUStream npu_stream, int32_t type, uint32_t value) { |
| 560 | - c10_npu::acl::aclrtDevResLimitType restype = | 514 | + c10_npu::acl::aclrtDevResLimitType restype = static_cast<c10_npu::acl::aclrtDevResLimitType>(type); |
| 561 | - static_cast<c10_npu::acl::aclrtDevResLimitType>(type); | 515 | + aclError err = c10_npu::acl::AclrtSetStreamResLimit(npu_stream.stream(), restype, value); |
| 562 | - aclError err = | ||
| 563 | - c10_npu::acl::AclrtSetStreamResLimit(npu_stream.stream(), restype, value); | ||
| 564 | enable_core_control.store(true, std::memory_order_relaxed); | 516 | enable_core_control.store(true, std::memory_order_relaxed); |
| 565 | NPU_CHECK_ERROR(err); | 517 | NPU_CHECK_ERROR(err); |
| 566 | return err; | 518 | return err; |
| @@ -573,11 +525,9 @@ aclError ResetStreamResLimit(NPUStream npu_stream) { | |||
| 573 | } | 525 | } |
| 574 | 526 | ||
| 575 | uint32_t GetStreamResLimit(NPUStream npu_stream, int32_t type) { | 527 | uint32_t GetStreamResLimit(NPUStream npu_stream, int32_t type) { |
| 576 | - c10_npu::acl::aclrtDevResLimitType restype = | 528 | + c10_npu::acl::aclrtDevResLimitType restype = static_cast<c10_npu::acl::aclrtDevResLimitType>(type); |
| 577 | - static_cast<c10_npu::acl::aclrtDevResLimitType>(type); | ||
| 578 | uint32_t value; | 529 | uint32_t value; |
| 579 | - NPU_CHECK_ERROR(c10_npu::acl::AclrtGetStreamResLimit( | 530 | + NPU_CHECK_ERROR(c10_npu::acl::AclrtGetStreamResLimit(npu_stream.stream(false), restype, &value)); |
| 580 | - npu_stream.stream(false), restype, &value)); | ||
| 581 | return value; | 531 | return value; |
| 582 | } | 532 | } |
| 583 | 533 | ||
| @@ -594,8 +544,7 @@ aclError UnuseStreamResInCurrentThread(aclrtStream stream) { | |||
| 594 | } | 544 | } |
| 595 | 545 | ||
| 596 | uint32_t GetResInCurrentThread(int32_t type) { | 546 | uint32_t GetResInCurrentThread(int32_t type) { |
| 597 | - c10_npu::acl::aclrtDevResLimitType restype = | 547 | + c10_npu::acl::aclrtDevResLimitType restype = static_cast<c10_npu::acl::aclrtDevResLimitType>(type); |
| 598 | - static_cast<c10_npu::acl::aclrtDevResLimitType>(type); | ||
| 599 | uint32_t value; | 548 | uint32_t value; |
| 600 | NPU_CHECK_ERROR(c10_npu::acl::AclrtGetResInCurrentThread(restype, &value)); | 549 | NPU_CHECK_ERROR(c10_npu::acl::AclrtGetResInCurrentThread(restype, &value)); |
| 601 | return value; | 550 | return value; |
| @@ -620,13 +569,11 @@ uint32_t GetDeterministicLevel() { | |||
| 620 | 569 | ||
| 621 | DeterministicSnapshot CaptureDeterministicSnapshot() { | 570 | DeterministicSnapshot CaptureDeterministicSnapshot() { |
| 622 | DeterministicSnapshot snapshot; | 571 | DeterministicSnapshot snapshot; |
| 623 | - snapshot.deterministic_algorithms_enabled = | 572 | + snapshot.deterministic_algorithms_enabled = at::globalContext().deterministicAlgorithms(); |
| 624 | - at::globalContext().deterministicAlgorithms(); | ||
| 625 | snapshot.requested_level = GetDeterministicLevel(); | 573 | snapshot.requested_level = GetDeterministicLevel(); |
| 626 | snapshot.effective_level = 0; | 574 | snapshot.effective_level = 0; |
| 627 | if (snapshot.deterministic_algorithms_enabled) { | 575 | if (snapshot.deterministic_algorithms_enabled) { |
| 628 | - snapshot.effective_level = | 576 | + snapshot.effective_level = snapshot.requested_level == 0 ? 1 : snapshot.requested_level; |
| 629 | - snapshot.requested_level == 0 ? 1 : snapshot.requested_level; | ||
| 630 | } | 577 | } |
| 631 | snapshot.backend = GetDeterministicBackend(); | 578 | snapshot.backend = GetDeterministicBackend(); |
| 632 | return snapshot; | 579 | return snapshot; |
| @@ -637,8 +584,7 @@ uint32_t GetEffectiveDeterministicLevel() { | |||
| 637 | } | 584 | } |
| 638 | 585 | ||
| 639 | DeterministicBackend GetDeterministicBackend() { | 586 | DeterministicBackend GetDeterministicBackend() { |
| 640 | - return IsSupportDeterministicLevel3() ? DeterministicBackend::V2 | 587 | + return IsSupportDeterministicLevel3() ? DeterministicBackend::V2 : DeterministicBackend::Legacy; |
| 641 | - : DeterministicBackend::Legacy; | ||
| 642 | } | 588 | } |
| 643 | 589 | ||
| 644 | bool IsSupportDeterministicLevel3() { | 590 | bool IsSupportDeterministicLevel3() { |
| @@ -16,7 +16,7 @@ | |||
| 16 | 16 | ||
| 17 | 17 | ||
| 18 | 18 | ||
| 19 | -#include <third_party/acl/inc/acl/acl.h> | 19 | +#include <acl/acl.h> |
| 20 | 20 | ||
| 21 | namespace c10_npu { | 21 | namespace c10_npu { |
| 22 | 22 | ||
| @@ -7,7 +7,7 @@ | |||
| 7 | 7 | ||
| 8 | 8 | ||
| 9 | 9 | ||
| 10 | -#include "third_party/acl/inc/acl/error_codes/rt_error_codes.h" | 10 | +#include <acl/error_codes/rt_error_codes.h> |
| 11 | 11 | ||
| 12 | 12 | ||
| 13 | 13 | ||
| @@ -9,9 +9,9 @@ | |||
| 9 | 9 | ||
| 10 | 10 | ||
| 11 | 11 | ||
| 12 | -#include "third_party/acl/inc/acl/acl_base.h" | 12 | +#include <acl/acl_base.h> |
| 13 | -#include "third_party/acl/inc/acl/acl_rt.h" | 13 | +#include <acl/acl_rt.h> |
| 14 | -#include "third_party/acl/inc/acl/super_kernel.h" | 14 | +#include <acl/super_kernel.h> |
| 15 | 15 | ||
| 16 | 16 | ||
| 17 | 17 | ||
| @@ -1,7 +1,7 @@ | |||
| 1 | 1 | ||
| 2 | 2 | ||
| 3 | 3 | ||
| 4 | -#include <third_party/acl/inc/acl/acl_rt.h> | 4 | +#include <acl/acl_rt.h> |
| 5 | 5 | ||
| 6 | 6 | ||
| 7 | 7 | ||
| @@ -20,7 +20,7 @@ | |||
| 20 | 20 | ||
| 21 | 21 | ||
| 22 | 22 | ||
| 23 | -#include <third_party/acl/inc/acl/acl_rt.h> | 23 | +#include <acl/acl_rt.h> |
| 24 | 24 | ||
| 25 | namespace c10_npu { | 25 | namespace c10_npu { |
| 26 | struct timeval delay = {0, 1}; | 26 | struct timeval delay = {0, 1}; |
| @@ -7,7 +7,7 @@ | |||
| 7 | 7 | ||
| 8 | 8 | ||
| 9 | 9 | ||
| 10 | -#include <third_party/acl/inc/acl/acl_op.h> | 10 | +#include <acl/acl_op.h> |
| 11 | 11 | ||
| 12 | namespace c10_npu { | 12 | namespace c10_npu { |
| 13 | 13 | ||
| @@ -20,7 +20,7 @@ | |||
| 20 | 20 | ||
| 21 | 21 | ||
| 22 | 22 | ||
| 23 | -#include "third_party/acl/inc/acl/acl_rt.h" | 23 | +#include <acl/acl_rt.h> |
| 24 | 24 | ||
| 25 | 25 | ||
| 26 | 26 | ||
| @@ -10,8 +10,8 @@ | |||
| 10 | 10 | ||
| 11 | 11 | ||
| 12 | 12 | ||
| 13 | -#include "third_party/acl/inc/acl/acl.h" | 13 | +#include <acl/acl.h> |
| 14 | -#include "third_party/acl/inc/acl/acl_op.h" | 14 | +#include <acl/acl_op.h> |
| 15 | 15 | ||
| 16 | 16 | ||
| 17 | namespace c10_npu { | 17 | namespace c10_npu { |
| @@ -1,8 +1,8 @@ | |||
| 1 | 1 | ||
| 2 | 2 | ||
| 3 | 3 | ||
| 4 | -#include "third_party/acl/inc/acl/acl_base.h" | 4 | +#include <acl/acl_base.h> |
| 5 | -#include "third_party/acl/inc/acl/acl_rt.h" | 5 | +#include <acl/acl_rt.h> |
| 6 | 6 | ||
| 7 | 7 | ||
| 8 | 8 | ||
| @@ -4,8 +4,8 @@ | |||
| 4 | 4 | ||
| 5 | 5 | ||
| 6 | 6 | ||
| 7 | -#include "third_party/acl/inc/acl/acl_base.h" | 7 | +#include <acl/acl_base.h> |
| 8 | -#include "third_party/acl/inc/acl/acl_rt.h" | 8 | +#include <acl/acl_rt.h> |
| 9 | 9 | ||
| 10 | 10 | ||
| 11 | 11 | ||
| @@ -22,8 +22,7 @@ namespace at_npu { | |||
| 22 | namespace native { | 22 | namespace native { |
| 23 | 23 | ||
| 24 | at::Tensor allocate_workspace(uint64_t workspace_size, aclrtStream stream) { | 24 | at::Tensor allocate_workspace(uint64_t workspace_size, aclrtStream stream) { |
| 25 | - return at_npu::native::OpPreparation::unsafe_empty_workspace( | 25 | + return at_npu::native::OpPreparation::unsafe_empty_workspace(workspace_size, stream); |
| 26 | - workspace_size, stream); | ||
| 27 | } | 26 | } |
| 28 | 27 | ||
| 29 | } // namespace native | 28 | } // namespace native |
| @@ -63,8 +62,7 @@ class DeviceWorkspaceAllocator { | |||
| 63 | context_recorder_.store(nullptr); | 62 | context_recorder_.store(nullptr); |
| 64 | } | 63 | } |
| 65 | 64 | ||
| 66 | - std::shared_ptr<c10::GatheredContext> maybeGatherContext( | 65 | + std::shared_ptr<c10::GatheredContext> maybeGatherContext(RecordContext level) { |
| 67 | - RecordContext level) { | ||
| 68 | // Memory snapshots have deadlock issues in some scenarios, no longer | 66 | // Memory snapshots have deadlock issues in some scenarios, no longer |
| 69 | // capture python stacks. | 67 | // capture python stacks. |
| 70 | return nullptr; | 68 | return nullptr; |
| @@ -85,37 +83,28 @@ class DeviceWorkspaceAllocator { | |||
| 85 | WorkspaceBlock* block = blocks[stream]; | 83 | WorkspaceBlock* block = blocks[stream]; |
| 86 | if (block->size < alloc_size) { | 84 | if (block->size < alloc_size) { |
| 87 | if (block->data_ptr != nullptr) { | 85 | if (block->data_ptr != nullptr) { |
| 88 | - ASCEND_LOGI( | 86 | + ASCEND_LOGI("NPUWorkspaceAllocator free by aclrtFree: size=%zu", block->size); |
| 89 | - "NPUWorkspaceAllocator free by aclrtFree: size=%zu", block->size); | ||
| 90 | NPU_CHECK_ERROR(c10_npu::acl::AclrtSynchronizeDeviceWithTimeout()); | 87 | NPU_CHECK_ERROR(c10_npu::acl::AclrtSynchronizeDeviceWithTimeout()); |
| 91 | NPU_CHECK_ERROR(aclrtFree(block->data_ptr)); | 88 | NPU_CHECK_ERROR(aclrtFree(block->data_ptr)); |
| 92 | update_stat(stats.reserved_bytes, -block->size); | 89 | update_stat(stats.reserved_bytes, -block->size); |
| 93 | 90 | ||
| 94 | if (torch_npu::profiler::MstxMgr::GetInstance()->isMsleaksEnable()) { | 91 | if (torch_npu::profiler::MstxMgr::GetInstance()->isMsleaksEnable()) { |
| 95 | - mstxDomainHandle_t workspaceDomain = | 92 | + mstxDomainHandle_t workspaceDomain = torch_npu::profiler::MstxMgr::GetInstance()->createLeaksDomain( |
| 96 | - torch_npu::profiler::MstxMgr::GetInstance()->createLeaksDomain( | 93 | + torch_npu::profiler::DOMAIN_WORKSPACE.c_str()); |
| 97 | - torch_npu::profiler::DOMAIN_WORKSPACE.c_str()); | 94 | + mstxMemVirtualRangeDesc_t desc{device, block->data_ptr, stats.reserved_bytes.current}; |
| 98 | - mstxMemVirtualRangeDesc_t desc{ | 95 | + torch_npu::profiler::MstxMgr::GetInstance()->memHeapRegister(workspaceDomain, &desc); |
| 99 | - device, block->data_ptr, stats.reserved_bytes.current}; | ||
| 100 | - torch_npu::profiler::MstxMgr::GetInstance()->memHeapRegister( | ||
| 101 | - workspaceDomain, &desc); | ||
| 102 | } | 96 | } |
| 103 | record_mem_size_decrement(block->size); | 97 | record_mem_size_decrement(block->size); |
| 104 | - const c10_npu::impl::PyCallbackTrigger* trigger = | 98 | + const c10_npu::impl::PyCallbackTrigger* trigger = c10_npu::impl::NPUTrace::getTrace(); |
| 105 | - c10_npu::impl::NPUTrace::getTrace(); | ||
| 106 | if (C10_UNLIKELY(trigger)) { | 99 | if (C10_UNLIKELY(trigger)) { |
| 107 | - trigger->traceNpuMemoryDeallocation( | 100 | + trigger->traceNpuMemoryDeallocation(reinterpret_cast<uintptr_t>(block->data_ptr)); |
| 108 | - reinterpret_cast<uintptr_t>(block->data_ptr)); | ||
| 109 | } | 101 | } |
| 110 | torch_npu::profiler::reportMemoryDataToNpuProfiler( | 102 | torch_npu::profiler::reportMemoryDataToNpuProfiler( |
| 111 | {static_cast<int8_t>(c10::DeviceType::PrivateUse1), | 103 | {static_cast<int8_t>(c10::DeviceType::PrivateUse1), |
| 112 | device, | 104 | device, |
| 113 | - static_cast<uint8_t>( | 105 | + static_cast<uint8_t>(torch_npu::profiler::MemoryComponentType::WORKSPACE_ALLOCATOR), |
| 114 | - torch_npu::profiler::MemoryComponentType::WORKSPACE_ALLOCATOR), | 106 | + static_cast<uint8_t>(torch_npu::profiler::MemoryDataType::MEMORY_FREE), |
| 115 | - static_cast<uint8_t>( | 107 | + static_cast<uint8_t>(torch_npu::profiler::MemoryAllocatorType::ALLOCATOR_INNER), |
| 116 | - torch_npu::profiler::MemoryDataType::MEMORY_FREE), | ||
| 117 | - static_cast<uint8_t>( | ||
| 118 | - torch_npu::profiler::MemoryAllocatorType::ALLOCATOR_INNER), | ||
| 119 | reinterpret_cast<int64_t>(block->data_ptr), | 108 | reinterpret_cast<int64_t>(block->data_ptr), |
| 120 | -block->size, | 109 | -block->size, |
| 121 | stats.allocated_bytes.current, | 110 | stats.allocated_bytes.current, |
| @@ -126,8 +115,7 @@ class DeviceWorkspaceAllocator { | |||
| 126 | block->data_ptr = nullptr; | 115 | block->data_ptr = nullptr; |
| 127 | } | 116 | } |
| 128 | 117 | ||
| 129 | - block->size = | 118 | + block->size = kRoundLarge * ((alloc_size + kRoundLarge - 1) / kRoundLarge); |
| 130 | - kRoundLarge * ((alloc_size + kRoundLarge - 1) / kRoundLarge); | ||
| 131 | 119 | ||
| 132 | TORCH_CHECK( | 120 | TORCH_CHECK( |
| 133 | alloc_size <= block->size, | 121 | alloc_size <= block->size, |
| @@ -139,39 +127,29 @@ class DeviceWorkspaceAllocator { | |||
| 139 | PTA_ERROR(ErrCode::MEMORY)); | 127 | PTA_ERROR(ErrCode::MEMORY)); |
| 140 | 128 | ||
| 141 | aclError err = c10_npu::acl::AclrtMallocAlign32( | 129 | aclError err = c10_npu::acl::AclrtMallocAlign32( |
| 142 | - &block->data_ptr, | 130 | + &block->data_ptr, block->size, aclrtMemMallocPolicy::ACL_MEM_MALLOC_HUGE_ONLY); |
| 143 | - block->size, | ||
| 144 | - aclrtMemMallocPolicy::ACL_MEM_MALLOC_HUGE_ONLY); | ||
| 145 | if (err != ACL_ERROR_NONE) { | 131 | if (err != ACL_ERROR_NONE) { |
| 146 | return nullptr; | 132 | return nullptr; |
| 147 | } | 133 | } |
| 148 | block->context_when_allocated = std::move(context); | 134 | block->context_when_allocated = std::move(context); |
| 149 | block->requested_size = static_cast<int64_t>(size); | 135 | block->requested_size = static_cast<int64_t>(size); |
| 150 | 136 | ||
| 151 | - ASCEND_LOGD( | 137 | + ASCEND_LOGD("NPUWorkspaceAllocator malloc by AclrtMallocAlign32: size=%zu", block->size); |
| 152 | - "NPUWorkspaceAllocator malloc by AclrtMallocAlign32: size=%zu", | ||
| 153 | - block->size); | ||
| 154 | update_stat(stats.reserved_bytes, block->size); | 138 | update_stat(stats.reserved_bytes, block->size); |
| 155 | 139 | ||
| 156 | if (torch_npu::profiler::MstxMgr::GetInstance()->isMsleaksEnable()) { | 140 | if (torch_npu::profiler::MstxMgr::GetInstance()->isMsleaksEnable()) { |
| 157 | - mstxDomainHandle_t workspaceDomain = | 141 | + mstxDomainHandle_t workspaceDomain = torch_npu::profiler::MstxMgr::GetInstance()->createLeaksDomain( |
| 158 | - torch_npu::profiler::MstxMgr::GetInstance()->createLeaksDomain( | 142 | + torch_npu::profiler::DOMAIN_WORKSPACE.c_str()); |
| 159 | - torch_npu::profiler::DOMAIN_WORKSPACE.c_str()); | 143 | + mstxMemVirtualRangeDesc_t desc{device, block->data_ptr, stats.reserved_bytes.current}; |
| 160 | - mstxMemVirtualRangeDesc_t desc{ | 144 | + torch_npu::profiler::MstxMgr::GetInstance()->memHeapRegister(workspaceDomain, &desc); |
| 161 | - device, block->data_ptr, stats.reserved_bytes.current}; | ||
| 162 | - torch_npu::profiler::MstxMgr::GetInstance()->memHeapRegister( | ||
| 163 | - workspaceDomain, &desc); | ||
| 164 | } | 145 | } |
| 165 | record_mem_size_increment(block->size); | 146 | record_mem_size_increment(block->size); |
| 166 | torch_npu::profiler::reportMemoryDataToNpuProfiler( | 147 | torch_npu::profiler::reportMemoryDataToNpuProfiler( |
| 167 | {static_cast<int8_t>(c10::DeviceType::PrivateUse1), | 148 | {static_cast<int8_t>(c10::DeviceType::PrivateUse1), |
| 168 | device, | 149 | device, |
| 169 | - static_cast<uint8_t>( | 150 | + static_cast<uint8_t>(torch_npu::profiler::MemoryComponentType::WORKSPACE_ALLOCATOR), |
| 170 | - torch_npu::profiler::MemoryComponentType::WORKSPACE_ALLOCATOR), | 151 | + static_cast<uint8_t>(torch_npu::profiler::MemoryDataType::MEMORY_MALLOC), |
| 171 | - static_cast<uint8_t>( | 152 | + static_cast<uint8_t>(torch_npu::profiler::MemoryAllocatorType::ALLOCATOR_INNER), |
| 172 | - torch_npu::profiler::MemoryDataType::MEMORY_MALLOC), | ||
| 173 | - static_cast<uint8_t>( | ||
| 174 | - torch_npu::profiler::MemoryAllocatorType::ALLOCATOR_INNER), | ||
| 175 | reinterpret_cast<int64_t>(block->data_ptr), | 153 | reinterpret_cast<int64_t>(block->data_ptr), |
| 176 | block->size, | 154 | block->size, |
| 177 | stats.allocated_bytes.current, | 155 | stats.allocated_bytes.current, |
| @@ -180,11 +158,9 @@ class DeviceWorkspaceAllocator { | |||
| 180 | stream}); | 158 | stream}); |
| 181 | this->last_block = block; | 159 | this->last_block = block; |
| 182 | this->last_stream = stream; | 160 | this->last_stream = stream; |
| 183 | - const c10_npu::impl::PyCallbackTrigger* trigger = | 161 | + const c10_npu::impl::PyCallbackTrigger* trigger = c10_npu::impl::NPUTrace::getTrace(); |
| 184 | - c10_npu::impl::NPUTrace::getTrace(); | ||
| 185 | if (C10_UNLIKELY(trigger)) { | 162 | if (C10_UNLIKELY(trigger)) { |
| 186 | - trigger->traceNpuMemoryAllocation( | 163 | + trigger->traceNpuMemoryAllocation(reinterpret_cast<uintptr_t>(block->data_ptr)); |
| 187 | - reinterpret_cast<uintptr_t>(block->data_ptr)); | ||
| 188 | } | 164 | } |
| 189 | 165 | ||
| 190 | } | 166 | } |
| @@ -194,22 +170,16 @@ class DeviceWorkspaceAllocator { | |||
| 194 | 170 | ||
| 195 | if (torch_npu::profiler::MstxMgr::GetInstance()->isMsleaksEnable()) { | 171 | if (torch_npu::profiler::MstxMgr::GetInstance()->isMsleaksEnable()) { |
| 196 | mstxDomainHandle_t workspaceDomain = | 172 | mstxDomainHandle_t workspaceDomain = |
| 197 | - torch_npu::profiler::MstxMgr::GetInstance()->createLeaksDomain( | 173 | + torch_npu::profiler::MstxMgr::GetInstance()->createLeaksDomain(torch_npu::profiler::DOMAIN_WORKSPACE.c_str()); |
| 198 | - torch_npu::profiler::DOMAIN_WORKSPACE.c_str()); | 174 | + mstxMemVirtualRangeDesc_t desc{device, block->data_ptr, stats.allocated_bytes.current}; |
| 199 | - mstxMemVirtualRangeDesc_t desc{ | 175 | + torch_npu::profiler::MstxMgr::GetInstance()->memRegionsRegister(workspaceDomain, &desc); |
| 200 | - device, block->data_ptr, stats.allocated_bytes.current}; | ||
| 201 | - torch_npu::profiler::MstxMgr::GetInstance()->memRegionsRegister( | ||
| 202 | - workspaceDomain, &desc); | ||
| 203 | } | 176 | } |
| 204 | torch_npu::profiler::reportMemoryDataToNpuProfiler( | 177 | torch_npu::profiler::reportMemoryDataToNpuProfiler( |
| 205 | {static_cast<int8_t>(c10::DeviceType::PrivateUse1), | 178 | {static_cast<int8_t>(c10::DeviceType::PrivateUse1), |
| 206 | device, | 179 | device, |
| 207 | - static_cast<uint8_t>( | 180 | + static_cast<uint8_t>(torch_npu::profiler::MemoryComponentType::WORKSPACE_ALLOCATOR), |
| 208 | - torch_npu::profiler::MemoryComponentType::WORKSPACE_ALLOCATOR), | 181 | + static_cast<uint8_t>(torch_npu::profiler::MemoryDataType::MEMORY_MALLOC), |
| 209 | - static_cast<uint8_t>( | 182 | + static_cast<uint8_t>(torch_npu::profiler::MemoryAllocatorType::ALLOCATOR_INNER), |
| 210 | - torch_npu::profiler::MemoryDataType::MEMORY_MALLOC), | ||
| 211 | - static_cast<uint8_t>( | ||
| 212 | - torch_npu::profiler::MemoryAllocatorType::ALLOCATOR_INNER), | ||
| 213 | reinterpret_cast<int64_t>(block->data_ptr), | 183 | reinterpret_cast<int64_t>(block->data_ptr), |
| 214 | block->size, | 184 | block->size, |
| 215 | stats.allocated_bytes.current, | 185 | stats.allocated_bytes.current, |
| @@ -228,21 +198,16 @@ class DeviceWorkspaceAllocator { | |||
| 228 | 198 | ||
| 229 | if (this->last_block && this->last_block->data_ptr && this->last_stream) { | 199 | if (this->last_block && this->last_block->data_ptr && this->last_stream) { |
| 230 | if (torch_npu::profiler::MstxMgr::GetInstance()->isMsleaksEnable()) { | 200 | if (torch_npu::profiler::MstxMgr::GetInstance()->isMsleaksEnable()) { |
| 231 | - mstxDomainHandle_t workspaceDomain = | 201 | + mstxDomainHandle_t workspaceDomain = torch_npu::profiler::MstxMgr::GetInstance()->createLeaksDomain( |
| 232 | - torch_npu::profiler::MstxMgr::GetInstance()->createLeaksDomain( | 202 | + torch_npu::profiler::DOMAIN_WORKSPACE.c_str()); |
| 233 | - torch_npu::profiler::DOMAIN_WORKSPACE.c_str()); | 203 | + torch_npu::profiler::MstxMgr::GetInstance()->memRegionsUnregister(workspaceDomain, this->last_block->data_ptr); |
| 234 | - torch_npu::profiler::MstxMgr::GetInstance()->memRegionsUnregister( | ||
| 235 | - workspaceDomain, this->last_block->data_ptr); | ||
| 236 | } | 204 | } |
| 237 | torch_npu::profiler::reportMemoryDataToNpuProfiler( | 205 | torch_npu::profiler::reportMemoryDataToNpuProfiler( |
| 238 | {static_cast<int8_t>(c10::DeviceType::PrivateUse1), | 206 | {static_cast<int8_t>(c10::DeviceType::PrivateUse1), |
| 239 | device, | 207 | device, |
| 240 | - static_cast<uint8_t>( | 208 | + static_cast<uint8_t>(torch_npu::profiler::MemoryComponentType::WORKSPACE_ALLOCATOR), |
| 241 | - torch_npu::profiler::MemoryComponentType::WORKSPACE_ALLOCATOR), | 209 | + static_cast<uint8_t>(torch_npu::profiler::MemoryDataType::MEMORY_FREE), |
| 242 | - static_cast<uint8_t>( | 210 | + static_cast<uint8_t>(torch_npu::profiler::MemoryAllocatorType::ALLOCATOR_INNER), |
| 243 | - torch_npu::profiler::MemoryDataType::MEMORY_FREE), | ||
| 244 | - static_cast<uint8_t>( | ||
| 245 | - torch_npu::profiler::MemoryAllocatorType::ALLOCATOR_INNER), | ||
| 246 | reinterpret_cast<int64_t>(this->last_block->data_ptr), | 211 | reinterpret_cast<int64_t>(this->last_block->data_ptr), |
| 247 | -allocated_size, | 212 | -allocated_size, |
| 248 | stats.allocated_bytes.current, | 213 | stats.allocated_bytes.current, |
| @@ -255,46 +220,32 @@ class DeviceWorkspaceAllocator { | |||
| 255 | 220 | ||
| 256 | // return to the system allocator | 221 | // return to the system allocator |
| 257 | void empty_cache(bool check_error) { | 222 | void empty_cache(bool check_error) { |
| 258 | - ASCEND_LOGD( | 223 | + ASCEND_LOGD("NPUWorkspaceAllocator begin empty cache with check_error = %d", check_error); |
| 259 | - "NPUWorkspaceAllocator begin empty cache with check_error = %d", | ||
| 260 | - check_error); | ||
| 261 | 224 | ||
| 262 | std::lock_guard<std::recursive_mutex> lock(mutex); | 225 | std::lock_guard<std::recursive_mutex> lock(mutex); |
| 263 | for (const auto& block_pair : blocks) { | 226 | for (const auto& block_pair : blocks) { |
| 264 | if (block_pair.second->data_ptr != nullptr) { | 227 | if (block_pair.second->data_ptr != nullptr) { |
| 265 | - ASCEND_LOGI( | 228 | + ASCEND_LOGI("NPUWorkspaceAllocator free by aclrtFree: size=%zu", block_pair.second->size); |
| 266 | - "NPUWorkspaceAllocator free by aclrtFree: size=%zu", | ||
| 267 | - block_pair.second->size); | ||
| 268 | NPU_CHECK_ERROR(aclrtFree(block_pair.second->data_ptr)); | 229 | NPU_CHECK_ERROR(aclrtFree(block_pair.second->data_ptr)); |
| 269 | update_stat(stats.reserved_bytes, -block_pair.second->size); | 230 | update_stat(stats.reserved_bytes, -block_pair.second->size); |
| 270 | 231 | ||
| 271 | if (torch_npu::profiler::MstxMgr::GetInstance()->isMsleaksEnable()) { | 232 | if (torch_npu::profiler::MstxMgr::GetInstance()->isMsleaksEnable()) { |
| 272 | - mstxDomainHandle_t workspaceDomain = | 233 | + mstxDomainHandle_t workspaceDomain = torch_npu::profiler::MstxMgr::GetInstance()->createLeaksDomain( |
| 273 | - torch_npu::profiler::MstxMgr::GetInstance()->createLeaksDomain( | 234 | + torch_npu::profiler::DOMAIN_WORKSPACE.c_str()); |
| 274 | - torch_npu::profiler::DOMAIN_WORKSPACE.c_str()); | 235 | + mstxMemVirtualRangeDesc_t desc{device, block_pair.second->data_ptr, stats.reserved_bytes.current}; |
| 275 | - mstxMemVirtualRangeDesc_t desc{ | 236 | + torch_npu::profiler::MstxMgr::GetInstance()->memHeapRegister(workspaceDomain, &desc); |
| 276 | - device, | ||
| 277 | - block_pair.second->data_ptr, | ||
| 278 | - stats.reserved_bytes.current}; | ||
| 279 | - torch_npu::profiler::MstxMgr::GetInstance()->memHeapRegister( | ||
| 280 | - workspaceDomain, &desc); | ||
| 281 | } | 237 | } |
| 282 | record_mem_size_decrement(block_pair.second->size); | 238 | record_mem_size_decrement(block_pair.second->size); |
| 283 | - const c10_npu::impl::PyCallbackTrigger* trigger = | 239 | + const c10_npu::impl::PyCallbackTrigger* trigger = c10_npu::impl::NPUTrace::getTrace(); |
| 284 | - c10_npu::impl::NPUTrace::getTrace(); | ||
| 285 | if (C10_UNLIKELY(trigger)) { | 240 | if (C10_UNLIKELY(trigger)) { |
| 286 | - trigger->traceNpuMemoryDeallocation( | 241 | + trigger->traceNpuMemoryDeallocation(reinterpret_cast<uintptr_t>(block_pair.second->data_ptr)); |
| 287 | - reinterpret_cast<uintptr_t>(block_pair.second->data_ptr)); | ||
| 288 | } | 242 | } |
| 289 | torch_npu::profiler::reportMemoryDataToNpuProfiler( | 243 | torch_npu::profiler::reportMemoryDataToNpuProfiler( |
| 290 | {static_cast<int8_t>(c10::DeviceType::PrivateUse1), | 244 | {static_cast<int8_t>(c10::DeviceType::PrivateUse1), |
| 291 | device, | 245 | device, |
| 292 | - static_cast<uint8_t>( | 246 | + static_cast<uint8_t>(torch_npu::profiler::MemoryComponentType::WORKSPACE_ALLOCATOR), |
| 293 | - torch_npu::profiler::MemoryComponentType::WORKSPACE_ALLOCATOR), | 247 | + static_cast<uint8_t>(torch_npu::profiler::MemoryDataType::MEMORY_FREE), |
| 294 | - static_cast<uint8_t>( | 248 | + static_cast<uint8_t>(torch_npu::profiler::MemoryAllocatorType::ALLOCATOR_INNER), |
| 295 | - torch_npu::profiler::MemoryDataType::MEMORY_FREE), | ||
| 296 | - static_cast<uint8_t>( | ||
| 297 | - torch_npu::profiler::MemoryAllocatorType::ALLOCATOR_INNER), | ||
| 298 | reinterpret_cast<int64_t>(block_pair.second->data_ptr), | 249 | reinterpret_cast<int64_t>(block_pair.second->data_ptr), |
| 299 | -block_pair.second->size, | 250 | -block_pair.second->size, |
| 300 | stats.allocated_bytes.current, | 251 | stats.allocated_bytes.current, |
| @@ -307,19 +258,12 @@ class DeviceWorkspaceAllocator { | |||
| 307 | } | 258 | } |
| 308 | 259 | ||
| 309 | blocks.clear(); | 260 | blocks.clear(); |
| 310 | - ASCEND_LOGD( | 261 | + ASCEND_LOGD("NPUWorkspaceAllocator end empty cache with check_error = %d", check_error); |
| 311 | - "NPUWorkspaceAllocator end empty cache with check_error = %d", | ||
| 312 | - check_error); | ||
| 313 | } | 262 | } |
| 314 | 263 | ||
| 315 | - void record_history( | 264 | + void record_history(bool enabled, CreateContextFn context_recorder, RecordContext when) { |
| 316 | - bool enabled, | ||
| 317 | - CreateContextFn context_recorder, | ||
| 318 | - RecordContext when) { | ||
| 319 | std::lock_guard<std::recursive_mutex> lock(mutex); | 265 | std::lock_guard<std::recursive_mutex> lock(mutex); |
| 320 | - TORCH_CHECK( | 266 | + TORCH_CHECK(when == RecordContext::NEVER || context_recorder, PTA_ERROR(ErrCode::INTERNAL)); |
| 321 | - when == RecordContext::NEVER || context_recorder, | ||
| 322 | - PTA_ERROR(ErrCode::INTERNAL)); | ||
| 323 | record_flag = enabled; | 267 | record_flag = enabled; |
| 324 | context_recorder_.store(record_flag ? context_recorder : nullptr); | 268 | context_recorder_.store(record_flag ? context_recorder : nullptr); |
| 325 | record_context_ = enabled ? when : RecordContext::NEVER; | 269 | record_context_ = enabled ? when : RecordContext::NEVER; |
| @@ -340,9 +284,7 @@ class DeviceWorkspaceAllocator { | |||
| 340 | block_pair.second->size, | 284 | block_pair.second->size, |
| 341 | block_pair.first, | 285 | block_pair.first, |
| 342 | MempoolId_t{0, 0}, | 286 | MempoolId_t{0, 0}, |
| 343 | - record_context_ >= RecordContext::ALLOC | 287 | + record_context_ >= RecordContext::ALLOC ? block_pair.second->context_when_allocated : nullptr); |
| 344 | - ? block_pair.second->context_when_allocated | ||
| 345 | - : nullptr); | ||
| 346 | alloc_trace.emplace_back(te); | 288 | alloc_trace.emplace_back(te); |
| 347 | 289 | ||
| 348 | te = TraceEntry( | 290 | te = TraceEntry( |
| @@ -352,9 +294,7 @@ class DeviceWorkspaceAllocator { | |||
| 352 | block_pair.second->size, | 294 | block_pair.second->size, |
| 353 | block_pair.first, | 295 | block_pair.first, |
| 354 | MempoolId_t{0, 0}, | 296 | MempoolId_t{0, 0}, |
| 355 | - record_context_ >= RecordContext::ALLOC | 297 | + record_context_ >= RecordContext::ALLOC ? block_pair.second->context_when_allocated : nullptr); |
| 356 | - ? block_pair.second->context_when_allocated | ||
| 357 | - : nullptr); | ||
| 358 | alloc_trace.emplace_back(te); | 298 | alloc_trace.emplace_back(te); |
| 359 | 299 | ||
| 360 | te = TraceEntry( | 300 | te = TraceEntry( |
| @@ -364,9 +304,7 @@ class DeviceWorkspaceAllocator { | |||
| 364 | block_pair.second->size, | 304 | block_pair.second->size, |
| 365 | block_pair.first, | 305 | block_pair.first, |
| 366 | MempoolId_t{0, 0}, | 306 | MempoolId_t{0, 0}, |
| 367 | - record_context_ >= RecordContext::ALLOC | 307 | + record_context_ >= RecordContext::ALLOC ? block_pair.second->context_when_allocated : nullptr); |
| 368 | - ? block_pair.second->context_when_allocated | ||
| 369 | - : nullptr); | ||
| 370 | alloc_trace.emplace_back(te); | 308 | alloc_trace.emplace_back(te); |
| 371 | } | 309 | } |
| 372 | 310 | ||
| @@ -381,13 +319,11 @@ class DeviceWorkspaceAllocator { | |||
| 381 | result.emplace_back(); | 319 | result.emplace_back(); |
| 382 | SegmentInfo& segment_info = result.back(); | 320 | SegmentInfo& segment_info = result.back(); |
| 383 | segment_info.device = device; | 321 | segment_info.device = device; |
| 384 | - segment_info.address = | 322 | + segment_info.address = reinterpret_cast<int64_t>(block_pair.second->data_ptr); |
| 385 | - reinterpret_cast<int64_t>(block_pair.second->data_ptr); | ||
| 386 | segment_info.stream = block_pair.first; | 323 | segment_info.stream = block_pair.first; |
| 387 | segment_info.is_large = true; | 324 | segment_info.is_large = true; |
| 388 | segment_info.is_expandable = false; | 325 | segment_info.is_expandable = false; |
| 389 | - segment_info.context_when_allocated = | 326 | + segment_info.context_when_allocated = block_pair.second->context_when_allocated; |
| 390 | - block_pair.second->context_when_allocated; | ||
| 391 | 327 | ||
| 392 | const WorkspaceBlock* block = block_pair.second; | 328 | const WorkspaceBlock* block = block_pair.second; |
| 393 | segment_info.blocks.emplace_back(); | 329 | segment_info.blocks.emplace_back(); |
| @@ -484,26 +420,18 @@ class NpuWorkspaceAllocator : public c10::Allocator { | |||
| 484 | } | 420 | } |
| 485 | 421 | ||
| 486 | void malloc(void** new_ptr, int device, size_t size, aclrtStream stream) { | 422 | void malloc(void** new_ptr, int device, size_t size, aclrtStream stream) { |
| 487 | - auto src_ptr = | 423 | + auto src_ptr = static_cast<void*>(device_allocator[device]->getStreamPtr(stream)); |
| 488 | - static_cast<void*>(device_allocator[device]->getStreamPtr(stream)); | 424 | + *new_ptr = static_cast<void*>(device_allocator[device]->malloc(size, stream)); |
| 489 | - *new_ptr = | ||
| 490 | - static_cast<void*>(device_allocator[device]->malloc(size, stream)); | ||
| 491 | 425 | ||
| 492 | if ((*new_ptr) == nullptr) { | 426 | if ((*new_ptr) == nullptr) { |
| 493 | size_t device_free; | 427 | size_t device_free; |
| 494 | size_t device_total; | 428 | size_t device_total; |
| 495 | - NPU_CHECK_ERROR( | 429 | + NPU_CHECK_ERROR(aclrtGetMemInfo(ACL_HBM_MEM, &device_free, &device_total)); |
| 496 | - aclrtGetMemInfo(ACL_HBM_MEM, &device_free, &device_total)); | ||
| 497 | 430 | ||
| 498 | - auto retmsg = | 431 | + auto retmsg = std::string("NPU out of memory. NPUWorkspaceAllocator tried to allocate ") + format_size(size) + |
| 499 | - std::string( | 432 | + "(NPU " + std::to_string(device) + "; " + format_size(device_total) + " total capacity; " + |
| 500 | - "NPU out of memory. NPUWorkspaceAllocator tried to allocate ") + | 433 | + format_size(device_free) + " free). If you want to reduce memory usage, " + |
| 501 | - format_size(size) + "(NPU " + std::to_string(device) + "; " + | 434 | + "take a try to set the environment variable TASK_QUEUE_ENABLE=1.\n" + PTA_ERROR(ErrCode::MEMORY); |
| 502 | - format_size(device_total) + " total capacity; " + | ||
| 503 | - format_size(device_free) + | ||
| 504 | - " free). If you want to reduce memory usage, " + | ||
| 505 | - "take a try to set the environment variable TASK_QUEUE_ENABLE=1.\n" + | ||
| 506 | - PTA_ERROR(ErrCode::MEMORY); | ||
| 507 | ASCEND_LOGE("%s", retmsg.c_str()); | 435 | ASCEND_LOGE("%s", retmsg.c_str()); |
| 508 | TORCH_CHECK_WITH(OutOfMemoryError, false, retmsg.c_str()); | 436 | TORCH_CHECK_WITH(OutOfMemoryError, false, retmsg.c_str()); |
| 509 | } | 437 | } |
| @@ -518,10 +446,7 @@ class NpuWorkspaceAllocator : public c10::Allocator { | |||
| 518 | allocated_ptrs.clear(); | 446 | allocated_ptrs.clear(); |
| 519 | } | 447 | } |
| 520 | 448 | ||
| 521 | - void record_history( | 449 | + void record_history(bool enabled, CreateContextFn context_recorder, RecordContext when) { |
| 522 | - bool enabled, | ||
| 523 | - CreateContextFn context_recorder, | ||
| 524 | - RecordContext when) { | ||
| 525 | for (auto& allocator : device_allocator) { | 450 | for (auto& allocator : device_allocator) { |
| 526 | allocator->record_history(enabled, context_recorder, when); | 451 | allocator->record_history(enabled, context_recorder, when); |
| 527 | } | 452 | } |
| @@ -543,11 +468,7 @@ class NpuWorkspaceAllocator : public c10::Allocator { | |||
| 543 | NPU_CHECK_ERROR(c10_npu::GetDevice(&device)); | 468 | NPU_CHECK_ERROR(c10_npu::GetDevice(&device)); |
| 544 | void* dev_ptr = nullptr; | 469 | void* dev_ptr = nullptr; |
| 545 | void (*delete_func)(void*) = &local_raw_delete; | 470 | void (*delete_func)(void*) = &local_raw_delete; |
| 546 | - return { | 471 | + return {dev_ptr, dev_ptr, delete_func, c10::Device(c10::DeviceType::PrivateUse1, device)}; |
| 547 | - dev_ptr, | ||
| 548 | - dev_ptr, | ||
| 549 | - delete_func, | ||
| 550 | - c10::Device(c10::DeviceType::PrivateUse1, device)}; | ||
| 551 | } | 472 | } |
| 552 | 473 | ||
| 553 | c10::DataPtr allocate_with_stream(size_t size, aclrtStream stream) { | 474 | c10::DataPtr allocate_with_stream(size_t size, aclrtStream stream) { |
| @@ -560,21 +481,15 @@ class NpuWorkspaceAllocator : public c10::Allocator { | |||
| 560 | delete_func = &uncached_delete; | 481 | delete_func = &uncached_delete; |
| 561 | if (size != 0) { | 482 | if (size != 0) { |
| 562 | size_t alloc_size = size + 32; | 483 | size_t alloc_size = size + 32; |
| 563 | - NPU_CHECK_ERROR(c10_npu::acl::AclrtMallocAlign32( | 484 | + NPU_CHECK_ERROR( |
| 564 | - &dev_ptr, | 485 | + c10_npu::acl::AclrtMallocAlign32(&dev_ptr, alloc_size, aclrtMemMallocPolicy::ACL_MEM_MALLOC_HUGE_ONLY)); |
| 565 | - alloc_size, | ||
| 566 | - aclrtMemMallocPolicy::ACL_MEM_MALLOC_HUGE_ONLY)); | ||
| 567 | } | 486 | } |
| 568 | } else { | 487 | } else { |
| 569 | if (size != 0) { | 488 | if (size != 0) { |
| 570 | this->malloc(&dev_ptr, device, size, stream); | 489 | this->malloc(&dev_ptr, device, size, stream); |
| 571 | } | 490 | } |
| 572 | } | 491 | } |
| 573 | - return { | 492 | + return {dev_ptr, dev_ptr, delete_func, c10::Device(c10::DeviceType::PrivateUse1, device)}; |
| 574 | - dev_ptr, | ||
| 575 | - dev_ptr, | ||
| 576 | - delete_func, | ||
| 577 | - c10::Device(c10::DeviceType::PrivateUse1, device)}; | ||
| 578 | } | 493 | } |
| 579 | 494 | ||
| 580 | c10::DeleterFnPtr raw_deleter() const override { | 495 | c10::DeleterFnPtr raw_deleter() const override { |
| @@ -586,8 +501,7 @@ class NpuWorkspaceAllocator : public c10::Allocator { | |||
| 586 | 501 | ||
| 587 | // Note [COW/lazy_clone is not supported yet] | 502 | // Note [COW/lazy_clone is not supported yet] |
| 588 | void copy_data(void* dest, const void* src, std::size_t count) const final { | 503 | void copy_data(void* dest, const void* src, std::size_t count) const final { |
| 589 | - NPU_CHECK_ERROR( | 504 | + NPU_CHECK_ERROR(aclrtMemcpy(dest, count, src, count, ACL_MEMCPY_DEVICE_TO_DEVICE)); |
| 590 | - aclrtMemcpy(dest, count, src, count, ACL_MEMCPY_DEVICE_TO_DEVICE)); | ||
| 591 | } | 505 | } |
| 592 | 506 | ||
| 593 | void assertValidDevice(int device) { | 507 | void assertValidDevice(int device) { |
| @@ -663,10 +577,7 @@ void emptyCache(int device, bool check_error) { | |||
| 663 | workspace_allocator.empty_cache(device, check_error); | 577 | workspace_allocator.empty_cache(device, check_error); |
| 664 | } | 578 | } |
| 665 | 579 | ||
| 666 | -void recordHistory( | 580 | +void recordHistory(bool enabled, CreateContextFn context_recorder, RecordContext when) { |
| 667 | - bool enabled, | ||
| 668 | - CreateContextFn context_recorder, | ||
| 669 | - RecordContext when) { | ||
| 670 | workspace_allocator.record_history(enabled, context_recorder, when); | 581 | workspace_allocator.record_history(enabled, context_recorder, when); |
| 671 | } | 582 | } |
| 672 | SnapshotInfo snapshot() { | 583 | SnapshotInfo snapshot() { |
| @@ -7,9 +7,9 @@ | |||
| 7 | 7 | ||
| 8 | 8 | ||
| 9 | 9 | ||
| 10 | -#include "third_party/acl/inc/acl/acl.h" | 10 | +#include <acl/acl.h> |
| 11 | -#include "third_party/acl/inc/acl/acl_base.h" | 11 | +#include <acl/acl_base.h> |
| 12 | -#include "third_party/acl/inc/acl/acl_rt.h" | 12 | +#include <acl/acl_rt.h> |
| 13 | 13 | ||
| 14 | namespace c10_npu { | 14 | namespace c10_npu { |
| 15 | namespace impl { | 15 | namespace impl { |
| @@ -2,12 +2,12 @@ | |||
| 2 | 2 | ||
| 3 | 3 | ||
| 4 | 4 | ||
| 5 | -#include "third_party/acl/inc/acl/acl_rt.h" | 5 | +#include <acl/acl_rt.h> |
| 6 | -#include "third_party/acl/inc/acl/acl_base.h" | 6 | +#include <acl/acl_base.h> |
| 7 | -#include "third_party/acl/inc/acl/acl_mdl.h" | 7 | +#include <acl/acl_mdl.h> |
| 8 | -#include "third_party/acl/inc/acl/acl_prof.h" | 8 | +#include <acl/acl_prof.h> |
| 9 | 9 | ||
| 10 | -#include "third_party/acl/inc/acl/acl.h" | 10 | +#include <acl/acl.h> |
| 11 | 11 | ||
| 12 | using aclrtHostFunc = void (*)(void* args); | 12 | using aclrtHostFunc = void (*)(void* args); |
| 13 | struct aclrtMemUsageInfo; | 13 | struct aclrtMemUsageInfo; |
| @@ -6,7 +6,7 @@ | |||
| 6 | 6 | ||
| 7 | 7 | ||
| 8 | 8 | ||
| 9 | -#include "third_party/acl/inc/acl/acl_rt.h" | 9 | +#include <acl/acl_rt.h> |
| 10 | 10 | ||
| 11 | 11 | ||
| 12 | 12 | ||
| @@ -2,7 +2,7 @@ | |||
| 2 | 2 | ||
| 3 | 3 | ||
| 4 | 4 | ||
| 5 | -#include "third_party/acl/inc/acl/acl_rt.h" | 5 | +#include <acl/acl_rt.h> |
| 6 | 6 | ||
| 7 | namespace c10_npu { | 7 | namespace c10_npu { |
| 8 | namespace queue { | 8 | namespace queue { |
| @@ -1,5 +1,5 @@ | |||
| 1 | 1 | ||
| 2 | -#include "third_party/acl/inc/aml/aml_fwk_detect.h" | 2 | +#include <aml/aml_fwk_detect.h> |
| 3 | 3 | ||
| 4 | namespace c10_npu { | 4 | namespace c10_npu { |
| 5 | namespace amlapi { | 5 | namespace amlapi { |
| @@ -1,8 +1,8 @@ | |||
| 1 | 1 | ||
| 2 | 2 | ||
| 3 | -#include "third_party/acl/inc/acl/super_kernel.h" | 3 | +#include <acl/super_kernel.h> |
| 4 | -#include "third_party/acl/inc/acl/acl_base.h" | 4 | +#include <acl/acl_base.h> |
| 5 | -#include "third_party/acl/inc/acl/acl_mdl.h" | 5 | +#include <acl/acl_mdl.h> |
| 6 | 6 | ||
| 7 | namespace c10_npu { | 7 | namespace c10_npu { |
| 8 | namespace skapi { | 8 | namespace skapi { |
| @@ -3,7 +3,7 @@ | |||
| 3 | 3 | ||
| 4 | 4 | ||
| 5 | 5 | ||
| 6 | -#include "third_party/acl/inc/acl/acl_base.h" | 6 | +#include <acl/acl_base.h> |
| 7 | 7 | ||
| 8 | 8 | ||
| 9 | 9 | ||
| @@ -22,8 +22,8 @@ | |||
| 22 | 22 | ||
| 23 | 23 | ||
| 24 | 24 | ||
| 25 | -#include "third_party/acl/inc/acl/acl_op_compiler.h" | 25 | +#include <acl/acl_op_compiler.h> |
| 26 | -#include "third_party/acl/inc/acl/acl_rt.h" | 26 | +#include <acl/acl_rt.h> |
| 27 | 27 | ||
| 28 | 28 | ||
| 29 | 29 | ||
| @@ -42,10 +42,8 @@ const uint32_t kMaxOpExecuteTimeOut = 547U; | |||
| 42 | const size_t kMaxPathLen = 4096U; | 42 | const size_t kMaxPathLen = 4096U; |
| 43 | 43 | ||
| 44 | void SetDefaultAllowInternalFromatDisable() { | 44 | void SetDefaultAllowInternalFromatDisable() { |
| 45 | - auto allow_internal_format = | 45 | + auto allow_internal_format = c10_npu::option::GetOption("ALLOW_INTERNAL_FORMAT"); |
| 46 | - c10_npu::option::GetOption("ALLOW_INTERNAL_FORMAT"); | 46 | + if (allow_internal_format.has_value() && allow_internal_format.value() != "") { |
| 47 | - if (allow_internal_format.has_value() && | ||
| 48 | - allow_internal_format.value() != "") { | ||
| 49 | return; | 47 | return; |
| 50 | } | 48 | } |
| 51 | 49 | ||
| @@ -54,8 +52,7 @@ void SetDefaultAllowInternalFromatDisable() { | |||
| 54 | } | 52 | } |
| 55 | 53 | ||
| 56 | void SetDeterministicFromLevel() { | 54 | void SetDeterministicFromLevel() { |
| 57 | - at_npu::native::ApplyDeterministicSnapshot( | 55 | + at_npu::native::ApplyDeterministicSnapshot(c10_npu::CaptureDeterministicSnapshot(), true); |
| 58 | - c10_npu::CaptureDeterministicSnapshot(), true); | ||
| 59 | } | 56 | } |
| 60 | 57 | ||
| 61 | 58 | ||
| @@ -88,8 +85,7 @@ std::string GetAclConfigJsonPath() { | |||
| 88 | const char* acl_init_path = c10_npu::option::OptionsManager::GetAclInitPath(); | 85 | const char* acl_init_path = c10_npu::option::OptionsManager::GetAclInitPath(); |
| 89 | if (acl_init_path != nullptr) { | 86 | if (acl_init_path != nullptr) { |
| 90 | std::string json_path = std::string(acl_init_path); | 87 | std::string json_path = std::string(acl_init_path); |
| 91 | - std::string json_path_str = | 88 | + std::string json_path_str = torch_npu::toolkit::profiler::Utils::RealPath(json_path); |
| 92 | - torch_npu::toolkit::profiler::Utils::RealPath(json_path); | ||
| 93 | if (json_path_str.empty()) { | 89 | if (json_path_str.empty()) { |
| 94 | TORCH_CHECK( | 90 | TORCH_CHECK( |
| 95 | false, | 91 | false, |
| @@ -125,8 +121,7 @@ std::string GetAclConfigJsonPath() { | |||
| 125 | } | 121 | } |
| 126 | 122 | ||
| 127 | if (c10_npu::is_lazy_set_device()) { | 123 | if (c10_npu::is_lazy_set_device()) { |
| 128 | - if (!config.contains("defaultDevice") || | 124 | + if (!config.contains("defaultDevice") || !config["defaultDevice"].is_object()) { |
| 129 | - !config["defaultDevice"].is_object()) { | ||
| 130 | TORCH_CHECK( | 125 | TORCH_CHECK( |
| 131 | false, | 126 | false, |
| 132 | "User acl json ", | 127 | "User acl json ", |
| @@ -136,8 +131,7 @@ std::string GetAclConfigJsonPath() { | |||
| 136 | PTA_ERROR(ErrCode::VALUE)); | 131 | PTA_ERROR(ErrCode::VALUE)); |
| 137 | } | 132 | } |
| 138 | const auto& default_dev = config["defaultDevice"]; | 133 | const auto& default_dev = config["defaultDevice"]; |
| 139 | - if (!default_dev.contains("default_device") || | 134 | + if (!default_dev.contains("default_device") || !default_dev["default_device"].is_string() || |
| 140 | - !default_dev["default_device"].is_string() || | ||
| 141 | default_dev["default_device"].get<std::string>() != "0") { | 135 | default_dev["default_device"].get<std::string>() != "0") { |
| 142 | TORCH_CHECK( | 136 | TORCH_CHECK( |
| 143 | false, | 137 | false, |
| @@ -172,8 +166,7 @@ std::string GetAclConfigJsonPath() { | |||
| 172 | } else { | 166 | } else { |
| 173 | json_path = npu_path.append("torch_npu/acl.json"); | 167 | json_path = npu_path.append("torch_npu/acl.json"); |
| 174 | } | 168 | } |
| 175 | - std::string json_path_str = | 169 | + std::string json_path_str = torch_npu::toolkit::profiler::Utils::RealPath(json_path); |
| 176 | - torch_npu::toolkit::profiler::Utils::RealPath(json_path); | ||
| 177 | if (json_path_str == "") { | 170 | if (json_path_str == "") { |
| 178 | ASCEND_LOGW("this path:%s is not exist!", json_path.c_str()); | 171 | ASCEND_LOGW("this path:%s is not exist!", json_path.c_str()); |
| 179 | } | 172 | } |
| @@ -263,11 +256,9 @@ NpuSysCtrl::SysStatus NpuSysCtrl::Initialize(int device_id) { | |||
| 263 | 256 | ||
| 264 | if (!c10_npu::is_lazy_set_device()) { | 257 | if (!c10_npu::is_lazy_set_device()) { |
| 265 | if (c10_npu::IsSupportInfNan()) { | 258 | if (c10_npu::IsSupportInfNan()) { |
| 266 | - c10_npu::acl::AclrtSetDeviceSatMode( | 259 | + c10_npu::acl::AclrtSetDeviceSatMode(aclrtFloatOverflowMode::ACL_RT_OVERFLOW_MODE_INFNAN); |
| 267 | - aclrtFloatOverflowMode::ACL_RT_OVERFLOW_MODE_INFNAN); | ||
| 268 | } else { | 260 | } else { |
| 269 | - c10_npu::acl::AclrtSetDeviceSatMode( | 261 | + c10_npu::acl::AclrtSetDeviceSatMode(aclrtFloatOverflowMode::ACL_RT_OVERFLOW_MODE_SATURATION); |
| 270 | - aclrtFloatOverflowMode::ACL_RT_OVERFLOW_MODE_SATURATION); | ||
| 271 | } | 262 | } |
| 272 | } | 263 | } |
| 273 | 264 | ||
| @@ -287,8 +278,7 @@ NpuSysCtrl::SysStatus NpuSysCtrl::Initialize(int device_id) { | |||
| 287 | 278 | ||
| 288 | if (!c10_npu::is_lazy_set_device()) { | 279 | if (!c10_npu::is_lazy_set_device()) { |
| 289 | SetDeterministicFromLevel(); | 280 | SetDeterministicFromLevel(); |
| 290 | - NPU_CHECK_ERROR( | 281 | + NPU_CHECK_ERROR(c10_npu::acl::AclrtSetOpExecuteTimeOut(kMaxOpExecuteTimeOut)); |
| 291 | - c10_npu::acl::AclrtSetOpExecuteTimeOut(kMaxOpExecuteTimeOut)); | ||
| 292 | } | 282 | } |
| 293 | 283 | ||
| 294 | // lazy call for the setoption | 284 | // lazy call for the setoption |
| @@ -329,11 +319,9 @@ NpuSysCtrl::SysStatus NpuSysCtrl::LazyInitialize(int device_id) { | |||
| 329 | auto ret = aclrtGetDevice(&device_id_); | 319 | auto ret = aclrtGetDevice(&device_id_); |
| 330 | 320 | ||
| 331 | if (c10_npu::IsSupportInfNan()) { | 321 | if (c10_npu::IsSupportInfNan()) { |
| 332 | - c10_npu::acl::AclrtSetDeviceSatMode( | 322 | + c10_npu::acl::AclrtSetDeviceSatMode(aclrtFloatOverflowMode::ACL_RT_OVERFLOW_MODE_INFNAN); |
| 333 | - aclrtFloatOverflowMode::ACL_RT_OVERFLOW_MODE_INFNAN); | ||
| 334 | } else { | 323 | } else { |
| 335 | - c10_npu::acl::AclrtSetDeviceSatMode( | 324 | + c10_npu::acl::AclrtSetDeviceSatMode(aclrtFloatOverflowMode::ACL_RT_OVERFLOW_MODE_SATURATION); |
| 336 | - aclrtFloatOverflowMode::ACL_RT_OVERFLOW_MODE_SATURATION); | ||
| 337 | } | 325 | } |
| 338 | 326 | ||
| 339 | SetDeterministicFromLevel(); | 327 | SetDeterministicFromLevel(); |
| @@ -358,8 +346,7 @@ NpuSysCtrl::SysStatus NpuSysCtrl::BackwardsInit() { | |||
| 358 | 346 | ||
| 359 | NpuSysCtrl::SysStatus NpuSysCtrl::OverflowSwitchEnable() { | 347 | NpuSysCtrl::SysStatus NpuSysCtrl::OverflowSwitchEnable() { |
| 360 | if (!c10_npu::IsSupportInfNan()) { | 348 | if (!c10_npu::IsSupportInfNan()) { |
| 361 | - c10_npu::acl::AclrtSetStreamOverflowSwitch( | 349 | + c10_npu::acl::AclrtSetStreamOverflowSwitch(c10_npu::getCurrentNPUStream(), 1); |
| 362 | - c10_npu::getCurrentNPUStream(), 1); | ||
| 363 | ASCEND_LOGI("Npu overflow check switch set successfully."); | 350 | ASCEND_LOGI("Npu overflow check switch set successfully."); |
| 364 | } | 351 | } |
| 365 | return INIT_SUCC; | 352 | return INIT_SUCC; |
| @@ -430,22 +417,15 @@ int NpuSysCtrl::InitializedDeviceID() { | |||
| 430 | if (GetInitFlag()) { | 417 | if (GetInitFlag()) { |
| 431 | return device_id_; | 418 | return device_id_; |
| 432 | } | 419 | } |
| 433 | - TORCH_CHECK( | 420 | + TORCH_CHECK(false, "no npu device has been initialized!", PTA_ERROR(ErrCode::INTERNAL)); |
| 434 | - false, | ||
| 435 | - "no npu device has been initialized!", | ||
| 436 | - PTA_ERROR(ErrCode::INTERNAL)); | ||
| 437 | return -1; | 421 | return -1; |
| 438 | } | 422 | } |
| 439 | 423 | ||
| 440 | -void NpuSysCtrl::RegisterLazyFn( | 424 | +void NpuSysCtrl::RegisterLazyFn(const option::OptionCallBack& call_, const std::string& in) { |
| 441 | - const option::OptionCallBack& call_, | ||
| 442 | - const std::string& in) { | ||
| 443 | lazy_fn_.emplace_back(std::make_pair(call_, in)); | 425 | lazy_fn_.emplace_back(std::make_pair(call_, in)); |
| 444 | } | 426 | } |
| 445 | 427 | ||
| 446 | -void NpuSysCtrl::RegisterReleaseFn( | 428 | +void NpuSysCtrl::RegisterReleaseFn(ReleaseFn release_fn, ReleasePriority priority) { |
| 447 | - ReleaseFn release_fn, | ||
| 448 | - ReleasePriority priority) { | ||
| 449 | const auto& iter = this->release_fn_.find(priority); | 429 | const auto& iter = this->release_fn_.find(priority); |
| 450 | if (iter != release_fn_.end()) { | 430 | if (iter != release_fn_.end()) { |
| 451 | release_fn_[priority].emplace_back(release_fn); | 431 | release_fn_[priority].emplace_back(release_fn); |
| @@ -456,12 +436,10 @@ void NpuSysCtrl::RegisterReleaseFn( | |||
| 456 | 436 | ||
| 457 | aclError SetCurrentDevice() { | 437 | aclError SetCurrentDevice() { |
| 458 | if (c10_npu::NpuSysCtrl::GetInstance().GetInitFlag()) { | 438 | if (c10_npu::NpuSysCtrl::GetInstance().GetInitFlag()) { |
| 459 | - c10_npu::SetDevice( | 439 | + c10_npu::SetDevice(c10_npu::NpuSysCtrl::GetInstance().InitializedDeviceID()); |
| 460 | - c10_npu::NpuSysCtrl::GetInstance().InitializedDeviceID()); | ||
| 461 | return ACL_SUCCESS; | 440 | return ACL_SUCCESS; |
| 462 | } | 441 | } |
| 463 | - TORCH_CHECK( | 442 | + TORCH_CHECK(false, "npu device has not been inited.", PTA_ERROR(ErrCode::INTERNAL)); |
| 464 | - false, "npu device has not been inited.", PTA_ERROR(ErrCode::INTERNAL)); | ||
| 465 | } | 443 | } |
| 466 | 444 | ||
| 467 | } // namespace c10_npu | 445 | } // namespace c10_npu |
| @@ -1,6 +1,6 @@ | |||
| 1 | 1 | ||
| 2 | 2 | ||
| 3 | -#include <third_party/acl/inc/acl/acl.h> | 3 | +#include <acl/acl.h> |
| 4 | 4 | ||
| 5 | 5 | ||
| 6 | 6 | ||
| @@ -7,7 +7,7 @@ | |||
| 7 | 7 | ||
| 8 | 8 | ||
| 9 | 9 | ||
| 10 | -#include "third_party/acl/inc/acl/acl_base.h" | 10 | +#include <acl/acl_base.h> |
| 11 | 11 | ||
| 12 | namespace c10_npu { | 12 | namespace c10_npu { |
| 13 | const int g_toAclOffset = 256; | 13 | const int g_toAclOffset = 256; |
| @@ -33,8 +33,8 @@ | |||
| 33 | 33 | ||
| 34 | 34 | ||
| 35 | 35 | ||
| 36 | -#include "third_party/acl/inc/acl/acl.h" | 36 | +#include <acl/acl.h> |
| 37 | -#include "third_party/acl/inc/acl/acl_base.h" | 37 | +#include <acl/acl_base.h> |
| 38 | 38 | ||
| 39 | 39 | ||
| 40 | 40 | ||
| @@ -3,7 +3,7 @@ | |||
| 3 | 3 | ||
| 4 | 4 | ||
| 5 | 5 | ||
| 6 | -#include "third_party/acl/inc/acl/acl_base.h" | 6 | +#include <acl/acl_base.h> |
| 7 | 7 | ||
| 8 | namespace c10d { | 8 | namespace c10d { |
| 9 | namespace symmetric_memory { | 9 | namespace symmetric_memory { |
| @@ -4,7 +4,7 @@ | |||
| 4 | 4 | ||
| 5 | 5 | ||
| 6 | 6 | ||
| 7 | -#include "third_party/acl/inc/acl/acl_base.h" | 7 | +#include <acl/acl_base.h> |
| 8 | 8 | ||
| 9 | namespace at_npu { | 9 | namespace at_npu { |
| 10 | namespace native { | 10 | namespace native { |
| @@ -5,7 +5,7 @@ | |||
| 5 | 5 | ||
| 6 | 6 | ||
| 7 | 7 | ||
| 8 | -#include "third_party/acl/inc/acl/acl_op_compiler.h" | 8 | +#include <acl/acl_op_compiler.h> |
| 9 | 9 | ||
| 10 | namespace at_npu { | 10 | namespace at_npu { |
| 11 | namespace aclops { | 11 | namespace aclops { |
| @@ -4,8 +4,8 @@ | |||
| 4 | 4 | ||
| 5 | 5 | ||
| 6 | 6 | ||
| 7 | -#include "third_party/acl/inc/acl/acl.h" | 7 | +#include <acl/acl.h> |
| 8 | -#include "third_party/acl/inc/acl/acl_base.h" | 8 | +#include <acl/acl_base.h> |
| 9 | 9 | ||
| 10 | namespace at_npu { | 10 | namespace at_npu { |
| 11 | namespace native { | 11 | namespace native { |
| @@ -4,7 +4,7 @@ | |||
| 4 | 4 | ||
| 5 | 5 | ||
| 6 | 6 | ||
| 7 | -#include "third_party/acl/inc/acl/acl_base.h" | 7 | +#include <acl/acl_base.h> |
| 8 | 8 | ||
| 9 | 9 | ||
| 10 | 10 | ||
| @@ -2,7 +2,7 @@ | |||
| 2 | 2 | ||
| 3 | 3 | ||
| 4 | 4 | ||
| 5 | -#include <third_party/acl/inc/acl/acl_op_compiler.h> | 5 | +#include <acl/acl_op_compiler.h> |
| 6 | 6 | ||
| 7 | 7 | ||
| 8 | namespace at_npu { | 8 | namespace at_npu { |
| @@ -3,7 +3,7 @@ | |||
| 3 | 3 | ||
| 4 | 4 | ||
| 5 | 5 | ||
| 6 | -#include "third_party/acl/inc/acl/acl_base.h" | 6 | +#include <acl/acl_base.h> |
| 7 | 7 | ||
| 8 | 8 | ||
| 9 | 9 | ||
| @@ -17,7 +17,6 @@ constexpr int MAX_DIM = 5; | |||
| 17 | // Define the discontiguous cases vector to be optimized | 17 | // Define the discontiguous cases vector to be optimized |
| 18 | using OptimizationCases = c10::SmallVector<std::string, MAX_CASES>; | 18 | using OptimizationCases = c10::SmallVector<std::string, MAX_CASES>; |
| 19 | 19 | ||
| 20 | - | ||
| 21 | struct ContiguousTensorDesc { | 20 | struct ContiguousTensorDesc { |
| 22 | bool is_contiguous_; | 21 | bool is_contiguous_; |
| 23 | c10::SmallVector<int64_t, MAX_DIM> sizes_; | 22 | c10::SmallVector<int64_t, MAX_DIM> sizes_; |
| @@ -30,8 +29,8 @@ struct ContiguousTensorDesc { | |||
| 30 | aclFormat npu_format_; | 29 | aclFormat npu_format_; |
| 31 | OptimizationCases opt_cases_; | 30 | OptimizationCases opt_cases_; |
| 32 | void refresh_contiguous_using_size_and_stride(); | 31 | void refresh_contiguous_using_size_and_stride(); |
| 33 | - void reset_optimization_cases(const OptimizationCases &opt_cases); | 32 | + void reset_optimization_cases(const OptimizationCases& opt_cases); |
| 34 | - void add_optimization_case(const std::string &opt_case); | 33 | + void add_optimization_case(const std::string& opt_case); |
| 35 | void find_match_optimization_cases(); | 34 | void find_match_optimization_cases(); |
| 36 | size_t hash_src_desc; | 35 | size_t hash_src_desc; |
| 37 | bool cached_contiguous; | 36 | bool cached_contiguous; |
| @@ -1,10 +1,10 @@ | |||
| 1 | 1 | ||
| 2 | 2 | ||
| 3 | 3 | ||
| 4 | -#include "third_party/acl/inc/acl/acl_rt.h" | 4 | +#include <acl/acl_rt.h> |
| 5 | -#include <third_party/acl/inc/acl/acl_base.h> | 5 | +#include <acl/acl_base.h> |
| 6 | -#include <third_party/acl/inc/acl/acl_prof.h> | 6 | +#include <acl/acl_prof.h> |
| 7 | -#include <third_party/acl/inc/acl/acl_op.h> | 7 | +#include <acl/acl_op.h> |
| 8 | 8 | ||
| 9 | namespace at_npu { | 9 | namespace at_npu { |
| 10 | namespace native { | 10 | namespace native { |
| @@ -5,7 +5,7 @@ | |||
| 5 | 5 | ||
| 6 | 6 | ||
| 7 | 7 | ||
| 8 | -#include "third_party/acl/inc/acl/acl_base.h" | 8 | +#include <acl/acl_base.h> |
| 9 | 9 | ||
| 10 | namespace at_npu { | 10 | namespace at_npu { |
| 11 | namespace native { | 11 | namespace native { |
| @@ -1,7 +1,7 @@ | |||
| 1 | 1 | ||
| 2 | 2 | ||
| 3 | 3 | ||
| 4 | -#include "third_party/acl/inc/acl/acl_op_compiler.h" | 4 | +#include <acl/acl_op_compiler.h> |
| 5 | 5 | ||
| 6 | typedef struct aclOpExecutor aclOpExecutor; | 6 | typedef struct aclOpExecutor aclOpExecutor; |
| 7 | 7 | ||
| @@ -7,7 +7,7 @@ | |||
| 7 | 7 | ||
| 8 | 8 | ||
| 9 | 9 | ||
| 10 | -#include "third_party/acl/inc/acl/acl_mdl.h" | 10 | +#include <acl/acl_mdl.h> |
| 11 | 11 | ||
| 12 | 12 | ||
| 13 | 13 | ||
| @@ -1,7 +1,7 @@ | |||
| 1 | 1 | ||
| 2 | 2 | ||
| 3 | 3 | ||
| 4 | -#include "third_party/acl/inc/acl/acl_prof.h" | 4 | +#include <acl/acl_prof.h> |
| 5 | 5 | ||
| 6 | namespace at_npu { | 6 | namespace at_npu { |
| 7 | namespace native { | 7 | namespace native { |
| @@ -1,7 +1,7 @@ | |||
| 1 | 1 | ||
| 2 | 2 | ||
| 3 | 3 | ||
| 4 | -#include <third_party/acl/inc/acl/acl_prof.h> | 4 | +#include <acl/acl_prof.h> |
| 5 | 5 | ||
| 6 | 6 | ||
| 7 | namespace at_npu { | 7 | namespace at_npu { |
| @@ -1,7 +1,7 @@ | |||
| 1 | 1 | ||
| 2 | 2 | ||
| 3 | -#include "third_party/acl/inc/acl/acl_base.h" | 3 | +#include <acl/acl_base.h> |
| 4 | -#include "third_party/acl/inc/acl/acl_rt.h" | 4 | +#include <acl/acl_rt.h> |
| 5 | 5 | ||
| 6 | 6 | ||
| 7 | 7 | ||
| @@ -26,9 +26,7 @@ constexpr float EPSILON = 1e-6; | |||
| 26 | static const string CUBE_MATH_TYPE = "CUBE_MATH_TYPE"; | 26 | static const string CUBE_MATH_TYPE = "CUBE_MATH_TYPE"; |
| 27 | 27 | ||
| 28 | // check all at::ScalarType is not negative | 28 | // check all at::ScalarType is not negative |
| 29 | -#define ENUM_PAIR_FUNC(_1, n) \ | 29 | +#define ENUM_PAIR_FUNC(_1, n) static_assert(static_cast<int64_t>(at::ScalarType::n) >= 0, #n " is negative"); |
| 30 | - static_assert( \ | ||
| 31 | - static_cast<int64_t>(at::ScalarType::n) >= 0, | ||
| 32 | AT_FORALL_SCALAR_TYPES_WITH_COMPLEX_AND_QINTS(ENUM_PAIR_FUNC) | 30 | AT_FORALL_SCALAR_TYPES_WITH_COMPLEX_AND_QINTS(ENUM_PAIR_FUNC) |
| 33 | 31 | ||
| 34 | 32 | ||
| @@ -39,8 +37,7 @@ AT_FORALL_SCALAR_TYPES_WITH_COMPLEX_AND_QINTS(ENUM_PAIR_FUNC) | |||
| 39 | // passes on 2.13 rc14 (where BComplex32 does not exist) and on 2.14 (where | 37 | // passes on 2.13 rc14 (where BComplex32 does not exist) and on 2.14 (where |
| 40 | // it does). Ascend has no native BComplex32 dtype, so map to ACL_DT_UNDEFINED. | 38 | // it does). Ascend has no native BComplex32 dtype, so map to ACL_DT_UNDEFINED. |
| 41 | 39 | ||
| 42 | -#define AT_SCALAR_TYPE_V214_ADDS(_) \ | 40 | +#define AT_SCALAR_TYPE_V214_ADDS(_) _(at::ScalarType::BComplex32, ACL_DT_UNDEFINED) |
| 43 | - _(at::ScalarType::BComplex32, ACL_DT_UNDEFINED) | ||
| 44 | 41 | ||
| 45 | 42 | ||
| 46 | 43 | ||
| @@ -96,61 +93,57 @@ AT_FORALL_SCALAR_TYPES_WITH_COMPLEX_AND_QINTS(ENUM_PAIR_FUNC) | |||
| 96 | _(at::ScalarType::Undefined, ACL_DT_UNDEFINED) \ | 93 | _(at::ScalarType::Undefined, ACL_DT_UNDEFINED) \ |
| 97 | _(at::ScalarType::NumOptions, ACL_DT_UNDEFINED) | 94 | _(at::ScalarType::NumOptions, ACL_DT_UNDEFINED) |
| 98 | 95 | ||
| 99 | -constexpr aclDataType kATenScalarTypeToAclDataTypeTable | 96 | +constexpr aclDataType kATenScalarTypeToAclDataTypeTable[static_cast<int64_t>(at::ScalarType::NumOptions) + 1] = { |
| 100 | - [static_cast<int64_t>(at::ScalarType::NumOptions) + 1] = { | ||
| 101 | 97 | ||
| 102 | - AT_ALL_SCALAR_TYPE_AND_ACL_DATATYPE_PAIR(DEFINE_ENUM) | 98 | + AT_ALL_SCALAR_TYPE_AND_ACL_DATATYPE_PAIR(DEFINE_ENUM) |
| 103 | 99 | ||
| 104 | }; | 100 | }; |
| 105 | 101 | ||
| 106 | // check at::ScalarType has been changed or not | 102 | // check at::ScalarType has been changed or not |
| 107 | -#define ENUM_PAIR_FUNC(at_dtype, acl_dtype) \ | 103 | +#define ENUM_PAIR_FUNC(at_dtype, acl_dtype) \ |
| 108 | - static_assert( \ | 104 | + static_assert( \ |
| 109 | - kATenScalarTypeToAclDataTypeTable[static_cast<int64_t>(at_dtype)] == \ | 105 | + kATenScalarTypeToAclDataTypeTable[static_cast<int64_t>(at_dtype)] == (acl_dtype), \ |
| 110 | - (acl_dtype), \ | 106 | + #at_dtype " and " #acl_dtype \ |
| 111 | - #at_dtype " and " #acl_dtype \ | 107 | + " is not match any more, please check " \ |
| 112 | - " is not match any more, please check " \ | ||
| 113 | "AT_ALL_SCALAR_TYPE_AND_ACL_DATATYPE_PAIR and modify it"); | 108 | "AT_ALL_SCALAR_TYPE_AND_ACL_DATATYPE_PAIR and modify it"); |
| 114 | AT_ALL_SCALAR_TYPE_AND_ACL_DATATYPE_PAIR(ENUM_PAIR_FUNC) | 109 | AT_ALL_SCALAR_TYPE_AND_ACL_DATATYPE_PAIR(ENUM_PAIR_FUNC) |
| 115 | 110 | ||
| 116 | 111 | ||
| 117 | -static std::map<const std::string, const aclDataType> | 112 | +static std::map<const std::string, const aclDataType> STRING_SCALAR_TYPE_TO_ACL_TYPE_MAP = { |
| 118 | - STRING_SCALAR_TYPE_TO_ACL_TYPE_MAP = { | 113 | + {"uint16", ACL_UINT16}, |
| 119 | - {"uint16", ACL_UINT16}, | 114 | + {"uint8", ACL_UINT8}, |
| 120 | - {"uint8", ACL_UINT8}, | 115 | + {"uint64", ACL_UINT64}, |
| 121 | - {"uint64", ACL_UINT64}, | 116 | + {"string", ACL_STRING}}; |
| 122 | - {"string", ACL_STRING}}; | ||
| 123 | 117 | ||
| 124 | -static std::unordered_map<const aclDataType, const at::ScalarType> | 118 | +static std::unordered_map<const aclDataType, const at::ScalarType> ACL_TYPE_TO_SCALAR_TYPE_MAP = { |
| 125 | - ACL_TYPE_TO_SCALAR_TYPE_MAP = { | 119 | + {ACL_DT_UNDEFINED, at::ScalarType::Undefined}, |
| 126 | - {ACL_DT_UNDEFINED, at::ScalarType::Undefined}, | 120 | + {ACL_FLOAT, at::ScalarType::Float}, |
| 127 | - {ACL_FLOAT, at::ScalarType::Float}, | 121 | + {ACL_FLOAT16, at::ScalarType::Half}, |
| 128 | - {ACL_FLOAT16, at::ScalarType::Half}, | 122 | + {ACL_INT8, at::ScalarType::Char}, |
| 129 | - {ACL_INT8, at::ScalarType::Char}, | 123 | + {ACL_INT32, at::ScalarType::Int}, |
| 130 | - {ACL_INT32, at::ScalarType::Int}, | 124 | + {ACL_UINT8, at::ScalarType::Byte}, |
| 131 | - {ACL_UINT8, at::ScalarType::Byte}, | 125 | + {ACL_INT16, at::ScalarType::Short}, |
| 132 | - {ACL_INT16, at::ScalarType::Short}, | 126 | + {ACL_UINT16, at::ScalarType::UInt16}, |
| 133 | - {ACL_UINT16, at::ScalarType::UInt16}, | 127 | + {ACL_UINT32, at::ScalarType::UInt32}, |
| 134 | - {ACL_UINT32, at::ScalarType::UInt32}, | 128 | + {ACL_INT64, at::ScalarType::Long}, |
| 135 | - {ACL_INT64, at::ScalarType::Long}, | 129 | + {ACL_UINT64, at::ScalarType::UInt64}, |
| 136 | - {ACL_UINT64, at::ScalarType::UInt64}, | 130 | + {ACL_DOUBLE, at::ScalarType::Double}, |
| 137 | - {ACL_DOUBLE, at::ScalarType::Double}, | 131 | + {ACL_BOOL, at::ScalarType::Bool}, |
| 138 | - {ACL_BOOL, at::ScalarType::Bool}, | 132 | + {ACL_STRING, at::ScalarType::Undefined}, |
| 139 | - {ACL_STRING, at::ScalarType::Undefined}, | 133 | + {ACL_COMPLEX64, at::ScalarType::ComplexFloat}, |
| 140 | - {ACL_COMPLEX64, at::ScalarType::ComplexFloat}, | 134 | + {ACL_COMPLEX128, at::ScalarType::ComplexDouble}, |
| 141 | - {ACL_COMPLEX128, at::ScalarType::ComplexDouble}, | 135 | + {ACL_BF16, at::ScalarType::BFloat16}, |
| 142 | - {ACL_BF16, at::ScalarType::BFloat16}, | 136 | + {ACL_INT4, at::ScalarType::Undefined}, |
| 143 | - {ACL_INT4, at::ScalarType::Undefined}, | 137 | + {ACL_UINT1, at::ScalarType::Undefined}, |
| 144 | - {ACL_UINT1, at::ScalarType::Undefined}, | 138 | + {ACL_COMPLEX32, at::ScalarType::ComplexHalf}, |
| 145 | - {ACL_COMPLEX32, at::ScalarType::ComplexHalf}, | 139 | + {ACL_HIFLOAT8, at::ScalarType::Byte}, |
| 146 | - {ACL_HIFLOAT8, at::ScalarType::Byte}, | 140 | + {ACL_FLOAT8_E5M2, at::ScalarType::Float8_e5m2}, |
| 147 | - {ACL_FLOAT8_E5M2, at::ScalarType::Float8_e5m2}, | 141 | + {ACL_FLOAT8_E4M3FN, at::ScalarType::Float8_e4m3fn}, |
| 148 | - {ACL_FLOAT8_E4M3FN, at::ScalarType::Float8_e4m3fn}, | 142 | + {ACL_FLOAT8_E8M0, at::ScalarType::Float8_e8m0fnu}, |
| 149 | - {ACL_FLOAT8_E8M0, at::ScalarType::Float8_e8m0fnu}, | 143 | + {ACL_FLOAT6_E3M2, at::ScalarType::Byte}, |
| 150 | - {ACL_FLOAT6_E3M2, at::ScalarType::Byte}, | 144 | + {ACL_FLOAT6_E2M3, at::ScalarType::Byte}, |
| 151 | - {ACL_FLOAT6_E2M3, at::ScalarType::Byte}, | 145 | + {ACL_FLOAT4_E2M1, at::ScalarType::Float4_e2m1fn_x2}, |
| 152 | - {ACL_FLOAT4_E2M1, at::ScalarType::Float4_e2m1fn_x2}, | 146 | + {ACL_FLOAT4_E1M2, at::ScalarType::Byte}}; |
| 153 | - {ACL_FLOAT4_E1M2, at::ScalarType::Byte}}; | ||
| 154 | 147 | ||
| 155 | aclError AclrtMemcpyAsyncParamCheck( | 148 | aclError AclrtMemcpyAsyncParamCheck( |
| 156 | void* dst, | 149 | void* dst, |
| @@ -163,12 +156,7 @@ aclError AclrtMemcpyAsyncParamCheck( | |||
| 163 | return ret; | 156 | return ret; |
| 164 | } | 157 | } |
| 165 | 158 | ||
| 166 | -aclError AclrtMemcpyParamCheck( | 159 | +aclError AclrtMemcpyParamCheck(void* dst, size_t destMax, const void* src, size_t count, aclrtMemcpyKind kind) { |
| 167 | - void* dst, | ||
| 168 | - size_t destMax, | ||
| 169 | - const void* src, | ||
| 170 | - size_t count, | ||
| 171 | - aclrtMemcpyKind kind) { | ||
| 172 | auto ret = aclrtMemcpy(dst, destMax, src, count, kind); | 160 | auto ret = aclrtMemcpy(dst, destMax, src, count, kind); |
| 173 | return ret; | 161 | return ret; |
| 174 | } | 162 | } |
| @@ -179,8 +167,7 @@ namespace native { | |||
| 179 | aclDataType CalcuOpUtil::ConvertToAclDataType(const at::ScalarType& data_type) { | 167 | aclDataType CalcuOpUtil::ConvertToAclDataType(const at::ScalarType& data_type) { |
| 180 | int64_t dtype_index = static_cast<int64_t>(data_type); | 168 | int64_t dtype_index = static_cast<int64_t>(data_type); |
| 181 | TORCH_CHECK( | 169 | TORCH_CHECK( |
| 182 | - dtype_index >= 0 && | 170 | + dtype_index >= 0 && dtype_index < static_cast<int64_t>(at::ScalarType::NumOptions) + 1, |
| 183 | - dtype_index < static_cast<int64_t>(at::ScalarType::NumOptions) + 1, | ||
| 184 | "data_type enum value (", | 171 | "data_type enum value (", |
| 185 | dtype_index, | 172 | dtype_index, |
| 186 | ") is out of range: [0, ", | 173 | ") is out of range: [0, ", |
| @@ -195,13 +182,10 @@ aclDataType CalcuOpUtil::ConvertToAclDataType(const at::ScalarType& data_type) { | |||
| 195 | return acl_dtype; | 182 | return acl_dtype; |
| 196 | } | 183 | } |
| 197 | 184 | ||
| 198 | -aclDataType CalcuOpUtil::ConvertToAclDataType( | 185 | +aclDataType CalcuOpUtil::ConvertToAclDataType(const at::ScalarType& data_type, const std::string& realDataType) { |
| 199 | - const at::ScalarType& data_type, | ||
| 200 | - const std::string& realDataType) { | ||
| 201 | int64_t dtype_index = static_cast<int64_t>(data_type); | 186 | int64_t dtype_index = static_cast<int64_t>(data_type); |
| 202 | TORCH_CHECK( | 187 | TORCH_CHECK( |
| 203 | - dtype_index >= 0 && | 188 | + dtype_index >= 0 && dtype_index < static_cast<int64_t>(at::ScalarType::NumOptions) + 1, |
| 204 | - dtype_index < static_cast<int64_t>(at::ScalarType::NumOptions) + 1, | ||
| 205 | "data_type enum value (", | 189 | "data_type enum value (", |
| 206 | dtype_index, | 190 | dtype_index, |
| 207 | ") is out of range: [0, ", | 191 | ") is out of range: [0, ", |
| @@ -250,11 +234,8 @@ c10::Scalar CalcuOpUtil::ConvertTensorToScalar(const at::Tensor& tensor) { | |||
| 250 | return expScalar; | 234 | return expScalar; |
| 251 | } | 235 | } |
| 252 | 236 | ||
| 253 | -at::Tensor CalcuOpUtil::CopyScalarToDevice( | 237 | +at::Tensor CalcuOpUtil::CopyScalarToDevice(const c10::Scalar& cpu_scalar, at::ScalarType scalar_data_type) { |
| 254 | - const c10::Scalar& cpu_scalar, | 238 | + return CalcuOpUtil::CopyTensorHostToDevice(scalar_to_tensor(cpu_scalar).to(scalar_data_type)); |
| 255 | - at::ScalarType scalar_data_type) { | ||
| 256 | - return CalcuOpUtil::CopyTensorHostToDevice( | ||
| 257 | - scalar_to_tensor(cpu_scalar).to(scalar_data_type)); | ||
| 258 | } | 239 | } |
| 259 | 240 | ||
| 260 | at::Tensor CalcuOpUtil::CopyTensorHostToDevice(const at::Tensor& cpu_tensor) { | 241 | at::Tensor CalcuOpUtil::CopyTensorHostToDevice(const at::Tensor& cpu_tensor) { |
| @@ -262,10 +243,7 @@ at::Tensor CalcuOpUtil::CopyTensorHostToDevice(const at::Tensor& cpu_tensor) { | |||
| 262 | int deviceIndex = 0; | 243 | int deviceIndex = 0; |
| 263 | NPU_CHECK_ERROR(c10_npu::GetDevice(&deviceIndex)); | 244 | NPU_CHECK_ERROR(c10_npu::GetDevice(&deviceIndex)); |
| 264 | return cpuPinMemTensor.to( | 245 | return cpuPinMemTensor.to( |
| 265 | - c10::Device(c10::DeviceType::PrivateUse1, deviceIndex), | 246 | + c10::Device(c10::DeviceType::PrivateUse1, deviceIndex), cpuPinMemTensor.scalar_type(), true, true); |
| 266 | - cpuPinMemTensor.scalar_type(), | ||
| 267 | - true, | ||
| 268 | - true); | ||
| 269 | } | 247 | } |
| 270 | 248 | ||
| 271 | NPUStatus CalcuOpUtil::AclrtMemcpyAsync( | 249 | NPUStatus CalcuOpUtil::AclrtMemcpyAsync( |
| @@ -274,12 +252,9 @@ NPUStatus CalcuOpUtil::AclrtMemcpyAsync( | |||
| 274 | const std::pair<at::Tensor, int64_t>& src, | 252 | const std::pair<at::Tensor, int64_t>& src, |
| 275 | size_t src_size, | 253 | size_t src_size, |
| 276 | aclrtMemcpyKind kind) { | 254 | aclrtMemcpyKind kind) { |
| 277 | - void* dst_ptr = reinterpret_cast<uint8_t*>(dst.first.data_ptr()) + | 255 | + void* dst_ptr = reinterpret_cast<uint8_t*>(dst.first.data_ptr()) + dst.second * dst.first.itemsize(); |
| 278 | - dst.second * dst.first.itemsize(); | 256 | + void* src_ptr = reinterpret_cast<uint8_t*>(src.first.data_ptr()) + src.second * src.first.itemsize(); |
| 279 | - void* src_ptr = reinterpret_cast<uint8_t*>(src.first.data_ptr()) + | 257 | + NPU_CHECK_ERROR(c10_npu::queue::LaunchAsyncCopyTask(dst_ptr, dst_size, const_cast<void*>(src_ptr), src_size, kind)); |
| 280 | - src.second * src.first.itemsize(); | ||
| 281 | - NPU_CHECK_ERROR(c10_npu::queue::LaunchAsyncCopyTask( | ||
| 282 | - dst_ptr, dst_size, const_cast<void*>(src_ptr), src_size, kind)); | ||
| 283 | 258 | ||
| 284 | return NPU_STATUS_SUCCESS; | 259 | return NPU_STATUS_SUCCESS; |
| 285 | } | 260 | } |
| @@ -290,12 +265,9 @@ aclError CalcuOpUtil::AclrtMemcpyWithModeSwitch( | |||
| 290 | const StorageAndOffsetMemSizePair& src, | 265 | const StorageAndOffsetMemSizePair& src, |
| 291 | size_t count, | 266 | size_t count, |
| 292 | aclrtMemcpyKind kind) { | 267 | aclrtMemcpyKind kind) { |
| 293 | - void* dst_ptr = static_cast<void*>( | 268 | + void* dst_ptr = static_cast<void*>(static_cast<uint8_t*>(const_cast<void*>(dst.first->data())) + dst.second); |
| 294 | - static_cast<uint8_t*>(const_cast<void*>(dst.first->data())) + dst.second); | 269 | + void* src_ptr = static_cast<void*>(static_cast<uint8_t*>(const_cast<void*>(src.first->data())) + src.second); |
| 295 | - void* src_ptr = static_cast<void*>( | 270 | + return AclrtMemcpyParamCheck(dst_ptr, dstMax, const_cast<void*>(src_ptr), count, kind); |
| 296 | - static_cast<uint8_t*>(const_cast<void*>(src.first->data())) + src.second); | ||
| 297 | - return AclrtMemcpyParamCheck( | ||
| 298 | - dst_ptr, dstMax, const_cast<void*>(src_ptr), count, kind); | ||
| 299 | } | 271 | } |
| 300 | 272 | ||
| 301 | aclError CalcuOpUtil::AclrtMemcpyWithModeSwitch( | 273 | aclError CalcuOpUtil::AclrtMemcpyWithModeSwitch( |
| @@ -304,8 +276,7 @@ aclError CalcuOpUtil::AclrtMemcpyWithModeSwitch( | |||
| 304 | const void* src, | 276 | const void* src, |
| 305 | size_t count, | 277 | size_t count, |
| 306 | aclrtMemcpyKind kind) { | 278 | aclrtMemcpyKind kind) { |
| 307 | - void* dst_ptr = static_cast<void*>( | 279 | + void* dst_ptr = static_cast<void*>(static_cast<uint8_t*>(const_cast<void*>(dst.first->data())) + dst.second); |
| 308 | - static_cast<uint8_t*>(const_cast<void*>(dst.first->data())) + dst.second); | ||
| 309 | return AclrtMemcpyParamCheck(dst_ptr, dstMax, src, count, kind); | 280 | return AclrtMemcpyParamCheck(dst_ptr, dstMax, src, count, kind); |
| 310 | } | 281 | } |
| 311 | 282 | ||
| @@ -315,10 +286,8 @@ aclError CalcuOpUtil::AclrtMemcpyWithModeSwitch( | |||
| 315 | const StorageAndOffsetMemSizePair& src, | 286 | const StorageAndOffsetMemSizePair& src, |
| 316 | size_t count, | 287 | size_t count, |
| 317 | aclrtMemcpyKind kind) { | 288 | aclrtMemcpyKind kind) { |
| 318 | - void* src_ptr = static_cast<void*>( | 289 | + void* src_ptr = static_cast<void*>(static_cast<uint8_t*>(const_cast<void*>(src.first->data())) + src.second); |
| 319 | - static_cast<uint8_t*>(const_cast<void*>(src.first->data())) + src.second); | 290 | + return AclrtMemcpyParamCheck(dst, dstMax, const_cast<void*>(src_ptr), count, kind); |
| 320 | - return AclrtMemcpyParamCheck( | ||
| 321 | - dst, dstMax, const_cast<void*>(src_ptr), count, kind); | ||
| 322 | } | 291 | } |
| 323 | 292 | ||
| 324 | aclError CalcuOpUtil::LaunchAsyncCopyTaskWithModeSwitch( | 293 | aclError CalcuOpUtil::LaunchAsyncCopyTaskWithModeSwitch( |
| @@ -327,8 +296,7 @@ aclError CalcuOpUtil::LaunchAsyncCopyTaskWithModeSwitch( | |||
| 327 | const at::Tensor& src, | 296 | const at::Tensor& src, |
| 328 | size_t count, | 297 | size_t count, |
| 329 | aclrtMemcpyKind kind) { | 298 | aclrtMemcpyKind kind) { |
| 330 | - aclError ret = c10_npu::queue::LaunchAsyncCopyTask( | 299 | + aclError ret = c10_npu::queue::LaunchAsyncCopyTask(dst.data_ptr(), dstMax, src.data_ptr(), count, kind); |
| 331 | - dst.data_ptr(), dstMax, src.data_ptr(), count, kind); | ||
| 332 | return ret; | 300 | return ret; |
| 333 | } | 301 | } |
| 334 | 302 | ||
| @@ -338,8 +306,7 @@ aclError CalcuOpUtil::LaunchAsyncCopyTaskWithModeSwitch( | |||
| 338 | void* src, | 306 | void* src, |
| 339 | size_t count, | 307 | size_t count, |
| 340 | aclrtMemcpyKind kind) { | 308 | aclrtMemcpyKind kind) { |
| 341 | - aclError ret = c10_npu::queue::LaunchAsyncCopyTask( | 309 | + aclError ret = c10_npu::queue::LaunchAsyncCopyTask(const_cast<void*>(dst.data()), dstMax, src, count, kind); |
| 342 | - const_cast<void*>(dst.data()), dstMax, src, count, kind); | ||
| 343 | return ret; | 310 | return ret; |
| 344 | } | 311 | } |
| 345 | 312 | ||
| @@ -351,8 +318,7 @@ int64_t CalcuOpUtil::GetTensorNpuFormat(const at::Tensor& tensor) { | |||
| 351 | "device is correct.", | 318 | "device is correct.", |
| 352 | OPS_ERROR(ErrCode::TYPE)); | 319 | OPS_ERROR(ErrCode::TYPE)); |
| 353 | if (NpuUtils::check_match(&tensor) || NpuUtils::check_5d_5d_match(tensor)) { | 320 | if (NpuUtils::check_match(&tensor) || NpuUtils::check_5d_5d_match(tensor)) { |
| 354 | - const torch_npu::NPUStorageDesc& tensor_desc = | 321 | + const torch_npu::NPUStorageDesc& tensor_desc = torch_npu::NPUBridge::GetNpuStorageImpl(tensor)->npu_desc_; |
| 355 | - torch_npu::NPUBridge::GetNpuStorageImpl(tensor)->npu_desc_; | ||
| 356 | return tensor_desc.npu_format_; | 322 | return tensor_desc.npu_format_; |
| 357 | } else if (tensor.data_ptr() == nullptr) { | 323 | } else if (tensor.data_ptr() == nullptr) { |
| 358 | // transforming faketensor into realtensor and assigning format ND | 324 | // transforming faketensor into realtensor and assigning format ND |
| @@ -362,9 +328,7 @@ int64_t CalcuOpUtil::GetTensorNpuFormat(const at::Tensor& tensor) { | |||
| 362 | } | 328 | } |
| 363 | } | 329 | } |
| 364 | 330 | ||
| 365 | -void CalcuOpUtil::CheckMemoryOverLaps( | 331 | +void CalcuOpUtil::CheckMemoryOverLaps(c10::ArrayRef<at::Tensor> inputs, c10::ArrayRef<at::Tensor> outputs) { |
| 366 | - c10::ArrayRef<at::Tensor> inputs, | ||
| 367 | - c10::ArrayRef<at::Tensor> outputs) { | ||
| 368 | for (const auto i : c10::irange(outputs.size())) { | 332 | for (const auto i : c10::irange(outputs.size())) { |
| 369 | if (!outputs[i].defined()) { | 333 | if (!outputs[i].defined()) { |
| 370 | continue; | 334 | continue; |
| @@ -379,8 +343,7 @@ void CalcuOpUtil::CheckMemoryOverLaps( | |||
| 379 | } | 343 | } |
| 380 | 344 | ||
| 381 | bool CalcuOpUtil::IsScalarWrappedToTensor(const at::Tensor& tensor) { | 345 | bool CalcuOpUtil::IsScalarWrappedToTensor(const at::Tensor& tensor) { |
| 382 | - return tensor.unsafeGetTensorImpl()->is_wrapped_number() && | 346 | + return tensor.unsafeGetTensorImpl()->is_wrapped_number() && (!torch_npu::utils::is_npu(tensor)); |
| 383 | - (!torch_npu::utils::is_npu(tensor)); | ||
| 384 | } | 347 | } |
| 385 | 348 | ||
| 386 | float CalcuOpUtil::GetScalarFloatValue(const c10::Scalar& scalar) { | 349 | float CalcuOpUtil::GetScalarFloatValue(const c10::Scalar& scalar) { |
| @@ -394,8 +357,7 @@ float CalcuOpUtil::GetScalarFloatValue(const c10::Scalar& scalar) { | |||
| 394 | return value; | 357 | return value; |
| 395 | } | 358 | } |
| 396 | 359 | ||
| 397 | -c10::SmallVector<int64_t, SHAPE_SIZE> CalcuOpUtil:: | 360 | +c10::SmallVector<int64_t, SHAPE_SIZE> CalcuOpUtil::ConvertIntArrayRefToSmallVector(c10::IntArrayRef intArray) { |
| 398 | - ConvertIntArrayRefToSmallVector(c10::IntArrayRef intArray) { | ||
| 399 | c10::SmallVector<int64_t, SHAPE_SIZE> intVec; | 361 | c10::SmallVector<int64_t, SHAPE_SIZE> intVec; |
| 400 | for (const auto i : c10::irange(intArray.size())) { | 362 | for (const auto i : c10::irange(intArray.size())) { |
| 401 | intVec.emplace_back(intArray[i]); | 363 | intVec.emplace_back(intArray[i]); |
| @@ -419,19 +381,13 @@ static std::unordered_map<uint8_t, aclCubeMathType> ACL_CUBE_MATH_TYPE_MAP = { | |||
| 419 | {0b10, USE_HF32}, | 381 | {0b10, USE_HF32}, |
| 420 | {0b11, ALLOW_FP32_DOWN_PRECISION}}; | 382 | {0b11, ALLOW_FP32_DOWN_PRECISION}}; |
| 421 | 383 | ||
| 422 | -static std::unordered_map<uint8_t, aclCubeMathType> | 384 | +static std::unordered_map<uint8_t, aclCubeMathType> ACL_CUBE_MATH_TYPE_MAP_PASSTHROUGH = |
| 423 | - ACL_CUBE_MATH_TYPE_MAP_PASSTHROUGH = { | 385 | + {{0b00, KEEP_DTYPE}, {0b01, ALLOW_FP32_DOWN_PRECISION}, {0b10, USE_FP16}, {0b11, USE_HF32}, {0b100, USE_FP32_ADD}}; |
| 424 | - {0b00, KEEP_DTYPE}, | ||
| 425 | - {0b01, ALLOW_FP32_DOWN_PRECISION}, | ||
| 426 | - {0b10, USE_FP16}, | ||
| 427 | - {0b11, USE_HF32}, | ||
| 428 | - {0b100, USE_FP32_ADD}}; | ||
| 429 | 386 | ||
| 430 | int8_t CalcuOpUtil::GetCubeMathType() { | 387 | int8_t CalcuOpUtil::GetCubeMathType() { |
| 431 | auto option_key = c10_npu::option::GetOption(CUBE_MATH_TYPE); | 388 | auto option_key = c10_npu::option::GetOption(CUBE_MATH_TYPE); |
| 432 | if (option_key.has_value() && !option_key.value().empty()) { | 389 | if (option_key.has_value() && !option_key.value().empty()) { |
| 433 | - uint8_t cube_math_type = | 390 | + uint8_t cube_math_type = static_cast<uint8_t>(std::stoi(option_key.value().c_str())); |
| 434 | - static_cast<uint8_t>(std::stoi(option_key.value().c_str())); | ||
| 435 | auto iter = ACL_CUBE_MATH_TYPE_MAP_PASSTHROUGH.find(cube_math_type); | 391 | auto iter = ACL_CUBE_MATH_TYPE_MAP_PASSTHROUGH.find(cube_math_type); |
| 436 | if (iter != ACL_CUBE_MATH_TYPE_MAP_PASSTHROUGH.end()) { | 392 | if (iter != ACL_CUBE_MATH_TYPE_MAP_PASSTHROUGH.end()) { |
| 437 | return iter->second; | 393 | return iter->second; |
| @@ -442,8 +398,7 @@ int8_t CalcuOpUtil::GetCubeMathType() { | |||
| 442 | 398 | ||
| 443 | int8_t CalcuOpUtil::GetCubeMathType(bool allowHf32) { | 399 | int8_t CalcuOpUtil::GetCubeMathType(bool allowHf32) { |
| 444 | bool allowFp32ToFp16 = native::env::IsAllowFP32ToFP16(); | 400 | bool allowFp32ToFp16 = native::env::IsAllowFP32ToFP16(); |
| 445 | - uint8_t CubeMathTypeCode = (static_cast<uint8_t>(allowHf32) << 1) + | 401 | + uint8_t CubeMathTypeCode = (static_cast<uint8_t>(allowHf32) << 1) + static_cast<uint8_t>(allowFp32ToFp16); |
| 446 | - static_cast<uint8_t>(allowFp32ToFp16); | ||
| 447 | auto iter = ACL_CUBE_MATH_TYPE_MAP.find(CubeMathTypeCode); | 402 | auto iter = ACL_CUBE_MATH_TYPE_MAP.find(CubeMathTypeCode); |
| 448 | if (iter == ACL_CUBE_MATH_TYPE_MAP.end()) { | 403 | if (iter == ACL_CUBE_MATH_TYPE_MAP.end()) { |
| 449 | return ALLOW_FP32_DOWN_PRECISION; | 404 | return ALLOW_FP32_DOWN_PRECISION; |
| @@ -456,8 +411,7 @@ at::ScalarType CalcuOpUtil::ConvertToScalarType(const aclDataType data_type) { | |||
| 456 | if (iter == ACL_TYPE_TO_SCALAR_TYPE_MAP.end()) { | 411 | if (iter == ACL_TYPE_TO_SCALAR_TYPE_MAP.end()) { |
| 457 | TORCH_CHECK( | 412 | TORCH_CHECK( |
| 458 | false, | 413 | false, |
| 459 | - std::string("aclDataType:") + std::to_string(data_type) + | 414 | + std::string("aclDataType:") + std::to_string(data_type) + " has not been supported", |
| 460 | - " has not been supported", | ||
| 461 | OPS_ERROR(ErrCode::NOT_SUPPORT)) | 415 | OPS_ERROR(ErrCode::NOT_SUPPORT)) |
| 462 | } | 416 | } |
| 463 | 417 | ||
| @@ -13,8 +13,8 @@ | |||
| 13 | 13 | ||
| 14 | 14 | ||
| 15 | 15 | ||
| 16 | -#include "third_party/acl/inc/acl/acl_base.h" | 16 | +#include <acl/acl_base.h> |
| 17 | -#include "third_party/acl/inc/acl/acl.h" | 17 | +#include <acl/acl.h> |
| 18 | 18 | ||
| 19 | using std::string; | 19 | using std::string; |
| 20 | using std::vector; | 20 | using std::vector; |
| @@ -2,7 +2,7 @@ | |||
| 2 | 2 | ||
| 3 | 3 | ||
| 4 | 4 | ||
| 5 | -#include <third_party/acl/inc/graph/operator.h> | 5 | +#include <graph/operator.h> |
| 6 | 6 | ||
| 7 | 7 | ||
| 8 | 8 | ||
| @@ -7,9 +7,9 @@ | |||
| 7 | 7 | ||
| 8 | 8 | ||
| 9 | 9 | ||
| 10 | -#include "third_party/acl/inc/acl/acl.h" | 10 | +#include <acl/acl.h> |
| 11 | -#include "third_party/acl/inc/acl/acl_base.h" | 11 | +#include <acl/acl_base.h> |
| 12 | -#include "third_party/acl/inc/acl/acl_op.h" | 12 | +#include <acl/acl_op.h> |
| 13 | 13 | ||
| 14 | 14 | ||
| 15 | 15 | ||
| @@ -2,8 +2,8 @@ | |||
| 2 | 2 | ||
| 3 | 3 | ||
| 4 | 4 | ||
| 5 | -#include "third_party/acl/inc/acl/acl_base.h" | 5 | +#include <acl/acl_base.h> |
| 6 | -#include "third_party/acl/inc/acl/acl_rt.h" | 6 | +#include <acl/acl_rt.h> |
| 7 | 7 | ||
| 8 | typedef void* NPUdeviceptr; | 8 | typedef void* NPUdeviceptr; |
| 9 | 9 | ||
| @@ -6,7 +6,7 @@ | |||
| 6 | // C ABI defined in torch_npu/csrc/inductor/aoti_torch/c/shim.h. The same rule | 6 | // C ABI defined in torch_npu/csrc/inductor/aoti_torch/c/shim.h. The same rule |
| 7 | // applies to other files under torch_npu/csrc/inductor/aoti_runtime/. | 7 | // applies to other files under torch_npu/csrc/inductor/aoti_runtime/. |
| 8 | 8 | ||
| 9 | -#include <third_party/acl/inc/acl/acl_base.h> | 9 | +#include <acl/acl_base.h> |
| 10 | 10 | ||
| 11 | 11 | ||
| 12 | namespace torch::aot_inductor { | 12 | namespace torch::aot_inductor { |
| @@ -8,8 +8,8 @@ | |||
| 8 | 8 | ||
| 9 | 9 | ||
| 10 | 10 | ||
| 11 | -#include "third_party/acl/inc/profiling/prof_api.h" | 11 | +#include <profiling/prof_api.h> |
| 12 | -#include "third_party/acl/inc/profiling/prof_common.h" | 12 | +#include <profiling/prof_common.h> |
| 13 | 13 | ||
| 14 | struct TilingMem { | 14 | struct TilingMem { |
| 15 | std::unique_ptr<void, decltype(&aclrtFreeHost)> arg_tiling_host; | 15 | std::unique_ptr<void, decltype(&aclrtFreeHost)> arg_tiling_host; |
| @@ -1,8 +1,8 @@ | |||
| 1 | 1 | ||
| 2 | 2 | ||
| 3 | 3 | ||
| 4 | -#include "third_party/acl/inc/acl/acl_base.h" | 4 | +#include <acl/acl_base.h> |
| 5 | -#include "third_party/acl/inc/acl/acl_rt.h" | 5 | +#include <acl/acl_rt.h> |
| 6 | 6 | ||
| 7 | 7 | ||
| 8 | rtError_t common_launch( | 8 | rtError_t common_launch( |
| @@ -8,8 +8,8 @@ | |||
| 8 | 8 | ||
| 9 | 9 | ||
| 10 | 10 | ||
| 11 | -#include "third_party/acl/inc/acl/acl_base.h" | 11 | +#include <acl/acl_base.h> |
| 12 | -#include "third_party/acl/inc/acl/acl_rt.h" | 12 | +#include <acl/acl_rt.h> |
| 13 | 13 | ||
| 14 | namespace torch_npu { | 14 | namespace torch_npu { |
| 15 | namespace ipc { | 15 | namespace ipc { |
| @@ -22,8 +22,8 @@ | |||
| 22 | 22 | ||
| 23 | 23 | ||
| 24 | 24 | ||
| 25 | -#include "third_party/acl/inc/acl/acl_base.h" | 25 | +#include <acl/acl_base.h> |
| 26 | -#include "third_party/acl/inc/acl/acl_rt.h" | 26 | +#include <acl/acl_rt.h> |
| 27 | 27 | ||
| 28 | namespace torch_npu { | 28 | namespace torch_npu { |
| 29 | namespace reductions { | 29 | namespace reductions { |
| @@ -5,9 +5,9 @@ | |||
| 5 | 5 | ||
| 6 | 6 | ||
| 7 | 7 | ||
| 8 | -#include "third_party/acl/inc/acl/acl_base.h" | 8 | +#include <acl/acl_base.h> |
| 9 | -#include "third_party/acl/inc/acl/acl_rt.h" | 9 | +#include <acl/acl_rt.h> |
| 10 | -#include "third_party/acl/inc/acl/super_kernel.h" | 10 | +#include <acl/super_kernel.h> |
| 11 | 11 | ||
| 12 | struct PendingTensorData { | 12 | struct PendingTensorData { |
| 13 | PendingTensorData(uintptr_t dataPtr, Py_ssize_t nbytes, PyObject* shape, PyObject* dtype) | 13 | PendingTensorData(uintptr_t dataPtr, Py_ssize_t nbytes, PyObject* shape, PyObject* dtype) |
| @@ -27,7 +27,7 @@ | |||
| 27 | 27 | ||
| 28 | 28 | ||
| 29 | 29 | ||
| 30 | -#include <third_party/acl/inc/acl/acl.h> | 30 | +#include <acl/acl.h> |
| 31 | 31 | ||
| 32 | 32 | ||
| 33 | 33 | ||
| @@ -3,9 +3,9 @@ | |||
| 3 | 3 | ||
| 4 | 4 | ||
| 5 | 5 | ||
| 6 | -#include "third_party/acl/inc/acl/acl.h" | 6 | +#include <acl/acl.h> |
| 7 | -#include "third_party/acl/inc/acl/acl_base.h" | 7 | +#include <acl/acl_base.h> |
| 8 | -#include "third_party/acl/inc/acl/acl_rt.h" | 8 | +#include <acl/acl_rt.h> |
| 9 | 9 | ||
| 10 | 10 | ||
| 11 | 11 | ||
| @@ -7,7 +7,7 @@ | |||
| 7 | 7 | ||
| 8 | 8 | ||
| 9 | 9 | ||
| 10 | -#include "third_party/acl/inc/acl/acl_prof.h" | 10 | +#include <acl/acl_prof.h> |
| 11 | 11 | ||
| 12 | 12 | ||
| 13 | 13 | ||
| @@ -7,8 +7,8 @@ | |||
| 7 | 7 | ||
| 8 | 8 | ||
| 9 | 9 | ||
| 10 | -#include "third_party/acl/inc/acl/acl_base.h" | 10 | +#include <acl/acl_base.h> |
| 11 | -#include "third_party/acl/inc/acl/acl_rt.h" | 11 | +#include <acl/acl_rt.h> |
| 12 | 12 | ||
| 13 | 13 | ||
| 14 | 14 | ||
| @@ -4,7 +4,7 @@ | |||
| 4 | 4 | ||
| 5 | 5 | ||
| 6 | 6 | ||
| 7 | -#include "third_party/acl/inc/acl/acl_prof.h" | 7 | +#include <acl/acl_prof.h> |
| 8 | 8 | ||
| 9 | 9 | ||
| 10 | 10 | ||
| @@ -7,7 +7,7 @@ | |||
| 7 | 7 | ||
| 8 | 8 | ||
| 9 | 9 | ||
| 10 | -#include "third_party/acl/inc/acl/acl_rt.h" | 10 | +#include <acl/acl_rt.h> |
| 11 | 11 | ||
| 12 | namespace torch_npu { | 12 | namespace torch_npu { |
| 13 | namespace profiler { | 13 | namespace profiler { |
| @@ -1,7 +1,6 @@ | |||
| 1 | import os | 1 | import os |
| 2 | import setuptools | 2 | import setuptools |
| 3 | 3 | ||
| 4 | -import torch | ||
| 5 | import torch.utils.cpp_extension as TorchExtension | 4 | import torch.utils.cpp_extension as TorchExtension |
| 6 | 5 | ||
| 7 | import torch_npu | 6 | import torch_npu |
| @@ -38,7 +37,6 @@ def NpuExtension(name, sources, *args, **kwargs): | |||
| 38 | torch_npu_dir = PYTORCH_NPU_INSTALL_PATH | 37 | torch_npu_dir = PYTORCH_NPU_INSTALL_PATH |
| 39 | include_dirs = kwargs.get('include_dirs', []) | 38 | include_dirs = kwargs.get('include_dirs', []) |
| 40 | include_dirs.append(os.path.join(torch_npu_dir, 'include')) | 39 | include_dirs.append(os.path.join(torch_npu_dir, 'include')) |
| 41 | - include_dirs.append(os.path.join(torch_npu_dir, 'include', 'third_party', 'acl', 'inc')) | ||
| 42 | include_dirs.append(os.path.join(torch_npu_dir, 'include', 'third_party', 'hccl', 'inc')) | 40 | include_dirs.append(os.path.join(torch_npu_dir, 'include', 'third_party', 'hccl', 'inc')) |
| 43 | include_dirs += TorchExtension.include_paths() | 41 | include_dirs += TorchExtension.include_paths() |
| 44 | kwargs['include_dirs'] = include_dirs | 42 | kwargs['include_dirs'] = include_dirs |