配置启智Ascend环境
【摘要】 昇腾算子开发和应用开发环境配置
AscendC算子开发环境
vim install_cmake_cann.sh
chmod +x install_cmake_cann.sh
#!/bin/bash
# 检查是否是root用户
if [[ $EUID -ne 0 ]]; then
echo "这个脚本必须用root用户运行"
exit 1
fi
# 切换到用户目录
cd /home/ma-user
# 安装cmake
echo "开始安装cmake..."
wget https://cmake.org/files/v3.20/cmake-3.20.0-rc5-linux-aarch64.tar.gz
tar -xzvf cmake-3.20.0-rc5-linux-aarch64.tar.gz
echo 'export PATH=/home/ma-user/cmake-3.20.0-rc5-linux-aarch64/bin:$PATH' >> ~/.bashrc
source ~/.bashrc
echo "cmake安装成功!"
echo "---------------------------------------------------------------"
# 安装CANN包
echo "开始安装CANN包..."
# 检查/usr/local/Ascend/ascend-toolkit目录是否存在
if [ -d "/usr/local/Ascend/ascend-toolkit" ]; then
echo "警告:发现已存在的CANN包安装在/usr/local/Ascend/ascend-toolkit目录下。"
echo "是否继续安装并覆盖旧版本?(y/n)"
read continue
if [ "$continue" != "y" ] && [ "$continue" != "Y" ]; then
echo "取消安装。"
exit 1
fi
# 如果用户选择继续,则删除旧版本的ascend-toolkit目录(注意:这里不包括driver目录)
echo "正在删除旧版本的CANN包..."
rm -rf /usr/local/Ascend/ascend-toolkit
echo "删除完成。"
fi
# 下载CANN包
wget https://ascend-repo.obs.cn-east-2.myhuaweicloud.com/Milan-ASL/Milan-ASL%20V100R001C17SPC702/Ascend-cann-toolkit_8.0.RC1.alpha002_linux-aarch64.run
chmod +x Ascend-cann-toolkit_8.0.RC1.alpha002_linux-aarch64.run
./Ascend-cann-toolkit_8.0.RC1.alpha002_linux-aarch64.run --full --quiet
echo 'source /usr/local/Ascend/ascend-toolkit/set_env.sh' >> ~/.bashrc
source ~/.bashrc
echo "CANN包安装成功!"
echo "---------------------------------------------------------------"
# 下载samples
echo "开始下载samples..."
cd /home/ma-user
git clone https://gitee.com/ascend/samples.git
echo "samples下载完成!"
echo "---------------------------------------------------------------"
echo "开始执行AddCustomSample算子"
cd /home/ma-user/samples/operator/AddCustomSample/KernelLaunch/AddKernelInvocation
source ~/.bashrc
bash run.sh -r npu -v Ascend910A
source ~/.bashrc
# 脚本结束
exit 0
AscendCL应用开发环境
# 克隆仓库
git clone https://gitee.com/ascend/samples.git
### 安装准备
# 以安装用户在任意目录下执行以下命令,打开.bashrc文件。
vi ~/.bashrc
# 在文件最后一行后面添加如下内容。
export CPU_ARCH=`arch`
export HOME=/usr/local
export THIRDPART_PATH=${HOME}/Ascend/thirdpart/${CPU_ARCH} #代码编译时链接samples所依赖的相关库文件
export LD_LIBRARY_PATH=${THIRDPART_PATH}/lib:$LD_LIBRARY_PATH #运行时链接库文件
export INSTALL_DIR=${HOME}/Ascend/ascend-toolkit/latest #CANN软件安装后的文件存储路径,根据安装目录自行修改
# 执行命令保存文件并退出。
:wq!
# 执行命令使其立即生效。
source ~/.bashrc
# 创建第samples相关依赖文件夹
mkdir -p ${THIRDPART_PATH}
# 拷贝公共文件到samples相关依赖路径中
cp -r /home/ma-user/samples/common ${THIRDPART_PATH}
# 安装cmake
pip install cmake
### 安装ffmpeg及x246插件
# 下载x264
cd /home/ma-user
git clone https://code.videolan.org/videolan/x264.git
cd x264
# 安装x264
./configure --enable-shared --disable-asm
make
sudo make install
sudo cp /usr/local/lib/libx264.so.164 /lib
# 下载ffmpeg
cd /home/ma-user
wget http://www.ffmpeg.org/releases/ffmpeg-4.1.3.tar.gz --no-check-certificate
tar -zxvf ffmpeg-4.1.3.tar.gz
cd ffmpeg-4.1.3
# 安装ffmpeg
./configure --enable-shared --enable-pic --enable-static --disable-x86asm --enable-libx264 --enable-gpl --prefix=${THIRDPART_PATH}
make -j8
make install
#### 安装acllite库
# 编译并安装acllite
cd /home/ma-user/samples/cplusplus/common/acllite/
make
make install
#### 安装presentagent
# 安装protobuf相关依赖
sudo yum install autoconf automake libtool -y
# 下载protobuf源码
cd /home/ma-user
git clone -b 3.13.x https://gitee.com/mirrors/protobufsource.git protobuf
# 编译安装protobuf
cd protobuf
./autogen.sh
./configure --prefix=${THIRDPART_PATH}
make clean
make -j8
sudo make install
# 进入presentagent源码目录并编译
cd /home/ma-user/samples/cplusplus/common/presenteragent/proto
${THIRDPART_PATH}/bin/protoc presenter_message.proto --cpp_out=./
# 开始编译presentagnet
cd ..
make -j8
make install
# opencv安装
# 下载安装包
wget https://cc-showmessage-1307535036.cos.ap-nanjing.myqcloud.com/model/opencv-4.8.0.zip
unzip opencv-4.8.0.zip
# 创建安装目录
mkdir -p build && cd build
# 安装
cmake -DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX=/usr/local \
-DPYTHON_INCLUDE_DIR=$(python3 -c "from distutils.sysconfig import get_python_inc; print(get_python_inc())") \
-DPYTHON_LIBRARY=$(python3 -c "import distutils.sysconfig as sysconfig; print(sysconfig.get_config_var('LIBDIR'))") \
../opencv-4.8.0/
make -j8
make install
#修改在/src 下的CMakeLists.txt文件,增加库文件路径,修改部分如下所示
# Header path
include_directories(
$ENV{INSTALL_DIR}/runtime/include/
../inc/
/usr/local/include/opencv4
)
【版权声明】本文为华为云社区用户原创内容,转载时必须标注文章的来源(华为云社区)、文章链接、文章作者等基本信息, 否则作者和本社区有权追究责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)