Skip to content
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

[llvm-openmp,openmp] add a meta-package for OpenMP #39389

Draft
wants to merge 46 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
15601a2
[llvm-openmp] new port
valgur Jun 14, 2024
9d4762e
[openmp] new meta-package
valgur Jun 19, 2024
d604a38
[dmlc] add openmp dependency as a test
valgur Jun 19, 2024
02de561
vdb
valgur Jun 19, 2024
c706c61
[llvm-openmp] fix portfile.cmake issue
valgur Jun 19, 2024
2b82509
vdb
valgur Jun 19, 2024
56d87ef
[dmlc] add missing dependency to installed config
valgur Jun 19, 2024
7147c2a
vdb
valgur Jun 19, 2024
093f31f
[llvm-openmp] disable unsupported i18n on Android
valgur Jun 19, 2024
3923506
vdb
valgur Jun 19, 2024
a5e393d
[llvm-openmp] fixes for AppleClang
valgur Jun 19, 2024
53dfe61
vdb
valgur Jun 19, 2024
a5e43c0
[llvm-openmp] add gettext-libintl for Android
valgur Jun 19, 2024
200dde7
vdb
valgur Jun 19, 2024
a69c5ba
[llvm-openmp] fix a CMake error
valgur Jun 19, 2024
aa78b5f
vdb
valgur Jun 19, 2024
c963fd9
[llvm-openmp] Android is not supported due to nl_types.h
valgur Jun 19, 2024
5c8c4ed
vdb
valgur Jun 19, 2024
69c8752
[llvm-openmp] temporarily always use llvm-openmp for testing
valgur Jun 19, 2024
eb1057c
vdb
valgur Jun 19, 2024
2bd4b35
[llvm-openmp] only shared builds are supported by the project on Windows
valgur Jun 20, 2024
0ff691a
vdb
valgur Jun 20, 2024
7b7d2d3
[llvm-openmp] add ONLY_DYNAMIC_CRT
valgur Jun 20, 2024
50bd3bf
vdb
valgur Jun 20, 2024
1d69490
[llvm-openmp] remove unnecessary CACHE var
valgur Jun 20, 2024
d2f69f6
[llvm-openmp] force shared on Windows
valgur Jun 20, 2024
e966c87
vdb
valgur Jun 20, 2024
eac6142
[llvm-openmp] try a different patch for Windows import lib issue
valgur Jun 21, 2024
a7fa2b2
vdb
valgur Jun 21, 2024
1f9fbe6
[llvm-openmp] Fix Windows build
valgur Jul 3, 2024
5d26728
vdb
valgur Jul 3, 2024
ee6c93d
[llvm-openmp] disable windows-static and uwp in supports
valgur Jul 4, 2024
58ffc59
vdp
valgur Jul 4, 2024
c929c14
[llvm-openmp] Export 'omp' target without a namespace to match the 'l…
valgur Jul 4, 2024
1222ca9
[llvm-openmp] Export CMake vars
valgur Jul 4, 2024
6d20fe8
[llvm-openmp] Bump to v18.1.8
valgur Jul 4, 2024
2d9775a
[llvm-openmp] Place omp.h under a subdirectory to avoid conflicts
valgur Jul 4, 2024
a8bcff8
[llvm-openmp] remove `REQUIRED` from FindOpenMP.cmake.in
valgur Jul 5, 2024
95280e1
[llvm-openmp] install libs in an 'unofficial-llvm-openmp' subdir to a…
valgur Jul 6, 2024
e297073
vdb
valgur Jul 7, 2024
78ffd23
[openmp] Use llvm-openmp only for Clang and AppleClang
valgur Jul 8, 2024
535de03
vdb
valgur Jul 8, 2024
5e22a88
Add usage info
valgur Jul 8, 2024
5e358cd
vdb
valgur Jul 8, 2024
710ed57
[llvm-openmp] Fix Windows static triplet support
valgur Jul 8, 2024
1c2ab7b
vdb
valgur Jul 8, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions ports/dmlc/add-config-deps.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
--- a/cmake/dmlc-config.cmake.in
+++ b/cmake/dmlc-config.cmake.in
@@ -1,4 +1,9 @@
@PACKAGE_INIT@
+
+include(CMakeFindDependencyMacro)
+if(@USE_OPENMP@)
+ find_dependency(OpenMP REQUIRED)
+endif()

if(NOT TARGET dmlc::dmlc)
include(${CMAKE_CURRENT_LIST_DIR}/DMLCTargets.cmake)
1 change: 1 addition & 0 deletions ports/dmlc/portfile.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ vcpkg_from_github(
HEAD_REF main
PATCHES
cxx-fix.patch # from https://github.com/dmlc/dmlc-core/pull/676
add-config-deps.patch
)

vcpkg_check_features(OUT_FEATURE_OPTIONS FEATURE_OPTIONS
Expand Down
9 changes: 8 additions & 1 deletion ports/dmlc/vcpkg.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"name": "dmlc",
"version-date": "2022-06-22",
"port-version": 1,
"description": "DMLC-Core is the backbone library to support all DMLC projects, offers the bricks to build efficient and scalable distributed machine learning libraries.",
"homepage": "https://github.com/dmlc/dmlc-core",
"license": "Apache-2.0",
Expand All @@ -15,9 +16,15 @@
"host": true
}
],
"default-features": [
"openmp"
],
"features": {
"openmp": {
"description": "Build with openmp"
"description": "Build with openmp",
"dependencies": [
"openmp"
]
}
}
}
24 changes: 24 additions & 0 deletions ports/llvm-openmp/0001-disable-libomp-aliases.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
runtime/src/CMakeLists.txt | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/openmp/runtime/src/CMakeLists.txt b/openmp/runtime/src/CMakeLists.txt
index bb5822264514..340cef14df89 100644
--- a/runtime/src/CMakeLists.txt
+++ b/runtime/src/CMakeLists.txt
@@ -215,7 +215,7 @@ endif()
set(LIBOMP_INCLUDE_DIR ${CMAKE_CURRENT_BINARY_DIR} PARENT_SCOPE)

# Add symbolic links to libomp
-if(NOT WIN32)
+if(0)
add_custom_command(TARGET omp POST_BUILD
COMMAND ${CMAKE_COMMAND} -E create_symlink ${LIBOMP_LIB_FILE}
libgomp${LIBOMP_LIBRARY_SUFFIX}
@@ -367,6 +367,6 @@ if(WIN32)
install(TARGETS omp ${export_to_llvmexports} RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}")
install(TARGETS ${LIBOMP_IMP_LIB_TARGET} ARCHIVE DESTINATION "${OPENMP_INSTALL_LIBDIR}")
# Create aliases (regular copies) of the library for backwards compatibility
- set(LIBOMP_ALIASES "libiomp5md")
vicroms marked this conversation as resolved.
Show resolved Hide resolved
+ set(LIBOMP_ALIASES)
foreach(alias IN LISTS LIBOMP_ALIASES)
install(CODE "execute_process(COMMAND \"\${CMAKE_COMMAND}\" -E copy \"${LIBOMP_LIB_FILE}\"
10 changes: 10 additions & 0 deletions ports/llvm-openmp/0002-disable-tests.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
--- a/runtime/CMakeLists.txt
+++ b/runtime/CMakeLists.txt
@@ -450,7 +450,6 @@
endif()

add_subdirectory(src)
-add_subdirectory(test)

# make these variables available for tools:
set(LIBOMP_LIBRARY_DIR ${LIBOMP_LIBRARY_DIR} PARENT_SCOPE)
67 changes: 67 additions & 0 deletions ports/llvm-openmp/0004-install-config.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
Add installation of config files since the project does not install any when building a standalone library.

Add an "unofficial-llvm-openmp" prefix to the headers to avoid conflicts with the same unprefixed headers provided GCC and other compilers.
Add an "unofficial-llvm-openmp" to the library files to avoid conflicts with the LLVM port.

--- a/runtime/src/CMakeLists.txt
+++ b/runtime/src/CMakeLists.txt
@@ -365,10 +365,12 @@
set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS omp)
endif()

+set(OPENMP_INSTALL_LIBDIR "lib/unofficial-llvm-openmp")
+set(OPENMP_INSTALL_BINDIR "bin/unofficial-llvm-openmp")
# Install rules
# We want to install libomp in ${DESTDIR}/${CMAKE_INSTALL_FULL_LIBDIR}
# We want to install headers in ${DESTDIR}/${CMAKE_INSTALL_FULL_INCLUDEDIR}
if(WIN32)
- install(TARGETS omp ${export_to_llvmexports} RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}")
- install(TARGETS ${LIBOMP_IMP_LIB_TARGET} ARCHIVE DESTINATION "${OPENMP_INSTALL_LIBDIR}")
+ install(TARGETS omp ${export_to_llvmexports} EXPORT llvm-openmp-targets RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}")
+ install(TARGETS ${LIBOMP_IMP_LIB_TARGET} EXPORT llvm-openmp-targets ARCHIVE DESTINATION "${OPENMP_INSTALL_LIBDIR}")
# Create aliases (regular copies) of the library for backwards compatibility
@@ -382,7 +384,7 @@
endforeach()
else()

- install(TARGETS omp ${export_to_llvmexports} ${LIBOMP_INSTALL_KIND} DESTINATION "${OPENMP_INSTALL_LIBDIR}")
+ install(TARGETS omp EXPORT llvm-openmp-targets ${LIBOMP_INSTALL_KIND} DESTINATION "${OPENMP_INSTALL_LIBDIR}")

if(${LIBOMP_INSTALL_ALIASES})
# Create aliases (symlinks) of the library for backwards compatibility
@@ -399,7 +401,7 @@
FILES
${CMAKE_CURRENT_BINARY_DIR}/omp.h
${CMAKE_CURRENT_BINARY_DIR}/ompx.h
- DESTINATION ${LIBOMP_HEADERS_INSTALL_PATH}
+ DESTINATION include/unofficial-llvm-openmp
)
if(${LIBOMP_OMPT_SUPPORT})
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/omp-tools.h DESTINATION ${LIBOMP_HEADERS_INSTALL_PATH})
@@ -415,3 +417,26 @@
DESTINATION ${LIBOMP_HEADERS_INSTALL_PATH}
)
endif()
+
+target_include_directories(omp PUBLIC $<INSTALL_INTERFACE:include/unofficial-llvm-openmp>)
+
+set(PORT_SHARE_DIR share/unofficial-llvm-openmp)
+install(EXPORT llvm-openmp-targets
+ FILE unofficial-llvm-openmp-targets.cmake
+ DESTINATION ${PORT_SHARE_DIR}
+)
+include(CMakePackageConfigHelpers)
+configure_package_config_file(${CMAKE_SOURCE_DIR}/runtime/cmake/llvm-openmp-config.cmake.in
+ ${CMAKE_CURRENT_BINARY_DIR}/unofficial-llvm-openmp-config.cmake
+ INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/share/unofficial-llvm-openmp
+)
+write_basic_package_version_file(
+ "${CMAKE_CURRENT_BINARY_DIR}/unofficial-llvm-openmp-config-version.cmake"
+ VERSION ${LLVM_OPENMP_VERSION}
+ COMPATIBILITY SameMajorVersion
+)
+install(FILES
+ "${CMAKE_CURRENT_BINARY_DIR}/unofficial-llvm-openmp-config.cmake"
+ "${CMAKE_CURRENT_BINARY_DIR}/unofficial-llvm-openmp-config-version.cmake"
+ DESTINATION ${PORT_SHARE_DIR}
+)
207 changes: 207 additions & 0 deletions ports/llvm-openmp/FindOpenMP.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,207 @@
# Based on https://github.com/Kitware/CMake/blob/v3.30.0-rc3/Modules/FindOpenMP.cmake

include(CMakeFindDependencyMacro)
find_dependency(unofficial-llvm-openmp CONFIG)
get_target_property(_OpenMP_INCLUDE_DIR omp INTERFACE_INCLUDE_DIRECTORIES)
get_target_property(_OpenMP_LIB_NAMES omp INTERFACE_LINK_LIBRARIES)

# handle omp location being set directly via IMPORTED_LOCATION instead
if(NOT _OpenMP_LIB_NAMES)
set(_OpenMP_LIB_NAMES omp)
endif()

foreach(_lang C CXX)
set(OpenMP_${_lang}_INCLUDE_DIR "${_OpenMP_INCLUDE_DIR}")
set(OpenMP_${_lang}_INCLUDE_DIRS "${_OpenMP_INCLUDE_DIR}")
set(OpenMP_${_lang}_LIB_NAMES "${_OpenMP_LIB_NAMES}")
set(OpenMP_${_lang}_LIBRARIES "OpenMP::OpenMP_${_lang}")
if (NOT TARGET OpenMP::OpenMP_${_lang})
add_library(OpenMP::OpenMP_${_lang} ALIAS omp)
endif()
endforeach()

function(_openmp_set_flags)
set(OMP_FLAG_GNU "-fopenmp")
set(OMP_FLAG_LCC "-fopenmp")
set(OMP_FLAG_Clang "-fopenmp=libomp")
set(OMP_FLAG_AppleClang "-Xclang -fopenmp")
set(OMP_FLAG_HP "+Oopenmp")
if(WIN32)
set(OMP_FLAG_Intel "-Qopenmp")
elseif(CMAKE_${LANG}_COMPILER_ID STREQUAL "Intel" AND
"${CMAKE_${LANG}_COMPILER_VERSION}" VERSION_LESS "15.0.0.20140528")
set(OMP_FLAG_Intel "-openmp")
else()
set(OMP_FLAG_Intel "-qopenmp")
endif()
if(CMAKE_${LANG}_COMPILER_ID STREQUAL "IntelLLVM" AND
"x${CMAKE_${LANG}_COMPILER_FRONTEND_VARIANT}" STREQUAL "xMSVC")
set(OMP_FLAG_IntelLLVM "-Qiopenmp")
else()
set(OMP_FLAG_IntelLLVM "-fiopenmp")
endif()
set(OMP_FLAG_MSVC "-openmp:llvm")
set(OMP_FLAG_PathScale "-openmp")
set(OMP_FLAG_NAG "-openmp")
set(OMP_FLAG_Absoft "-openmp")
set(OMP_FLAG_NVHPC "-mp")
set(OMP_FLAG_PGI "-mp")
set(OMP_FLAG_Flang "-fopenmp")
set(OMP_FLAG_SunPro "-xopenmp")
set(OMP_FLAG_XL "-qsmp=omp")
set(OMP_FLAG_Cray "-h omp")
set(OMP_FLAG_Fujitsu "-Kopenmp")
set(OMP_FLAG_FujitsuClang "-fopenmp")
foreach(_lang C CXX)
if(DEFINED OMP_FLAG_${CMAKE_${_lang}_COMPILER_ID})
set(OpenMP_C_FLAGS "${OMP_FLAG_${CMAKE_${_lang}_COMPILER_ID}}" PARENT_SCOPE)
set(OpenMP_CXX_FLAGS "${OMP_FLAG_${CMAKE_${_lang}_COMPILER_ID}}" PARENT_SCOPE)
break()
endif()
endforeach()
endfunction()

_openmp_set_flags()
if(NOT DEFINED OpenMP_C_FLAGS)
message(FATAL_ERROR "OpenMP build flags not found for compiler \"${CMAKE_C_COMPILER_ID}\"")
endif()
set_target_properties(omp PROPERTIES
INTERFACE_COMPILE_OPTIONS "${OpenMP_C_FLAGS}"
INTERFACE_LINK_OPTIONS "${OpenMP_C_FLAGS}"
)

# Determine OpenMP specification date and version supported by the compiler.
function(_openmp_get_compiler_spec_date)
set(BUILD_DIR "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/FindOpenMP")
set(SRC_FILE "${BUILD_DIR}/ompver.c")
if(NOT CMAKE_C_COMPILER_LOADED)
set(SRC_FILE "${BUILD_DIR}/ompver.cpp")
endif()
set(BIN_FILE "${BUILD_DIR}/ompver.bin")
file(WRITE "${SRC_FILE}" "
#include <stdio.h>
#include <omp.h>
const char ompver_str[] = { 'I', 'N', 'F', 'O', ':', 'O', 'p', 'e', 'n', 'M',
'P', '-', 'd', 'a', 't', 'e', '[',
('0' + ((_OPENMP/100000)%10)),
('0' + ((_OPENMP/10000)%10)),
('0' + ((_OPENMP/1000)%10)),
('0' + ((_OPENMP/100)%10)),
('0' + ((_OPENMP/10)%10)),
('0' + ((_OPENMP/1)%10)),
']', '\\0' };
int main(void)
{
puts(ompver_str);
return 0;
}
")
try_compile(OpenMP_SPECTEST ${BUILD_DIR}
SOURCES "${SRC_FILE}"
CMAKE_FLAGS
"-DCOMPILE_DEFINITIONS:STRING=${OpenMP_C_FLAGS}"
"-DINCLUDE_DIRECTORIES:STRING=${OpenMP_C_INCLUDE_DIR}"
COPY_FILE "${BIN_FILE}"
)
if(NOT OpenMP_SPECTEST)
if(OpenMP_FIND_REQUIRED)
message(FATAL_ERROR "Failed to build OpenMP test executable for specification date detection")
elseif(NOT OpenMP_FIND_QUIETLY)
message(SEND_ERROR "Failed to build OpenMP test executable for specification date detection")
endif()
return()
endif()
file(STRINGS ${BIN_FILE} specstr LIMIT_COUNT 1 REGEX "INFO:OpenMP-date")
if(specstr MATCHES ".*INFO:OpenMP-date\\[0*([^]]*)\\].*")
set(OpenMP_SPEC_DATE ${CMAKE_MATCH_1} PARENT_SCOPE)
else()
if(OpenMP_FIND_REQUIRED)
message(FATAL_ERROR "Failed to detect OpenMP specification date")
elseif(NOT OpenMP_FIND_QUIETLY)
message(SEND_ERROR "Failed to detect OpenMP specification date")
endif()
return()
endif()
endfunction()

function(_openmp_set_version_by_spec_date)
set(OpenMP_SPEC_DATE_MAP
"202111=5.2"
"202011=5.1"
# Preview versions
"201611=5.0" # OpenMP 5.0 preview 1
# Combined versions, 2.5 onwards
"201811=5.0"
"201611=5.0"
"201511=4.5"
"201307=4.0"
"201107=3.1"
"200805=3.0"
"200505=2.5"
# C/C++ version 2.0
"200203=2.0"
# Fortran version 2.0
"200011=2.0"
# Fortran version 1.1
"199911=1.1"
# C/C++ version 1.0 (there's no 1.1 for C/C++)
"199810=1.0"
# Fortran version 1.0
"199710=1.0"
)
if(OpenMP_SPEC_DATE_MAP MATCHES "${OpenMP_SPEC_DATE}=([0-9]+)\\.([0-9]+)")
set(major "${CMAKE_MATCH_1}")
set(minor "${CMAKE_MATCH_2}")
else()
if(OpenMP_FIND_REQUIRED)
message(FATAL_ERROR "Failed to detect OpenMP specification version")
elseif(NOT OpenMP_FIND_QUIETLY)
message(SEND_ERROR "Failed to detect OpenMP specification version")
endif()
return()
endif()
set(OpenMP_VERSION_MAJOR "${major}" PARENT_SCOPE)
set(OpenMP_VERSION_MINOR "${minor}" PARENT_SCOPE)
set(OpenMP_VERSION "${major}.${minor}" PARENT_SCOPE)
endfunction()

# Compare the OpenMP API version supported by the compiler to
# the version supported by the LLVM OMP runtime and use the lower of the two.
# Note that this differs slightly from the CMake's FindOpenMP.cmake implementation,
# which checks only the version supported by the compiler.
_openmp_get_compiler_spec_date()
if(OpenMP_SPEC_DATE GREATER @OpenMP_SPEC_DATE@)
set(OpenMP_SPEC_DATE @OpenMP_SPEC_DATE@)
set(OpenMP_VERSION_MAJOR @OpenMP_VERSION_MAJOR@)
set(OpenMP_VERSION_MINOR @OpenMP_VERSION_MINOR@)
set(OpenMP_VERSION @OpenMP_VERSION@)
else()
_openmp_set_version_by_spec_date()
endif()

foreach(_lang C CXX)
set(OpenMP_${_lang}_FOUND TRUE)
set(OpenMP_${_lang}_SPEC_DATE "${OpenMP_SPEC_DATE}")
set(OpenMP_${_lang}_VERSION_MAJOR "${OpenMP_VERSION_MAJOR}")
set(OpenMP_${_lang}_VERSION_MINOR "${OpenMP_VERSION_MINOR}")
set(OpenMP_${_lang}_VERSION "${OpenMP_VERSION}")
endforeach()

# Check specification version against the requested min version, validate components
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(OpenMP
VERSION_VAR OpenMP_VERSION
REQUIRED_VARS
OpenMP_C_FLAGS
OpenMP_C_LIB_NAMES
OpenMP_C_SPEC_DATE
OpenMP_C_VERSION
OpenMP_CXX_FLAGS
OpenMP_CXX_LIB_NAMES
OpenMP_CXX_SPEC_DATE
OpenMP_CXX_VERSION
HANDLE_COMPONENTS
)
set(OPENMP_FOUND ${OpenMP_FOUND})
set(OpenMP_C_FOUND ${OpenMP_FOUND})
set(OpenMP_CXX_FOUND ${OpenMP_FOUND})
13 changes: 13 additions & 0 deletions ports/llvm-openmp/llvm-openmp-config.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
@PACKAGE_INIT@

include(${CMAKE_CURRENT_LIST_DIR}/unofficial-llvm-openmp-targets.cmake)

# When built as part of LLVM, the headers are instead located at
# tools/llvm/lib/clang/18/include/omp.h
set_and_check(unofficial-llvm-openmp_INCLUDE_DIR "${CMAKE_CURRENT_LIST_DIR}/../../include/unofficial-llvm-openmp")
set(unofficial-llvm-openmp_LIBRARIES omp)

if(WIN32)
set_and_check(unofficial-llvm-openmp_IMPLIB "${CMAKE_CURRENT_LIST_DIR}/../../lib/unofficial-llvm-openmp/libomp.lib")
set_target_properties(omp PROPERTIES IMPORTED_IMPLIB "${unofficial-llvm-openmp_IMPLIB}")
endif()
Loading