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

Disable numpy AVX512 when compiled with Intel classic #486

Open
wants to merge 11 commits into
base: spack-stack-dev
Choose a base branch
from

Conversation

DavidHuber-NOAA
Copy link
Collaborator

This sets the environmental variable NPY_DISABLE_CPU_FEATURES=AVX512F to disable AVX512 features when the py-numpy module is loaded. The AVX512 features produce undefined behavior when executing certain ndarray methods such as min().

Partly resolves JCSDA/spack-stack#1276 numpy/numpy#27840 matplotlib/matplotlib#28762

@@ -482,6 +482,11 @@ def setup_build_environment(self, env):

env.set("NPY_LAPACK_ORDER", lapack)

def setup_run_environment(self, env):
archs = ("x86_64_v4:", "cannonlake:", "mic_knl")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you add the URLS of the github issues/discussions as hyperlinks above the archs = line`, for example:

    # https://linktomatplotlibissue
    # https://linktonumpyissue
    archs = ...

Thanks!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done, thanks!

@DavidHuber-NOAA
Copy link
Collaborator Author

Per a comment from @seberg, I will try disabling the AVX512 features at build time.

@DavidHuber-NOAA
Copy link
Collaborator Author

@seberg @climbfuji @AlexanderRichert-NOAA I tried adding this to the package.py with this patch. This produces the following lines at build time:

  Configuring npy_cpu_dispatch_config.h using configuration
  Message:
  CPU Optimization Options
    baseline:
      Requested : min
      Enabled   : SSE SSE2 SSE3
    dispatch:
      Requested : MAX -AVX512F -AVX512CD -AVX512_KNL -AVX512_KNM -AVX512_SKX -AVX512_CLX -AVX512_CNL -AVX512_ICL
      Enabled   : SSSE3 SSE41 POPCNT SSE42 AVX F16C FMA3 AVX2 AVX512F AVX512CD AVX512_SKX AVX512_CLX AVX512_CNL AVX512_ICL

Indicating that AVX512 instructions are still being used. I have also tried this all lower case, but it still produces AVX512 instructions. What command should I use in the spack recipe to disable these?

@seberg
Copy link

seberg commented Nov 26, 2024

I'll have to look it up myself, let me pin @seiko2plus in case he sees it, he would know exactly immediately.

@r-devulap
Copy link

Indicating that AVX512 instructions are still being used. I have also tried this all lower case, but it still produces AVX512 instructions. What command should I use in the spack recipe to disable these?

Using NPY_DISABLE_CPU_FEATURES=AVX512F disables dynamic dispatch to these features, they still get build into NumPy library. But AVX512 code paths are never taken. Does that suffice in your case or do you not even want to build AVX512?

@seiko2plus
Copy link

Requested : MAX -AVX512F -AVX512CD -AVX512_KNL -AVX512_KNM -AVX512_SKX -AVX512_CLX -AVX512_CNL -AVX512_ICL

MAX also holds the value AVX512_SPR, if one feature is enabled it will leads to enable all implied features.

"setup-args": {
   "-Dcpu-dispatch": (
        settings.get("setup-args", {}).get("-Dcpu-dispatch", "") +
            "MAX -AVX512F -AVX512CD -AVX512_KNL -AVX512_KNM -AVX512_SKX -AVX512_CLX -AVX512_CNL -AVX512_ICL -AVX512_SPR"
       )
}

@DavidHuber-NOAA
Copy link
Collaborator Author

@r-devulap Yes, I think that would be sufficient (tested sufficiently at 26dd56f), though @seberg suggested that disabling the builds may be desirable. Since we would always be disabling the feature anyway, skipping the build may be desirable.

@seiko2plus Thank you!! Adding -AVX512_SP worked.

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.

matplotlib 3.8.0 is unable to create a basic plot
5 participants