diff --git a/Makefile b/Makefile index ddccca4f2..f6b0947eb 100644 --- a/Makefile +++ b/Makefile @@ -6,64 +6,24 @@ SAVANT_VERSION := $(shell cat savant/VERSION | awk -F= '$$1=="SAVANT"{print $$2} DEEPSTREAM_VERSION := $(shell cat savant/VERSION | awk -F= '$$1=="DEEPSTREAM"{print $$2}' | sed 's/"//g') DOCKER_FILE := Dockerfile.deepstream PLATFORM_SUFFIX := -PYDS_DOCKER_BUILDKIT := 1 -OPENCV_DOCKER_BUILDKIT := 1 -PYDS_BASE_IMAGE := nvcr.io/nvidia/deepstream:$(DEEPSTREAM_VERSION)-devel -OPENCV_BASE_IMAGE := nvcr.io/nvidia/deepstream:$(DEEPSTREAM_VERSION)-devel -PYDS_PIP_PLATFORM := linux_x86_64 PYDS_VERSION := 1.1.4 ifeq ("$(shell uname -m)", "aarch64") PLATFORM_SUFFIX := -l4t DOCKER_FILE := Dockerfile.deepstream-l4t L4T_MAJOR_VERSION := $(shell dpkg-query --showformat='$${Version}' --show nvidia-l4t-core | cut -f 1 -d '-' | cut -f 1 -d '.') - # We cannot use buildkit to build pyds on Jetson devices since buildkit doesn't use nvidia runtime. - # But we need nvidia runtime to mount required libraries to the containers. - PYDS_DOCKER_BUILDKIT := 0 - OPENCV_DOCKER_BUILDKIT := 0 - PYDS_BASE_IMAGE := nvcr.io/nvidia/deepstream-l4t:$(DEEPSTREAM_VERSION)-triton - OPENCV_BASE_IMAGE := nvcr.io/nvidia/deepstream-l4t:$(DEEPSTREAM_VERSION)-triton - PYDS_PIP_PLATFORM := linux_aarch64 ifeq ($(L4T_MAJOR_VERSION), 32) DEEPSTREAM_VERSION := 6.0.1 DOCKER_FILE := Dockerfile.deepstream-l4t-6.0.1 - PYDS_VERSION := 1.1.1 - PYDS_BASE_IMAGE := nvcr.io/nvidia/deepstream-l4t:$(DEEPSTREAM_VERSION)-samples - OPENCV_BASE_IMAGE := nvcr.io/nvidia/deepstream-l4t:$(DEEPSTREAM_VERSION)-samples endif endif -build-pyds: - DOCKER_BUILDKIT=$(PYDS_DOCKER_BUILDKIT) docker build \ - --build-arg BASE_IMAGE=$(PYDS_BASE_IMAGE) \ - --build-arg PIP_PLATFORM=$(PYDS_PIP_PLATFORM) \ - --build-arg PYDS_TAG=v$(PYDS_VERSION)-unmap \ - --progress plain \ - -f docker/Dockerfile.pyds \ - -t savant-pyds$(PLATFORM_SUFFIX):$(SAVANT_VERSION)-$(DEEPSTREAM_VERSION) . - mkdir -p libs/wheels - docker run --rm \ - --entrypoint cat \ - savant-pyds$(PLATFORM_SUFFIX):$(SAVANT_VERSION)-$(DEEPSTREAM_VERSION) \ - /dist/pyds-$(PYDS_VERSION)-py3-none-$(PYDS_PIP_PLATFORM).whl > libs/wheels/pyds-$(PYDS_VERSION)-py3-none-$(PYDS_PIP_PLATFORM).whl - -build-opencv: - DOCKER_BUILDKIT=$(OPENCV_DOCKER_BUILDKIT) docker build \ - --build-arg BASE_IMAGE=$(OPENCV_BASE_IMAGE) \ - --progress plain \ - -f docker/Dockerfile.opencv \ - -t savant-opencv$(PLATFORM_SUFFIX):$(SAVANT_VERSION)-$(DEEPSTREAM_VERSION) . - docker run --rm \ - --entrypoint cat \ - savant-opencv$(PLATFORM_SUFFIX):$(SAVANT_VERSION)-$(DEEPSTREAM_VERSION) \ - /opencv/dist.tar.gz > libs/opencv.tar.gz - - -build: build-pyds build-opencv +build: DOCKER_BUILDKIT=1 docker build \ - --target base \ + --target pyds_build \ --progress plain \ --build-arg DEEPSTREAM_VERSION=$(DEEPSTREAM_VERSION) \ + --build-arg PYDS_TAG=v$(PYDS_VERSION)-unmap \ -f docker/$(DOCKER_FILE) \ -t savant-deepstream$(PLATFORM_SUFFIX):$(SAVANT_VERSION)-$(DEEPSTREAM_VERSION)-base . diff --git a/docker/Dockerfile.deepstream b/docker/Dockerfile.deepstream index 9eaa4e447..cbe0bc12c 100644 --- a/docker/Dockerfile.deepstream +++ b/docker/Dockerfile.deepstream @@ -1,9 +1,18 @@ ARG DEEPSTREAM_VERSION -FROM nvcr.io/nvidia/deepstream:$DEEPSTREAM_VERSION-devel AS pygstsavantframemeta_build +FROM nvcr.io/nvidia/deepstream:$DEEPSTREAM_VERSION-devel AS base_build + +# Newer cmake ver. needed for "FindCUDAToolkit" +RUN mkdir -p /tmp/cmake \ + && cd /tmp/cmake \ + && wget --progress=bar:force:noscroll https://github.com/Kitware/CMake/releases/download/v3.23.2/cmake-3.23.2-linux-x86_64.sh \ + && sh cmake-3.23.2-linux-x86_64.sh --skip-license --prefix=/usr/local/ # python to python3 by default RUN update-alternatives --install /usr/bin/python python /usr/bin/python3 10 + +FROM base_build AS pygstsavantframemeta_build + WORKDIR /libs/gstsavantframemeta COPY libs/gstsavantframemeta/requirements.txt . RUN pip install --no-cache-dir -r requirements.txt @@ -13,7 +22,7 @@ RUN python setup.py bdist_wheel && \ rm -rf _skbuild -FROM nvcr.io/nvidia/deepstream:$DEEPSTREAM_VERSION-devel AS opencv_build +FROM base_build AS opencv_build WORKDIR /opencv ARG OPENCV_VERSION=4.6.0 @@ -21,7 +30,7 @@ RUN git clone --branch "${OPENCV_VERSION}" --depth 1 https://github.com/opencv/o RUN git clone --branch "${OPENCV_VERSION}" --depth 1 https://github.com/opencv/opencv_contrib WORKDIR /opencv/build -RUN python3 -m pip install --no-cache-dir 'numpy~=1.22.4' +RUN python -m pip install --no-cache-dir 'numpy~=1.22.4' COPY libs/opencv/savant /opencv/opencv_contrib/modules/savant RUN --mount=type=cache,target=/tmp/opencv-cache \ @@ -46,19 +55,9 @@ RUN --mount=type=cache,target=/tmp/opencv-cache \ /opencv/opencv RUN make -j$(nproc) install -RUN tar -C /opencv/dist/ -cvzf /opencv/dist.tar.gz $(ls -A /opencv/dist/) - -FROM nvcr.io/nvidia/deepstream:$DEEPSTREAM_VERSION-devel AS savantboost_build - -# Newer cmake ver. needed for "FindCUDAToolkit" -RUN mkdir -p /tmp/cmake \ - && cd /tmp/cmake \ - && wget --progress=bar:force:noscroll https://github.com/Kitware/CMake/releases/download/v3.23.2/cmake-3.23.2-linux-x86_64.sh \ - && sh cmake-3.23.2-linux-x86_64.sh --skip-license --prefix=/usr/local/ -# python to python3 by default -RUN update-alternatives --install /usr/bin/python python /usr/bin/python3 10 +FROM base_build AS savantboost_build WORKDIR /libs/savanboost COPY libs/savantboost/requirements.txt . @@ -67,6 +66,36 @@ RUN pip install --no-cache-dir -r requirements.txt COPY libs/savantboost . RUN python setup.py bdist_wheel && rm -rf _skbuild + +FROM base_build AS pyds_build + +RUN apt-get update \ + && apt-get install -y \ + python-gi-dev \ + && rm -rf /var/lib/apt/lists/* + +ARG PYDS_TAG +RUN git clone https://github.com/tomskikh/deepstream_python_apps.git /deepstream_python_apps \ + && cd /deepstream_python_apps \ + && git checkout $PYDS_TAG \ + && git submodule init \ + && git submodule update \ + && cd 3rdparty/gst-python \ + && git submodule init \ + && git submodule update + +WORKDIR /deepstream_python_apps/3rdparty/gst-python +RUN ./autogen.sh \ + && make \ + && make install + +WORKDIR /deepstream_python_apps/bindings/build +RUN cmake -DPIP_PLATFORM=linux_x86_64 .. \ + && make \ + && mkdir /dist \ + && mv *.whl /dist/ + + FROM nvcr.io/nvidia/deepstream:$DEEPSTREAM_VERSION-base AS base # python to python3 by default @@ -98,21 +127,23 @@ ENV LD_LIBRARY_PATH=/opt/nvidia/deepstream/deepstream/lib/:$LD_LIBRARY_PATH COPY requirements/base.txt requirements-base.txt COPY requirements/deepstream.txt requirements-deepstream.txt RUN python -m pip install --no-cache-dir --upgrade pip -COPY libs/wheels libs/wheels RUN python -m pip install --no-cache-dir \ -r requirements-base.txt \ -r requirements-deepstream.txt \ && rm requirements-base.txt \ && rm requirements-deepstream.txt -#COPY --from=opencv_build /opencv/dist /usr/local -ADD libs/opencv.tar.gz /usr/local +COPY --from=opencv_build /opencv/dist /usr/local + COPY --from=pygstsavantframemeta_build /libs/gstsavantframemeta/dist /libs/gstsavantframemeta/dist RUN python -m pip install --no-cache-dir /libs/gstsavantframemeta/dist/*.whl COPY --from=savantboost_build /libs/savanboost/dist /libs/savanboost/dist RUN python -m pip install --no-cache-dir /libs/savanboost/dist/*.whl +COPY --from=pyds_build /dist /libs/pyds/dist +RUN python -m pip install --no-cache-dir /libs/pyds/dist/*.whl + COPY savant savant COPY LICENSE savant/ ENV GST_PLUGIN_PATH=$APP_PATH/savant/gst_plugins:$APP_PATH/savant/utils/gst_plugins diff --git a/docker/Dockerfile.deepstream-l4t b/docker/Dockerfile.deepstream-l4t index 292437f9a..51637eb2e 100644 --- a/docker/Dockerfile.deepstream-l4t +++ b/docker/Dockerfile.deepstream-l4t @@ -1,5 +1,25 @@ ARG DEEPSTREAM_VERSION -FROM nvcr.io/nvidia/deepstream-l4t:$DEEPSTREAM_VERSION-triton AS pygstsavantframemeta_build +FROM nvcr.io/nvidia/deepstream-l4t:$DEEPSTREAM_VERSION-triton AS base_build + +ARG soc=t194 + +RUN wget --no-verbose -O /tmp/cmake.sh \ + https://github.com/Kitware/CMake/releases/download/v3.24.2/cmake-3.24.2-linux-aarch64.sh \ + && sh /tmp/cmake.sh --skip-license --prefix=/usr/local \ + && rm -f /tmp/cmake.sh + +RUN echo "deb https://repo.download.nvidia.com/jetson/$soc `cat /etc/apt/sources.list | grep jetson/common | cut -d' ' -f3` main" \ + > /etc/apt/sources.list.d/nvidia-l4t-apt-source.list \ + && rm /etc/ld.so.conf.d/nvidia-tegra.conf \ + && mkdir -p /opt/nvidia/l4t-packages/ \ + && touch /opt/nvidia/l4t-packages/.nv-l4t-disable-boot-fw-update-in-preinstall \ + && apt-get update \ + && apt-get install -y \ + nvidia-l4t-multimedia \ + && rm -rf /var/lib/apt/lists/* + + +FROM base_build AS pygstsavantframemeta_build WORKDIR /libs/gstsavantframemeta COPY libs/gstsavantframemeta/requirements.txt . @@ -10,7 +30,31 @@ RUN python setup.py bdist_wheel && \ rm -rf _skbuild -FROM nvcr.io/nvidia/deepstream-l4t:$DEEPSTREAM_VERSION-triton AS opencv_build +FROM base_build AS pyds_build + +ARG PYDS_TAG +RUN git clone https://github.com/tomskikh/deepstream_python_apps.git /deepstream_python_apps \ + && cd /deepstream_python_apps \ + && git checkout $PYDS_TAG \ + && git submodule init \ + && git submodule update \ + && cd 3rdparty/gst-python \ + && git submodule init \ + && git submodule update + +WORKDIR /deepstream_python_apps/3rdparty/gst-python +RUN ./autogen.sh \ + && make \ + && make install + +WORKDIR /deepstream_python_apps/bindings/build +RUN cmake -DPIP_PLATFORM=linux_aarch64 .. \ + && make \ + && mkdir /dist \ + && mv *.whl /dist/ + + +FROM base_build AS opencv_build WORKDIR /opencv ARG OPENCV_VERSION=4.6.0 @@ -45,25 +89,7 @@ RUN --mount=type=cache,target=/tmp/opencv-cache \ RUN make -j$(nproc) install -FROM nvcr.io/nvidia/deepstream-l4t:$DEEPSTREAM_VERSION-triton AS savantboost_build - -ARG soc=t194 - - -RUN wget --no-verbose -O /tmp/cmake.sh \ - https://github.com/Kitware/CMake/releases/download/v3.24.2/cmake-3.24.2-linux-aarch64.sh \ - && sh /tmp/cmake.sh --skip-license --prefix=/usr/local \ - && rm -f /tmp/cmake.sh - -RUN echo "deb https://repo.download.nvidia.com/jetson/$soc `cat /etc/apt/sources.list | grep jetson/common | cut -d' ' -f3` main" \ - > /etc/apt/sources.list.d/nvidia-l4t-apt-source.list \ - && rm /etc/ld.so.conf.d/nvidia-tegra.conf \ - && mkdir -p /opt/nvidia/l4t-packages/ \ - && touch /opt/nvidia/l4t-packages/.nv-l4t-disable-boot-fw-update-in-preinstall \ - && apt-get update \ - && apt-get install -y \ - nvidia-l4t-multimedia \ - && rm -rf /var/lib/apt/lists/* +FROM base_build AS savantboost_build WORKDIR /libs/savanboost COPY libs/savantboost/requirements.txt . @@ -101,21 +127,23 @@ ENV LD_LIBRARY_PATH=/opt/nvidia/deepstream/deepstream/lib/:$LD_LIBRARY_PATH COPY requirements/base.txt requirements-base.txt COPY requirements/deepstream-l4t.txt requirements-deepstream-l4t.txt RUN python -m pip install --no-cache-dir --upgrade pip -COPY libs/wheels libs/wheels RUN python -m pip install --no-cache-dir \ -r requirements-base.txt \ -r requirements-deepstream-l4t.txt \ && rm requirements-base.txt \ && rm requirements-deepstream-l4t.txt -#COPY --from=opencv_build /opencv/dist /usr/local -ADD libs/opencv.tar.gz /usr/local +COPY --from=opencv_build /opencv/dist /usr/local + COPY --from=pygstsavantframemeta_build /libs/gstsavantframemeta/dist /libs/gstsavantframemeta/dist RUN python -m pip install --no-cache-dir /libs/gstsavantframemeta/dist/*.whl COPY --from=savantboost_build /libs/savanboost/dist /libs/savanboost/dist RUN python -m pip install --no-cache-dir /libs/savanboost/dist/*.whl +COPY --from=pyds_build /dist /libs/pyds/dist +RUN python -m pip install --no-cache-dir /libs/pyds/dist/*.whl + COPY savant savant COPY LICENSE savant/ ENV GST_PLUGIN_PATH=$APP_PATH/savant/gst_plugins:$APP_PATH/savant/utils/gst_plugins diff --git a/docker/Dockerfile.opencv b/docker/Dockerfile.opencv index 1f5a62904..0b57244a0 100644 --- a/docker/Dockerfile.opencv +++ b/docker/Dockerfile.opencv @@ -9,6 +9,11 @@ WORKDIR /opencv/build RUN python3 -m pip install --no-cache-dir 'numpy~=1.22.4' +# Newer cmake ver. needed for "FindCUDAToolkit" +RUN mkdir -p /tmp/cmake \ + && cd /tmp/cmake \ + && wget --progress=bar:force:noscroll https://github.com/Kitware/CMake/releases/download/v3.23.2/cmake-3.23.2-linux-x86_64.sh \ + && sh cmake-3.23.2-linux-x86_64.sh --skip-license --prefix=/usr/local/ COPY libs/opencv/savant /opencv/opencv_contrib/modules/savant RUN cmake \ -D CMAKE_BUILD_TYPE=RELEASE \ diff --git a/libs/opencv/savant/src/savant.cpp b/libs/opencv/savant/src/savant.cpp index bfab58095..12f26e43f 100644 --- a/libs/opencv/savant/src/savant.cpp +++ b/libs/opencv/savant/src/savant.cpp @@ -2,7 +2,7 @@ #include "opencv2/core.hpp" #include "opencv2/core/cuda.hpp" #include -#include +//#include #include #include "nvbufsurface.h" @@ -32,8 +32,8 @@ namespace cv { std::cout << std::endl; // TODO: check memory type is NVBUF_MEM_SURFACE_ARRAY - int ret = NvBufSurfaceMapEglImage(nvsurface, batch_id); - std::cout << "ret=" << ret << std::endl; +// int ret = NvBufSurfaceMapEglImage(nvsurface, batch_id); +// std::cout << "ret=" << ret << std::endl; std::cout << "nvsurface->memType : " << nvsurface->memType << std::endl; std::cout << "surface.height : " << surface.height << std::endl; @@ -45,20 +45,21 @@ namespace cv { std::cout << "surface.mappedAddr.eglImage: " << surface.mappedAddr.eglImage << std::endl; std::cout << std::endl; - CUeglFrame eglFrame; - CUgraphicsResource pResource = NULL; - CUresult status; - status = cuGraphicsEGLRegisterImage(&pResource, surface.mappedAddr.eglImage, CU_GRAPHICS_MAP_RESOURCE_FLAGS_NONE); - std::cout << "cuGraphicsEGLRegisterImage: " << status << std::endl; - std::cout << "pResource: " << pResource << std::endl; - status = cuGraphicsResourceGetMappedEglFrame(&eglFrame, pResource, 0, 0); - std::cout << "cuGraphicsResourceGetMappedEglFrame: " << status << std::endl; - std::cout << "eglFrame: " << eglFrame << std::endl; - status = cuCtxSynchronize(); - std::cout << "cuCtxSynchronize: " << status << std::endl; - std::cout << std::endl; +// CUeglFrame eglFrame; +// CUgraphicsResource pResource = NULL; +// CUresult status; +// status = cuGraphicsEGLRegisterImage(&pResource, surface.mappedAddr.eglImage, CU_GRAPHICS_MAP_RESOURCE_FLAGS_NONE); +// std::cout << "cuGraphicsEGLRegisterImage: " << status << std::endl; +// //std::cout << "pResource: " << pResource << std::endl; +// status = cuGraphicsResourceGetMappedEglFrame(&eglFrame, pResource, 0, 0); +// std::cout << "cuGraphicsResourceGetMappedEglFrame: " << status << std::endl; +// //std::cout << "eglFrame: " << eglFrame << std::endl; +// status = cuCtxSynchronize(); +// std::cout << "cuCtxSynchronize: " << status << std::endl; +// std::cout << std::endl; - cv::cuda::GpuMat gpuMat(surface.height, surface.width, CV_8UC4, eglFrame.frame.pPitch[0]); +// cv::cuda::GpuMat gpuMat(surface.height, surface.width, CV_8UC4, eglFrame.frame.pPitch[0]); + cv::cuda::GpuMat gpuMat(surface.height, surface.width, CV_8UC4, surface.dataPtr); return gpuMat; } } diff --git a/requirements/deepstream.txt b/requirements/deepstream.txt index cfadf922d..aaecbf6b1 100644 --- a/requirements/deepstream.txt +++ b/requirements/deepstream.txt @@ -3,4 +3,4 @@ pycairo~=1.21.0 # pyds # TODO: Use an artifact from https://github.com/NVIDIA-AI-IOT/deepstream_python_apps # when https://github.com/NVIDIA-AI-IOT/deepstream_python_apps/pull/6 is merged and released -./libs/wheels/pyds-1.1.4-py3-none-linux_x86_64.whl +# ./libs/wheels/pyds-1.1.4-py3-none-linux_x86_64.whl