PageRenderTime 56ms CodeModel.GetById 28ms RepoModel.GetById 1ms app.codeStats 0ms

/doc/README.md

https://gitlab.com/mmoelle1/UETLI
Markdown | 273 lines | 219 code | 54 blank | 0 comment | 0 complexity | 4fde2f428db03c254a29bc67ffb8e055 MD5 | raw file
  1. UETLI (Unified Expression Template Library Interface) is a C++ wrapper
  2. library that provides a unified interface (API) to several expression
  3. template libraries
  4. - The latest revision of the **UETLI** library is available at
  5. https://gitlab.com/mmoelle1/UETLI.
  6. - The latest documentation of the **UETLI** library is available at
  7. https://mmoelle1.gitlab.io/UETLI/.
  8. # <a name="contents">Contents</a>
  9. 1. [Introduction](#introduction)
  10. * [Prerequisites](#prerequisites)
  11. * [Coding style](#coding-style)
  12. * [License](#license)
  13. 2. [Getting started](#getting-started)
  14. * [Obtaining the latest code](#obtaining-the-latest-code)
  15. * [Compiling and running the UnitTests](#compiling-and-running-the-unittests)
  16. * [Including UETLI into own codes](#including-uetli-into-own-codes)
  17. 3. [The plain program](#the-plain-program)
  18. ___
  19. # <a name="introduction">Introduction</a>
  20. **UETLI** is a unified expression template library interface written
  21. in C++14 (C++11 by compiler flag) that provides a unified interface
  22. (API) to several of the most widely used expression template
  23. libraries. It is designed as a header-only C++ library that can be
  24. easily integrated into existing codes by including the main header
  25. file `uetli.h`.
  26. ## <a name="prerequisites">Prerequisites</a>
  27. The **UETLI** library makes extensively use of C++11 features (`auto`
  28. keyword, variadic templates, etc.) so that a C++ compiler with full
  29. C++11 support is a prerequisite. Some ETLs, like Blaze, even require
  30. C++14 support. Beside that, additional prerequisites depend on the
  31. specific ETL used. The **UETLI** library currently supports the
  32. following ETLs and compilers (tested under Linux/macOS)
  33. | ETL | Remark | Clang | GCC 4.9 | GCC 5.x | GCC 6.x | PGI 16.10 | OracleStudio 12.5 |
  34. |-----------------------------------------------------------------------|----------------------------------------|-------|---------|---------|---------|-----------|-------------------|
  35. | [Armadillo](http://arma.sourceforge.net) | version 7.800.2 and better | yes | yes | yes | yes | no | yes (1) |
  36. | [Arrayfire](http://arrayfire.com) | version 3.3.x and better | yes | yes | yes | yes | no | yes |
  37. | [Blaze](https://bitbucket.org/blaze-lib/blaze) | version 3.0 and better | yes | yes | yes | yes | no | no |
  38. | [CMTL4](http://www.simunova.com/de/cmtl4) | not tested yet | - | - | - | - | - | - |
  39. | [Eigen](http://eigen.tuxfamily.org/index.php?title=Main_Page) | version 3.2.x and better with patching | yes | yes | yes | yes | no | no |
  40. | [IT++](http://itpp.sourceforge.net) | version 4.3.1 with patching | yes | yes | yes | yes | no | no |
  41. | [MTL4](http://www.simunova.com/de/mtl4) | not fully supported yet | - | - | - | - | - | - |
  42. | [uBLAS](http://www.boost.org/doc/libs/1_60_0/libs/numeric/ublas/doc/) | version 1.58 and better | yes | yes | yes | yes | no | no |
  43. | [VexCL](https://github.com/ddemidov/vexcl) | developer version | yes | yes | yes | yes | no | no |
  44. | [ViennaCL](http://viennacl.sourceforge.net) | developer version | yes | yes | yes | yes | no | no |
  45. (1) OracleStudio 12.5 only supports double-type data and throws an
  46. error of float-type data is used. Moreover, C++14 support is very
  47. limited leading to many errors about missing trailing return type
  48. specification.
  49. ## <a name="coding-style">Coding style</a>
  50. The coding style of the **UETLI** library is based on [Google's C++
  51. style guide](https://google.github.io/styleguide/cppguide.html). The
  52. [ClangFormat](http://clang.llvm.org/docs/ClangFormat.html) tool is
  53. used regularly to ensure a consistent code format.
  54. ## <a name="license">License</a>
  55. The library is licensed under the [Mozilla Public License Version 2.0](https://www.mozilla.org/MPL/2.0).
  56. The MPL is a simple copyleft license. The MPL's "file-level" copyleft
  57. is designed to encourage contributors to share their modifications
  58. with the library, while still allowing them to combine the library
  59. with code under other licenses (open or proprietary) with minimal
  60. restrictions.
  61. ___
  62. # <a name="getting-started">Getting started</a>
  63. ## <a name="obtaining-the-latest-code">Obtaining the latest code</a>
  64. * On **Linux/MacOSX**, you may checkout the latest revision using
  65. ```shell
  66. $ git clone https://gitlab.com/mmoelle1/UETLI.git UETLI
  67. ```
  68. Once the initial checkout is complete you can keep the code up-to-date using
  69. ```shell
  70. $ cd UETLI
  71. $ git pull
  72. ```
  73. * On **Windows**, you can use any [git
  74. client](https://git-scm.com/download/win) to checkout the **UETLI**
  75. library and keep the code up-to-date, using the same URL as above.
  76. ## <a name="compiling-and-running-the-unittests">Compiling and running the UnitTests</a>
  77. The **UETLI** library comes with unit tests for all supported ETLs. The
  78. compilation requires configuration using [CMake](https://cmake.org) at
  79. a new, empty folder (in-source builds are disabled).
  80. * On **Linux/MacOSX**, you need to create an empty `build` folder,
  81. execute CMake and start the compilation process inside that
  82. folder. If your source folder is `UETLI` then the sequence of commands
  83. ```shell
  84. $ mkdir build
  85. $ cd build
  86. $ cmake ../path/to/UETLI -DUETLI_BUILD_UNITTESTS=ON -DUETLI_BUILD_UNITTESTS_<ETL>=ON -DUETLI_<FEATURE>=ON
  87. -- Build files have been written to: /path/to/build
  88. $ make
  89. ...
  90. [100%] Built
  91. ```
  92. compiles the unit tests for the enabled ETLs and features. To see
  93. a complete list of supported ETLs and features run
  94. ```shell
  95. $ mkdir build
  96. $ cd build
  97. $ ccmake ../path/to/UETLI
  98. ```
  99. and set/unset the configuration in the CMake GUI.
  100. After successful compilation executable unit tests are created at
  101. the `./unittests/<ETL>/` subdirectory of the build folder.
  102. All compiled unit tests can be run by executing
  103. ```shell
  104. $ make test
  105. ```
  106. If Doxygen is available on your system, you can compile and open
  107. the Doxygen HTML pages by executing
  108. ```shell
  109. $ cd build
  110. $ make doc
  111. ...
  112. Built target doc
  113. $ firefox doc/html/index.html
  114. ```
  115. * On **Windows**, you need to run the cmake-gui tool to generate a
  116. project file and open it with your IDE (e.g., [Visual
  117. Studio](https://www.visualstudio.com)). Please consider the
  118. documentation of your IDE how to compile and run executables.
  119. ### Example: Compiling UnitTests for VexCL
  120. To compile the unit tests for the VexCL library under Linux/MacOSX you
  121. need to call CMake as follows:
  122. ```shell
  123. $ mkdir build
  124. $ cd build
  125. $ cmake ../path/to/UETLI -DUETLI_BUILD_UNITTESTS=ON -DUETLI_BUILD_UNITTESTS_VEXCL=ON -DUETLI_OCL=ON
  126. ...
  127. Options:
  128. UETLI_BUILD_TESTS...................: OFF
  129. UETLI_BUILD_UNITTESTS...............: ON
  130. Features:
  131. UETLI_CXX_STANDARD..................: 14
  132. UETLI_WITH_CUDA.....................: OFF
  133. UETLI_WITH_MIC......................: OFF
  134. UETLI_WITH_OCL......................: ON
  135. UETLI_WITH_OMP......................: OFF
  136. UnitTests:
  137. UETLI_BUILD_UNITTESTS_DEVICES.......: CPU
  138. UETLI_BUILD_UNITTESTS_PERFMODE......: OFF
  139. UETLI_BUILD_UNITTESTS_PRECISIONS....: ALL
  140. UETLI_BUILD_UNITTESTS_SIZES.........: 1000
  141. UETLI_BUILD_UNITTESTS_RUNS..........: 1
  142. UETLI_BUILD_UNITTESTS_TESTS.........: ALL
  143. UETLI_BUILD_UNITTESTS_ARMADILLO.....: OFF
  144. UETLI_BUILD_UNITTESTS_ARRAYFIRE.....: OFF
  145. UETLI_BUILD_UNITTESTS_BLAZE.........: OFF
  146. UETLI_BUILD_UNITTESTS_CMTL4.........: OFF
  147. UETLI_BUILD_UNITTESTS_EIGEN.........: OFF
  148. UETLI_BUILD_UNITTESTS_ITPP..........: OFF
  149. UETLI_BUILD_UNITTESTS_MTL4..........: OFF
  150. UETLI_BUILD_UNITTESTS_UBLAS.........: OFF
  151. UETLI_BUILD_UNITTESTS_VEXCL.........: ON
  152. UETLI_BUILD_UNITTESTS_VIENNACL......: OFF
  153. ...
  154. -- Build files have been written to: /path/to/build
  155. $ make vexcl-unittest
  156. ...
  157. [100%] Built
  158. $ make test
  159. Running tests...
  160. Test project /path/to/build
  161. Start 1: vexcl-unittest
  162. 1/1 Test #1: vexcl-unittest ............... Passed 0.02 sec
  163. 100% tests passed, 0 tests failed out of 1
  164. Total Test time (real) = 0.03 sec
  165. ```
  166. ### Example: Compiling selection of UnitTests
  167. It is also possible to specify a selection of unit tests that should
  168. be run by specifying a list/file patterns of tests to be included and
  169. a list/file pattern of tests to be excluded.
  170. To perform all unit tests for element-wise operations except for the
  171. power function you need to call CMake as follows:
  172. ```shell
  173. $ mkdir build
  174. $ cd build
  175. $ cmake ../path/to/UETLI -DUETLI_BUILD_UNITTESTS=ON -DUETLI_BUILD_UNITTESTS_VEXCL=ON -DUETLI_OCL=ON \
  176. -DUETLI_UNITTESTS_TESTS=ALL \
  177. -DUETLI_UNITTESTS_TESTS_INCLUDE="test_op_elem_*" \
  178. -DUETLI_UNITTESTS_TESTS_EXCLUDE="test_op_elem_pow"
  179. ```
  180. ## <a name="including-uetli-into-own-codes">Including UETLI into own codes</a>
  181. The **UETLI** library is included in your program by including the
  182. header file
  183. ```cpp
  184. #include "uetli.h"
  185. ```
  186. By default, **UETLI** assumes
  187. C++14 support enabled and all accelerators and parallelization
  188. techniques disabled. This behavior can be changed by enabled one or
  189. more of the following flags when compiling your program:
  190. * C++11 support: `-DUETLI_WITH_CXX11`
  191. * CUDA support: `-DUETLI_WITH_CUDA`
  192. * Intel MIC support: `-DUETLI_WITH_MIC`
  193. * OpenCL support: `-DUETLI_WITH_OCL`
  194. * OpenMP support: `-DUETLI_WITH_OMP`
  195. # <a name="the-plain-program">The plain program</a>
  196. ```cpp
  197. #include <vector>
  198. #include <vexcl/vexcl.hpp>
  199. #include "uetli.h"
  200. // VexCL context
  201. vex::Context ctx( vex::Filter::CPU && vex::Filter::DoublePrecision );
  202. // Vector length
  203. std::size_t N = 10;
  204. // VexCL vectors
  205. vex::vector<double> u0(ctx, N);
  206. vex::vector<double> u1(ctx, N);
  207. vex::vector<double> u2(ctx, N);
  208. vex::vector<double> u3(ctx, N);
  209. // Initialization
  210. u0 = 2.0;
  211. u1 = 1.0;
  212. u2 = 5.0;
  213. // Compute element-wise expression sin(u0+u1)*u2
  214. auto expr = uetli::elem_mul(uetli::elem_sin(u0+u1),u2);
  215. // Assign expression to u3
  216. u3 = expr;
  217. ```
  218. ___
  219. Author: Matthias Möller