Skip to content

Commit

Permalink
Merge commit for internal changes
Browse files Browse the repository at this point in the history
 - 02f2c8f - CUDA 9.0 Toolkit is no longer required for pre-built binaries @cliffwoolley
 - 696d5ff - Make only API functions exposed. @JanuszL
 - 26ce6ac - Rework ABI compatibility @cliffwoolley
 - e320b7e - Namespace prefix C API @cliffwoolley
 - 71c7eb7 - logging.warn() is obsolete @cliffwoolley
 - 7bca211 - Fix crash when no files are loaded by reader @JanuszL
 - 9e4cdab - Test importing DALI simultaneously w/ every framework @cliffwoolley
  • Loading branch information
cliffwoolley committed Jun 28, 2018
1 parent 276d045 commit 6d13bc6
Show file tree
Hide file tree
Showing 52 changed files with 618 additions and 405 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ latex
valgrind-out.txt
**/.ipynb_checkpoints
.dockerignore
wheelhouse
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/modules)
include(cmake/Dependencies.cmake)

# CXX flags
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Wno-unused-variable -Wno-unused-function -fno-strict-aliasing -O2 -fPIC")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Wno-unused-variable -Wno-unused-function -fno-strict-aliasing -O2 -fPIC -fvisibility=hidden")

# Add ptx & bin flags for cuda
set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS} \
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#########################################################################################
## Stage 2: build DALI wheels using manylinux1 (CentOS 5 derivative)
## Stage 2: build DALI wheels on top of the dependencies image built in Stage 1
#########################################################################################
ARG DEPS_IMAGE_NAME
FROM ${DEPS_IMAGE_NAME}
Expand Down
22 changes: 18 additions & 4 deletions Dockerfile.deps
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
#########################################################################################
## Stage 1: build DALI dependencies using manylinux1 (CentOS 5 derivative)
## Stage 1: build DALI dependencies
## We would prefer to use publicly maintained manylinux1 (CentOS 5 derivative), but
## there are CXX11 ABI problems with the rh-devtoolset2 included with it, so we
## have switched to a "manylinux3" base that is just a minimally altered manylinux1
## built from CentOS 7 (w/ devtoolset3) instead of CentOS 5. You can switch back
## to manylinux1 (or any other base you like) by changing FROM_IMAGE_NAME below
## or by passing an argument of the form `--build-arg FROM_IMAGE_NAME=myimage:mytag`
## to `docker build -f Dockerfile.deps ... .`
#########################################################################################
FROM quay.io/pypa/manylinux1_x86_64
#ARG FROM_IMAGE_NAME=quay.io/pypa/manylinux1_x86_64
ARG FROM_IMAGE_NAME=gitlab-dl.nvidia.com:5005/dali/manylinux:manylinux3_x86_64
FROM ${FROM_IMAGE_NAME}

# Install yum Dependencies
RUN yum install -y zip
Expand Down Expand Up @@ -29,14 +38,17 @@ RUN PROTOBUF_VERSION=3.5.1 && \
curl -L https://github.com/google/protobuf/releases/download/v${PROTOBUF_VERSION}/protobuf-all-${PROTOBUF_VERSION}.tar.gz | tar -xzf - && \
cd /protobuf-${PROTOBUF_VERSION} && \
./autogen.sh && \
./configure --prefix=/usr/local 2>&1 > /dev/null && \
./configure CXXFLAGS="-fPIC" --prefix=/usr/local --disable-shared 2>&1 > /dev/null && \
make -j"$(grep ^processor /proc/cpuinfo | wc -l)" install 2>&1 > /dev/null && \
rm -rf /protobuf-${PROTOBUF_VERSION}

# LMDB
COPY docker/Makefile-lmdb.patch /tmp
RUN LMDB_VERSION=0.9.22 && \
git clone -b LMDB_${LMDB_VERSION} --single-branch https://github.com/LMDB/lmdb && \
cd /lmdb/libraries/liblmdb && \
patch -p3 < /tmp/Makefile-lmdb.patch && \
rm -f /tmp/Makefile-lmdb.patch && \
make -j"$(grep ^processor /proc/cpuinfo | wc -l)" install && \
rm -rf /lmdb

Expand All @@ -45,6 +57,7 @@ RUN OPENCV_VERSION=3.1.0 && \
curl -L https://github.com/opencv/opencv/archive/${OPENCV_VERSION}.tar.gz | tar -xzf - && \
cd /opencv-${OPENCV_VERSION} && \
cmake -DCMAKE_BUILD_TYPE=RELEASE -DCMAKE_INSTALL_PREFIX=/usr/local \
-DBUILD_SHARED_LIBS=OFF \
-DWITH_CUDA=OFF -DWITH_1394=OFF -DWITH_IPP=OFF -DWITH_OPENCL=OFF -DWITH_GTK=OFF \
-DBUILD_DOCS=OFF -DBUILD_TESTS=OFF -DBUILD_PERF_TESTS=OFF \
-DBUILD_opencv_cudalegacy=OFF -DBUILD_opencv_stitching=OFF . && \
Expand Down Expand Up @@ -77,9 +90,10 @@ RUN CUDA_VERSION=9.0 && \

# NVJPEG
RUN NVJPEG_VERSION=9.0 && \
NVJPEG_BUILD=9.0.462 && \
curl -L https://developer.download.nvidia.com/compute/redist/libnvjpeg/cuda-linux64-nvjpeg-${NVJPEG_VERSION}.tar.gz | tar -xzf - && \
cd /cuda-linux64-nvjpeg/ && \
mv lib64/libnvjpeg.so* /usr/local/lib/ && \
mv lib64/libnvjpeg*.a* /usr/local/lib/ && \
mv include/nvjpeg.h /usr/local/include/ && \
rm -rf /cuda-linux64-nvjpeg

Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ Note: DALI v0.1 is a pre-release software, which means certain features may not

## Prerequisities

* Linux
* [NVIDIA CUDA 9.0](https://developer.nvidia.com/cuda-downloads)
* Linux x64
* [NVIDIA Driver](https://www.nvidia.com/drivers) supporting [CUDA 9.0](https://developer.nvidia.com/cuda-downloads) or later
- This corresponds to 384.xx and later driver releases.
* DALI can work with any of the following Deep Learning frameworks:
- [MXNet](http://mxnet.incubator.apache.org)
- Version 1.3 beta is required, `mxnet-cu90==1.3.0b20180612` or later
Expand Down
43 changes: 31 additions & 12 deletions cmake/Dependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,32 @@
find_package(CUDA REQUIRED)
include_directories(${CUDA_INCLUDE_DIRS})
list(APPEND DALI_LIBS ${CUDA_LIBRARIES})
list(APPEND DALI_EXCLUDES libcudart_static.a)

# For NVJPEG
find_package(NVJPEG REQUIRED)
include_directories(SYSTEM ${NVJPEG_INCLUDE_DIRS})
list(APPEND DALI_LIBS ${NVJPEG_LIBRARY})
list(APPEND DALI_EXCLUDES libnvjpeg_static.a)

# For NPP
find_cuda_helper_libs(nppicom)
find_cuda_helper_libs(nppicc)
find_cuda_helper_libs(nppc)
find_cuda_helper_libs(nppig)
list(APPEND DALI_LIBS ${CUDA_nppicom_LIBRARY}
${CUDA_nppicc_LIBRARY}
${CUDA_nppc_LIBRARY}
${CUDA_nppig_LIBRARY})
find_cuda_helper_libs(nppc_static)
find_cuda_helper_libs(nppicom_static)
find_cuda_helper_libs(nppicc_static)
find_cuda_helper_libs(nppig_static)
list(APPEND DALI_LIBS ${CUDA_nppc_static_LIBRARY}
${CUDA_nppicom_static_LIBRARY}
${CUDA_nppicc_static_LIBRARY}
${CUDA_nppig_static_LIBRARY})
list(APPEND DALI_EXCLUDES libnppc_static.a
libnppicom_static.a
libnppicc_static.a
libnppig_static.a)

# CULIBOS needed when using static CUDA libs
find_cuda_helper_libs(culibos)
list(APPEND DALI_LIBS ${CUDA_culibos_LIBRARY})
list(APPEND DALI_EXCLUDES libculibos.a)

# NVTX for profiling
if (BUILD_NVTX)
Expand All @@ -21,10 +37,6 @@ if (BUILD_NVTX)
add_definitions(-DDALI_USE_NVTX)
endif()

find_package(NVJPEG REQUIRED)
include_directories(SYSTEM ${NVJPEG_INCLUDE_DIRS})
list(APPEND DALI_LIBS ${NVJPEG_LIBRARY})

# Google C++ testing framework
if (BUILD_TEST)
set(BUILD_GTEST ON CACHE INTERNAL "Builds gtest submodule")
Expand All @@ -44,6 +56,7 @@ endif()
find_package(JpegTurbo REQUIRED)
include_directories(SYSTEM ${JPEG_TURBO_INCLUDE_DIR})
list(APPEND DALI_LIBS ${JPEG_TURBO_LIBRARY})
list(APPEND DALI_EXCLUDES libturbojpeg.a)

# OpenCV
# Note: OpenCV 3.* 'imdecode()' is in the imgcodecs library
Expand All @@ -60,6 +73,7 @@ if (OpenCV_FOUND)
endif()
include_directories(SYSTEM ${OpenCV_INCLUDE_DIRS})
list(APPEND DALI_LIBS ${OpenCV_LIBRARIES})
list(APPEND DALI_EXCLUDES libopencv_core.a;libopencv_imgproc.a;libopencv_imgcodecs.a)

# PyBind
if (BUILD_PYTHON)
Expand All @@ -75,6 +89,7 @@ if (BUILD_LMDB)
message(STATUS "Found LMDB ${LMDB_INCLUDE_DIR} : ${LMDB_LIBRARIES}")
include_directories(SYSTEM ${LMDB_INCLUDE_DIR})
list(APPEND DALI_LIBS ${LMDB_LIBRARIES})
list(APPEND DALI_EXCLUDES liblmdb.a)
else()
message(STATUS "LMDB not found")
endif()
Expand All @@ -95,6 +110,10 @@ if (PROTOBUF_FOUND)
endif()
include_directories(SYSTEM ${PROTOBUF_INCLUDE_DIRS})
list(APPEND DALI_LIBS ${PROTOBUF_LIBRARY})
################
### Don't exclude protobuf symbols; doing so will lead to segfaults
#list(APPEND DALI_EXCLUDES libprotobuf.a)
################
else()
message(STATUS "Protobuf not found")
endif()
4 changes: 4 additions & 0 deletions cmake/libdali.map
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
DALI_0.1.1 {
global:
*;
};
2 changes: 1 addition & 1 deletion cmake/modules/FindNVJPEG.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ find_path(NVJPEG_INCLUDE_DIR nvjpeg.h
PATHS ${NVJPEG_ROOT_DIR}
PATH_SUFFIXES include)

find_library(NVJPEG_LIBRARY libnvjpeg.so nvjpeg
find_library(NVJPEG_LIBRARY libnvjpeg_static.a nvjpeg
PATHS ${NVJPEG_ROOT_DIR}
PATH_SUFFIXES lib lib64)

Expand Down
85 changes: 50 additions & 35 deletions dali/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,43 +18,57 @@ set(DALI_TEST_SRCS)
set(DALI_BENCHMARK_SRCS)
set(DALI_TF_SRCS)

# Build the library
################################################
# Build libdali
################################################
add_subdirectory(image)
add_subdirectory(pipeline)
add_subdirectory(util)
add_subdirectory(plugin)
add_subdirectory(c_api)

# Collect files in this directory
file(GLOB tmp *.cc)
set(DALI_SRCS ${DALI_SRCS} ${tmp})

set(dali_lib "dali")

if (BUILD_TENSORFLOW)
set(customop_lib "dali_tf")
endif()
# Collect source files for dali
file(GLOB tmp *.cc)
set(DALI_SRCS ${DALI_SRCS} ${tmp})

set(DALI_PROTO_OBJ $<TARGET_OBJECTS:DALI_PROTO>)

if (BUILD_LMDB)
list(APPEND DALI_PROTO_OBJ $<TARGET_OBJECTS:CAFFE_PROTO> $<TARGET_OBJECTS:CAFFE2_PROTO>)
endif()

if (BUILD_PROTO3)
list(APPEND DALI_PROTO_OBJ $<TARGET_OBJECTS:TF_PROTO>)
endif()

# cuda_add_library(${dali_lib} SHARED ${DALI_SRCS} $<TARGET_OBJECTS:CAFFE_PROTO> $<TARGET_OBJECTS:CAFFE2_PROTO> $<TARGET_OBJECTS:TF_PROTO> $<TARGET_OBJECTS:DALI_PROTO>)
set(CUDA_LINK_LIBRARIES_KEYWORD PRIVATE)
cuda_add_library(${dali_lib} SHARED ${DALI_SRCS} ${DALI_PROTO_OBJ})
target_link_libraries(${dali_lib} ${DALI_LIBS})

# Add install rules
# Define symbol version script for libdali.so
set(exports_map_path "${PROJECT_SOURCE_DIR}/cmake")
set(dali_lib_exports "lib${dali_lib}.map")
target_link_libraries(${dali_lib} PRIVATE -Wl,--version-script=${exports_map_path}/${dali_lib_exports})
add_custom_target(${dali_lib_exports} DEPENDS "${exports_map_path}/${dali_lib_exports}")
add_dependencies(${dali_lib} ${dali_lib_exports})

# Exclude (most) statically linked dali dependencies from the exports of libdali.so
string(REPLACE ";" ":" exclude_libs "${DALI_EXCLUDES}")
message(STATUS "Exclude libs '${exclude_libs}'")
target_link_libraries(${dali_lib} PRIVATE "-Wl,--exclude-libs,${exclude_libs}")

# Link in dali's dependencies
message(STATUS "Adding dependencies to ${dali_lib}: '${DALI_LIBS}'")
target_link_libraries(${dali_lib} PRIVATE ${DALI_LIBS})

# libdali installation paths
install(TARGETS ${dali_lib} DESTINATION lib)
install(DIRECTORY ${CMAKE_CURRENT_LIST_DIR} DESTINATION
include FILES_MATCHING PATTERN "*.h" PATTERN "*_test.h" EXCLUDE)


################################################
# Build test suite
################################################
if (BUILD_TEST)
# get all test srcs
add_subdirectory(test)
Expand All @@ -63,16 +77,20 @@ if (BUILD_TEST)
cuda_add_executable(${test_main_bin} "${DALI_TEST_SRCS}")

# Link to the dali lib
message(STATUS "Adding dependencies to ${test_main_bin}: '${dali_lib}'")
add_dependencies(${test_main_bin} ${dali_lib})

# We'll have to add dependency libs
target_link_libraries(${test_main_bin} ${DALI_LIBS} ${dali_lib} gtest)
target_link_libraries(${test_main_bin} PRIVATE ${DALI_LIBS} ${dali_lib} gtest)

set_target_properties(${test_main_bin} PROPERTIES
RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/dali/python/nvidia/dali/test)
endif()


################################################
# Build benchmark suite
################################################
if (BUILD_BENCHMARK)
# get benchmark main
add_subdirectory(benchmark)
Expand All @@ -81,53 +99,50 @@ if (BUILD_BENCHMARK)
cuda_add_executable(${benchmark_bin} "${DALI_BENCHMARK_SRCS}")

# Link to the dali lib
message(STATUS "Adding dependencies to ${benchmark_bin}: '${dali_lib}'")
add_dependencies(${benchmark_bin} ${dali_lib})

target_link_libraries(${benchmark_bin} ${DALI_LIBS} ${dali_lib} benchmark pthread)
target_link_libraries(${benchmark_bin} PRIVATE ${DALI_LIBS} ${dali_lib} benchmark pthread)

set_target_properties(${benchmark_bin} PROPERTIES
RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/dali/python/nvidia/dali/test)
endif()

# Build the python bindings
if (BUILD_PYTHON)
# Get all python srcs
add_subdirectory(python)
endif()

################################################
# Build the TensorFlow op
################################################
if (BUILD_TENSORFLOW)
# Get the TF compile et linking flags
#execute_process(
# COMMAND python -c "from __future__ import print_function; import tensorflow as tf; print(\" \".join(tf.sysconfig.get_compile_flags()), end=\"\")"
# OUTPUT_VARIABLE TF_CFLAGS)

#execute_process(
# COMMAND python -c "from __future__ import print_function; import tensorflow as tf; print(\" \".join(tf.sysconfig.get_link_flags()), end=\"\")"
# OUTPUT_VARIABLE TF_LFLAGS)

execute_process(
COMMAND python -c "from __future__ import print_function; import sys; paths = sys.path; f = [p for p in paths if \"-packages\" in p] ; print(f[0], end=\"\")"
OUTPUT_VARIABLE DIST_PACKAGES_DIR)

add_subdirectory(tensorflow)

#set(customop_lib "dali_tf")
cuda_add_library(${customop_lib} SHARED ${DALI_TF_SRCS})
set(customop_lib "dali_tf")

# TF <= 1.3
# target_compile_options(${customop_lib} PRIVATE -D_GLIBCXX_USE_CXX11_ABI=0 -I${TF_INC} -I${TF_INC}/external/nsync/public -lcudart -L /usr/local/cuda/lib64 -L${TF_LIB} -ltensorflow_framework)
cuda_add_library(${customop_lib} SHARED ${DALI_TF_SRCS})

separate_arguments(TF_CFLAGS UNIX_COMMAND "-I${DIST_PACKAGES_DIR}/tensorflow/include -D_GLIBCXX_USE_CXX11_ABI=0")
target_compile_options(${customop_lib} PRIVATE ${TF_CFLAGS})

message(STATUS "Adding dependencies to ${customop_lib}: '${dali_lib}'")
add_dependencies(${customop_lib} ${dali_lib})

target_link_libraries(${customop_lib} -L${DIST_PACKAGES_DIR}/tensorflow)
target_link_libraries(${customop_lib} -ltensorflow_framework)
target_link_libraries(${customop_lib} ${DALI_LIBS} ${dali_lib})
target_link_libraries(${customop_lib} PRIVATE -L${DIST_PACKAGES_DIR}/tensorflow -ltensorflow_framework)
target_link_libraries(${customop_lib} PRIVATE ${dali_lib})

set_target_properties(${customop_lib} PROPERTIES
LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/dali/python/nvidia/dali/plugin")
endif()


################################################
# Build the DALI python bindings
################################################
if (BUILD_PYTHON)
# Get all python srcs
add_subdirectory(python)
endif()

Loading

0 comments on commit 6d13bc6

Please sign in to comment.