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
Merged

[offload] Standalone build fixes #118173

merged 8 commits into from
Dec 4, 2024

Conversation

mgorny
Copy link
Member

@mgorny mgorny commented Nov 30, 2024

A fair number of fixes to get standalone builds of offload working — mostly copying missing bits from openmp. It's almost ready — I still need to figure out why some of the tsts aren't linking to the right libraries.

@mgorny mgorny requested review from jdoerfert and jhuber6 November 30, 2024 14:58
Copy link
Contributor

@jhuber6 jhuber6 left a comment

Choose a reason for hiding this comment

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

Do you know if #117933 will conflict with anything here? It includes a header file cross-project.

mgorny added a commit to mgorny/llvm-project that referenced this pull request Nov 30, 2024
@mgorny mgorny force-pushed the offload-standalone branch from 1638053 to d72daa7 Compare November 30, 2024 16:15
@mgorny
Copy link
Member Author

mgorny commented Nov 30, 2024

Do you know if #117933 will conflict with anything here? It includes a header file cross-project.

We'll probably have to define LLVM_MAIN_SRC_DIR, but that shouldn't be a big problem.

Switched PluginCommon back to object library, and added updating explicit_llvm_config instead. Moved the FrontendOffloading dep to PluginCommon, as requested.

@mgorny mgorny requested review from MaskRay and thesamesam November 30, 2024 16:16
mgorny added a commit to mgorny/llvm-project that referenced this pull request Nov 30, 2024
@mgorny mgorny force-pushed the offload-standalone branch from d72daa7 to 2c39a1f Compare November 30, 2024 16:47
@mgorny mgorny marked this pull request as ready for review November 30, 2024 16:56
@mgorny
Copy link
Member Author

mgorny commented Nov 30, 2024

Ok, I think it's ready. The remaining test failures I see are in amdgcn-amd-amdhsa tests, and they fail with regular build for me as well. I'm guessing it's because I don't have HSA installed.

@mgorny
Copy link
Member Author

mgorny commented Dec 1, 2024

Moved the dependencies into add_target_library, as discussed. Also switched to reusing DetectTestCompiler from openmp instead of copying the files here.

@llvmbot
Copy link
Member

llvmbot commented Dec 1, 2024

@llvm/pr-subscribers-backend-amdgpu

Author: Michał Górny (mgorny)

Changes

A fair number of fixes to get standalone builds of offload working — mostly copying missing bits from openmp. It's almost ready — I still need to figure out why some of the tsts aren't linking to the right libraries.


Full diff: https://github.com/llvm/llvm-project/pull/118173.diff

6 Files Affected:

  • (modified) offload/CMakeLists.txt (+24)
  • (modified) offload/cmake/OpenMPTesting.cmake (+2-13)
  • (modified) offload/plugins-nextgen/CMakeLists.txt (+2)
  • (modified) offload/plugins-nextgen/amdgpu/CMakeLists.txt (+1-2)
  • (modified) offload/plugins-nextgen/common/CMakeLists.txt (+1-2)
  • (modified) offload/test/CMakeLists.txt (+8-3)
diff --git a/offload/CMakeLists.txt b/offload/CMakeLists.txt
index e24f0faa912117..2d2413688183bc 100644
--- a/offload/CMakeLists.txt
+++ b/offload/CMakeLists.txt
@@ -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.")
@@ -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
@@ -286,6 +290,26 @@ if(OPENMP_STANDALONE_BUILD)
       ${LLVM_LIBRARY_DIRS}
     REQUIRED
   )
+
+  find_path (
+    LIBOMP_INCLUDE_DIR
+    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
+    "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)
diff --git a/offload/cmake/OpenMPTesting.cmake b/offload/cmake/OpenMPTesting.cmake
index 6609d6301d0f93..20b640ab5a4a8e 100644
--- a/offload/cmake/OpenMPTesting.cmake
+++ b/offload/cmake/OpenMPTesting.cmake
@@ -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})
@@ -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)
@@ -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_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
diff --git a/offload/plugins-nextgen/CMakeLists.txt b/offload/plugins-nextgen/CMakeLists.txt
index d31bf557669eac..9b5b12bea7142f 100644
--- a/offload/plugins-nextgen/CMakeLists.txt
+++ b/offload/plugins-nextgen/CMakeLists.txt
@@ -12,6 +12,7 @@ function(add_target_library target_name lib_name)
       CodeGen
       Core
       Extensions
+      FrontendOffloading
       InstCombine
       Instrumentation
       IPO
@@ -20,6 +21,7 @@ function(add_target_library target_name lib_name)
       MC
       Object
       Passes
+      ProfileData
       Remarks
       ScalarOpts
       Support
diff --git a/offload/plugins-nextgen/amdgpu/CMakeLists.txt b/offload/plugins-nextgen/amdgpu/CMakeLists.txt
index b40c62d43226f4..47cd2feefc7288 100644
--- a/offload/plugins-nextgen/amdgpu/CMakeLists.txt
+++ b/offload/plugins-nextgen/amdgpu/CMakeLists.txt
@@ -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
diff --git a/offload/plugins-nextgen/common/CMakeLists.txt b/offload/plugins-nextgen/common/CMakeLists.txt
index 3a861a47eedabc..e771f150b03175 100644
--- a/offload/plugins-nextgen/common/CMakeLists.txt
+++ b/offload/plugins-nextgen/common/CMakeLists.txt
@@ -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)
@@ -43,7 +43,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
diff --git a/offload/test/CMakeLists.txt b/offload/test/CMakeLists.txt
index 5a6f637b57fa7b..8a827e0a625eff 100644
--- a/offload/test/CMakeLists.txt
+++ b/offload/test/CMakeLists.txt
@@ -28,6 +28,11 @@ 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)
@@ -35,7 +40,7 @@ foreach(CURRENT_TARGET IN LISTS SYSTEM_TARGETS)
   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})
 
@@ -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})

@llvmbot
Copy link
Member

llvmbot commented Dec 1, 2024

@llvm/pr-subscribers-offload

Author: Michał Górny (mgorny)

Changes

A fair number of fixes to get standalone builds of offload working — mostly copying missing bits from openmp. It's almost ready — I still need to figure out why some of the tsts aren't linking to the right libraries.


Full diff: https://github.com/llvm/llvm-project/pull/118173.diff

6 Files Affected:

  • (modified) offload/CMakeLists.txt (+24)
  • (modified) offload/cmake/OpenMPTesting.cmake (+2-13)
  • (modified) offload/plugins-nextgen/CMakeLists.txt (+2)
  • (modified) offload/plugins-nextgen/amdgpu/CMakeLists.txt (+1-2)
  • (modified) offload/plugins-nextgen/common/CMakeLists.txt (+1-2)
  • (modified) offload/test/CMakeLists.txt (+8-3)
diff --git a/offload/CMakeLists.txt b/offload/CMakeLists.txt
index e24f0faa912117..2d2413688183bc 100644
--- a/offload/CMakeLists.txt
+++ b/offload/CMakeLists.txt
@@ -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.")
@@ -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
@@ -286,6 +290,26 @@ if(OPENMP_STANDALONE_BUILD)
       ${LLVM_LIBRARY_DIRS}
     REQUIRED
   )
+
+  find_path (
+    LIBOMP_INCLUDE_DIR
+    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
+    "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)
diff --git a/offload/cmake/OpenMPTesting.cmake b/offload/cmake/OpenMPTesting.cmake
index 6609d6301d0f93..20b640ab5a4a8e 100644
--- a/offload/cmake/OpenMPTesting.cmake
+++ b/offload/cmake/OpenMPTesting.cmake
@@ -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})
@@ -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)
@@ -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_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
diff --git a/offload/plugins-nextgen/CMakeLists.txt b/offload/plugins-nextgen/CMakeLists.txt
index d31bf557669eac..9b5b12bea7142f 100644
--- a/offload/plugins-nextgen/CMakeLists.txt
+++ b/offload/plugins-nextgen/CMakeLists.txt
@@ -12,6 +12,7 @@ function(add_target_library target_name lib_name)
       CodeGen
       Core
       Extensions
+      FrontendOffloading
       InstCombine
       Instrumentation
       IPO
@@ -20,6 +21,7 @@ function(add_target_library target_name lib_name)
       MC
       Object
       Passes
+      ProfileData
       Remarks
       ScalarOpts
       Support
diff --git a/offload/plugins-nextgen/amdgpu/CMakeLists.txt b/offload/plugins-nextgen/amdgpu/CMakeLists.txt
index b40c62d43226f4..47cd2feefc7288 100644
--- a/offload/plugins-nextgen/amdgpu/CMakeLists.txt
+++ b/offload/plugins-nextgen/amdgpu/CMakeLists.txt
@@ -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
diff --git a/offload/plugins-nextgen/common/CMakeLists.txt b/offload/plugins-nextgen/common/CMakeLists.txt
index 3a861a47eedabc..e771f150b03175 100644
--- a/offload/plugins-nextgen/common/CMakeLists.txt
+++ b/offload/plugins-nextgen/common/CMakeLists.txt
@@ -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)
@@ -43,7 +43,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
diff --git a/offload/test/CMakeLists.txt b/offload/test/CMakeLists.txt
index 5a6f637b57fa7b..8a827e0a625eff 100644
--- a/offload/test/CMakeLists.txt
+++ b/offload/test/CMakeLists.txt
@@ -28,6 +28,11 @@ 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)
@@ -35,7 +40,7 @@ foreach(CURRENT_TARGET IN LISTS SYSTEM_TARGETS)
   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})
 
@@ -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})

@@ -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.


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…

@mgorny mgorny force-pushed the offload-standalone branch from d9d6d42 to d493d69 Compare December 1, 2024 18:36
@jplehr
Copy link
Contributor

jplehr commented Dec 2, 2024

What is the understanding of a standalone build here? Would you mind sharing an example CMake invocation? Thank you.

@mgorny
Copy link
Member Author

mgorny commented Dec 2, 2024

What is the understanding of a standalone build here? Would you mind sharing an example CMake invocation? Thank you.

cmake -G Ninja .../llvm-project/offload

The one indicated by OPENMP_STANDALONE_BUILD.

Copy link
Member

@thesamesam thesamesam left a comment

Choose a reason for hiding this comment

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

No concerns from me, at least.

@thesamesam
Copy link
Member

@jhuber6 Is it OK if we go ahead with this as-is? We can file a bug for reconsidering some of the split if needed, but right now, offload is broken in our configuration and has been for quite some time - and we had some users start requesting it.

@jplehr
Copy link
Contributor

jplehr commented Dec 3, 2024

Can you see if your patch still works or needs some modification after #117933 has landed? Once confirmed, I think we can accept.
Thank you, much appreciated!

I ran this through some buildbot configs and did not see any issues.

@mgorny
Copy link
Member Author

mgorny commented Dec 3, 2024

Can you see if your patch still works or needs some modification after #117933 has landed? Once confirmed, I think we can accept. Thank you, much appreciated!

It will need changes to correctly get libc path. Otherwise, it ends up using -I/../libc and fails to build:

[1/948] Building LLVM bitcode Misc.cpp-gfx700.bc
FAILED: DeviceRTL/Misc.cpp-gfx700.bc /home/mgorny/git/llvm-project/offload/build/DeviceRTL/Misc.cpp-gfx700.bc 
cd /home/mgorny/git/llvm-project/offload/build/DeviceRTL && /usr/lib/llvm/20/bin/clang -c -foffload-lto -std=c++17 -fvisibility=hidden -O3 -mllvm -openmp-opt-disable -DSHARED_SCRATCHPAD_SIZE=512 -mllvm -vectorize-slp=false --offload-device-only -nocudalib -nogpulib -nogpuinc -nostdlibinc -fopenmp -fopenmp-cuda-mode -Wno-unknown-cuda-version -DOMPTARGET_DEVICE_RUNTIME -I/home/mgorny/git/llvm-project/offload/DeviceRTL/include -I/home/mgorny/git/llvm-project/offload/DeviceRTL/../include -I/../libc -I/usr/lib/llvm/20/include --offload-arch=gfx700 -Xclang -mcode-object-version=none -MD -MF Misc.cpp-gfx700.bc.d /home/mgorny/git/llvm-project/offload/DeviceRTL/src/Misc.cpp -o Misc.cpp-gfx700.bc && /usr/bin/cmake -E cmake_transform_depfile Ninja gccdepfile /home/mgorny/git/llvm-project/offload /home/mgorny/git/llvm-project/offload/DeviceRTL /home/mgorny/git/llvm-project/offload/build /home/mgorny/git/llvm-project/offload/build/DeviceRTL /home/mgorny/git/llvm-project/offload/build/DeviceRTL/Misc.cpp-gfx700.bc.d /home/mgorny/git/llvm-project/offload/build/CMakeFiles/d/9c7958eff40701604e86ea8dc6b37f4c825ec8823d58e7cb26ac0ea9f8a5c29b.d
/home/mgorny/git/llvm-project/offload/DeviceRTL/src/Misc.cpp:16:10: fatal error: 'shared/rpc.h' file not found
   16 | #include "shared/rpc.h"
      |          ^~~~~~~~~~~~~~
1 error generated.
[14/948] Building LLVM bitcode Parallelism.cpp-gfx700.bc
ninja: build stopped: subcommand failed.

I can make a PR to that PR branch, if you'd like, though it'd probably be cleaner if it were rebased on this one first — or just submit another fix once it's merged.

@jplehr
Copy link
Contributor

jplehr commented Dec 3, 2024

I personally would appreciate to rebase this PR and add the changes required to work with the libc patch. Don't know how difficult that will be though.

@mgorny
Copy link
Member Author

mgorny commented Dec 3, 2024

I personally would appreciate to rebase this PR and add the changes required to work with the libc patch. Don't know how difficult that will be though.

Actually, the right approach would be to fix the libc path not to use LLVM_MAIN_SRC_DIR (after all, it's not using llvm subdirectory at all), and instead declare a path relative to CMAKE_CURRENT_SOURCE_DIR, much like LLVM_COMMON_CMAKE_UTILS is declared now.

@jplehr
Copy link
Contributor

jplehr commented Dec 3, 2024

I personally would appreciate to rebase this PR and add the changes required to work with the libc patch. Don't know how difficult that will be though.

Actually, the right approach would be to fix the libc path not to use LLVM_MAIN_SRC_DIR (after all, it's not using llvm subdirectory at all), and instead declare a path relative to CMAKE_CURRENT_SOURCE_DIR, much like LLVM_COMMON_CMAKE_UTILS is declared now.

We could key off of devicertl_base_directory which is already used in those places.

@arsenm arsenm added the cmake Build system in general and CMake in particular label Dec 3, 2024
jplehr added a commit that referenced this pull request Dec 3, 2024
This was discussed as a potential solution in
#118173
@mgorny
Copy link
Member Author

mgorny commented Dec 4, 2024

Thanks!

Is it okay to merge this now? I'd also like to try backporting it for 19.x (at least for Gentoo, ideally upstream too).

Copy link
Contributor

@jplehr jplehr left a comment

Choose a reason for hiding this comment

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

LGTM
I ran it through a couple of configs locally.

Include CheckCXXCompilerFlag before it is used in the top-level CMake
file.  This fixes standalone builds, but it is also cleaner than
assuming that some previous CMake file will include it for us.
Add the `omp` target dependency to tests only when the respective target
is present, i.e. when not building standalone against system libomp.
Copy the `OPENMP_TEST_FLAGS` and `OPENMP_TEST_OPENMP_FLAGS` from openmp
for standalone builds, as required by the lit configs.
Define `LIBOMPTARGET_OPENMP_HEADER_FOLDER`
and `LIBOMPTARGET_OPENMP_HOST_RTL_FOLDER` needed for testing
in standalone builds.
Fix path to `llvm-offload-device-info` tool in standalone build.
This tool is built as part of offload, so rather than looking it up
as a preinstalled tool, set correct `LLVM_RUNTIME_OUTPUT_INTDIR`
for the `llvm_add_tool()` call, and unconditionally set
`OFFLOAD_DEVICE_INFO_EXECUTABLE` using that directory.
Move the dependencies on `LLVMFrontendOffloading` and `LLVMProfileData`
from amdgpu and common, respectively, to the base `add_target_library()`
macro.  This means we can take advantage of LINK_COMPONENTS and do not
have to add extra complexity to handle dylib and standalone builds.
Fix the DetectTestCompiler project use to reference the openmp source
tree, since the respective files were not copied to offload, and there
is no point in duplicating them.

Fixes llvm#90333
@mgorny mgorny force-pushed the offload-standalone branch from d493d69 to 931cf3c Compare December 4, 2024 11:21
@mgorny mgorny merged commit 04b26f0 into llvm:main Dec 4, 2024
6 checks passed
@mgorny mgorny deleted the offload-standalone branch December 4, 2024 11:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend:AMDGPU cmake Build system in general and CMake in particular offload
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants