Skip to content

[offload] Standalone build fixes #118173

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Dec 4, 2024
24 changes: 24 additions & 0 deletions offload/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ if (OPENMP_STANDALONE_BUILD)
# Do not use OPENMP_LIBDIR_SUFFIX directly, use OPENMP_INSTALL_LIBDIR.
set(OPENMP_INSTALL_LIBDIR "lib${OPENMP_LIBDIR_SUFFIX}")

# Used by llvm_add_tool() and tests.
set(LLVM_RUNTIME_OUTPUT_INTDIR ${CMAKE_CURRENT_BINARY_DIR})

# Group test settings.
set(OPENMP_TEST_C_COMPILER ${CMAKE_C_COMPILER} CACHE STRING
"C compiler to use for testing OpenMP runtime libraries.")
Expand Down Expand Up @@ -129,6 +132,7 @@ include(LibomptargetGetDependencies)
# Set up testing infrastructure.
include(OpenMPTesting)

include(CheckCXXCompilerFlag)
check_cxx_compiler_flag(-Werror=global-constructors OFFLOAD_HAVE_WERROR_CTOR)

# LLVM source tree is required at build time for libomptarget
Expand Down Expand Up @@ -286,6 +290,26 @@ if(OPENMP_STANDALONE_BUILD)
${LLVM_LIBRARY_DIRS}
REQUIRED
)

find_path (
LIBOMP_INCLUDE_DIR
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fact that offload is still depending on libomp is a disaster…

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will forever maintain that only the plugins should've been moved. Maybe it's not too late to do that instead.

NAMES
omp.h
HINTS
${COMPILER_RESOURCE_DIR}/include
${CMAKE_INSTALL_PREFIX}/include
)

get_filename_component(LIBOMP_LIBRARY_DIR ${LIBOMP_STANDALONE} DIRECTORY)

set(OPENMP_TEST_FLAGS "" CACHE STRING
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are basically pulling in things from libomp. Why did we split them up at the first place then…

"Extra compiler flags to send to the test compiler.")
set(OPENMP_TEST_OPENMP_FLAGS ${OPENMP_TEST_COMPILER_OPENMP_FLAGS} CACHE STRING
"OpenMP compiler flag to use for testing OpenMP runtime libraries.")
set(LIBOMPTARGET_OPENMP_HEADER_FOLDER "${LIBOMP_INCLUDE_DIR}" CACHE STRING
"Path to folder containing omp.h")
set(LIBOMPTARGET_OPENMP_HOST_RTL_FOLDER "${LIBOMP_LIBRARY_DIR}" CACHE STRING
"Path to folder containing libomp.so, and libLLVMSupport.so with profiling enabled")
endif()

macro(pythonize_bool var)
Expand Down
15 changes: 2 additions & 13 deletions offload/cmake/OpenMPTesting.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,6 @@ function(find_standalone_test_dependencies)
return()
endif()

find_program(OFFLOAD_DEVICE_INFO_EXECUTABLE
NAMES llvm-offload-device-info
PATHS ${OPENMP_LLVM_TOOLS_DIR})
if (NOT OFFLOAD_DEVICE_INFO_EXECUTABLE)
message(STATUS "Cannot find 'llvm-offload-device-info'.")
message(STATUS "Please put 'not' in your PATH, set OFFLOAD_DEVICE_INFO_EXECUTABLE to its full path, or point OPENMP_LLVM_TOOLS_DIR to its directory.")
message(WARNING "The check targets will not be available!")
set(ENABLE_CHECK_TARGETS FALSE PARENT_SCOPE)
return()
endif()

find_program(OPENMP_NOT_EXECUTABLE
NAMES not
PATHS ${OPENMP_LLVM_TOOLS_DIR})
Expand Down Expand Up @@ -82,8 +71,8 @@ else()
set(OPENMP_FILECHECK_EXECUTABLE ${LLVM_RUNTIME_OUTPUT_INTDIR}/FileCheck)
endif()
set(OPENMP_NOT_EXECUTABLE ${LLVM_RUNTIME_OUTPUT_INTDIR}/not)
set(OFFLOAD_DEVICE_INFO_EXECUTABLE ${LLVM_RUNTIME_OUTPUT_INTDIR}/llvm-offload-device-info)
endif()
set(OFFLOAD_DEVICE_INFO_EXECUTABLE ${LLVM_RUNTIME_OUTPUT_INTDIR}/llvm-offload-device-info)

# Macro to extract information about compiler from file. (no own scope)
macro(extract_test_compiler_information lang file)
Expand Down Expand Up @@ -136,7 +125,7 @@ if (${OPENMP_STANDALONE_BUILD})
# project is built which is too late for detecting the compiler...
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/DetectTestCompiler)
execute_process(
COMMAND ${CMAKE_COMMAND} -G${CMAKE_GENERATOR} ${CMAKE_CURRENT_LIST_DIR}/DetectTestCompiler
COMMAND ${CMAKE_COMMAND} -G${CMAKE_GENERATOR} ${CMAKE_CURRENT_SOURCE_DIR}/../openmp/cmake/DetectTestCompiler
-DCMAKE_C_COMPILER=${OPENMP_TEST_C_COMPILER}
-DCMAKE_CXX_COMPILER=${OPENMP_TEST_CXX_COMPILER}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/DetectTestCompiler
Expand Down
2 changes: 2 additions & 0 deletions offload/plugins-nextgen/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ function(add_target_library target_name lib_name)
CodeGen
Core
Extensions
FrontendOffloading
InstCombine
Instrumentation
IPO
Expand All @@ -20,6 +21,7 @@ function(add_target_library target_name lib_name)
MC
Object
Passes
ProfileData
Remarks
ScalarOpts
Support
Expand Down
3 changes: 1 addition & 2 deletions offload/plugins-nextgen/amdgpu/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,11 @@ target_include_directories(omptarget.rtl.amdgpu PRIVATE

if(hsa-runtime64_FOUND AND NOT "amdgpu" IN_LIST LIBOMPTARGET_DLOPEN_PLUGINS)
message(STATUS "Building AMDGPU plugin linked against libhsa")
target_link_libraries(omptarget.rtl.amdgpu PRIVATE hsa-runtime64::hsa-runtime64 LLVMFrontendOffloading)
target_link_libraries(omptarget.rtl.amdgpu PRIVATE hsa-runtime64::hsa-runtime64)
else()
message(STATUS "Building AMDGPU plugin for dlopened libhsa")
target_include_directories(omptarget.rtl.amdgpu PRIVATE dynamic_hsa)
target_sources(omptarget.rtl.amdgpu PRIVATE dynamic_hsa/hsa.cpp)
target_link_libraries(omptarget.rtl.amdgpu PRIVATE LLVMFrontendOffloading)
endif()

# Configure testing for the AMDGPU plugin. We will build tests if we could a
Expand Down
3 changes: 1 addition & 2 deletions offload/plugins-nextgen/common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ add_library(PluginCommon OBJECT
src/RPC.cpp
src/Utils/ELF.cpp
)
add_dependencies(PluginCommon intrinsics_gen LLVMProfileData)
add_dependencies(PluginCommon intrinsics_gen)

# Only enable JIT for those targets that LLVM can support.
set(supported_jit_targets AMDGPU NVPTX)
Expand Down Expand Up @@ -44,7 +44,6 @@ target_compile_definitions(PluginCommon PRIVATE

target_compile_options(PluginCommon PUBLIC ${offload_compile_flags})
target_link_options(PluginCommon PUBLIC ${offload_link_flags})
target_link_libraries(PluginCommon PRIVATE LLVMProfileData)

target_include_directories(PluginCommon PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/include
Expand Down
11 changes: 8 additions & 3 deletions offload/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,19 @@ if(CUDAToolkit_FOUND)
get_filename_component(CUDA_LIBDIR "${CUDA_cudart_static_LIBRARY}" DIRECTORY)
endif()

set(OMP_DEPEND)
if(TARGET omp)
set(OMP_DEPEND omp)
endif()

string(REGEX MATCHALL "([^\ ]+\ |[^\ ]+$)" SYSTEM_TARGETS "${LIBOMPTARGET_SYSTEM_TARGETS}")
foreach(CURRENT_TARGET IN LISTS SYSTEM_TARGETS)
string(STRIP "${CURRENT_TARGET}" CURRENT_TARGET)

add_offload_testsuite(check-libomptarget-${CURRENT_TARGET}
"Running libomptarget tests"
${CMAKE_CURRENT_BINARY_DIR}/${CURRENT_TARGET}
DEPENDS omptarget omp ${LIBOMPTARGET_TESTED_PLUGINS}
DEPENDS omptarget ${OMP_DEPEND} ${LIBOMPTARGET_TESTED_PLUGINS}
ARGS ${LIBOMPTARGET_LIT_ARG_LIST})
list(APPEND LIBOMPTARGET_LIT_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/${CURRENT_TARGET})

Expand All @@ -49,12 +54,12 @@ add_offload_testsuite(check-libomptarget
"Running libomptarget tests"
${LIBOMPTARGET_LIT_TESTSUITES}
EXCLUDE_FROM_CHECK_ALL
DEPENDS omptarget omp ${LIBOMPTARGET_TESTED_PLUGINS}
DEPENDS llvm-offload-device-info omptarget ${OMP_DEPEND} ${LIBOMPTARGET_TESTED_PLUGINS}
ARGS ${LIBOMPTARGET_LIT_ARG_LIST})

add_offload_testsuite(check-offload
"Running libomptarget tests"
${LIBOMPTARGET_LIT_TESTSUITES}
EXCLUDE_FROM_CHECK_ALL
DEPENDS omptarget omp ${LIBOMPTARGET_TESTED_PLUGINS}
DEPENDS llvm-offload-device-info omptarget ${OMP_DEPEND} ${LIBOMPTARGET_TESTED_PLUGINS}
ARGS ${LIBOMPTARGET_LIT_ARG_LIST})
Loading