已合并
fix(example): rename NPU_ARCH to NPU_SOC_VERSION and dynamically adapt Python version tag #1067
liu-wei创建于 7月1日
fix(example): rename NPU_ARCH to NPU_SOC_VERSION and dynamically adapt Python version tag #1067
已合并
共 4 个文件变更+24-9
| @@ -23,8 +23,16 @@ include(cmake/torch.cmake) | |||
| 23 | include(cmake/torch_npu.cmake) | 23 | include(cmake/torch_npu.cmake) |
| 24 | include(cmake/func.cmake) | 24 | include(cmake/func.cmake) |
| 25 | 25 | ||
| 26 | -# set NPU architecture, default to ascend910b | 26 | +# set NPU SOC version, default to ascend910b |
| 27 | -set(NPU_ARCH "ascend910b" CACHE STRING "NPU architecture") | 27 | +if(NOT DEFINED NPU_SOC_VERSION) |
| 28 | + if(DEFINED NPU_ARCH) | ||
| 29 | + set(NPU_SOC_VERSION "${NPU_ARCH}" CACHE STRING "NPU SOC version") | ||
| 30 | + else() | ||
| 31 | + set(NPU_SOC_VERSION "ascend910b" CACHE STRING "NPU SOC version") | ||
| 32 | + endif() | ||
| 33 | +else() | ||
| 34 | + set(NPU_SOC_VERSION "${NPU_SOC_VERSION}" CACHE STRING "NPU SOC version") | ||
| 35 | +endif() | ||
| 28 | # set EXTENSION_MODULE_NAME to `ascend_ops` | 36 | # set EXTENSION_MODULE_NAME to `ascend_ops` |
| 29 | set(EXTENSION_MODULE_NAME "ascend_ops" CACHE STRING "Extension module name") | 37 | set(EXTENSION_MODULE_NAME "ascend_ops" CACHE STRING "Extension module name") |
| 30 | 38 | ||
| @@ -31,11 +31,14 @@ | |||
| 31 | 3. 构建Wheel包 | Build the Wheel: | 31 | 3. 构建Wheel包 | Build the Wheel: |
| 32 | 32 | ||
| 33 | ```sh | 33 | ```sh |
| 34 | + # NPU_SOC_VERSION设置编译款型, Atlas A2系列产品使用"ascend910b"(默认),Atlas A3系列产品使用"ascend910_93",Ascend 950PR/Ascend 950DT产品使用"ascend950" | ||
| 35 | + export NPU_SOC_VERSION=ascend910b | ||
| 34 | # -n: non-isolated build (uses existing environment) | 36 | # -n: non-isolated build (uses existing environment) |
| 35 | python3 -m build --wheel -n | 37 | python3 -m build --wheel -n |
| 36 | ``` | 38 | ``` |
| 37 | 39 | ||
| 38 | - 构建完成后,产物在当前目录的`dist`文件夹下,产物名`ascend_ops-1.0.0-${python_version}-abi3-${arch}.whl`,`${python_version}`表示当前环境中的python版本(python3.8.3为cp38),`${arch}`表示CPU架构。 | 40 | + 构建完成后,产物在当前目录的`dist`文件夹下,产物名`ascend_ops-1.0.0-cp38-abi3-${arch}.whl`,`cp38-abi3`表示该Wheel包使用Python 3.8稳定ABI并支持Python 3.8及以上版本,`${arch}`表示CPU架构。 |
| 41 | + 旧环境变量`NPU_ARCH`仍可兼容读取,但建议使用`NPU_SOC_VERSION`。 | ||
| 39 | 42 | ||
| 40 | 4. 安装Wheel包 | Install Package: | 43 | 4. 安装Wheel包 | Install Package: |
| 41 | 44 | ||
| @@ -14,8 +14,8 @@ | |||
| 14 | macro(recursive_add_subdirectory) | 14 | macro(recursive_add_subdirectory) |
| 15 | file(GLOB CURRENT_DIRS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/*) | 15 | file(GLOB CURRENT_DIRS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/*) |
| 16 | foreach(SUB_DIR ${CURRENT_DIRS}) | 16 | foreach(SUB_DIR ${CURRENT_DIRS}) |
| 17 | - if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${SUB_DIR}/${NPU_ARCH}/CMakeLists.txt") | 17 | + if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${SUB_DIR}/${NPU_SOC_VERSION}/CMakeLists.txt") |
| 18 | - add_subdirectory(${SUB_DIR}/${NPU_ARCH}) | 18 | + add_subdirectory(${SUB_DIR}/${NPU_SOC_VERSION}) |
| 19 | endif() | 19 | endif() |
| 20 | endforeach() | 20 | endforeach() |
| 21 | endmacro() | 21 | endmacro() |
| @@ -106,9 +106,13 @@ class CMakeBuildCommand(Command): | |||
| 106 | TORCH_NPU_PATH = os.path.dirname(torch_npu.__file__) | 106 | TORCH_NPU_PATH = os.path.dirname(torch_npu.__file__) |
| 107 | logging.info(f"Using Torch NPU path: {TORCH_NPU_PATH}") | 107 | logging.info(f"Using Torch NPU path: {TORCH_NPU_PATH}") |
| 108 | 108 | ||
| 109 | - # Get NPU_ARCH from environment variable or set default | 109 | + # Get NPU_SOC_VERSION from environment variable or set default |
| 110 | - NPU_ARCH = os.environ.get('NPU_ARCH', 'ascend910b') | 110 | + npu_soc_version = os.environ.get('NPU_SOC_VERSION') |
| 111 | - logging.info(f"Using NPU_ARCH: {NPU_ARCH}") | 111 | + if npu_soc_version is None: |
| 112 | + npu_soc_version = os.environ.get('NPU_ARCH', 'ascend910b') | ||
| 113 | + if 'NPU_ARCH' in os.environ: | ||
| 114 | + logging.info("NPU_ARCH is deprecated, please use NPU_SOC_VERSION.") | ||
| 115 | + logging.info(f"Using NPU_SOC_VERSION: {npu_soc_version}") | ||
| 112 | 116 | ||
| 113 | # Build the CMake project | 117 | # Build the CMake project |
| 114 | build_temp = os.path.join(os.getcwd(), 'build') | 118 | build_temp = os.path.join(os.getcwd(), 'build') |
| @@ -116,7 +120,7 @@ class CMakeBuildCommand(Command): | |||
| 116 | '-DCMAKE_BUILD_TYPE=Release', | 120 | '-DCMAKE_BUILD_TYPE=Release', |
| 117 | f'-DTorch_DIR={Torch_DIR}', | 121 | f'-DTorch_DIR={Torch_DIR}', |
| 118 | f'-DTORCH_NPU_PATH={TORCH_NPU_PATH}', | 122 | f'-DTORCH_NPU_PATH={TORCH_NPU_PATH}', |
| 119 | - f'-DNPU_ARCH={NPU_ARCH}' | 123 | + f'-DNPU_SOC_VERSION={npu_soc_version}' |
| 120 | ] | 124 | ] |
| 121 | subprocess.check_call(cmake_config_command, cwd=os.getcwd()) | 125 | subprocess.check_call(cmake_config_command, cwd=os.getcwd()) |
| 122 | subprocess.check_call(['cmake', '--build', build_temp, '--config', 'Release', '--parallel', num_jobs], cwd=os.getcwd()) | 126 | subprocess.check_call(['cmake', '--build', build_temp, '--config', 'Release', '--parallel', num_jobs], cwd=os.getcwd()) |