Jetson TX2下编译AArch64版本的libtorch

发现问题:由于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/

  • 7
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值