diff --git a/.gitmodules b/.gitmodules index 8c21a3877b15b063631c4f77e5e83078454ab50c..b8b928285a5ead3f8d0ec87142512efdbf513d12 100644 --- a/.gitmodules +++ b/.gitmodules @@ -11,3 +11,6 @@ [submodule "third_party/Tensorpipe"] path = third_party/Tensorpipe url = https://gitee.com/ascend/Tensorpipe.git +[submodule "third_party/npu_extend/npu_extend"] + path = third_party/npu_extend/npu_extend + url = https://gitee.com/ascend/torch-npu-extend.git diff --git a/CMakeLists.txt b/CMakeLists.txt index 1b1a81efd08e0dfba2a942fb9c4a401c63289bb3..d46cbd1ed37e9ef96ee0d37b5d6985d5d088963a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -253,6 +253,15 @@ if (DEFINED BUILD_TORCHAIR) add_dependencies(${PLUGIN_NAME} copy_torchair_pyfiles) endif() +if (DEFINED BUILD_NPU_EXTEND) + if(NOT DEFINED NPU_EXTEND_INSTALL_PREFIX) + message(FATAL_ERROR, "npu_extend install prefix is not defined") + else() + execute_process(COMMAND bash ${TORCHNPU_THIRD_PARTY_ROOT}/npu_extend/install.sh ${NPU_EXTEND_INSTALL_PREFIX}) + message("Copy npu_extend files to ${NPU_EXTEND_INSTALL_PREFIX}") + endif() +endif() + link_directories(${PYTORCH_INSTALL_DIR}/lib) link_directories(${TORCHNPU_THIRD_PARTY_ROOT}/acl/libs) diff --git a/ci/build.sh b/ci/build.sh index e6e5b2d140833be8d37b380f79f50e23e437da1f..562ace9ab22d4804392156dfc3de807c1ba15484 100644 --- a/ci/build.sh +++ b/ci/build.sh @@ -49,6 +49,10 @@ function parse_script_args() { export DISABLE_RPC_FRAMEWORK=TRUE shift ;; + --disable_npu_extend) + export DISABLE_INSTALL_NPU_EXTEND=TRUE + shift + ;; -*) echo "ERROR Unsupported parameters: ${1}" return 1 diff --git a/setup.py b/setup.py index b2e74958dd087401f8d213cf9597b28dc4fc6434..f52b0b452dc6acd0cca04b4ac60c207259cc0c77 100644 --- a/setup.py +++ b/setup.py @@ -37,6 +37,9 @@ if os.environ.get("DISABLE_INSTALL_TORCHAIR") is not None: DISABLE_RPC = "FALSE" if os.environ.get("DISABLE_RPC_FRAMEWORK") is not None: DISABLE_RPC = os.environ.get("DISABLE_RPC_FRAMEWORK") +DISABLE_NPU_EXTEND = "FALSE" +if os.environ.get("DISABLE_INSTALL_NPU_EXTEND") is not None: + DISABLE_NPU_EXTEND = os.environ.get("DISABLE_INSTALL_NPU_EXTEND") def get_submodule_folders(): @@ -208,6 +211,12 @@ def check_tensorpipe_valid(base_dir): return os.path.exists(tensorpipe_path) +def check_npu_extend_valid(base_dir): + npu_extend_path = os.path.join(base_dir, "third_party", "npu_extend", "npu_extend") + return os.path.exists(npu_extend_path) and (os.path.isdir(npu_extend_path) and + len(os.listdir(npu_extend_path)) != 0) + + def generate_dbg_files_and_strip(): library_dir = Path(BASE_DIR).joinpath("build/packages/torch_npu") dbg_dir = Path(BASE_DIR).joinpath("build/dbg") @@ -334,6 +343,12 @@ class CPPLibBuild(build_clib, object): if check_tensorpipe_valid(BASE_DIR): cmake_args.append('-DBUILD_TENSORPIPE=on') + if DISABLE_NPU_EXTEND == 'FALSE' and check_npu_extend_valid(BASE_DIR): + npu_extend_install_prefix = os.path.join(build_type_dir, "packages", "torch_npu", "contrib") + cmake_args.append(f'-DNPU_EXTEND_INSTALL_PREFIX={npu_extend_install_prefix}') + cmake_args.append('-DBUILD_NPU_EXTEND=on') + + build_args = ['-j', str(multiprocessing.cpu_count())] subprocess.check_call([self.cmake, BASE_DIR] + cmake_args, cwd=build_type_dir, env=os.environ) diff --git a/third_party/npu_extend/install.sh b/third_party/npu_extend/install.sh new file mode 100644 index 0000000000000000000000000000000000000000..aa8ada4ee2f58092b280b3edf9df9e811a9c39d7 --- /dev/null +++ b/third_party/npu_extend/install.sh @@ -0,0 +1,7 @@ +set -e +set -o pipefail + +SCRIPT_BASE=$(dirname $(readlink -f $0)) +NPU_EXTEND_BASE=${SCRIPT_BASE}/npu_extend + +cd ${NPU_EXTEND_BASE} && chmod +x install.sh && ./install.sh $1 diff --git a/third_party/npu_extend/npu_extend b/third_party/npu_extend/npu_extend new file mode 160000 index 0000000000000000000000000000000000000000..7f0293dc3533b8be009e2c5831586590c3b06621 --- /dev/null +++ b/third_party/npu_extend/npu_extend @@ -0,0 +1 @@ +Subproject commit 7f0293dc3533b8be009e2c5831586590c3b06621