[Openmp-commits] [PATCH] D128130: [libomptarget] Make libomptarget.devicertl.a built in all cases.
Ye Luo via Phabricator via Openmp-commits
openmp-commits at lists.llvm.org
Sun Jun 19 14:11:21 PDT 2022
ye-luo updated this revision to Diff 438217.
ye-luo added a comment.
Use -O3 in DeviceRTL static library build.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D128130/new/
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 -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()
@@ -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} --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.438217.patch
Type: text/x-patch
Size: 3535 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/openmp-commits/attachments/20220619/00ab42d1/attachment.bin>
More information about the Openmp-commits
mailing list