cann-operator-env-config

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

CANN开发环境配置

CANN Development Environment Configuration

此技能为在昇腾NPU平台上安装CANN(神经网络计算架构)提供全面指导。
This skill provides comprehensive guidance for installing CANN (Computing Architecture for Neural Networks) on the Ascend NPU platform.

调用时机

Trigger Scenarios

在以下情况下调用此技能:
  • 用户询问CANN安装
  • 用户需要帮助设置昇腾开发环境
  • 用户遇到CANN安装问题
  • 用户想了解CANN安装方法
Call this skill in the following situations:
  • Users inquire about CANN installation
  • Users need help setting up the Ascend development environment
  • Users encounter CANN installation issues
  • Users want to learn about CANN installation methods

安装步骤

Installation Steps

第1步:检查驱动是否安装

Step 1: Check if the Driver is Installed

硬件要求
  • 已安装昇腾NPU设备
  • 设备状态正常
驱动检查命令
bash
npu-smi info
检查结果
  • 如果显示NPU设备信息,说明驱动已安装
  • 记录驱动版本用于后续CANN版本兼容性检查
  • 如果提示"command not found",需要先安装昇腾驱动
Hardware Requirements
  • Ascend NPU device has been installed
  • Device status is normal
Driver Check Command
bash
npu-smi info
Check Results
  • If NPU device information is displayed, the driver is already installed
  • Record the driver version for subsequent CANN version compatibility check
  • If "command not found" is prompted, you need to install the Ascend driver first

第2步:检查CANN安装依赖

Step 2: Check CANN Installation Dependencies

检查CANN安装依赖(Python和pip)是否已安装:
bash
undefined
Check whether CANN installation dependencies (Python and pip) are installed:
bash
undefined

检查Python

Check Python

if ! command -v python3 &> /dev/null && ! command -v python &> /dev/null; then echo "Python not found, please install from env_dependence.md" fi
if ! command -v python3 &> /dev/null && ! command -v python &> /dev/null; then echo "Python not found, please install from env_dependence.md" fi

检查pip

Check pip

if ! command -v pip3 &> /dev/null && ! command -v pip &> /dev/null; then echo "pip not found, please install from env_dependence.md" fi

如果任何依赖缺少,会显示提示信息,请参考 [环境依赖安装指南](./reference/env_dependence.md) 进行安装。
if ! command -v pip3 &> /dev/null && ! command -v pip &> /dev/null; then echo "pip not found, please install from env_dependence.md" fi

If any dependency is missing, a prompt message will be displayed. Please refer to the [Environment Dependence Installation Guide](./reference/env_dependence.md) for installation.

第3步:安装CANN

Step 3: Install CANN

方法一:离线安装

Method 1: Offline Installation

步骤3.1:检查当前文件夹是否存在安装包
bash
undefined
Step 3.1: Check if the installation package exists in the current folder
bash
undefined

检查当前文件夹是否存在CANN安装包

Check if CANN Toolkit installation package exists in the current folder

if ls Ascend-cann-toolkit_.run 2>/dev/null | grep -q .; then echo "找到CANN Toolkit安装包" TOOLKIT_PACKAGE=$(ls Ascend-cann-toolkit_.run) else echo "未找到CANN Toolkit安装包,请使用在线安装方式" # 退出离线安装,建议使用在线安装 exit 1 fi
if ls Ascend-cann-toolkit_.run 2>/dev/null | grep -q .; then echo "CANN Toolkit installation package found" TOOLKIT_PACKAGE=$(ls Ascend-cann-toolkit_.run) else echo "CANN Toolkit installation package not found, please use online installation method" # Exit offline installation, recommend using online installation exit 1 fi

检查当前文件夹是否存在ops安装包

Check if CANN ops installation package exists in the current folder

if ls Ascend-cann--ops_.run 2>/dev/null | grep -q .; then echo "找到CANN ops安装包" OPS_PACKAGE=$(ls Ascend-cann--ops_.run) else echo "未找到CANN ops安装包,请使用在线安装方式" # 退出离线安装,建议使用在线安装 exit 1 fi

**步骤3.2:安装CANN**

**重要:必须先安装Toolkit,再安装ops**

**run格式安装:**
```bash
if ls Ascend-cann--ops_.run 2>/dev/null | grep -q .; then echo "CANN ops installation package found" OPS_PACKAGE=$(ls Ascend-cann--ops_.run) else echo "CANN ops installation package not found, please use online installation method" # Exit offline installation, recommend using online installation exit 1 fi

**Step 3.2: Install CANN**

**Important: Install Toolkit first, then ops**

**Run format installation:**
```bash

安装 Toolkit (默认路径 /usr/local/Ascend)

Install Toolkit (default path /usr/local/Ascend)

bash "$TOOLKIT_PACKAGE" --install --quiet
bash "$TOOLKIT_PACKAGE" --install --quiet

安装 ops

Install ops

bash "$OPS_PACKAGE" --install --quiet
undefined
bash "$OPS_PACKAGE" --install --quiet
undefined

方法二:在线安装(conda方式)

Method 2: Online Installation (conda Method)

注意:conda主要用于创建Python虚拟环境,CANN工具包仍需通过离线安装包安装。
步骤3.1:创建conda虚拟环境
bash
undefined
Note: conda is mainly used to create Python virtual environments, and the CANN toolkit still needs to be installed via offline installation packages.
Step 3.1: Create a conda virtual environment
bash
undefined

创建Python环境(CANN支持Python 3.7.x - 3.13.11)

Create Python environment (CANN supports Python 3.7.x - 3.13.11)

conda create -n cann_env python
conda create -n cann_env python

激活环境

Activate the environment

conda activate cann_env

**步骤3.2:配置昇腾conda官方源**
```bash
conda activate cann_env

**Step 3.2: Configure the official Ascend conda source**
```bash

添加昇腾conda源

Add Ascend conda source


**步骤3.3:安装CANN包**
```bash

**Step 3.3: Install CANN packages**
```bash

使用conda安装CANN工具包

Install CANN toolkit using conda

conda install ascend::cann-toolkit
conda install ascend::cann-toolkit

安装CANN ops包(根据芯片类型选择,如910、910b、310等)

Install CANN ops package (select according to chip type, such as 910, 910b, 310, etc.)

conda install ascend::cann-{芯片类型}-ops
undefined
conda install ascend::cann-{chip-type}-ops
undefined

方法三:在线安装(yum方式 - CentOS/RHEL)

Method 3: Online Installation (yum Method - CentOS/RHEL)

步骤3.1:配置华为官方源
bash
sudo curl https://repo.oepkgs.net/ascend/cann/ascend.repo -o /etc/yum.repos.d/ascend.repo && yum makecache
步骤3.2:安装CANN包
bash
yum install -y Ascend-cann-toolkit
yum install -y Ascend-cann-{芯片类型}-ops
Step 3.1: Configure Huawei official source
bash
sudo curl https://repo.oepkgs.net/ascend/cann/ascend.repo -o /etc/yum.repos.d/ascend.repo && yum makecache
Step 3.2: Install CANN packages
bash
yum install -y Ascend-cann-toolkit
yum install -y Ascend-cann-{chip-type}-ops

第4步:环境变量配置

Step 4: Environment Variable Configuration

临时设置(仅当前终端生效)
bash
source /usr/local/Ascend/ascend-toolkit/set_env.sh
永久设置(写入Shell配置文件)
bash
echo "source /usr/local/Ascend/ascend-toolkit/set_env.sh" >> ~/.bashrc
Temporary Setting (only valid for the current terminal)
bash
source /usr/local/Ascend/ascend-toolkit/set_env.sh
Permanent Setting (write to Shell configuration file)
bash
echo "source /usr/local/Ascend/ascend-toolkit/set_env.sh" >> ~/.bashrc

第5步:安装验证

Step 5: Installation Verification

使用Python验证ACL接口
bash
python3 -c "import acl;acl.init();acl.rt.set_device(0)"
验证结果
  • 如果执行成功,说明CANN Python接口正常工作
  • 如果执行失败,检查环境变量是否配置正确
Verify ACL interface using Python
bash
python3 -c "import acl;acl.init();acl.rt.set_device(0)"
Verification Results
  • If executed successfully, the CANN Python interface is working properly
  • If execution fails, check whether the environment variables are configured correctly

第6步:安装运行时依赖

Step 6: Install Runtime Dependencies

bash
pip3 install attrs cython numpy decorator sympy cffi pyyaml pathlib2 psutil protobuf==3.20.0 scipy requests absl-py --user
pip3 install protobuf==3.20.0
bash
pip3 install attrs cython numpy decorator sympy cffi pyyaml pathlib2 psutil protobuf==3.20.0 scipy requests absl-py --user
pip3 install protobuf==3.20.0

注意事项

Notes

  1. 版本兼容性:确保CANN版本与驱动版本匹配
  2. 安装顺序:必须先安装Toolkit,再安装ops
  3. 环境变量:安装后必须设置环境变量
  4. 权限问题:某些操作可能需要root权限
  5. 依赖包:确保所有必要的依赖包已安装
  1. Version Compatibility: Ensure the CANN version matches the driver version
  2. Installation Order: Must install Toolkit first, then ops
  3. Environment Variables: Must set environment variables after installation
  4. Permission Issues: Some operations may require root permissions
  5. Dependency Packages: Ensure all necessary dependency packages are installed

故障排查

Troubleshooting

如果安装过程中遇到问题:
  • 检查驱动版本是否与CANN版本兼容
  • 检查依赖包是否安装完整
  • 查看安装日志获取详细错误信息
  • 参考昇腾社区文档或寻求技术支持
If you encounter issues during installation:
  • Check if the driver version is compatible with the CANN version
  • Check if dependency packages are fully installed
  • Check installation logs for detailed error information
  • Refer to Ascend community documents or seek technical support

参考资料

Reference Materials

详细参考资料请查看 reference 目录,包含:
  • 环境依赖安装指南:必需软件安装命令和验证方法
For detailed reference materials, please check the reference directory, which includes:
  • Environment Dependence Installation Guide: Required software installation commands and verification methods