diff --git a/plugins/cann-toolkit/config.yaml b/plugins/cann-toolkit/config.yaml new file mode 100644 index 0000000000000000000000000000000000000000..77a04a1a55b80aa9da353ef2692b071062625b16 --- /dev/null +++ b/plugins/cann-toolkit/config.yaml @@ -0,0 +1,31 @@ +all: + hosts: + target-host: + ansible_host: 127.0.0.1 # 目标主机IP地址 + ansible_port: 22 # SSH端口号 + ansible_user: root # 用户名(只能使用root用户或具有sudo权限的用户) + ansible_password: "" # 密码 + vars: + # SSH连接配置 + ansible_ssh_common_args: '-o StrictHostKeyChecking=no' + + # ========== CANN工具链配置参数 ========== + + # 硬件型号配置 + # 可选范围: 310b, 310p, 910, 910b, Atlas-A3 + hardware_model: "Atlas-A3" + + # NNAL神经网络加速库类型配置 + # 可选范围: ATB, SiP + nnal_type: "ATB" + + # ========== 高级配置(可选) ========== + + # 是否强制重新安装(即使已安装) + force_install: false + + # 是否跳过环境变量配置(如果用户已手动配置) + skip_env_config: false + + # 是否启用详细日志输出 + verbose_logging: true diff --git a/plugins/cann-toolkit/doc/readme.md b/plugins/cann-toolkit/doc/readme.md new file mode 100644 index 0000000000000000000000000000000000000000..c6f3e24cf6eb6e72b5cc16412bfca8f3ea6a5559 --- /dev/null +++ b/plugins/cann-toolkit/doc/readme.md @@ -0,0 +1,238 @@ +# CANN Toolkit 一键部署插件 + +## 插件简介 + +CANN Toolkit 一键部署插件是基于 oeDeploy 框架开发的自动化部署工具,用于在 openEuler 系统上快速部署昇腾 CANN(Compute Architecture for Neural Networks)工具链。 + +该插件支持以下组件的自动化安装和卸载: +- **Toolkit 开发套件包**:提供开发和编译环境 +- **Kernels 算子包**:针对不同硬件型号的算子库 +- **NNAL 神经网络加速库**:支持 ATB 和 SiP 两种加速库类型 +- **NNAE 神经网络加速引擎**:提供神经网络加速能力 +- **NNRT 神经网络运行时环境**:提供运行时支持 + +## 系统要求 + +- **操作系统**:openEuler 24.03-LTS-SPX +- **用户权限**:root 用户或具有 sudo 权限的用户 +- **网络连接**:需要访问互联网下载软件包和依赖 +- **硬件支持**:支持昇腾 AI 处理器(310b/310p/910/910b/Atlas-A3) + +## 配置参数 + +### 主要配置项 + +在 `config.yaml` 中可以配置以下参数: + +| 参数名 | 类型 | 默认值 | 说明 | +|--------|------|---------|------| +| `hardware_model` | string | "Atlas-A3" | 硬件型号,可选:310b, 310p, 910, 910b, Atlas-A3 | +| `nnal_type` | string | "ATB" | NNAL加速库类型,可选:ATB, SiP | +| `force_install` | boolean | false | 是否强制重新安装(即使已安装) | +| `skip_env_config` | boolean | false | 是否跳过环境变量配置 | +| `verbose_logging` | boolean | true | 是否启用详细日志输出 | + +### 连接配置 + +```yaml +all: + hosts: + target-host: + ansible_host: 127.0.0.1 # 目标主机IP地址 + ansible_port: 22 # SSH端口号 + ansible_user: root # 用户名(建议使用root用户) + ansible_password: "" # 密码 +``` + +## 支持的操作 + +### 一键操作 + +- **`install`**:一键安装所有 CANN 组件 +- **`uninstall`**:一键卸载所有 CANN 组件 +- **`run-samples`**:下载并执行用例代码 + +### 单独操作 + +#### 安装操作 +- **`sub:env-prepare`**:环境准备(安装依赖包、配置软件源) +- **`sub:install-toolkit`**:安装 Toolkit 开发套件包 +- **`sub:install-kernels`**:安装 Kernels 算子包 +- **`sub:install-nnal`**:安装 NNAL 神经网络加速库 +- **`sub:install-nnae`**:安装 NNAE 神经网络加速引擎 +- **`sub:install-nnrt`**:安装 NNRT 神经网络运行时环境 + +#### 卸载操作 +- **`sub:uninstall-toolkit`**:卸载 Toolkit 开发套件包 +- **`sub:uninstall-kernels`**:卸载 Kernels 算子包 +- **`sub:uninstall-nnal`**:卸载 NNAL 神经网络加速库 +- **`sub:uninstall-nnae`**:卸载 NNAE 神经网络加速引擎 +- **`sub:uninstall-nnrt`**:卸载 NNRT 神经网络运行时环境 +- **`sub:env-cleanup`**:环境清理 + +## 使用方法 + +### 1. 获取插件 + +```bash +# 下载插件包 +wget https://example.com/cann-toolkit.tar.gz +tar -xzf cann-toolkit.tar.gz +cd cann-toolkit +``` + +### 2. 配置参数 + +编辑 `config.yaml` 文件,设置目标主机信息和硬件型号: + +```yaml +all: + hosts: + target-host: + ansible_host: 192.168.1.100 # 修改为实际IP + ansible_user: root + ansible_password: "your_password" + vars: + hardware_model: "Atlas-A3" # 根据实际硬件修改 + nnal_type: "ATB" # 选择加速库类型 +``` + +### 3. 执行部署 + +```bash +# 一键安装所有组件 +oedp run install + +# 或者分步安装 +oedp run sub:env-prepare # 环境准备 +oedp run sub:install-toolkit # 安装 Toolkit +oedp run sub:install-kernels # 安装 Kernels +oedp run sub:install-nnal # 安装 NNAL +oedp run sub:install-nnae # 安装 NNAE +oedp run sub:install-nnrt # 安装 NNRT + +# 执行用例代码 +oedp run run-samples + +# 一键卸载 +oedp run uninstall +``` + +### 4. 验证安装 + +安装完成后,需要重新加载环境变量: + +```bash +source /root/.bashrc +``` + +然后可以验证安装: + +```bash +# 检查环境变量 +echo $ASCEND_TOOLKIT_HOME + +# 运行用例代码 +oedp run run-samples +``` + +## 硬件型号支持 + +| 硬件型号 | Kernels 包名 | 说明 | +|----------|-------------|------| +| 310b | Ascend-cann-kernels-310b | 昇腾310B处理器 | +| 310p | Ascend-cann-kernels-310p | 昇腾310P处理器 | +| 910 | Ascend-cann-kernels-910 | 昇腾910处理器 | +| 910b | Ascend-cann-kernels-910b | 昇腾910B处理器 | +| Atlas-A3 | Atlas-A3-cann-kernels | Atlas A3训练卡 | + +## NNAL 加速库类型 + +- **ATB**:Ascend Tensor Boost,昇腾张量加速库 +- **SiP**:System in Package,系统级封装加速库 + +**注意**:ATB 和 SiP 不能同时使用,插件会自动处理冲突。 + +## 用例代码 + +插件会自动下载并执行以下用例: + +1. `AddKernelInvocationNeo` - 基础算子调用示例 +2. `AddKernelInvocationTilingNeo` - Tiling算子调用示例 +3. `addn_kernellaunch` - 多输入加法算子示例 +4. `MatmulLeakyReluInvocation` - 矩阵乘法+LeakyRelu融合算子示例 +5. `MatmulInvocationNeo` - 矩阵乘法算子示例 + +## 环境变量 + +插件会自动配置以下环境变量到 `/root/.bashrc`: + +```bash +# C++编译环境 +export CPLUS_INCLUDE_PATH=/usr/include/c++/12:/usr/include/c++/12/backward:/usr/include/c++/12/x86_64-openEuler-linux/:$CPLUS_INCLUDE_PATH + +# CANN组件环境变量 +source /usr/local/Ascend/ascend-toolkit/set_env.sh +source /usr/local/Ascend/nnae/set_env.sh +source /usr/local/Ascend/nnal/atb/set_env.sh # 或 asdsip/set_env.sh +source /usr/local/Ascend/nnrt/set_env.sh +``` + +## 故障排除 + +### 常见问题 + +1. **权限不足** + - 确保使用 root 用户或具有 sudo 权限的用户 + - 检查 SSH 连接配置 + +2. **网络连接问题** + - 检查网络连接 + - 确认可以访问昇腾软件源 + +3. **硬件型号不匹配** + - 确认 `hardware_model` 配置正确 + - 检查硬件是否支持 + +4. **环境变量未生效** + - 执行 `source /root/.bashrc` 重新加载 + - 或重新登录 bash 会话 + +### 日志查看 + +启用详细日志输出: + +```yaml +vars: + verbose_logging: true +``` + +### 重新安装 + +如需重新安装: + +```yaml +vars: + force_install: true +``` + +## 技术支持 + +如遇到问题,请检查: + +1. 系统版本是否支持 +2. 网络连接是否正常 +3. 硬件型号配置是否正确 +4. 用户权限是否足够 + +更多信息请参考昇腾官方文档:https://www.hiascend.com/ + +## 版本信息 + +- **插件版本**:1.0.0 +- **支持的CANN版本**:8.2.RC1 +- **兼容的oeDeploy版本**:1.0+ + +## 许可证 + +本插件遵循开源许可证,具体请参考相关组件的许可证条款。 diff --git a/plugins/cann-toolkit/main.yaml b/plugins/cann-toolkit/main.yaml new file mode 100644 index 0000000000000000000000000000000000000000..138f491da7be156cea57a6b86df2bbd9dc69a78f --- /dev/null +++ b/plugins/cann-toolkit/main.yaml @@ -0,0 +1,153 @@ +name: cann-toolkit +version: 1.0.0 +description: CANN (Compute Architecture for Neural Networks) Toolkit deployment plugin +description_zh: 昇腾CANN工具链一键部署插件,支持Toolkit开发套件包、Kernels算子包、NNAL神经网络加速库、NNAE神经网络加速引擎、NNRT神经网络运行时环境的安装和卸载 +description_en: Ascend CANN Toolkit deployment plugin for one-click installation and uninstallation of Toolkit, Kernels, NNAL, NNAE, and NNRT components +type: app +localhost_available: true +action: + install: + description: 一键安装CANN开发环境(环境准备, 安装Toolkit, Kernels算子包, NNAL, NNAE, NNRT) + tasks: + - name: 环境准备 + playbook: prepare.yaml + vars: variables.yaml + scope: all + - name: 安装Toolkit开发套件包 + playbook: install-toolkit.yaml + vars: variables.yaml + scope: all + - name: 安装Kernels算子包 + playbook: install-kernels.yaml + vars: variables.yaml + scope: all + - name: 安装NNAL神经网络加速库 + playbook: install-nnal.yaml + vars: variables.yaml + scope: all + - name: 安装NNAE神经网络加速引擎 + playbook: install-nnae.yaml + vars: variables.yaml + scope: all + - name: 安装NNRT神经网络运行时环境 + playbook: install-nnrt.yaml + vars: variables.yaml + scope: all + uninstall: + description: 一键卸载CANN开发环境(卸载NNRT, NNAE, NNAL, Kernels算子包, Toolkit, 环境清理) + tasks: + - name: 卸载NNRT神经网络运行时环境 + playbook: uninstall-nnrt.yaml + vars: variables.yaml + scope: all + - name: 卸载NNAE神经网络加速引擎 + playbook: uninstall-nnae.yaml + vars: variables.yaml + scope: all + - name: 卸载NNAL神经网络加速库 + playbook: uninstall-nnal.yaml + vars: variables.yaml + scope: all + - name: 卸载Kernels算子包 + playbook: uninstall-kernels.yaml + vars: variables.yaml + scope: all + - name: 卸载Toolkit开发套件包 + playbook: uninstall-toolkit.yaml + vars: variables.yaml + scope: all + - name: 环境清理 + playbook: cleanup.yaml + vars: variables.yaml + scope: all + run-samples: + description: 执行用例代码 + tasks: + - name: 下载并执行用例代码 + playbook: run-samples.yaml + vars: variables.yaml + scope: all + sub:env-prepare: + description: 环境准备 + tasks: + - name: 环境准备 + playbook: prepare.yaml + vars: variables.yaml + scope: all + sub:install-toolkit: + description: 安装Toolkit开发套件包(依赖环境准备) + tasks: + - name: 安装Toolkit开发套件包 + playbook: install-toolkit.yaml + vars: variables.yaml + scope: all + sub:install-kernels: + description: 安装Kernels算子包(依赖Toolkit) + tasks: + - name: 安装Kernels算子包 + playbook: install-kernels.yaml + vars: variables.yaml + scope: all + sub:install-nnal: + description: 安装NNAL神经网络加速库 + tasks: + - name: 安装NNAL神经网络加速库 + playbook: install-nnal.yaml + vars: variables.yaml + scope: all + sub:install-nnae: + description: 安装NNAE神经网络加速引擎 + tasks: + - name: 安装NNAE神经网络加速引擎 + playbook: install-nnae.yaml + vars: variables.yaml + scope: all + sub:install-nnrt: + description: 安装NNRT神经网络运行时环境 + tasks: + - name: 安装NNRT神经网络运行时环境 + playbook: install-nnrt.yaml + vars: variables.yaml + scope: all + sub:env-cleanup: + description: 环境清理(环境准备的逆过程) + tasks: + - name: 环境清理 + playbook: cleanup.yaml + vars: variables.yaml + scope: all + sub:uninstall-toolkit: + description: 卸载Toolkit开发套件包 + tasks: + - name: 卸载Toolkit开发套件包 + playbook: uninstall-toolkit.yaml + vars: variables.yaml + scope: all + sub:uninstall-kernels: + description: 卸载Kernels算子包 + tasks: + - name: 卸载Kernels算子包 + playbook: uninstall-kernels.yaml + vars: variables.yaml + scope: all + sub:uninstall-nnal: + description: 卸载NNAL神经网络加速库 + tasks: + - name: 卸载NNAL神经网络加速库 + playbook: uninstall-nnal.yaml + vars: variables.yaml + scope: all + sub:uninstall-nnae: + description: 卸载NNAE神经网络加速引擎 + tasks: + - name: 卸载NNAE神经网络加速引擎 + playbook: uninstall-nnae.yaml + vars: variables.yaml + scope: all + sub:uninstall-nnrt: + description: 卸载NNRT神经网络运行时环境 + tasks: + - name: 卸载NNRT神经网络运行时环境 + playbook: uninstall-nnrt.yaml + vars: variables.yaml + scope: all diff --git a/plugins/cann-toolkit/workspace/cleanup.yaml b/plugins/cann-toolkit/workspace/cleanup.yaml new file mode 100644 index 0000000000000000000000000000000000000000..e84db7af3d5d0154c8c1d190257e775b69cce811 --- /dev/null +++ b/plugins/cann-toolkit/workspace/cleanup.yaml @@ -0,0 +1,131 @@ +--- +- hosts: all + become: yes + gather_facts: no + tasks: + - name: Check if C++ environment variables are configured + shell: grep -q "CPLUS_INCLUDE_PATH.*c++" /root/.bashrc + register: cpp_env_check + failed_when: false + changed_when: false + become: no + + - name: Remove C++ environment variable configuration + lineinfile: + path: /root/.bashrc + regexp: ".*CPLUS_INCLUDE_PATH.*c\\+\\+.*" + state: absent + backup: yes + when: cpp_env_check.rc == 0 + become: no + register: cpp_env_removed + + - name: Display C++ environment variable removal result + debug: + msg: + - "========================================" + - "C++环境变量配置已从.bashrc中移除" + - "========================================" + when: cpp_env_removed.changed + + - name: Check if Ascend software repository exists + stat: + path: "{{ ascend_repo.path }}" + register: ascend_repo_stat + + - name: Remove Ascend software repository + file: + path: "{{ ascend_repo.path }}" + state: absent + when: ascend_repo_stat.stat.exists + register: repo_removed + + - name: Display Ascend software repository removal result + debug: + msg: + - "========================================" + - "昇腾软件源已移除" + - "路径: {{ ascend_repo.path }}" + - "========================================" + when: repo_removed.changed + + - name: Update yum cache + yum: + update_cache: yes + when: repo_removed.changed + + - name: Check if system dependency packages need to be uninstalled + debug: + msg: + - "========================================" + - "注意: 系统依赖包不会被自动卸载" + - "这些包可能被其他应用程序使用:" + - "{{ system_packages | join(', ') }}" + - "如需卸载,请手动执行:" + - "sudo yum remove {{ system_packages | join(' ') }}" + - "========================================" + + - name: Check if Python third-party libraries need to be uninstalled + debug: + msg: + - "========================================" + - "注意: Python第三方库不会被自动卸载" + - "这些库可能被其他应用程序使用:" + - "{{ python_packages | join(', ') }}" + - "如需卸载,请手动执行:" + - "pip3 uninstall {{ python_packages | join(' ') }}" + - "========================================" + + - name: Check if sample code directory exists + stat: + path: "{{ samples_config.clone_path }}" + register: samples_dir_stat + + - name: Ask whether to delete sample code directory + debug: + msg: + - "========================================" + - "发现用例代码目录: {{ samples_config.clone_path }}" + - "如需删除,请手动执行:" + - "rm -rf {{ samples_config.clone_path }}" + - "========================================" + when: samples_dir_stat.stat.exists + + - name: Clean yum cache + shell: yum clean all + register: yum_clean_result + + - name: Display yum cache cleanup result + debug: + msg: + - "========================================" + - "yum缓存已清理" + - "========================================" + when: yum_clean_result.changed + + - name: Display environment variable update reminder + debug: + msg: + - "========================================" + - "环境清理已完成" + - "已移除C++环境变量配置和昇腾软件源" + - "如果修改了环境变量,请执行:" + - "source /root/.bashrc" + - "或者重新登录bash会话" + - "========================================" + when: cpp_env_removed.changed or repo_removed.changed + + - name: Display cleanup completion information + debug: + msg: + - "========================================" + - "环境清理操作完成" + - "已执行的清理操作:" + - "- 移除C++环境变量配置" + - "- 移除昇腾软件源" + - "- 清理yum缓存" + - "未自动执行的操作(需手动处理):" + - "- 卸载系统依赖包" + - "- 卸载Python第三方库" + - "- 删除用例代码目录" + - "========================================" diff --git a/plugins/cann-toolkit/workspace/install-kernels.yaml b/plugins/cann-toolkit/workspace/install-kernels.yaml new file mode 100644 index 0000000000000000000000000000000000000000..d45a2cd941b939a5584e66d85cfba5cd8f522e97 --- /dev/null +++ b/plugins/cann-toolkit/workspace/install-kernels.yaml @@ -0,0 +1,28 @@ +--- +- hosts: all + become: yes + gather_facts: no + tasks: + - name: Set Kernels package name variable + set_fact: + kernels_package_name: "{{ kernels_packages[hardware_model] }}" + + - name: Validate hardware model configuration + fail: + msg: "不支持的硬件型号: {{ hardware_model }}. 支持的型号: {{ kernels_packages.keys() | list | join(', ') }}" + when: hardware_model not in kernels_packages + + - name: Install Kernels operator package + shell: script -q -c 'yum install -y "{{ kernels_package_name }}"' /dev/null + register: kernels_install_result + + - name: Display Kernels installation result + debug: + msg: + - "========================================" + - "CANN Kernels 算子包安装操作完成" + - "硬件型号: {{ hardware_model }}" + - "包名: {{ kernels_package_name }}" + - "状态: {{ 'Success' if kernels_install_result.rc == 0 else 'Failed' }}" + - "========================================" + diff --git a/plugins/cann-toolkit/workspace/install-nnae.yaml b/plugins/cann-toolkit/workspace/install-nnae.yaml new file mode 100644 index 0000000000000000000000000000000000000000..e73573ad9b51dec3f13a6b17c1e46f83a9074aec --- /dev/null +++ b/plugins/cann-toolkit/workspace/install-nnae.yaml @@ -0,0 +1,61 @@ +--- +- hosts: all + become: yes + gather_facts: no + tasks: + - name: Install NNAE neural network acceleration engine + shell: script -q -c 'yum install -y "{{ cann_packages.nnae }}"' /dev/null + register: nnae_install_result + + - name: Display NNAE installation result + debug: + msg: + - "========================================" + - "CANN NNAE 神经网络加速引擎安装操作完成" + - "包名: {{ cann_packages.nnae }}" + - "状态: {{ 'Success' if nnae_install_result.rc == 0 else 'Failed' }}" + - "========================================" + + - name: Check if NNAE environment variable script exists + stat: + path: "{{ env_scripts.nnae }}" + register: nnae_env_script + + - name: Display NNAE installation error message + debug: + msg: + - "========================================" + - "错误: NNAE安装可能有问题" + - "找不到环境变量脚本: {{ env_scripts.nnae }}" + - "请检查安装包是否正确安装" + - "========================================" + when: not nnae_env_script.stat.exists + + - name: Fail if NNAE environment variable script not found + fail: + msg: "NNAE环境变量脚本不存在,安装失败" + when: not nnae_env_script.stat.exists + + - name: Check if NNAE environment variables are configured + shell: grep -q "{{ env_scripts.nnae }}" /root/.bashrc + register: nnae_env_check + failed_when: false + changed_when: false + become: no + when: nnae_env_script.stat.exists and not skip_env_config + + - name: Configure NNAE environment variables to .bashrc + lineinfile: + path: /root/.bashrc + line: "source {{ env_scripts.nnae }}" + create: yes + backup: yes + when: nnae_env_script.stat.exists and nnae_env_check.rc != 0 and not skip_env_config + become: no + register: nnae_env_configured + + - name: Display environment variable configuration reminder + debug: + msg: "{{ env_reminder_message }}" + when: nnae_env_configured.changed + diff --git a/plugins/cann-toolkit/workspace/install-nnal.yaml b/plugins/cann-toolkit/workspace/install-nnal.yaml new file mode 100644 index 0000000000000000000000000000000000000000..bf285bca4b6a99ffcc0086958b41316a95974997 --- /dev/null +++ b/plugins/cann-toolkit/workspace/install-nnal.yaml @@ -0,0 +1,100 @@ +--- +- hosts: all + become: yes + gather_facts: no + tasks: + - name: Validate NNAL type configuration + fail: + msg: "不支持的NNAL类型: {{ nnal_type }}. 支持的类型: ATB, SiP" + when: nnal_type not in ['ATB', 'SiP'] + + - name: Install NNAL neural network acceleration library + shell: script -q -c 'yum install -y "{{ cann_packages.nnal }}"' /dev/null + register: nnal_install_result + + - name: Display NNAL installation result + debug: + msg: + - "========================================" + - "CANN NNAL 神经网络加速库安装操作完成" + - "包名: {{ cann_packages.nnal }}" + - "状态: {{ 'Success' if nnal_install_result.rc == 0 else 'Failed' }}" + - "========================================" + + - name: Set NNAL environment variable script path + set_fact: + nnal_env_script: "{{ env_scripts.nnal_atb if nnal_type == 'ATB' else env_scripts.nnal_sip }}" + other_nnal_env_script: "{{ env_scripts.nnal_sip if nnal_type == 'ATB' else env_scripts.nnal_atb }}" + + - name: Check if NNAL environment variable script exists + stat: + path: "{{ nnal_env_script }}" + register: nnal_env_script_stat + + - name: Display NNAL installation error message + debug: + msg: + - "========================================" + - "错误: NNAL安装可能有问题" + - "找不到环境变量脚本: {{ nnal_env_script }}" + - "NNAL类型: {{ nnal_type }}" + - "请检查安装包是否正确安装" + - "========================================" + when: not nnal_env_script_stat.stat.exists + + - name: Fail if NNAL environment variable script not found + fail: + msg: "NNAL环境变量脚本不存在,安装失败" + when: not nnal_env_script_stat.stat.exists + + - name: Check if current NNAL environment variables are configured + shell: grep -q "{{ nnal_env_script }}" /root/.bashrc + register: nnal_env_check + failed_when: false + changed_when: false + become: no + when: nnal_env_script_stat.stat.exists and not skip_env_config + + - name: Check if other NNAL environment variables are configured (need to remove) + shell: grep -q "{{ other_nnal_env_script }}" /root/.bashrc + register: other_nnal_env_check + failed_when: false + changed_when: false + become: no + when: not skip_env_config + + - name: Remove other NNAL environment variable configurations + lineinfile: + path: /root/.bashrc + regexp: ".*{{ other_nnal_env_script }}.*" + state: absent + backup: yes + when: other_nnal_env_check.rc == 0 and not skip_env_config + become: no + register: other_nnal_env_removed + + - name: Display NNAL environment variable conflict handling information + debug: + msg: + - "========================================" + - "已移除冲突的NNAL环境变量配置" + - "移除的脚本: {{ other_nnal_env_script }}" + - "NNAL不支持同时配置ATB和SiP加速库" + - "========================================" + when: other_nnal_env_removed.changed + + - name: Configure NNAL environment variables to .bashrc + lineinfile: + path: /root/.bashrc + line: "source {{ nnal_env_script }}" + create: yes + backup: yes + when: nnal_env_script_stat.stat.exists and nnal_env_check.rc != 0 and not skip_env_config + become: no + register: nnal_env_configured + + - name: Display environment variable configuration reminder + debug: + msg: "{{ env_reminder_message }}" + when: nnal_env_configured.changed or other_nnal_env_removed.changed + diff --git a/plugins/cann-toolkit/workspace/install-nnrt.yaml b/plugins/cann-toolkit/workspace/install-nnrt.yaml new file mode 100644 index 0000000000000000000000000000000000000000..f0fcb93ea2fc702e40d2a4800167157e562dff14 --- /dev/null +++ b/plugins/cann-toolkit/workspace/install-nnrt.yaml @@ -0,0 +1,61 @@ +--- +- hosts: all + become: yes + gather_facts: no + tasks: + - name: Install NNRT neural network runtime environment + shell: script -q -c 'yum install -y "{{ cann_packages.nnrt }}"' /dev/null + register: nnrt_install_result + + - name: Display NNRT installation result + debug: + msg: + - "========================================" + - "CANN NNRT 神经网络运行时环境安装操作完成" + - "包名: {{ cann_packages.nnrt }}" + - "状态: {{ 'Success' if nnrt_install_result.rc == 0 else 'Failed' }}" + - "========================================" + + - name: Check if NNRT environment variable script exists + stat: + path: "{{ env_scripts.nnrt }}" + register: nnrt_env_script + + - name: Display NNRT installation error message + debug: + msg: + - "========================================" + - "错误: NNRT安装可能有问题" + - "找不到环境变量脚本: {{ env_scripts.nnrt }}" + - "请检查安装包是否正确安装" + - "========================================" + when: not nnrt_env_script.stat.exists + + - name: Fail if NNRT environment variable script not found + fail: + msg: "NNRT环境变量脚本不存在,安装失败" + when: not nnrt_env_script.stat.exists + + - name: Check if NNRT environment variables are configured + shell: grep -q "{{ env_scripts.nnrt }}" /root/.bashrc + register: nnrt_env_check + failed_when: false + changed_when: false + become: no + when: nnrt_env_script.stat.exists and not skip_env_config + + - name: Configure NNRT environment variables to .bashrc + lineinfile: + path: /root/.bashrc + line: "source {{ env_scripts.nnrt }}" + create: yes + backup: yes + when: nnrt_env_script.stat.exists and nnrt_env_check.rc != 0 and not skip_env_config + become: no + register: nnrt_env_configured + + - name: Display environment variable configuration reminder + debug: + msg: "{{ env_reminder_message }}" + when: nnrt_env_configured.changed + diff --git a/plugins/cann-toolkit/workspace/install-toolkit.yaml b/plugins/cann-toolkit/workspace/install-toolkit.yaml new file mode 100644 index 0000000000000000000000000000000000000000..16080b28983ef0614ff3bb50c274ebf22a821cda --- /dev/null +++ b/plugins/cann-toolkit/workspace/install-toolkit.yaml @@ -0,0 +1,60 @@ +--- +- hosts: all + become: yes + gather_facts: no + tasks: + - name: Install Toolkit development kit package + shell: script -q -c 'yum install -y "{{ cann_packages.toolkit }}"' /dev/null + register: toolkit_install_result + + - name: Display Toolkit installation result + debug: + msg: + - "========================================" + - "CANN Toolkit 开发套件包安装操作完成" + - "包名: {{ cann_packages.toolkit }}" + - "状态: {{ 'Success' if toolkit_install_result.rc == 0 else 'Failed' }}" + - "========================================" + + - name: Check if Toolkit environment variable script exists + stat: + path: "{{ env_scripts.toolkit }}" + register: toolkit_env_script + + - name: Display Toolkit installation error message + debug: + msg: + - "========================================" + - "错误: Toolkit安装可能有问题" + - "找不到环境变量脚本: {{ env_scripts.toolkit }}" + - "请检查安装包是否正确安装" + - "========================================" + when: not toolkit_env_script.stat.exists + + - name: Fail if Toolkit environment variable script not found + fail: + msg: "Toolkit环境变量脚本不存在,安装失败" + when: not toolkit_env_script.stat.exists + + - name: Check if Toolkit environment variables are configured + shell: grep -q "{{ env_scripts.toolkit }}" /root/.bashrc + register: toolkit_env_check + failed_when: false + changed_when: false + become: no + when: toolkit_env_script.stat.exists and not skip_env_config + + - name: Configure Toolkit environment variables to .bashrc + lineinfile: + path: /root/.bashrc + line: "source {{ env_scripts.toolkit }}" + create: yes + backup: yes + when: toolkit_env_script.stat.exists and toolkit_env_check.rc != 0 and not skip_env_config + become: no + register: toolkit_env_configured + + - name: Display environment variable configuration reminder + debug: + msg: "{{ env_reminder_message }}" + when: toolkit_env_configured.changed diff --git a/plugins/cann-toolkit/workspace/prepare.yaml b/plugins/cann-toolkit/workspace/prepare.yaml new file mode 100644 index 0000000000000000000000000000000000000000..1b44afc7a96d7c1772bd52a489afb2b9b3d853f4 --- /dev/null +++ b/plugins/cann-toolkit/workspace/prepare.yaml @@ -0,0 +1,106 @@ +--- +- hosts: all + become: yes + gather_facts: yes + tasks: + - name: Check if running as root or with sudo privileges + fail: + msg: "此插件需要root用户或具有sudo权限的用户执行" + when: ansible_user_id != "root" and ansible_become is not defined + + - name: Install system dependency packages + yum: + name: "{{ system_packages }}" + state: present + register: system_packages_result + + - name: Display system dependency packages installation result + debug: + msg: + - "========================================" + - "系统依赖包安装完成" + - "已安装: {{ system_packages | join(', ') }}" + - "========================================" + when: system_packages_result.changed + + - name: Get C++ header file path + shell: | + find /usr/include/c++ -maxdepth 1 -type d -name "[0-9]*" | head -1 + register: cpp_version_path + changed_when: false + + - name: Set C++ version variables + set_fact: + cpp_version: "{{ cpp_version_path.stdout | basename }}" + cpp_base_path: "{{ cpp_version_path.stdout }}" + when: cpp_version_path.stdout != "" + + - name: Check if C++ environment variables are configured + shell: grep -q "CPLUS_INCLUDE_PATH.*{{ cpp_version }}" /root/.bashrc + register: cpp_env_check + failed_when: false + changed_when: false + become: no + + - name: Configure C++ related environment variables to .bashrc + lineinfile: + path: /root/.bashrc + line: "export CPLUS_INCLUDE_PATH={{ cpp_base_path }}:{{ cpp_base_path }}/backward:{{ cpp_base_path }}/x86_64-openEuler-linux/:$CPLUS_INCLUDE_PATH" + create: yes + backup: yes + when: cpp_env_check.rc != 0 and cpp_version is defined + become: no + + - name: Install Python third-party libraries + pip: + name: "{{ python_packages }}" + extra_args: "--trusted-host {{ pip_config.trusted_host }} -i {{ pip_config.index_url }}" + state: present + register: pip_install_result + + - name: Display Python packages installation result + debug: + msg: + - "========================================" + - "Python第三方库安装完成" + - "已安装: {{ python_packages | join(', ') }}" + - "========================================" + when: pip_install_result.changed + + - name: Check if Ascend software repository exists + stat: + path: "{{ ascend_repo.path }}" + register: ascend_repo_stat + + - name: Configure Ascend software repository + get_url: + url: "{{ ascend_repo.url }}" + dest: "{{ ascend_repo.path }}" + mode: '0644' + when: not ascend_repo_stat.stat.exists + register: repo_config_result + + - name: Update yum cache + yum: + update_cache: yes + when: repo_config_result.changed + + - name: Display Ascend software repository configuration result + debug: + msg: + - "========================================" + - "昇腾软件源配置完成" + - "源文件路径: {{ ascend_repo.path }}" + - "========================================" + when: repo_config_result.changed + + - name: Display environment preparation completion message + debug: + msg: + - "========================================" + - "环境准备已完成" + - "已安装系统依赖包、Python第三方库" + - "已配置C++环境变量和昇腾软件源" + - "如果配置了新的环境变量,请执行:" + - "source /root/.bashrc" + - "========================================" diff --git a/plugins/cann-toolkit/workspace/run-samples.yaml b/plugins/cann-toolkit/workspace/run-samples.yaml new file mode 100644 index 0000000000000000000000000000000000000000..4933ed10783aeedcb0f2760aab2242bdeb58a8eb --- /dev/null +++ b/plugins/cann-toolkit/workspace/run-samples.yaml @@ -0,0 +1,131 @@ +--- +- hosts: all + become: no + gather_facts: no + tasks: + - name: Check if sample code directory already exists + stat: + path: "{{ samples_config.clone_path }}" + register: samples_dir_stat + + - name: Display sample code already exists information + debug: + msg: + - "========================================" + - "用例代码目录已存在" + - "路径: {{ samples_config.clone_path }}" + - "将跳过克隆步骤" + - "========================================" + when: samples_dir_stat.stat.exists + + - name: Clone sample code repository + git: + repo: "{{ samples_config.repo_url }}" + dest: "{{ samples_config.clone_path }}" + version: "{{ samples_config.branch }}" + force: yes + register: git_clone_result + when: not samples_dir_stat.stat.exists + + - name: Display clone result + debug: + msg: + - "========================================" + - "用例代码克隆完成" + - "仓库: {{ samples_config.repo_url }}" + - "分支: {{ samples_config.branch }}" + - "路径: {{ samples_config.clone_path }}" + - "========================================" + when: git_clone_result.changed + + - name: Update existing sample code repository + git: + repo: "{{ samples_config.repo_url }}" + dest: "{{ samples_config.clone_path }}" + version: "{{ samples_config.branch }}" + force: yes + register: git_update_result + when: samples_dir_stat.stat.exists + + - name: Display update result + debug: + msg: + - "========================================" + - "用例代码更新完成" + - "分支: {{ samples_config.branch }}" + - "========================================" + when: git_update_result.changed + + - name: Check if environment variables are configured + shell: | + source /root/.bashrc + if [ -z "$ASCEND_TOOLKIT_HOME" ]; then + echo "ASCEND_TOOLKIT_HOME not set" + exit 1 + fi + echo "Environment configured" + register: env_check + failed_when: false + changed_when: false + + - name: Display environment variable check result + debug: + msg: + - "========================================" + - "环境变量检查结果:" + - "{{ env_check.stdout }}" + - "如果环境变量未配置,请先执行安装操作" + - "========================================" + when: env_check.rc != 0 + + - name: Execute sample code + shell: | + cd {{ item.path }} + source /root/.bashrc + {{ item.command }} + register: sample_result + failed_when: false + loop: "{{ samples_config.test_cases }}" + when: env_check.rc == 0 + + - name: Display sample execution result + debug: + msg: + - "========================================" + - "用例执行结果 - {{ item.item.path }}" + - "命令: {{ item.item.command }}" + - "返回码: {{ item.rc }}" + - "输出:" + - "{{ item.stdout }}" + - "错误信息:" + - "{{ item.stderr }}" + - "========================================" + loop: "{{ sample_result.results }}" + when: sample_result.results is defined + + - name: Calculate sample execution statistics + set_fact: + success_count: "{{ sample_result.results | selectattr('rc', 'equalto', 0) | list | length }}" + total_count: "{{ sample_result.results | length }}" + when: sample_result.results is defined + + - name: Display sample execution summary + debug: + msg: + - "========================================" + - "用例执行总结" + - "成功: {{ success_count | default(0) }}/{{ total_count | default(0) }}" + - "失败: {{ (total_count | default(0) | int) - (success_count | default(0) | int) }}" + - "========================================" + when: sample_result.results is defined + + - name: Display sample path information + debug: + msg: + - "========================================" + - "用例代码路径信息" + - "主目录: {{ samples_config.clone_path }}" + - "用例列表:" + - "{% for case in samples_config.test_cases %} - {{ case.path }}{% endfor %}" + - "您可以手动进入这些目录执行用例" + - "========================================" diff --git a/plugins/cann-toolkit/workspace/uninstall-kernels.yaml b/plugins/cann-toolkit/workspace/uninstall-kernels.yaml new file mode 100644 index 0000000000000000000000000000000000000000..96244964ff4ef575a889795bd7e4dd44961bea6f --- /dev/null +++ b/plugins/cann-toolkit/workspace/uninstall-kernels.yaml @@ -0,0 +1,29 @@ +--- +- hosts: all + become: yes + gather_facts: no + tasks: + - name: Set Kernels package name variable + set_fact: + kernels_package_name: "{{ kernels_packages[hardware_model] }}" + + - name: Validate hardware model configuration + fail: + msg: "不支持的硬件型号: {{ hardware_model }}. 支持的型号: {{ kernels_packages.keys() | list | join(', ') }}" + when: hardware_model not in kernels_packages + + - name: Uninstall Kernels operator package + shell: script -q -c 'yum remove -y "{{ kernels_package_name }}"' /dev/null + register: kernels_uninstall_result + failed_when: false + + - name: Display Kernels uninstallation result + debug: + msg: + - "========================================" + - "CANN Kernels 算子包卸载操作完成" + - "硬件型号: {{ hardware_model }}" + - "包名: {{ kernels_package_name }}" + - "状态: {{ 'Success' if kernels_uninstall_result.rc == 0 else 'Failed' }}" + - "========================================" + diff --git a/plugins/cann-toolkit/workspace/uninstall-nnae.yaml b/plugins/cann-toolkit/workspace/uninstall-nnae.yaml new file mode 100644 index 0000000000000000000000000000000000000000..2feeaea49bd302dfdc8ad3ce3996067d05ba8a6f --- /dev/null +++ b/plugins/cann-toolkit/workspace/uninstall-nnae.yaml @@ -0,0 +1,46 @@ +--- +- hosts: all + become: yes + gather_facts: no + tasks: + - name: Uninstall NNAE neural network acceleration engine + shell: script -q -c 'yum remove -y "{{ cann_packages.nnae }}"' /dev/null + register: nnae_uninstall_result + failed_when: false + + - name: Display NNAE uninstallation result + debug: + msg: + - "========================================" + - "CANN NNAE 神经网络加速引擎卸载操作完成" + - "包名: {{ cann_packages.nnae }}" + - "状态: {{ 'Success' if nnae_uninstall_result.rc == 0 else 'Failed' }}" + - "========================================" + + - name: Check if NNAE environment variables are configured + shell: grep -q "{{ env_scripts.nnae }}" /root/.bashrc + register: nnae_env_check + failed_when: false + changed_when: false + become: no + + - name: Remove NNAE environment variable configuration + lineinfile: + path: /root/.bashrc + regexp: ".*{{ env_scripts.nnae }}.*" + state: absent + backup: yes + when: nnae_env_check.rc == 0 + become: no + register: nnae_env_removed + + - name: Display environment variable removal reminder + debug: + msg: + - "========================================" + - "NNAE环境变量配置已从.bashrc中移除" + - "请执行以下命令使更改生效:" + - "source /root/.bashrc" + - "========================================" + when: nnae_env_removed.changed + diff --git a/plugins/cann-toolkit/workspace/uninstall-nnal.yaml b/plugins/cann-toolkit/workspace/uninstall-nnal.yaml new file mode 100644 index 0000000000000000000000000000000000000000..ac22d315a3108f1a54079190e24918921d250243 --- /dev/null +++ b/plugins/cann-toolkit/workspace/uninstall-nnal.yaml @@ -0,0 +1,64 @@ +--- +- hosts: all + become: yes + gather_facts: no + tasks: + - name: Uninstall NNAL neural network acceleration library + shell: script -q -c 'yum remove -y "{{ cann_packages.nnal }}"' /dev/null + register: nnal_uninstall_result + failed_when: false + + - name: Display NNAL uninstallation result + debug: + msg: + - "========================================" + - "CANN NNAL 神经网络加速库卸载操作完成" + - "包名: {{ cann_packages.nnal }}" + - "状态: {{ 'Success' if nnal_uninstall_result.rc == 0 else 'Failed' }}" + - "========================================" + + - name: Check if NNAL ATB environment variables are configured + shell: grep -q "{{ env_scripts.nnal_atb }}" /root/.bashrc + register: nnal_atb_env_check + failed_when: false + changed_when: false + become: no + + - name: Check if NNAL SiP environment variables are configured + shell: grep -q "{{ env_scripts.nnal_sip }}" /root/.bashrc + register: nnal_sip_env_check + failed_when: false + changed_when: false + become: no + + - name: Remove NNAL ATB environment variable configuration + lineinfile: + path: /root/.bashrc + regexp: ".*{{ env_scripts.nnal_atb }}.*" + state: absent + backup: yes + when: nnal_atb_env_check.rc == 0 + become: no + register: nnal_atb_env_removed + + - name: Remove NNAL SiP environment variable configuration + lineinfile: + path: /root/.bashrc + regexp: ".*{{ env_scripts.nnal_sip }}.*" + state: absent + backup: yes + when: nnal_sip_env_check.rc == 0 + become: no + register: nnal_sip_env_removed + + - name: Display environment variable removal reminder + debug: + msg: + - "========================================" + - "NNAL环境变量配置已从.bashrc中移除" + - "已移除ATB和SiP相关配置" + - "请执行以下命令使更改生效:" + - "source /root/.bashrc" + - "========================================" + when: nnal_atb_env_removed.changed or nnal_sip_env_removed.changed + diff --git a/plugins/cann-toolkit/workspace/uninstall-nnrt.yaml b/plugins/cann-toolkit/workspace/uninstall-nnrt.yaml new file mode 100644 index 0000000000000000000000000000000000000000..1a9ea81191c3b3912b5d9542ea4be3216087c76e --- /dev/null +++ b/plugins/cann-toolkit/workspace/uninstall-nnrt.yaml @@ -0,0 +1,46 @@ +--- +- hosts: all + become: yes + gather_facts: no + tasks: + - name: Uninstall NNRT neural network runtime environment + shell: script -q -c 'yum remove -y "{{ cann_packages.nnrt }}"' /dev/null + register: nnrt_uninstall_result + failed_when: false + + - name: Display NNRT uninstallation result + debug: + msg: + - "========================================" + - "CANN NNRT 神经网络运行时环境卸载操作完成" + - "包名: {{ cann_packages.nnrt }}" + - "状态: {{ 'Success' if nnrt_uninstall_result.rc == 0 else 'Failed' }}" + - "========================================" + + - name: Check if NNRT environment variables are configured + shell: grep -q "{{ env_scripts.nnrt }}" /root/.bashrc + register: nnrt_env_check + failed_when: false + changed_when: false + become: no + + - name: Remove NNRT environment variable configuration + lineinfile: + path: /root/.bashrc + regexp: ".*{{ env_scripts.nnrt }}.*" + state: absent + backup: yes + when: nnrt_env_check.rc == 0 + become: no + register: nnrt_env_removed + + - name: Display environment variable removal reminder + debug: + msg: + - "========================================" + - "NNRT环境变量配置已从.bashrc中移除" + - "请执行以下命令使更改生效:" + - "source /root/.bashrc" + - "========================================" + when: nnrt_env_removed.changed + diff --git a/plugins/cann-toolkit/workspace/uninstall-toolkit.yaml b/plugins/cann-toolkit/workspace/uninstall-toolkit.yaml new file mode 100644 index 0000000000000000000000000000000000000000..a3eae7d7bc63cca717bcd9e79e3bdb4bbfafd481 --- /dev/null +++ b/plugins/cann-toolkit/workspace/uninstall-toolkit.yaml @@ -0,0 +1,46 @@ +--- +- hosts: all + become: yes + gather_facts: no + tasks: + - name: Uninstall Toolkit development kit package + shell: script -q -c 'yum remove -y "{{ cann_packages.toolkit }}"' /dev/null + register: toolkit_uninstall_result + failed_when: false + + - name: Display Toolkit uninstallation result + debug: + msg: + - "========================================" + - "CANN Toolkit 开发套件包卸载操作完成" + - "包名: {{ cann_packages.toolkit }}" + - "状态: {{ 'Success' if toolkit_uninstall_result.rc == 0 else 'Failed' }}" + - "========================================" + + - name: Check if Toolkit environment variables are configured + shell: grep -q "{{ env_scripts.toolkit }}" /root/.bashrc + register: toolkit_env_check + failed_when: false + changed_when: false + become: no + + - name: Remove Toolkit environment variable configuration + lineinfile: + path: /root/.bashrc + regexp: ".*{{ env_scripts.toolkit }}.*" + state: absent + backup: yes + when: toolkit_env_check.rc == 0 + become: no + register: toolkit_env_removed + + - name: Display environment variable removal reminder + debug: + msg: + - "========================================" + - "Toolkit环境变量配置已从.bashrc中移除" + - "请执行以下命令使更改生效:" + - "source /root/.bashrc" + - "========================================" + when: toolkit_env_removed.changed + diff --git a/plugins/cann-toolkit/workspace/variables.yaml b/plugins/cann-toolkit/workspace/variables.yaml new file mode 100644 index 0000000000000000000000000000000000000000..e66607f4891c357db78234e1787ddb94b32bd14f --- /dev/null +++ b/plugins/cann-toolkit/workspace/variables.yaml @@ -0,0 +1,83 @@ +# CANN工具链固定配置信息 +# 这些配置相对固定,通常不需要用户调整 + +# Python第三方库列表 +python_packages: + - attrs + - cython + - 'numpy>=1.19.2,<=1.24.0' + - decorator + - sympy + - cffi + - pyyaml + - pathlib2 + - psutil + - protobuf==3.20.0 + - scipy + - requests + - absl-py + +# Python包安装配置 +pip_config: + trusted_host: mirrors.huaweicloud.com + index_url: https://mirrors.huaweicloud.com/repository/pypi/simple + +# 昇腾软件源配置 +ascend_repo: + url: https://repo.oepkgs.net/ascend/cann/ascend.repo + path: /etc/yum.repos.d/ascend.repo + +# 硬件型号与Kernels算子包的映射关系 +kernels_packages: + "310b": "Ascend-cann-kernels-310b" + "310p": "Ascend-cann-kernels-310p" + "910": "Ascend-cann-kernels-910" + "910b": "Ascend-cann-kernels-910b" + "Atlas-A3": "Atlas-A3-cann-kernels" + +# CANN组件包名称 +cann_packages: + toolkit: "Ascend-cann-toolkit" + nnae: "Ascend-cann-nnae" + nnal: "Ascend-cann-nnal" + nnrt: "Ascend-cann-nnrt" + +# 环境变量脚本路径 +env_scripts: + toolkit: "/usr/local/Ascend/ascend-toolkit/set_env.sh" + nnae: "/usr/local/Ascend/nnae/set_env.sh" + nnal_atb: "/usr/local/Ascend/nnal/atb/set_env.sh" + nnal_sip: "/usr/local/Ascend/nnal/asdsip/set_env.sh" + nnrt: "/usr/local/Ascend/nnrt/set_env.sh" + +# 用例代码配置 +samples_config: + repo_url: "https://gitee.com/ascend/samples.git" + branch: "v1.5-8.2.RC1" + clone_path: "/root/samples" + test_cases: + - path: "/root/samples/operator/ascendc/0_introduction/3_add_kernellaunch/AddKernelInvocationNeo" + command: "sudo bash run.sh -r cpu" + - path: "/root/samples/operator/ascendc/0_introduction/3_add_kernellaunch/AddKernelInvocationTilingNeo" + command: "sudo bash run.sh -r cpu" + - path: "/root/samples/operator/ascendc/0_introduction/5_addn_kernellaunch" + command: "sudo bash run.sh -r cpu" + - path: "/root/samples/operator/ascendc/0_introduction/13_matmulleakyrelu_kernellaunch/MatmulLeakyReluInvocation" + command: "sudo bash run.sh -r cpu" + - path: "/root/samples/operator/ascendc/0_introduction/11_matmul_kernellaunch/MatmulInvocationNeo" + command: "sudo bash run.sh -r cpu" + +# 系统依赖包 +system_packages: + - gcc-c++ + - libstdc++-devel + - python3-libselinux + +# 环境变量提示信息 +env_reminder_message: + - "========================================" + - "环境变量配置已完成" + - "请执行以下命令使环境变量生效:" + - "source /root/.bashrc" + - "或者重新登录bash会话" + - "========================================"