[Openmp-commits] [openmp] 4d9499e - [libomptarget] Make libomptarget.devicertl.a built in all cases.
Ye Luo via Openmp-commits
openmp-commits at lists.llvm.org
Mon Jun 20 06:29:55 PDT 2022
Author: Ye Luo
Date: 2022-06-20T08:29:16-05:00
New Revision: 4d9499e8cc39080e50f75d6059737bcc5cc43847
URL: https://github.com/llvm/llvm-project/commit/4d9499e8cc39080e50f75d6059737bcc5cc43847
DIFF: https://github.com/llvm/llvm-project/commit/4d9499e8cc39080e50f75d6059737bcc5cc43847.diff
LOG: [libomptarget] Make libomptarget.devicertl.a built in all cases.
Make libomptarget.device.a built when using -DLLVM_ENABLE_PROJECTS=openmp
Use add_custom_command.
Reviewed By: jhuber6
Differential Revision: https://reviews.llvm.org/D128130
Added:
Modified:
openmp/libomptarget/DeviceRTL/CMakeLists.txt
Removed:
################################################################################
diff --git a/openmp/libomptarget/DeviceRTL/CMakeLists.txt b/openmp/libomptarget/DeviceRTL/CMakeLists.txt
index 5a1386f0bfe85..00324df4f1704 100644
--- a/openmp/libomptarget/DeviceRTL/CMakeLists.txt
+++ b/openmp/libomptarget/DeviceRTL/CMakeLists.txt
@@ -244,15 +244,8 @@ foreach(mcpu ${amdgpu_mcpus})
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 -mllvm -openmp-opt-disable -nocudalib -nogpulib -nostdinc -DSHARED_SCRATCHPAD_SIZE=512 -O3)
foreach(arch ${nvptx_sm_list})
set(clang_lib_flags ${clang_lib_flags} --offload-arch=sm_${arch})
endforeach()
@@ -261,11 +254,43 @@ foreach(arch ${amdgpu_mcpus})
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} --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)
More information about the Openmp-commits
mailing list