[Openmp-commits] [PATCH] D105051: [OpenMP][Documentation] Add FAQ entry for CMake module

Joseph Huber via Phabricator via Openmp-commits openmp-commits at lists.llvm.org
Mon Jun 28 12:35:49 PDT 2021


jhuber6 created this revision.
jhuber6 added a reviewer: jdoerfert.
Herald added subscribers: guansong, yaxunl, mgorny.
jhuber6 requested review of this revision.
Herald added subscribers: openmp-commits, sstefan1.
Herald added a project: OpenMP.

This patch adds documentation for using the CMake find module for OpenMP
target offloading provided by LLVM. It also removes the requirement for
AMD's architecture to be set as this isn't necessary for upstream LLVM.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D105051

Files:
  openmp/docs/SupportAndFAQ.rst
  openmp/tools/Modules/FindOpenMPTarget.cmake


Index: openmp/tools/Modules/FindOpenMPTarget.cmake
===================================================================
--- openmp/tools/Modules/FindOpenMPTarget.cmake
+++ openmp/tools/Modules/FindOpenMPTarget.cmake
@@ -140,10 +140,6 @@
 
 # Get flags for setting the device's architecture for each compiler.
 function(_OPENMP_TARGET_DEVICE_ARCH_CANDIDATES LANG DEVICE DEVICE_FLAG)
-  # AMD requires the architecture, default to gfx908 if not provided.
-  if((NOT OpenMPTarget_${DEVICE}_ARCH) AND ("${DEVICE}" STREQUAL "AMDGCN"))
-    set(OpenMPTarget_${DEVICE}_ARCH "gfx908")
-  endif()
   if(OpenMPTarget_${DEVICE}_ARCH)
     # Only Clang supports selecting the architecture for now.
     set(OMPTarget_ARCH_Clang "-Xopenmp-target=${DEVICE_FLAG} -march=${OpenMPTarget_${DEVICE}_ARCH}")
Index: openmp/docs/SupportAndFAQ.rst
===================================================================
--- openmp/docs/SupportAndFAQ.rst
+++ openmp/docs/SupportAndFAQ.rst
@@ -53,11 +53,12 @@
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 To build an *effective* OpenMP offload capable compiler, only one extra CMake
 option, `LLVM_ENABLE_RUNTIMES="openmp"`, is needed when building LLVM (Generic
-information about building LLVM is available `here <https://llvm.org/docs/GettingStarted.html>`__.).
-Make sure all backends that are targeted by OpenMP to be enabled. By default,
-Clang will be built with all backends enabled.
-When building with `LLVM_ENABLE_RUNTIMES="openmp"` OpenMP should not be enabled
-in `LLVM_ENABLE_PROJECTS` because it is enabled by default.
+information about building LLVM is available `here
+<https://llvm.org/docs/GettingStarted.html>`__.).  Make sure all backends that
+are targeted by OpenMP to be enabled. By default, Clang will be built with all
+backends enabled.  When building with `LLVM_ENABLE_RUNTIMES="openmp"` OpenMP
+should not be enabled in `LLVM_ENABLE_PROJECTS` because it is enabled by
+default.
 
 For Nvidia offload, please see :ref:`_build_nvidia_offload_capable_compiler`.
 For AMDGPU offload, please see :ref:`_build_amdgpu_offload_capable_compiler`.
@@ -153,8 +154,8 @@
 Q: Does Clang support `<math.h>` and `<complex.h>` operations in OpenMP target on GPUs?
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
-Yes, LLVM/Clang allows math functions and complex arithmetic inside of OpenMP target regions
-that are compiled for GPUs.
+Yes, LLVM/Clang allows math functions and complex arithmetic inside of OpenMP
+target regions that are compiled for GPUs.
 
 Clang provides a set of wrapper headers that are found first when `math.h` and
 `complex.h`, for C, `cmath` and `complex`, for C++, or similar headers are
@@ -202,8 +203,8 @@
 Currently, the only solution is to change how the application is built and avoid
 the use of static libraries.
 
-Q: Can I use dynamically linked libraries with OpenMP offloading
-^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+Q: Can I use dynamically linked libraries with OpenMP offloading?
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
 Dynamically linked libraries can be only used if there is no device code split
 between the library and application. Anything declared on the device inside the
@@ -220,3 +221,30 @@
 For example, if your system-wide GCC installation is too old to build LLVM and
 you would like to use a newer GCC, set the CMake variable `GCC_INSTALL_PREFIX`
 to inform clang of the GCC installation you would like to use in the second stage.
+
+Q: How can I include OpenMP offloading support in my CMake project?
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+Currently, there is a CMake find module for OpenMP target offloading provided by
+LLVM. It will attempt to find OpenMP target offloading support for your
+compiler. Currently supported targets are ``AMDGCN`` and ``NVPTX``. Including
+OpenMP offloading support in your application should now only require a few
+additions.
+
+.. code-block:: cmake
+
+  cmake_minimum_required(VERSION 3.13.4)
+  project(offloadTest VERSION 1.0 LANGUAGES CXX)
+  
+  list(APPEND CMAKE_MODULE_PATH "${PATH_TO_OPENMP_INSTALL}/lib/cmake/openmp")
+  
+  find_package(OpenMPTarget REQUIRED NVPTX)
+  
+  add_executable(offload)
+  target_link_libraries(offload PRIVATE OpenMPTarget::OpenMPTarget_NVPTX)
+  target_sources(offload PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src/Main.cpp)
+
+Using this module requires at least CMake version 3.13.4. Supported languages
+are C and C++ with Fortran support planned in the future. Compiler support is
+best for Clang but this module should work for other compiler vendors such as
+IBM or GNU.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D105051.354991.patch
Type: text/x-patch
Size: 4683 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/openmp-commits/attachments/20210628/30704474/attachment.bin>


More information about the Openmp-commits mailing list