Files
derek.holloway 7502bf64a4
CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
Flatten subprojects into a single base monorepo
2026-09-02 16:34:47 -07:00

176 lines
5.9 KiB
CMake

message(STATUS "Building offloading runtime library libomptarget.")
if(NOT TARGET "omp")
message(FATAL_ERROR "Error: omp target dependency of libomptarget not found. Please ensure 'openmp' is on LLVM_ENABLE_RUNTIMES list.")
endif()
add_library(omptarget SHARED
device.cpp
interface.cpp
omptarget.cpp
OffloadRTL.cpp
LegacyAPI.cpp
PluginManager.cpp
DeviceImage.cpp
OpenMP/API.cpp
OpenMP/Mapping.cpp
OpenMP/InteropAPI.cpp
OpenMP/OMPT/Callback.cpp
OpenMP/OMPT/OmptTracing.cpp
OpenMP/OMPT/OmptTracingBuffer.cpp
KernelLanguage/API.cpp
)
if(LLVM_LINK_LLVM_DYLIB)
set(llvm_libs LLVM)
else()
llvm_map_components_to_libnames(llvm_libs FrontendOpenMP Support Object)
endif()
target_link_libraries(omptarget PRIVATE omp ${llvm_libs})
target_include_directories(omptarget PRIVATE
${LIBOMPTARGET_INCLUDE_DIR} ${LIBOMPTARGET_BINARY_INCLUDE_DIR}
)
if (LIBOMP_HAVE_VERSION_SCRIPT_FLAG)
target_link_libraries(omptarget PRIVATE
"-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/exports")
endif()
# Don't override an externally defined RPATH
if(NOT DEFINED CMAKE_INSTALL_RPATH)
set_target_properties(omptarget PROPERTIES INSTALL_RPATH "$ORIGIN:$ORIGIN/../lib:$ORIGIN/../../lib" BUILD_RPATH "$ORIGIN")
else()
set_target_properties(omptarget PROPERTIES INSTALL_RPATH ${CMAKE_INSTALL_RPATH} BUILD_RPATH ${CMAKE_INSTALL_RPATH})
endif()
if (OPENMP_ENABLE_LIBOMPTARGET_PROFILING)
# Add LLVMSupport dependency if profiling is enabled.
# Linking with LLVM component libraries also requires
# aligning the compile flags.
llvm_update_compile_flags(omptarget)
target_compile_definitions(omptarget PUBLIC OMPTARGET_PROFILE_ENABLED)
target_link_libraries(omptarget PRIVATE LLVMSupport)
endif()
target_include_directories(omptarget PRIVATE ${LIBOMPTARGET_INCLUDE_DIR})
target_link_libraries(
omptarget
PRIVATE
${CMAKE_DL_LIBS}
"-Wl,--no-allow-shlib-undefined")
# Define the TARGET_NAME and DEBUG_PREFIX.
target_compile_definitions(omptarget PRIVATE
TARGET_NAME=omptarget
DEBUG_PREFIX="omptarget"
)
foreach(plugin IN LISTS LIBOMPTARGET_PLUGINS_TO_BUILD)
target_link_libraries(omptarget PRIVATE omptarget.rtl.${plugin})
endforeach()
target_compile_options(omptarget PRIVATE ${offload_compile_flags})
target_link_options(omptarget PRIVATE ${offload_link_flags})
if (OMPT_TARGET_DEFAULT AND LIBOMPTARGET_OMPT_SUPPORT)
target_link_libraries(omptarget PRIVATE PluginOmpt)
endif()
macro(check_plugin_target target)
if (TARGET omptarget.rtl.${target})
list(APPEND LIBOMPTARGET_PLUGINS_TO_LOAD ${target})
endif()
endmacro()
set(LIBOMPTARGET_PLUGINS_TO_LOAD "" CACHE STRING
"Comma separated list of plugin names to look for at runtime")
if (NOT LIBOMPTARGET_PLUGINS_TO_LOAD)
check_plugin_target(amdgpu)
check_plugin_target(host)
check_plugin_target(cuda)
endif()
list(TRANSFORM LIBOMPTARGET_PLUGINS_TO_LOAD PREPEND "\"libomptarget.rtl.")
list(TRANSFORM LIBOMPTARGET_PLUGINS_TO_LOAD APPEND "\"")
list(JOIN LIBOMPTARGET_PLUGINS_TO_LOAD "," ENABLED_OFFLOAD_PLUGINS)
target_compile_definitions(omptarget PRIVATE ENABLED_OFFLOAD_PLUGINS=${ENABLED_OFFLOAD_PLUGINS})
if(NOT DEFINED CMAKE_INSTALL_RPATH)
set_target_properties(omptarget PROPERTIES INSTALL_RPATH "$ORIGIN")
endif()
# libomptarget.so needs to be aware of where the plugins live as they
# are now separated in the build directory.
set_target_properties(omptarget PROPERTIES
POSITION_INDEPENDENT_CODE ON
BUILD_RPATH "$ORIGIN:${CMAKE_CURRENT_BINARY_DIR}/..")
if(UNIX AND NOT APPLE)
set_target_properties(omptarget PROPERTIES
SOVERSION "${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}${LLVM_VERSION_SUFFIX}"
VERSION "${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}${LLVM_VERSION_SUFFIX}")
endif()
install(TARGETS omptarget LIBRARY COMPONENT offload DESTINATION "${OFFLOAD_INSTALL_LIBDIR}")
#===============================================================================
# Ensure that omptarget does not contain a mixture of static and dynamically
# linked LLVM libs.
#===============================================================================
if (LLVM_LINK_LLVM_DYLIB)
if(LLVM_AVAILABLE_LIBS)
set(llvm_libs ${LLVM_AVAILABLE_LIBS})
else()
# Inside LLVM itself available libs are in a global property.
get_property(llvm_libs GLOBAL PROPERTY LLVM_LIBS)
endif()
#-----------------------------------------------------------------------------
# Helper function to recursively get the llvm targets that 'tgt' links against
#-----------------------------------------------------------------------------
function(get_llvm_link_targets var tgt visited)
if(${tgt} IN_LIST visited)
return()
endif()
list(APPEND visited ${tgt})
get_target_property(link_libs ${tgt} LINK_LIBRARIES)
if(NOT link_libs)
set(link_libs "")
endif()
get_target_property(i_link_libs ${tgt} INTERFACE_LINK_LIBRARIES)
if(i_link_libs)
list(APPEND link_libs ${i_link_libs})
endif()
if(NOT link_libs)
return()
endif()
list(REMOVE_DUPLICATES link_libs)
foreach(lib ${link_libs})
if(${lib} IN_LIST llvm_libs)
list(APPEND rv ${lib})
endif()
if(TARGET ${lib})
get_llvm_link_targets(indirect ${lib} visited)
list(APPEND rv ${indirect})
list(REMOVE_DUPLICATES rv)
endif()
endforeach()
set(${var} ${rv} PARENT_SCOPE)
endfunction()
#-----------------------------------------------------------------------------
# Check for extraneous libs
#-----------------------------------------------------------------------------
get_llvm_link_targets(llvm_link_targets omptarget "")
list(REMOVE_ITEM llvm_link_targets "LLVM")
if(llvm_link_targets)
list(JOIN llvm_link_targets " " pp_list)
message(
FATAL_ERROR
"'omptarget' should only link against 'LLVM' when 'LLVM_LINK_LLVM_DYLIB' "
"is on. Extraneous LLVM Libraries: ${pp_list}")
endif()
endif()