This is an archive of the discontinued LLVM Phabricator instance.

[Clang][OpenMP] libompd: get libomp hwloc includedir by target_link_libraries
ClosedPublic

Authored by bernhardkaindl on Apr 15 2022, 7:16 PM.

Details

Summary

When hwloc is used and is installed outside of the default paths, the omp CMake target
needs to provide the needed include path thru the CMake target by adding it with
target_include_directories to it, so libompd gets it as well when it defines it's cmake
target using target_link_libraries.

As suggested in D122667

Diff Detail

Event Timeline

bernhardkaindl created this revision.Apr 15 2022, 7:16 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 15 2022, 7:16 PM
bernhardkaindl requested review of this revision.Apr 15 2022, 7:16 PM
Herald added a project: Restricted Project. · View Herald Transcript
bernhardkaindl edited the summary of this revision. (Show Details)Apr 15 2022, 7:18 PM
ye-luo requested changes to this revision.Apr 15 2022, 7:42 PM
ye-luo added a subscriber: ye-luo.
ye-luo added inline comments.
openmp/runtime/src/CMakeLists.txt
158

Please fix
https://github.com/llvm/llvm-project/blob/dd018b96d4cce044feb9edd6b5da59b718231ace/openmp/runtime/cmake/config-ix.cmake#L336
check_include_file(hwloc.h LIBOMP_HAVE_HWLOC_H)
guarantees the hwloc.h file can be found but doesn't mean ${LIBOMP_HWLOC_INSTALL_DIR}/include is a valid path.
Please add before check_include_file
find_path(LIBOMP_HWLOC_INCLUDE_DIR NAMES hwloc.h HINTS ${LIBOMP_HWLOC_INSTALL_DIR} PATH_SUFFIXES include)
to confirm a solid include path to the header file,
and then use LIBOMP_HWLOC_INCLUDE_DIR in target_include_directories here.

This revision now requires changes to proceed.Apr 15 2022, 7:42 PM
bernhardkaindl updated this revision to Diff 423208.EditedApr 15 2022, 8:10 PM

Thanks, added:

--- a/openmp/runtime/cmake/config-ix.cmake
+++ b/openmp/runtime/cmake/config-ix.cmake
@@ -333,6 +333,7 @@ endif()
 # Check if HWLOC support is available
 if(${LIBOMP_USE_HWLOC})
   set(CMAKE_REQUIRED_INCLUDES ${LIBOMP_HWLOC_INSTALL_DIR}/include)
+  find_path(LIBOMP_HWLOC_INCLUDE_DIR NAMES hwloc.h HINTS ${LIBOMP_HWLOC_INSTALL_DIR} PATH_SUFFIXES include)
   check_include_file(hwloc.h LIBOMP_HAVE_HWLOC_H)
   set(CMAKE_REQUIRED_INCLUDES)
   find_library(LIBOMP_HWLOC_LIBRARY

And use the created LIBOMP_HWLOC_INCLUDE_DIR here:

--- a/openmp/runtime/src/CMakeLists.txt
+++ b/openmp/runtime/src/CMakeLists.txt
@@ -157,6 +154,13 @@ else()
   # libomp must be a C++ library such that it can link libLLVMSupport
   set(LIBOMP_LINKER_LANGUAGE CXX)
 endif()
+if(${LIBOMP_USE_HWLOC})
+  target_include_directories(omp
+                             PUBLIC
+          "$<BUILD_INTERFACE:${LIBOMP_HWLOC_INCLUDE_DIR}>"
+          "$<INSTALL_INTERFACE:${LIBOMP_HWLOC_INCLUDE_DIR}>"
+  )
+endif()

 if(OPENMP_MSVC_NAME_SCHEME)
   if(uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG")

Exactly as suggested. Thanks @ye-luo for the exact blueprint what to do!

ye-luo accepted this revision.Apr 15 2022, 8:16 PM

One minor change requested. All the rest LGTM.

openmp/runtime/cmake/config-ix.cmake
336

Please remove line 335 and add after 336
set(CMAKE_REQUIRED_INCLUDES ${LIBOMP_HWLOC_INCLUDE_DIR})

This revision is now accepted and ready to land.Apr 15 2022, 8:16 PM
bernhardkaindl updated this revision to Diff 423211.EditedApr 15 2022, 8:33 PM

Looks perfect now! Thanks @ye-luo, incremental diff:

--- openmp/runtime/cmake/config-ix.cmake.2
+++ openmp/runtime/cmake/config-ix.cmake.3
@@ -333,6 +333,6 @@
 # Check if HWLOC support is available
 if(${LIBOMP_USE_HWLOC})
-  set(CMAKE_REQUIRED_INCLUDES ${LIBOMP_HWLOC_INSTALL_DIR}/include)
   find_path(LIBOMP_HWLOC_INCLUDE_DIR NAMES hwloc.h HINTS ${LIBOMP_HWLOC_INSTALL_DIR} PATH_SUFFIXES include)
+  set(CMAKE_REQUIRED_INCLUDES ${LIBOMP_HWLOC_INCLUDE_DIR})
   check_include_file(hwloc.h LIBOMP_HAVE_HWLOC_H)
   set(CMAKE_REQUIRED_INCLUDES)

I believe we would not even need the new line 336

set(CMAKE_REQUIRED_INCLUDES ${LIBOMP_HWLOC_INCLUDE_DIR})

anymore because of "$<BUILD_INTERFACE:${LIBOMP_HWLOC_INCLUDE_DIR}>", here, but if in doubt, the current revision LGTM too.

--- a/openmp/runtime/src/CMakeLists.txt
+++ b/openmp/runtime/src/CMakeLists.txt
@@ -157,6 +154,13 @@ else()
   # libomp must be a C++ library such that it can link libLLVMSupport
   set(LIBOMP_LINKER_LANGUAGE CXX)
 endif()
+if(${LIBOMP_USE_HWLOC})
+  target_include_directories(omp
+                             PUBLIC
+                            "$<BUILD_INTERFACE:${LIBOMP_HWLOC_INCLUDE_DIR}>"
+                            "$<INSTALL_INTERFACE:${LIBOMP_HWLOC_INCLUDE_DIR}>"
+  )
+endif()

I test using a build of llvm (using ninja) and didn't test a standalone build of just openmp

check_include_file is like writing an empty main with one include line and gets it compiled. So it doesn't pull any dependency.
To test whether hwloc.h is a valid header file, you'd need to provide CMAKE_REQUIRED_INCLUDES pointing to hwloc.h.
So it is needed.

bernhardkaindl added a comment.EditedApr 15 2022, 8:41 PM

check_include_file is like writing an empty main with one include line and gets it compiled. So it doesn't pull any dependency.
To test whether hwloc.h is a valid header file, you'd need to provide CMAKE_REQUIRED_INCLUDES pointing to hwloc.h.
So it is needed.

Great, so your review is finished by this update. The job "Build and test" of the pre-merge check is running now.

Debian is broken for some unrelated reason, Libcxx CI has passed: https://buildkite.com/llvm-project/libcxx-ci/builds/1024 - Status is Ready to land, btw. What next?

The debian failure seems unrelated. Let me know if you need me to commit the patch.

Hi Ye Luo! Yes, I would need you to commit the patch. Thanks and have a good day, Bernhard

This revision was landed with ongoing or failed builds.Apr 22 2022, 3:36 PM
This revision was automatically updated to reflect the committed changes.