Skip to content

Fix building DALI with TRITON_DALI_SKIP_DOWNLOAD=ON #222

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ message(STATUS "Build configuration: " ${CMAKE_BUILD_TYPE})
# projects included in this one by FetchContent.
#
option(TRITON_DALI_SKIP_DOWNLOAD "Don't download DALI. Use the version provided in the system" OFF)
option(TRITON_DALI_BUILD_IN_TRITON "Turn this option on, if the DALI Backend is built inside Triton docker container." OFF)
option(TRITON_ENABLE_GPU "Enable GPU support in backend" ON)
option(TRITON_ENABLE_STATS "Include statistics collections in backend" ON)
option(WERROR "Trigger error on warnings" OFF)
Expand Down
12 changes: 7 additions & 5 deletions cmake/dali.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -20,28 +20,30 @@
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

# Using DALI's installed whl, find the location of DALI libs and DALI include dirs
function(get_dali_paths DALI_INCLUDE_DIR_VAR DALI_LIB_DIR_VAR DALI_LIBRARIES_VAR)
function(get_dali_paths PYTHON_BINARY DALI_INCLUDE_DIR_VAR DALI_LIB_DIR_VAR DALI_LIBRARIES_VAR)

execute_process(
COMMAND python3 -c "import nvidia.dali as dali; print(dali.sysconfig.get_include_dir())"
COMMAND ${PYTHON_BINARY} -c "import nvidia.dali as dali; print(dali.sysconfig.get_include_dir())"
OUTPUT_VARIABLE DALI_INCLUDE_DIR
RESULT_VARIABLE INCLUDE_DIR_RESULT)
string(STRIP ${DALI_INCLUDE_DIR} DALI_INCLUDE_DIR)

if (${INCLUDE_DIR_RESULT} EQUAL "1")
message(FATAL_ERROR "Failed to get include paths for DALI. Make sure that DALI is installed.")
endif ()

string(STRIP ${DALI_INCLUDE_DIR} DALI_INCLUDE_DIR)

execute_process(
COMMAND python3 -c "import nvidia.dali as dali; print(dali.sysconfig.get_lib_dir())"
COMMAND ${PYTHON_BINARY} -c "import nvidia.dali as dali; print(dali.sysconfig.get_lib_dir())"
OUTPUT_VARIABLE DALI_LIB_DIR
RESULT_VARIABLE LIB_DIR_RESULT)
string(STRIP ${DALI_LIB_DIR} DALI_LIB_DIR)

if (${LIB_DIR_RESULT} EQUAL "1")
message(FATAL_ERROR "Failed to get library paths for DALI. Make sure that DALI is installed.")
endif ()

string(STRIP ${DALI_LIB_DIR} DALI_LIB_DIR)

set(${DALI_INCLUDE_DIR_VAR} ${DALI_INCLUDE_DIR} PARENT_SCOPE)
set(${DALI_LIB_DIR_VAR} ${DALI_LIB_DIR} PARENT_SCOPE)
set(${DALI_LIBRARIES_VAR} dali dali_core dali_kernels dali_operators PARENT_SCOPE)
Expand Down
1 change: 1 addition & 0 deletions docker/Dockerfile.devel
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ RUN mkdir build_in_ci && cd build_in_ci && \
-D CMAKE_BUILD_TYPE=Debug \
-D TRITON_BACKEND_API_VERSION=${TRITON_BACKEND_API_VERSION} \
-D TRITON_DALI_SKIP_DOWNLOAD=ON \
-D TRITON_DALI_BUILD_IN_TRITON=ON \
.. && \
make -j"$(grep ^processor /proc/cpuinfo | wc -l)" install

Expand Down
2 changes: 2 additions & 0 deletions docker/Dockerfile.release
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ RUN set -ex && mkdir build_in_ci && cd build_in_ci &&
-D DALI_EXTRA_INDEX_URL=${DALI_DOWNLOAD_EXTRA_INDEX_URL}} \
-D DALI_VERSION=${DALI_DOWNLOAD_VERSION} \
-D DALI_DOWNLOAD_EXTRA_OPTIONS="${DALI_DOWNLOAD_EXTRA_OPTIONS}" \
-D TRITON_DALI_SKIP_DOWNLOAD=OFF \
-D TRITON_DALI_BUILD_IN_TRITON=ON \
.. && \
make -j"$(grep ^processor /proc/cpuinfo | wc -l)" install

Expand Down
13 changes: 10 additions & 3 deletions src/dali_executor/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ endif()

configure_file(${tritondalibackend_SOURCE_DIR}/cmake/dalienv.yml.in dalienv.yml @ONLY)

set(CONDA_ENV_PREFIX ${CMAKE_INSTALL_PREFIX}/backends/dali/conda/envs)
set(CONDA_ENV_PATH ${CONDA_ENV_PREFIX}/dalienv)

add_custom_command(
OUTPUT dali_env
COMMAND
Expand All @@ -48,7 +51,11 @@ add_custom_command(
)

if(${TRITON_DALI_SKIP_DOWNLOAD})
get_dali_paths(DALI_INCLUDE_DIR DALI_LIB_DIR DALI_LIBRARIES)
if(${TRITON_DALI_BUILD_IN_TRITON})
get_dali_paths("${CONDA_ENV_PATH}/bin/python3" DALI_INCLUDE_DIR DALI_LIB_DIR DALI_LIBRARIES)
else()
get_dali_paths("python3" DALI_INCLUDE_DIR DALI_LIB_DIR DALI_LIBRARIES)
endif()
else()
set(DALI_INCLUDE_DIR ${CMAKE_CURRENT_BINARY_DIR}/dalienv/lib/python${PYTHON_VERSION}/site-packages/nvidia/dali/include)
set(DALI_LIB_DIR ${CMAKE_CURRENT_BINARY_DIR}/dalienv/lib/python${PYTHON_VERSION}/site-packages/nvidia/dali)
Expand Down Expand Up @@ -84,7 +91,7 @@ target_link_libraries(dali_executor PUBLIC

target_compile_definitions(dali_executor PUBLIC)
if (NOT ${TRITON_DALI_SKIP_DOWNLOAD})
install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/dalienv
DESTINATION ${CMAKE_INSTALL_PREFIX}/backends/dali/conda/envs
install(DIRECTORY ${CONDA_ENV_PATH}
DESTINATION ${CONDA_ENV_PREFIX}
USE_SOURCE_PERMISSIONS)
endif ()