[Openmp-commits] [PATCH] D125315: [Libomptarget] Build the device runtime as a static library

Joseph Huber via Phabricator via Openmp-commits openmp-commits at lists.llvm.org
Tue May 10 07:04:40 PDT 2022


jhuber6 created this revision.
jhuber6 added reviewers: jdoerfert, tianshilei1992, JonChesterfield.
Herald added a subscriber: mgorny.
Herald added a project: All.
jhuber6 requested review of this revision.
Herald added subscribers: openmp-commits, sstefan1.
Herald added a project: OpenMP.

This patch adds the necessary CMake configuration to build a static
library version of the device runtime, `libomptarget.devicertl.a`.
Various improvements in how we handle static libraries and generating
offloading code should allow us to treat the device library as a regular
project without needing to invoke the clang front-end directly. Here we
generate a job for each offloading architecture supported. Each
offloading architecture will be embedded into the static library and
used as-needed by the host.

This library will primarily be used to replace the bitcode library when
performing LTO. Currently, we need to manually pass in the bitcode
library which requires foreknowledge of the offloading architecture.
This approach lets us handle that in the linker wrapper instead.
Furthermore this should improve our interface to the device runtime. We
can now build it fully under a release build and have all the expected
entry points, as well as supporting debug builds.

Depends on D125265 <https://reviews.llvm.org/D125265> D125256 <https://reviews.llvm.org/D125256> D125260 <https://reviews.llvm.org/D125260> D125314 <https://reviews.llvm.org/D125314>


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D125315

Files:
  openmp/libomptarget/CMakeLists.txt
  openmp/libomptarget/DeviceRTL/CMakeLists.txt
  openmp/libomptarget/DeviceRTL/src/CMakeLists.txt


Index: openmp/libomptarget/DeviceRTL/src/CMakeLists.txt
===================================================================
--- /dev/null
+++ openmp/libomptarget/DeviceRTL/src/CMakeLists.txt
@@ -0,0 +1,13 @@
+target_sources(omptarget.devicertl PRIVATE
+  Configuration.cpp
+  Debug.cpp
+  Kernel.cpp
+  Mapping.cpp
+  Misc.cpp
+  Parallelism.cpp
+  Reduction.cpp
+  State.cpp
+  Synchronization.cpp
+  Tasking.cpp
+  Utils.cpp
+  Workshare.cpp)
Index: openmp/libomptarget/DeviceRTL/CMakeLists.txt
===================================================================
--- openmp/libomptarget/DeviceRTL/CMakeLists.txt
+++ openmp/libomptarget/DeviceRTL/CMakeLists.txt
@@ -241,3 +241,22 @@
 foreach(mcpu ${amdgpu_mcpus})
   compileDeviceRTLLibrary(${mcpu} amdgpu -target amdgcn-amd-amdhsa -D__AMDGCN__ -nogpulib)
 endforeach()
+
+# Set the flags to build the device runtime from clang.
+set(clang_lib_flags -fopenmp -fopenmp-cuda-mode -foffload-lto -fvisibility=hidden -mllvm -openmp-opt-disable -nogpulib -nostdinc -DSHARED_SCRATCHPAD_SIZE=512)
+foreach(arch ${nvptx_sm_list})
+  set(clang_lib_flags ${clang_lib_flags} --offload-arch=sm_${arch})
+endforeach()
+foreach(arch ${amdgpu_mcpus})
+  set(clang_lib_flags ${clang_lib_flags} --offload-arch=${arch})
+endforeach()
+
+# Build the static library version of the device runtime.
+add_library(omptarget.devicertl STATIC)
+target_compile_features(omptarget.devicertl PRIVATE cxx_std_17)
+target_include_directories(omptarget.devicertl PRIVATE ${include_directory} ${devicertl_base_directory}/../include)
+target_compile_options(omptarget.devicertl PRIVATE ${clang_lib_flags})
+
+install(TARGETS omptarget.devicertl ARCHIVE DESTINATION ${OPENMP_INSTALL_LIBDIR})
+
+add_subdirectory(src)
Index: openmp/libomptarget/CMakeLists.txt
===================================================================
--- openmp/libomptarget/CMakeLists.txt
+++ openmp/libomptarget/CMakeLists.txt
@@ -37,6 +37,9 @@
 
 include_directories(${LIBOMPTARGET_LLVM_INCLUDE_DIRS})
 
+# Build the device RTL before we set the libomptarget include directories.
+add_subdirectory(DeviceRTL)
+
 # This is a list of all the targets that are supported/tested right now.
 set (LIBOMPTARGET_ALL_TARGETS "${LIBOMPTARGET_ALL_TARGETS} aarch64-unknown-linux-gnu")
 set (LIBOMPTARGET_ALL_TARGETS "${LIBOMPTARGET_ALL_TARGETS} aarch64-unknown-linux-gnu-oldDriver")
@@ -85,7 +88,6 @@
 
 # Build offloading plugins and device RTLs if they are available.
 add_subdirectory(plugins)
-add_subdirectory(DeviceRTL)
 add_subdirectory(tools)
 
 # Add tests.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D125315.428363.patch
Type: text/x-patch
Size: 2549 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/openmp-commits/attachments/20220510/2e8f3202/attachment.bin>


More information about the Openmp-commits mailing list