Skip to content

Commit

Permalink
Committing oneTBB 2021.1-beta09 source code
Browse files Browse the repository at this point in the history
  • Loading branch information
tbbdev committed Sep 24, 2020
1 parent 05b1dd0 commit 8632c27
Show file tree
Hide file tree
Showing 122 changed files with 6,971 additions and 651 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ __pycache__/
# -------- IDE --------
.vscode/*
.vs/*
out/*
CMakeSettings.json

# -------- CTags --------
.tags
Expand Down
18 changes: 17 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@ if (TBB_WINDOWS_DRIVER AND (NOT ("${CMAKE_MSVC_RUNTIME_LIBRARY}" STREQUAL MultiT
message(FATAL_ERROR "Enabled TBB_WINDOWS_DRIVER requires CMAKE_MSVC_RUNTIME_LIBRARY to be set to MultiThreaded or MultiThreadedDebug.")
endif()

# Enable support of minimum supported macOS version flag
if (APPLE)
if (NOT CMAKE_CXX_OSX_DEPLOYMENT_TARGET_FLAG)
set(CMAKE_CXX_OSX_DEPLOYMENT_TARGET_FLAG "-mmacosx-version-min=" CACHE STRING "Minimum macOS version flag")
endif()
if (NOT CMAKE_C_OSX_DEPLOYMENT_TARGET_FLAG)
set(CMAKE_C_OSX_DEPLOYMENT_TARGET_FLAG "-mmacosx-version-min=" CACHE STRING "Minimum macOS version flag")
endif()
endif()

# Until CMake 3.4.0 FindThreads.cmake requires C language enabled.
# Enable C language before CXX to avoid possible override of CMAKE_SIZEOF_VOID_P.
if (CMAKE_VERSION VERSION_LESS 3.4)
Expand All @@ -41,7 +51,9 @@ string(REGEX REPLACE ".*#define TBB_VERSION_MAJOR ([0-9]+).*" "\\1" _tbb_ver_maj
string(REGEX REPLACE ".*#define TBB_VERSION_MINOR ([0-9]+).*" "\\1" _tbb_ver_minor "${_tbb_version_info}")
string(REGEX REPLACE ".*#define TBB_INTERFACE_VERSION ([0-9]+).*" "\\1" TBB_INTERFACE_VERSION "${_tbb_version_info}")
string(REGEX REPLACE ".*#define __TBB_BINARY_VERSION ([0-9]+).*" "\\1" TBB_BINARY_VERSION "${_tbb_version_info}")
set(TBB_BINARY_MINOR_VERSION 0)
set(TBBMALLOC_BINARY_VERSION 2)
set(TBBBIND_BINARY_VERSION 3)

project(TBB VERSION ${_tbb_ver_major}.${_tbb_ver_minor} LANGUAGES CXX)
unset(_tbb_ver_major)
Expand Down Expand Up @@ -176,7 +188,11 @@ else()
add_subdirectory(src/tbbmalloc)
add_subdirectory(src/tbbmalloc_proxy)
if (TBB_NUMA_SUPPORT)
add_subdirectory(src/tbbbind)
if (APPLE)
message(WARNING "TBBBind build target is disabled due to unsupported environment")
else()
add_subdirectory(src/tbbbind)
endif()
endif()
endif()

Expand Down
48 changes: 45 additions & 3 deletions cmake/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ TBB_CPF:BOOL - Enable preview features of the library (OFF by default)
TBB_INSTALL_VARS:BOOL - Enable auto-generated vars installation(packages generated by `cpack` and `make install` will also include the vars script)(OFF by default)
```

# Getting Started

## Configure, build and test

### Prerequisites
Expand All @@ -25,7 +23,7 @@ TBB_INSTALL_VARS:BOOL - Enable auto-generated vars installation(packages generat

### Preparation

In order to perform out-of-source build you have to create a build directory somewhere and go there:
In order to perform out-of-source build you have to create a build directory and go there:

```bash
mkdir /tmp/my-build
Expand Down Expand Up @@ -148,6 +146,50 @@ cmake <options> ..
cpack
```

## TBBConfig - integration of binary packages

It is a configuration module that is used for integration of prebuilt oneTBB. It consists of two files (TBBConfig.cmake and TBBConfigVersion.cmake) and can be used via [find_package](https://cmake.org/cmake/help/latest/command/find_package.html) function.

How to use this module in your CMake project:
1. Let CMake know where to search for TBBConfig, e.g. specify location of TBBConfig.cmake in `TBB_DIR` (for more details about search paths see [find_package](https://cmake.org/cmake/help/latest/command/find_package.html)).
2. Use [find_package](https://cmake.org/cmake/help/latest/command/find_package.html) to find oneTBB.
3. Use provided variables and/or imported targets (described below) to work with the found oneTBB.

Example:

```cmake
add_executable(foo foo.cpp)
find_package(TBB)
target_link_libraries(foo TBB::tbb)
```

oneTBB components can be passed to [find_package](https://cmake.org/cmake/help/latest/command/find_package.html) after keyword ``COMPONENTS`` or ``REQUIRED``.
Use basic names of components (`tbb`, `tbbmalloc`, etc.).

If components are not specified then the default set is used: `tbb`, `tbbmalloc` and ``tbbmalloc_proxy``.

If `tbbmalloc_proxy` is requested, `tbbmalloc` component will also be added and set as dependency for `tbbmalloc_proxy`.

TBBConfig creates [imported targets](https://cmake.org/cmake/help/latest/manual/cmake-buildsystem.7.html#imported-targets>) as
shared libraries using the following format: `TBB::<component>` (for example, `TBB::tbb`, `TBB::tbbmalloc`).

Set `TBB_FIND_RELEASE_ONLY` to `TRUE` before calling `find_package` in order to search only for release oneTBB version. This variable helps to avoid simultaneous linkage of release and debug oneTBB versions when CMake configuration is `Debug` but a third-party component depends on release oneTBB version.

Variables set during TBB configuration:

Variable | Description
--- | ---
`TBB_FOUND` | oneTBB is found
`TBB_<component>_FOUND` | Specific oneTBB component is found
`TBB_VERSION` | oneTBB version (format: `<major>.<minor>.<patch>.<tweak>`)
`TBB_IMPORTED_TARGETS` | All created oneTBB imported targets (not supported for builds from source code)

Starting from [oneTBB 2021.1-beta08](https://github.com/oneapi-src/oneTBB/releases/tag/v2021.1-beta08) GitHub release TBBConfig files in the binary packages are located under `<tbb-root>/lib[/<intel64|ia32>]/cmake/TBB`.
For example, for Linux 64-bit `TBB_DIR` should be set to `<tbb-root>/lib/intel64/cmake/TBB`.

TBBConfig files are automatically created during the build from source code and can be installed together with the library.
Also oneTBB provides a helper function that creates TBBConfig files from predefined templates: see `tbb_generate_config` in `cmake/config_generation.cmake`.

## oneTBB Python Module support
`TBB4PY_BUILD` Cmake option provides ability to build Python module for oneTBB.

Expand Down
98 changes: 98 additions & 0 deletions cmake/config_generation.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
# Copyright (c) 2020 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Save current location,
# see for details: https://cmake.org/cmake/help/latest/variable/CMAKE_CURRENT_LIST_DIR.html
set(_tbb_gen_cfg_path ${CMAKE_CURRENT_LIST_DIR})

include(CMakeParseArguments)

function(tbb_generate_config)
set(options HANDLE_SUBDIRS)
set(oneValueArgs INSTALL_DIR
SYSTEM_NAME
SIZEOF_VOID_P # 4 for 32 bit, 8 for 64 bit.
LIB_REL_PATH INC_REL_PATH DLL_REL_PATH
VERSION
TBB_BINARY_VERSION
TBBMALLOC_BINARY_VERSION
TBBMALLOC_PROXY_BINARY_VERSION
TBBBIND_BINARY_VERSION)

cmake_parse_arguments(tbb_gen_cfg "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})

get_filename_component(config_install_dir ${tbb_gen_cfg_INSTALL_DIR} ABSOLUTE)
file(MAKE_DIRECTORY ${config_install_dir})

file(TO_CMAKE_PATH "${tbb_gen_cfg_LIB_REL_PATH}" TBB_LIB_REL_PATH)
file(TO_CMAKE_PATH "${tbb_gen_cfg_DLL_REL_PATH}" TBB_DLL_REL_PATH)
file(TO_CMAKE_PATH "${tbb_gen_cfg_INC_REL_PATH}" TBB_INC_REL_PATH)

set(TBB_SIZEOF_VOID_P "${tbb_gen_cfg_SIZEOF_VOID_P}")

set(TBB_VERSION ${tbb_gen_cfg_VERSION})

set(TBB_COMPONENTS_BIN_VERSION "
set(_tbb_bin_version ${tbb_gen_cfg_TBB_BINARY_VERSION})
set(_tbbmalloc_bin_version ${tbb_gen_cfg_TBBMALLOC_BINARY_VERSION})
set(_tbbmalloc_proxy_bin_version ${tbb_gen_cfg_TBBMALLOC_PROXY_BINARY_VERSION})
set(_tbbbind_bin_version ${tbb_gen_cfg_TBBBIND_BINARY_VERSION})
")

if (tbb_gen_cfg_SYSTEM_NAME STREQUAL "Linux")
set(TBB_LIB_PREFIX "lib")
set(TBB_LIB_EXT "so.\${_\${_tbb_component}_bin_version}")
set(TBB_IMPLIB_RELEASE "")
set(TBB_IMPLIB_DEBUG "")
if (tbb_gen_cfg_HANDLE_SUBDIRS)
set(TBB_HANDLE_SUBDIRS "
set(_tbb_subdir gcc4.8)
")
endif()
elseif (tbb_gen_cfg_SYSTEM_NAME STREQUAL "Darwin")
set(TBB_LIB_PREFIX "lib")
set(TBB_LIB_EXT "\${_\${_tbb_component}_bin_version}.dylib")
set(TBB_IMPLIB_RELEASE "")
set(TBB_IMPLIB_DEBUG "")
elseif (tbb_gen_cfg_SYSTEM_NAME STREQUAL "Windows")
set(TBB_LIB_PREFIX "")
set(TBB_LIB_EXT "dll")
set(TBB_COMPILE_DEFINITIONS "
INTERFACE_COMPILE_DEFINITIONS \"__TBB_NO_IMPLICIT_LINKAGE=1\"")

# .lib files installed to TBB_LIB_REL_PATH (e.g. <prefix>/lib);
# .dll files installed to TBB_DLL_REL_PATH (e.g. <prefix>/bin);
# Expand TBB_LIB_REL_PATH here in IMPORTED_IMPLIB property and
# redefine it with TBB_DLL_REL_PATH value to properly fill IMPORTED_LOCATION property in TBBConfig.cmake.in template.
set(TBB_IMPLIB_RELEASE "
IMPORTED_IMPLIB_RELEASE \"\${CMAKE_CURRENT_LIST_DIR}/${TBB_LIB_REL_PATH}/\${_tbb_subdir}/\${_tbb_component}.lib\"")
set(TBB_IMPLIB_DEBUG "
IMPORTED_IMPLIB_DEBUG \"\${CMAKE_CURRENT_LIST_DIR}/${TBB_LIB_REL_PATH}/\${_tbb_subdir}/\${_tbb_component}_debug.lib\"")
set(TBB_LIB_REL_PATH ${TBB_DLL_REL_PATH})

if (tbb_gen_cfg_HANDLE_SUBDIRS)
set(TBB_HANDLE_SUBDIRS "
set(_tbb_subdir vc14)
if (WINDOWS_STORE)
set(_tbb_subdir \${_tbb_subdir}_uwp)
endif()
")
endif()
else()
message(FATAL_ERROR "Unsupported OS name: ${tbb_system_name}")
endif()

configure_file(${_tbb_gen_cfg_path}/templates/TBBConfig.cmake.in ${config_install_dir}/TBBConfig.cmake @ONLY)
configure_file(${_tbb_gen_cfg_path}/templates/TBBConfigVersion.cmake.in ${config_install_dir}/TBBConfigVersion.cmake @ONLY)
endfunction()
86 changes: 72 additions & 14 deletions cmake/modules/FindHWLOC.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,82 @@
# See the License for the specific language governing permissions and
# limitations under the License.

if (NOT HWLOC_FOUND)
find_path(HWLOC_INCLUDE_DIRS
include(FindPackageHandleStandardArgs)

# Firstly search for HWLOC in config mode (i.e. search for HWLOCConfig.cmake).
find_package(HWLOC QUIET CONFIG)
if (HWLOC_FOUND)
find_package_handle_standard_args(HWLOC CONFIG_MODE)
return()
endif()

find_program(_hwloc_info_exe
NAMES hwloc-info
PATHS ENV HWLOC_ROOT ENV PATH
PATH_SUFFIXES bin
)

if (_hwloc_info_exe)
execute_process(
COMMAND ${_hwloc_info_exe} "--version"
OUTPUT_VARIABLE _hwloc_info_output
OUTPUT_STRIP_TRAILING_WHITESPACE
)

string(REGEX MATCH "([0-9]+.[0-9]+.[0-9]+)$" HWLOC_VERSION "${_hwloc_info_output}")
if ("${HWLOC_VERSION}" STREQUAL "")
unset(HWLOC_VERSION)
endif()

unset(_hwloc_info_output)
unset(_hwloc_info_exe)
endif()

if (WIN32)
list(APPEND _additional_lib_dirs ENV PATH ENV LIB)
list(APPEND _additional_include_dirs ENV INCLUDE ENV CPATH)
set(_hwloc_lib_name libhwloc)
else()
list(APPEND _additional_lib_dirs ENV LIBRARY_PATH ENV LD_LIBRARY_PATH ENV DYLD_LIBRARY_PATH)
list(APPEND _additional_include_dirs ENV CPATH ENV C_INCLUDE_PATH ENV CPLUS_INCLUDE_PATH ENV INCLUDE_PATH)
set(_hwloc_lib_name hwloc)
endif()

if (NOT TARGET HWLOC::hwloc)
find_path(_hwloc_include_dirs
NAMES hwloc.h
HINTS $ENV{INCLUDE} $ENV{CPATH} $ENV{C_INCLUDE_PATH} $ENV{INCLUDE_PATH}
PATHS ${_additional_include_dirs}
PATH_SUFFIXES "hwloc")

if (UNIX)
set(HWLOC_LIB_NAME hwloc)
elseif(WIN32)
set(HWLOC_LIB_NAME libhwloc)
if (_hwloc_include_dirs)
add_library(HWLOC::hwloc SHARED IMPORTED)
set_property(TARGET HWLOC::hwloc APPEND PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${_hwloc_include_dirs})

find_library(_hwloc_lib_dirs ${_hwloc_lib_name} PATHS ${_additional_lib_dirs})
if (_hwloc_lib_dirs)
if (WIN32)
set_target_properties(HWLOC::hwloc PROPERTIES
IMPORTED_LOCATION "${_hwloc_lib_dirs}"
IMPORTED_IMPLIB "${_hwloc_lib_dirs}")
else()
set_target_properties(HWLOC::hwloc PROPERTIES
IMPORTED_LOCATION "${_hwloc_lib_dirs}")
endif()

set(HWLOC_FOUND 1)
endif()
endif()
endif()

find_library(HWLOC_LIBRARIES
NAMES ${HWLOC_LIB_NAME}
HINTS $ENV{LIBRARY_PATH} $ENV{LD_LIBRARY_PATH} $ENV{DYLD_LIBRARY_PATH})
unset(_additional_include_dirs CACHE)
unset(_additional_lib_dirs CACHE)
unset(_hwloc_lib_name CACHE)

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(HWLOC DEFAULT_MSG HWLOC_LIBRARIES HWLOC_INCLUDE_DIRS)
find_package_handle_standard_args(
HWLOC
REQUIRED_VARS _hwloc_include_dirs _hwloc_lib_dirs
VERSION_VAR HWLOC_VERSION
)

mark_as_advanced(HWLOC_LIB_NAME)
endif()
unset(_hwloc_include_dirs CACHE)
unset(_hwloc_lib_dirs CACHE)
57 changes: 57 additions & 0 deletions cmake/scripts/cmake_gen_github_configs.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Copyright (c) 2020 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

include(${CMAKE_CURRENT_LIST_DIR}/../config_generation.cmake)

# TBBConfig in TBB provided packages are expected to be placed into: <tbb-root>/lib[/<intel64|ia32>]/cmake/TBB
set(WIN_LIN_INC_REL_PATH "../../../../include")
set(DARWIN_INC_REL_PATH "../../../include")
set(LIB_REL_PATH "../..")
set(DLL_REL_PATH "../../../../redist") # ia32/intel64 subdir is appended depending on configuration.

# Parse version info
file(READ ${CMAKE_CURRENT_LIST_DIR}/../../include/tbb/version.h _tbb_version_info)
string(REGEX REPLACE ".*#define TBB_VERSION_MAJOR ([0-9]+).*" "\\1" _tbb_ver_major "${_tbb_version_info}")
string(REGEX REPLACE ".*#define TBB_VERSION_MINOR ([0-9]+).*" "\\1" _tbb_ver_minor "${_tbb_version_info}")
string(REGEX REPLACE ".*#define TBB_INTERFACE_VERSION ([0-9]+).*" "\\1" _tbb_interface_ver "${_tbb_version_info}")
string(REGEX REPLACE ".*#define __TBB_BINARY_VERSION ([0-9]+).*" "\\1" TBB_BINARY_VERSION "${_tbb_version_info}")
file(READ ${CMAKE_CURRENT_LIST_DIR}/../../CMakeLists.txt _tbb_cmakelist)
string(REGEX REPLACE ".*TBBMALLOC_BINARY_VERSION ([0-9]+).*" "\\1" TBBMALLOC_BINARY_VERSION "${_tbb_cmakelist}")
set(TBBMALLOC_PROXY_BINARY_VERSION ${TBBMALLOC_BINARY_VERSION})
string(REGEX REPLACE ".*TBBBIND_BINARY_VERSION ([0-9]+).*" "\\1" TBBBIND_BINARY_VERSION "${_tbb_cmakelist}")

# Parse patch and tweak versions from interface version: e.g. 12014 --> 01 - patch version, 4 - tweak version.
math(EXPR _tbb_ver_patch "${_tbb_interface_ver} % 1000 / 10")
math(EXPR _tbb_ver_tweak "${_tbb_interface_ver} % 10")

# Applicable for beta releases.
if (_tbb_ver_patch EQUAL 0)
math(EXPR _tbb_ver_tweak "${_tbb_ver_tweak} + 6")
endif()

set(COMMON_ARGS
LIB_REL_PATH ${LIB_REL_PATH}
VERSION ${_tbb_ver_major}.${_tbb_ver_minor}.${_tbb_ver_patch}.${_tbb_ver_tweak}
TBB_BINARY_VERSION ${TBB_BINARY_VERSION}
TBBMALLOC_BINARY_VERSION ${TBBMALLOC_BINARY_VERSION}
TBBMALLOC_PROXY_BINARY_VERSION ${TBBMALLOC_PROXY_BINARY_VERSION}
TBBBIND_BINARY_VERSION ${TBBBIND_BINARY_VERSION}
)

tbb_generate_config(INSTALL_DIR ${INSTALL_DIR}/linux-32 SYSTEM_NAME Linux INC_REL_PATH ${WIN_LIN_INC_REL_PATH} SIZEOF_VOID_P 4 HANDLE_SUBDIRS ${COMMON_ARGS})
tbb_generate_config(INSTALL_DIR ${INSTALL_DIR}/linux-64 SYSTEM_NAME Linux INC_REL_PATH ${WIN_LIN_INC_REL_PATH} SIZEOF_VOID_P 8 HANDLE_SUBDIRS ${COMMON_ARGS})
tbb_generate_config(INSTALL_DIR ${INSTALL_DIR}/windows-32 SYSTEM_NAME Windows INC_REL_PATH ${WIN_LIN_INC_REL_PATH} SIZEOF_VOID_P 4 HANDLE_SUBDIRS DLL_REL_PATH ${DLL_REL_PATH}/ia32 ${COMMON_ARGS})
tbb_generate_config(INSTALL_DIR ${INSTALL_DIR}/windows-64 SYSTEM_NAME Windows INC_REL_PATH ${WIN_LIN_INC_REL_PATH} SIZEOF_VOID_P 8 HANDLE_SUBDIRS DLL_REL_PATH ${DLL_REL_PATH}/intel64 ${COMMON_ARGS})
tbb_generate_config(INSTALL_DIR ${INSTALL_DIR}/darwin SYSTEM_NAME Darwin INC_REL_PATH ${DARWIN_INC_REL_PATH} SIZEOF_VOID_P 8 ${COMMON_ARGS})
message(STATUS "TBBConfig files were created in ${INSTALL_DIR}")
Loading

0 comments on commit 8632c27

Please sign in to comment.