diff --git a/common/__init__.py b/ads/__init__.py similarity index 100% rename from common/__init__.py rename to ads/__init__.py diff --git a/ads/common/__init__.py b/ads/common/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..0249033a3c482d4e85a4d41e3879bfb0447097a1 --- /dev/null +++ b/ads/common/__init__.py @@ -0,0 +1 @@ +from .ops.scatter_max import scatter_max \ No newline at end of file diff --git a/common/components/README.md b/ads/common/components/README.md similarity index 98% rename from common/components/README.md rename to ads/common/components/README.md index 4fb297accc04fcc5bb00b284330d4fe51cdf649e..f1cf0540a17c9ebd79472f7ebcac5909a1bc078f 100644 --- a/common/components/README.md +++ b/ads/common/components/README.md @@ -1,2 +1,2 @@ -## Description +## Description + The folder contains some pytorch algorithm modules. \ No newline at end of file diff --git a/common/ops/CMakeLists.txt b/ads/common/ops/CMakeLists.txt similarity index 100% rename from common/ops/CMakeLists.txt rename to ads/common/ops/CMakeLists.txt diff --git a/motion/__init__.py b/ads/common/ops/__init__.py similarity index 100% rename from motion/__init__.py rename to ads/common/ops/__init__.py diff --git a/common/ops/csrc/README.md b/ads/common/ops/csrc/README.md similarity index 99% rename from common/ops/csrc/README.md rename to ads/common/ops/csrc/README.md index 5bac61ce9d5934bb387e54855e9112151ad795ae..ec025ef95be9e783d06ff25a95d006fa64a25e07 100644 --- a/common/ops/csrc/README.md +++ b/ads/common/ops/csrc/README.md @@ -1,2 +1,2 @@ -## Description +## Description + The folder contains some cpp source files, which provide codes for adaptation of ascend kernels. It provide links for kernels and cpp interfaces. \ No newline at end of file diff --git a/common/ops/csrc/ScatterMaxKernelNpu.cpp b/ads/common/ops/csrc/ScatterMaxKernelNpu.cpp similarity index 100% rename from common/ops/csrc/ScatterMaxKernelNpu.cpp rename to ads/common/ops/csrc/ScatterMaxKernelNpu.cpp diff --git a/common/ops/csrc/functions.h b/ads/common/ops/csrc/functions.h similarity index 88% rename from common/ops/csrc/functions.h rename to ads/common/ops/csrc/functions.h index 9371de3324b6719d0c798665fa24dde51c1088f6..d5b69716c3ede9e25ce5f65efc154aa523ae0e60 100644 --- a/common/ops/csrc/functions.h +++ b/ads/common/ops/csrc/functions.h @@ -1,5 +1,7 @@ #include #include +void init_common(pybind11::module &m); + std::tuple npu_scatter_max(const at::Tensor& updates, const at::Tensor& indices, c10::optional out); at::Tensor npu_scatter_max_backward(const at::Tensor& x, const at::Tensor& segment_ids, const at::Tensor& num_segments); diff --git a/common/ops/pybind.cpp b/ads/common/ops/csrc/pybind.cpp similarity index 67% rename from common/ops/pybind.cpp rename to ads/common/ops/csrc/pybind.cpp index f5ea46465c94e61586aff388207a280dbecd6103..7feba1dafff09ca39fcad22f7e609a08c3e19bbb 100644 --- a/common/ops/pybind.cpp +++ b/ads/common/ops/csrc/pybind.cpp @@ -1,7 +1,8 @@ #include -#include "csrc/functions.h" +#include "functions.h" -PYBIND11_MODULE(TORCH_EXTENSION_NAME, m) { +void init_common(pybind11::module &m) +{ m.def("npu_scatter_max", &npu_scatter_max); m.def("npu_scatter_max_backward", &npu_scatter_max_backward); } diff --git a/perception/fused/ops/kernels/README.md b/ads/common/ops/kernels/README.md similarity index 99% rename from perception/fused/ops/kernels/README.md rename to ads/common/ops/kernels/README.md index 7fc09008da55ec8f9e5fc10a0c9c61d93f928b59..214fb0a6d662e806bd7f6bdd1b8962bc1639026e 100644 --- a/perception/fused/ops/kernels/README.md +++ b/ads/common/ops/kernels/README.md @@ -1,2 +1,2 @@ -## Description +## Description + The folder contains some ascend-kernel source files, which are like cuda-kernels and supply some ops that can be run on ascend device. \ No newline at end of file diff --git a/common/modules.py b/ads/common/ops/scatter_max.py similarity index 84% rename from common/modules.py rename to ads/common/ops/scatter_max.py index 5d8b41335fda11ab57bb98b63126962ac785b155..1d613688e9c285876b7ee2d9f11285f897b26cd3 100644 --- a/common/modules.py +++ b/ads/common/ops/scatter_max.py @@ -3,13 +3,13 @@ from torch.autograd import Function from torch.nn import Module import torch_npu -import ads +import ads_c class ScatterMaxFunction(Function): @staticmethod def forward(ctx, updates, indices, out=None): - func = ads.npu_scatter_max + func = ads_c.npu_scatter_max out, argmax = func(updates, indices, out) ctx.save_for_backward(argmax, updates) return out, argmax @@ -25,8 +25,8 @@ class ScatterMaxFunction(Function): grad_updates_indices_uss = grad_updates_indices[..., 0] * grad_updates_indices.shape[1] + grad_updates_indices[..., 1] num_segments = torch.tensor(updates.shape[0] * updates.shape[1]).to(device) - grad = ads.npu_scatter_max_backward(grad_output, grad_updates_indices_uss, num_segments) + grad = ads_c.npu_scatter_max_backward(grad_output, grad_updates_indices_uss, num_segments) return grad.reshape(updates.shape), None, None -npuscattermax = ScatterMaxFunction.apply +scatter_max = ScatterMaxFunction.apply diff --git a/perception/__init__.py b/ads/motion/__init__.py similarity index 100% rename from perception/__init__.py rename to ads/motion/__init__.py diff --git a/motion/components/README.md b/ads/motion/components/README.md similarity index 98% rename from motion/components/README.md rename to ads/motion/components/README.md index 4fb297accc04fcc5bb00b284330d4fe51cdf649e..f1cf0540a17c9ebd79472f7ebcac5909a1bc078f 100644 --- a/motion/components/README.md +++ b/ads/motion/components/README.md @@ -1,2 +1,2 @@ -## Description +## Description + The folder contains some pytorch algorithm modules. \ No newline at end of file diff --git a/motion/ops/CMakeLists.txt b/ads/motion/ops/CMakeLists.txt similarity index 100% rename from motion/ops/CMakeLists.txt rename to ads/motion/ops/CMakeLists.txt diff --git a/perception/fused/ops/csrc/README.md b/ads/motion/ops/csrc/README.md similarity index 99% rename from perception/fused/ops/csrc/README.md rename to ads/motion/ops/csrc/README.md index 4e14f0ef43f275b57ffe7a316a188ca911e7c0ef..0bbe4f394307b9d81004b5bd923e630eabd9a509 100644 --- a/perception/fused/ops/csrc/README.md +++ b/ads/motion/ops/csrc/README.md @@ -1,2 +1,2 @@ -## Description +## Description + The folder contains some cpp source files, which provide code for adaptation of ascend kernels. It provide links for kernels and cpp interfaces. \ No newline at end of file diff --git a/perception/point/ops/kernels/README.md b/ads/motion/ops/kernels/README.md similarity index 99% rename from perception/point/ops/kernels/README.md rename to ads/motion/ops/kernels/README.md index 7fc09008da55ec8f9e5fc10a0c9c61d93f928b59..214fb0a6d662e806bd7f6bdd1b8962bc1639026e 100644 --- a/perception/point/ops/kernels/README.md +++ b/ads/motion/ops/kernels/README.md @@ -1,2 +1,2 @@ -## Description +## Description + The folder contains some ascend-kernel source files, which are like cuda-kernels and supply some ops that can be run on ascend device. \ No newline at end of file diff --git a/motion/ops/pybind.cpp b/ads/motion/ops/pybind.cpp similarity index 100% rename from motion/ops/pybind.cpp rename to ads/motion/ops/pybind.cpp diff --git a/perception/fused/__init__.py b/ads/perception/__init__.py similarity index 100% rename from perception/fused/__init__.py rename to ads/perception/__init__.py diff --git a/perception/point/__init__.py b/ads/perception/fused/__init__.py similarity index 100% rename from perception/point/__init__.py rename to ads/perception/fused/__init__.py diff --git a/perception/fused/components/README.md b/ads/perception/fused/components/README.md similarity index 98% rename from perception/fused/components/README.md rename to ads/perception/fused/components/README.md index 4fb297accc04fcc5bb00b284330d4fe51cdf649e..f1cf0540a17c9ebd79472f7ebcac5909a1bc078f 100644 --- a/perception/fused/components/README.md +++ b/ads/perception/fused/components/README.md @@ -1,2 +1,2 @@ -## Description +## Description + The folder contains some pytorch algorithm modules. \ No newline at end of file diff --git a/perception/fused/ops/CMakeLists.txt b/ads/perception/fused/ops/CMakeLists.txt similarity index 100% rename from perception/fused/ops/CMakeLists.txt rename to ads/perception/fused/ops/CMakeLists.txt diff --git a/perception/point/ops/csrc/README.md b/ads/perception/fused/ops/csrc/README.md similarity index 99% rename from perception/point/ops/csrc/README.md rename to ads/perception/fused/ops/csrc/README.md index 4e14f0ef43f275b57ffe7a316a188ca911e7c0ef..0bbe4f394307b9d81004b5bd923e630eabd9a509 100644 --- a/perception/point/ops/csrc/README.md +++ b/ads/perception/fused/ops/csrc/README.md @@ -1,2 +1,2 @@ -## Description +## Description + The folder contains some cpp source files, which provide code for adaptation of ascend kernels. It provide links for kernels and cpp interfaces. \ No newline at end of file diff --git a/motion/ops/kernels/README.md b/ads/perception/fused/ops/kernels/README.md similarity index 99% rename from motion/ops/kernels/README.md rename to ads/perception/fused/ops/kernels/README.md index 7fc09008da55ec8f9e5fc10a0c9c61d93f928b59..214fb0a6d662e806bd7f6bdd1b8962bc1639026e 100644 --- a/motion/ops/kernels/README.md +++ b/ads/perception/fused/ops/kernels/README.md @@ -1,2 +1,2 @@ -## Description +## Description + The folder contains some ascend-kernel source files, which are like cuda-kernels and supply some ops that can be run on ascend device. \ No newline at end of file diff --git a/perception/fused/ops/pybind.cpp b/ads/perception/fused/ops/pybind.cpp similarity index 100% rename from perception/fused/ops/pybind.cpp rename to ads/perception/fused/ops/pybind.cpp diff --git a/perception/vision/__init__.py b/ads/perception/point/__init__.py similarity index 100% rename from perception/vision/__init__.py rename to ads/perception/point/__init__.py diff --git a/perception/point/components/README.md b/ads/perception/point/components/README.md similarity index 98% rename from perception/point/components/README.md rename to ads/perception/point/components/README.md index 4fb297accc04fcc5bb00b284330d4fe51cdf649e..f1cf0540a17c9ebd79472f7ebcac5909a1bc078f 100644 --- a/perception/point/components/README.md +++ b/ads/perception/point/components/README.md @@ -1,2 +1,2 @@ -## Description +## Description + The folder contains some pytorch algorithm modules. \ No newline at end of file diff --git a/perception/point/ops/CMakeLists.txt b/ads/perception/point/ops/CMakeLists.txt similarity index 100% rename from perception/point/ops/CMakeLists.txt rename to ads/perception/point/ops/CMakeLists.txt diff --git a/motion/ops/csrc/README.md b/ads/perception/point/ops/csrc/README.md similarity index 99% rename from motion/ops/csrc/README.md rename to ads/perception/point/ops/csrc/README.md index 4e14f0ef43f275b57ffe7a316a188ca911e7c0ef..0bbe4f394307b9d81004b5bd923e630eabd9a509 100644 --- a/motion/ops/csrc/README.md +++ b/ads/perception/point/ops/csrc/README.md @@ -1,2 +1,2 @@ -## Description +## Description + The folder contains some cpp source files, which provide code for adaptation of ascend kernels. It provide links for kernels and cpp interfaces. \ No newline at end of file diff --git a/common/ops/kernels/README.md b/ads/perception/point/ops/kernels/README.md similarity index 99% rename from common/ops/kernels/README.md rename to ads/perception/point/ops/kernels/README.md index 7fc09008da55ec8f9e5fc10a0c9c61d93f928b59..214fb0a6d662e806bd7f6bdd1b8962bc1639026e 100644 --- a/common/ops/kernels/README.md +++ b/ads/perception/point/ops/kernels/README.md @@ -1,2 +1,2 @@ -## Description +## Description + The folder contains some ascend-kernel source files, which are like cuda-kernels and supply some ops that can be run on ascend device. \ No newline at end of file diff --git a/perception/point/ops/pybind.cpp b/ads/perception/point/ops/pybind.cpp similarity index 100% rename from perception/point/ops/pybind.cpp rename to ads/perception/point/ops/pybind.cpp diff --git a/perception/vision/ops/CMakeLists.txt b/ads/perception/vision/__init__.py similarity index 100% rename from perception/vision/ops/CMakeLists.txt rename to ads/perception/vision/__init__.py diff --git a/ads/perception/vision/components/README.md b/ads/perception/vision/components/README.md new file mode 100644 index 0000000000000000000000000000000000000000..f1cf0540a17c9ebd79472f7ebcac5909a1bc078f --- /dev/null +++ b/ads/perception/vision/components/README.md @@ -0,0 +1,2 @@ +## Description ++ The folder contains some pytorch algorithm modules. \ No newline at end of file diff --git a/perception/vision/ops/pybind.cpp b/ads/perception/vision/ops/CMakeLists.txt similarity index 100% rename from perception/vision/ops/pybind.cpp rename to ads/perception/vision/ops/CMakeLists.txt diff --git a/perception/vision/ops/csrc/README.md b/ads/perception/vision/ops/csrc/README.md similarity index 99% rename from perception/vision/ops/csrc/README.md rename to ads/perception/vision/ops/csrc/README.md index 4e14f0ef43f275b57ffe7a316a188ca911e7c0ef..0bbe4f394307b9d81004b5bd923e630eabd9a509 100644 --- a/perception/vision/ops/csrc/README.md +++ b/ads/perception/vision/ops/csrc/README.md @@ -1,2 +1,2 @@ -## Description +## Description + The folder contains some cpp source files, which provide code for adaptation of ascend kernels. It provide links for kernels and cpp interfaces. \ No newline at end of file diff --git a/ads/perception/vision/ops/kernels/README.md b/ads/perception/vision/ops/kernels/README.md new file mode 100644 index 0000000000000000000000000000000000000000..214fb0a6d662e806bd7f6bdd1b8962bc1639026e --- /dev/null +++ b/ads/perception/vision/ops/kernels/README.md @@ -0,0 +1,2 @@ +## Description ++ The folder contains some ascend-kernel source files, which are like cuda-kernels and supply some ops that can be run on ascend device. \ No newline at end of file diff --git a/ads/perception/vision/ops/pybind.cpp b/ads/perception/vision/ops/pybind.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/bind/pybind.cpp b/bind/pybind.cpp new file mode 100644 index 0000000000000000000000000000000000000000..351c837ee0e6e8ecd6edb5c2164558389e2f8dee --- /dev/null +++ b/bind/pybind.cpp @@ -0,0 +1,6 @@ +#include +#include "../ads/common/ops/csrc/functions.h" + +PYBIND11_MODULE(TORCH_EXTENSION_NAME, m) { + init_common(m); +} diff --git a/ci/access_control_test.py b/ci/access_control_test.py index 7685657aaf3df9d7a758c99f7698b35cb55e8a86..b5caff6773fcced4419d83d6cc6f284d7b30e287 100644 --- a/ci/access_control_test.py +++ b/ci/access_control_test.py @@ -115,7 +115,7 @@ class DirectoryStrategy(AccurateTest): """ def identify(self, modify_file): - is_test_file = str(Path(modify_file).parts[0]) == "test" \ + is_test_file = str(Path(modify_file).parts[0]) == "tests" \ and re.match("test_(.+).py", Path(modify_file).name) return [(str(BASE_DIR / modify_file))] if is_test_file else [] diff --git a/perception/vision/components/README.md b/perception/vision/components/README.md deleted file mode 100644 index 4fb297accc04fcc5bb00b284330d4fe51cdf649e..0000000000000000000000000000000000000000 --- a/perception/vision/components/README.md +++ /dev/null @@ -1,2 +0,0 @@ -## Description -+ The folder contains some pytorch algorithm modules. \ No newline at end of file diff --git a/perception/vision/ops/kernels/README.md b/perception/vision/ops/kernels/README.md deleted file mode 100644 index 7fc09008da55ec8f9e5fc10a0c9c61d93f928b59..0000000000000000000000000000000000000000 --- a/perception/vision/ops/kernels/README.md +++ /dev/null @@ -1,2 +0,0 @@ -## Description -+ The folder contains some ascend-kernel source files, which are like cuda-kernels and supply some ops that can be run on ascend device. \ No newline at end of file diff --git a/setup.py b/setup.py index 03a7c2400bea3d34488bd405e39375ec86b4ca9a..2ff09279597f43ac9d5e6550ecc325b79de5440d 100644 --- a/setup.py +++ b/setup.py @@ -1,17 +1,16 @@ import os import glob from setuptools import setup, find_packages -# from torch_npu.utils import cpp_extension from torch.utils.cpp_extension import BuildExtension -import cpp_extension +from utils import extension source_file = [] -source_file += glob.glob(os.path.join("./common/ops/csrc/", "*.cpp")) -source_file += glob.glob(os.path.join("./common/ops/", "*.cpp")) +source_file += glob.glob(os.path.join("./ads/common/ops/csrc/", "*.cpp")) +source_file += glob.glob(os.path.join("./bind/", "*.cpp")) exts = [] -ext1 = cpp_extension.NpuExtension( - name="ads", +ext1 = extension.NpuExtension( + name="ads_c", sources=source_file, ) @@ -19,7 +18,7 @@ exts.append(ext1) setup( name="ads", version="1.0", - description='Cpp Extension Include ascend_accelerator', + description='Cpp Extension Include ascend_ads', keywords='ads', ext_modules=exts, author='Ascend Contributors', diff --git a/tests/test_scatter_max.py b/tests/test_scatter_max.py index 6b96f27a1e132d77e23981d9da9095cc833353d9..be6c35e700780d1997f34d804e12169cd3a8c026 100644 --- a/tests/test_scatter_max.py +++ b/tests/test_scatter_max.py @@ -5,7 +5,7 @@ import torch_scatter import torch_npu from torch_npu.testing.testcase import TestCase, run_tests from torch_npu.testing.common_utils import create_common_tensor -from common import modules +import ads.common class TestScatterMaxWithArgmax(TestCase): @@ -26,7 +26,7 @@ class TestScatterMaxWithArgmax(TestCase): def npu_op_exec(self, updates, indices): updates.requires_grad = True - output, output_argmax = modules.npuscattermax(updates, indices) + output, output_argmax = ads.common.scatter_max(updates, indices) output.backward(torch.ones_like(output)) output_grad = updates.grad.cpu() diff --git a/cpp_extension.py b/utils/extension.py similarity index 100% rename from cpp_extension.py rename to utils/extension.py