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

openblas: cross-compilation support #24171

Merged
merged 2 commits into from
Jun 11, 2024

Conversation

tttapa
Copy link
Contributor

@tttapa tttapa commented May 30, 2024

Specify library name and version: openblas/*

This PR adds support for cross-compiling OpenBLAS. In previous versions of the recipe, cross-building was explicitly disabled.

When cross-compiling, OpenBLAS requires the TARGET option to be set, so this option has also been added to the Conan recipe. By default, it is set to None which has no effect. When cross-compiling, the default TARGET is determined based on settings.arch.

Native builds should not be affected by these changes.


Differences compared to other open pull requests for the OpenBLAS recipe:

  • Updated openblas from validate to validate_build #24038:
    Checking for cross-compilation support should be done in validate_build(), not validate().
    This change is included in the present PR as well, but the check is now different.

  • Openblas cross compile #23207:
    Support for ARMv8 is also covered by the present PR, without the need for backporting patches.
    #23207 uses tc.cache_variables["TARGET"] = str(self.settings.arch).upper(), which only works for some architectures, the dictionary in the present PR supports all common architectures, not just ARM.


@conan-center-bot

This comment has been minimized.

@jcar87 jcar87 self-assigned this May 31, 2024
@conan-center-bot
Copy link
Collaborator

Conan v1 pipeline ✔️

All green in build 2 (0cea4c97e209c93d8f8ee0fc3541a4ba022b9e54):

  • openblas/0.3.26:
    All packages built successfully! (All logs)

  • openblas/0.3.25:
    All packages built successfully! (All logs)

  • openblas/0.3.27:
    All packages built successfully! (All logs)

  • openblas/0.3.24:
    All packages built successfully! (All logs)

  • openblas/0.3.20:
    All packages built successfully! (All logs)

  • openblas/0.3.17:
    All packages built successfully! (All logs)

  • openblas/0.3.12:
    All packages built successfully! (All logs)

  • openblas/0.3.15:
    All packages built successfully! (All logs)

  • openblas/0.3.10:
    All packages built successfully! (All logs)

  • openblas/0.3.13:
    All packages built successfully! (All logs)


Conan v2 pipeline ✔️

Note: Conan v2 builds are now mandatory. Please read our discussion about it.

All green in build 2 (0cea4c97e209c93d8f8ee0fc3541a4ba022b9e54):

  • openblas/0.3.27:
    All packages built successfully! (All logs)

  • openblas/0.3.25:
    All packages built successfully! (All logs)

  • openblas/0.3.17:
    All packages built successfully! (All logs)

  • openblas/0.3.24:
    All packages built successfully! (All logs)

  • openblas/0.3.26:
    All packages built successfully! (All logs)

  • openblas/0.3.20:
    All packages built successfully! (All logs)

  • openblas/0.3.10:
    All packages built successfully! (All logs)

  • openblas/0.3.13:
    All packages built successfully! (All logs)

  • openblas/0.3.12:
    All packages built successfully! (All logs)

  • openblas/0.3.15:
    All packages built successfully! (All logs)

@elvisdukaj
Copy link
Contributor

I was looking for this :)

}
options_description = {
"build_lapack": "Build LAPACK and LAPACKE",
"build_relapack": "Build with ReLAPACK (recursive implementation of several LAPACK functions on top of standard LAPACK)",
"use_thread": "Enable threads support",
"use_locking": "Use locks even in single-threaded builds to make them callable from multiple threads",
"dynamic_arch": "Include support for multiple CPU targets, with automatic selection at runtime (x86/x86_64, aarch64 or ppc only)",
"target": "OpenBLAS TARGET variable (see TargetList.txt)",
Copy link
Contributor

Choose a reason for hiding this comment

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

Where is TargetList.txt?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

@jcar87 jcar87 left a comment

Choose a reason for hiding this comment

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

Thanks @tttapa, this is excellent!

I had a bit of trouble locating where the TARGET CMake variable was used in the upstream scripts -

please see my comment above and thanks so much for solving this one!

target = conan_arch_to_openblas_target.get(str(self.settings.arch))
if target:
self.output.warning(f'Setting OpenBLAS TARGET={target} based on settings.arch. This may result in suboptimal performance. Set the "{self.name}/*:target=XXX" option to silence this warning.')
self.options.target = target
Copy link
Contributor

Choose a reason for hiding this comment

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

question here!

if we only set self.options.target when cross_building, that means that given a host profile, this recipe will have different package IDs depending on whether it was crossbuilt or not. This is not ideal - one may expect a "producer" such as CI to be able to cross-build, and a consumer on the "native" target system will not find that package because when not-crossbuild this option will default to None - unless I'm mistaken.

I wonder what values are mapped when NOT cross building - but if this file https://github.com/OpenMathLib/OpenBLAS/blob/442dec28df3c04b32e6f8630b40080d6a5715843/cmake/prebuild.cmake#L1402 is any indication, I have a suspicion that it is dynamically setting based on the features of the CPU of the machine doing the build? Then we're also in the same situation: for the same package ID, the contents may be different depending on which machine the build ran on, correct?

If this is the case - would it make sense to always give self.options.target a value derived from the arch setting - regardless of whether or not it is cross-compiled, and point the user to set one that better suits their needs if necessary? I think that solves that particular concern

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I agree. The reason why I set target=None by default is to keep the existing behavior and not break things for current users. But as you said, this is a lie, since OpenBLAS will dynamically change the options in that case, and this should result in different package IDs.

To complicate matters even further, there doesn't seem to be a way to disable the automatic detection in OpenBLAS, the logic you linked to is always executed if (NOT CMAKE_CROSSCOMPILING), so we'd need to patch that (and hope nothing else breaks) if we want to explicitly set TARGET from Conan.

And then there's DYNAMIC_ARCH, which includes multiple versions of each function, and dispatches dynamically based on the target it's being executed on. I haven't tried this myself, and it does of course increase binary size and compile times.

Does Conan have any standard way to deal with different microarchitectures? I suspect that any library that uses SIMD or other modern instructions runs into this specific issue, so maybe this should be standardized (e.g. as a setting in the user's profile). E.g. Spack supports this: https://spack.readthedocs.io/en/latest/basic_usage.html#support-for-specific-microarchitectures. An alternative could be to adopt the System V ABI micro-architecture levels with coarser granularity: https://gitlab.com/x86-psABIs/x86-64-ABI

A quick google search only yields some old discussions without solutions like conan-io/conan#847. This one about OpenBLAS's TARGET option is definitely relevant, though: #13478

Copy link
Contributor

Choose a reason for hiding this comment

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

thanks @tttapa - indeed those are the issues.

I think the current PR is fine:

  • it keeps the current behaviour
  • it gives an ability that wasn't there before

while I think it's worth fixing this issues, since doing so may result in changing the default option value - it's probably best to handle that in a follow-up PR

@elvisdukaj
Copy link
Contributor

Maybe it’s worth considering creating an MR on Conan?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants