参考
教程参考
https://blog.csdn.net/lida2003/article/details/145322174
https://blog.csdn.net/fengshengwei3/article/details/146228414
下载
https://developer.nvidia.com/rdp/cudnn-archive
https://forums.developer.nvidia.com/t/pytorch-for-jetson/72048
https://pypi.jetson-ai-lab.dev/jp6/cu126
https://elinux.org/Jetson/L4T/TRT_Customized_Example#YoloV11_using_Pytorch
https://pytorch.org/TensorRT/getting_started/jetpack.html
https://developer.nvidia.com/cudnn-9-3-0-download-archive?target_os=Linux&target_arch=aarch64-jetson&Compilation=Native&Distribution=Ubuntu&target_version=22.04&target_type=deb_local
https://developer.download.nvidia.com/compute/redist/jp/v61/pytorch/
https://forums.developer.nvidia.com/t/jetpack-6-1-cuda-12-6-support-cusparselt-pytorch-installation/310222
https://developer.nvidia.com/cusparselt-downloads?target_os=Linux&target_arch=aarch64-jetson&Compilation=Native&Distribution=Ubuntu&target_version=22.04&target_type=deb_local
开发环境
基础环境:
jetson orin nx engineering performance developer kit super 【Mem 16G】
jetpack 6.2 【https://developer.nvidia.com/embedded/jetpack-sdk-62】
cuda: 12.6.68
cudnn: 9.3.0.75
tensorrt: 10.3.0.30
python: 3.10
docker:
docker image: nvcr.io/nvidia/l4t-tensorrt:r10.3.0-devel
cmake version: 3.14
考虑到适配性问题,我下载10.3.0的tensorrt镜像,cuda版本和cudnn版本与基础环境保持一致。
查看cuda版本命令nvcc -V, 当然也可以用dpkg -l|grep cuda
查看安装的包
可以用dpkg -l|grep cudnn
查看安装的cudnn
Dockerfile
FROM nvcr.io/nvidia/l4t-tensorrt:r10.3.0-devel
# Required to build Ubuntu 22.04 without user prompts with DLFW container
ARG DEBIAN_FRONTEND=noninteractive
# Set environment and working directory
ENV TZ=Asia/Shanghai \
LANG=C.UTF-8
RUN sed -i 's|http://ports.ubuntu.com/ubuntu-ports/|https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/|g' /etc/apt/sources.list
# Install requried libraries
RUN apt-get update && apt-get install -y --no-install-recommends \
software-properties-common \
build-essential \
gdb \
libopencv-dev \
wget \
git \
pkg-config \
ssh \
pbzip2 \
bzip2 \
unzip \
axel \
vim \
curl
# 设置 pip 使用清华源
RUN pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple \
&& pip config set install.trusted-host pypi.tuna.tsinghua.edu.cn \
&& pip install --upgrade pip \
&& pip install --upgrade setuptools>=41.0.0 \
&& pip install --upgrade "pybind11[global]"
WORKDIR /workspace
# 准备好依赖,包括torch等
COPY dependencies/ /workspace/dependencies/
# 安装torch, torchvision, 参考https://blog.csdn.net/lida2003/article/details/145322174下载torch,下载torchvision参考https://elinux.org/Jetson/L4T/TRT_Customized_Example#YoloV11_using_Pytorch
RUN cd /workspace/dependencies/ \
&& pip install torch-2.5.1+l4t36.4-cp310-cp310-linux_aarch64.whl \
&& pip install torchvision-0.20.0-cp310-cp310-linux_aarch64.whl
# 安装最新cmake
RUN cd /workspace/dependencies/ \
&& tar -zxvf cmake-3.31.6-linux-aarch64.tar.gz \
&& mv cmake-3.31.6-linux-aarch64 /
ENV PATH=/cmake-3.31.6-linux-aarch64/bin:$PATH
# 安装(cudnn)[https://developer.nvidia.com/cudnn-9-3-0-download-archive?target_os=Linux&target_arch=aarch64-jetson&Compilation=Native&Distribution=Ubuntu&target_version=22.04&target_type=deb_local]
RUN wget https://developer.download.nvidia.com/compute/cudnn/9.3.0/local_installers/cudnn-local-tegra-repo-ubuntu2204-9.3.0_1.0-1_arm64.deb \
&& dpkg -i cudnn-local-tegra-repo-ubuntu2204-9.3.0_1.0-1_arm64.deb \
&& cp /var/cudnn-local-tegra-repo-ubuntu2204-9.3.0/cudnn-*-keyring.gpg /usr/share/keyrings/ \
&& apt-get update \
&& apt-get -y install cudnn \
&& rm cudnn-local-tegra-repo-ubuntu2204-9.3.0_1.0-1_arm64.deb
# 安装缺失库
RUN wget https://developer.download.nvidia.com/compute/cusparselt/0.7.1/local_installers/cusparselt-local-tegra-repo-ubuntu2204-0.7.1_1.0-1_arm64.deb \
&& dpkg -i cusparselt-local-tegra-repo-ubuntu2204-0.7.1_1.0-1_arm64.deb \
&& cp /var/cusparselt-local-tegra-repo-ubuntu2204-0.7.1/cusparselt-*-keyring.gpg /usr/share/keyrings/ \
&& apt-get update \
&& apt-get -y install libcusparselt0 libcusparselt-dev \
&& rm cusparselt-local-tegra-repo-ubuntu2204-0.7.1_1.0-1_arm64.deb
RUN apt update \
&& apt install -y --no-install-recommends libopenblas-dev \
&& apt-get install libnuma-dev
# 下载不下来可以用https://gitee.com/menglongyue-love/TensorRT-YOLO.git
RUN git clone https://github.com/laugh12321/TensorRT-YOLO.git /workspace/TensorRT-YOLO \
&& cd /workspace/TensorRT-YOLO \
&& cmake -S . -B build -DTENSORRT_PATH=/usr/local/tensorrt -DBUILD_PYTHON=ON \
&& cmake --build build -j$(nproc) --config Release
RUN cd /workspace/TensorRT-YOLO/python \
&& pip install --upgrade build \
&& python -m build --wheel \
&& pip install dist/tensorrt_yolo-6.0.0-py3-none-any.whl[export]
RUN pip install dill \
&& pip install onnxexplorer \
&& pip install numpy==1.26.3
RUN rm -rf /workspace/dependencies && rm -rf /var/lib/apt/lists/*
VOLUME /workspace
RUN ["/bin/bash"]
Build
build.sh
docker build -t jetson-trtyolo-base:jetpack62 .
运行构建镜像
bash build.sh
测试
docker run -dit --gpus all --shm-size=8g --restart=always --net=host --name test --runtime nvidia -e NVIDIA_DRIVER_CAPABILITIES=video,compute,utility -v /etc/localtime:/etc/localtime jetson-trtyolo-base:jetpack62 /bin/bash
过程中遇到的问题
python -c "import torch; print(torch.version.cuda, torch.backends.cudnn.version())"
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/usr/local/lib/python3.10/dist-packages/torch/__init__.py", line 367, in <module>
from torch._C import * # noqa: F403
ImportError: libcudnn.so.9: cannot open shared object file: No such file or directory
使用以下命令找到主机上的 cuDNN 库路径:
ls /usr/lib/aarch64-linux-gnu/libcudnn*
找不到直接装,安装[cudnn](https://developer.nvidia.com/cudnn-9-3-0-download-archive?target_os=Linux&target_arch=aarch64-jetson&Compilation=Native&Distribution=Ubuntu&target_version=22.04&target_type=deb_local)
ImportError: libopenblas.so.0: cannot open shared object file: No such file or directory
这个错误表示你的程序(通常是 Python 的 NumPy 或 SciPy 等库)尝试加载 OpenBLAS 库,但系统找不到它。OpenBLAS 是一个优化的 BLAS(Basic Linear Algebra Subprograms)库,用于执行基本的线性代数运算,它对数值计算性能至关重要。
find / -name "libopenblas.so.0"
找不到装
apt update
apt install libopenblas-dev
ImportError: libcusparseLt.so.0: cannot open shared object file: No such file or directory
这个错误表明你的程序(通常是依赖于 CUDA 的深度学习框架,如 PyTorch 或 TensorFlow)无法找到 `libcusparseLt.so.0` 共享库。`libcusparseLt.so.0` 是 NVIDIA cuSPARSELt 库的一部分,它提供了用于稀疏矩阵运算的优化函数,特别是在深度学习中用于加速 Transformer 模型等。
find / -name libcusparseLt.so.0
https://forums.developer.nvidia.com/t/jetpack-6-1-cuda-12-6-support-cusparselt-pytorch-installation/310222
https://developer.nvidia.com/cusparselt-downloads?target_os=Linux&target_arch=aarch64-jetson&Compilation=Native&Distribution=Ubuntu&target_version=22.04&target_type=deb_local
wget https://developer.download.nvidia.com/compute/cusparselt/0.7.1/local_installers/cusparselt-local-tegra-repo-ubuntu2204-0.7.1_1.0-1_arm64.deb
dpkg -i cusparselt-local-tegra-repo-ubuntu2204-0.7.1_1.0-1_arm64.deb
cp /var/cusparselt-local-tegra-repo-ubuntu2204-0.7.1/cusparselt-*-keyring.gpg /usr/share/keyrings/
apt-get update
apt-get -y install libcusparselt0 libcusparselt-dev
ImportError: libnuma.so.1: cannot open shared object file: No such file or directory
apt-get install libnuma-dev