Skip to content

Commit

Permalink
Replace OneDPL with TBB in ParallelScan.h
Browse files Browse the repository at this point in the history
IPP version check for directory layout
TBB linking is still WIP
Attempt with FetchContent.
  • Loading branch information
ssheorey committed Jun 9, 2024
1 parent 419a241 commit e52a208
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 327 deletions.
27 changes: 4 additions & 23 deletions 3rdparty/find_dependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -1550,9 +1550,9 @@ if(BUILD_SYCL_MODULE)
endif()

if(BUILD_SYCL_MODULE)
option(OPEN3D_USE_ONEAPI_PACKAGES "Use the oneAPI distribution of MKL/TBB/DPL." ON)
option(OPEN3D_USE_ONEAPI_PACKAGES "Use the oneAPI distribution of MKL/TBB." ON)
else()
option(OPEN3D_USE_ONEAPI_PACKAGES "Use the oneAPI distribution of MKL/TBB/DPL." OFF)
option(OPEN3D_USE_ONEAPI_PACKAGES "Use the oneAPI distribution of MKL/TBB." OFF)
endif()
mark_as_advanced(OPEN3D_USE_ONEAPI_PACKAGES)

Expand All @@ -1565,17 +1565,7 @@ if(OPEN3D_USE_ONEAPI_PACKAGES)
)
list(APPEND Open3D_3RDPARTY_PRIVATE_TARGETS_FROM_SYSTEM Open3D::3rdparty_tbb)

# 2. oneDPL
# /opt/intel/oneapi/dpl/latest/lib/cmake/oneDPL
open3d_find_package_3rdparty_library(3rdparty_onedpl
PACKAGE oneDPL
TARGETS oneDPL
)
target_compile_definitions(3rdparty_onedpl INTERFACE _GLIBCXX_USE_TBB_PAR_BACKEND=0)
target_compile_definitions(3rdparty_onedpl INTERFACE PSTL_USE_PARALLEL_POLICIES=0)
list(APPEND Open3D_3RDPARTY_PRIVATE_TARGETS_FROM_SYSTEM Open3D::3rdparty_onedpl)

# 3. oneMKL
# 2. oneMKL
# /opt/intel/oneapi/mkl/latest/lib/cmake/mkl
set(MKL_THREADING tbb_thread)
set(MKL_LINK static)
Expand Down Expand Up @@ -1612,16 +1602,6 @@ else(OPEN3D_USE_ONEAPI_PACKAGES)
list(APPEND Open3D_3RDPARTY_PRIVATE_TARGETS_FROM_SYSTEM Open3D::3rdparty_tbb)
endif()

# parallelstl
include(${Open3D_3RDPARTY_DIR}/parallelstl/parallelstl.cmake)
open3d_import_3rdparty_library(3rdparty_parallelstl
PUBLIC
INCLUDE_DIRS ${PARALLELSTL_INCLUDE_DIRS}
INCLUDE_ALL
DEPENDS ext_parallelstl
)
list(APPEND Open3D_3RDPARTY_PUBLIC_TARGETS_FROM_SYSTEM Open3D::3rdparty_parallelstl)

# MKL/BLAS
if(USE_BLAS)
if (USE_SYSTEM_BLAS)
Expand Down Expand Up @@ -1846,6 +1826,7 @@ if (WITH_IPP)
LIB_DIR ${IPP_LIB_DIR}
DEPENDS ext_ipp
)
target_compile_definitions(3rdparty_ipp INTERFACE IPP_VERSION_INT=${IPP_VERSION_INT})
list(APPEND Open3D_3RDPARTY_PRIVATE_TARGETS_FROM_SYSTEM Open3D::3rdparty_ipp)
endif()
endif()
Expand Down
12 changes: 9 additions & 3 deletions 3rdparty/ipp/ipp.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@
# - IPP_INCLUDE_DIR
# - IPP_LIBRARIES
# - IPP_LIB_DIR
# - IPP_VERSION_STRING
# - IPP_VERSION_INT (for version check)

include(ExternalProject)

# Check in order APPLE -> WIN32 -> UNIX, since UNIX may be defined on APPLE / WIN32 as well
set(IPP_VERSION_STRING "2021.11.0") # From ipp/ippversion.h
set(IPP_VERSION_INT 20211100)
if(APPLE AND CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL x86_64)
set(IPP_VERSION_STRING "2021.9.1") # From ipp/ippversion.h
set(IPP_VERSION_INT 20210901)
set(IPP_URL "https://github.com/isl-org/open3d_downloads/releases/download/mkl-static-2024.1/ipp_static-2021.9.1-macosx_10_15_x86_64.tar.xz")
set(IPP_HASH "f27e45da604a1f6d1d2a747a0f67ffafeaff084b0f860a963d8c3996e2f40bb3")
elseif(WIN32 AND CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL AMD64)
Expand All @@ -24,10 +28,8 @@ else()
endif()

if(WIN32)
set(TL mt_tl_tbb)
set(IPP_SUBPATH "Library/")
else()
set(TL _tl_tbb)
set(IPP_SUBPATH "")
endif()

Expand All @@ -48,5 +50,9 @@ set(IPP_INCLUDE_DIR "${SOURCE_DIR}/${IPP_SUBPATH}include/")
# https://www.intel.com/content/www/us/en/docs/ipp/developer-guide-reference/2021-11/ipp-performace-benefits-with-tl-functions.html
# Library dependency order:
# https://www.intel.com/content/www/us/en/docs/ipp/developer-guide-reference/2021-11/library-dependencies-by-domain.html
set(IPP_LIBRARIES ipp_iw ippcv${TL} ippcv ippi${TL} ippi ippcc${TL} ippcc ipps ippvm ippcore${TL} ippcore)
if (WIN32)
set(IPP_LIBRARIES ipp_iw ippcvmt_tl_tbb ippcvmt ippimt_tl_tbb ippimt ippccmt_tl_tbb ippccmt ippsmt ippvmmt ippcoremt_tl_tbb ippcoremt)
else()
set(IPP_LIBRARIES ipp_iw ippcv_tl_tbb ippcv ippi_tl_tbb ippi ippcc_tl_tbb ippcc ipps ippvm ippcore_tl_tbb ippcore)
endif()
set(IPP_LIB_DIR "${SOURCE_DIR}/${IPP_SUBPATH}lib")
26 changes: 13 additions & 13 deletions 3rdparty/mkl/tbb.cmake
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
# TBB build scripts.
#
# - TBB_INCLUDE_DIR
# - TBB_LIB_DIR
# - TBB_LIBRARIES

include(ExternalProject)

# Where MKL and TBB headers and libs will be installed.
# This needs to be consistent with mkl.cmake.
set(MKL_INSTALL_PREFIX ${CMAKE_BINARY_DIR}/mkl_install)
set(STATIC_MKL_INCLUDE_DIR "${MKL_INSTALL_PREFIX}/include/")
set(STATIC_MKL_INCLUDE_DIR "${MKL_INSTALL_PREFIX}/${Open3D_INSTALL_INCLUDE_DIR}/")
set(STATIC_MKL_LIB_DIR "${MKL_INSTALL_PREFIX}/${Open3D_INSTALL_LIB_DIR}")

# TBB variables exported for PyTorch Ops and TensorFlow Ops
set(TBB_INCLUDE_DIR "${STATIC_MKL_INCLUDE_DIR}")
set(TBB_LIB_DIR "${STATIC_MKL_LIB_DIR}")
set(TBB_RUNTIME_DIR "${MKL_INSTALL_PREFIX}/${Open3D_INSTALL_BIN_DIR}")
set(TBB_LIBRARIES tbb tbbmalloc)

ExternalProject_Add(
Expand All @@ -31,23 +28,26 @@ ExternalProject_Add(
-DTBBMALLOC_PROXY_BUILD=OFF
-DTBB_TEST=OFF
-DCMAKE_INSTALL_LIBDIR=${Open3D_INSTALL_LIB_DIR}
-DCMAKE_INSTALL_BINDIR=${Open3D_INSTALL_BIN_DIR}
${ExternalProject_CMAKE_ARGS}
BUILD_BYPRODUCTS
${TBB_LIB_DIR}/${CMAKE_SHARED_LIBRARY_PREFIX}tbb${CMAKE_SHARED_LIBRARY_SUFFIX}
${TBB_LIB_DIR}/${CMAKE_SHARED_LIBRARY_PREFIX}tbbmalloc${CMAKE_SHARED_LIBRARY_SUFFIX}
)
set(__TBB_BINARY_VERSION 12) # from tbb/version.h

# TBB is built and linked as a shared library - this is different from all other Open3D dependencies.
add_library(3rdparty_tbb INTERFACE)
target_include_directories(3rdparty_tbb SYSTEM INTERFACE $<BUILD_INTERFACE:${TBB_INCLUDE_DIR}>)
set(TBB_LIBRARIES_PATH "")
foreach(TBB_LIBRARY IN LISTS TBB_LIBRARIES)
file(REAL_PATH ${CMAKE_SHARED_LIBRARY_PREFIX}${TBB_LIBRARY}${CMAKE_SHARED_LIBRARY_SUFFIX}
TBB_LIBRARY_PATH BASE_DIRECTORY ${TBB_LIB_DIR})
list(APPEND TBB_LIBRARIES_PATH ${TBB_LIBRARY_PATH})
endforeach()
target_link_libraries(3rdparty_tbb INTERFACE ${TBB_LIBRARIES_PATH})
add_dependencies(3rdparty_tbb ext_tbb)
add_library(${PROJECT_NAME}::3rdparty_tbb ALIAS 3rdparty_tbb)
if (WIN32)
set(TBB_LIBRARIES_PATH "${TBB_LIB_DIR}/tbb${__TBB_BINARY_VERSION}.lib;${TBB_LIB_DIR}/tbbmalloc.lib")
set(TBB_RUNTIMES_PATH "${TBB_RUNTIME_DIR}/tbb${__TBB_BINARY_VERSION}.dll;${TBB_RUNTIME_DIR}/tbbmalloc.dll")
install(FILES ${TBB_RUNTIMES_PATH} DESTINATION ${Open3D_INSTALL_BIN_DIR})
else()
set(TBB_LIBRARIES_PATH "${TBB_LIB_DIR}/${CMAKE_SHARED_LIBRARY_PREFIX}tbb${CMAKE_SHARED_LIBRARY_SUFFIX};${TBB_LIB_DIR}/${CMAKE_SHARED_LIBRARY_PREFIX}tbbmalloc${CMAKE_SHARED_LIBRARY_SUFFIX}")
endif()
target_link_libraries(3rdparty_tbb INTERFACE ${TBB_LIBRARIES_PATH})
install(TARGETS 3rdparty_tbb EXPORT ${PROJECT_NAME}Targets)
install(FILES ${TBB_LIBRARIES_PATH} DESTINATION ${Open3D_INSTALL_LIB_DIR})
add_library(${PROJECT_NAME}::3rdparty_tbb ALIAS 3rdparty_tbb)
33 changes: 33 additions & 0 deletions 3rdparty/mkl/tbb.fetccontent.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# TBB build scripts.

include(FetchContent)
cmake_policy(SET CMP0077 NEW)

# Where MKL and TBB headers and libs will be installed.
# This needs to be consistent with mkl.cmake.
set(MKL_INSTALL_PREFIX ${CMAKE_BINARY_DIR}/mkl_install)
set(STATIC_MKL_INCLUDE_DIR "${MKL_INSTALL_PREFIX}/${Open3D_INSTALL_INCLUDE_DIR}/")
set(STATIC_MKL_LIB_DIR "${MKL_INSTALL_PREFIX}/${Open3D_INSTALL_LIB_DIR}")

# TBB variables exported for PyTorch Ops and TensorFlow Ops
set(TBB_INCLUDE_DIR "${STATIC_MKL_INCLUDE_DIR}")
set(TBB_LIB_DIR "${STATIC_MKL_LIB_DIR}")
set(TBB_RUNTIME_DIR "${MKL_INSTALL_PREFIX}/${Open3D_INSTALL_BIN_DIR}")
set(TBB_LIBRARIES tbb tbbmalloc)

FetchContent_Declare(
3rdparty_tbb
URL https://github.com/oneapi-src/oneTBB/archive/refs/tags/v2021.12.0.tar.gz # April 2024
URL_HASH SHA256=c7bb7aa69c254d91b8f0041a71c5bcc3936acb64408a1719aec0b2b7639dd84f
DOWNLOAD_DIR "${OPEN3D_THIRD_PARTY_DOWNLOAD_DIR}/tbb"
)
set(TBBMALLOC_BUILD ON CACHE BOOL "Build TBB malloc library.")
set(TBBMALLOC_PROXY_BUILD OFF CACHE BOOL "Build TBB malloc proxy library.")
set(TBB_TEST OFF CACHE BOOL "Build TBB tests.")
FetchContent_MakeAvailable(3rdparty_tbb)

# TBB is built and linked as a shared library - this is different from all other Open3D dependencies.
install(TARGETS 3rdparty_tbb EXPORT ${PROJECT_NAME}Targets
LIBRARY DESTINATION ${Open3D_INSTALL_LIB_DIR}
RUNTIME DESTINATION ${Open3D_INSTALL_BIN_DIR})
add_library(${PROJECT_NAME}::3rdparty_tbb ALIAS 3rdparty_tbb)
Loading

0 comments on commit e52a208

Please sign in to comment.