README.md 13.3 KB
Newer Older
1
Embedded Multicore Building Blocks (EMB²)
2 3
=========================================

4 5
Introduction
------------
6

7
### Overview
8 9 10 11 12 13

The Embedded Multicore Building Blocks (EMB²) are an easy to use yet powerful and efficient C/C++ library for the development of parallel applications. EMB² has been specifically designed for embedded systems and the typical requirements that accompany them, such as real-time capability and constraints on memory consumption. As a major advantage, low-level operations are hidden in the library which relieves software developers from the burden of thread management and synchronization. This not only improves productivity of parallel software development, but also results in increased reliability and performance of the applications.

EMB² is independent of the hardware architecture (x86, ARM, ...) and runs on various platforms, from small devices to large systems containing numerous processor cores. It builds on MTAPI, a standardized programming interface for leveraging task parallelism in embedded systems containing symmetric or asymmetric (heterogeneous) multicore processors. A core feature of MTAPI is low-overhead scheduling of fine-grained tasks among the available cores during runtime. Unlike existing libraries, EMB² supports task priorities and affinities, which allows the creation of soft real-time systems. Additionally, the scheduling strategy can be optimized for non-functional requirements such as minimal latency and fairness.

Besides the task scheduler, EMB² provides basic parallel algorithms, concurrent data structures, and skeletons for implementing stream processing applications (see figure below). These building blocks are largely implemented in a non-blocking fashion, thus preventing frequently encountered pitfalls like lock contention, deadlocks, and priority inversion. As another advantage in real-time systems, the algorithms and data structures give certain progress guarantees. For example, wait-free data structures guarantee system-wide progress which means that every operation completes within a finite number of steps independently of any other concurrent operations on the same data structure.
14

15
<img src="doc/images/embb.png" alt="Building blocks of EMB²" width="500"/>
16

17
### Important Links
18

19
GitHub:
Tobias Schuele committed
20
  - https://github.com/siemens/embb
21

22
Repository:
Tobias Schuele committed
23 24
  - https://github.com/siemens/embb.git (HTTP)
  - git@github.com:siemens/embb.git (SSH)
25

26
Mailing list:
27 28 29 30
  - embb-announcements@googlegroups.com (low volume, release announcements, news, etc.)<br/>
    Join: https://groups.google.com/forum/#!forum/embb-announcements/join
	
Community:
Tobias Schuele committed
31
  - https://github.com/siemens/embb/issues (for help, create an issue labeled with 'question').
32

Tobias Schuele committed
33
Contact:
34
  - embb.info@gmail.com
35

36
### License
37

38
See the file [COPYING.md](https://github.com/siemens/embb/blob/master/COPYING.md) in the project's root directory.
39

40
### Contributions
41

42
See the file [CONTRIBUTING.md](https://github.com/siemens/embb/blob/master/CONTRIBUTING.md) in the project's root directory.
43

44 45
Build and Installation
----------------------
46

47
### General
48

49 50 51 52
It is strongly recommended to build from a release file and not from a repository snapshot in order to get the documentation and the examples out-of-the box. The release files can be found at https://github.com/siemens/embb/releases.

### Platforms

53
EMB² is regularly built and tested on a variety of OS/compiler/architecture combinations including Linux (x86 and ARM using GCC/Clang) and Windows (x86 using MSVC). Other platforms may be supported without any changes to the source code. The included unit tests can be used to find out whether a system not officially supported is suitable to run EMB². If the build process or the unit tests fail on your system, please contact us.
54 55 56

### Prerequisites

Tobias Schuele committed
57
The project is based on the standards C99 (for C code) and C++03 (for C++ code) to be usable on a wide range of target systems. Besides a C/C++ compiler supporting these standards, [CMake](https://cmake.org/) 2.8.9 or higher is required to build EMB² (CMake is a build file generator which abstracts from the concrete build tools).
58

59
### Quick Installation on Linux
60

61
To generate and invoke the platform-specific build files, open a shell and change to the project's root directory. Create a subdirectory, where you want to build the library, e.g., "build", and change to that subdirectory. In the following, it is assumed that the project's root directory is the parent directory. Now you can generate the build files using CMake:
62 63 64

    cmake ..

65
As the next step, compile EMB²:
66 67 68 69 70 71 72 73 74 75 76 77 78

    cmake --build .

After compilation has finished, execute the tests:

    binaries/run_tests.sh

Finally, install EMB² (the default path is `/usr/local`):

    sudo cmake --build . --target install

### Quick Installation on Windows

79
To generate and invoke the platform-specific build files, open a Developer Command Prompt for Visual Studio and change to the project's root directory. Create a subdirectory, where you want to build the library, e.g., "build", and change to that subdirectory. In the following, it is assumed that the project's root directory is the parent directory. Now you can generate the build files using CMake (a list of supported CMake generators can be displayed by typing `cmake --help`). For example:
80 81 82

    cmake -G "Visual Studio 14 2015" ..

83
As the next step, compile EMB²:
84 85 86 87 88 89 90

    cmake --build . --config Release

After compilation has finished, execute the tests:

    binaries\run_tests.bat

91
Finally, install EMB² with *administrator privileges*:
92 93

    cmake --build . --target install --config Release
94

95
### Detailed Installation Instructions
96

97
EMB² provides several options which allow you to configure it to your needs. This section explains these options and describes the build process in more detail.
98

99
#### 1. Generation of Native Build Files
100

101
As mentioned above, it is recommended to build EMB² in a subdirectory such as "build". The actual build files are generated by the following command (a list of available generators can be displayed by typing `cmake --help`):
102

Roger Meier committed
103
    cmake -G <generator> .. [OPTIONS]
104

105
Note that on Linux, the architecture (32/64 bit) cannot be selected by the generator. The default is "Unix Makefiles" for which reason `-G <generator>` may be omitted.
106

107
EMB² can be built in Release or Debug mode. The latter contains additional checks during runtime and is only recommended for development purposes. On Linux, the build mode can be specified using the option `-DCMAKE_BUILD_TYPE=[Release|Debug]`, for example:
108

109
     cmake .. -DCMAKE_BUILD_TYPE=Debug
110

111
If no build mode is given, the default (Release) is used. The Visual Studio generators create build files for both modes (the selection is done at build time as described below).
112

113
You may choose a custom compiler instead the default one by defining `CMAKE_CXX_COMPILER` and/or `CMAKE_C_COMPILER`. For example, to use Clang on Linux, type:
114

115
    cmake .. -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_C_COMPILER=clang
116

117
In the same way, you may cross compile to another platform. For example, to cross compile to ARM v7 using GCC, you need to specify the cross compiler itself and the target architecture as an argument to the compiler:
118

119 120 121 122
    cmake .. -DCMAKE_CXX_COMPILER=arm-linux-gnueabi-gcc++ \
             -DCMAKE_CXX_FLAGS=-march=armv7-a \
             -DCMAKE_C_COMPILER=arm-linux-gnueabi-gcc \
             -DCMAKE_C_FLAGS=-march=armv7-a
123

124
EMB² can be built with C++ exception handling (default) or without exceptions. When exceptions are turned off, a message is emitted in case of an error and the program aborts. To disable exceptions, add the option `-DUSE_EXCEPTIONS=OFF`.
125

126
Similarly, automatic initialization of the task scheduler by the MTAPI C++ interface can be disabled with `-DUSE_AUTOMATIC_INITIALIZATION=OFF`. This way, unexpected delays after startup can be avoided, e.g. for timing measurements.
127

128
Furthermore, EMB² can be built to work with threading analysis tools such as Helgrind or ThreadSanitizer with -DTHREADING_ANALYSIS_MODE=ON. This uses mutexes around atomics to avoid false positives but degrades performance significantly.
129

130

131
The tutorial of EMB² comes with a number of examples in `doc/examples/`. These can be built with the other source files using the option `-DBUILD_EXAMPLES=ON`. Note, however, that the examples use C++11 features and require an appropriate compiler.
132

133
By default, the included unit tests are built as part of the installation process. To override the default behavior, add the option `-DBUILD_TESTS=OFF`.
134

135
#### 2. Compiling and Linking
136

137
As the next step, you can compile the library using the generated build files. On Linux, the build mode (Release|Debug) is already given in the build files, whereas on Windows, it has to be specified now.
138 139 140

For a Linux build, type

Roger Meier committed
141
    cmake --build .
142 143 144

For a Windows Release build, type

Roger Meier committed
145
    cmake --build . --config Release
146

147 148 149 150
If you are a developer working on a repository snapshot of EMB², you can build the documentation as follows (provided that you have [Doxygen](http://www.doxygen.org/) installed):

    cmake --build . --target doxygen

151
Note that this is *not* necessary if you build from a release file.
152

153
#### 3. Running the Tests
154

155
To check whether EMB² was compiled correctly, run the tests. The test executables are contained in the subfolder "binaries".
156 157 158

On Linux, type

Roger Meier committed
159
    binaries/run_tests.sh
160 161 162

On Windows, type

Roger Meier committed
163
    binaries\run_tests.bat
164

165
If no error message occurs, EMB² works fine.
166

167
#### 4. Installation
168 169 170

The default installation path on Linux is

Roger Meier committed
171
    /usr/local/
172 173 174

and on Windows

175 176 177 178 179
    C:\Program Files\embb-X.Y.Z\

or

    C:\Program Files (x86)\embb-X.Y.Z
180 181 182 183 184

depending on the target architecture.

If you want a different installation path, you can change it now by typing

Roger Meier committed
185
    cmake -DINSTALL_PREFIX=YourCustomPath ..
186 187 188

To install the files, use the command

Roger Meier committed
189
    cmake --build . --target install
190

191
which copies the contents of the "install" folder to the "bin", "lib", and "include" folders in the installation path. For the default paths, the installation has to be run with administrator / root privileges.
192 193

Using the Library
194
-----------------
195

196 197 198 199 200 201 202 203 204 205
### Components

For some of the components, there exist C and C++ versions, wheras others are only implemented in C++. The directory names are postfixed with either "_cpp" or "_c" for the C++ and C versions, respectively. Currently, EMB² is composed of the following components:

  - Base library: base_c, base_cpp
  - MTAPI: mtapi_c, mtapi_cpp, and mtapi_plugins_c (mtapi_network_c, mtapi_opencl_c, mtapi_cuda_c)
  - Algorithms: algorithms_cpp
  - Dataflow: dataflow_cpp
  - Containers: containers_cpp

206
Directory "base_c" contains abstractions for threading, synchronization, atomic operations, and other functionalities. As the name indicates, the code is implemented in C. Directory "base_cpp" contains C++ wrappers around the "base_c" functions. Similarly, the MTAPI task scheduler is available for programs written in C ("mtapi_c") or C++ ("mtapi_cpp"). Heterogeneous and distributed systems are supported via the plugins contained in "mtapi_plugins_c". Directory "algorithms_cpp" provides high-level constructs for typical parallelization tasks in C++, and "dataflow_cpp" generic skeletons for the development of parallel stream-based applications. Finally, "containers_cpp" provides data structures for storing objects in a thread-safe way.
207

208
### Using C++
209

210
If you want to use the C++ functionalities of EMB², you have to link the following libraries (names will be slightly different on Windows and on Linux) in the given order:
211

212
    embb_dataflow_cpp, embb_algorithms_cpp, embb_containers_cpp, embb_mtapi_cpp, embb_mtapi_c, embb_base_cpp, embb_base_c
213 214 215

The C++ header files can be included as follows:

Roger Meier committed
216
    #include<embb/base/base.h>
217
    #include<embb/mtapi/mtapi.h>
Roger Meier committed
218
    #include<embb/containers/containers.h>
219
    #include<embb/dataflow/algorithms.h>
Roger Meier committed
220
    #include<embb/dataflow/dataflow.h>
221

222
### Using C
223

224
If you only want to use the C versions of MTAPI and the base library, link them in the following order:
225

226
    embb_mtapi_c, embb_base_c
227 228 229

The C header files can be included as follows:

Roger Meier committed
230
    #include<embb/base/c/base.h>
231 232
    #include<embb/mtapi/c/mtapi.h>

233
Alternatively, you can include MTAPI by `#include<mtapi.h>`.
234

235
### Documentation
236

237
The release files of EMB² come with a tutorial, example programs, and a reference manual (HTML) describing the APIs. All documentation is contained in the "doc" folder. The root document of the HTML reference is `doc/reference/index.html`. Note that the generated documentation files are not under version control and hence not contained in the repository. As mentioned above, it is therefore recommended to download one of the packaged release files in order to have ready-to-use documentation.
238

239
### Limitations and Important Notes
Tobias Schuele committed
240

241 242 243
- For memory management reasons, the number of threads EMB² can deal with is bounded by a predefined but modifiable constant (see functions `embb_thread_get_max_count()` / `embb_thread_set_max_count()` and class `embb::base::Thread`).
- The MTAPI C++ interface supports automatic initialization, which allows for easy usage of the MTAPI C++, Algorithms, and Dataflow components. For performance measurements, explicit initialization is strongly recommended since the measurements will otherwise include the initialization time of MTAPI.
- When using ThreadSanitizer, a bug causes the built-in CMake type size determination to fail which in turn leads to a broken configuration. Therefore, you have to do a normal build first and then run CMake again with flags and libs configured for ThreadSanitizer.