99 lines · plain
1# Ensure the compiler is a valid clang when building the GPU target.2set(req_ver "${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}.${LLVM_VERSION_PATCH}")3if(LLVM_VERSION_MAJOR AND NOT (CMAKE_CXX_COMPILER_ID MATCHES "[Cc]lang" AND4 ${CMAKE_CXX_COMPILER_VERSION} VERSION_EQUAL "${req_ver}"))5 message(FATAL_ERROR "Cannot build GPU device runtime. CMake compiler "6 "'${CMAKE_CXX_COMPILER_ID} ${CMAKE_CXX_COMPILER_VERSION}' "7 " is not 'Clang ${req_ver}'.")8endif()9 10set(src_files11 ${CMAKE_CURRENT_SOURCE_DIR}/src/Allocator.cpp12 ${CMAKE_CURRENT_SOURCE_DIR}/src/Configuration.cpp13 ${CMAKE_CURRENT_SOURCE_DIR}/src/Debug.cpp14 ${CMAKE_CURRENT_SOURCE_DIR}/src/Kernel.cpp15 ${CMAKE_CURRENT_SOURCE_DIR}/src/LibC.cpp16 ${CMAKE_CURRENT_SOURCE_DIR}/src/Mapping.cpp17 ${CMAKE_CURRENT_SOURCE_DIR}/src/Misc.cpp18 ${CMAKE_CURRENT_SOURCE_DIR}/src/Parallelism.cpp19 ${CMAKE_CURRENT_SOURCE_DIR}/src/Profiling.cpp20 ${CMAKE_CURRENT_SOURCE_DIR}/src/Reduction.cpp21 ${CMAKE_CURRENT_SOURCE_DIR}/src/State.cpp22 ${CMAKE_CURRENT_SOURCE_DIR}/src/Synchronization.cpp23 ${CMAKE_CURRENT_SOURCE_DIR}/src/Tasking.cpp24 ${CMAKE_CURRENT_SOURCE_DIR}/src/DeviceUtils.cpp25 ${CMAKE_CURRENT_SOURCE_DIR}/src/Workshare.cpp26)27 28list(APPEND compile_options -flto)29list(APPEND compile_options -fvisibility=hidden)30list(APPEND compile_options -nogpulib)31list(APPEND compile_options -nostdlibinc)32list(APPEND compile_options -fno-rtti)33list(APPEND compile_options -fno-exceptions)34list(APPEND compile_options -fconvergent-functions)35list(APPEND compile_options -Wno-unknown-cuda-version)36if(LLVM_DEFAULT_TARGET_TRIPLE)37 list(APPEND compile_options --target=${LLVM_DEFAULT_TARGET_TRIPLE})38endif()39 40# We disable the slp vectorizer during the runtime optimization to avoid41# vectorized accesses to the shared state. Generally, those are "good" but42# the optimizer pipeline (esp. Attributor) does not fully support vectorized43# instructions yet and we end up missing out on way more important constant44# propagation. That said, we will run the vectorizer again after the runtime45# has been linked into the user program.46list(APPEND compile_options "SHELL: -mllvm -vectorize-slp=false")47if("${LLVM_DEFAULT_TARGET_TRIPLE}" MATCHES "^amdgcn" OR48 "${CMAKE_CXX_COMPILER_TARGET}" MATCHES "^amdgcn")49 set(target_name "amdgpu")50 list(APPEND compile_options "SHELL:-Xclang -mcode-object-version=none")51elseif("${LLVM_DEFAULT_TARGET_TRIPLE}" MATCHES "^nvptx" OR52 "${CMAKE_CXX_COMPILER_TARGET}" MATCHES "^nvptx")53 set(target_name "nvptx")54 list(APPEND compile_options --cuda-feature=+ptx63)55endif()56 57# Trick to combine these into a bitcode file via the linker's LTO pass.58add_executable(libompdevice ${src_files})59set_target_properties(libompdevice PROPERTIES60 RUNTIME_OUTPUT_DIRECTORY "${LLVM_LIBRARY_OUTPUT_INTDIR}/${LLVM_DEFAULT_TARGET_TRIPLE}"61 LINKER_LANGUAGE CXX62 BUILD_RPATH ""63 INSTALL_RPATH ""64 RUNTIME_OUTPUT_NAME libomptarget-${target_name}.bc)65 66# If the user built with the GPU C library enabled we will use that instead.67if(TARGET libc)68 target_compile_definitions(libompdevice PRIVATE OMPTARGET_HAS_LIBC)69endif()70target_compile_definitions(libompdevice PRIVATE SHARED_SCRATCHPAD_SIZE=512)71 72target_include_directories(libompdevice PRIVATE73 ${CMAKE_CURRENT_SOURCE_DIR}/include74 ${CMAKE_CURRENT_SOURCE_DIR}/../../libc75 ${CMAKE_CURRENT_SOURCE_DIR}/../../offload/include)76target_compile_options(libompdevice PRIVATE ${compile_options})77target_link_options(libompdevice PRIVATE78 "-flto" "-r" "-nostdlib" "-Wl,--lto-emit-llvm")79if(LLVM_DEFAULT_TARGET_TRIPLE)80 target_link_options(libompdevice PRIVATE "--target=${LLVM_DEFAULT_TARGET_TRIPLE}")81endif()82install(TARGETS libompdevice83 PERMISSIONS OWNER_WRITE OWNER_READ GROUP_READ WORLD_READ84 DESTINATION ${OPENMP_INSTALL_LIBDIR})85 86add_library(ompdevice.all_objs OBJECT IMPORTED)87set_property(TARGET ompdevice.all_objs APPEND PROPERTY IMPORTED_OBJECTS88 ${LLVM_LIBRARY_OUTPUT_INTDIR}/${LLVM_DEFAULT_TARGET_TRIPLE}/libomptarget-${target_name}.bc)89 90# Archive all the object files generated above into a static library91add_library(ompdevice STATIC)92add_dependencies(ompdevice libompdevice)93set_target_properties(ompdevice PROPERTIES94 ARCHIVE_OUTPUT_DIRECTORY "${LLVM_LIBRARY_OUTPUT_INTDIR}/${LLVM_DEFAULT_TARGET_TRIPLE}"95 LINKER_LANGUAGE CXX96)97target_link_libraries(ompdevice PRIVATE ompdevice.all_objs)98install(TARGETS ompdevice ARCHIVE DESTINATION "${OPENMP_INSTALL_LIBDIR}")99