[Openmp-commits] [llvm] [openmp] [Offload] Provide a CMake cache file to easily build offloading (PR #115074)

Joseph Huber via Openmp-commits openmp-commits at lists.llvm.org
Thu Nov 7 13:19:29 PST 2024


https://github.com/jhuber6 updated https://github.com/llvm/llvm-project/pull/115074

>From a0f27ce88872f379f818cd70e9050db3c7a4ed00 Mon Sep 17 00:00:00 2001
From: Joseph Huber <huberjn at outlook.com>
Date: Tue, 5 Nov 2024 15:43:17 -0600
Subject: [PATCH 1/3] [Offload] Provide a CMake cache file to easily build
 offloading

Summary:
This patch adds a cache file that will automatically enable openpm,
offload, and all the fancy GPU libraries.
---
 offload/cmake/caches/Offload.cmake | 12 ++++++++++++
 openmp/docs/SupportAndFAQ.rst      | 16 ++++++++++++++++
 2 files changed, 28 insertions(+)
 create mode 100644 offload/cmake/caches/Offload.cmake

diff --git a/offload/cmake/caches/Offload.cmake b/offload/cmake/caches/Offload.cmake
new file mode 100644
index 00000000000000..9205c38903d65f
--- /dev/null
+++ b/offload/cmake/caches/Offload.cmake
@@ -0,0 +1,12 @@
+set(LLVM_ENABLE_PROJECTS "clang;clang-tools-extra;lld" CACHE STRING "")
+set(LLVM_ENABLE_RUNTIMES "libunwind;libcxx;libcxxabi;openmp;offload" CACHE STRING "")
+set(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR ON CACHE BOOL "")
+
+set(CLANG_DEFAULT_CXX_STDLIB "libc++" CACHE STRING "")
+set(CLANG_DEFAULT_LINKER "lld" CACHE STRING "")
+
+set(LLVM_RUNTIME_TARGETS default;amdgcn-amd-amdhsa;nvptx64-nvidia-cuda CACHE STRING "") 
+set(RUNTIMES_nvptx64-nvidia-cuda_CACHE_FILES "${CMAKE_SOURCE_DIR}/../libcxx/cmake/caches/NVPTX.cmake" CACHE STRING "")
+set(RUNTIMES_amdgcn-amd-amdhsa_CACHE_FILES "${CMAKE_SOURCE_DIR}/../libcxx/cmake/caches/AMDGPU.cmake" CACHE STRING "")
+set(RUNTIMES_nvptx64-nvidia-cuda_LLVM_ENABLE_RUNTIMES "compiler-rt;libc;libcxx;libcxxabi" CACHE STRING "")
+set(RUNTIMES_amdgcn-amd-amdhsa_LLVM_ENABLE_RUNTIMES "compiler-rt;libc;libcxx;libcxxabi" CACHE STRING "")
diff --git a/openmp/docs/SupportAndFAQ.rst b/openmp/docs/SupportAndFAQ.rst
index dee707cf50f919..df6aea11416184 100644
--- a/openmp/docs/SupportAndFAQ.rst
+++ b/openmp/docs/SupportAndFAQ.rst
@@ -51,6 +51,22 @@ All patches go through the regular `LLVM review process
 
 Q: How to build an OpenMP GPU offload capable compiler?
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+The easiest way to create an offload capable compiler is to use the provided 
+CMake cache file. This will enable the projects and runtimes necessary for 
+offloading as well as some extra options.
+
+.. code-block:: sh
+
+  $> cd llvm-project  # The llvm-project checkout
+  $> mkdir build
+  $> cd build
+  $> cmake ../llvm -G Ninja                                                 \
+     -C ../offload/cmake/caches/Offload.cmake \ # The preset cache file
+     -DCMAKE_BUILD_TYPE=<Debug|Release>   \ # Select build type
+     -DCMAKE_INSTALL_PREFIX=<PATH>        \ # Where the libraries will live
+  $> ninja install
+
 To build an *effective* OpenMP offload capable compiler, only one extra CMake
 option, ``LLVM_ENABLE_RUNTIMES="openmp;offload"``, is needed when building LLVM (Generic
 information about building LLVM is available `here

>From 7f8d6128e9980672c3b4045e34bbdc92f4ec8efa Mon Sep 17 00:00:00 2001
From: Joseph Huber <huberjn at outlook.com>
Date: Wed, 6 Nov 2024 14:47:01 -0600
Subject: [PATCH 2/3] Update SupportAndFAQ.rst

---
 openmp/docs/SupportAndFAQ.rst | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/openmp/docs/SupportAndFAQ.rst b/openmp/docs/SupportAndFAQ.rst
index df6aea11416184..b645723dcfd5ec 100644
--- a/openmp/docs/SupportAndFAQ.rst
+++ b/openmp/docs/SupportAndFAQ.rst
@@ -67,7 +67,7 @@ offloading as well as some extra options.
      -DCMAKE_INSTALL_PREFIX=<PATH>        \ # Where the libraries will live
   $> ninja install
 
-To build an *effective* OpenMP offload capable compiler, only one extra CMake
+To manually build an *effective* OpenMP offload capable compiler, only one extra CMake
 option, ``LLVM_ENABLE_RUNTIMES="openmp;offload"``, is needed when building LLVM (Generic
 information about building LLVM is available `here
 <https://llvm.org/docs/GettingStarted.html>`__.). Make sure all backends that

>From 445e395c314555155d5194abb3e619fc3a15688f Mon Sep 17 00:00:00 2001
From: Joseph Huber <huberjn at outlook.com>
Date: Thu, 7 Nov 2024 15:19:20 -0600
Subject: [PATCH 3/3] Update Offload.cmake

---
 offload/cmake/caches/Offload.cmake | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/offload/cmake/caches/Offload.cmake b/offload/cmake/caches/Offload.cmake
index 9205c38903d65f..57363e99b10afc 100644
--- a/offload/cmake/caches/Offload.cmake
+++ b/offload/cmake/caches/Offload.cmake
@@ -1,4 +1,4 @@
-set(LLVM_ENABLE_PROJECTS "clang;clang-tools-extra;lld" CACHE STRING "")
+set(LLVM_ENABLE_PROJECTS "clang;clang-tools-extra;compiler-rt;lld" CACHE STRING "")
 set(LLVM_ENABLE_RUNTIMES "libunwind;libcxx;libcxxabi;openmp;offload" CACHE STRING "")
 set(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR ON CACHE BOOL "")
 



More information about the Openmp-commits mailing list