-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
A case for improved OpenMP support on CCI #24577
Comments
The proposed solution is basically but for CCI. |
Hi @valgur thanks a lot for the write-up, we appreciate it :) I just wanted to let you know that we are in fact looking into this and how to best approach openmp support - it might even include some built-in Conan client support, but we're in preliminary stages yet! Thanks a lot for your effort and patience while we also figure this out |
Ok, I'm glad to hear that. Thanks! Realistically, though, the OpenMP runtime and the preprocessor flag will probably need to be included in the dependency graph in one form or another, with the correct visibility as well, right? If not as a (meta-)package, then do you have some kind of an alternative mechanism in mind, perhaps? Not intending this as a critique, just curious.
The |
Still working on this - however, I think it needs to be clarified that there is no limitation in Conan Center recipes to support OpenMP, or with Conan in general. Recipes that currently support OpenMP should already work for the most part, provided the compiler supports it and it comes with the appropriate runtime. There are a few limitations currently:
so If I'm understanding correctly, the real issues are:
This is a worthy discussion with the distro maintainers too. The matching libomp headers and runtime are made available by the distros. On ubuntu please note that the assessment of the debian maintainers:
seems to contradict the "widely adopted" premise in this issue. Please note that these distributions of clang do contain the runtime, so we can't generalise around
|
The fact that we are discussing the problems and correct ways of using the library should be enough of a reason for encapsulating and abstracting away the complexity, especially if there's a straightforward and low-risk solution available (based on what has been discussed so far at least). While a motivated developer can figure it out on their own, sure, it does not mean that they should. Regarding the interest from "real users" - the near complete lack of computer vision, ML, and robotics communities on Conan/CCI does not mean that they don't exist or care. Far from it. See some of the most actively discussed packages on Vcpkg: colmap, ceres, suitesparse, lapack. And while it's much more down to CUDA support, other technical reasons or plain momentum, having to fight Conan where Vcpkg gets by with a nice abstraction with proper visibility support from CMake out of the box really does not help move the needle in the right direction. |
Regarding whether splitting |
To give some more objective numbers, I grepped through all of the source archives of the latest versions of packages on CCI (plus some pending PRs) for For reference, that's more than double the number of direct uses of Here's a detailed list including all of the packages and their respective files (excluding tests, examples and vendored libraries unvendored by the recipes) that make use of OpenMP: https://gist.github.com/valgur/15d5dc0c31dbfc94f168188a4d1859f7 And just the list of packages, where usages in headers are in bold:
|
Motivation
OpenMP (Open Multi-Processing) is a widely adopted API that provides parallel programming in C, C++, and Fortran, optionally with multi-platform shared-memory support. It is a critical building block for many numerical and scientific libraries, but is used in general-purpose software as well for easy parallelization support.
OpenMP consists of a set of
#pragma omp ...
compiler directives that get translated into OpenMP API calls, which are then handled by the runtime library, which is often (but not always) provided with the compiler toolchain and linked dynamically. The translation of OpenMP directives needs to be enabled with a suitable compiler flag, typically-fopenmp
or/openmp
. Passing the same flag to a linker instructs it to link against the OpenMP runtime library found in the compiler toolchain.Based on the info in recipes alone, there are currently about 50 recipes on CCI currently or upcoming in PRs. Some more notable ones include:
Although some of these libraries support alternative parallelization mechanisms, such as plain pthreads or TBB, several of these libraries don't and are entirely (e.g. SuiteSparse) or close to unusable without parallelization via OpenMP enabled.
Problems
clang
package by default (Ubuntu, Arch, Fedora)llvm-openmp
recipe exports aFindOpenMP.cmake
module with the appropriateOpenMP::OpenMP_CXX
andOpenMP::OpenMP_C
targets, but is otherwise not compatible with the output variables and version set by the officialFindOpenMP.cmake
module.Here's the current output for
find_package(OpenMP)
withllvm-openmp
:Here's the output with the fixes addressing this issue from #22353 applied:
Many (typically older) projects rely on these variables being available. The official module also supports
C
,CXX
andFortran
components in thefind_package()
call, which the exported module ignores.Solutions
openmp
meta-package - addllvm-openmp
as a requirement for Clang and AppleClang and export the appropriate compiler and linker flags for all others. I have an experimental version available in openmp/system: new recipe #22360. Except for the irrelevant linter errors, it works fine with the leftoverllvm-openmp/18.1.8
from llvm-openmp: match FindOpenMP.cmake output, add MSVC support #22353. There is not much of a precedent for meta-packages on CCI and Conan does not have a suitablepackage_type
for it, but it's something that can hopefully applied for other packages with many alternative implementations in the future as well, such asblas
,lapack
and maybe evenjpeg
. The benefits of having a separateopenmp
package are:The exporting of appropriate build flags without the redundancy and potential bugs.
Maps well from the
OpenMP
dependency in CMake when writing a recipe.Allows
transitive_headers=True
andtransitive_libs=True
to clearly state the the library uses OpenMP directives in its public headers.Allows consumers to swap out or customize the
openmp
package for an alternative runtime or some less common compiler support.The
llvm-openmp
package can be pinned to the latest available version for each major version matching the compiler / LLVM version. That would guarantee the stability of ABI and API of the library dependency, to be safe. Realistically, I would expect the latest version to be backwards- and forwards-compatible (up to the available OpenMP standard standard supported by it, of course) thanks to the highly standardized API, plus some non-standard but stable extensions by GOMP, for example. Sincelibomp
and others don't apply SONAME versioning to their library files, ABI compatibility can most likely be assumed as well. I have not looked into the compatibility guarantees any closer than that, though.Alternatively, the C3I Docker images could simply be updated to include
libomp-dev
or the equivalent, but that would not fix the missing library issues for consumers and there's no real blockers to using thellvm-openmp
package (unlike for CUDA, for example), as far as I can tell.FindOpenMP.cmake
compatibility issues inllvm-openmp
. There are basically two options:validate()
and create a thin wrapper around CMake'sFindOpenMP.cmake
. This only works for Clang/AppleClang because CMake'sFindOpenMP.cmake
always selects the compiler's native OpenMP runtime to link against and would lead to mixing oflibomp
and the native runtime in transitive dependencies, which is not safe. Note that CMake'sFindOpenMP.cmake
assumes that the runtime library is on the compiler's default search paths, so creating such a wrapper might not be as simple as it looks at first glance.FindOpenMP
somewhat, but not by a significant amount since it does not need to be nearly as generic. This will work as expected with all compilers - use the compiler's preprocessor for the translation andlibomp
as the runtime. TheFindOpenMP
interface has been very stable as well and can easily be updated if it does changes (as it did in 3.30). This is the approach that was proposed in llvm-openmp: match FindOpenMP.cmake output, add MSVC support #22353.I'm fine with either approach, but lean towards the latter. Not because I think that other compilers should use
libomp
for whatever the reason, but rather because I don't see a reason to limit the use of the package to providelibomp
if the consumer has a specific reason to prefer it and knows what they are doing.That's all.
The text was updated successfully, but these errors were encountered: