Skip to content

BUG: Undefined math symbols when compiling from source against intel MKL #27111

Closed

Description

@AgilentGCMS

Describe the issue:

I have compiled python 3.12.4 from source on a computing cluster, and I am trying to compile numpy. The goal is to install it in the same tree as the locally compiled python binary. We have intel compilers on the cluster, so I am trying to get numpy to use intel MKL libraries. I compiled numpy with

CC=icx CXX=icpx python -m pip install --no-build-isolation -v . -Cbuild-dir=build -Csetup-args=-Dallow-noblas=false -Csetup-args=-Dblas-order=mkl -Csetup-args=-Dlapack-order=mkl -Csetup-args=-Dblas=mkl-static-lp64-iomp -Csetup-args=-Dlapack=mkl-static-lp64-iomp

This installed and compiled without complaints. However, when I try to import numpy from within python, I get

$ python
Python 3.12.4 (main, Jul 29 2024, 10:14:44) [Clang 18.0.0 (icx 2024.1.0.20240308)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
Traceback (most recent call last):
  File "/work2/noaa/co2/sbasu/packages/python/3.12.4/lib/python3.12/site-packages/numpy/_core/__init__.py", line 23, in <module>
    from . import multiarray
  File "/work2/noaa/co2/sbasu/packages/python/3.12.4/lib/python3.12/site-packages/numpy/_core/multiarray.py", line 10, in <module>
    from . import overrides
  File "/work2/noaa/co2/sbasu/packages/python/3.12.4/lib/python3.12/site-packages/numpy/_core/overrides.py", line 8, in <module>
    from numpy._core._multiarray_umath import (
ImportError: /work2/noaa/co2/sbasu/packages/python/3.12.4/lib/python3.12/site-packages/numpy/_core/_multiarray_umath.cpython-312-x86_64-linux-gnu.so: undefined symbol: pow8_h

An invocation of ldd shows the following libraries linked to the above mentioned shared object file:

$ ldd /work2/noaa/co2/sbasu/packages/python/3.12.4/lib/python3.12/site-packages/numpy/_core/_multiarray_umath.cpython-312-x86_64-linux-gnu.so
	linux-vdso.so.1 (0x00007ffef53dd000)
	libimf.so => /apps/spack-managed/gcc-11.3.1/intel-oneapi-compilers-2024.1.0-76aou5yu2oqfcz72vq7lp77bp3rqcoht/compiler/2024.1/lib/libimf.so (0x000014a0f6287000)
	libiomp5.so => /apps/spack-managed/gcc-11.3.1/intel-oneapi-compilers-2024.1.0-76aou5yu2oqfcz72vq7lp77bp3rqcoht/compiler/2024.1/lib/libiomp5.so (0x000014a0f5ea1000)
	libsvml.so => /apps/spack-managed/gcc-11.3.1/intel-oneapi-compilers-2024.1.0-76aou5yu2oqfcz72vq7lp77bp3rqcoht/compiler/2024.1/lib/libsvml.so (0x000014a0f484d000)
	libstdc++.so.6 => /usr/lib64/libstdc++.so.6 (0x000014a0f4626000)
	libintlc.so.5 => /apps/spack-managed/gcc-11.3.1/intel-oneapi-compilers-2024.1.0-76aou5yu2oqfcz72vq7lp77bp3rqcoht/compiler/2024.1/lib/libintlc.so.5 (0x000014a0f45c4000)
	libc.so.6 => /usr/lib64/libc.so.6 (0x000014a0f43bb000)
	librt.so.1 => /usr/lib64/librt.so.1 (0x000014a0f43b6000)
	libdl.so.2 => /usr/lib64/libdl.so.2 (0x000014a0f43b1000)
	libpthread.so.0 => /usr/lib64/libpthread.so.0 (0x000014a0f43aa000)
	/lib64/ld-linux-x86-64.so.2 (0x000014a0f8526000)
	libm.so.6 => /usr/lib64/libm.so.6 (0x000014a0f42cf000)
	libgcc_s.so.1 => /usr/lib64/libgcc_s.so.1 (0x000014a0f42b4000)

So what is missing here?

Reproduce the code example:

import numpy

Error message:

Traceback (most recent call last):
  File "/work2/noaa/co2/sbasu/packages/python/3.12.4/lib/python3.12/site-packages/numpy/_core/__init__.py", line 23, in <module>
    from . import multiarray
  File "/work2/noaa/co2/sbasu/packages/python/3.12.4/lib/python3.12/site-packages/numpy/_core/multiarray.py", line 10, in <module>
    from . import overrides
  File "/work2/noaa/co2/sbasu/packages/python/3.12.4/lib/python3.12/site-packages/numpy/_core/overrides.py", line 8, in <module>
    from numpy._core._multiarray_umath import (
ImportError: /work2/noaa/co2/sbasu/packages/python/3.12.4/lib/python3.12/site-packages/numpy/_core/_multiarray_umath.cpython-312-x86_64-linux-gnu.so: undefined symbol: pow8_h

Python and NumPy Versions:

Python 3.12.4
Numpy 2.0.1

Runtime Environment:

Cannot show this because importing numpy fails

Context for the issue:

No response

Activity

  1. AgilentGCMS commented on Aug 4, 2024

    @AgilentGCMS
    Author

    @rgommers Apologies for bothering you, but in the past you've helped solve issues at the confluence of numpy and MKL, so perhaps this problem has an obvious solution to you?

  2. mattip commented on Aug 5, 2024

    @mattip
    Member

    The missing symbol is pow8_h. What cpu architecture are you targeting? Google does not seem to be able to find that symbol at all.

  3. rgommers commented on Aug 5, 2024

    @rgommers
    Member

    I can't find any reports about pow8_h in this issue tracker, but I'm sure I've seen it before - it's a known issue with SVML IIRC.

  4. AgilentGCMS commented on Aug 5, 2024

    @AgilentGCMS
    Author

    The missing symbol is pow8_h. What cpu architecture are you targeting? Google does not seem to be able to find that symbol at all.

    Intel Ice Lake, or, from /proc/cpuinfo,

    vendor_id	: GenuineIntel
    cpu family	: 6
    model		: 106
    model name	: Intel(R) Xeon(R) Platinum 8380 CPU @ 2.30GHz
    stepping	: 6
    microcode	: 0xd0003d1
    cpu MHz		: 2300.000
    cache size	: 61440 KB
    physical id	: 1
    siblings	: 80
    core id		: 39
    cpu cores	: 40
    apicid		: 207
    initial apicid	: 207
    fpu		: yes
    fpu_exception	: yes
    cpuid level	: 27
    wp		: yes
    flags		: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault epb cat_l3 invpcid_single intel_ppin ssbd mba ibrs ibpb stibp ibrs_enhanced tpr_shadow vnmi flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid cqm rdt_a avx512f avx512dq rdseed adx smap avx512ifma clflushopt clwb intel_pt avx512cd sha_ni avx512bw avx512vl xsaveopt xsavec xgetbv1 xsaves cqm_llc cqm_occup_llc cqm_mbm_total cqm_mbm_local split_lock_detect wbnoinvd dtherm ida arat pln pts avx512vbmi umip pku ospke avx512_vbmi2 gfni vaes vpclmulqdq avx512_vnni avx512_bitalg tme avx512_vpopcntdq la57 rdpid fsrm md_clear pconfig flush_l1d arch_capabilities
    vmx flags	: vnmi preemption_timer posted_intr invvpid ept_x_only ept_ad ept_1gb flexpriority apicv tsc_offset vtpr mtf vapic ept vpid unrestricted_guest vapic_reg vid ple shadow_vmcs pml ept_mode_based_exec tsc_scaling
    bugs		: spectre_v1 spectre_v2 spec_store_bypass swapgs mmio_stale_data eibrs_pbrsb
    bogomips	: 4605.65
    clflush size	: 64
    cache_alignment	: 64
    address sizes	: 46 bits physical, 57 bits virtual
    
  5. r-devulap commented on Aug 5, 2024

    @r-devulap
    Member

    I have seen this before, let me try and find what the mitigation was

  6. AgilentGCMS commented on Aug 5, 2024

    @AgilentGCMS
    Author

    Not that this helps, when I compile against the dynamic library (i.e., mkl-dynamic-lp64-iomp instead of mkl-static-lp64-iomp), I get an error about undefined symbol: tan8_h. It's probably the first undefined symbol found, i.e., I don't believe that tan8_h was defined in the static library but is undefined in the dynamic library.

  7. r-devulap commented on Aug 5, 2024

    @r-devulap
    Member

    Could you add this to CFLAGS and rebuild? -fveclib=none. That should fix the error.

  8. r-devulap commented on Aug 5, 2024

    @r-devulap
    Member

    I had filed this issue a while back and forgot about it :) #26257. This flag should be added into our meson build for icx/icpx compiler. I will submit a PR to do that.

  9. AgilentGCMS commented on Aug 5, 2024

    @AgilentGCMS
    Author

    Could you add this to CFLAGS and rebuild? -fveclib=none. That should fix the error.

    You mean just CFLAGS='-fveclib=none' on the same line where I'm defining CC and CXX? I am not setting any other CFLAGS anywhere.

  10. r-devulap commented on Aug 5, 2024

    @r-devulap
    Member

    Could you add this to CFLAGS and rebuild? -fveclib=none. That should fix the error.

    You mean just CFLAGS='-fveclib=none' on the same line where I'm defining CC and CXX? I am not setting any other CFLAGS anywhere.

    yup

  11. AgilentGCMS commented on Aug 5, 2024

    @AgilentGCMS
    Author

    @r-devulap That indeed fixed the issue. Thanks!

  12. AgilentGCMS commented on Aug 8, 2024

    @AgilentGCMS
    Author

    I think I need to reopen this issue, unless what I'm seeing is unrelated. With that addition to CFLAGS, numpy built successfully. However, it fails import numpy; numpy.test() with the following:

    Fatal Python error: Segmentation fault
    
    Thread 0x000014baf042a640 (most recent call first):
      File "/work2/noaa/co2/sbasu/packages/python/3.12.4/lib/python3.12/threading.py", line 355 in wait
      File "/work2/noaa/co2/sbasu/packages/python/3.12.4/lib/python3.12/threading.py", line 655 in wait
      File "/work2/noaa/co2/sbasu/packages/python/3.12.4/lib/python3.12/site-packages/IPython/core/history.py", line 903 in run
      File "/work2/noaa/co2/sbasu/packages/python/3.12.4/lib/python3.12/site-packages/IPython/core/history.py", line 61 in only_when_enabled
      File "/work2/noaa/co2/sbasu/packages/python/3.12.4/lib/python3.12/site-packages/decorator.py", line 232 in fun
      File "/work2/noaa/co2/sbasu/packages/python/3.12.4/lib/python3.12/threading.py", line 1073 in _bootstrap_inner
      File "/work2/noaa/co2/sbasu/packages/python/3.12.4/lib/python3.12/threading.py", line 1030 in _bootstrap
    
    Current thread 0x000014baf3d8a740 (most recent call first):
      File "/work2/noaa/co2/sbasu/packages/python/3.12.4/lib/python3.12/site-packages/numpy/_core/fromnumeric.py", line 57 in _wrapfunc
      File "/work2/noaa/co2/sbasu/packages/python/3.12.4/lib/python3.12/site-packages/numpy/_core/fromnumeric.py", line 1200 in argsort
      File "/work2/noaa/co2/sbasu/packages/python/3.12.4/lib/python3.12/site-packages/numpy/_core/tests/test_multiarray.py", line 10106 in test_argsort_float
      File "/work2/noaa/co2/sbasu/packages/python/3.12.4/lib/python3.12/site-packages/_pytest/python.py", line 159 in pytest_pyfunc_call
      File "/work2/noaa/co2/sbasu/packages/python/3.12.4/lib/python3.12/site-packages/pluggy/_callers.py", line 103 in _multicall
      File "/work2/noaa/co2/sbasu/packages/python/3.12.4/lib/python3.12/site-packages/pluggy/_manager.py", line 120 in _hookexec
      File "/work2/noaa/co2/sbasu/packages/python/3.12.4/lib/python3.12/site-packages/pluggy/_hooks.py", line 513 in __call__
      File "/work2/noaa/co2/sbasu/packages/python/3.12.4/lib/python3.12/site-packages/_pytest/python.py", line 1627 in runtest
      File "/work2/noaa/co2/sbasu/packages/python/3.12.4/lib/python3.12/site-packages/_pytest/runner.py", line 174 in pytest_runtest_call
      File "/work2/noaa/co2/sbasu/packages/python/3.12.4/lib/python3.12/site-packages/pluggy/_callers.py", line 103 in _multicall
      File "/work2/noaa/co2/sbasu/packages/python/3.12.4/lib/python3.12/site-packages/pluggy/_manager.py", line 120 in _hookexec
      File "/work2/noaa/co2/sbasu/packages/python/3.12.4/lib/python3.12/site-packages/pluggy/_hooks.py", line 513 in __call__
      File "/work2/noaa/co2/sbasu/packages/python/3.12.4/lib/python3.12/site-packages/_pytest/runner.py", line 242 in <lambda>
      File "/work2/noaa/co2/sbasu/packages/python/3.12.4/lib/python3.12/site-packages/_pytest/runner.py", line 341 in from_call
      File "/work2/noaa/co2/sbasu/packages/python/3.12.4/lib/python3.12/site-packages/_pytest/runner.py", line 241 in call_and_report
      File "/work2/noaa/co2/sbasu/packages/python/3.12.4/lib/python3.12/site-packages/_pytest/runner.py", line 132 in runtestprotocol
      File "/work2/noaa/co2/sbasu/packages/python/3.12.4/lib/python3.12/site-packages/_pytest/runner.py", line 113 in pytest_runtest_protocol
      File "/work2/noaa/co2/sbasu/packages/python/3.12.4/lib/python3.12/site-packages/pluggy/_callers.py", line 103 in _multicall
      File "/work2/noaa/co2/sbasu/packages/python/3.12.4/lib/python3.12/site-packages/pluggy/_manager.py", line 120 in _hookexec
      File "/work2/noaa/co2/sbasu/packages/python/3.12.4/lib/python3.12/site-packages/pluggy/_hooks.py", line 513 in __call__
      File "/work2/noaa/co2/sbasu/packages/python/3.12.4/lib/python3.12/site-packages/_pytest/main.py", line 362 in pytest_runtestloop
      File "/work2/noaa/co2/sbasu/packages/python/3.12.4/lib/python3.12/site-packages/pluggy/_callers.py", line 103 in _multicall
      File "/work2/noaa/co2/sbasu/packages/python/3.12.4/lib/python3.12/site-packages/pluggy/_manager.py", line 120 in _hookexec
      File "/work2/noaa/co2/sbasu/packages/python/3.12.4/lib/python3.12/site-packages/pluggy/_hooks.py", line 513 in __call__
      File "/work2/noaa/co2/sbasu/packages/python/3.12.4/lib/python3.12/site-packages/_pytest/main.py", line 337 in _main
      File "/work2/noaa/co2/sbasu/packages/python/3.12.4/lib/python3.12/site-packages/_pytest/main.py", line 283 in wrap_session
      File "/work2/noaa/co2/sbasu/packages/python/3.12.4/lib/python3.12/site-packages/_pytest/main.py", line 330 in pytest_cmdline_main
      File "/work2/noaa/co2/sbasu/packages/python/3.12.4/lib/python3.12/site-packages/pluggy/_callers.py", line 103 in _multicall
      File "/work2/noaa/co2/sbasu/packages/python/3.12.4/lib/python3.12/site-packages/pluggy/_manager.py", line 120 in _hookexec
      File "/work2/noaa/co2/sbasu/packages/python/3.12.4/lib/python3.12/site-packages/pluggy/_hooks.py", line 513 in __call__
      File "/work2/noaa/co2/sbasu/packages/python/3.12.4/lib/python3.12/site-packages/_pytest/config/__init__.py", line 175 in main
      File "/work2/noaa/co2/sbasu/packages/python/3.12.4/lib/python3.12/site-packages/numpy/_pytesttester.py", line 195 in __call__
      File "<ipython-input-2-dab0198860c9>", line 1 in <module>
      File "/work2/noaa/co2/sbasu/packages/python/3.12.4/lib/python3.12/site-packages/IPython/core/interactiveshell.py", line 3577 in run_code
      File "/work2/noaa/co2/sbasu/packages/python/3.12.4/lib/python3.12/site-packages/IPython/core/interactiveshell.py", line 3517 in run_ast_nodes
      File "/work2/noaa/co2/sbasu/packages/python/3.12.4/lib/python3.12/site-packages/IPython/core/interactiveshell.py", line 3334 in run_cell_async
      File "/work2/noaa/co2/sbasu/packages/python/3.12.4/lib/python3.12/site-packages/IPython/core/async_helpers.py", line 128 in _pseudo_sync_runner
      File "/work2/noaa/co2/sbasu/packages/python/3.12.4/lib/python3.12/site-packages/IPython/core/interactiveshell.py", line 3130 in _run_cell
      File "/work2/noaa/co2/sbasu/packages/python/3.12.4/lib/python3.12/site-packages/IPython/core/interactiveshell.py", line 3075 in run_cell
      File "/work2/noaa/co2/sbasu/packages/python/3.12.4/lib/python3.12/site-packages/IPython/terminal/interactiveshell.py", line 910 in interact
      File "/work2/noaa/co2/sbasu/packages/python/3.12.4/lib/python3.12/site-packages/IPython/terminal/interactiveshell.py", line 917 in mainloop
      File "/work2/noaa/co2/sbasu/packages/python/3.12.4/lib/python3.12/site-packages/IPython/terminal/ipapp.py", line 317 in start
      File "/work2/noaa/co2/sbasu/packages/python/3.12.4/lib/python3.12/site-packages/traitlets/config/application.py", line 1075 in launch_instance
      File "/work2/noaa/co2/sbasu/packages/python/3.12.4/lib/python3.12/site-packages/IPython/__init__.py", line 130 in start_ipython
      File "/work2/noaa/co2/sbasu/packages/python/3.12.4/bin/ipython", line 8 in <module>
    
  13. 6 remaining items

  14. r-devulap commented on Aug 8, 2024

    @r-devulap
    Member

    compile with the -fp-model=strict flag enabled, obviously :)

  15. AgilentGCMS commented on Aug 8, 2024

    @AgilentGCMS
    Author

    @r-devulap I compiled your code with icx -fp-model=strict test_rdevulap.c and ran the executable:

    $ ./a.out
    before: 0x1f80
    after: 0x1f81
    
  16. seberg commented on Aug 9, 2024

    @seberg
    Member

    The errors look pretty harmless overall. I would guess the math libraries are still using fast-math, so anything that calls out of NumPy into math libs is still sloppy about FPEs.
    (Of course they might still require users to disable checking FPEs.)

    EDIT: Ah, not sure about the longdouble versions being calls out into math libs, I suppose they may also be related to longdouble itself. I don't think the f2py thing is a problem.

  17. AgilentGCMS commented on Aug 9, 2024

    @AgilentGCMS
    Author

    @seberg Any reason why math libraries would still use fast-math even after I've specified -fp-model=strict?

  18. seberg commented on Aug 9, 2024

    @seberg
    Member

    They are dynamically linked and there is only one version of them, no? So either strict, or not.

  19. r-devulap commented on Aug 9, 2024

    @r-devulap
    Member

    @seberg I agree, these look specific to ICPX. Most the test failures seem harmless, except I am not sure about these two:

    FAILED numpy/f2py/tests/test_kind.py::TestKind::test_int - AssertionError: selectedintkind(19): expected 16 but got -1
    FAILED numpy/f2py/tests/test_kind.py::TestKind::test_real - AssertionError: selectedrealkind(16): expected 10 but got 16
    

    Do you know what these failures are?

  20. AgilentGCMS commented on Aug 9, 2024

    @AgilentGCMS
    Author

    They are dynamically linked and there is only one version of them, no? So either strict, or not.

    So these will disappear if I link with the static library? I'll try.

  21. seberg commented on Aug 9, 2024

    @seberg
    Member

    Do you know what these failures are?

    I forgot the exact cause but IIRC they are some wrong dtype mappings in f2py (and with that I think just the tests) and probably harmless as well, i.e.the test setup is brittle w.r.t. to new platforms.

  22. r-devulap commented on Aug 9, 2024

    @r-devulap
    Member

    static linking or dynamic link shouldn't fix it, I think. The libraries are precompiled and shipped, changing the way you link to them won't affect their behavior.

  23. r-devulap commented on Aug 9, 2024

    @r-devulap
    Member

    From the docs, -fp-model=strict should raise all appropriate FP exceptions.

    -fp-model=strict or /fp:strict | Tells the compiler to strictly adhere to value-safe optimizations when implementing floating-point calculations and enables floating-point exception semantics.
    
  24. AgilentGCMS commented on Aug 9, 2024

    @AgilentGCMS
    Author

    static linking or dynamic link shouldn't fix it, I think. The libraries are precompiled and shipped, changing the way you link to them won't affect their behavior.

    I can confirm that linking to the static library did not fix/change anything. I get the same failures, including the two you were concerned about.

    FAILED numpy/_core/tests/test_numeric.py::TestFloatExceptions::test_floating_exceptions[G] - AssertionError: Type <class 'numpy.clongdouble'> did not raise fpe error 'overflow'.
    FAILED numpy/_core/tests/test_umath.py::TestRemainder::test_float_divmod_errors[g] - AssertionError: FloatingPointError not raised by divmod
    FAILED numpy/_core/tests/test_umath.py::TestRemainder::test_float_remainder_errors[fmod-g] - Failed: DID NOT RAISE <class 'FloatingPointError'>
    FAILED numpy/_core/tests/test_umath.py::TestRemainder::test_float_remainder_errors[remainder-g] - Failed: DID NOT RAISE <class 'FloatingPointError'>
    FAILED numpy/_core/tests/test_umath.py::TestSpecialFloats::test_log_values - AssertionError: FloatingPointError not raised by log2
    FAILED numpy/_core/tests/test_umath.py::TestSpecialFloats::test_arcsincos - AssertionError: FloatingPointError not raised by arcsin
    FAILED numpy/_core/tests/test_umath_complex.py::TestClog::test_special_values - AssertionError: FloatingPointError not raised by log
    FAILED numpy/f2py/tests/test_kind.py::TestKind::test_int - AssertionError: selectedintkind(19): expected 16 but got -1
    FAILED numpy/f2py/tests/test_kind.py::TestKind::test_real - AssertionError: selectedrealkind(16): expected 10 but got 16
    
  25. mattip commented on Aug 11, 2024

    @mattip
    Member

    IIRC they are some wrong dtype mappings in f2py

    I seem to remember this as well.

  26. seberg commented on Aug 11, 2024

    @seberg
    Member

    @AgilentGCMS I am not sure about those exact test failures. However:

    • Compiler and/or math library bugs around correct (strict) FPE handling are not super uncommon. So there is also some chance that it is impossible to remove the warnings.
    • Under normal runtime, these will be warnings not errors. Also the first of these are in longdouble handling which very few users use. (Leaving those in log2 and arcsin) So you can probably get away with this by telling your users that these are harmless warnings and that they can suppress them with np.errstate. (Not suppressing warnings does come with a non-negligible overhead for small arrays.)
    • For the kind errors, see e.g. BUG: loongarch doesn't use REAL(10) #24904 or search a bit more. It might be nice to see what we have to change to make the test pass simply. (Or maybe we should finally give up on this brittle test...)
  27. AgilentGCMS commented on Aug 11, 2024

    @AgilentGCMS
    Author

    OK, I'm going to close this for now. Thanks for all your help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions