CANN Development Environment Configuration
This skill provides comprehensive guidance for installing CANN (Computing Architecture for Neural Networks) on the Ascend NPU platform.
Trigger Scenarios
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
Step 1: Check if the Driver is Installed
Hardware Requirements
- Ascend NPU device has been installed
- Device status is normal
Driver Check Command
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
Step 2: Check CANN Installation Dependencies
Check whether CANN installation dependencies (Python and pip) are installed:
bash
# 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
# 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
If any dependency is missing, a prompt message will be displayed. Please refer to the Environment Dependence Installation Guide for installation.
Step 3: Install CANN
Method 1: Offline Installation
Step 3.1: Check if the installation package exists in the current folder
bash
# 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 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
# 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 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
# Install Toolkit (default path /usr/local/Ascend)
bash "$TOOLKIT_PACKAGE" --install --quiet
# Install ops
bash "$OPS_PACKAGE" --install --quiet
Method 2: Online Installation (conda Method)
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
# Create Python environment (CANN supports Python 3.7.x - 3.13.11)
conda create -n cann_env python
# Activate the environment
conda activate cann_env
Step 3.2: Configure the official Ascend conda source
bash
# Add Ascend conda source
conda config --add channels https://repo.huaweicloud.com/ascend/repos/conda
Step 3.3: Install CANN packages
bash
# Install CANN toolkit using conda
conda install ascend::cann-toolkit
# Install CANN ops package (select according to chip type, such as 910, 910b, 310, etc.)
conda install ascend::cann-{chip-type}-ops
Method 3: Online Installation (yum Method - CentOS/RHEL)
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
Step 4: Environment Variable Configuration
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
Step 5: Installation Verification
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
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
Notes
- Version Compatibility: Ensure the CANN version matches the driver version
- Installation Order: Must install Toolkit first, then ops
- Environment Variables: Must set environment variables after installation
- Permission Issues: Some operations may require root permissions
- Dependency Packages: Ensure all necessary dependency packages are installed
Troubleshooting
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
For detailed reference materials, please check the reference directory, which includes:
- Environment Dependence Installation Guide: Required software installation commands and verification methods