Skip to content

Commit a003284

Browse files
authored
Integrate nvimagecodec (NVIDIA#5297)
Replaces handwritten experimental ImageDecoder operators, with a version based on the nvImageCodec library: https://docs.nvidia.com/cuda/nvimagecodec/ Signed-off-by: Joaquin Anton <janton@nvidia.com>
1 parent 5869dd0 commit a003284

File tree

205 files changed

+3071
-13714
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

205 files changed

+3071
-13714
lines changed

CMakeLists.txt

+11-8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2017-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
1+
# Copyright (c) 2017-2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.
@@ -39,14 +39,18 @@ check_cxx_compiler_flag(-fopenmp-simd CXX_HAVE_OMP_SIMD)
3939
# Build options
4040
option(BUILD_DALI_NODEPS "Disable components that require extra external libraries to be present in the system. Effectively, it builds only the DALI core and kernel libraries")
4141
option(LINK_DRIVER "Links directly with libcuda.so instead of dlopen it at runtime" OFF)
42-
option(WITH_DYNAMIC_CUDA_TOOLKIT "Links CUDA toolkit libraires dynamically (NPP, nvJPEG, cuFFT)" OFF)
42+
option(WITH_DYNAMIC_CUDA_TOOLKIT "Links CUDA toolkit libraries dynamically (NPP, nvJPEG, cuFFT)" OFF)
4343
cmake_dependent_option(WITH_DYNAMIC_NVJPEG "Dynamicly load nvJPEG" ON
4444
"WITH_DYNAMIC_CUDA_TOOLKIT" OFF)
4545
cmake_dependent_option(WITH_DYNAMIC_CUFFT "Dynamicly load cuFFT" ON
4646
"WITH_DYNAMIC_CUDA_TOOLKIT" OFF)
4747
cmake_dependent_option(WITH_DYNAMIC_NPP "Dynamicly load npp" ON
4848
"WITH_DYNAMIC_CUDA_TOOLKIT" OFF)
4949

50+
# TODO(janton): handle OFF option
51+
option(WITH_DYNAMIC_NVIMGCODEC "Links nvimgcodec library dynamically during runtime" ON)
52+
53+
5054
# Tests use OpenCV...
5155
cmake_dependent_option(BUILD_TEST "Build googletest test suite" ON
5256
"NOT BUILD_DALI_NODEPS" OFF)
@@ -83,6 +87,10 @@ cmake_dependent_option(BUILD_LIBTAR "Build with support for libtar library" ON
8387
option(BUILD_FFTS "Build with ffts support" ON) # Built from thirdparty sources
8488
cmake_dependent_option(BUILD_CFITSIO "Build with cfitsio support" ON
8589
"NOT BUILD_DALI_NODEPS" OFF)
90+
cmake_dependent_option(BUILD_NVIMAGECODEC "Build with support for nvimagecodec library" ON
91+
"NOT BUILD_DALI_NODEPS" OFF)
92+
set(NVIMGCODEC_DEFAULT_INSTALL_PATH "/opt/nvidia/nvimgcodec_cuda${CUDA_VERSION_MAJOR}" CACHE STRING
93+
"Path of the nvimagecodec installation")
8694

8795
cmake_dependent_option(BUILD_CVCUDA "Build with CV-CUDA" ON
8896
"NOT STATIC_LIBS" OFF) # Built from thirdparty sources; doesn't support static libs build
@@ -151,11 +159,9 @@ set(BUILD_DALI_KERNELS ON)
151159
if (BUILD_DALI_KERNELS AND NOT BUILD_DALI_NODEPS)
152160
set(BUILD_DALI_PIPELINE ON)
153161
set(BUILD_DALI_OPERATORS ON)
154-
set(BUILD_DALI_IMGCODEC ON)
155162
else()
156163
set(BUILD_DALI_PIPELINE OFF)
157164
set(BUILD_DALI_OPERATORS OFF)
158-
set(BUILD_DALI_IMGCODEC OFF)
159165
endif()
160166

161167
# Experimental, only enabled for BUILD_DALI_NODEPS=ON
@@ -297,6 +303,7 @@ propagate_option(LINK_DRIVER)
297303
propagate_option(WITH_DYNAMIC_NVJPEG)
298304
propagate_option(WITH_DYNAMIC_CUFFT)
299305
propagate_option(WITH_DYNAMIC_NPP)
306+
propagate_option(WITH_DYNAMIC_NVIMGCODEC)
300307

301308
# add more flags after they are populated by find_package from Dependencies.cmake
302309

@@ -453,7 +460,3 @@ endif()
453460
if (BUILD_DALI_OPERATORS)
454461
add_library(DALI::dali_operators ALIAS dali_operators)
455462
endif()
456-
457-
if (BUILD_DALI_IMGCODEC)
458-
add_library(DALI::dali_imgcodec ALIAS dali_imgcodec)
459-
endif()

cmake/Dependencies.common.cmake

+26-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2019-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
1+
# Copyright (c) 2019-2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.
@@ -268,3 +268,28 @@ if (BUILD_CVCUDA)
268268
check_and_add_cmake_submodule(${PROJECT_SOURCE_DIR}/third_party/cvcuda)
269269
set(BUILD_PYTHON ${DALI_BUILD_PYTHON})
270270
endif()
271+
272+
##################################################################
273+
# nvimagecodec
274+
##################################################################
275+
if(BUILD_NVIMAGECODEC)
276+
# Note: We are getting the x86_64 tarball, but we are only interested in the headers.
277+
include(FetchContent)
278+
FetchContent_Declare(
279+
nvimgcodec_headers
280+
URL https://developer.download.nvidia.com/compute/nvimgcodec/redist/nvimgcodec/linux-x86_64/nvimgcodec-linux-x86_64-0.2.0.6-archive.tar.xz
281+
URL_HASH SHA512=6577a8ff5589400cdf5767aa4a507245527a96e48065f23f626dfc6ba13b136960cacfe7f61c345dc158ed0352e1e971834aec6fd98038649b08b250c3306aeb
282+
)
283+
FetchContent_Populate(nvimgcodec_headers)
284+
set(nvimgcodec_SEARCH_PATH "${nvimgcodec_headers_SOURCE_DIR}/${CUDA_VERSION_MAJOR}/include")
285+
find_path(nvimgcodec_INCLUDE_DIR nvimgcodec.h PATHS "${nvimgcodec_SEARCH_PATH}")
286+
if (${nvimgcodec_INCLUDE_DIR} STREQUAL "nvimgcodec_INCLUDE_DIR-NOTFOUND")
287+
message(FATAL_ERROR "nvimgcodec not found in ${nvimgcodec_SEARCH_PATH} - something went wrong with the download")
288+
endif()
289+
message(STATUS "Using nvimgcodec_INCLUDE_DIR=${nvimgcodec_INCLUDE_DIR}")
290+
include_directories(SYSTEM ${nvimgcodec_INCLUDE_DIR})
291+
292+
# Setting default installation path for dynamic loading
293+
message(STATUS "NVIMGCODEC_DEFAULT_INSTALL_PATH=${NVIMGCODEC_DEFAULT_INSTALL_PATH}")
294+
add_definitions(-DNVIMGCODEC_DEFAULT_INSTALL_PATH=\"${NVIMGCODEC_DEFAULT_INSTALL_PATH}\")
295+
endif()

cmake/Install.cmake

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2020-2022, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
1+
# Copyright (c) 2020-2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.
@@ -31,10 +31,6 @@ if (BUILD_DALI_OPERATORS)
3131
list(APPEND DALI_LIBS dali_operators)
3232
endif()
3333

34-
if (BUILD_DALI_IMGCODEC)
35-
list(APPEND DALI_LIBS dali_imgcodec)
36-
endif()
37-
3834
install(TARGETS ${DALI_LIBS}
3935
ARCHIVE DESTINATION lib
4036
LIBRARY DESTINATION lib

cmake/libdali_imgcodec.map.in

-7
This file was deleted.

conda/build_conda_packages.sh

+3
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ conda mambabuild ${CONDA_BUILD_OPTIONS} third_party/dali_opencv/recipe
6060
# but wiht mpeg4_unpack_bframes enabled
6161
conda mambabuild ${CONDA_BUILD_OPTIONS} third_party/dali_ffmpeg/recipe
6262

63+
# Build nvimagecodec
64+
conda mambabuild ${CONDA_BUILD_OPTIONS} third_party/dali_nvimagecodec/recipe
65+
6366
# Building DALI core package
6467
conda mambabuild ${CONDA_BUILD_OPTIONS} dali_native_libs/recipe
6568

conda/dali_native_libs/recipe/build.sh

+3
Original file line numberDiff line numberDiff line change
@@ -86,18 +86,21 @@ cmake -DCUDA_TOOLKIT_ROOT_DIR=/usr/local/cuda \
8686
-DBUILD_CUFILE=${BUILD_CUFILE:-ON} \
8787
-DBUILD_NVCOMP=${BUILD_NVCOMP} \
8888
-DBUILD_CVCUDA=${BUILD_CVCUDA:-ON} \
89+
-DBUILD_NVIMAGECODEC=${BUILD_NVIMAGECODEC:-ON} \
8990
-DLINK_LIBCUDA=${LINK_LIBCUDA:-OFF} \
9091
-DWITH_DYNAMIC_CUDA_TOOLKIT=${WITH_DYNAMIC_CUDA_TOOLKIT:-${WITH_DYNAMIC_CUDA_TOOLKIT_DEFAULT}}\
9192
-DWITH_DYNAMIC_NVJPEG=${WITH_DYNAMIC_NVJPEG:-ON} \
9293
-DWITH_DYNAMIC_CUFFT=${WITH_DYNAMIC_CUFFT:-ON} \
9394
-DWITH_DYNAMIC_NPP=${WITH_DYNAMIC_NPP:-ON} \
95+
-DWITH_DYNAMIC_NVIMGCODEC=${WITH_DYNAMIC_NVIMGCODEC:-ON} \
9496
-DVERBOSE_LOGS=${VERBOSE_LOGS:-OFF} \
9597
-DWERROR=${WERROR:-ON} \
9698
-DBUILD_WITH_ASAN=${BUILD_WITH_ASAN:-OFF} \
9799
-DBUILD_WITH_LSAN=${BUILD_WITH_LSAN:-OFF} \
98100
-DBUILD_WITH_UBSAN=${BUILD_WITH_UBSAN:-OFF} \
99101
-DDALI_BUILD_FLAVOR=${NVIDIA_DALI_BUILD_FLAVOR} \
100102
-DTIMESTAMP=${DALI_TIMESTAMP} -DGIT_SHA=${GIT_SHA-${GIT_FULL_HASH}} \
103+
-DNVIMGCODEC_DEFAULT_INSTALL_PATH=$PREFIX/opt/nvidia/nvimgcodec \
101104
..
102105
make -j"$(nproc --all)"
103106

conda/dali_native_libs/recipe/meta.yaml

+9-5
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ build:
4444
- WITH_DYNAMIC_NVJPEG
4545
- WITH_DYNAMIC_CUFFT
4646
- WITH_DYNAMIC_NPP
47+
- WITH_DYNAMIC_NVIMGCODEC
4748
- VERBOSE_LOGS
4849
- WERROR
4950
- BUILD_WITH_ASAN
@@ -80,27 +81,30 @@ requirements:
8081
- libsndfile
8182
- libtar
8283
- libvorbis =1.3.7
83-
# dali-opencv we that depends on libtiff also depends on libwebp-base (silently)
84-
# we link it statically so it doesn't carry the dependency, so we need to add it manually
84+
# dali-opencv silently depends on openjpeg and libwebp-base
85+
# Since we link statically, we need to add those dependencies explicitly
8586
- libwebp-base
8687
- openjpeg
8788
- cfitsio
89+
- nvidia-nvimagecodec-cuda{{ environ.get('CUDA_VERSION', '') | replace(".","") }}
8890
run:
8991
- libjpeg-turbo
9092
- lmdb
9193
- libtiff
9294
- libsndfile
9395
- libvorbis =1.3.7
94-
# dali-opencv we that depends on libtiff also depends on libwebp-base (silently)
95-
# we link it statically so it doesn't carry the dependency, so we need to add it manually
96+
# dali-opencv silently depends on openjpeg and libwebp-base
97+
# Since we link statically, we need to add those dependencies explicitly
9698
- libwebp-base
99+
- openjpeg
97100
# libprotobuf-static we link statically depends on libabseil so add protobuf here as a runtime
98101
# dependency to install the right version on the libabseil (as protobuf depends on
99102
# libprotobuf-static and a newer version of libprotobuf-static may be available than
100103
# the protobuf was build with)
101104
- protobuf >=3.6.1
102-
- openjpeg
103105
- cfitsio
106+
- nvidia-nvimagecodec-cuda{{ environ.get('CUDA_VERSION', '') | replace(".","") }}
107+
104108
about:
105109
home: https://github.com/NVIDIA/DALI
106110
license: Apache-2.0 license

conda/dali_python_bindings/recipe/build.sh

+1
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ cmake -DCUDA_TOOLKIT_ROOT_DIR=/usr/local/cuda \
8989
-DBUILD_CUFILE=${BUILD_CUFILE:-ON} \
9090
-DBUILD_NVCOMP=${BUILD_NVCOMP} \
9191
-DBUILD_CVCUDA=${BUILD_CVCUDA:-ON} \
92+
-DBUILD_NVIMAGECODEC=${BUILD_NVIMAGECODEC:-ON} \
9293
-DLINK_LIBCUDA=${LINK_LIBCUDA:-OFF} \
9394
-DWITH_DYNAMIC_CUDA_TOOLKIT=${WITH_DYNAMIC_CUDA_TOOLKIT:-${WITH_DYNAMIC_CUDA_TOOLKIT_DEFAULT}}\
9495
-DWITH_DYNAMIC_NVJPEG=${WITH_DYNAMIC_NVJPEG:-ON} \

conda/dali_python_bindings/recipe/meta.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -86,13 +86,15 @@ requirements:
8686
- gast >=0.3.3
8787
- dm-tree >=0.1.8
8888
- nvidia-dali-core{% if environ.get('NVIDIA_DALI_BUILD_FLAVOR', '')|length %}{{"-" + environ.get('NVIDIA_DALI_BUILD_FLAVOR', '')}}{% endif %}-cuda{{ environ.get('CUDA_VERSION', '') | replace(".","") }} ={{ environ.get('DALI_CONDA_BUILD_VERSION', '') }}
89+
- nvidia-nvimagecodec-cuda{{ environ.get('CUDA_VERSION', '') | replace(".","") }}
8990
run:
9091
- python
9192
- future
9293
- astunparse >=1.6.0
9394
- gast >=0.3.3
9495
- dm-tree >=0.1.8
9596
- nvidia-dali-core{% if environ.get('NVIDIA_DALI_BUILD_FLAVOR', '')|length %}{{"-" + environ.get('NVIDIA_DALI_BUILD_FLAVOR', '')}}{% endif %}-cuda{{ environ.get('CUDA_VERSION', '') | replace(".","") }} ={{ environ.get('DALI_CONDA_BUILD_VERSION', '') }}
97+
- nvidia-nvimagecodec-cuda{{ environ.get('CUDA_VERSION', '') | replace(".","") }}
9698
about:
9799
home: https://github.com/NVIDIA/DALI
98100
license: Apache-2.0 license
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#!/bin/bash -ex
2+
#
3+
# SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
4+
# SPDX-License-Identifier: Apache-2.0
5+
#
6+
# Licensed under the Apache License, Version 2.0 (the "License");
7+
# you may not use this file except in compliance with the License.
8+
# You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
18+
#Determine Architecture
19+
ARCH="$(arch)"
20+
if [ ${ARCH} = "x86_64" ]; then
21+
ARCH_LONGNAME="x86_64-conda_cos6"
22+
elif [ ${ARCH} = "ppc64le" ]; then
23+
ARCH_LONGNAME="powerpc64le-conda_cos7"
24+
else
25+
echo "Error: Unsupported Architecture. Expected: [x86_64|ppc64le] Actual: ${ARCH}"
26+
exit 1
27+
fi
28+
29+
# Create 'gcc' and 'g++' symlinks so nvcc can find it
30+
ln -s $CC $BUILD_PREFIX/bin/gcc
31+
ln -s $CXX $BUILD_PREFIX/bin/g++
32+
33+
# Force -std=c++17 in CXXFLAGS
34+
export CXXFLAGS=${CXXFLAGS/-std=c++??/-std=c++17}
35+
export PATH=/usr/local/cuda/bin:${PATH}
36+
37+
cd $SRC_DIR
38+
39+
# Create build directory for cmake and enter it
40+
mkdir $SRC_DIR/build
41+
cd $SRC_DIR/build
42+
# Build
43+
cmake -DCMAKE_PREFIX_PATH=${PREFIX}/opt/nvidia/nvimgcodec \
44+
-DCMAKE_INSTALL_PREFIX=${PREFIX}/opt/nvidia/nvimgcodec \
45+
-DCUDA_TARGET_ARCHS=${CUDA_TARGET_ARCHS} \
46+
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE:-Release} \
47+
-DTIMESTAMP=${TIMESTAMP} \
48+
-DGIT_SHA=${GIT_SHA} \
49+
-DBUILD_PYTHON=OFF \
50+
-DBUILD_DOCS=OFF \
51+
..
52+
make -j"$(nproc --all)"
53+
make install
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Copyright (c) 2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
16+
{% set build_version = "0.2.0" %}
17+
18+
package:
19+
name: nvidia-nvimagecodec-cuda{{ environ.get('CUDA_VERSION', '') | replace(".","") }}
20+
version: {{ build_version }}
21+
22+
source:
23+
git_url: https://github.com/NVIDIA/nvImageCodec.git
24+
git_rev: v0.2.0
25+
26+
build:
27+
number: 0
28+
string: dali_nvimagecodec
29+
30+
requirements:
31+
build:
32+
skip: True # [not linux]
33+
- {{ compiler('c') }}
34+
- {{ compiler('cxx')}}
35+
- pkg-config
36+
- cmake >=3.18
37+
- make
38+
- python-clang
39+
- git-lfs
40+
host:
41+
- libjpeg-turbo
42+
- libtiff
43+
- dali-opencv
44+
# dali-opencv silently depends on openjpeg and libwebp-base
45+
# Since we link statically, we need to add those dependencies explicitly
46+
- libwebp-base
47+
- openjpeg
48+
49+
run:
50+
- libjpeg-turbo
51+
- libtiff
52+
# dali-opencv silently depends on openjpeg and libwebp-base
53+
# Since we link statically, we need to add those dependencies explicitly
54+
- libwebp-base
55+
- openjpeg

0 commit comments

Comments
 (0)