Skip to content

Add optimal optimization flags for Intel compilers on AMD CPUs #3793

Open
@Flamefire

Description

@Flamefire

We have the following code for Intel toolchains:

    # used when 'optarch' toolchain option is enabled (and --optarch is not specified)
    COMPILER_OPTIMAL_ARCHITECTURE_OPTION = {
        (systemtools.X86_64, systemtools.AMD): 'xHost',
        (systemtools.X86_64, systemtools.INTEL): 'xHost',
    }

However for AMD CPUs this is bad: xHost will use SSE only even when AVX2 is available. This then even fully fails installing software or installs it with worse optimizations.

As we usually care about CPU vendor and vector instructions supported, I'd optionally add a third argument here: The max supported vector instruction set.
In EB, we then need to define a list of supported types, e.g. "avx2, avx, sse2, sse" in that order. If a tuple (<arch>, <vendor>, <vector>) is found in the dict that flag is used, otherwise the next lower vec is tried. If all were tried, the last entry is removed and the remaining is tried
Extending this to the vendor part would allow this:

    COMPILER_OPTIMAL_ARCHITECTURE_OPTION = {
        (systemtools.X86_64, ): 'xHost',
        (systemtools.X86_64, systemtools.AMD, systemtools.AVX2): 'mavx2',
    }

We should also allow to set this via env vars, similar to EASYBUILD_OPTARCH: Instead of conditionally setting it to EASYBUILD_OPTARCH="Intel:mavx2 -fma; GCC:march=native" as we do on our site while having to check for AMD in the shell script we could do:
EASYBUILD_OPTARCH="Intel,x86:xHost; Intel,x86,AMD,AVX2:mavx2 -fma; GCC:march=native"

This would allow some sort of future-proofing this.

For detecting the supported vector extensions we could use archspec or just use the cpu features query we already have and search for avx2 etc.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions