From ed912c5c39adb11c43d4d28bf785d9fc8326de4c Mon Sep 17 00:00:00 2001 From: Siarhei Fedartsou Date: Fri, 19 Aug 2022 21:24:04 +0200 Subject: [PATCH 01/14] Migrate to modern TBB version --- .github/workflows/osrm-backend.yml | 25 +- CHANGELOG.md | 1 + CMakeLists.txt | 30 +- cmake/FindTBB.cmake | 720 +++++++++++------- example/cmake/FindTBB.cmake | 284 +------ include/util/packed_vector.hpp | 24 +- src/contractor/contractor.cpp | 10 - src/customize/customizer.cpp | 9 - src/extractor/edge_based_graph_factory.cpp | 19 +- src/extractor/extractor.cpp | 36 +- src/guidance/guidance_processing.cpp | 15 +- src/partitioner/partitioner.cpp | 10 - src/partitioner/recursive_bisection.cpp | 6 +- unit_tests/contractor/graph_contractor.cpp | 10 - .../partitioner/recursive_bisection.cpp | 5 - unit_tests/util/static_rtree.cpp | 5 - 16 files changed, 529 insertions(+), 680 deletions(-) mode change 100644 => 120000 example/cmake/FindTBB.cmake diff --git a/.github/workflows/osrm-backend.yml b/.github/workflows/osrm-backend.yml index 4addd056473..2d93b798cc9 100644 --- a/.github/workflows/osrm-backend.yml +++ b/.github/workflows/osrm-backend.yml @@ -198,7 +198,7 @@ jobs: CXXCOMPILER: g++-9 CXXFLAGS: -Wno-cast-function-type - - name: gcc-9-release-i686 + - name: gcc-9-conan-release-i686 continue-on-error: false node: 12 runs-on: ubuntu-20.04 @@ -209,7 +209,8 @@ jobs: CXXCOMPILER: g++-9 CXXFLAGS: "-m32 -msse2 -mfpmath=sse" TARGET_ARCH: i686 - + ENABLE_CONAN: ON + - name: gcc-8-release continue-on-error: false node: 12 @@ -413,7 +414,6 @@ jobs: ENABLE_CONAN: ON NODE_PACKAGE_TESTS_ONLY: ON - name: ${{ matrix.name}} continue-on-error: ${{ matrix.continue-on-error }} runs-on: ${{ matrix.runs-on }} @@ -510,10 +510,6 @@ jobs: wget --quiet -O - ${CMAKE_URL} | tar --strip-components=1 -xz -C ${CMAKE_DIR} echo "${CMAKE_DIR}/bin" >> $GITHUB_PATH - # TBB - ${MASON} install tbb 2017_U7 - echo "LD_LIBRARY_PATH=$(${MASON} prefix tbb 2017_U7)/lib/:${LD_LIBRARY_PATH}" >> $GITHUB_ENV - # ccache ${MASON} install ccache ${CCACHE_VERSION} echo "$(${MASON} prefix ccache ${CCACHE_VERSION})/bin" >> $GITHUB_PATH @@ -537,7 +533,7 @@ jobs: if [ "${TARGET_ARCH}" != "i686" ] && [ "${ENABLE_CONAN}" != "ON" ]; then sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y sudo apt-get update -y - sudo apt-get install -y libbz2-dev libxml2-dev libzip-dev liblua5.2-dev libtbb-dev libboost-all-dev + sudo apt-get install -y libbz2-dev libxml2-dev libzip-dev liblua5.2-dev libboost-all-dev if [[ -z "${CLANG_VERSION}" ]]; then sudo apt-get install -y ${CXXCOMPILER} fi @@ -549,6 +545,18 @@ jobs: echo "PKG_CONFIG_PATH=/usr/lib/i386-linux-gnu/pkgconfig:${PKG_CONFIG_PATH}" >> $GITHUB_ENV fi + # TBB + TBB_VERSION=2021.3.0 + if [[ "${RUNNER_OS}" == "Linux" ]]; then + TBB_URL="https://github.com/oneapi-src/oneTBB/releases/download/v${TBB_VERSION}/oneapi-tbb-${TBB_VERSION}-lin.tgz" + elif [[ "${RUNNER_OS}" == "macOS" ]]; then + TBB_URL="https://github.com/oneapi-src/oneTBB/releases/download/v${TBB_VERSION}/oneapi-tbb-${TBB_VERSION}-mac.tgz" + fi + wget --tries 5 ${TBB_URL} -O onetbb.tgz + tar zxvf onetbb.tgz + sudo cp -a oneapi-tbb-${TBB_VERSION}/lib/. /usr/local/lib/ + sudo cp -a oneapi-tbb-${TBB_VERSION}/include/. /usr/local/include/ + - name: Prepare build run: | mkdir ${OSRM_BUILD_DIR} @@ -564,6 +572,7 @@ jobs: run: | echo "Using ${JOBS} jobs" pushd ${OSRM_BUILD_DIR} + cmake .. -DCMAKE_BUILD_TYPE=${BUILD_TYPE} \ -DENABLE_CONAN=${ENABLE_CONAN:-OFF} \ -DENABLE_ASSERTIONS=${ENABLE_ASSERTIONS:-OFF} \ diff --git a/CHANGELOG.md b/CHANGELOG.md index d9ed1703ec7..850687ec9b7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ - FIXED: Fix bug with reading Set values from Lua scripts. [#6285](https://github.com/Project-OSRM/osrm-backend/pull/6285) - FIXED: Bug in bicycle profile that caused exceptions if there is a highway=bicycle in the data. [#6296](https://github.com/Project-OSRM/osrm-backend/pull/6296) - Build: + - CHANGED: Migrate to modern TBB version. [#6300](https://github.com/Project-OSRM/osrm-backend/pull/6300) - CHANGED: Use the latest node on CI. [#6317](https://github.com/Project-OSRM/osrm-backend/pull/6317) - CHANGED: Migrate Windows CI to GitHub Actions. [#6312](https://github.com/Project-OSRM/osrm-backend/pull/6312) - ADDED: Add smoke test for Docker image. [#6313](https://github.com/Project-OSRM/osrm-backend/pull/6313) diff --git a/CMakeLists.txt b/CMakeLists.txt index 41875bbef0f..df6e9a4c0c0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -463,26 +463,17 @@ if(ENABLE_CONAN) set(CONAN_BZIP2_VERSION 1.0.8) set(CONAN_EXPAT_VERSION 2.2.10) set(CONAN_LUA_VERSION 5.4.4) - set(CONAN_TBB_VERSION 2020.3) + set(CONAN_TBB_VERSION 2021.3.0) set(CONAN_SYSTEM_INCLUDES ON) - - # TODO: - # if we link TBB dynamically osrm-extract.exe finishes on the first access to any TBB symbol - # with exit code = -1073741515, which means that program cannot load required DLL. - if (MSVC) - set(TBB_SHARED False) - else() - set(TBB_SHARED True) - endif() - conan_cmake_run( + set(CONAN_ARGS REQUIRES boost/${CONAN_BOOST_VERSION} bzip2/${CONAN_BZIP2_VERSION} expat/${CONAN_EXPAT_VERSION} lua/${CONAN_LUA_VERSION} - tbb/${CONAN_TBB_VERSION} + onetbb/${CONAN_TBB_VERSION} BASIC_SETUP BUILD missing GENERATORS cmake_find_package @@ -491,6 +482,12 @@ if(ENABLE_CONAN) OPTIONS boost:filesystem_version=3 # https://stackoverflow.com/questions/73392648/error-with-boost-filesystem-version-in-cmake tbb:shared=${TBB_SHARED} ) + # explicitly say Conan to use x86 dependencies if build for x86 platforms (https://github.com/conan-io/cmake-conan/issues/141) + if(NOT CMAKE_SIZEOF_VOID_P EQUAL 8) + conan_cmake_run("${CONAN_ARGS} ARCH x86") + else() + conan_cmake_run("${CONAN_ARGS}") + endif() add_dependency_includes(${CONAN_INCLUDE_DIRS_BOOST}) add_dependency_includes(${CONAN_INCLUDE_DIRS_BZIP2}) @@ -511,6 +508,7 @@ if(ENABLE_CONAN) set(Boost_REGEX_LIBRARY "${Boost_regex_LIB_TARGETS}") set(Boost_UNIT_TEST_FRAMEWORK_LIBRARY "${Boost_unit_test_framework_LIB_TARGETS}") + find_package(BZip2 REQUIRED) find_package(EXPAT REQUIRED) find_package(lua REQUIRED) @@ -533,9 +531,7 @@ else() find_package(TBB REQUIRED) add_dependency_includes(${TBB_INCLUDE_DIR}) - if(WIN32) - set(TBB_LIBRARIES optimized ${TBB_LIBRARY} optimized ${TBB_MALLOC_LIBRARY} debug ${TBB_LIBRARY_DEBUG} debug ${TBB_MALLOC_LIBRARY_DEBUG}) - endif() + set(TBB_LIBRARIES TBB::tbb) find_package(EXPAT REQUIRED) add_dependency_includes(${EXPAT_INCLUDE_DIRS}) @@ -809,9 +805,9 @@ JOIN("-I${DEPENDENCIES_INCLUDE_DIRS}" " -I" PKGCONFIG_OSRM_INCLUDE_FLAGS) # Boost uses imported targets, we need to use a generator expression to extract # the link libraries to be written to the pkg-config file. -# Conan defines dependencies as CMake targets too, that's why we do the same for them. +# Conan & TBB define dependencies as CMake targets too, that's why we do the same for them. foreach(engine_lib ${ENGINE_LIBRARIES}) - if("${engine_lib}" MATCHES "^Boost.*" OR "${engine_lib}" MATCHES "^CONAN_LIB.*") + if("${engine_lib}" MATCHES "^Boost.*" OR "${engine_lib}" MATCHES "^CONAN_LIB.*" OR "${engine_lib}" MATCHES "^TBB.*") list(APPEND PKGCONFIG_DEPENDENT_LIBRARIES "$") else() list(APPEND PKGCONFIG_DEPENDENT_LIBRARIES "${engine_lib}") diff --git a/cmake/FindTBB.cmake b/cmake/FindTBB.cmake index 09ba1655549..ca5a792ae40 100644 --- a/cmake/FindTBB.cmake +++ b/cmake/FindTBB.cmake @@ -1,286 +1,456 @@ -# Locate Intel Threading Building Blocks include paths and libraries -# FindTBB.cmake can be found at https://code.google.com/p/findtbb/ -# Written by Hannes Hofmann -# Improvements by Gino van den Bergen , -# Florian Uhlig , -# Jiri Marsik - -# The MIT License +# - Find ThreadingBuildingBlocks include dirs and libraries +# Use this module by invoking find_package with the form: +# find_package(TBB +# [REQUIRED] # Fail with error if TBB is not found +# ) # +# Once done, this will define # -# Copyright (c) 2011 Hannes Hofmann +# TBB_FOUND - system has TBB +# TBB_INCLUDE_DIRS - the TBB include directories +# TBB_LIBRARIES - TBB libraries to be lined, doesn't include malloc or +# malloc proxy +# TBB::tbb - imported target for the TBB library # -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: +# TBB_VERSION_MAJOR - Major Product Version Number +# TBB_VERSION_MINOR - Minor Product Version Number +# TBB_INTERFACE_VERSION - Engineering Focused Version Number +# TBB_COMPATIBLE_INTERFACE_VERSION - The oldest major interface version +# still supported. This uses the engineering +# focused interface version numbers. # -# The above copyright notice and this permission notice shall be included in -# all copies or substantial portions of the Software. +# TBB_MALLOC_FOUND - system has TBB malloc library +# TBB_MALLOC_INCLUDE_DIRS - the TBB malloc include directories +# TBB_MALLOC_LIBRARIES - The TBB malloc libraries to be lined +# TBB::malloc - imported target for the TBB malloc library # -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -# THE SOFTWARE. - -# GvdB: This module uses the environment variable TBB_ARCH_PLATFORM which defines architecture and compiler. -# e.g. "ia32/vc8" or "em64t/cc4.1.0_libc2.4_kernel2.6.16.21" -# TBB_ARCH_PLATFORM is set by the build script tbbvars[.bat|.sh|.csh], which can be found -# in the TBB installation directory (TBB_INSTALL_DIR). +# TBB_MALLOC_PROXY_FOUND - system has TBB malloc proxy library +# TBB_MALLOC_PROXY_INCLUDE_DIRS = the TBB malloc proxy include directories +# TBB_MALLOC_PROXY_LIBRARIES - The TBB malloc proxy libraries to be lined +# TBB::malloc_proxy - imported target for the TBB malloc proxy library # -# GvdB: Mac OS X distribution places libraries directly in lib directory. # -# For backwards compatibility, you may explicitely set the CMake variables TBB_ARCHITECTURE and TBB_COMPILER. -# TBB_ARCHITECTURE [ ia32 | em64t | itanium ] -# which architecture to use -# TBB_COMPILER e.g. vc9 or cc3.2.3_libc2.3.2_kernel2.4.21 or cc4.0.1_os10.4.9 -# which compiler to use (detected automatically on Windows) - -# This module respects -# TBB_INSTALL_DIR or $ENV{TBB21_INSTALL_DIR} or $ENV{TBB_INSTALL_DIR} - -# This module defines -# TBB_INCLUDE_DIRS, where to find task_scheduler_init.h, etc. -# TBB_LIBRARY_DIRS, where to find libtbb, libtbbmalloc -# TBB_DEBUG_LIBRARY_DIRS, where to find libtbb_debug, libtbbmalloc_debug -# TBB_INSTALL_DIR, the base TBB install directory -# TBB_LIBRARIES, the libraries to link against to use TBB. -# TBB_DEBUG_LIBRARIES, the libraries to link against to use TBB with debug symbols. -# TBB_FOUND, If false, don't try to use TBB. -# TBB_INTERFACE_VERSION, as defined in tbb/tbb_stddef.h - - -if (WIN32) - # has em64t/vc8 em64t/vc9 - # has ia32/vc7.1 ia32/vc8 ia32/vc9 - set(_TBB_DEFAULT_INSTALL_DIR "C:/Program Files/Intel/TBB") - set(_TBB_LIB_NAME "tbb") - set(_TBB_LIB_MALLOC_NAME "${_TBB_LIB_NAME}malloc") - set(_TBB_LIB_DEBUG_NAME "${_TBB_LIB_NAME}_debug") - set(_TBB_LIB_MALLOC_DEBUG_NAME "${_TBB_LIB_MALLOC_NAME}_debug") - if (MSVC71) - set (_TBB_COMPILER "vc7.1") - endif(MSVC71) - if (MSVC80) - set(_TBB_COMPILER "vc8") - endif(MSVC80) - if (MSVC90) - set(_TBB_COMPILER "vc9") - endif(MSVC90) - if(MSVC10) - set(_TBB_COMPILER "vc10") - endif(MSVC10) - # Todo: add other Windows compilers such as ICL. - set(_TBB_ARCHITECTURE ${TBB_ARCHITECTURE}) -endif (WIN32) - -if (UNIX) - if (APPLE) - # MAC - set(_TBB_DEFAULT_INSTALL_DIR "/Library/Frameworks/Intel_TBB.framework/Versions") - # libs: libtbb.dylib, libtbbmalloc.dylib, *_debug - set(_TBB_LIB_NAME "tbb") - set(_TBB_LIB_MALLOC_NAME "${_TBB_LIB_NAME}malloc") - set(_TBB_LIB_DEBUG_NAME "${_TBB_LIB_NAME}_debug") - set(_TBB_LIB_MALLOC_DEBUG_NAME "${_TBB_LIB_MALLOC_NAME}_debug") - # default flavor on apple: ia32/cc4.0.1_os10.4.9 - # Jiri: There is no reason to presume there is only one flavor and - # that user's setting of variables should be ignored. - if(NOT TBB_COMPILER) - set(_TBB_COMPILER "cc4.0.1_os10.4.9") - elseif (NOT TBB_COMPILER) - set(_TBB_COMPILER ${TBB_COMPILER}) - endif(NOT TBB_COMPILER) - if(NOT TBB_ARCHITECTURE) - set(_TBB_ARCHITECTURE "ia32") - elseif(NOT TBB_ARCHITECTURE) - set(_TBB_ARCHITECTURE ${TBB_ARCHITECTURE}) - endif(NOT TBB_ARCHITECTURE) - else (APPLE) - # LINUX - set(_TBB_DEFAULT_INSTALL_DIR "/usr") - set(_TBB_LIB_NAME "tbb") - set(_TBB_LIB_MALLOC_NAME "${_TBB_LIB_NAME}malloc") - set(_TBB_LIB_DEBUG_NAME "${_TBB_LIB_NAME}_debug") - set(_TBB_LIB_MALLOC_DEBUG_NAME "${_TBB_LIB_MALLOC_NAME}_debug") - # has em64t/cc3.2.3_libc2.3.2_kernel2.4.21 em64t/cc3.3.3_libc2.3.3_kernel2.6.5 em64t/cc3.4.3_libc2.3.4_kernel2.6.9 em64t/cc4.1.0_libc2.4_kernel2.6.16.21 - # has ia32/* - # has itanium/* - set(_TBB_COMPILER ${TBB_COMPILER}) - set(_TBB_ARCHITECTURE ${TBB_ARCHITECTURE}) - endif (APPLE) -endif (UNIX) - -if (CMAKE_SYSTEM MATCHES "SunOS.*") -# SUN -# not yet supported -# has em64t/cc3.4.3_kernel5.10 -# has ia32/* -endif (CMAKE_SYSTEM MATCHES "SunOS.*") - - -#-- Clear the public variables -set (TBB_FOUND "NO") - - -#-- Find TBB install dir and set ${_TBB_INSTALL_DIR} and cached ${TBB_INSTALL_DIR} -# first: use CMake variable TBB_INSTALL_DIR -if (TBB_INSTALL_DIR) - set (_TBB_INSTALL_DIR ${TBB_INSTALL_DIR}) -endif (TBB_INSTALL_DIR) -# second: use environment variable -if (NOT _TBB_INSTALL_DIR) - if (NOT "$ENV{TBB_INSTALL_DIR}" STREQUAL "") - set (_TBB_INSTALL_DIR $ENV{TBB_INSTALL_DIR}) - endif (NOT "$ENV{TBB_INSTALL_DIR}" STREQUAL "") - # Intel recommends setting TBB21_INSTALL_DIR - if (NOT "$ENV{TBB21_INSTALL_DIR}" STREQUAL "") - set (_TBB_INSTALL_DIR $ENV{TBB21_INSTALL_DIR}) - endif (NOT "$ENV{TBB21_INSTALL_DIR}" STREQUAL "") - if (NOT "$ENV{TBB22_INSTALL_DIR}" STREQUAL "") - set (_TBB_INSTALL_DIR $ENV{TBB22_INSTALL_DIR}) - endif (NOT "$ENV{TBB22_INSTALL_DIR}" STREQUAL "") - if (NOT "$ENV{TBB30_INSTALL_DIR}" STREQUAL "") - set (_TBB_INSTALL_DIR $ENV{TBB30_INSTALL_DIR}) - endif (NOT "$ENV{TBB30_INSTALL_DIR}" STREQUAL "") -endif (NOT _TBB_INSTALL_DIR) -# third: try to find path automatically -if (NOT _TBB_INSTALL_DIR) - if (_TBB_DEFAULT_INSTALL_DIR) - set (_TBB_INSTALL_DIR ${_TBB_DEFAULT_INSTALL_DIR}) - endif (_TBB_DEFAULT_INSTALL_DIR) -endif (NOT _TBB_INSTALL_DIR) -# sanity check -if (NOT _TBB_INSTALL_DIR) - message ("ERROR: Unable to find Intel TBB install directory. ${_TBB_INSTALL_DIR}") -else (NOT _TBB_INSTALL_DIR) -# finally: set the cached CMake variable TBB_INSTALL_DIR -if (NOT TBB_INSTALL_DIR) - set (TBB_INSTALL_DIR ${_TBB_INSTALL_DIR} CACHE PATH "Intel TBB install directory") - mark_as_advanced(TBB_INSTALL_DIR) -endif (NOT TBB_INSTALL_DIR) - - -#-- A macro to rewrite the paths of the library. This is necessary, because -# find_library() always found the em64t/vc9 version of the TBB libs -macro(TBB_CORRECT_LIB_DIR var_name) -# if (NOT "${_TBB_ARCHITECTURE}" STREQUAL "em64t") - string(REPLACE em64t "${_TBB_ARCHITECTURE}" ${var_name} ${${var_name}}) -# endif (NOT "${_TBB_ARCHITECTURE}" STREQUAL "em64t") - string(REPLACE ia32 "${_TBB_ARCHITECTURE}" ${var_name} ${${var_name}}) - string(REPLACE vc7.1 "${_TBB_COMPILER}" ${var_name} ${${var_name}}) - string(REPLACE vc8 "${_TBB_COMPILER}" ${var_name} ${${var_name}}) - string(REPLACE vc9 "${_TBB_COMPILER}" ${var_name} ${${var_name}}) - string(REPLACE vc10 "${_TBB_COMPILER}" ${var_name} ${${var_name}}) -endmacro(TBB_CORRECT_LIB_DIR var_content) - - -#-- Look for include directory and set ${TBB_INCLUDE_DIR} -set (TBB_INC_SEARCH_DIR ${_TBB_INSTALL_DIR}/include) -# Jiri: tbbvars now sets the CPATH environment variable to the directory -# containing the headers. +# This module reads hints about search locations from variables: +# ENV TBB_ARCH_PLATFORM - for eg. set it to "mic" for Xeon Phi builds +# ENV TBB_ROOT or just TBB_ROOT - root directory of tbb installation +# ENV TBB_BUILD_PREFIX - specifies the build prefix for user built tbb +# libraries. Should be specified with ENV TBB_ROOT +# and optionally... +# ENV TBB_BUILD_DIR - if build directory is different than ${TBB_ROOT}/build +# +# +# Modified by Robert Maynard from the original OGRE source +# +#------------------------------------------------------------------- +# This file is part of the CMake build system for OGRE +# (Object-oriented Graphics Rendering Engine) +# For the latest info, see http://www.ogre3d.org/ +# +# The contents of this file are placed in the public domain. Feel +# free to make use of it in any way you like. +#------------------------------------------------------------------- +# +#============================================================================= +# Copyright 2010-2012 Kitware, Inc. +# Copyright 2012 Rolf Eike Beer +# +# Distributed under the OSI-approved BSD License (the "License"); +# see accompanying file Copyright.txt for details. +# +# This software is distributed WITHOUT ANY WARRANTY; without even the +# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the License for more information. +#============================================================================= +# (To distribute this file outside of CMake, substitute the full +# License text for the above reference.) + + +#============================================================================= +# FindTBB helper functions and macros +# + +# Use TBBConfig.cmake if possible. + +set(_tbb_find_quiet) +if (TBB_FIND_QUIETLY) + set(_tbb_find_quiet QUIET) +endif () +set(_tbb_find_components) +set(_tbb_find_optional_components) +foreach (_tbb_find_component IN LISTS TBB_FIND_COMPONENTS) + if (TBB_FIND_REQUIRED_${_tbb_find_component}) + list(APPEND _tbb_find_components "${_tbb_find_component}") + else () + list(APPEND _tbb_find_optional_components "${_tbb_find_component}") + endif () +endforeach () +unset(_tbb_find_component) +find_package(TBB CONFIG ${_tbb_find_quiet} + COMPONENTS ${_tbb_find_components} + OPTIONAL_COMPONENTS ${_tbb_find_optional_components}) +unset(_tbb_find_quiet) +unset(_tbb_find_components) +unset(_tbb_find_optional_components) +if (TBB_FOUND) + return () +endif () + +#==================================================== +# Fix the library path in case it is a linker script +#==================================================== +function(tbb_extract_real_library library real_library) + if(NOT UNIX OR NOT EXISTS ${library}) + set(${real_library} "${library}" PARENT_SCOPE) + return() + endif() + + #Read in the first 4 bytes and see if they are the ELF magic number + set(_elf_magic "7f454c46") + file(READ ${library} _hex_data OFFSET 0 LIMIT 4 HEX) + if(_hex_data STREQUAL _elf_magic) + #we have opened a elf binary so this is what + #we should link to + set(${real_library} "${library}" PARENT_SCOPE) + return() + endif() + + file(READ ${library} _data OFFSET 0 LIMIT 1024) + if("${_data}" MATCHES "INPUT \\(([^(]+)\\)") + #extract out the .so name from REGEX MATCH command + set(_proper_so_name "${CMAKE_MATCH_1}") + + #construct path to the real .so which is presumed to be in the same directory + #as the input file + get_filename_component(_so_dir "${library}" DIRECTORY) + set(${real_library} "${_so_dir}/${_proper_so_name}" PARENT_SCOPE) + else() + #unable to determine what this library is so just hope everything works + #and pass it unmodified. + set(${real_library} "${library}" PARENT_SCOPE) + endif() +endfunction() + +#=============================================== +# Do the final processing for the package find. +#=============================================== +macro(findpkg_finish PREFIX TARGET_NAME) + if (${PREFIX}_INCLUDE_DIR AND ${PREFIX}_LIBRARY) + set(${PREFIX}_FOUND TRUE) + set (${PREFIX}_INCLUDE_DIRS ${${PREFIX}_INCLUDE_DIR}) + set (${PREFIX}_LIBRARIES ${${PREFIX}_LIBRARY}) + else () + if (${PREFIX}_FIND_REQUIRED AND NOT ${PREFIX}_FIND_QUIETLY) + message(FATAL_ERROR "Required library ${PREFIX} not found.") + endif () + endif () + + if (NOT TARGET "TBB::${TARGET_NAME}") + if (${PREFIX}_LIBRARY_RELEASE) + tbb_extract_real_library(${${PREFIX}_LIBRARY_RELEASE} real_release) + endif () + if (${PREFIX}_LIBRARY_DEBUG) + tbb_extract_real_library(${${PREFIX}_LIBRARY_DEBUG} real_debug) + endif () + add_library(TBB::${TARGET_NAME} UNKNOWN IMPORTED) + set_target_properties(TBB::${TARGET_NAME} PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${${PREFIX}_INCLUDE_DIR}") + if (${PREFIX}_LIBRARY_DEBUG AND ${PREFIX}_LIBRARY_RELEASE) + set_target_properties(TBB::${TARGET_NAME} PROPERTIES + IMPORTED_LOCATION "${real_release}" + IMPORTED_LOCATION_DEBUG "${real_debug}" + IMPORTED_LOCATION_RELEASE "${real_release}") + elseif (${PREFIX}_LIBRARY_RELEASE) + set_target_properties(TBB::${TARGET_NAME} PROPERTIES + IMPORTED_LOCATION "${real_release}") + elseif (${PREFIX}_LIBRARY_DEBUG) + set_target_properties(TBB::${TARGET_NAME} PROPERTIES + IMPORTED_LOCATION "${real_debug}") + endif () + endif () + + #mark the following variables as internal variables + mark_as_advanced(${PREFIX}_INCLUDE_DIR + ${PREFIX}_LIBRARY + ${PREFIX}_LIBRARY_DEBUG + ${PREFIX}_LIBRARY_RELEASE) +endmacro() + +#=============================================== +# Generate debug names from given release names +#=============================================== +macro(get_debug_names PREFIX) + foreach(i ${${PREFIX}}) + set(${PREFIX}_DEBUG ${${PREFIX}_DEBUG} ${i}d ${i}D ${i}_d ${i}_D ${i}_debug ${i}) + endforeach() +endmacro() + +#=============================================== +# See if we have env vars to help us find tbb +#=============================================== +macro(getenv_path VAR) + set(ENV_${VAR} $ENV{${VAR}}) + # replace won't work if var is blank + if (ENV_${VAR}) + string( REGEX REPLACE "\\\\" "/" ENV_${VAR} ${ENV_${VAR}} ) + endif () +endmacro() + +#=============================================== +# Couple a set of release AND debug libraries +#=============================================== +macro(make_library_set PREFIX) + if (${PREFIX}_RELEASE AND ${PREFIX}_DEBUG) + set(${PREFIX} optimized ${${PREFIX}_RELEASE} debug ${${PREFIX}_DEBUG}) + elseif (${PREFIX}_RELEASE) + set(${PREFIX} ${${PREFIX}_RELEASE}) + elseif (${PREFIX}_DEBUG) + set(${PREFIX} ${${PREFIX}_DEBUG}) + endif () +endmacro() + + +#============================================================================= +# Now to actually find TBB +# + +# Get path, convert backslashes as ${ENV_${var}} +getenv_path(TBB_ROOT) + +# initialize search paths +set(TBB_PREFIX_PATH ${TBB_ROOT} ${ENV_TBB_ROOT}) +set(TBB_INC_SEARCH_PATH "") +set(TBB_LIB_SEARCH_PATH "") + + +# If user built from sources +set(TBB_BUILD_PREFIX $ENV{TBB_BUILD_PREFIX}) +if (TBB_BUILD_PREFIX AND ENV_TBB_ROOT) + getenv_path(TBB_BUILD_DIR) + if (NOT ENV_TBB_BUILD_DIR) + set(ENV_TBB_BUILD_DIR ${ENV_TBB_ROOT}/build) + endif () + + # include directory under ${ENV_TBB_ROOT}/include + list(APPEND TBB_LIB_SEARCH_PATH + ${ENV_TBB_BUILD_DIR}/${TBB_BUILD_PREFIX}_release + ${ENV_TBB_BUILD_DIR}/${TBB_BUILD_PREFIX}_debug) +endif () + + +# For Windows, let's assume that the user might be using the precompiled +# TBB packages from the main website. These use a rather awkward directory +# structure (at least for automatically finding the right files) depending +# on platform and compiler, but we'll do our best to accommodate it. +# Not adding the same effort for the precompiled linux builds, though. Those +# have different versions for CC compiler versions and linux kernels which +# will never adequately match the user's setup, so there is no feasible way +# to detect the "best" version to use. The user will have to manually +# select the right files. (Chances are the distributions are shipping their +# custom version of tbb, anyway, so the problem is probably nonexistent.) +if (WIN32 AND MSVC) + set(COMPILER_PREFIX "vc7.1") + if (MSVC_VERSION EQUAL 1400) + set(COMPILER_PREFIX "vc8") + elseif(MSVC_VERSION EQUAL 1500) + set(COMPILER_PREFIX "vc9") + elseif(MSVC_VERSION EQUAL 1600) + set(COMPILER_PREFIX "vc10") + elseif(MSVC_VERSION EQUAL 1700) + set(COMPILER_PREFIX "vc11") + elseif(MSVC_VERSION EQUAL 1800) + set(COMPILER_PREFIX "vc12") + elseif(MSVC_VERSION GREATER_EQUAL 1900) + set(COMPILER_PREFIX "vc14") + endif () + + # for each prefix path, add ia32/64\${COMPILER_PREFIX}\lib to the lib search path + foreach (dir IN LISTS TBB_PREFIX_PATH) + if (CMAKE_CL_64) + list(APPEND TBB_LIB_SEARCH_PATH ${dir}/ia64/${COMPILER_PREFIX}/lib) + list(APPEND TBB_LIB_SEARCH_PATH ${dir}/lib/ia64/${COMPILER_PREFIX}) + list(APPEND TBB_LIB_SEARCH_PATH ${dir}/intel64/${COMPILER_PREFIX}/lib) + list(APPEND TBB_LIB_SEARCH_PATH ${dir}/lib/intel64/${COMPILER_PREFIX}) + else () + list(APPEND TBB_LIB_SEARCH_PATH ${dir}/ia32/${COMPILER_PREFIX}/lib) + list(APPEND TBB_LIB_SEARCH_PATH ${dir}/lib/ia32/${COMPILER_PREFIX}) + endif () + endforeach () +endif () + +# For OS X binary distribution, choose libc++ based libraries for Mavericks (10.9) +# and above and AppleClang +if (CMAKE_SYSTEM_NAME STREQUAL "Darwin" AND + NOT CMAKE_SYSTEM_VERSION VERSION_LESS 13.0) + set (USE_LIBCXX OFF) + cmake_policy(GET CMP0025 POLICY_VAR) + + if (POLICY_VAR STREQUAL "NEW") + if (CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang") + set (USE_LIBCXX ON) + endif () + else () + if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang") + set (USE_LIBCXX ON) + endif () + endif () + + if (USE_LIBCXX) + foreach (dir IN LISTS TBB_PREFIX_PATH) + list (APPEND TBB_LIB_SEARCH_PATH ${dir}/lib/libc++ ${dir}/libc++/lib) + endforeach () + endif () +endif () + +# check compiler ABI +if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") + set(COMPILER_PREFIX) + if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.8) + list(APPEND COMPILER_PREFIX "gcc4.8") + endif() + if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.7) + list(APPEND COMPILER_PREFIX "gcc4.7") + endif() + if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.4) + list(APPEND COMPILER_PREFIX "gcc4.4") + endif() + list(APPEND COMPILER_PREFIX "gcc4.1") +elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang") + set(COMPILER_PREFIX) + if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.0) # Complete guess + list(APPEND COMPILER_PREFIX "gcc4.8") + endif() + if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.6) + list(APPEND COMPILER_PREFIX "gcc4.7") + endif() + list(APPEND COMPILER_PREFIX "gcc4.4") +else() # Assume compatibility with 4.4 for other compilers + list(APPEND COMPILER_PREFIX "gcc4.4") +endif () + +# if platform architecture is explicitly specified +set(TBB_ARCH_PLATFORM $ENV{TBB_ARCH_PLATFORM}) +if (TBB_ARCH_PLATFORM) + foreach (dir IN LISTS TBB_PREFIX_PATH) + list(APPEND TBB_LIB_SEARCH_PATH ${dir}/${TBB_ARCH_PLATFORM}/lib) + list(APPEND TBB_LIB_SEARCH_PATH ${dir}/lib/${TBB_ARCH_PLATFORM}) + endforeach () +endif () + +foreach (dir IN LISTS TBB_PREFIX_PATH) + foreach (prefix IN LISTS COMPILER_PREFIX) + if (CMAKE_SIZEOF_VOID_P EQUAL 8) + list(APPEND TBB_LIB_SEARCH_PATH ${dir}/lib/intel64) + list(APPEND TBB_LIB_SEARCH_PATH ${dir}/lib/intel64/${prefix}) + list(APPEND TBB_LIB_SEARCH_PATH ${dir}/intel64/lib) + list(APPEND TBB_LIB_SEARCH_PATH ${dir}/intel64/${prefix}/lib) + else () + list(APPEND TBB_LIB_SEARCH_PATH ${dir}/lib/ia32) + list(APPEND TBB_LIB_SEARCH_PATH ${dir}/lib/ia32/${prefix}) + list(APPEND TBB_LIB_SEARCH_PATH ${dir}/ia32/lib) + list(APPEND TBB_LIB_SEARCH_PATH ${dir}/ia32/${prefix}/lib) + endif () + endforeach() +endforeach () + +# add general search paths +foreach (dir IN LISTS TBB_PREFIX_PATH) + list(APPEND TBB_LIB_SEARCH_PATH ${dir}/lib ${dir}/Lib ${dir}/lib/tbb + ${dir}/Libs) + list(APPEND TBB_INC_SEARCH_PATH ${dir}/include ${dir}/Include + ${dir}/include/tbb) +endforeach () + +set(TBB_LIBRARY_NAMES tbb) +get_debug_names(TBB_LIBRARY_NAMES) + + find_path(TBB_INCLUDE_DIR - tbb/task_scheduler_init.h - HINTS ${TBB_INC_SEARCH_DIR} ENV CPATH -) -mark_as_advanced(TBB_INCLUDE_DIR) - -#-- Look for libraries -# GvdB: $ENV{TBB_ARCH_PLATFORM} is set by the build script tbbvars[.bat|.sh|.csh] -if (NOT $ENV{TBB_ARCH_PLATFORM} STREQUAL "") - set (_TBB_LIBRARY_DIR - ${_TBB_INSTALL_DIR}/lib/$ENV{TBB_ARCH_PLATFORM} - ${_TBB_INSTALL_DIR}/$ENV{TBB_ARCH_PLATFORM}/lib - ) -endif (NOT $ENV{TBB_ARCH_PLATFORM} STREQUAL "") -# Jiri: This block isn't mutually exclusive with the previous one -# (hence no else), instead I test if the user really specified -# the variables in question. -if ((NOT ${TBB_ARCHITECTURE} STREQUAL "") AND (NOT ${TBB_COMPILER} STREQUAL "")) - # HH: deprecated - message(STATUS "[Warning] FindTBB.cmake: The use of TBB_ARCHITECTURE and TBB_COMPILER is deprecated and may not be supported in future versions. Please set \$ENV{TBB_ARCH_PLATFORM} (using tbbvars.[bat|csh|sh]).") - # Jiri: It doesn't hurt to look in more places, so I store the hints from - # ENV{TBB_ARCH_PLATFORM} and the TBB_ARCHITECTURE and TBB_COMPILER - # variables and search them both. - set (_TBB_LIBRARY_DIR "${_TBB_INSTALL_DIR}/${_TBB_ARCHITECTURE}/${_TBB_COMPILER}/lib" ${_TBB_LIBRARY_DIR}) -endif ((NOT ${TBB_ARCHITECTURE} STREQUAL "") AND (NOT ${TBB_COMPILER} STREQUAL "")) - -# GvdB: Mac OS X distribution places libraries directly in lib directory. -list(APPEND _TBB_LIBRARY_DIR ${_TBB_INSTALL_DIR}/lib) - -if(EXISTS ${_TBB_INSTALL_DIR}/build) - file(GLOB _TBB_BUILD_DIR_RELEASE ${_TBB_INSTALL_DIR}/build/*_release) - file(GLOB _TBB_BUILD_DIR_DEBUG ${_TBB_INSTALL_DIR}/build/*_debug) -endif() - -# Jiri: No reason not to check the default paths. From recent versions, -# tbbvars has started exporting the LIBRARY_PATH and LD_LIBRARY_PATH -# variables, which now point to the directories of the lib files. -# It all makes more sense to use the ${_TBB_LIBRARY_DIR} as a HINTS -# argument instead of the implicit PATHS as it isn't hard-coded -# but computed by system introspection. Searching the LIBRARY_PATH -# and LD_LIBRARY_PATH environment variables is now even more important -# that tbbvars doesn't export TBB_ARCH_PLATFORM and it facilitates -# the use of TBB built from sources. -find_library(TBB_LIBRARY ${_TBB_LIB_NAME} HINTS ${_TBB_BUILD_DIR_RELEASE} ${_TBB_LIBRARY_DIR}) -find_library(TBB_MALLOC_LIBRARY ${_TBB_LIB_MALLOC_NAME} HINTS ${_TBB_BUILD_DIR_RELEASE} ${_TBB_LIBRARY_DIR}) - -#Extract path from TBB_LIBRARY name -get_filename_component(TBB_LIBRARY_DIR ${TBB_LIBRARY} PATH) - -#TBB_CORRECT_LIB_DIR(TBB_LIBRARY) -#TBB_CORRECT_LIB_DIR(TBB_MALLOC_LIBRARY) -mark_as_advanced(TBB_LIBRARY TBB_MALLOC_LIBRARY) - -#-- Look for debug libraries -# Jiri: Changed the same way as for the release libraries. -find_library(TBB_LIBRARY_DEBUG ${_TBB_LIB_DEBUG_NAME} HINTS ${_TBB_BUILD_DIR_DEBUG} ${_TBB_LIBRARY_DIR} - PATHS ENV LIBRARY_PATH ENV LD_LIBRARY_PATH) -find_library(TBB_MALLOC_LIBRARY_DEBUG ${_TBB_LIB_MALLOC_DEBUG_NAME} HINTS ${_TBB_BUILD_DIR_DEBUG} ${_TBB_LIBRARY_DIR} - PATHS ENV LIBRARY_PATH ENV LD_LIBRARY_PATH) - -# Jiri: Self-built TBB stores the debug libraries in a separate directory. -# Extract path from TBB_LIBRARY_DEBUG name -get_filename_component(TBB_LIBRARY_DEBUG_DIR ${TBB_LIBRARY_DEBUG} PATH) - -#TBB_CORRECT_LIB_DIR(TBB_LIBRARY_DEBUG) -#TBB_CORRECT_LIB_DIR(TBB_MALLOC_LIBRARY_DEBUG) -mark_as_advanced(TBB_LIBRARY_DEBUG TBB_MALLOC_LIBRARY_DEBUG) - - -if (TBB_INCLUDE_DIR) - if (TBB_LIBRARY) - set (TBB_FOUND "YES") - set (TBB_LIBRARIES ${TBB_LIBRARY} ${TBB_MALLOC_LIBRARY} ${TBB_LIBRARIES}) - set (TBB_DEBUG_LIBRARIES ${TBB_LIBRARY_DEBUG} ${TBB_MALLOC_LIBRARY_DEBUG} ${TBB_DEBUG_LIBRARIES}) - set (TBB_INCLUDE_DIRS ${TBB_INCLUDE_DIR} CACHE PATH "TBB include directory" FORCE) - set (TBB_LIBRARY_DIRS ${TBB_LIBRARY_DIR} CACHE PATH "TBB library directory" FORCE) - # Jiri: Self-built TBB stores the debug libraries in a separate directory. - set (TBB_DEBUG_LIBRARY_DIRS ${TBB_LIBRARY_DEBUG_DIR} CACHE PATH "TBB debug library directory" FORCE) - mark_as_advanced(TBB_INCLUDE_DIRS TBB_LIBRARY_DIRS TBB_DEBUG_LIBRARY_DIRS TBB_LIBRARIES TBB_DEBUG_LIBRARIES) - message(STATUS "Found Intel TBB") - endif (TBB_LIBRARY) -endif (TBB_INCLUDE_DIR) + NAMES tbb/tbb.h + PATHS ${TBB_INC_SEARCH_PATH}) + +find_library(TBB_LIBRARY_RELEASE + NAMES ${TBB_LIBRARY_NAMES} + PATHS ${TBB_LIB_SEARCH_PATH}) +find_library(TBB_LIBRARY_DEBUG + NAMES ${TBB_LIBRARY_NAMES_DEBUG} + PATHS ${TBB_LIB_SEARCH_PATH}) +make_library_set(TBB_LIBRARY) +findpkg_finish(TBB tbb) + +#if we haven't found TBB no point on going any further if (NOT TBB_FOUND) - message("ERROR: Intel TBB NOT found!") - message(STATUS "Looked for Threading Building Blocks in ${_TBB_INSTALL_DIR}") - # do only throw fatal, if this pkg is REQUIRED - if (TBB_FIND_REQUIRED) - message(FATAL_ERROR "Could NOT find TBB library.") - endif (TBB_FIND_REQUIRED) -endif (NOT TBB_FOUND) + return() +endif () -endif (NOT _TBB_INSTALL_DIR) +#============================================================================= +# Look for TBB's malloc package +set(TBB_MALLOC_LIBRARY_NAMES tbbmalloc) +get_debug_names(TBB_MALLOC_LIBRARY_NAMES) -if (TBB_FOUND) - set(TBB_INTERFACE_VERSION 0) - FILE(READ "${TBB_INCLUDE_DIRS}/tbb/tbb_stddef.h" _TBB_VERSION_CONTENTS) - STRING(REGEX REPLACE ".*#define TBB_INTERFACE_VERSION ([0-9]+).*" "\\1" TBB_INTERFACE_VERSION "${_TBB_VERSION_CONTENTS}") - set(TBB_INTERFACE_VERSION "${TBB_INTERFACE_VERSION}") - message(STATUS "TBB interface version: ${TBB_INTERFACE_VERSION}") -endif (TBB_FOUND) +find_path(TBB_MALLOC_INCLUDE_DIR + NAMES tbb/tbb.h + PATHS ${TBB_INC_SEARCH_PATH}) + +find_library(TBB_MALLOC_LIBRARY_RELEASE + NAMES ${TBB_MALLOC_LIBRARY_NAMES} + PATHS ${TBB_LIB_SEARCH_PATH}) +find_library(TBB_MALLOC_LIBRARY_DEBUG + NAMES ${TBB_MALLOC_LIBRARY_NAMES_DEBUG} + PATHS ${TBB_LIB_SEARCH_PATH}) +make_library_set(TBB_MALLOC_LIBRARY) + +findpkg_finish(TBB_MALLOC tbbmalloc) + +#============================================================================= +# Look for TBB's malloc proxy package +set(TBB_MALLOC_PROXY_LIBRARY_NAMES tbbmalloc_proxy) +get_debug_names(TBB_MALLOC_PROXY_LIBRARY_NAMES) + +find_path(TBB_MALLOC_PROXY_INCLUDE_DIR + NAMES tbb/tbbmalloc_proxy.h + PATHS ${TBB_INC_SEARCH_PATH}) + +find_library(TBB_MALLOC_PROXY_LIBRARY_RELEASE + NAMES ${TBB_MALLOC_PROXY_LIBRARY_NAMES} + PATHS ${TBB_LIB_SEARCH_PATH}) +find_library(TBB_MALLOC_PROXY_LIBRARY_DEBUG + NAMES ${TBB_MALLOC_PROXY_LIBRARY_NAMES_DEBUG} + PATHS ${TBB_LIB_SEARCH_PATH}) +make_library_set(TBB_MALLOC_PROXY_LIBRARY) + +findpkg_finish(TBB_MALLOC_PROXY tbbmalloc_proxy) + + +#============================================================================= +#parse all the version numbers from tbb +if(NOT TBB_VERSION) + if (EXISTS "${TBB_INCLUDE_DIR}/oneapi/tbb/version.h") + file(STRINGS + "${TBB_INCLUDE_DIR}/oneapi/tbb/version.h" + TBB_VERSION_CONTENTS + REGEX "VERSION") + else() + #only read the start of the file + file(STRINGS + "${TBB_INCLUDE_DIR}/tbb/tbb_stddef.h" + TBB_VERSION_CONTENTS + REGEX "VERSION") + endif() + + string(REGEX REPLACE + ".*#define TBB_VERSION_MAJOR ([0-9]+).*" "\\1" + TBB_VERSION_MAJOR "${TBB_VERSION_CONTENTS}") + + string(REGEX REPLACE + ".*#define TBB_VERSION_MINOR ([0-9]+).*" "\\1" + TBB_VERSION_MINOR "${TBB_VERSION_CONTENTS}") + + string(REGEX REPLACE + ".*#define TBB_INTERFACE_VERSION ([0-9]+).*" "\\1" + TBB_INTERFACE_VERSION "${TBB_VERSION_CONTENTS}") + + string(REGEX REPLACE + ".*#define TBB_COMPATIBLE_INTERFACE_VERSION ([0-9]+).*" "\\1" + TBB_COMPATIBLE_INTERFACE_VERSION "${TBB_VERSION_CONTENTS}") + +endif() \ No newline at end of file diff --git a/example/cmake/FindTBB.cmake b/example/cmake/FindTBB.cmake deleted file mode 100644 index e5ca1003912..00000000000 --- a/example/cmake/FindTBB.cmake +++ /dev/null @@ -1,283 +0,0 @@ -# Locate Intel Threading Building Blocks include paths and libraries -# FindTBB.cmake can be found at https://code.google.com/p/findtbb/ -# Written by Hannes Hofmann -# Improvements by Gino van den Bergen , -# Florian Uhlig , -# Jiri Marsik - -# The MIT License -# -# Copyright (c) 2011 Hannes Hofmann -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in -# all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -# THE SOFTWARE. - -# GvdB: This module uses the environment variable TBB_ARCH_PLATFORM which defines architecture and compiler. -# e.g. "ia32/vc8" or "em64t/cc4.1.0_libc2.4_kernel2.6.16.21" -# TBB_ARCH_PLATFORM is set by the build script tbbvars[.bat|.sh|.csh], which can be found -# in the TBB installation directory (TBB_INSTALL_DIR). -# -# GvdB: Mac OS X distribution places libraries directly in lib directory. -# -# For backwards compatibility, you may explicitely set the CMake variables TBB_ARCHITECTURE and TBB_COMPILER. -# TBB_ARCHITECTURE [ ia32 | em64t | itanium ] -# which architecture to use -# TBB_COMPILER e.g. vc9 or cc3.2.3_libc2.3.2_kernel2.4.21 or cc4.0.1_os10.4.9 -# which compiler to use (detected automatically on Windows) - -# This module respects -# TBB_INSTALL_DIR or $ENV{TBB21_INSTALL_DIR} or $ENV{TBB_INSTALL_DIR} - -# This module defines -# TBB_INCLUDE_DIRS, where to find task_scheduler_init.h, etc. -# TBB_LIBRARY_DIRS, where to find libtbb, libtbbmalloc -# TBB_DEBUG_LIBRARY_DIRS, where to find libtbb_debug, libtbbmalloc_debug -# TBB_INSTALL_DIR, the base TBB install directory -# TBB_LIBRARIES, the libraries to link against to use TBB. -# TBB_DEBUG_LIBRARIES, the libraries to link against to use TBB with debug symbols. -# TBB_FOUND, If false, don't try to use TBB. -# TBB_INTERFACE_VERSION, as defined in tbb/tbb_stddef.h - - -if (WIN32) - # has em64t/vc8 em64t/vc9 - # has ia32/vc7.1 ia32/vc8 ia32/vc9 - set(_TBB_DEFAULT_INSTALL_DIR "C:/Program Files/Intel/TBB" "C:/Program Files (x86)/Intel/TBB") - set(_TBB_LIB_NAME "tbb") - set(_TBB_LIB_MALLOC_NAME "${_TBB_LIB_NAME}malloc") - set(_TBB_LIB_DEBUG_NAME "${_TBB_LIB_NAME}_debug") - set(_TBB_LIB_MALLOC_DEBUG_NAME "${_TBB_LIB_MALLOC_NAME}_debug") - if (MSVC71) - set (_TBB_COMPILER "vc7.1") - endif(MSVC71) - if (MSVC80) - set(_TBB_COMPILER "vc8") - endif(MSVC80) - if (MSVC90) - set(_TBB_COMPILER "vc9") - endif(MSVC90) - if(MSVC10) - set(_TBB_COMPILER "vc10") - endif(MSVC10) - # Todo: add other Windows compilers such as ICL. - set(_TBB_ARCHITECTURE ${TBB_ARCHITECTURE}) -endif (WIN32) - -if (UNIX) - if (APPLE) - # MAC - set(_TBB_DEFAULT_INSTALL_DIR "/Library/Frameworks/Intel_TBB.framework/Versions") - # libs: libtbb.dylib, libtbbmalloc.dylib, *_debug - set(_TBB_LIB_NAME "tbb") - set(_TBB_LIB_MALLOC_NAME "${_TBB_LIB_NAME}malloc") - set(_TBB_LIB_DEBUG_NAME "${_TBB_LIB_NAME}_debug") - set(_TBB_LIB_MALLOC_DEBUG_NAME "${_TBB_LIB_MALLOC_NAME}_debug") - # default flavor on apple: ia32/cc4.0.1_os10.4.9 - # Jiri: There is no reason to presume there is only one flavor and - # that user's setting of variables should be ignored. - if(NOT TBB_COMPILER) - set(_TBB_COMPILER "cc4.0.1_os10.4.9") - elseif (NOT TBB_COMPILER) - set(_TBB_COMPILER ${TBB_COMPILER}) - endif(NOT TBB_COMPILER) - if(NOT TBB_ARCHITECTURE) - set(_TBB_ARCHITECTURE "ia32") - elseif(NOT TBB_ARCHITECTURE) - set(_TBB_ARCHITECTURE ${TBB_ARCHITECTURE}) - endif(NOT TBB_ARCHITECTURE) - else (APPLE) - # LINUX - set(_TBB_DEFAULT_INSTALL_DIR "/opt/intel/tbb" "/usr/local/include" "/usr/include") - set(_TBB_LIB_NAME "tbb") - set(_TBB_LIB_MALLOC_NAME "${_TBB_LIB_NAME}malloc") - set(_TBB_LIB_DEBUG_NAME "${_TBB_LIB_NAME}_debug") - set(_TBB_LIB_MALLOC_DEBUG_NAME "${_TBB_LIB_MALLOC_NAME}_debug") - # has em64t/cc3.2.3_libc2.3.2_kernel2.4.21 em64t/cc3.3.3_libc2.3.3_kernel2.6.5 em64t/cc3.4.3_libc2.3.4_kernel2.6.9 em64t/cc4.1.0_libc2.4_kernel2.6.16.21 - # has ia32/* - # has itanium/* - set(_TBB_COMPILER ${TBB_COMPILER}) - set(_TBB_ARCHITECTURE ${TBB_ARCHITECTURE}) - endif (APPLE) -endif (UNIX) - -if (CMAKE_SYSTEM MATCHES "SunOS.*") -# SUN -# not yet supported -# has em64t/cc3.4.3_kernel5.10 -# has ia32/* -endif (CMAKE_SYSTEM MATCHES "SunOS.*") - - -#-- Clear the public variables -set (TBB_FOUND "NO") - - -#-- Find TBB install dir and set ${_TBB_INSTALL_DIR} and cached ${TBB_INSTALL_DIR} -# first: use CMake variable TBB_INSTALL_DIR -if (TBB_INSTALL_DIR) - set (_TBB_INSTALL_DIR ${TBB_INSTALL_DIR}) -endif (TBB_INSTALL_DIR) -# second: use environment variable -if (NOT _TBB_INSTALL_DIR) - if (NOT "$ENV{TBB_INSTALL_DIR}" STREQUAL "") - set (_TBB_INSTALL_DIR $ENV{TBB_INSTALL_DIR}) - endif (NOT "$ENV{TBB_INSTALL_DIR}" STREQUAL "") - # Intel recommends setting TBB21_INSTALL_DIR - if (NOT "$ENV{TBB21_INSTALL_DIR}" STREQUAL "") - set (_TBB_INSTALL_DIR $ENV{TBB21_INSTALL_DIR}) - endif (NOT "$ENV{TBB21_INSTALL_DIR}" STREQUAL "") - if (NOT "$ENV{TBB22_INSTALL_DIR}" STREQUAL "") - set (_TBB_INSTALL_DIR $ENV{TBB22_INSTALL_DIR}) - endif (NOT "$ENV{TBB22_INSTALL_DIR}" STREQUAL "") - if (NOT "$ENV{TBB30_INSTALL_DIR}" STREQUAL "") - set (_TBB_INSTALL_DIR $ENV{TBB30_INSTALL_DIR}) - endif (NOT "$ENV{TBB30_INSTALL_DIR}" STREQUAL "") -endif (NOT _TBB_INSTALL_DIR) -# third: try to find path automatically -if (NOT _TBB_INSTALL_DIR) - if (_TBB_DEFAULT_INSTALL_DIR) - set (_TBB_INSTALL_DIR ${_TBB_DEFAULT_INSTALL_DIR}) - endif (_TBB_DEFAULT_INSTALL_DIR) -endif (NOT _TBB_INSTALL_DIR) -# sanity check -if (NOT _TBB_INSTALL_DIR) - message ("ERROR: Unable to find Intel TBB install directory. ${_TBB_INSTALL_DIR}") -else (NOT _TBB_INSTALL_DIR) -# finally: set the cached CMake variable TBB_INSTALL_DIR -if (NOT TBB_INSTALL_DIR) - set (TBB_INSTALL_DIR ${_TBB_INSTALL_DIR} CACHE PATH "Intel TBB install directory") - mark_as_advanced(TBB_INSTALL_DIR) -endif (NOT TBB_INSTALL_DIR) - - -#-- A macro to rewrite the paths of the library. This is necessary, because -# find_library() always found the em64t/vc9 version of the TBB libs -macro(TBB_CORRECT_LIB_DIR var_name) -# if (NOT "${_TBB_ARCHITECTURE}" STREQUAL "em64t") - string(REPLACE em64t "${_TBB_ARCHITECTURE}" ${var_name} ${${var_name}}) -# endif (NOT "${_TBB_ARCHITECTURE}" STREQUAL "em64t") - string(REPLACE ia32 "${_TBB_ARCHITECTURE}" ${var_name} ${${var_name}}) - string(REPLACE vc7.1 "${_TBB_COMPILER}" ${var_name} ${${var_name}}) - string(REPLACE vc8 "${_TBB_COMPILER}" ${var_name} ${${var_name}}) - string(REPLACE vc9 "${_TBB_COMPILER}" ${var_name} ${${var_name}}) - string(REPLACE vc10 "${_TBB_COMPILER}" ${var_name} ${${var_name}}) -endmacro(TBB_CORRECT_LIB_DIR var_content) - - -#-- Look for include directory and set ${TBB_INCLUDE_DIR} -set (TBB_INC_SEARCH_DIR ${_TBB_INSTALL_DIR}/include) -# Jiri: tbbvars now sets the CPATH environment variable to the directory -# containing the headers. -find_path(TBB_INCLUDE_DIR - tbb/task_scheduler_init.h - PATHS ${TBB_INC_SEARCH_DIR} ENV CPATH -) -mark_as_advanced(TBB_INCLUDE_DIR) - - -#-- Look for libraries -# GvdB: $ENV{TBB_ARCH_PLATFORM} is set by the build script tbbvars[.bat|.sh|.csh] -if (NOT $ENV{TBB_ARCH_PLATFORM} STREQUAL "") - set (_TBB_LIBRARY_DIR - ${_TBB_INSTALL_DIR}/lib/$ENV{TBB_ARCH_PLATFORM} - ${_TBB_INSTALL_DIR}/$ENV{TBB_ARCH_PLATFORM}/lib - ) -endif (NOT $ENV{TBB_ARCH_PLATFORM} STREQUAL "") -# Jiri: This block isn't mutually exclusive with the previous one -# (hence no else), instead I test if the user really specified -# the variables in question. -if ((NOT ${TBB_ARCHITECTURE} STREQUAL "") AND (NOT ${TBB_COMPILER} STREQUAL "")) - # HH: deprecated - message(STATUS "[Warning] FindTBB.cmake: The use of TBB_ARCHITECTURE and TBB_COMPILER is deprecated and may not be supported in future versions. Please set \$ENV{TBB_ARCH_PLATFORM} (using tbbvars.[bat|csh|sh]).") - # Jiri: It doesn't hurt to look in more places, so I store the hints from - # ENV{TBB_ARCH_PLATFORM} and the TBB_ARCHITECTURE and TBB_COMPILER - # variables and search them both. - set (_TBB_LIBRARY_DIR "${_TBB_INSTALL_DIR}/${_TBB_ARCHITECTURE}/${_TBB_COMPILER}/lib" ${_TBB_LIBRARY_DIR}) -endif ((NOT ${TBB_ARCHITECTURE} STREQUAL "") AND (NOT ${TBB_COMPILER} STREQUAL "")) - -# GvdB: Mac OS X distribution places libraries directly in lib directory. -list(APPEND _TBB_LIBRARY_DIR ${_TBB_INSTALL_DIR}/lib) - -# Jiri: No reason not to check the default paths. From recent versions, -# tbbvars has started exporting the LIBRARY_PATH and LD_LIBRARY_PATH -# variables, which now point to the directories of the lib files. -# It all makes more sense to use the ${_TBB_LIBRARY_DIR} as a HINTS -# argument instead of the implicit PATHS as it isn't hard-coded -# but computed by system introspection. Searching the LIBRARY_PATH -# and LD_LIBRARY_PATH environment variables is now even more important -# that tbbvars doesn't export TBB_ARCH_PLATFORM and it facilitates -# the use of TBB built from sources. -find_library(TBB_LIBRARY ${_TBB_LIB_NAME} HINTS ${_TBB_LIBRARY_DIR} - PATHS ENV LIBRARY_PATH ENV LD_LIBRARY_PATH) -find_library(TBB_MALLOC_LIBRARY ${_TBB_LIB_MALLOC_NAME} HINTS ${_TBB_LIBRARY_DIR} - PATHS ENV LIBRARY_PATH ENV LD_LIBRARY_PATH) - -#Extract path from TBB_LIBRARY name -get_filename_component(TBB_LIBRARY_DIR ${TBB_LIBRARY} PATH) - -#TBB_CORRECT_LIB_DIR(TBB_LIBRARY) -#TBB_CORRECT_LIB_DIR(TBB_MALLOC_LIBRARY) -mark_as_advanced(TBB_LIBRARY TBB_MALLOC_LIBRARY) - -#-- Look for debug libraries -# Jiri: Changed the same way as for the release libraries. -find_library(TBB_LIBRARY_DEBUG ${_TBB_LIB_DEBUG_NAME} HINTS ${_TBB_LIBRARY_DIR} - PATHS ENV LIBRARY_PATH ENV LD_LIBRARY_PATH) -find_library(TBB_MALLOC_LIBRARY_DEBUG ${_TBB_LIB_MALLOC_DEBUG_NAME} HINTS ${_TBB_LIBRARY_DIR} - PATHS ENV LIBRARY_PATH ENV LD_LIBRARY_PATH) - -# Jiri: Self-built TBB stores the debug libraries in a separate directory. -# Extract path from TBB_LIBRARY_DEBUG name -get_filename_component(TBB_LIBRARY_DEBUG_DIR ${TBB_LIBRARY_DEBUG} PATH) - -#TBB_CORRECT_LIB_DIR(TBB_LIBRARY_DEBUG) -#TBB_CORRECT_LIB_DIR(TBB_MALLOC_LIBRARY_DEBUG) -mark_as_advanced(TBB_LIBRARY_DEBUG TBB_MALLOC_LIBRARY_DEBUG) - - -if (TBB_INCLUDE_DIR) - if (TBB_LIBRARY) - set (TBB_FOUND "YES") - set (TBB_LIBRARIES ${TBB_LIBRARY} ${TBB_MALLOC_LIBRARY} ${TBB_LIBRARIES}) - set (TBB_DEBUG_LIBRARIES ${TBB_LIBRARY_DEBUG} ${TBB_MALLOC_LIBRARY_DEBUG} ${TBB_DEBUG_LIBRARIES}) - set (TBB_INCLUDE_DIRS ${TBB_INCLUDE_DIR} CACHE PATH "TBB include directory" FORCE) - set (TBB_LIBRARY_DIRS ${TBB_LIBRARY_DIR} CACHE PATH "TBB library directory" FORCE) - # Jiri: Self-built TBB stores the debug libraries in a separate directory. - set (TBB_DEBUG_LIBRARY_DIRS ${TBB_LIBRARY_DEBUG_DIR} CACHE PATH "TBB debug library directory" FORCE) - mark_as_advanced(TBB_INCLUDE_DIRS TBB_LIBRARY_DIRS TBB_DEBUG_LIBRARY_DIRS TBB_LIBRARIES TBB_DEBUG_LIBRARIES) - message(STATUS "Found Intel TBB") - endif (TBB_LIBRARY) -endif (TBB_INCLUDE_DIR) - -if (NOT TBB_FOUND) - message("ERROR: Intel TBB NOT found!") - message(STATUS "Looked for Threading Building Blocks in ${_TBB_INSTALL_DIR}") - # do only throw fatal, if this pkg is REQUIRED - if (TBB_FIND_REQUIRED) - message(FATAL_ERROR "Could NOT find TBB library.") - endif (TBB_FIND_REQUIRED) -endif (NOT TBB_FOUND) - -endif (NOT _TBB_INSTALL_DIR) - -if (TBB_FOUND) - set(TBB_INTERFACE_VERSION 0) - FILE(READ "${TBB_INCLUDE_DIRS}/tbb/tbb_stddef.h" _TBB_VERSION_CONTENTS) - STRING(REGEX REPLACE ".*#define TBB_INTERFACE_VERSION ([0-9]+).*" "\\1" TBB_INTERFACE_VERSION "${_TBB_VERSION_CONTENTS}") - set(TBB_INTERFACE_VERSION "${TBB_INTERFACE_VERSION}") -endif (TBB_FOUND) diff --git a/example/cmake/FindTBB.cmake b/example/cmake/FindTBB.cmake new file mode 120000 index 00000000000..f51bdf7429c --- /dev/null +++ b/example/cmake/FindTBB.cmake @@ -0,0 +1 @@ +../../cmake/FindTBB.cmake \ No newline at end of file diff --git a/include/util/packed_vector.hpp b/include/util/packed_vector.hpp index dfe4ef7e31f..b746dd27db7 100644 --- a/include/util/packed_vector.hpp +++ b/include/util/packed_vector.hpp @@ -11,12 +11,15 @@ #include #include -#include - #include #include #include +#if defined(_MSC_VER) +// for `InterlockedCompareExchange` +#include +#endif + namespace osrm { namespace util @@ -89,6 +92,17 @@ inline WordT set_upper_value(WordT word, WordT mask, std::uint8_t offset, T valu return (word & ~mask) | ((static_cast(value) >> offset) & mask); } +inline bool compare_and_swap(uint64_t *ptr, uint64_t old_value, uint64_t new_value) +{ +#if defined(_MSC_VER) + return InterlockedCompareExchange(ptr, new_value, old_value) != old_value; +#elif defined(__GNUC__) + return __sync_bool_compare_and_swap(ptr, old_value, new_value); +#else +#error "Unsupported compiler"; +#endif +} + template class PackedVector { using WordT = std::uint64_t; @@ -527,8 +541,7 @@ template class Pack lower_mask[internal_index.element], lower_offset[internal_index.element], value); - } while (tbb::internal::as_atomic(lower_word) - .compare_and_swap(new_lower_word, local_lower_word) != local_lower_word); + } while (!compare_and_swap(&lower_word, local_lower_word, new_lower_word)); // Lock-free update of the upper word WordT local_upper_word, new_upper_word; @@ -539,8 +552,7 @@ template class Pack upper_mask[internal_index.element], upper_offset[internal_index.element], value); - } while (tbb::internal::as_atomic(upper_word) - .compare_and_swap(new_upper_word, local_upper_word) != local_upper_word); + } while (!compare_and_swap(&upper_word, local_upper_word, new_upper_word)); } util::ViewOrVector vec; diff --git a/src/contractor/contractor.cpp b/src/contractor/contractor.cpp index f151eeb5939..b98a2273782 100644 --- a/src/contractor/contractor.cpp +++ b/src/contractor/contractor.cpp @@ -35,12 +35,7 @@ #include #include - -#if TBB_VERSION_MAJOR == 2020 #include -#else -#include -#endif namespace osrm { @@ -49,13 +44,8 @@ namespace contractor int Contractor::Run() { -#if TBB_VERSION_MAJOR == 2020 tbb::global_control gc(tbb::global_control::max_allowed_parallelism, config.requested_num_threads); -#else - tbb::task_scheduler_init init(config.requested_num_threads); - BOOST_ASSERT(init.is_active()); -#endif if (config.core_factor != 1.0) { diff --git a/src/customize/customizer.cpp b/src/customize/customizer.cpp index da95f996797..38efef41994 100644 --- a/src/customize/customizer.cpp +++ b/src/customize/customizer.cpp @@ -21,11 +21,7 @@ #include -#if TBB_VERSION_MAJOR == 2020 #include -#else -#include -#endif namespace osrm { @@ -123,13 +119,8 @@ std::vector customizeFilteredMetrics(const partitioner::MultiLevelEd int Customizer::Run(const CustomizationConfig &config) { -#if TBB_VERSION_MAJOR == 2020 tbb::global_control gc(tbb::global_control::max_allowed_parallelism, config.requested_num_threads); -#else - tbb::task_scheduler_init init(config.requested_num_threads); - BOOST_ASSERT(init.is_active()); -#endif TIMER_START(loading_data); diff --git a/src/extractor/edge_based_graph_factory.cpp b/src/extractor/edge_based_graph_factory.cpp index edef3d58951..ec0675936a2 100644 --- a/src/extractor/edge_based_graph_factory.cpp +++ b/src/extractor/edge_based_graph_factory.cpp @@ -37,7 +37,7 @@ #include #include -#include +#include namespace std { @@ -483,8 +483,8 @@ void EdgeBasedGraphFactory::GenerateEdgeExpandedEdges( // Sets of intersection IDs are batched in groups of GRAINSIZE (100) `generator_stage`, then // those groups are processed in parallel `processor_stage`. Finally, results are appended to // the various buffer vectors by the `output_stage` in the same order that the `generator_stage` - // created them in (tbb::filter::serial_in_order creates this guarantee). The order needs to be - // maintained because we depend on it later in the processing pipeline. + // created them in (tbb::filter_mode::serial_in_order creates this guarantee). The order needs + // to be maintained because we depend on it later in the processing pipeline. { const NodeID node_count = m_node_based_graph.GetNumberOfNodes(); @@ -534,8 +534,8 @@ void EdgeBasedGraphFactory::GenerateEdgeExpandedEdges( const constexpr unsigned GRAINSIZE = 100; // First part of the pipeline generates iterator ranges of IDs in sets of GRAINSIZE - tbb::filter_t> generator_stage( - tbb::filter::serial_in_order, [&](tbb::flow_control &fc) { + tbb::filter> generator_stage( + tbb::filter_mode::serial_in_order, [&](tbb::flow_control &fc) { if (current_node < node_count) { auto next_node = std::min(current_node + GRAINSIZE, node_count); @@ -669,8 +669,9 @@ void EdgeBasedGraphFactory::GenerateEdgeExpandedEdges( // // Edge-based-graph stage // - tbb::filter_t, EdgesPipelineBufferPtr> processor_stage( - tbb::filter::parallel, [&](const tbb::blocked_range &intersection_node_range) { + tbb::filter, EdgesPipelineBufferPtr> processor_stage( + tbb::filter_mode::parallel, + [&](const tbb::blocked_range &intersection_node_range) { auto buffer = std::make_shared(); buffer->nodes_processed = intersection_node_range.size(); @@ -1067,8 +1068,8 @@ void EdgeBasedGraphFactory::GenerateEdgeExpandedEdges( util::UnbufferedLog log; util::Percent routing_progress(log, node_count); std::vector delayed_data; - tbb::filter_t output_stage( - tbb::filter::serial_in_order, [&](auto buffer) { + tbb::filter output_stage( + tbb::filter_mode::serial_in_order, [&](auto buffer) { routing_progress.PrintAddition(buffer->nodes_processed); m_connectivity_checksum = buffer->checksum.update_checksum(m_connectivity_checksum); diff --git a/src/extractor/extractor.cpp b/src/extractor/extractor.cpp index d3fa345c74f..3d91ff3f327 100644 --- a/src/extractor/extractor.cpp +++ b/src/extractor/extractor.cpp @@ -43,13 +43,8 @@ #include #include #include - -#if TBB_VERSION_MAJOR == 2020 #include -#else -#include -#endif -#include +#include #include #include @@ -206,13 +201,8 @@ int Extractor::run(ScriptingEnvironment &scripting_environment) const unsigned recommended_num_threads = std::thread::hardware_concurrency(); const auto number_of_threads = std::min(recommended_num_threads, config.requested_num_threads); -#if TBB_VERSION_MAJOR == 2020 tbb::global_control gc(tbb::global_control::max_allowed_parallelism, config.requested_num_threads); -#else - tbb::task_scheduler_init init(config.requested_num_threads); - BOOST_ASSERT(init.is_active()); -#endif LaneDescriptionMap turn_lane_map; std::vector turn_restrictions; @@ -454,8 +444,8 @@ std:: ExtractionRelationContainer relations; const auto buffer_reader = [](osmium::io::Reader &reader) { - return tbb::filter_t( - tbb::filter::serial_in_order, [&reader](tbb::flow_control &fc) { + return tbb::filter( + tbb::filter_mode::serial_in_order, [&reader](tbb::flow_control &fc) { if (auto buffer = reader.read()) { return std::make_shared(std::move(buffer)); @@ -476,15 +466,15 @@ std:: osmium_index_type location_cache; osmium_location_handler_type location_handler(location_cache); - tbb::filter_t location_cacher( - tbb::filter::serial_in_order, [&location_handler](SharedBuffer buffer) { + tbb::filter location_cacher( + tbb::filter_mode::serial_in_order, [&location_handler](SharedBuffer buffer) { osmium::apply(buffer->begin(), buffer->end(), location_handler); return buffer; }); // OSM elements Lua parser - tbb::filter_t buffer_transformer( - tbb::filter::parallel, + tbb::filter buffer_transformer( + tbb::filter_mode::parallel, // NOLINTNEXTLINE(performance-unnecessary-value-param) [&](const SharedBuffer buffer) { ParsedBuffer parsed_buffer; @@ -505,8 +495,8 @@ std:: unsigned number_of_ways = 0; unsigned number_of_restrictions = 0; unsigned number_of_maneuver_overrides = 0; - tbb::filter_t buffer_storage( - tbb::filter::serial_in_order, [&](const ParsedBuffer &parsed_buffer) { + tbb::filter buffer_storage( + tbb::filter_mode::serial_in_order, [&](const ParsedBuffer &parsed_buffer) { number_of_nodes += parsed_buffer.resulting_nodes.size(); // put parsed objects thru extractor callbacks for (const auto &result : parsed_buffer.resulting_nodes) @@ -532,8 +522,8 @@ std:: } }); - tbb::filter_t> buffer_relation_cache( - tbb::filter::parallel, + tbb::filter> buffer_relation_cache( + tbb::filter_mode::parallel, // NOLINTNEXTLINE(performance-unnecessary-value-param) [&](const SharedBuffer buffer) { if (!buffer) @@ -570,8 +560,8 @@ std:: }); unsigned number_of_relations = 0; - tbb::filter_t, void> buffer_storage_relation( - tbb::filter::serial_in_order, + tbb::filter, void> buffer_storage_relation( + tbb::filter_mode::serial_in_order, // NOLINTNEXTLINE(performance-unnecessary-value-param) [&](const std::shared_ptr parsed_relations) { number_of_relations += parsed_relations->GetRelationsNum(); diff --git a/src/guidance/guidance_processing.cpp b/src/guidance/guidance_processing.cpp index 0f3155046ea..cd24dabf03e 100644 --- a/src/guidance/guidance_processing.cpp +++ b/src/guidance/guidance_processing.cpp @@ -9,7 +9,7 @@ #include "util/percent.hpp" #include -#include +#include #include @@ -97,8 +97,8 @@ void annotateTurns(const util::NodeBasedDynamicGraph &node_based_graph, const constexpr unsigned GRAINSIZE = 100; // First part of the pipeline generates iterator ranges of IDs in sets of GRAINSIZE - tbb::filter_t> generator_stage( - tbb::filter::serial_in_order, [&](tbb::flow_control &fc) { + tbb::filter> generator_stage( + tbb::filter_mode::serial_in_order, [&](tbb::flow_control &fc) { if (current_node < node_count) { auto next_node = std::min(current_node + GRAINSIZE, node_count); @@ -116,8 +116,9 @@ void annotateTurns(const util::NodeBasedDynamicGraph &node_based_graph, // // Guidance stage // - tbb::filter_t, TurnsPipelineBufferPtr> guidance_stage( - tbb::filter::parallel, [&](const tbb::blocked_range &intersection_node_range) { + tbb::filter, TurnsPipelineBufferPtr> guidance_stage( + tbb::filter_mode::parallel, + [&](const tbb::blocked_range &intersection_node_range) { auto buffer = std::make_shared(); buffer->nodes_processed = intersection_node_range.size(); @@ -307,8 +308,8 @@ void annotateTurns(const util::NodeBasedDynamicGraph &node_based_graph, util::Percent guidance_progress(log, node_count); std::vector delayed_turn_data; - tbb::filter_t guidance_output_stage( - tbb::filter::serial_in_order, [&](auto buffer) { + tbb::filter guidance_output_stage( + tbb::filter_mode::serial_in_order, [&](auto buffer) { guidance_progress.PrintAddition(buffer->nodes_processed); connectivity_checksum = buffer->checksum.update_checksum(connectivity_checksum); diff --git a/src/partitioner/partitioner.cpp b/src/partitioner/partitioner.cpp index f01ea966c57..63a1a7fc26f 100644 --- a/src/partitioner/partitioner.cpp +++ b/src/partitioner/partitioner.cpp @@ -27,12 +27,7 @@ #include #include - -#if TBB_VERSION_MAJOR == 2020 #include -#else -#include -#endif #include "util/geojson_debug_logger.hpp" #include "util/geojson_debug_policies.hpp" @@ -74,13 +69,8 @@ auto getGraphBisection(const PartitionerConfig &config) int Partitioner::Run(const PartitionerConfig &config) { -#if TBB_VERSION_MAJOR == 2020 tbb::global_control gc(tbb::global_control::max_allowed_parallelism, config.requested_num_threads); -#else - tbb::task_scheduler_init init(config.requested_num_threads); - BOOST_ASSERT(init.is_active()); -#endif const std::vector &node_based_partition_ids = getGraphBisection(config); diff --git a/src/partitioner/recursive_bisection.cpp b/src/partitioner/recursive_bisection.cpp index 7c3ef98e3d3..85d478923d1 100644 --- a/src/partitioner/recursive_bisection.cpp +++ b/src/partitioner/recursive_bisection.cpp @@ -7,7 +7,7 @@ #include "util/log.hpp" #include "util/timing_util.hpp" -#include +#include #include #include // for CHAR_BIT @@ -64,12 +64,12 @@ RecursiveBisection::RecursiveBisection(BisectionGraph &bisection_graph_, return TreeNode{std::move(graph), internal_state.SCCDepth()}; }); - using Feeder = tbb::parallel_do_feeder; + using Feeder = tbb::feeder; TIMER_START(bisection); // Bisect graph into two parts. Get partition point and recurse left and right in parallel. - tbb::parallel_do(begin(forest), end(forest), [&](const TreeNode &node, Feeder &feeder) { + tbb::parallel_for_each(begin(forest), end(forest), [&](const TreeNode &node, Feeder &feeder) { const auto cut = computeInertialFlowCut(node.graph, num_optimizing_cuts, balance, boundary_factor); const auto center = internal_state.ApplyBisection( diff --git a/unit_tests/contractor/graph_contractor.cpp b/unit_tests/contractor/graph_contractor.cpp index a87e98fe401..81fbd28e0b9 100644 --- a/unit_tests/contractor/graph_contractor.cpp +++ b/unit_tests/contractor/graph_contractor.cpp @@ -4,13 +4,7 @@ #include "helper.hpp" #include - -#include // For version lookup -#if TBB_VERSION_MAJOR == 2020 #include -#else -#include -#endif using namespace osrm; using namespace osrm::contractor; @@ -20,11 +14,7 @@ BOOST_AUTO_TEST_SUITE(graph_contractor) BOOST_AUTO_TEST_CASE(contract_graph) { -#if TBB_VERSION_MAJOR == 2020 tbb::global_control scheduler(tbb::global_control::max_allowed_parallelism, 1); -#else - tbb::task_scheduler_init scheduler(1); -#endif /* * <--1--< * (0) >--3--> (1) >--3--> (3) diff --git a/unit_tests/partitioner/recursive_bisection.cpp b/unit_tests/partitioner/recursive_bisection.cpp index 2e040a2bf29..ecbf3cc2edf 100644 --- a/unit_tests/partitioner/recursive_bisection.cpp +++ b/unit_tests/partitioner/recursive_bisection.cpp @@ -8,13 +8,8 @@ #include // make sure not to leak in recursive bisection -#if TBB_VERSION_MAJOR == 2020 #include tbb::global_control scheduler(tbb::global_control::max_allowed_parallelism, 2); -#else -#include -tbb::task_scheduler_init init(2); -#endif using namespace osrm::partitioner; using namespace osrm::util; diff --git a/unit_tests/util/static_rtree.cpp b/unit_tests/util/static_rtree.cpp index 8f18f915e06..14666a13e33 100644 --- a/unit_tests/util/static_rtree.cpp +++ b/unit_tests/util/static_rtree.cpp @@ -25,13 +25,8 @@ #include // explicit TBB scheduler init to register resources cleanup at exit -#if TBB_VERSION_MAJOR == 2020 #include tbb::global_control scheduler(tbb::global_control::max_allowed_parallelism, 2); -#else -#include -tbb::task_scheduler_init init(2); -#endif BOOST_AUTO_TEST_SUITE(static_rtree) From 1d59fdd1405af17b87ad5688d8c807d3c0d74764 Mon Sep 17 00:00:00 2001 From: Siarhei Fedartsou Date: Fri, 19 Aug 2022 22:42:59 +0200 Subject: [PATCH 02/14] Migrate to modern TBB version --- CMakeLists.txt | 5 ++--- docker/Dockerfile | 13 ++++++++++--- include/util/packed_vector.hpp | 2 +- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index df6e9a4c0c0..50b215c2c50 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -475,7 +475,6 @@ if(ENABLE_CONAN) lua/${CONAN_LUA_VERSION} onetbb/${CONAN_TBB_VERSION} BASIC_SETUP - BUILD missing GENERATORS cmake_find_package KEEP_RPATHS NO_OUTPUT_DIRS @@ -484,9 +483,9 @@ if(ENABLE_CONAN) ) # explicitly say Conan to use x86 dependencies if build for x86 platforms (https://github.com/conan-io/cmake-conan/issues/141) if(NOT CMAKE_SIZEOF_VOID_P EQUAL 8) - conan_cmake_run("${CONAN_ARGS} ARCH x86") + conan_cmake_run("${CONAN_ARGS} BUILD all ARCH x86") else() - conan_cmake_run("${CONAN_ARGS}") + conan_cmake_run("${CONAN_ARGS} BUILD missing ") endif() add_dependency_includes(${CONAN_INCLUDE_DIRS_BOOST}) diff --git a/docker/Dockerfile b/docker/Dockerfile index 5c06dc8ea42..0ce7c6f3c29 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -4,8 +4,15 @@ ARG BUILD_CONCURRENCY RUN mkdir -p /src && mkdir -p /opt RUN apt-get update && \ - apt-get -y --no-install-recommends install cmake make git gcc g++ libbz2-dev libxml2-dev \ - libzip-dev libboost1.74-all-dev lua5.2 liblua5.2-dev libtbb-dev -o APT::Install-Suggests=0 -o APT::Install-Recommends=0 + apt-get -y --no-install-recommends install cmake make git gcc g++ libbz2-dev libxml2-dev wget \ + libzip-dev libboost1.74-all-dev lua5.2 liblua5.2-dev -o APT::Install-Suggests=0 -o APT::Install-Recommends=0 + +RUN export TBB_VERSION=2021.3.0 && \ + export TBB_URL="https://github.com/oneapi-src/oneTBB/releases/download/v${TBB_VERSION}/oneapi-tbb-${TBB_VERSION}-lin.tgz" && \ + wget --tries 5 ${TBB_URL} -O onetbb.tgz && \ + tar zxvf onetbb.tgz && \ + cp -a oneapi-tbb-${TBB_VERSION}/lib/. /usr/local/lib/ && \ + cp -a oneapi-tbb-${TBB_VERSION}/include/. /usr/local/include/ COPY . /src WORKDIR /src @@ -37,7 +44,7 @@ RUN apt-get update && \ apt-get install -y --no-install-recommends libboost-program-options1.74.0 libboost-regex1.74.0 \ libboost-date-time1.74.0 libboost-chrono1.74.0 libboost-filesystem1.74.0 \ libboost-iostreams1.74.0 libboost-system1.74.0 libboost-thread1.74.0 \ - expat liblua5.2-0 libtbb2 &&\ + expat liblua5.2-0 &&\ rm -rf /var/lib/apt/lists/* COPY --from=builder /usr/local /usr/local COPY --from=builder /opt /opt diff --git a/include/util/packed_vector.hpp b/include/util/packed_vector.hpp index b746dd27db7..c6c08b86c26 100644 --- a/include/util/packed_vector.hpp +++ b/include/util/packed_vector.hpp @@ -17,7 +17,7 @@ #if defined(_MSC_VER) // for `InterlockedCompareExchange` -#include +#include #endif namespace osrm From 1657c7adf8162363b000bbe77e041dcce766ca36 Mon Sep 17 00:00:00 2001 From: Siarhei Fedartsou Date: Fri, 19 Aug 2022 22:53:51 +0200 Subject: [PATCH 03/14] Migrate to modern TBB version --- .github/workflows/osrm-backend.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/osrm-backend.yml b/.github/workflows/osrm-backend.yml index 2d93b798cc9..d75b657cc14 100644 --- a/.github/workflows/osrm-backend.yml +++ b/.github/workflows/osrm-backend.yml @@ -462,9 +462,9 @@ jobs: uses: actions/cache@v2 with: path: ~/.conan - key: v2-conan-${{ matrix.name }}-${{ github.sha }} + key: v3-conan-${{ matrix.name }}-${{ github.sha }} restore-keys: | - v2-conan-${{ matrix.name }}- + v3-conan-${{ matrix.name }}- - name: Enable test cache uses: actions/cache@v2 with: From d0f71748f87fe1b756efd73e4e37252e44359283 Mon Sep 17 00:00:00 2001 From: Siarhei Fedartsou Date: Fri, 19 Aug 2022 22:56:38 +0200 Subject: [PATCH 04/14] Migrate to modern TBB version --- include/util/packed_vector.hpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/util/packed_vector.hpp b/include/util/packed_vector.hpp index c6c08b86c26..85fcefba0e6 100644 --- a/include/util/packed_vector.hpp +++ b/include/util/packed_vector.hpp @@ -18,6 +18,8 @@ #if defined(_MSC_VER) // for `InterlockedCompareExchange` #include +// defined by `windows.h` +#undef OPTIONAL #endif namespace osrm From a125c48eb49133ad30842a634f9fa871c368ad3c Mon Sep 17 00:00:00 2001 From: Siarhei Fedartsou Date: Fri, 19 Aug 2022 22:59:55 +0200 Subject: [PATCH 05/14] Migrate to modern TBB version --- include/util/packed_vector.hpp | 2 -- src/storage/storage.cpp | 52 +++++++++++++++++----------------- 2 files changed, 26 insertions(+), 28 deletions(-) diff --git a/include/util/packed_vector.hpp b/include/util/packed_vector.hpp index 85fcefba0e6..c6c08b86c26 100644 --- a/include/util/packed_vector.hpp +++ b/include/util/packed_vector.hpp @@ -18,8 +18,6 @@ #if defined(_MSC_VER) // for `InterlockedCompareExchange` #include -// defined by `windows.h` -#undef OPTIONAL #endif namespace osrm diff --git a/src/storage/storage.cpp b/src/storage/storage.cpp index 9494285abed..13ba1b01510 100644 --- a/src/storage/storage.cpp +++ b/src/storage/storage.cpp @@ -290,27 +290,27 @@ int Storage::Run(int max_wait, const std::string &dataset_name, bool only_metric std::vector> Storage::GetStaticFiles() { - constexpr bool REQUIRED = true; - constexpr bool OPTIONAL = false; + constexpr bool IS_REQUIRED = true; + constexpr bool IS_OPTIONAL = false; std::vector> files = { - {OPTIONAL, config.GetPath(".osrm.cells")}, - {OPTIONAL, config.GetPath(".osrm.partition")}, - {REQUIRED, config.GetPath(".osrm.icd")}, - {REQUIRED, config.GetPath(".osrm.properties")}, - {REQUIRED, config.GetPath(".osrm.nbg_nodes")}, - {REQUIRED, config.GetPath(".osrm.ebg_nodes")}, - {REQUIRED, config.GetPath(".osrm.tls")}, - {REQUIRED, config.GetPath(".osrm.tld")}, - {REQUIRED, config.GetPath(".osrm.timestamp")}, - {REQUIRED, config.GetPath(".osrm.maneuver_overrides")}, - {REQUIRED, config.GetPath(".osrm.edges")}, - {REQUIRED, config.GetPath(".osrm.names")}, - {REQUIRED, config.GetPath(".osrm.ramIndex")}}; + {IS_OPTIONAL, config.GetPath(".osrm.cells")}, + {IS_OPTIONAL, config.GetPath(".osrm.partition")}, + {IS_REQUIRED, config.GetPath(".osrm.icd")}, + {IS_REQUIRED, config.GetPath(".osrm.properties")}, + {IS_REQUIRED, config.GetPath(".osrm.nbg_nodes")}, + {IS_REQUIRED, config.GetPath(".osrm.ebg_nodes")}, + {IS_REQUIRED, config.GetPath(".osrm.tls")}, + {IS_REQUIRED, config.GetPath(".osrm.tld")}, + {IS_REQUIRED, config.GetPath(".osrm.timestamp")}, + {IS_REQUIRED, config.GetPath(".osrm.maneuver_overrides")}, + {IS_REQUIRED, config.GetPath(".osrm.edges")}, + {IS_REQUIRED, config.GetPath(".osrm.names")}, + {IS_REQUIRED, config.GetPath(".osrm.ramIndex")}}; for (const auto &file : files) { - if (file.first == REQUIRED && !boost::filesystem::exists(file.second)) + if (file.first == IS_REQUIRED && !boost::filesystem::exists(file.second)) { throw util::exception("Could not find required filed: " + std::get<1>(file).string()); } @@ -321,21 +321,21 @@ std::vector> Storage::GetStaticFiles() std::vector> Storage::GetUpdatableFiles() { - constexpr bool REQUIRED = true; - constexpr bool OPTIONAL = false; + constexpr bool IS_REQUIRED = true; + constexpr bool IS_OPTIONAL = false; std::vector> files = { - {OPTIONAL, config.GetPath(".osrm.mldgr")}, - {OPTIONAL, config.GetPath(".osrm.cell_metrics")}, - {OPTIONAL, config.GetPath(".osrm.hsgr")}, - {REQUIRED, config.GetPath(".osrm.datasource_names")}, - {REQUIRED, config.GetPath(".osrm.geometry")}, - {REQUIRED, config.GetPath(".osrm.turn_weight_penalties")}, - {REQUIRED, config.GetPath(".osrm.turn_duration_penalties")}}; + {IS_OPTIONAL, config.GetPath(".osrm.mldgr")}, + {IS_OPTIONAL, config.GetPath(".osrm.cell_metrics")}, + {IS_OPTIONAL, config.GetPath(".osrm.hsgr")}, + {IS_REQUIRED, config.GetPath(".osrm.datasource_names")}, + {IS_REQUIRED, config.GetPath(".osrm.geometry")}, + {IS_REQUIRED, config.GetPath(".osrm.turn_weight_penalties")}, + {IS_REQUIRED, config.GetPath(".osrm.turn_duration_penalties")}}; for (const auto &file : files) { - if (file.first == REQUIRED && !boost::filesystem::exists(file.second)) + if (file.first == IS_REQUIRED && !boost::filesystem::exists(file.second)) { throw util::exception("Could not find required filed: " + std::get<1>(file).string()); } From 39256166a62b9bc90c66b1e7a67cb6254e28c59d Mon Sep 17 00:00:00 2001 From: Siarhei Fedartsou Date: Fri, 19 Aug 2022 23:01:08 +0200 Subject: [PATCH 06/14] Migrate to modern TBB version --- docker/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker/Dockerfile b/docker/Dockerfile index 0ce7c6f3c29..9f06ef6c3dd 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -4,7 +4,7 @@ ARG BUILD_CONCURRENCY RUN mkdir -p /src && mkdir -p /opt RUN apt-get update && \ - apt-get -y --no-install-recommends install cmake make git gcc g++ libbz2-dev libxml2-dev wget \ + apt-get -y --no-install-recommends install ca-certificates cmake make git gcc g++ libbz2-dev libxml2-dev wget \ libzip-dev libboost1.74-all-dev lua5.2 liblua5.2-dev -o APT::Install-Suggests=0 -o APT::Install-Recommends=0 RUN export TBB_VERSION=2021.3.0 && \ From 57a22933657b47c97d1dac9f5c4b69d57e07a04e Mon Sep 17 00:00:00 2001 From: Siarhei Fedartsou Date: Fri, 19 Aug 2022 23:08:59 +0200 Subject: [PATCH 07/14] Migrate to modern TBB version --- CMakeLists.txt | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 50b215c2c50..66d59c91e92 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -467,6 +467,15 @@ if(ENABLE_CONAN) set(CONAN_SYSTEM_INCLUDES ON) + # TODO: + # if we link TBB dynamically osrm-extract.exe finishes on the first access to any TBB symbol + # with exit code = -1073741515, which means that program cannot load required DLL. + if (MSVC) + set(TBB_SHARED False) + else() + set(TBB_SHARED True) + endif() + set(CONAN_ARGS REQUIRES boost/${CONAN_BOOST_VERSION} @@ -480,12 +489,13 @@ if(ENABLE_CONAN) NO_OUTPUT_DIRS OPTIONS boost:filesystem_version=3 # https://stackoverflow.com/questions/73392648/error-with-boost-filesystem-version-in-cmake tbb:shared=${TBB_SHARED} + BUILD missing ) # explicitly say Conan to use x86 dependencies if build for x86 platforms (https://github.com/conan-io/cmake-conan/issues/141) if(NOT CMAKE_SIZEOF_VOID_P EQUAL 8) - conan_cmake_run("${CONAN_ARGS} BUILD all ARCH x86") + conan_cmake_run("${CONAN_ARGS};ARCH;x86") else() - conan_cmake_run("${CONAN_ARGS} BUILD missing ") + conan_cmake_run("${CONAN_ARGS}") endif() add_dependency_includes(${CONAN_INCLUDE_DIRS_BOOST}) From 2b316f019782baa49cc5888f5faccf1c1f66ec69 Mon Sep 17 00:00:00 2001 From: Siarhei Fedartsou Date: Fri, 19 Aug 2022 23:36:19 +0200 Subject: [PATCH 08/14] Migrate to modern TBB version --- docker/Dockerfile | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/docker/Dockerfile b/docker/Dockerfile index 9f06ef6c3dd..210d5eb66fa 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -7,17 +7,19 @@ RUN apt-get update && \ apt-get -y --no-install-recommends install ca-certificates cmake make git gcc g++ libbz2-dev libxml2-dev wget \ libzip-dev libboost1.74-all-dev lua5.2 liblua5.2-dev -o APT::Install-Suggests=0 -o APT::Install-Recommends=0 -RUN export TBB_VERSION=2021.3.0 && \ - export TBB_URL="https://github.com/oneapi-src/oneTBB/releases/download/v${TBB_VERSION}/oneapi-tbb-${TBB_VERSION}-lin.tgz" && \ - wget --tries 5 ${TBB_URL} -O onetbb.tgz && \ - tar zxvf onetbb.tgz && \ - cp -a oneapi-tbb-${TBB_VERSION}/lib/. /usr/local/lib/ && \ - cp -a oneapi-tbb-${TBB_VERSION}/include/. /usr/local/include/ +RUN NPROC=${BUILD_CONCURRENCY:-$(nproc)} && \ + git clone --branch v2021.3.0 --single-branch https://github.com/oneapi-src/oneTBB.git && \ + cd oneTBB && \ + mkdir build && \ + cd build && \ + cmake .. && \ + make -j${NPROC} && \ + make install COPY . /src WORKDIR /src -RUN NPROC=${BUILD_CONCURRENCY:-$(grep -c ^processor /proc/cpuinfo 2>/dev/null || 1)} && \ +RUN NPROC=${BUILD_CONCURRENCY:-$(nproc)} && \ echo "Building OSRM ${DOCKER_TAG}" && \ git show --format="%H" | head -n1 > /opt/OSRM_GITSHA && \ echo "Building OSRM gitsha $(cat /opt/OSRM_GITSHA)" && \ @@ -53,6 +55,7 @@ RUN /usr/local/bin/osrm-extract --help && \ /usr/local/bin/osrm-contract --help && \ /usr/local/bin/osrm-partition --help && \ /usr/local/bin/osrm-customize --help + WORKDIR /opt EXPOSE 5000 From b27a43de2ca354e67841ed10a031e41f1ecbf9a0 Mon Sep 17 00:00:00 2001 From: Siarhei Fedartsou Date: Sat, 20 Aug 2022 11:17:08 +0200 Subject: [PATCH 09/14] Migrate to modern TBB version --- CMakeLists.txt | 2 +- docker/Dockerfile | 22 ++++++++++++++-------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 66d59c91e92..6f093ddcfe2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -488,7 +488,7 @@ if(ENABLE_CONAN) KEEP_RPATHS NO_OUTPUT_DIRS OPTIONS boost:filesystem_version=3 # https://stackoverflow.com/questions/73392648/error-with-boost-filesystem-version-in-cmake - tbb:shared=${TBB_SHARED} + onetbb:shared=${TBB_SHARED} BUILD missing ) # explicitly say Conan to use x86 dependencies if build for x86 platforms (https://github.com/conan-io/cmake-conan/issues/141) diff --git a/docker/Dockerfile b/docker/Dockerfile index 210d5eb66fa..4f2e77838dd 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -8,13 +8,14 @@ RUN apt-get update && \ libzip-dev libboost1.74-all-dev lua5.2 liblua5.2-dev -o APT::Install-Suggests=0 -o APT::Install-Recommends=0 RUN NPROC=${BUILD_CONCURRENCY:-$(nproc)} && \ + ldconfig /usr/local/lib && \ git clone --branch v2021.3.0 --single-branch https://github.com/oneapi-src/oneTBB.git && \ cd oneTBB && \ mkdir build && \ cd build && \ - cmake .. && \ - make -j${NPROC} && \ - make install + cmake -DTBB_TEST=OFF -DCMAKE_BUILD_TYPE=Release .. && \ + cmake --build . && \ + cmake --install . COPY . /src WORKDIR /src @@ -38,18 +39,23 @@ RUN NPROC=${BUILD_CONCURRENCY:-$(nproc)} && \ strip /usr/local/bin/* && \ rm -rf /src /usr/local/lib/libosrm* + # Multistage build to reduce image size - https://docs.docker.com/engine/userguide/eng-image/multistage-build/#use-multi-stage-builds # Only the content below ends up in the image, this helps remove /src from the image (which is large) FROM debian:bullseye-slim as runstage -RUN mkdir -p /src && mkdir -p /opt + +COPY --from=builder /usr/local /usr/local +COPY --from=builder /opt /opt + RUN apt-get update && \ apt-get install -y --no-install-recommends libboost-program-options1.74.0 libboost-regex1.74.0 \ libboost-date-time1.74.0 libboost-chrono1.74.0 libboost-filesystem1.74.0 \ libboost-iostreams1.74.0 libboost-system1.74.0 libboost-thread1.74.0 \ - expat liblua5.2-0 &&\ - rm -rf /var/lib/apt/lists/* -COPY --from=builder /usr/local /usr/local -COPY --from=builder /opt /opt + expat liblua5.2-0 && \ + rm -rf /var/lib/apt/lists/* && \ +# add /usr/local/lib to ldconfig to allow loading libraries from there + ldconfig /usr/local/lib + RUN /usr/local/bin/osrm-extract --help && \ /usr/local/bin/osrm-routed --help && \ /usr/local/bin/osrm-contract --help && \ From 02cb20e890818481eeb633a0552b05950d7db38d Mon Sep 17 00:00:00 2001 From: Siarhei Fedartsou Date: Sun, 21 Aug 2022 15:04:47 +0200 Subject: [PATCH 10/14] Migrate to modern TBB version --- include/util/packed_vector.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/util/packed_vector.hpp b/include/util/packed_vector.hpp index c6c08b86c26..fcd74fc0980 100644 --- a/include/util/packed_vector.hpp +++ b/include/util/packed_vector.hpp @@ -16,7 +16,7 @@ #include #if defined(_MSC_VER) -// for `InterlockedCompareExchange` +// for `InterlockedCompareExchange64` #include #endif @@ -95,7 +95,7 @@ inline WordT set_upper_value(WordT word, WordT mask, std::uint8_t offset, T valu inline bool compare_and_swap(uint64_t *ptr, uint64_t old_value, uint64_t new_value) { #if defined(_MSC_VER) - return InterlockedCompareExchange(ptr, new_value, old_value) != old_value; + return InterlockedCompareExchange64(ptr, new_value, old_value) == old_value; #elif defined(__GNUC__) return __sync_bool_compare_and_swap(ptr, old_value, new_value); #else From 51cfb1e5085cf5ead1d19529d48ac7487eb7c9d9 Mon Sep 17 00:00:00 2001 From: Siarhei Fedartsou Date: Sun, 21 Aug 2022 15:32:56 +0200 Subject: [PATCH 11/14] Migrate to modern TBB version --- include/util/packed_vector.hpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/include/util/packed_vector.hpp b/include/util/packed_vector.hpp index fcd74fc0980..7a1d93a6eec 100644 --- a/include/util/packed_vector.hpp +++ b/include/util/packed_vector.hpp @@ -95,7 +95,9 @@ inline WordT set_upper_value(WordT word, WordT mask, std::uint8_t offset, T valu inline bool compare_and_swap(uint64_t *ptr, uint64_t old_value, uint64_t new_value) { #if defined(_MSC_VER) - return InterlockedCompareExchange64(ptr, new_value, old_value) == old_value; + return InterlockedCompareExchange64(reinterpret_cast(ptr), + static_cast(new_value), + static_cast(old_value)) == old_value; #elif defined(__GNUC__) return __sync_bool_compare_and_swap(ptr, old_value, new_value); #else From 2c6527a562bab9796a79a5b427f86fa757ebb9c6 Mon Sep 17 00:00:00 2001 From: Siarhei Fedartsou Date: Sun, 21 Aug 2022 15:46:32 +0200 Subject: [PATCH 12/14] Migrate to modern TBB version --- include/util/packed_vector.hpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/util/packed_vector.hpp b/include/util/packed_vector.hpp index 7a1d93a6eec..ae79c3014d3 100644 --- a/include/util/packed_vector.hpp +++ b/include/util/packed_vector.hpp @@ -95,9 +95,9 @@ inline WordT set_upper_value(WordT word, WordT mask, std::uint8_t offset, T valu inline bool compare_and_swap(uint64_t *ptr, uint64_t old_value, uint64_t new_value) { #if defined(_MSC_VER) - return InterlockedCompareExchange64(reinterpret_cast(ptr), - static_cast(new_value), - static_cast(old_value)) == old_value; + return InterlockedCompareExchange64(reinterpret_cast(ptr), + static_cast(new_value), + static_cast(old_value)) == old_value; #elif defined(__GNUC__) return __sync_bool_compare_and_swap(ptr, old_value, new_value); #else From a64e58633db8341711fd8b74ae4a9dc1c51ba838 Mon Sep 17 00:00:00 2001 From: Siarhei Fedartsou Date: Tue, 23 Aug 2022 18:02:46 +0200 Subject: [PATCH 13/14] Migrate to modern TBB version --- unit_tests/partitioner/recursive_bisection.cpp | 3 --- unit_tests/util/static_rtree.cpp | 4 ---- 2 files changed, 7 deletions(-) diff --git a/unit_tests/partitioner/recursive_bisection.cpp b/unit_tests/partitioner/recursive_bisection.cpp index ecbf3cc2edf..cd6eec5d179 100644 --- a/unit_tests/partitioner/recursive_bisection.cpp +++ b/unit_tests/partitioner/recursive_bisection.cpp @@ -7,9 +7,6 @@ #include -// make sure not to leak in recursive bisection -#include -tbb::global_control scheduler(tbb::global_control::max_allowed_parallelism, 2); using namespace osrm::partitioner; using namespace osrm::util; diff --git a/unit_tests/util/static_rtree.cpp b/unit_tests/util/static_rtree.cpp index 14666a13e33..34eb18994b8 100644 --- a/unit_tests/util/static_rtree.cpp +++ b/unit_tests/util/static_rtree.cpp @@ -24,10 +24,6 @@ #include #include -// explicit TBB scheduler init to register resources cleanup at exit -#include -tbb::global_control scheduler(tbb::global_control::max_allowed_parallelism, 2); - BOOST_AUTO_TEST_SUITE(static_rtree) using namespace osrm; From 98ec27637ae21117b0eb75fd5bf5355000ea1a7e Mon Sep 17 00:00:00 2001 From: Siarhei Fedartsou Date: Tue, 23 Aug 2022 22:13:24 +0200 Subject: [PATCH 14/14] Migrate to modern TBB version --- unit_tests/partitioner/recursive_bisection.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/unit_tests/partitioner/recursive_bisection.cpp b/unit_tests/partitioner/recursive_bisection.cpp index cd6eec5d179..dfcbb805f1e 100644 --- a/unit_tests/partitioner/recursive_bisection.cpp +++ b/unit_tests/partitioner/recursive_bisection.cpp @@ -7,7 +7,6 @@ #include - using namespace osrm::partitioner; using namespace osrm::util;