README.rst 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  1. ========================================
  2. How to Build the LLVM* OpenMP* Libraries
  3. ========================================
  4. This repository requires `CMake <http://www.cmake.org/>`_ v2.8.0 or later. LLVM
  5. and Clang need a more recent version which also applies for in-tree builds. For
  6. more information than available in this document please see
  7. `LLVM's CMake documentation <https://llvm.org/docs/CMake.html>`_ and the
  8. `official documentation <https://cmake.org/cmake/help/v2.8.0/cmake.html>`_.
  9. .. contents::
  10. :local:
  11. How to Call CMake Initially, then Repeatedly
  12. ============================================
  13. - When calling CMake for the first time, all needed compiler options must be
  14. specified on the command line. After this initial call to CMake, the compiler
  15. definitions must not be included for further calls to CMake. Other options
  16. can be specified on the command line multiple times including all definitions
  17. in the build options section below.
  18. - Example of configuring, building, reconfiguring, rebuilding:
  19. .. code-block:: console
  20. $ mkdir build
  21. $ cd build
  22. $ cmake -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ .. # Initial configuration
  23. $ make
  24. ...
  25. $ make clean
  26. $ cmake -DCMAKE_BUILD_TYPE=Debug .. # Second configuration
  27. $ make
  28. ...
  29. $ rm -rf *
  30. $ cmake -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ .. # Third configuration
  31. $ make
  32. - Notice in the example how the compiler definitions are only specified for an
  33. empty build directory, but other build options are used at any time.
  34. - The file ``CMakeCache.txt`` which is created after the first call to CMake is
  35. a configuration file which holds all values for the build options. These
  36. values can be changed using a text editor to modify ``CMakeCache.txt`` as
  37. opposed to using definitions on the command line.
  38. - To have CMake create a particular type of build generator file simply include
  39. the ``-G <Generator name>`` option:
  40. .. code-block:: console
  41. $ cmake -G "Unix Makefiles" ...
  42. You can see a list of generators CMake supports by executing the cmake command
  43. with no arguments.
  44. Instructions to Build
  45. =====================
  46. .. code-block:: console
  47. $ cd openmp_top_level/ [ this directory with libomptarget/, runtime/, etc. ]
  48. $ mkdir build
  49. $ cd build
  50. [ Unix* Libraries ]
  51. $ cmake -DCMAKE_C_COMPILER=<C Compiler> -DCMAKE_CXX_COMPILER=<C++ Compiler> ..
  52. [ Windows* Libraries ]
  53. $ cmake -G <Generator Type> -DCMAKE_C_COMPILER=<C Compiler> -DCMAKE_CXX_COMPILER=<C++ Compiler> -DCMAKE_ASM_MASM_COMPILER=[ml | ml64] -DCMAKE_BUILD_TYPE=Release ..
  54. $ make
  55. $ make install
  56. CMake Options
  57. =============
  58. Builds with CMake can be customized by means of options as already seen above.
  59. One possibility is to pass them via the command line:
  60. .. code-block:: console
  61. $ cmake -DOPTION=<value> path/to/source
  62. .. note:: The first value listed is the respective default for that option.
  63. Generic Options
  64. ---------------
  65. For full documentation consult the CMake manual or execute
  66. ``cmake --help-variable VARIABLE_NAME`` to get information about a specific
  67. variable.
  68. **CMAKE_BUILD_TYPE** = ``Release|Debug|RelWithDebInfo``
  69. Build type can be ``Release``, ``Debug``, or ``RelWithDebInfo`` which chooses
  70. the optimization level and presence of debugging symbols.
  71. **CMAKE_C_COMPILER** = <C compiler name>
  72. Specify the C compiler.
  73. **CMAKE_CXX_COMPILER** = <C++ compiler name>
  74. Specify the C++ compiler.
  75. **CMAKE_Fortran_COMPILER** = <Fortran compiler name>
  76. Specify the Fortran compiler. This option is only needed when
  77. **LIBOMP_FORTRAN_MODULES** is ``ON`` (see below). So typically, a Fortran
  78. compiler is not needed during the build.
  79. **CMAKE_ASM_MASM_COMPILER** = ``ml|ml64``
  80. This option is only relevant for Windows*.
  81. Options for all Libraries
  82. -------------------------
  83. **OPENMP_ENABLE_WERROR** = ``OFF|ON``
  84. Treat warnings as errors and fail, if a compiler warning is triggered.
  85. **OPENMP_LIBDIR_SUFFIX** = ``""``
  86. Extra suffix to append to the directory where libraries are to be installed.
  87. **OPENMP_TEST_C_COMPILER** = ``${CMAKE_C_COMPILER}``
  88. Compiler to use for testing. Defaults to the compiler that was also used for
  89. building.
  90. **OPENMP_TEST_CXX_COMPILER** = ``${CMAKE_CXX_COMPILER}``
  91. Compiler to use for testing. Defaults to the compiler that was also used for
  92. building.
  93. **OPENMP_LLVM_TOOLS_DIR** = ``/path/to/built/llvm/tools``
  94. Additional path to search for LLVM tools needed by tests.
  95. **OPENMP_LLVM_LIT_EXECUTABLE** = ``/path/to/llvm-lit``
  96. Specify full path to ``llvm-lit`` executable for running tests. The default
  97. is to search the ``PATH`` and the directory in **OPENMP_LLVM_TOOLS_DIR**.
  98. **OPENMP_FILECHECK_EXECUTABLE** = ``/path/to/FileCheck``
  99. Specify full path to ``FileCheck`` executable for running tests. The default
  100. is to search the ``PATH`` and the directory in **OPENMP_LLVM_TOOLS_DIR**.
  101. **OPENMP_NOT_EXECUTABLE** = ``/path/to/not``
  102. Specify full path to ``not`` executable for running tests. The default
  103. is to search the ``PATH`` and the directory in **OPENMP_LLVM_TOOLS_DIR**.
  104. Options for ``libomp``
  105. ----------------------
  106. **LIBOMP_ARCH** = ``aarch64|arm|i386|mic|mips|mips64|ppc64|ppc64le|x86_64|riscv64``
  107. The default value for this option is chosen based on probing the compiler for
  108. architecture macros (e.g., is ``__x86_64__`` predefined by compiler?).
  109. **LIBOMP_MIC_ARCH** = ``knc|knf``
  110. Intel(R) Many Integrated Core Architecture (Intel(R) MIC Architecture) to
  111. build for. This value is ignored if **LIBOMP_ARCH** does not equal ``mic``.
  112. **LIBOMP_LIB_TYPE** = ``normal|profile|stubs``
  113. Library type can be ``normal``, ``profile``, or ``stubs``.
  114. **LIBOMP_USE_VERSION_SYMBOLS** = ``ON|OFF``
  115. Use versioned symbols for building the library. This option only makes sense
  116. for ELF based libraries where version symbols are supported (Linux*, some BSD*
  117. variants). It is ``OFF`` by default for Windows* and macOS*, but ``ON`` for
  118. other Unix based operating systems.
  119. **LIBOMP_ENABLE_SHARED** = ``ON|OFF``
  120. Build a shared library. If this option is ``OFF``, static OpenMP libraries
  121. will be built instead of dynamic ones.
  122. .. note::
  123. Static libraries are not supported on Windows*.
  124. **LIBOMP_FORTRAN_MODULES** = ``OFF|ON``
  125. Create the Fortran modules (requires Fortran compiler).
  126. macOS* Fat Libraries
  127. """"""""""""""""""""
  128. On macOS* machines, it is possible to build universal (or fat) libraries which
  129. include both i386 and x86_64 architecture objects in a single archive.
  130. .. code-block:: console
  131. $ cmake -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_OSX_ARCHITECTURES='i386;x86_64' ..
  132. $ make
  133. There is also an option **LIBOMP_OSX_ARCHITECTURES** which can be set in case
  134. this is an LLVM source tree build. It will only apply for the ``libomp`` library
  135. avoids having the entire LLVM/Clang build produce universal binaries.
  136. Optional Features
  137. """""""""""""""""
  138. **LIBOMP_USE_ADAPTIVE_LOCKS** = ``ON|OFF``
  139. Include adaptive locks, based on Intel(R) Transactional Synchronization
  140. Extensions (Intel(R) TSX). This feature is x86 specific and turned ``ON``
  141. by default for IA-32 architecture and Intel(R) 64 architecture.
  142. **LIBOMP_USE_INTERNODE_ALIGNMENT** = ``OFF|ON``
  143. Align certain data structures on 4096-byte. This option is useful on
  144. multi-node systems where a small ``CACHE_LINE`` setting leads to false sharing.
  145. **LIBOMP_OMPT_SUPPORT** = ``ON|OFF``
  146. Include support for the OpenMP Tools Interface (OMPT).
  147. This option is supported and ``ON`` by default for x86, x86_64, AArch64,
  148. PPC64 and RISCV64 on Linux* and macOS*.
  149. This option is ``OFF`` if this feature is not supported for the platform.
  150. **LIBOMP_OMPT_OPTIONAL** = ``ON|OFF``
  151. Include support for optional OMPT functionality. This option is ignored if
  152. **LIBOMP_OMPT_SUPPORT** is ``OFF``.
  153. **LIBOMP_STATS** = ``OFF|ON``
  154. Include stats-gathering code.
  155. **LIBOMP_USE_DEBUGGER** = ``OFF|ON``
  156. Include the friendly debugger interface.
  157. **LIBOMP_USE_HWLOC** = ``OFF|ON``
  158. Use `OpenMPI's hwloc library <https://www.open-mpi.org/projects/hwloc/>`_ for
  159. topology detection and affinity.
  160. **LIBOMP_HWLOC_INSTALL_DIR** = ``/path/to/hwloc/install/dir``
  161. Specify install location of hwloc. The configuration system will look for
  162. ``hwloc.h`` in ``${LIBOMP_HWLOC_INSTALL_DIR}/include`` and the library in
  163. ``${LIBOMP_HWLOC_INSTALL_DIR}/lib``. The default is ``/usr/local``.
  164. This option is only used if **LIBOMP_USE_HWLOC** is ``ON``.
  165. Additional Compiler Flags
  166. """""""""""""""""""""""""
  167. These flags are **appended**, they do not overwrite any of the preset flags.
  168. **LIBOMP_CPPFLAGS** = <space-separated flags>
  169. Additional C preprocessor flags.
  170. **LIBOMP_CXXFLAGS** = <space-separated flags>
  171. Additional C++ compiler flags.
  172. **LIBOMP_ASMFLAGS** = <space-separated flags>
  173. Additional assembler flags.
  174. **LIBOMP_LDFLAGS** = <space-separated flags>
  175. Additional linker flags.
  176. **LIBOMP_LIBFLAGS** = <space-separated flags>
  177. Additional libraries to link.
  178. **LIBOMP_FFLAGS** = <space-separated flags>
  179. Additional Fortran compiler flags.
  180. Options for ``libomptarget``
  181. ----------------------------
  182. An installed LLVM package is a prerequisite for building ``libomptarget``
  183. library. So ``libomptarget`` may only be built in two cases:
  184. - As a project of a regular LLVM build via **LLVM_ENABLE_PROJECTS**,
  185. **LLVM_EXTERNAL_PROJECTS**, or **LLVM_ENABLE_RUNTIMES** or
  186. - as a standalone project build that uses a pre-installed LLVM package.
  187. In this mode one has to make sure that the default CMake
  188. ``find_package(LLVM)`` call `succeeds <https://cmake.org/cmake/help/latest/command/find_package.html#search-procedure>`_.
  189. **LIBOMPTARGET_OPENMP_HEADER_FOLDER** = ``""``
  190. Path of the folder that contains ``omp.h``. This is required for testing
  191. out-of-tree builds.
  192. **LIBOMPTARGET_OPENMP_HOST_RTL_FOLDER** = ``""``
  193. Path of the folder that contains ``libomp.so``, and ``libLLVMSupport.so``
  194. when profiling is enabled. This is required for testing.
  195. Options for ``NVPTX device RTL``
  196. --------------------------------
  197. **LIBOMPTARGET_NVPTX_ENABLE_BCLIB** = ``ON|OFF``
  198. Enable CUDA LLVM bitcode offloading device RTL. This is used for link time
  199. optimization of the OMP runtime and application code. This option is enabled
  200. by default if the build system determines that `CMAKE_C_COMPILER` is able to
  201. compile and link the library.
  202. **LIBOMPTARGET_NVPTX_CUDA_COMPILER** = ``""``
  203. Location of a CUDA compiler capable of emitting LLVM bitcode. Currently only
  204. the Clang compiler is supported. This is only used when building the CUDA LLVM
  205. bitcode offloading device RTL. If unspecified, either the Clang from the build
  206. itself is used (i.e. an in-tree build with LLVM_ENABLE_PROJECTS including
  207. clang), or the Clang compiler that the build uses as C compiler
  208. (CMAKE_C_COMPILER; only if it is Clang). The latter is common for a
  209. stage2-build or when using -DLLVM_ENABLE_RUNTIMES=openmp.
  210. **LIBOMPTARGET_NVPTX_BC_LINKER** = ``""``
  211. Location of a linker capable of linking LLVM bitcode objects. This is only
  212. used when building the CUDA LLVM bitcode offloading device RTL. If
  213. unspecified, either the llvm-link in that same directory as
  214. LIBOMPTARGET_NVPTX_CUDA_COMPILER is used, or the llvm-link from the
  215. same build (available in an in-tree build).
  216. **LIBOMPTARGET_NVPTX_ALTERNATE_HOST_COMPILER** = ``""``
  217. Host compiler to use with NVCC. This compiler is not going to be used to
  218. produce any binary. Instead, this is used to overcome the input compiler
  219. checks done by NVCC. E.g. if using a default host compiler that is not
  220. compatible with NVCC, this option can be use to pass to NVCC a valid compiler
  221. to avoid the error.
  222. **LIBOMPTARGET_NVPTX_COMPUTE_CAPABILITIES** = ``35``
  223. List of CUDA compute capabilities that should be supported by the NVPTX
  224. device RTL. E.g. for compute capabilities 6.0 and 7.0, the option "60;70"
  225. should be used. Compute capability 3.5 is the minimum required.
  226. **LIBOMPTARGET_NVPTX_DEBUG** = ``OFF|ON``
  227. Enable printing of debug messages from the NVPTX device RTL.
  228. **LIBOMPTARGET_LIT_ARGS** = ``""``
  229. Arguments given to lit. ``make check-libomptarget`` and
  230. ``make check-libomptarget-*`` are affected. For example, use
  231. ``LIBOMPTARGET_LIT_ARGS="-j4"`` to force ``lit`` to start only four parallel
  232. jobs instead of by default the number of threads in the system.
  233. Example Usages of CMake
  234. =======================
  235. Typical Invocations
  236. -------------------
  237. .. code-block:: console
  238. $ cmake -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ ..
  239. $ cmake -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ ..
  240. $ cmake -DCMAKE_C_COMPILER=icc -DCMAKE_CXX_COMPILER=icpc ..
  241. Advanced Builds with Various Options
  242. ------------------------------------
  243. - Build the i386 Linux* library using GCC*
  244. .. code-block:: console
  245. $ cmake -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ -DLIBOMP_ARCH=i386 ..
  246. - Build the x86_64 debug Mac library using Clang*
  247. .. code-block:: console
  248. $ cmake -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DLIBOMP_ARCH=x86_64 -DCMAKE_BUILD_TYPE=Debug ..
  249. - Build the library (architecture determined by probing compiler) using the
  250. Intel(R) C Compiler and the Intel(R) C++ Compiler. Also, create Fortran
  251. modules with the Intel(R) Fortran Compiler.
  252. .. code-block:: console
  253. $ cmake -DCMAKE_C_COMPILER=icc -DCMAKE_CXX_COMPILER=icpc -DCMAKE_Fortran_COMPILER=ifort -DLIBOMP_FORTRAN_MODULES=on ..
  254. - Have CMake find the C/C++ compiler and specify additional flags for the
  255. preprocessor and C++ compiler.
  256. .. code-blocks:: console
  257. $ cmake -DLIBOMP_CPPFLAGS='-DNEW_FEATURE=1 -DOLD_FEATURE=0' -DLIBOMP_CXXFLAGS='--one-specific-flag --two-specific-flag' ..
  258. - Build the stubs library
  259. .. code-blocks:: console
  260. $ cmake -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ -DLIBOMP_LIB_TYPE=stubs ..
  261. **Footnotes**
  262. .. [*] Other names and brands may be claimed as the property of others.