SuperAPI AI Directory

external-gitcode-ascend-cann-operator-env-config

General & other

View repository

Updated 10-15 17:19

About this skill

CANN Development Environment Configuration

This skill provides comprehensive guidance for installing CANN (Compute Architecture for Neural Networks) on the Ascend NPU platform.

When to Invoke

Invoke this skill in the following situations:

  • The user asks about CANN installation
  • The user needs help setting up an Ascend development environment
  • The user encounters CANN installation issues
  • The user wants to learn about CANN installation methods

Installation Steps

Step 1: Check Whether the Driver Is Installed

Hardware Requirements

  • An Ascend NPU device is installed
  • The device status is normal

Driver Check Command

npu-smi info

Check Result

  • If NPU device information is displayed, the driver is installed
  • Record the driver version for subsequent CANN version compatibility checks
  • If "command not found" is displayed, the Ascend driver needs to be installed first

Step 2: Check CANN Installation Dependencies

Check whether the CANN installation dependencies (Python and pip) are installed:

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

# 检查pip
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 will be displayed; please refer to Environment Dependency Installation Guide to install.

Step 3: Install CANN

Method 1: Offline Installation

Step 3.1: Check Whether the Installation Package Exists in the Current Folder

# 检查当前文件夹是否存在CANN安装包
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

# 检查当前文件夹是否存在ops安装包
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

Step 3.2: Install CANN

Important: You must install the Toolkit first, then install ops

run format installation:

# 安装 Toolkit (默认路径 /usr/local/Ascend)
bash "$TOOLKIT_PACKAGE" --install --quiet
# 安装 ops
bash "$OPS_PACKAGE" --install --quiet

Method 2: Online Installation (conda Method)

Note: conda is mainly used to create Python virtual environments; the CANN toolkit still needs to be installed via the offline installation package.

Step 3.1: Create a conda Virtual Environment

# 创建Python环境(CANN支持Python 3.7.x - 3.13.11)
conda create -n cann_env python
# 激活环境
conda activate cann_env

Step 3.2: Configure the Official Ascend conda Source

# 添加昇腾conda源
conda config --add channels https://repo.huaweicloud.com/ascend/repos/conda

Step 3.3: Install the CANN Package

# 使用conda安装CANN工具包
conda install ascend::cann-toolkit
# 安装CANN ops包(根据芯片类型选择,如910、910b、310等)
conda install ascend::cann-{芯片类型}-ops

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

Step 3.1: Configure the Official Huawei Source

sudo curl https://repo.oepkgs.net/ascend/cann/ascend.repo -o /etc/yum.repos.d/ascend.repo && yum makecache

Step 3.2: Install the CANN Package

yum install -y Ascend-cann-toolkit
yum install -y Ascend-cann-{芯片类型}-ops

Step 4: Environment Variable Configuration

Temporary Setting (Effective Only in the Current Terminal)

source /usr/local/Ascend/ascend-toolkit/set_env.sh

Permanent Setting (Write to the Shell Configuration File)

echo "source /usr/local/Ascend/ascend-toolkit/set_env.sh" >> ~/.bashrc

Step 5: Installation Verification

Use Python to Verify the ACL Interface

python3 -c "import acl;acl.init();acl.rt.set_device(0)"

Verification Result

  • If execution succeeds, the CANN Python interface is working properly
  • If execution fails, check whether the environment variables are configured correctly

Step 6: Install Runtime Dependencies

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

Precautions

  1. Version Compatibility: Ensure that the CANN version matches the driver version
  2. Installation Order: You must install the Toolkit first, then install ops
  3. Environment Variables: Environment variables must be set after installation
  4. Permission Issues: Some operations may require root permissions
  5. Dependency Packages: Ensure that all necessary dependency packages are installed

Troubleshooting

If you encounter problems during installation:

  • Check whether the driver version is compatible with the CANN version
  • Check whether the dependency packages are fully installed
  • Check the installation logs for detailed error information
  • Refer to the Ascend community documentation or seek technical support

Reference Materials

For detailed reference materials, please see reference Table of Contents, including: