已合并
update doc #671
liuyufan创建于 1月8日
update doc #671
已合并
liuyufan创建于 1月8日
共 6 个文件变更+158-125
@@ -27,20 +27,21 @@
27 27 
28## 文档说明28## 文档说明
29 29 
30-为方便开发者快速熟悉本项目,可按需获取对应文档,文档内容包括:30+项目全量文档如下,请按需获取对应内容。
31 31 
32| 文档 | 说明 |32| 文档 | 说明 |
33| ------------------------------------------------ | ------------------------------------------------------------ |33| ------------------------------------------------ | ------------------------------------------------------------ |
34-| [算子列表](zh/op_list.md) | 介绍项目包含的所有算子。 |34+| [算子列表](zh/op_list.md) | 介绍项目包含的所有算子清单。 |
35-| [aclnn列表](zh/op_api_list.md) | 介绍项目包含的所有aclnn前缀的算子API,通过该API可直调算子。 |35+| [aclnn列表](zh/op_api_list.md) | 介绍项目包含的所有算子API,通过该API可直调算子。 |
36-| [环境部署](zh/context/quick_install.md) | 介绍项目的基础环境搭建,包括软件包和第三方依赖的获取和安装。 |36+| [环境部署](zh/context/quick_install.md) | 介绍基础环境搭建过程,包括不同场景下软件包和第三方依赖的获取和安装。 |
37-| [算子调用](zh/invocation/quick_op_invocation.md) | 介绍如何快速调用项目内算子,包括编译执行算子包和UT等。 |37+| [算子调用](zh/invocation/quick_op_invocation.md) | 介绍如何调用项目算子,包括不同场景下编译和执行算子包、UT等。 |
38-| [算子开发](zh/develop/aicore_develop_guide.md) | 介绍自定义算子的开发流程,包括算子原型定义、Tiling实现、Kernel实现等。 |38+| [算子开发](zh/develop/aicore_develop_guide.md) | 介绍如何基于本项目工程开发新算子,包括算子原型定义、Tiling实现、Kernel实现等。 |
39-| [算子调用方式](zh/invocation/op_invocation.md) | 介绍不同算子调用方式,包括aclnn调用、图模式调用等,方便算子快速应用于AI业务中。 |39+| [算子调用方式](zh/invocation/op_invocation.md) | 介绍多种算子调用方式和调用流程,例如aclnn调用、图模式调用等。 |
40| [算子调试调优](zh/debug/op_debug_prof.md) | 介绍常见的算子调试、调优方法。 |40| [算子调试调优](zh/debug/op_debug_prof.md) | 介绍常见的算子调试、调优方法。 |
41 41 
42## 附录42## 附录
43+ 
43| 文档 | 说明 |44| 文档 | 说明 |
44| ----------------------------------- | ------------------------------------------------------------ |45| ----------------------------------- | ------------------------------------------------------------ |
45-| [算子基本概念](zh/context/基本概念.md) | 介绍算子相关的基础概念和特性,包括量化/稀疏等术语、数据类型、数据格式等。 |46+| [算子基本概念](zh/context/基本概念.md) | 介绍算子领域相关的基础概念和术语,如量化/稀疏、数据类型、数据格式等。 |
46-| [build参数说明](zh/context/build.md) | 介绍项目中build.sh脚本功能和具体参数。 |47+| [build参数说明](zh/context/build.md) | 介绍本项目build.sh脚本的功能和参数含义。 |
@@ -18,14 +18,14 @@
18自定义算子包编译时,需增加--cann_3rd_lib_path配置选项并指定路径,命令如下:18自定义算子包编译时,需增加--cann_3rd_lib_path配置选项并指定路径,命令如下:
19 19 
20```bash20```bash
21-bash build.sh --pkg --soc=${soc_version} [--vendor_name=${vendor_name}] [--ops=${op_list}] --cann-3rd_lib_path=${cann_3rd_lib_path}21+bash build.sh --pkg --soc=${soc_version} [--vendor_name=${vendor_name}] [--ops=${op_list}] --cann_3rd_lib_path=${cann_3rd_lib_path}
22# 以TransposeBatchMatMul算子编译为例,假设第三方软件存放的目录为/path/cann_3rd_lib_path22# 以TransposeBatchMatMul算子编译为例,假设第三方软件存放的目录为/path/cann_3rd_lib_path
23-# bash build.sh --pkg --soc=ascend910b --ops=transpose_batch_mat_mul --cann-3rd_lib_path=/path/cann_3rd_lib_path23+# bash build.sh --pkg --soc=ascend910b --ops=transpose_batch_mat_mul --cann_3rd_lib_path=/path/cann_3rd_lib_path
24```24```
25 25 
26## 离线编译(ops-nn包)26## 离线编译(ops-nn包)
27整包编译时,需增加--cann_3rd_lib_path配置选项并指定路径,命令如下:27整包编译时,需增加--cann_3rd_lib_path配置选项并指定路径,命令如下:
28 28 
29```bash29```bash
30-bash build.sh --pkg [--jit] --soc=${soc_version} --cann-3rd_lib_path=${cann_3rd_lib_path}30+bash build.sh --pkg [--jit] --soc=${soc_version} --cann_3rd_lib_path=${cann_3rd_lib_path}
31```31```
@@ -1,6 +1,12 @@
1# 环境部署1# 环境部署
2 2 
3-基于本项目进行[算子调用](../invocation/quick_op_invocation.md)或[算子开发](../develop/aicore_develop_guide.md)之前,需要参考下述步骤完成基础环境搭建。3+ 
4+基于本项目进行[算子调用](../invocation/quick_op_invocation.md)或[算子开发](../develop/aicore_develop_guide.md)之前,请您先参考下面步骤完成基础环境搭建。
5+ 
6+环境搭建一般分为如下场景,您可以按需安装:
7+ 
8+- 编译态:针对仅编译不运行本项目的场景,只需安装前置依赖和CANN toolkit包。
9+- 运行态:针对运行本项目的场景(编译运行或纯运行),除了安装前置依赖和CANN toolkit包,还需安装驱动与固件、CANN ops包。
4 10 
5## 前提条件11## 前提条件
6 12 
@@ -10,12 +16,13 @@
10 16 
11 本项目源码编译用到的依赖如下,请注意版本要求。17 本项目源码编译用到的依赖如下,请注意版本要求。
12 18 
13- - python >= 3.7.019+ - python >= 3.7.0(建议版本 <= 3.10)
范其瑞
范其瑞范其瑞1月8日

install_deps.sh要给macos安装3.11版本,这两处要保证一致

likedislike
liuyufan
liuyufan
1月9日 评论:
14 - gcc >= 7.3.020 - gcc >= 7.3.0
15 - cmake >= 3.16.021 - cmake >= 3.16.0
16 - pigz(可选,安装后可提升打包速度,建议版本 >= 2.4)22 - pigz(可选,安装后可提升打包速度,建议版本 >= 2.4)
17 - dos2unix23 - dos2unix
18 - gawk24 - gawk
25+ - make
19 - googletest(仅执行UT时依赖,建议版本 [release-1.11.0](https://github.com/google/googletest/releases/tag/release-1.11.0))26 - googletest(仅执行UT时依赖,建议版本 [release-1.11.0](https://github.com/google/googletest/releases/tag/release-1.11.0))
20 27 
21 上述依赖包可通过项目根目录install\_deps.sh安装,命令如下,若遇到不支持系统,请参考该文件自行适配。28 上述依赖包可通过项目根目录install\_deps.sh安装,命令如下,若遇到不支持系统,请参考该文件自行适配。
@@ -31,14 +38,17 @@
31 38 
32 安装指导详见《[CANN 软件安装指南](https://www.hiascend.com/document/redirect/CannCommunityInstSoftware)》。39 安装指导详见《[CANN 软件安装指南](https://www.hiascend.com/document/redirect/CannCommunityInstSoftware)》。
33 40 
34-## 软件包安装41+## 环境准备
35 42 
36-1. **安装社区版CANN toolkit包**43+### 1. 下载软件包
44+ 
45+根据实际产品型号和环境架构,获取`Ascend-cann-toolkit_${cann_version}_linux-${arch}.run`、`Ascend-cann-${soc_name}-ops_${cann_version}_linux-${arch}.run`。其中ops包是运行态依赖,若仅编译算子,可以不安装此包。
46+- Atlas A2/A3系列产品:单击[下载链接](https://ascend.devcloud.huaweicloud.com/cann/run/software/8.5.0-beta.1)获取软件包。
47+- Ascend 950PR/Ascend 950DT产品:单击[下载链接](https://mirror-centralrepo.devcloud.cn-north-4.huaweicloud.com/artifactory/cann-run-release/software/9.0.0-alpha.1/)获取软件包。
48+ 
49+### 2. 安装软件包
50+1. **安装社区CANN toolkit包**
37 51 
38- 根据实际产品型号和环境架构,获取对应的`Ascend-cann-toolkit_${cann_version}_linux-${arch}.run`包。
39- - Atlas A2/A3系列产品:单击[下载链接](https://ascend.devcloud.huaweicloud.com/cann/run/software/8.5.0-beta.1)获取软件包。
40- - Ascend 950PR/Ascend 950DT产品:单击[下载链接](https://mirror-centralrepo.devcloud.cn-north-4.huaweicloud.com/artifactory/cann-run-release/software/9.0.0-alpha.1/)获取软件包。
41-
42 ```bash52 ```bash
43 # 确保安装包具有可执行权限53 # 确保安装包具有可执行权限
44 chmod +x Ascend-cann-toolkit_${cann_version}_linux-${arch}.run54 chmod +x Ascend-cann-toolkit_${cann_version}_linux-${arch}.run
@@ -53,21 +63,34 @@
53 63 
54 运行算子时必须安装本包,若仅编译算子,可跳过本操作。64 运行算子时必须安装本包,若仅编译算子,可跳过本操作。
55 65 
56- 根据实际产品型号和环境架构,获取对应的`Ascend-cann-${soc_name}-ops_${cann_version}_linux-${arch}.run`包。
57- - Atlas A2/A3系列产品:单击[下载链接](https://ascend.devcloud.huaweicloud.com/cann/run/software/8.5.0-beta.1)获取软件包。
58- - Ascend 950PR/Ascend 950DT产品:单击[下载链接](https://mirror-centralrepo.devcloud.cn-north-4.huaweicloud.com/artifactory/cann-run-release/software/9.0.0-alpha.1/)获取软件包。
59- 
60 ```bash66 ```bash
61 # 确保安装包具有可执行权限67 # 确保安装包具有可执行权限
62 chmod +x Ascend-cann-${soc_name}-ops_${cann_version}_linux-${arch}.run68 chmod +x Ascend-cann-${soc_name}-ops_${cann_version}_linux-${arch}.run
63 # 安装命令69 # 安装命令
64 ./Ascend-cann-${soc_name}-ops_${cann_version}_linux-${arch}.run --install --install-path=${install_path}70 ./Ascend-cann-${soc_name}-ops_${cann_version}_linux-${arch}.run --install --install-path=${install_path}
65 ```71 ```
66- - \$\{soc\_name\}:表示NPU型号名称,即\$\{soc\_version\}删除“ascend”后剩余的内容。72+
73+ - \$\{soc\_name\}:表示NPU型号名称。
67 - \$\{install\_path\}:表示指定安装路径,需要与toolkit包安装在相同路径,默认安装在`/usr/local/Ascend`目录。74 - \$\{install\_path\}:表示指定安装路径,需要与toolkit包安装在相同路径,默认安装在`/usr/local/Ascend`目录。
68 75 
76+## 环境验证
77+ 
78+安装完CANN包或进入Docker容器后,需验证环境和驱动是否正常。
79+ 
80+- **检查NPU设备**:
81+ ```bash
82+ # 运行npu-smi,若能正常显示设备信息,则驱动正常
83+ npu-smi info
84+ ```
85+- **检查CANN安装**:
86+ ```bash
87+ # 查看CANN Toolkit版本信息(默认路径安装)
88+ cat /usr/local/Ascend/ascend-toolkit/latest/opp/version.info
89+ ```
90+ 
69## 环境变量配置91## 环境变量配置
70 92 
93+按需选择合适的命令使环境变量生效。
71```bash94```bash
72# 默认路径安装,以root用户为例(非root用户,将/usr/local替换为${HOME})95# 默认路径安装,以root用户为例(非root用户,将/usr/local替换为${HOME})
73source /usr/local/Ascend/cann/set_env.sh96source /usr/local/Ascend/cann/set_env.sh
@@ -9,6 +9,7 @@
9开发指南以`AddExample`算子开发为例,介绍新算子开发流程以及涉及的交付件,完整样例代码请访问项目`examples`目录。9开发指南以`AddExample`算子开发为例,介绍新算子开发流程以及涉及的交付件,完整样例代码请访问项目`examples`目录。
10 10 
111. [工程创建](#工程创建):开发算子前,需完成环境部署并创建算子目录,方便后续算子编译和部署。111. [工程创建](#工程创建):开发算子前,需完成环境部署并创建算子目录,方便后续算子编译和部署。
12+ 
122. [算子定义](#算子定义):确定算子功能与原型定义。132. [算子定义](#算子定义):确定算子功能与原型定义。
13 14 
143. [Tiling实现](#Tiling实现):实现Host侧算子Tiling函数。153. [Tiling实现](#Tiling实现):实现Host侧算子Tiling函数。
@@ -35,7 +36,7 @@
35```bash36```bash
36# 创建指定算子目录,如bash build.sh --genop=examples/add_example37# 创建指定算子目录,如bash build.sh --genop=examples/add_example
37# ${op_class}表示算子类型,如matmul类。38# ${op_class}表示算子类型,如matmul类。
38-# ${op_name}表示算子名的小写下划线形式,如`AddExample`算子对应为add_example。39+# ${op_name}表示算子名的小写下划线形式,如`AddExample`算子对应为add_example,新增算子不允许与已有算子重名。
39bash build.sh --genop=${op_class}/${op_name}40bash build.sh --genop=${op_class}/${op_name}
40```41```
41 42 
@@ -49,23 +50,23 @@ Create the initial directory for ${op_name} under ${op_class} success
49```50```
50${op_name} # 替换为实际算子名的小写下划线形式51${op_name} # 替换为实际算子名的小写下划线形式
51├── examples # 算子调用示例52├── examples # 算子调用示例
52-│ ├── test_aclnn_${op_name}.cpp # 算子aclnn调用示例53+│ └── test_aclnn_${op_name}.cpp # 算子aclnn调用示例
53├── op_host # Host侧实现54├── op_host # Host侧实现
54│ ├── ${op_name}_def.cpp # 算子信息库,定义算子基本信息,如名称、输入输出、数据类型等55│ ├── ${op_name}_def.cpp # 算子信息库,定义算子基本信息,如名称、输入输出、数据类型等
55│ ├── ${op_name}_infershape.cpp # InferShape实现,实现算子形状推导,在运行时推导输出shape56│ ├── ${op_name}_infershape.cpp # InferShape实现,实现算子形状推导,在运行时推导输出shape
56-│ ├── ${op_name}_tiling.cpp # Tiling实现,将张量划分为多个小块,区分数据类型进行并行计算57+│ └── ${op_name}_tiling.cpp # Tiling实现,将张量划分为多个小块,区分数据类型进行并行计算
57-│ └── CMakeLists.txt # Host侧cmakelist文件58+├── op_kernel # Device侧Kernel实现
58-└── op_kernel # Device侧Kernel实现
59│ ├── ${op_name}_tiling_key.h # Tilingkey文件,定义Tiling策略的Key,标识不同的划分方式59│ ├── ${op_name}_tiling_key.h # Tilingkey文件,定义Tiling策略的Key,标识不同的划分方式
60│ ├── ${op_name}_tiling_data.h # Tilingdata文件,存储Tiling策略相关的配置数据,如块大小、并行度60│ ├── ${op_name}_tiling_data.h # Tilingdata文件,存储Tiling策略相关的配置数据,如块大小、并行度
61│ ├── ${op_name}.cpp # Kernel入口文件,包含主函数和调度逻辑61│ ├── ${op_name}.cpp # Kernel入口文件,包含主函数和调度逻辑
62│ └── ${op_name}.h # Kernel实现文件,定义Kernel头文件,包含函数声明、结构定义、逻辑实现62│ └── ${op_name}.h # Kernel实现文件,定义Kernel头文件,包含函数声明、结构定义、逻辑实现
63├── tests # UT实现63├── tests # UT实现
64-│ ├── ut # tiling/kernel/aclnn UT实现64+│ └── ut # tiling/kernel/aclnn UT实现
65└── CMakeLists.txt # 算子cmakelist入口65└── CMakeLists.txt # 算子cmakelist入口
66```66```
67 67 
68-使用上述命令行创建算子工程后,若要手动删除新创建出的算子工程,需要同时删除与算子工程同目录CMakeLists.txt中新添加的add_subdirectory(${op_class})。68+若`${op_class}`为全新算子分类,需额外在`cmake/variables.cmake`的`OP_CATEGORY_LIST`中添加`${op_class}`,否则无法正常编译。
69+ 
69## 算子定义70## 算子定义
70算子定义需要完成两个交付件:`README.md` `${op_name}_def.cpp`71算子定义需要完成两个交付件:`README.md` `${op_name}_def.cpp`
71 72 
@@ -356,10 +357,14 @@ __aicore__ inline void AddExample<T>::Process()
356 > 说明:编译过程依赖第三方开源软件,联网场景会自动下载,离线编译场景需要自行安装,具体参考[离线编译](../context/build_offline.md)。357 > 说明:编译过程依赖第三方开源软件,联网场景会自动下载,离线编译场景需要自行安装,具体参考[离线编译](../context/build_offline.md)。
357 358 
358 ```bash359 ```bash
359- # 编译指定算子,如--ops=add_example360+ # 编译指定算子,如bash build.sh --pkg --ops=add_example
360- bash build.sh --pkg --soc=${soc_version} --vendor_name=${vendor_name} --ops=${op_list}361+ bash build.sh --pkg --soc=${soc_version} --vendor_name=${vendor_name} --ops=${op_list} [--experimental]
361 ```362 ```
362- 363+ - --soc:\$\{soc\_version\}表示NPU型号。Atlas A2系列产品使用"ascend910b"(默认),Atlas A3系列产品使用"ascend910_93",Ascend 950PR/Ascend 950DT产品使用"ascend950"。
364+ - --vendor_name(可选):\$\{vendor\_name\}表示构建的自定义算子包名,默认名为custom。
365+ - --ops(可选):\$\{op\_list\}表示待编译算子,不指定时默认编译所有算子。格式形如"--ops=add_example"。
366+ - --experimental(可选):若编译的算子为贡献算子,需配置--experimental。
367+
363 若提示如下信息,说明编译成功:368 若提示如下信息,说明编译成功:
364 369
365 ```bash370 ```bash
@@ -373,7 +378,7 @@ __aicore__ inline void AddExample<T>::Process()
373 ./build_out/cann-ops-nn-${vendor_name}-linux.${arch}.run378 ./build_out/cann-ops-nn-${vendor_name}-linux.${arch}.run
374 ```379 ```
375 自定义算子包安装在`${ASCEND_HOME_PATH}/opp/vendors`路径中,`${ASCEND_HOME_PATH}`表示CANN软件安装目录,可提前在环境变量中配置。380 自定义算子包安装在`${ASCEND_HOME_PATH}/opp/vendors`路径中,`${ASCEND_HOME_PATH}`表示CANN软件安装目录,可提前在环境变量中配置。
376- 381+ 
3774. **(可选)卸载自定义算子包。**3824. **(可选)卸载自定义算子包。**
378 383 
379 自定义算子包安装后在`${ASCEND_HOME_PATH}/opp/vendors/${vendor_name}_nn/scripts`目录会生成`uninstall.sh`,通过该脚本可卸载自定义算子包,命令如下:384 自定义算子包安装后在`${ASCEND_HOME_PATH}/opp/vendors/${vendor_name}_nn/scripts`目录会生成`uninstall.sh`,通过该脚本可卸载自定义算子包,命令如下:
@@ -33,7 +33,7 @@
33```bash33```bash
34# 创建指定算子目录,如bash build.sh --genop_aicpu=examples/add_example34# 创建指定算子目录,如bash build.sh --genop_aicpu=examples/add_example
35# ${op_class}表示算子类型,如matmul类。35# ${op_class}表示算子类型,如matmul类。
36-# ${op_name}表示算子名的小写下划线形式,如`AddExample`算子对应为add_example。36+# ${op_name}表示算子名的小写下划线形式,如`AddExample`算子对应为add_example,新增算子不允许与已有算子重名。
37bash build.sh --genop_aicpu=${op_class}/${op_name}37bash build.sh --genop_aicpu=${op_class}/${op_name}
38```38```
39 39 
@@ -58,7 +58,8 @@ ${op_name} # 替换为实际算子名的小写下
58│ └── ut # Kernel/aclnn UT实现58│ └── ut # Kernel/aclnn UT实现
59└── CMakeLists.txt # 算子Cmakelist入口59└── CMakeLists.txt # 算子Cmakelist入口
60```60```
61-使用上述命令行创建算子工程后,若要手动删除新创建出的算子工程,需要同时删除与算子工程同目录CMakeLists.txt中新添加的add_subdirectory(${op_class})。61+ 
62+若`${op_class}`为全新算子分类,需额外在`cmake/variables.cmake`的`OP_CATEGORY_LIST`中添加`${op_class}`,否则无法正常编译。
62 63 
63## 算子定义64## 算子定义
64算子定义需要完成两个交付件:`README.md` `${op_name}.json`65算子定义需要完成两个交付件:`README.md` `${op_name}.json`
@@ -190,9 +191,13 @@ REGISTER_CPU_KERNEL(kAddExample, AddExampleCpuKernel);
190 以`AddExample`算子为例,假设开发交付件在`examples`目录,完整代码参见[add_example](../../../examples/add_example_aicpu)目录。191 以`AddExample`算子为例,假设开发交付件在`examples`目录,完整代码参见[add_example](../../../examples/add_example_aicpu)目录。
191 192 
192 ```bash193 ```bash
193- # 编译指定算子,如--ops=add_example194+ # 编译指定算子,如bash build.sh --pkg --ops=add_example
194- bash build.sh --pkg --soc=${soc_version} --vendor_name=${vendor_name} --ops=${op_list}195+ bash build.sh --pkg --soc=${soc_version} --vendor_name=${vendor_name} --ops=${op_list} [--experimental]
195 ```196 ```
197+ - --soc:\$\{soc\_version\}表示NPU型号。Atlas A2系列产品使用"ascend910b"(默认),Atlas A3系列产品使用"ascend910_93",Ascend 950PR/Ascend 950DT产品使用"ascend950"。
198+ - --vendor_name(可选):\$\{vendor\_name\}表示构建的自定义算子包名,默认名为custom。
199+ - --ops(可选):\$\{op\_list\}表示待编译算子,不指定时默认编译所有算子。格式形如"--ops=add_example"。
200+ - --experimental(可选):若编译的算子为贡献算子,需配置--experimental。
196 201
197 若提示如下信息,说明编译成功:202 若提示如下信息,说明编译成功:
198 203
@@ -220,7 +225,7 @@ REGISTER_CPU_KERNEL(kAddExample, AddExampleCpuKernel);
220 225 
221验证算子前需确保已配置了环境变量,命令如下:226验证算子前需确保已配置了环境变量,命令如下:
222```bash227```bash
223-export LD_LIBRARY_PATH=${ASCEND_HOME_PATH}/opp/vendors/${vendor_name}/op_api/lib:${LD_LIBRARY_PATH}228+export LD_LIBRARY_PATH=${ASCEND_HOME_PATH}/opp/vendors/${vendor_name}_nn/op_api/lib:${LD_LIBRARY_PATH}
224```229```
225- **UT验证**230- **UT验证**
226 231 
@@ -12,20 +12,20 @@ set -euo pipefail
12 12 
13run_command() {13run_command() {
14 local cmd="$*"14 local cmd="$*"
15- echo "执行命令:$cmd"15+ echo "Executing command: $cmd"
16 16 
17 if ! output=$("$@" 2>&1); then17 if ! output=$("$@" 2>&1); then
18 local exit_code=$?18 local exit_code=$?
19- echo -e "\n命令执行失败!"19+ echo -e "\nCommand execution failed!"
20- echo -e "\n失败的命令:$cmd"20+ echo -e "\nFailed command: $cmd"
21- echo -e "\n错误输出:$output"21+ echo -e "\nError output: $output"
22- echo -e "\n退出码:$exit_code"22+ echo -e "\nExit code: $exit_code"
23 exit $exit_code23 exit $exit_code
24 fi24 fi
25}25}
26 26 
27version_ge() {27version_ge() {
28- # 版本比较,版本形式:xx.xx.xx28+ # Version comparison, format: xx.xx.xx
29 IFS='.' read -r -a curr_arr <<< "$1"29 IFS='.' read -r -a curr_arr <<< "$1"
30 IFS='.' read -r -a req_arr <<< "$2"30 IFS='.' read -r -a req_arr <<< "$2"
31 31 
@@ -42,7 +42,7 @@ version_ge() {
42}42}
43 43 
44detect_os() {44detect_os() {
45- # 操作系统检查,支持debian(使用apt下载), rhel(使用dnf或者yum),macos45+ # OS detection, supports debian (uses apt), rhel (uses dnf or yum), macos
46 if [[ "$(uname -s)" == "Linux" ]]; then46 if [[ "$(uname -s)" == "Linux" ]]; then
47 if [[ -f /etc/debian_version ]]; then47 if [[ -f /etc/debian_version ]]; then
48 OS="debian"48 OS="debian"
@@ -55,31 +55,31 @@ detect_os() {
55 PKG_MANAGER="yum"55 PKG_MANAGER="yum"
56 fi56 fi
57 else57 else
58- echo "不支持的Linux发行版本"58+ echo "Unsupported Linux distribution, please install manually"
59 exit 159 exit 1
60 fi60 fi
61 elif [[ "$(uname -s)" == "Darwin" ]]; then61 elif [[ "$(uname -s)" == "Darwin" ]]; then
62 OS="macos"62 OS="macos"
63 if ! command -v brew &> /dev/null; then63 if ! command -v brew &> /dev/null; then
64- echo "请先安装Homebrew"64+ echo "Please install Homebrew first"
65 exit 165 exit 1
66 fi66 fi
67 PKG_MANAGER="brew"67 PKG_MANAGER="brew"
68 else68 else
69- echo "不支持的OS类型"69+ echo "Unsupported OS type, please install manually"
70 exit 170 exit 1
71 fi71 fi
72}72}
73 73 
74install_gawk() {74install_gawk() {
75- echo -e "\n==== 检查gawk ===="75+ echo -e "\n==== Checking Gawk ===="
76 76 
77 if command -v gawk &> /dev/null; then77 if command -v gawk &> /dev/null; then
78- echo "gawk已安装"78+ echo "Gawk has been installed"
79 return79 return
80 fi80 fi
81 81 
82- echo "安装gawk..."82+ echo "Installing Gawk..."
83 case "$OS" in83 case "$OS" in
84 debian)84 debian)
85 run_command sudo $PKG_MANAGER update85 run_command sudo $PKG_MANAGER update
@@ -94,28 +94,28 @@ install_gawk() {
94 esac94 esac
95 95 
96 if command -v gawk &> /dev/null; then96 if command -v gawk &> /dev/null; then
97- echo "gawk安装成功"97+ echo "Gawk installed successfully"
98 else98 else
99- echo "gawk安装失败"99+ echo "Gawk installation failed"
100 exit 1100 exit 1
101 fi101 fi
102}102}
103 103 
104install_python() {104install_python() {
105- # python版本号>=3.7.0105+ # Python version >= 3.7.0
106- echo -e "\n==== 检查Python ===="106+ echo -e "\n==== Checking Python ===="
107 local req_ver="3.7.0"107 local req_ver="3.7.0"
108 local curr_ver=""108 local curr_ver=""
109 109 
110 if command -v python3 &> /dev/null; then110 if command -v python3 &> /dev/null; then
111 curr_ver=$(python3 --version 2>&1 | awk '{print $2}')111 curr_ver=$(python3 --version 2>&1 | awk '{print $2}')
112- echo "当前Python版本:$curr_ver"112+ echo "Current Python version: $curr_ver"
113 if version_ge "$curr_ver" "$req_ver"; then113 if version_ge "$curr_ver" "$req_ver"; then
114- echo "Python满足要求"114+ echo "Python version meets requirements"
115 return115 return
116 fi116 fi
117 fi117 fi
118- echo "安装pyton..."118+ echo "Installing Python..."
119 case "$OS" in119 case "$OS" in
120 debian)120 debian)
121 run_command sudo $PKG_MANAGER update121 run_command sudo $PKG_MANAGER update
@@ -126,14 +126,14 @@ install_python() {
126 run_command sudo $PKG_MANAGER install -y centos-release-scl126 run_command sudo $PKG_MANAGER install -y centos-release-scl
127 run_command sudo $PKG_MANAGER install -y rh-python38 rh-python38-python-devel127 run_command sudo $PKG_MANAGER install -y rh-python38 rh-python38-python-devel
128 run_command source /opt/rh/rh-python38/enable128 run_command source /opt/rh/rh-python38/enable
129- echo "需要执行 'source /opt/rh/rh-python38/enable' 激活python3.8"129+ echo "Need to execute 'source /opt/rh/rh-python38/enable' to activate python3.8"
130 else130 else
131 run_command sudo $PKG_MANAGER install -y python3 python3-pip python3-devel131 run_command sudo $PKG_MANAGER install -y python3 python3-pip python3-devel
132 fi132 fi
133 ;;133 ;;
134 macos)134 macos)
135- run_command brew install python@3.11135+ run_command brew install python@3.10
136- echo 'export PATH="/usr/local/opt/python@3.11/bin:$PATH"' >> ~/.zshrc136+ echo 'export PATH="/usr/local/opt/python@3.10/bin:$PATH"' >> ~/.zshrc
137 run_command source ~/.zshrc137 run_command source ~/.zshrc
138 ;;138 ;;
139 esac139 esac
@@ -141,20 +141,20 @@ install_python() {
141 if command -v python3 &> /dev/null; then141 if command -v python3 &> /dev/null; then
142 curr_ver=$(python3 --version 2>&1 | awk '{print $2}')142 curr_ver=$(python3 --version 2>&1 | awk '{print $2}')
143 if version_ge "$curr_ver" "$req_ver"; then143 if version_ge "$curr_ver" "$req_ver"; then
144- echo "Python安装成功($curr_ver)"144+ echo "Python installed successfully ($curr_ver)"
145 else145 else
146- echo "Python版本仍不满足,请手动安装解决"146+ echo "Python version still doesn't meet requirements, please install manually"
147 exit 1147 exit 1
148 fi148 fi
149 else149 else
150- echo "Python安装失败"150+ echo "Python installation failed"
151 exit 1151 exit 1
152 fi152 fi
153}153}
154 154 
155install_gcc() {155install_gcc() {
156- # gcc版本号>=7.3.0156+ # GCC version >= 7.3.0
157- echo -e "\n==== 检查GCC ===="157+ echo -e "\n==== Checking GCC ===="
158 local req_ver="7.3.0"158 local req_ver="7.3.0"
159 local curr_ver=""159 local curr_ver=""
160 160 
@@ -165,13 +165,13 @@ install_gcc() {
165 else165 else
166 curr_ver="0.0.0"166 curr_ver="0.0.0"
167 fi167 fi
168- echo "当前GCC版本: $curr_ver"168+ echo "Current GCC version: $curr_ver"
169 if version_ge "$curr_ver" "$req_ver"; then169 if version_ge "$curr_ver" "$req_ver"; then
170- echo "GCC版本满足要求($curr_ver)"170+ echo "GCC version meets requirements ($curr_ver)"
171 return171 return
172 fi172 fi
173 173 
174- echo "安装GCC..."174+ echo "Installing GCC..."
175 case "$OS" in175 case "$OS" in
176 debian)176 debian)
177 run_command sudo $PKG_MANAGER update177 run_command sudo $PKG_MANAGER update
@@ -184,7 +184,7 @@ install_gcc() {
184 run_command sudo $PKG_MANAGER install -y centos-release-scl184 run_command sudo $PKG_MANAGER install -y centos-release-scl
185 run_command sudo $PKG_MANAGER install -y devtoolset-9-gcc devtoolset-9-gcc-c++185 run_command sudo $PKG_MANAGER install -y devtoolset-9-gcc devtoolset-9-gcc-c++
186 run_command source /opt/rh/devtoolset-9/enable186 run_command source /opt/rh/devtoolset-9/enable
187- echo "需要执行 'source /opt/rh/devtoolset-9/enable' 激活GCC9"187+ echo "Need to execute 'source /opt/rh/devtoolset-9/enable' to activate GCC9"
188 else188 else
189 run_command sudo $PKG_MANAGER install -y gcc gcc-c++189 run_command sudo $PKG_MANAGER install -y gcc gcc-c++
190 fi190 fi
@@ -203,52 +203,52 @@ install_gcc() {
203 if command -v gcc &> /dev/null; then203 if command -v gcc &> /dev/null; then
204 curr_ver=$(gcc --version | awk '/^gcc/ {print $4}')204 curr_ver=$(gcc --version | awk '/^gcc/ {print $4}')
205 if version_ge "$curr_ver" "$req_ver"; then205 if version_ge "$curr_ver" "$req_ver"; then
206- echo "GCC安装成功($curr_ver)"206+ echo "GCC installed successfully ($curr_ver)"
207 else207 else
208- echo "GCC版本仍不满足,请手动安装。"208+ echo "GCC version still doesn't meet requirements, please install manually."
209 exit 1209 exit 1
210 fi210 fi
211 else211 else
212- echo "GCC安装失败"212+ echo "GCC installation failed"
213 exit 1213 exit 1
214 fi214 fi
215}215}
216 216 
217install_cmake() {217install_cmake() {
218- # cmake版本号>=3.16.0218+ # CMake version >= 3.16.0
219- echo -e "\n==== 检查cmake ===="219+ echo -e "\n==== Checking CMake ===="
220 local req_ver="3.16.0"220 local req_ver="3.16.0"
221 local curr_ver=""221 local curr_ver=""
222 222 
223 if command -v cmake &> /dev/null; then223 if command -v cmake &> /dev/null; then
224 curr_ver=$(cmake --version | awk '/^cmake/ {print $3}')224 curr_ver=$(cmake --version | awk '/^cmake/ {print $3}')
225- echo "当前cmake版本: $curr_ver"225+ echo "Current CMake version: $curr_ver"
226 if version_ge "$curr_ver" "$req_ver"; then226 if version_ge "$curr_ver" "$req_ver"; then
227- echo "CMake满足要求"227+ echo "CMake meets requirements"
228 return228 return
229 fi229 fi
230 fi230 fi
231 231 
232- echo "安装CMake..."232+ echo "Installing CMake..."
233 case "$OS" in233 case "$OS" in
234 debian)234 debian)
235 if grep -q "Ubuntu 18.04" /etc/os-release; then235 if grep -q "Ubuntu 18.04" /etc/os-release; then
236 run_command wget -O - https://apt.kitware.com/keys/kitware-archive-latest.asc 2>/dev/null | gpg --dearmor - | sudo tee /usr/share/keyrings/kitware-archive-keyring.gpg >/dev/null236 run_command wget -O - https://apt.kitware.com/keys/kitware-archive-latest.asc 2>/dev/null | gpg --dearmor - | sudo tee /usr/share/keyrings/kitware-archive-keyring.gpg >/dev/null
237 run_command echo 'deb [signed-by=/usr/share/keyrings/kitware-archive-keyring.gpg] https://apt.kitware.com/ubuntu/ bionic main' | sudo tee /etc/apt/sources.list.d/kitware.list >/dev/null237 run_command echo 'deb [signed-by=/usr/share/keyrings/kitware-archive-keyring.gpg] https://apt.kitware.com/ubuntu/ bionic main' | sudo tee /etc/apt/sources.list.d/kitware.list >/dev/null
238 run_command sudo apt update238 run_command sudo apt update
239- run_command sudo apt install -y cmake239+ run_command sudo apt install -y cmake make
240 else240 else
241 run_command sudo $PKG_MANAGER update241 run_command sudo $PKG_MANAGER update
242- run_command sudo $PKG_MANAGER install -y cmake242+ run_command sudo $PKG_MANAGER install -y cmake make
243 fi243 fi
244 ;;244 ;;
245 rhel)245 rhel)
246 if grep -q "release 7" /etc/redhat-release; then246 if grep -q "release 7" /etc/redhat-release; then
247 run_command sudo $PKG_MANAGER install -y epel-release247 run_command sudo $PKG_MANAGER install -y epel-release
248- run_command sudo $PKG_MANAGER install -y cmake3248+ run_command sudo $PKG_MANAGER install -y cmake3 make
249 run_command sudo ln -s /usr/bin/cmake3 /usr/bin/cmake249 run_command sudo ln -s /usr/bin/cmake3 /usr/bin/cmake
250 else250 else
251- run_command sudo $PKG_MANAGER install -y cmake251+ run_command sudo $PKG_MANAGER install -y cmake make
252 fi252 fi
253 ;;253 ;;
254 macos)254 macos)
@@ -259,40 +259,40 @@ install_cmake() {
259 if command -v cmake &> /dev/null; then259 if command -v cmake &> /dev/null; then
260 curr_ver=$(cmake --version | awk '/^cmake/ {print $3}')260 curr_ver=$(cmake --version | awk '/^cmake/ {print $3}')
261 if version_ge "$curr_ver" "$req_ver"; then261 if version_ge "$curr_ver" "$req_ver"; then
262- echo "CMake安装成功($curr_ver)"262+ echo "CMake installed successfully ($curr_ver)"
263 else263 else
264- echo "CMake版本仍不满足,请手动安装"264+ echo "CMake version still doesn't meet requirements, please install manually"
265 exit 1265 exit 1
266 fi266 fi
267 else267 else
268- echo "CMake安装失败"268+ echo "CMake installation failed"
269 exit 1269 exit 1
270 fi270 fi
271}271}
272 272 
273install_pigz() {273install_pigz() {
274- # pigz版本号>=2.4274+ # pigz version >= 2.4
275- echo -e "\n==== 检查pigz ===="275+ echo -e "\n==== Checking pigz ===="
276 local req_ver="2.4"276 local req_ver="2.4"
277 local curr_ver=""277 local curr_ver=""
278 278 
279 if command -v pigz &> /dev/null; then279 if command -v pigz &> /dev/null; then
280 curr_ver=$(pigz --version 2>&1 | awk '{print $2}')280 curr_ver=$(pigz --version 2>&1 | awk '{print $2}')
281- echo "当前pigz版本: $curr_ver"281+ echo "Current pigz version: $curr_ver"
282 if version_ge "$curr_ver" "$req_ver"; then282 if version_ge "$curr_ver" "$req_ver"; then
283- echo "pigz满足要求"283+ echo "pigz meets requirements"
284 return284 return
285 fi285 fi
286 fi286 fi
287 287 
288- read -p "安装pigz?[Y/n] " -n 1 -r288+ read -p "Install pigz? [Y/n] " -n 1 -r
289 echo289 echo
290 if [[ ! $REPLY =~ ^[Yy]$ ]]; then290 if [[ ! $REPLY =~ ^[Yy]$ ]]; then
291- echo "跳过pigz安装"291+ echo "Skipping pigz installation"
292 return292 return
293 fi293 fi
294 294 
295- echo "安装pigz..."295+ echo "Installing pigz..."
296 case "$OS" in296 case "$OS" in
297 debian|rhel)297 debian|rhel)
298 run_command sudo $PKG_MANAGER install -y pigz298 run_command sudo $PKG_MANAGER install -y pigz
@@ -304,22 +304,21 @@ install_pigz() {
304 304 
305 if command -v pigz &> /dev/null; then305 if command -v pigz &> /dev/null; then
306 curr_ver=$(pigz --version 2>&1 | awk '{print $2}')306 curr_ver=$(pigz --version 2>&1 | awk '{print $2}')
307- echo "pigz安装成功($curr_ver)"307+ echo "pigz installed successfully ($curr_ver)"
308 else308 else
309- echo "pigz安装失败,可忽略"309+ echo "pigz installation failed, can be ignored"
310 fi310 fi
311}311}
312 312 
313- 
314install_dos2unix() {313install_dos2unix() {
315- echo -e "\n==== 检查dos2unix ===="314+ echo -e "\n==== Checking dos2unix ===="
316 315 
317 if command -v dos2unix &> /dev/null; then316 if command -v dos2unix &> /dev/null; then
318- echo "dos2unix已安装"317+ echo "dos2unix has been installed"
319 return318 return
320 fi319 fi
321 320 
322- echo "安装dos2unix..."321+ echo "Installing dos2unix..."
323 case "$OS" in322 case "$OS" in
324 debian|rhel)323 debian|rhel)
325 run_command sudo $PKG_MANAGER install -y dos2unix324 run_command sudo $PKG_MANAGER install -y dos2unix
@@ -330,56 +329,56 @@ install_dos2unix() {
330 esac329 esac
331 330 
332 if command -v dos2unix &> /dev/null; then331 if command -v dos2unix &> /dev/null; then
333- echo "dos2unix安装成功"332+ echo "dos2unix installed successfully"
334 else333 else
335- echo "dos2unix安装失败"334+ echo "dos2unix installation failed"
336 exit 1335 exit 1
337 fi336 fi
338}337}
339 338 
340install_googletest() {339install_googletest() {
341- # googletest建议版本使用release-1.11.0340+ # Recommended googletest version: release-1.11.0
342- echo -e "\n==== 检查googletest ===="341+ echo -e "\n==== Checking googletest ===="
343 local req_ver="1.11.0"342 local req_ver="1.11.0"
344 local curr_ver=""343 local curr_ver=""
345 local gtest_src_dir="/usr/src/gtest"344 local gtest_src_dir="/usr/src/gtest"
346 345 
347 if pkg-config --exists gtest; then346 if pkg-config --exists gtest; then
348 curr_ver=$(pkg-config --modversion gtest)347 curr_ver=$(pkg-config --modversion gtest)
349- echo "当前googletest版本: $curr_ver"348+ echo "Current googletest version: $curr_ver"
350 if version_ge "$curr_ver" "$req_ver"; then349 if version_ge "$curr_ver" "$req_ver"; then
351- echo "googletest满足要求"350+ echo "googletest meets requirements"
352 return351 return
353 fi352 fi
354 fi353 fi
355- read -p "安装googletest?[Y/n] " -n 1 -r354+ read -p "Install googletest? [Y/n] " -n 1 -r
356 echo355 echo
357 if [[ ! $REPLY =~ ^[Yy]$ ]]; then356 if [[ ! $REPLY =~ ^[Yy]$ ]]; then
358- echo "跳过googletest安装"357+ echo "Skipping googletest installation"
359 return358 return
360 fi359 fi
361 360 
362- echo "安装googletest..."361+ echo "Installing googletest..."
363 case "$OS" in362 case "$OS" in
364 debian)363 debian)
365- # 安装libgtest-dev364+ # Install libgtest-dev
366 run_command sudo $PKG_MANAGER install -y libgtest-dev365 run_command sudo $PKG_MANAGER install -y libgtest-dev
367- # 检查gtest源码目录是否存在366+ # Check if gtest source directory exists
368- if [ ! -d "$gtest_src_dir"]; then367+ if [ ! -d "$gtest_src_dir" ]; then
369- echo "未找到googletest源码目录:$gtest_src_dir"368+ echo "googletest source directory not found: $gtest_src_dir"
370- echo "尝试重新安装libgtest-dev..."369+ echo "Attempting to reinstall libgtest-dev..."
371 run_command sudo $PKG_MANAGER purge -y libgtest-dev370 run_command sudo $PKG_MANAGER purge -y libgtest-dev
372 run_command sudo $PKG_MANAGER install -y libgtest-dev371 run_command sudo $PKG_MANAGER install -y libgtest-dev
373- # 再次检查目录372+ # Check directory again
374 if [ ! -d "$gtest_src_dir" ]; then373 if [ ! -d "$gtest_src_dir" ]; then
375- echo "仍然无法找到$gtest_src_dir,请手动安装:"374+ echo "Still cannot find $gtest_src_dir, please install manually:"
376- echo "1.下载源码:wget https://github.com/google/googletest/archive/refs/tags/release-1.11.0.tar.gz"375+ echo "1. Download source: wget https://github.com/google/googletest/archive/refs/tags/release-1.11.0.tar.gz"
377- echo "2.解压并编译:tar -zxf release-1.11.0.tar.gz && cd googletest-release-1.11.0 && cmake . && make && sudo make install"376+ echo "2. Extract and compile: tar -zxf release-1.11.0.tar.gz && cd googletest-release-1.11.0 && cmake . && make && sudo make install"
378 exit 1377 exit 1
379 fi378 fi
380 fi379 fi
381- # 强制在gtest源码目录执行cmake(即使cd失败也能正确执行)380+ # Force cmake execution in gtest source directory (even if cd fails)
382- echo "进入$gtest_src_dir编译..."381+ echo "Entering $gtest_src_dir to compile..."
383 run_command sudo cmake -S "$gtest_src_dir" -B "$gtest_src_dir/build"382 run_command sudo cmake -S "$gtest_src_dir" -B "$gtest_src_dir/build"
384 run_command sudo make -C "$gtest_src_dir/build"383 run_command sudo make -C "$gtest_src_dir/build"
385 run_command sudo cp "$gtest_src_dir/build/lib/"*.a /usr/lib384 run_command sudo cp "$gtest_src_dir/build/lib/"*.a /usr/lib
@@ -395,16 +394,16 @@ install_googletest() {
395 394 
396 if pkg-config --exists gtest; then395 if pkg-config --exists gtest; then
397 curr_ver=$(pkg-config --modversion gtest)396 curr_ver=$(pkg-config --modversion gtest)
398- echo "googletest安装成功($curr_ver)"397+ echo "googletest installed successfully ($curr_ver)"
399 else398 else
400- echo "googletest安装失败"399+ echo "googletest installation failed"
401 exit 1400 exit 1
402 fi401 fi
403}402}
404 403 
405main() {404main() {
406 echo "===================================================="405 echo "===================================================="
407- echo "开始安装项目依赖"406+ echo "Starting project dependency installation"
408 echo "===================================================="407 echo "===================================================="
409 408 
410 detect_os409 detect_os
@@ -417,7 +416,7 @@ main() {
417 install_googletest416 install_googletest
418 417 
419 echo -e "===================================================="418 echo -e "===================================================="
420- echo "所有依赖安装完成!"419+ echo "All dependencies installed successfully!"
421 echo "===================================================="420 echo "===================================================="
422}421}
423 422