发现问题:由于libtorch的官方版只提供x86的动态链接文件,因此在arm架构处理器下使用会产生错误
error adding symbols: file in wrong format(添加符号时出错:文件格式错误)
在pytorch官网上下载的libtorch库:
Jetson TX2下编译出的libtorch库:
编译步骤:
1.下载pytorch源码
git clone --recursive https://github.com/pytorch/pytorch
cd pytorch
这里需要check成你需要的libtorch版本,这里我使用的是libtorch1.13.1
git checkout v1.13.1
2.安装依赖
sudo pip3 install -U setuptools
sudo pip3 install -r requirements.txt
pip3 install pyyaml
git submodule sync
git submodule update --init --recursive
3.关闭一些不必要的编译选项来加快编译速度
export BUILD_TEST=False
export USE_NCCL=0
export USE_DISTRIBUTED=0
export TORCH_CUDA_ARCH_LIST=“5.3;6.2;7.2”
4.加快编译速度
sudo nvpmodel -m 0
启动/usr/bin/下的jetson_clocks
5.开始编译
mkdir build && cd build
python3 …/tools/build_libtorch.py
6.编译完成之后使用
libtorch库的使用需要三个文件夹lib(动态库和静态库),include(头文件),share(用来配置cmake)
lib目录下的库在build/lib库下面:
include(头文件),share(用来配置cmake)在pytorch/torch/路径下:
常见错误:
1.错误:make[2]: warning: Clock skew detected. Your build may be incomplete
回到工作空间中(即build文件夹的上一级路径)
使用命令:find ./ -type f |xargs touch
2.nvlink error : Undefined reference to ‘_ZN8Strategy8backtestEPddd’
编译前使用命令:export USE_NCCL=0
参考文章
https://blog.csdn.net/chen499093551/article/details/129489295
https://zhuanlan.zhihu.com/p/585468425
https://txsangyj.github.io/post/armv8-bian-yi-libtorch/