Skip to content

Commit

Permalink
Commit oneTBB source code e0cc518
Browse files Browse the repository at this point in the history
  • Loading branch information
tbbdev committed Jan 25, 2022
1 parent 3df08fe commit 4533e4f
Show file tree
Hide file tree
Showing 178 changed files with 4,272 additions and 2,108 deletions.
2 changes: 1 addition & 1 deletion .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@
# use Bazel internally. The Bazel build can have security risks or
# optimization gaps.

build --symlink_prefix=/ # Out of source build
build --symlink_prefix=/ # Out of source build
2 changes: 1 addition & 1 deletion .bazelversion
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4.1.0
4.2.1
2 changes: 2 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ _Add comprehensive description of proposed changes_

Fixes # - _issue number(s) if exists_

- [ ] - git commit message contains appropriate signed-off-by string _(see [CONTRIBUTING.md](https://github.com/oneapi-src/oneTBB/blob/master/CONTRIBUTING.md#pull-requests) for details)_

### Type of change

_Choose one or multiple, leave empty if none of the other choices apply_
Expand Down
5 changes: 3 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,9 @@ jobs:
- uses: actions/checkout@v2
- name: Run scan
run: |
command -v clang-format-10
cp -r examples examples_formatted
find examples_formatted -regex '.*\.\(cpp\|hpp\)' -exec clang-format-9 -style=file -i {} \;
find examples_formatted -regex '.*\.\(cpp\|hpp\)' -exec clang-format-10 -style=file -i {} \;
diff -r examples examples_formatted
documentation:
Expand All @@ -67,7 +68,7 @@ jobs:
mkdir html
- name: Build documentation
run: |
export BUILD_TYPE=${BUILD_TYPE} && sphinx-build doc/main html
export BUILD_TYPE=${BUILD_TYPE} && sphinx-build doc html
tar -czvf html.tar.gz html/
- name: Save docs
uses: actions/[email protected]
Expand Down
9 changes: 6 additions & 3 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,12 @@ cc_library(
"include/oneapi/tbb/*.h",
"include/oneapi/tbb/detail/*.h",
]),
copts = [
"-w",
],
copts = ["-w"] + select({
"@bazel_tools//platforms:windows": [
"",
],
"//conditions:default": ["-mwaitpkg"],
}),
defines =
select({
"@platforms//cpu:x86_64": ["__TBB_NO_IMPLICIT_LINKAGE"],
Expand Down
74 changes: 55 additions & 19 deletions Bazel.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,38 @@
# Bazel build support
# Bazel* build support

The main build system of oneTBB is CMake.
Bazel support is community-based.
The maintainers do not use Bazel internally.
The Bazel configuration may not include recommended compiler and linker flags used in official CMake configuration.
The main build system of oneTBB is CMake*.
[Bazel*](https://bazel.build/) support is community-based.
The Bazel configuration may not include recommended compiler and/or linker flags used in the official CMake configuration.

The Bazel build of oneTBB currently only aims for a subset of oneTBB that suffices restricted use cases of the usage of oneTBB.
Pull requests to improve the Bazel build experience are welcomed.
---
**NOTE**

The standard approach of how Bazel handles third-party libraries is static linking.
Even this is not recommended by the oneTBB maintainers this is chosen since this is considered as the best practice in the Bazel ecosystem.
Bazel is not recommended for use by oneTBB maintainers. Thus, it is not used internally.

## Example usage
---

1. [Install Bazel](https://docs.bazel.build/versions/main/install.html).

2. Create the following files in one folder (this folder will be considered as the workspace folder):
The Bazel oneTBB build is currently only intended for a subset of oneTBB that suffices restricted use cases.
Pull requests to improve the Bazel build experience are welcome.

_WORKSPACE.bazel_:
The standard Bazel approach to handling third-party libraries is static linking. It is the best practice within the Bazel ecosystem.

## Using oneTBB as a dependency

This example demonstrates how to use oneTBB as a dependency within a Bazel project.

The following file structure is assumed:

```
example
├── .bazelrc
├── BUILD.bazel
├── main.cpp
└── WORKSPACE.bazel
```

_WORKSPACE.bazel_:
```python
load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")

git_repository(
Expand All @@ -28,17 +42,23 @@ git_repository(
)
```

_BUILD_:
```
In the *WORKSPACE* file, the oneTBB GitHub* repository is fetched.

_BUILD.bazel_:

```python
cc_binary(
name = "Demo",
srcs = ["main.cpp"],
deps = ["@oneTBB//:tbb"],
)
```

The *BUILD* file defines a binary named `Demo` that has a dependency to oneTBB.

_main.cpp_:
```

```c++
#include "oneapi/tbb/version.h"

#include <iostream>
Expand All @@ -54,7 +74,23 @@ int main() {
}
```

3. Switch to the folder where you create the files.
The expected output of this program is the current version of oneTBB.

Switch to the folder with the files created earlier and run the binary with `bazel run //:Demo`.

## Build oneTBB using Bazel

Run ```bazel build //...``` in the oneTBB root directory.

## Compiler support

The Bazel build uses the compiler flag `-mwaitpkg` in non-Windows* builds.
This flag is supported by the GNU* Compiler Collection (GCC) version 9.3, Clang* 12, and newer versions of those tools.


---
**NOTE**

To use the Bazel build with earlier versions of GCC, remove `-mwaitpkg` flag as it leads to errors during compilation.

4. Execute the command `bazel run //:Demo`.
As an expected output, you should see the oneTBB version.
---
25 changes: 23 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ unset(_tbb_ver_minor)

include(CheckCXXCompilerFlag)
include(GNUInstallDirs)
include(CMakeDependentOption)

# ---------------------------------------------------------------------------------------------------------
# Handle C++ standard version.
Expand Down Expand Up @@ -100,9 +101,11 @@ option(TBB_NO_APPCONTAINER "Apply /APPCONTAINER:NO (for testing binaries for Win
option(TBB4PY_BUILD "Enable tbb4py build" OFF)
option(TBB_BUILD "Enable tbb build" ON)
option(TBBMALLOC_BUILD "Enable tbbmalloc build" ON)
cmake_dependent_option(TBBMALLOC_PROXY_BUILD "Enable tbbmalloc_proxy build" ON "TBBMALLOC_BUILD" OFF)
option(TBB_CPF "Enable preview features of the library" OFF)
option(TBB_FIND_PACKAGE "Enable search for external oneTBB using find_package instead of build from sources" OFF)
option(TBB_DISABLE_HWLOC_AUTOMATIC_SEARCH "Disable HWLOC automatic search by pkg-config tool" OFF)
option(TBB_ENABLE_IPO "Enable Interprocedural Optimization (IPO) during the compilation" ON)

if (NOT DEFINED BUILD_SHARED_LIBS)
set(BUILD_SHARED_LIBS ON)
Expand Down Expand Up @@ -181,6 +184,22 @@ foreach(FILE_WITH_EXTRA_TARGETS ${FILES_WITH_EXTRA_TARGETS})
include(${FILE_WITH_EXTRA_TARGETS})
endforeach()

# - Enabling LTO on Android causes the NDK bug.
# NDK throws the warning: "argument unused during compilation: '-Wa,--noexecstack'"
# - For some reason GCC does not instrument code with Thread Sanitizer when lto is enabled and C linker is used.
if (TBB_ENABLE_IPO AND BUILD_SHARED_LIBS AND NOT ANDROID_PLATFORM AND NOT TBB_SANITIZE MATCHES "thread")
if (NOT CMAKE_VERSION VERSION_LESS 3.9)
cmake_policy(SET CMP0069 NEW)
include(CheckIPOSupported)
check_ipo_supported(RESULT TBB_IPO_PROPERTY)
else()
set(TBB_IPO_FLAGS TRUE)
endif()
if (TBB_IPO_PROPERTY OR TBB_IPO_FLAGS)
message(STATUS "IPO enabled")
endif()
endif()

set(TBB_COMPILER_SETTINGS_FILE ${CMAKE_CURRENT_SOURCE_DIR}/cmake/compilers/${CMAKE_CXX_COMPILER_ID}.cmake)
if (EXISTS ${TBB_COMPILER_SETTINGS_FILE})
include(${TBB_COMPILER_SETTINGS_FILE})
Expand All @@ -200,9 +219,11 @@ else()
if (NOT "${CMAKE_SYSTEM_PROCESSOR}" MATCHES "mips")
if (TBBMALLOC_BUILD)
add_subdirectory(src/tbbmalloc)
add_subdirectory(src/tbbmalloc_proxy)
if(TBBMALLOC_PROXY_BUILD AND NOT "${MSVC_CXX_ARCHITECTURE_ID}" MATCHES "ARM64")
add_subdirectory(src/tbbmalloc_proxy)
endif()
endif()
if (APPLE)
if (APPLE OR NOT BUILD_SHARED_LIBS)
message(STATUS "TBBBind build targets are disabled due to unsupported environment")
else()
add_subdirectory(src/tbbbind)
Expand Down
122 changes: 122 additions & 0 deletions INSTALL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
# Installation from Sources


## Prerequisites

- Make sure you have installed CMake version 3.1 (or newer) on your system. oneTBB uses CMake build configuration.
- Configure and build oneTBB. To work with build configurations, see [Build System Description](cmake/README.md).


## Configure oneTB

At the command prompt, type:
```
cmake <options> <repo_root>
```

You may want to use some additional options for configuration:

| Option | Purpose | Description |
| ------ |------ | ------ |
| `-G <generator>` | Specify project generator | For more information, run cmake `–help`. |
|`-DCMAKE_BUILD_TYPE=Debug` | Specify for Debug build | Not applicable for multi-configuration generators such as Visual Studio generator. |


## Build oneTBB

To build the system, run:
```
cmake --build . <options>
```

Some useful build options:
- `--target <target>` - specific target, "all" is default.
- `--config <Release|Debug>` - build configuration, applicable only for multi-config generators such as Visual Studio generator.


## Install and Pack oneTBB

---
**NOTE**

Be careful about installing prefix. It defaults to `/usr/local` on UNIX* and `c:/Program Files/${PROJECT_NAME}` on Windows* OS.
You can define custom `CMAKE_INSTALL_PREFIX` during configuration:

```
cmake -DCMAKE_INSTALL_PREFIX=/my/install/prefix ..
```

---

Installation can also be done using:

```
cmake --install <project-binary-dir>
```

Special ``--install`` target can alternatively be used for installation, e.g. ``make install``.

You can use the ``install`` components for partial installation.

The following install components are supported:
- `runtime` - oneTBB runtime package (core shared libraries and `.dll` files on Windows* OS).
- `devel` - oneTBB development package (header files, CMake integration files, library symbolic links, and `.lib` files on Windows* OS).
- `tbb4py` - [oneTBB Module for Python](#onetbb-python-module-support).

If you want to install specific components after configuration and build, run:

```bash
cmake -DCOMPONENT=<component> [-DBUILD_TYPE=<build-type>] -P cmake_install.cmake
```

Simple packaging using CPack is supported.
The following commands allow you to create a simple portable package that includes header files, libraries, and integration files for CMake:

```bash
cmake <options> ..
cpack
```

## Example of Installation

### Single-configuration generators

The following example demonstrates how to install oneTBB for single-configuration generators (e.g. GNU Make, Ninja, etc.).
```bash
# Do our experiments in /tmp
cd /tmp
# Clone oneTBB repository
git clone https://github.com/oneapi-src/oneTBB.git
cd oneTBB
# Create binary directory for out-of-source build
mkdir build && cd build
# Configure: customize CMAKE_INSTALL_PREFIX and disable TBB_TEST to avoid tests build
cmake -DCMAKE_INSTALL_PREFIX=/tmp/my_installed_onetbb -DTBB_TEST=OFF ..
# Build
cmake --build .
# Install
cmake --install .
# Well done! Your installed oneTBB is in /tmp/my_installed_onetbb
```

### Multi-configuration generators

The following example demonstrates how to install oneTBB for multi-configuration generators such as Visual Studio*.

Choose the configuration during the build and install steps:
```batch
REM Do our experiments in %TMP%
cd %TMP%
REM Clone oneTBB repository
git clone https://github.com/oneapi-src/oneTBB.git
cd oneTBB
REM Create binary directory for out-of-source build
mkdir build && cd build
REM Configure: customize CMAKE_INSTALL_PREFIX and disable TBB_TEST to avoid tests build
cmake -DCMAKE_INSTALL_PREFIX=%TMP%\my_installed_onetbb -DTBB_TEST=OFF ..
REM Build "release with debug information" configuration
cmake --build . --config relwithdebinfo
REM Install "release with debug information" configuration
cmake --install . --config relwithdebinfo
REM Well done! Your installed oneTBB is in %TMP%\my_installed_onetbb
```
Loading

0 comments on commit 4533e4f

Please sign in to comment.