注:基于openEuler 22.03 LTS SP1系统(联网环境)。
1 安装conda
参考 鲲鹏Linux环境安装conda参考
2 安装python3和依赖
dnf -y install python3 python3-devel
3 获取wenet源码
wget https://github.com/wenet-e2e/wenet/archive/refs/tags/v2.2.1.tar.gz
mv v2.2.1.tar.gz wenet-2.2.1.tar.gz
tar xf wenet-2.2.1.tar.gz
4 创建conda环境
/root/miniconda3/bin/conda create -n wenet python=3.9
/root/miniconda3/bin/activate wenet
5 进入wenet源码路径并安装依赖
cd wenet-2.2.1/
pip3 install -r requirements.txt
再次执行pip3 install -r requirements.txt可以查看依赖安装路径
6 编译libtorch
1)安装pytorch
/root/miniconda3/bin/conda install pytorch cpuonly -c pytorch
2)进入libtorch路径
cd runtime/libtorch
3)创建build编译路径并进入执行cmake编译
mkdir build
cd build/
cmake ..
4)重命名libtorch-src路径下的lib文件夹(默认获取的libtorch中的so均为x86_64架构,无法在鲲鹏aarch64架构下使用)
cd ../fc_base/libtorch-src
mv lib lib-bak
5)创建新的lib文件夹并将aarch64的so拷贝进去
mkdir lib
cp -r /usr/local/lib64/python3.9/site-packages/torch/lib/* lib/
6)拷贝libtorch_cpu.so依赖的so库文件到lib路径
cp -r /usr/local/lib64/python3.9/site-packages/torch.libs/* lib/
7)拷贝重命名的lib-bak文件夹下的libkineto.a到lib路径下
cp lib-bak/libkineto.a lib/
8)执行cmake编译
cd ../../build/
cmake --build .

编译的二进制在bin/路径下,然后执行make install安装
7 FAQ
1、执行cmake --build .报错“No rule to make target '../fc_base/libtorch-src/lib/libkineto.a', needed by 'api/libwenet_api.so'. Stop.”,具体报错如下
gmake[2]: *** No rule to make target '../fc_base/libtorch-src/lib/libkineto.a', needed by 'api/libwenet_api.so'. Stop.
gmake[2]: Leaving directory '/root/wenet/runtime/libtorch/build'
gmake[1]: *** [CMakeFiles/Makefile2:2317: api/CMakeFiles/wenet_api.dir/all] Error 2
gmake[1]: Leaving directory '/root/wenet/runtime/libtorch/build'
gmake: *** [Makefile:152: all] Error 2
解决方法:
将重命名的lib-bak文件夹下的libkineto.a到lib路径下
cp ../fc_base/libtorch-src/lib-bak/libkineto.a ../fc_base/libtorch-src/lib/
2、执行cmake --build .报错“warning: libgomp-d22c30c5.so.1.0.0, needed by /root/wenet/runtime/libtorch/fc_base/libtorch-src/lib/libtorch_cpu.so, not found”等错误,具体报错如下:
[ 85%] Linking CXX executable label_checker_main
/usr/bin/ld: warning: libgomp-d22c30c5.so.1.0.0, needed by /root/wenet/runtime/libtorch/fc_base/libtorch-src/lib/libtorch_cpu.so, not found (try using -rpath or -rpath-link)
/usr/bin/ld: warning: libarm_compute-873be09e.so, needed by /root/wenet/runtime/libtorch/fc_base/libtorch-src/lib/libtorch_cpu.so, not found (try using -rpath or -rpath-link)
/usr/bin/ld: warning: libarm_compute_graph-ab857ce5.so, needed by /root/wenet/runtime/libtorch/fc_base/libtorch-src/lib/libtorch_cpu.so, not found (try using -rpath or -rpath-link)
/usr/bin/ld: warning: libarm_compute_core-0793f69d.so, needed by /root/wenet/runtime/libtorch/fc_base/libtorch-src/lib/libtorch_cpu.so, not found (try using -rpath or -rpath-link)
解决方法:
拷贝libtorch_cpu.so依赖的so库文件到lib路径
cp -r /usr/local/lib64/python3.9/site-packages/torch.libs/* ../fc_base/libtorch-src/lib/
8 参考
- https://wenet.org.cn/wenet/install.html#install-prebuilt-python-package
- https://pytorch.org/get-started/locally/
注:基于openEuler 22.03 LTS SP1系统(联网环境)。
1 安装conda
参考 鲲鹏Linux环境安装conda参考
2 安装python3和依赖
dnf -y install python3 python3-devel
3 获取wenet源码
wget https://github.com/wenet-e2e/wenet/archive/refs/tags/v2.2.1.tar.gz
mv v2.2.1.tar.gz wenet-2.2.1.tar.gz
tar xf wenet-2.2.1.tar.gz
4 创建conda环境
/root/miniconda3/bin/conda create -n wenet python=3.9
/root/miniconda3/bin/activate wenet
5 进入wenet源码路径并安装依赖
cd wenet-2.2.1/
pip3 install -r requirements.txt
再次执行pip3 install -r requirements.txt可以查看依赖安装路径
6 编译libtorch
1)安装pytorch
/root/miniconda3/bin/conda install pytorch cpuonly -c pytorch
2)进入libtorch路径
cd runtime/libtorch
3)创建build编译路径并进入执行cmake编译
mkdir build
cd build/
cmake ..
4)重命名libtorch-src路径下的lib文件夹(默认获取的libtorch中的so均为x86_64架构,无法在鲲鹏aarch64架构下使用)
cd ../fc_base/libtorch-src
mv lib lib-bak
5)创建新的lib文件夹并将aarch64的so拷贝进去
mkdir lib
cp -r /usr/local/lib64/python3.9/site-packages/torch/lib/* lib/
6)拷贝libtorch_cpu.so依赖的so库文件到lib路径
cp -r /usr/local/lib64/python3.9/site-packages/torch.libs/* lib/
7)拷贝重命名的lib-bak文件夹下的libkineto.a到lib路径下
cp lib-bak/libkineto.a lib/
8)执行cmake编译
cd ../../build/
cmake --build .

编译的二进制在bin/路径下,然后执行make install安装
7 FAQ
1、执行cmake --build .报错“No rule to make target '../fc_base/libtorch-src/lib/libkineto.a', needed by 'api/libwenet_api.so'. Stop.”,具体报错如下
gmake[2]: *** No rule to make target '../fc_base/libtorch-src/lib/libkineto.a', needed by 'api/libwenet_api.so'. Stop.
gmake[2]: Leaving directory '/root/wenet/runtime/libtorch/build'
gmake[1]: *** [CMakeFiles/Makefile2:2317: api/CMakeFiles/wenet_api.dir/all] Error 2
gmake[1]: Leaving directory '/root/wenet/runtime/libtorch/build'
gmake: *** [Makefile:152: all] Error 2
解决方法:
将重命名的lib-bak文件夹下的libkineto.a到lib路径下
cp ../fc_base/libtorch-src/lib-bak/libkineto.a ../fc_base/libtorch-src/lib/
2、执行cmake --build .报错“warning: libgomp-d22c30c5.so.1.0.0, needed by /root/wenet/runtime/libtorch/fc_base/libtorch-src/lib/libtorch_cpu.so, not found”等错误,具体报错如下:
[ 85%] Linking CXX executable label_checker_main
/usr/bin/ld: warning: libgomp-d22c30c5.so.1.0.0, needed by /root/wenet/runtime/libtorch/fc_base/libtorch-src/lib/libtorch_cpu.so, not found (try using -rpath or -rpath-link)
/usr/bin/ld: warning: libarm_compute-873be09e.so, needed by /root/wenet/runtime/libtorch/fc_base/libtorch-src/lib/libtorch_cpu.so, not found (try using -rpath or -rpath-link)
/usr/bin/ld: warning: libarm_compute_graph-ab857ce5.so, needed by /root/wenet/runtime/libtorch/fc_base/libtorch-src/lib/libtorch_cpu.so, not found (try using -rpath or -rpath-link)
/usr/bin/ld: warning: libarm_compute_core-0793f69d.so, needed by /root/wenet/runtime/libtorch/fc_base/libtorch-src/lib/libtorch_cpu.so, not found (try using -rpath or -rpath-link)
解决方法:
拷贝libtorch_cpu.so依赖的so库文件到lib路径
cp -r /usr/local/lib64/python3.9/site-packages/torch.libs/* ../fc_base/libtorch-src/lib/
8 参考