[Openmp-commits] [PATCH] D128130: Make libomptarget.devicertl.a built in all cases.

Ye Luo via Phabricator via Openmp-commits openmp-commits at lists.llvm.org
Sat Jun 18 18:48:51 PDT 2022


ye-luo created this revision.
Herald added a subscriber: mgorny.
Herald added a project: All.
ye-luo requested review of this revision.
Herald added a reviewer: jdoerfert.
Herald added subscribers: openmp-commits, sstefan1.
Herald added a project: OpenMP.

Make libomptarget.device.a built when using -DLLVM_ENABLE_PROJECTS=openmp
Use add_custom_command.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D128130

Files:
  openmp/libomptarget/DeviceRTL/CMakeLists.txt


Index: openmp/libomptarget/DeviceRTL/CMakeLists.txt
===================================================================
--- openmp/libomptarget/DeviceRTL/CMakeLists.txt
+++ openmp/libomptarget/DeviceRTL/CMakeLists.txt
@@ -242,15 +242,8 @@
   compileDeviceRTLLibrary(${mcpu} amdgpu -target amdgcn-amd-amdhsa -DLIBOMPTARGET_BC_TARGET -D__AMDGCN__ -nogpulib)
 endforeach()
 
-set(LIBOMPTARGET_LLVM_VERSION "${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}.${LLVM_VERSION_PATCH}")
-if(NOT (CMAKE_CXX_COMPILER_ID MATCHES "[Cc]lang" AND CMAKE_CXX_COMPILER_VERSION VERSION_EQUAL LIBOMPTARGET_LLVM_VERSION))
-  libomptarget_say("Not building static library, CMake compiler '${CMAKE_CXX_COMPILER_ID} ${CMAKE_CXX_COMPILER_VERSION}' is not 'Clang ${LIBOMPTARGET_LLVM_VERSION}'.")
-  libomptarget_say("  Use the 'LLVM_ENABLE_RUNTIMES=openmp' option instead")
-  return()
-endif()
-
 # Set the flags to build the device runtime from clang.
-set(clang_lib_flags -fopenmp -fopenmp-cuda-mode -foffload-lto -fvisibility=hidden -Xopenmp-target=nvptx64-nvidia-cuda --cuda-feature=+ptx61 -mllvm -openmp-opt-disable -nocudalib -nogpulib -nostdinc -DSHARED_SCRATCHPAD_SIZE=512)
+set(clang_lib_flags -fopenmp -fopenmp-cuda-mode -foffload-lto -fvisibility=hidden -Xopenmp-target=nvptx64-nvidia-cuda --cuda-feature=+ptx61 -nocudalib -nogpulib -nostdinc)
 foreach(arch ${nvptx_sm_list})
   set(clang_lib_flags ${clang_lib_flags} --offload-arch=sm_${arch})
 endforeach()
@@ -259,11 +252,43 @@
 endforeach()
 
 # Build the static library version of the device runtime.
+# first create an object target
+add_library(omptarget.devicertl.all_objs OBJECT IMPORTED)
+foreach(src ${src_files})
+  get_filename_component(infile ${src} ABSOLUTE)
+  get_filename_component(outfile ${src} NAME)
+  set(outfile "${outfile}.o")
+  set(outfile_full_path "${CMAKE_CURRENT_BINARY_DIR}/${outfile}")
+
+  add_custom_command(OUTPUT ${outfile_full_path}
+    COMMAND ${CLANG_TOOL} ${clang_lib_flags} ${clang_opt_flags} --std=c++17 -c
+            -o ${outfile_full_path}
+            -I${include_directory}
+            -I${devicertl_base_directory}/../include
+            ${LIBOMPTARGET_LLVM_INCLUDE_DIRS_DEVICERTL}
+            ${infile}
+    DEPENDS ${infile} ${include_files}
+    IMPLICIT_DEPENDS CXX ${infile}
+    COMMENT "Building device code ${outfile}"
+    VERBATIM
+  )
+  if("${CLANG_TOOL}" STREQUAL "$<TARGET_FILE:clang>")
+    # Add a file-level dependency to ensure that clang is up-to-date.
+    # By default, add_custom_command only builds clang if the
+    # executable is missing.
+    add_custom_command(OUTPUT ${outfile_full_path}
+      DEPENDS clang
+      APPEND
+    )
+  endif()
+  set_property(DIRECTORY APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES ${outfile_full_path})
+
+  set_property(TARGET omptarget.devicertl.all_objs APPEND PROPERTY IMPORTED_OBJECTS ${outfile_full_path})
+endforeach()
+
+# second archive all the object files into a static library
 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})
+set_target_properties(omptarget.devicertl PROPERTIES LINKER_LANGUAGE CXX)
+target_link_libraries(omptarget.devicertl PRIVATE omptarget.devicertl.all_objs)
 
 install(TARGETS omptarget.devicertl ARCHIVE DESTINATION ${OPENMP_INSTALL_LIBDIR})
-
-add_subdirectory(src)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D128130.438164.patch
Type: text/x-patch
Size: 3494 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/openmp-commits/attachments/20220619/391b9c46/attachment.bin>


More information about the Openmp-commits mailing list