[PATCH] D101265: [OpenMP][CMake] Use in-project clang as CUDA->IR compiler.

Michael Kruse via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Apr 25 15:52:12 PDT 2021


Meinersbur created this revision.
Meinersbur added reviewers: jdoerfert, tianshilei1992, ye-luo.
Meinersbur added a project: OpenMP.
Herald added subscribers: guansong, yaxunl, mgorny.
Meinersbur requested review of this revision.
Herald added subscribers: llvm-commits, sstefan1.
Herald added a project: LLVM.

If available, use the clang that is already built in the same project as CUDA compiler unless another executable is explicitly defined. This also ensures the generated deviceRTL IR will be consistent with the version of Clang.

The change in `add_subdirectory` order is required to ensure that if clang is part of the project build, its target exists before openmp is included. Alternatively, `LLVM_TOOL_CLANG_BUILD` can could be used to determine whether clang build is enabled (Not sure how reliable it is).

This patch is required to reliably test OpenMP offloading in a buildbot without either a two-stage build (e.g. with LLVM_ENABLE_RUNTIMES) or a separately installed clang on the worker that will eventually become outdated.

See the current builder <http://meinersbur.de:8011/#/builders/142> and the build with this patch applied <http://meinersbur.de:8011/#/builders/142/builds/220>.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D101265

Files:
  llvm/CMakeLists.txt
  openmp/libomptarget/deviceRTLs/nvptx/CMakeLists.txt


Index: openmp/libomptarget/deviceRTLs/nvptx/CMakeLists.txt
===================================================================
--- openmp/libomptarget/deviceRTLs/nvptx/CMakeLists.txt
+++ openmp/libomptarget/deviceRTLs/nvptx/CMakeLists.txt
@@ -30,7 +30,17 @@
 
 if (NOT LIBOMPTARGET_NVPTX_CUDA_COMPILER STREQUAL "")
   set(cuda_compiler ${LIBOMPTARGET_NVPTX_CUDA_COMPILER})
+elseif (TARGET clang) # Or query LLVM_TOOL_CLANG_BUILD
+  # Compile the deviceRTL with the clang that is built in the project.
+  set(cuda_compiler clang)
 elseif(${CMAKE_C_COMPILER_ID} STREQUAL "Clang")
+  # Compile the device runtime with the compiler that OpenMP is built with.
+  # This is the case with LLVM_ENABLE_RUNTIMES=openmp.
+  # FIXME: This is unreliable; the compiler can be on older version of clang
+  # that does not support compiling CUDA, or only an older version of it. The
+  # risk is espicially high on sustems where clang is the default compiler
+  # (MacOS, BSDs). LLVM_ENABLE_RUNTIMES=openmp should itself set
+  # LIBOMPTARGET_NVPTX_CUDA_COMPILER instead.
   set(cuda_compiler ${CMAKE_C_COMPILER})
 else()
   libomptarget_say("Not building NVPTX deviceRTL: clang not found")
@@ -44,7 +54,12 @@
 if (NOT LIBOMPTARGET_NVPTX_BC_LINKER STREQUAL "")
   set(bc_linker ${LIBOMPTARGET_NVPTX_BC_LINKER})
 elseif (EXISTS ${llvm_link})
+  # Try to use the linker consistent with the CUDA compiler unless explicitly
+  # set to a different linker.
   set(bc_linker ${llvm_link})
+elseif (TARGET llvm-link)
+  # Use the linker also built in the same project.
+  set(bc_linker llvm-link)
 else()
   libomptarget_say("Not building NVPTX deviceRTL: llvm-link not found")
   return()
Index: llvm/CMakeLists.txt
===================================================================
--- llvm/CMakeLists.txt
+++ llvm/CMakeLists.txt
@@ -964,12 +964,12 @@
   endif()
 endforeach()
 
-add_subdirectory(projects)
-
 if( LLVM_INCLUDE_TOOLS )
   add_subdirectory(tools)
 endif()
 
+add_subdirectory(projects)
+
 if( LLVM_INCLUDE_RUNTIMES )
   add_subdirectory(runtimes)
 endif()


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D101265.340389.patch
Type: text/x-patch
Size: 2052 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210425/f49059aa/attachment.bin>


More information about the llvm-commits mailing list