Skip to content

Commit

Permalink
initial build support for x86
Browse files Browse the repository at this point in the history
  • Loading branch information
dusty-nv committed Jun 2, 2022
1 parent bed39a4 commit 2621464
Show file tree
Hide file tree
Showing 8 changed files with 95 additions and 155 deletions.
4 changes: 4 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -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
28 changes: 18 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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)

Expand Down
20 changes: 3 additions & 17 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
71 changes: 26 additions & 45 deletions docker/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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:<TAG>"
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:<TAG>"
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)
Expand All @@ -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
1 change: 1 addition & 0 deletions docker/containers
Submodule containers added at ddb1f2
75 changes: 42 additions & 33 deletions docker/tag.sh
Original file line number Diff line number Diff line change
@@ -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


49 changes: 0 additions & 49 deletions tools/l4t-version.sh

This file was deleted.

2 changes: 1 addition & 1 deletion utils
Submodule utils updated 1 files
+30 −34 CMakeLists.txt

0 comments on commit 2621464

Please sign in to comment.