diff --git a/.gitmodules b/.gitmodules index 953803f23..655acc60e 100644 --- a/.gitmodules +++ b/.gitmodules @@ -21,3 +21,7 @@ [submodule "plugins/pose"] path = plugins/pose url = https://github.com/dusty-nv/trt_pose +[submodule "docker/containers"] + path = docker/containers + url = https://github.com/dusty-nv/jetson-containers + branch = master diff --git a/CMakeLists.txt b/CMakeLists.txt index da9559f97..4c4b6b02d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -67,16 +67,21 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/utils/cu find_package(CUDA) message("-- CUDA version: ${CUDA_VERSION}") -set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS}; -O3 -gencode arch=compute_53,code=sm_53 -gencode arch=compute_62,code=sm_62) +set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS}; -O3) -if(CUDA_VERSION_MAJOR GREATER 9) - message("-- CUDA ${CUDA_VERSION_MAJOR} detected, enabling SM_72") - set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS}; -gencode arch=compute_72,code=sm_72) -endif() +if(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64") + message("-- CUDA ${CUDA_VERSION} detected (${CMAKE_SYSTEM_PROCESSOR}), enabling SM_53 SM_62") + set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS}; -gencode arch=compute_53,code=sm_53 -gencode arch=compute_62,code=sm_62) + + if(CUDA_VERSION_MAJOR GREATER 9) + message("-- CUDA ${CUDA_VERSION} detected (${CMAKE_SYSTEM_PROCESSOR}), enabling SM_72") + set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS}; -gencode arch=compute_72,code=sm_72) + endif() -if(CUDA_VERSION_MAJOR GREATER 10) - message("-- CUDA ${CUDA_VERSION_MAJOR} detected, enabling SM_87") - set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS}; -gencode arch=compute_87,code=sm_87) + if(CUDA_VERSION_MAJOR GREATER 10) + message("-- CUDA ${CUDA_VERSION} detected (${CMAKE_SYSTEM_PROCESSOR}), enabling SM_87") + set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS}; -gencode arch=compute_87,code=sm_87) + endif() endif() # setup project output paths @@ -96,7 +101,7 @@ set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_OUTPUT_DIR}/lib) # build C/C++ library include_directories(${PROJECT_INCLUDE_DIR} ${PROJECT_INCLUDE_DIR}/jetson-inference ${PROJECT_INCLUDE_DIR}/jetson-utils) -include_directories(/usr/include/gstreamer-1.0 /usr/lib/aarch64-linux-gnu/gstreamer-1.0/include /usr/include/glib-2.0 /usr/include/libxml2 /usr/lib/aarch64-linux-gnu/glib-2.0/include/) +include_directories(/usr/include/gstreamer-1.0 /usr/lib/${CMAKE_SYSTEM_PROCESSOR}/gstreamer-1.0/include /usr/include/glib-2.0 /usr/include/libxml2 /usr/lib/${CMAKE_SYSTEM_PROCESSOR}/glib-2.0/include/) file(GLOB inferenceSources c/*.cpp c/*.cu calibration/*.cpp) file(GLOB inferenceIncludes c/*.h c/*.cuh calibration/*.h) @@ -133,7 +138,10 @@ else() file(GLOB pluginSources plugins/*.cpp plugins/*.cu plugins/pose/trt_pose/parse/*.cpp) endif() -link_directories(/usr/lib/aarch64-linux-gnu/tegra) +if(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64") + link_directories(/usr/lib/aarch64-linux-gnu/tegra) +endif() + cuda_add_library(jetson-inference SHARED ${inferenceSources} ${pluginSources}) target_include_directories(jetson-inference PRIVATE ${PROJECT_SOURCE_DIR}/plugins/pose/trt_pose/parse) diff --git a/Dockerfile b/Dockerfile index 1ca99c7b7..7ff4f56d8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -57,23 +57,9 @@ RUN pip3 install --verbose --upgrade Cython && \ ARG OPENCV_URL=https://nvidia.box.com/shared/static/5v89u6g5rb62fpz4lh0rz531ajo2t5ef.gz ARG OPENCV_DEB=OpenCV-4.5.0-aarch64.tar.gz -RUN apt-get purge -y '*opencv*' || echo "previous OpenCV installation not found" && \ - mkdir opencv && \ - cd opencv && \ - wget --quiet --show-progress --progress=bar:force:noscroll --no-check-certificate ${OPENCV_URL} -O ${OPENCV_DEB} && \ - tar -xzvf ${OPENCV_DEB} && \ - dpkg -i --force-depends *.deb && \ - apt-get update && \ - apt-get install -y -f --no-install-recommends && \ - dpkg -i *.deb && \ - rm -rf /var/lib/apt/lists/* && \ - apt-get clean && \ - cd ../ && \ - rm -rf opencv && \ - PYTHON3_VERSION=`python3 -c 'import sys; version=sys.version_info[:3]; print("{0}.{1}".format(*version))'` && \ - cp -r /usr/include/opencv4 /usr/local/include/opencv4 && \ - cp -r /usr/lib/python${PYTHON3_VERSION}/dist-packages/cv2 /usr/local/lib/python${PYTHON3_VERSION}/dist-packages/cv2 - +COPY docker/containers/scripts/opencv_install.sh /tmp/opencv_install.sh +RUN cd /tmp && ./opencv_install.sh ${OPENCV_URL} ${OPENCV_DEB} + # # copy source diff --git a/docker/build.sh b/docker/build.sh index 94ac47387..99b5c21c8 100755 --- a/docker/build.sh +++ b/docker/build.sh @@ -13,32 +13,36 @@ BASE_IMAGE=$1 # find L4T_VERSION -source tools/l4t-version.sh +source docker/tag.sh if [ -z $BASE_IMAGE ]; then - if [ $L4T_VERSION = "34.1.0" ]; then - BASE_IMAGE="nvcr.io/nvidia/l4t-pytorch:r34.1.0-pth1.12-py3" - elif [ $L4T_VERSION = "32.6.1" ]; then - BASE_IMAGE="nvcr.io/nvidia/l4t-pytorch:r32.6.1-pth1.9-py3" - elif [ $L4T_VERSION = "32.5.1" ]; then - BASE_IMAGE="nvcr.io/nvidia/l4t-pytorch:r32.5.0-pth1.6-py3" - elif [ $L4T_VERSION = "32.5.0" ]; then - BASE_IMAGE="nvcr.io/nvidia/l4t-pytorch:r32.5.0-pth1.6-py3" - elif [ $L4T_VERSION = "32.4.4" ]; then - BASE_IMAGE="nvcr.io/nvidia/l4t-pytorch:r32.4.4-pth1.6-py3" - elif [ $L4T_VERSION = "32.4.3" ]; then - BASE_IMAGE="nvcr.io/nvidia/l4t-pytorch:r32.4.3-pth1.6-py3" - elif [ $L4T_VERSION = "32.4.2" ]; then - BASE_IMAGE="nvcr.io/nvidia/l4t-pytorch:r32.4.2-pth1.5-py3" - else - echo "cannot automatically select l4t-pytorch base container for L4T R$L4T_VERSION" - echo "please specify it manually as: docker/build.sh nvcr.io/nvidia/l4t-pytorch:" - exit 1 + if [ $ARCH = "aarch64" ]; then + if [ $L4T_VERSION = "34.1.0" ]; then + BASE_IMAGE="nvcr.io/nvidia/l4t-pytorch:r34.1.0-pth1.12-py3" + elif [ $L4T_VERSION = "32.6.1" ]; then + BASE_IMAGE="nvcr.io/nvidia/l4t-pytorch:r32.6.1-pth1.9-py3" + elif [ $L4T_VERSION = "32.5.1" ]; then + BASE_IMAGE="nvcr.io/nvidia/l4t-pytorch:r32.5.0-pth1.6-py3" + elif [ $L4T_VERSION = "32.5.0" ]; then + BASE_IMAGE="nvcr.io/nvidia/l4t-pytorch:r32.5.0-pth1.6-py3" + elif [ $L4T_VERSION = "32.4.4" ]; then + BASE_IMAGE="nvcr.io/nvidia/l4t-pytorch:r32.4.4-pth1.6-py3" + elif [ $L4T_VERSION = "32.4.3" ]; then + BASE_IMAGE="nvcr.io/nvidia/l4t-pytorch:r32.4.3-pth1.6-py3" + elif [ $L4T_VERSION = "32.4.2" ]; then + BASE_IMAGE="nvcr.io/nvidia/l4t-pytorch:r32.4.2-pth1.5-py3" + else + echo "cannot automatically select l4t-pytorch base container for L4T R$L4T_VERSION" + echo "please specify it manually as: docker/build.sh nvcr.io/nvidia/l4t-pytorch:" + exit 1 + fi + elif [ $ARCH = "x86_64" ]; then + BASE_IMAGE="nvcr.io/nvidia/pytorch:22.04-py3" fi fi echo "BASE_IMAGE=$BASE_IMAGE" -echo "TAG=jetson-inference:r$L4T_VERSION" +echo "TAG=$TAG" # sanitize workspace (so extra files aren't added to the container) @@ -48,37 +52,14 @@ rm -rf python/training/classification/models/* rm -rf python/training/detection/ssd/data/* rm -rf python/training/detection/ssd/models/* - -# opencv.csv mounts files that preclude us installing different version of opencv -# temporarily disable the opencv.csv mounts while we build the container -CV_CSV="/etc/nvidia-container-runtime/host-files-for-container.d/opencv.csv" - -if [ -f "$CV_CSV" ]; then - sudo mv $CV_CSV $CV_CSV.backup -fi - # distro release-dependent build options -LSB_RELEASE=$(lsb_release --codename --short) - -OPENCV_URL="https://nvidia.box.com/shared/static/5v89u6g5rb62fpz4lh0rz531ajo2t5ef.gz" -OPENCV_DEB="OpenCV-4.5.0-aarch64.tar.gz" - -if [ $LSB_RELEASE = "focal" ]; then - echo "configuring docker build for $LSB_RELEASE" - OPENCV_URL="https://nvidia.box.com/shared/static/2hssa5g3v28ozvo3tc3qwxmn78yerca9.gz" -fi +source docker/containers/scripts/opencv_version.sh # build the container -sudo docker build -t jetson-inference:r$L4T_VERSION -f Dockerfile \ +sudo docker build -t $TAG -f Dockerfile \ --build-arg BASE_IMAGE=$BASE_IMAGE \ --build-arg OPENCV_URL=$OPENCV_URL \ --build-arg OPENCV_DEB=$OPENCV_DEB \ . - - -# restore opencv.csv mounts -if [ -f "$CV_CSV.backup" ]; then - sudo mv $CV_CSV.backup $CV_CSV -fi diff --git a/docker/containers b/docker/containers new file mode 160000 index 000000000..ddb1f28a7 --- /dev/null +++ b/docker/containers @@ -0,0 +1 @@ +Subproject commit ddb1f28a7dad3d002d6b6bed4b2bf50d96286077 diff --git a/docker/tag.sh b/docker/tag.sh index 69687ccfd..96e46bfa9 100755 --- a/docker/tag.sh +++ b/docker/tag.sh @@ -1,53 +1,62 @@ #!/usr/bin/env bash # find L4T_VERSION -source tools/l4t-version.sh +source docker/containers/scripts/l4t_version.sh -# local container:tag name -CONTAINER_IMAGE="jetson-inference:r$L4T_VERSION" +if [ $ARCH = "aarch64" ]; then + # local container:tag name + CONTAINER_IMAGE="jetson-inference:r$L4T_VERSION" -# incompatible L4T version -function version_error() -{ - echo "cannot find compatible jetson-inference docker container for L4T R$L4T_VERSION" - echo "please upgrade to the latest JetPack, or build jetson-inference natively from source" - exit 1 -} + # incompatible L4T version + function version_error() + { + echo "cannot find compatible jetson-inference docker container for L4T R$L4T_VERSION" + echo "please upgrade to the latest JetPack, or build jetson-inference natively from source" + exit 1 + } -# get remote container URL -if [ $L4T_RELEASE -eq 32 ]; then - if [ $L4T_REVISION_MAJOR -eq 4 ]; then - if [ $L4T_REVISION_MINOR -gt 4 ]; then - CONTAINER_REMOTE_IMAGE="nvcr.io/ea-linux4tegra/$CONTAINER_IMAGE" - elif [ $L4T_REVISION_MINOR -ge 3 ]; then + # get remote container URL + if [ $L4T_RELEASE -eq 32 ]; then + if [ $L4T_REVISION_MAJOR -eq 4 ]; then + if [ $L4T_REVISION_MINOR -gt 4 ]; then + CONTAINER_REMOTE_IMAGE="nvcr.io/ea-linux4tegra/$CONTAINER_IMAGE" + elif [ $L4T_REVISION_MINOR -ge 3 ]; then + CONTAINER_REMOTE_IMAGE="dustynv/$CONTAINER_IMAGE" + else + version_error + fi + elif [ $L4T_REVISION_MAJOR -eq 5 ]; then + if [ $L4T_REVISION_MINOR -eq 0 ]; then + CONTAINER_REMOTE_IMAGE="dustynv/$CONTAINER_IMAGE" + elif [ $L4T_REVISION_MINOR -eq 1 ] || [ $L4T_REVISION_MINOR -eq 2 ]; then + # L4T R32.5.1 / R32.5.2 runs the R32.5.0 container + CONTAINER_IMAGE="jetson-inference:r32.5.0" + CONTAINER_REMOTE_IMAGE="dustynv/$CONTAINER_IMAGE" + else + CONTAINER_REMOTE_IMAGE="nvcr.io/ea-linux4tegra/$CONTAINER_IMAGE" + fi + elif [ $L4T_REVISION_MAJOR -gt 5 ]; then CONTAINER_REMOTE_IMAGE="dustynv/$CONTAINER_IMAGE" else version_error fi - elif [ $L4T_REVISION_MAJOR -eq 5 ]; then - if [ $L4T_REVISION_MINOR -eq 0 ]; then - CONTAINER_REMOTE_IMAGE="dustynv/$CONTAINER_IMAGE" - elif [ $L4T_REVISION_MINOR -eq 1 ] || [ $L4T_REVISION_MINOR -eq 2 ]; then - # L4T R32.5.1 / R32.5.2 runs the R32.5.0 container - CONTAINER_IMAGE="jetson-inference:r32.5.0" - CONTAINER_REMOTE_IMAGE="dustynv/$CONTAINER_IMAGE" - else - CONTAINER_REMOTE_IMAGE="nvcr.io/ea-linux4tegra/$CONTAINER_IMAGE" - fi - elif [ $L4T_REVISION_MAJOR -gt 5 ]; then + elif [ $L4T_RELEASE -eq 34 ]; then CONTAINER_REMOTE_IMAGE="dustynv/$CONTAINER_IMAGE" else version_error fi -elif [ $L4T_RELEASE -eq 34 ]; then - CONTAINER_REMOTE_IMAGE="dustynv/$CONTAINER_IMAGE" -else - version_error + +elif [ $ARCH = "x86_64" ]; then + # TODO: add logic here for getting the latest release + CONTAINER_IMAGE="jetson-inference:22.06" fi +# TAG is always the local container name +# CONTAINER_REMOTE_IMAGE is always the container name in NGC/dockerhub +# CONTAINER_IMAGE is either local container name (if it exists on the system) or the remote image name +TAG=$CONTAINER_IMAGE + # check for local image if [[ "$(sudo docker images -q $CONTAINER_IMAGE 2> /dev/null)" == "" ]]; then CONTAINER_IMAGE=$CONTAINER_REMOTE_IMAGE fi - - diff --git a/tools/l4t-version.sh b/tools/l4t-version.sh deleted file mode 100755 index 60d75d675..000000000 --- a/tools/l4t-version.sh +++ /dev/null @@ -1,49 +0,0 @@ -#!/bin/bash -# -# Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved. -# -# Permission is hereby granted, free of charge, to any person obtaining a -# copy of this software and associated documentation files (the "Software"), -# to deal in the Software without restriction, including without limitation -# the rights to use, copy, modify, merge, publish, distribute, sublicense, -# and/or sell copies of the Software, and to permit persons to whom the -# Software is furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in -# all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -# DEALINGS IN THE SOFTWARE. -# - -L4T_VERSION_STRING=$(head -n 1 /etc/nv_tegra_release) - -if [ -z "$L4T_VERSION_STRING" ]; then - echo "reading L4T version from \"dpkg-query --show nvidia-l4t-core\"" - - L4T_VERSION_STRING=$(dpkg-query --showformat='${Version}' --show nvidia-l4t-core) - L4T_VERSION_ARRAY=(${L4T_VERSION_STRING//./ }) - - #echo ${L4T_VERSION_ARRAY[@]} - #echo ${#L4T_VERSION_ARRAY[@]} - - L4T_RELEASE=${L4T_VERSION_ARRAY[0]} - L4T_REVISION=${L4T_VERSION_ARRAY[1]} -else - echo "reading L4T version from /etc/nv_tegra_release" - - L4T_RELEASE=$(echo $L4T_VERSION_STRING | cut -f 2 -d ' ' | grep -Po '(?<=R)[^;]+') - L4T_REVISION=$(echo $L4T_VERSION_STRING | cut -f 2 -d ',' | grep -Po '(?<=REVISION: )[^;]+') -fi - -L4T_REVISION_MAJOR=${L4T_REVISION:0:1} -L4T_REVISION_MINOR=${L4T_REVISION:2:1} - -L4T_VERSION="$L4T_RELEASE.$L4T_REVISION" - -echo "L4T BSP Version: L4T R$L4T_VERSION" diff --git a/utils b/utils index def4a04d0..a70a254a3 160000 --- a/utils +++ b/utils @@ -1 +1 @@ -Subproject commit def4a04d023960781a44f9cd97fd1464093becf0 +Subproject commit a70a254a33c317aef006289089a8f10e41fb6d61