numba / llvmlite

A lightweight LLVM python binding for writing JIT compilers
https://llvmlite.pydata.org/
BSD 2-Clause "Simplified" License
1.9k stars 316 forks source link

KeyError: 'LLVMPY_AddRefPrunePass' #773

Open ManPython opened 2 years ago

ManPython commented 2 years ago
Collecting llvmlite
  Using cached llvmlite-0.37.0.tar.gz (125 kB)
Building wheels for collected packages: llvmlite
  Building wheel for llvmlite (setup.py) ... done
  Created wheel for llvmlite: filename=llvmlite-0.37.0-cp37-cp37m-freebsd_12_2_release_p2_amd64.whl size=786970 sha256=67b982730ac8d9befbe13d48492e98b068e40ae21f30c24623e539b6e60fe610
  Stored in directory: /usr/bla bla
Successfully built llvmlite
Installing collected packages: llvmlite
Successfully installed llvmlite-0.37.0 

Running

#https://stumpy.readthedocs.io/en/latest/Tutorial_STUMPY_Basics.html
%matplotlib inline

import pandas as pd
import stumpy
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.dates as dates
from matplotlib.patches import Rectangle
import datetime as dt

plt.style.use('https://raw.githubusercontent.com/TDAmeritrade/stumpy/main/docs/stumpy.mplstyle')

Getting

---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
/usr/home/userman/venv/lib/python3.7/site-packages/llvmlite/binding/ffi.py in __getattr__(self, name)
     94         try:
---> 95             return self._fntab[name]
     96         except KeyError:

KeyError: 'LLVMPY_AddRefPrunePass'

During handling of the above exception, another exception occurred:

AttributeError                            Traceback (most recent call last)
/tmp/ipykernel_48923/1428017245.py in <module>
      3 
      4 import pandas as pd
----> 5 import stumpy
      6 import numpy as np
      7 import matplotlib.pyplot as plt

/usr/home/userman/venv/lib/python3.7/site-packages/stumpy/__init__.py in <module>
      1 from pkg_resources import get_distribution, DistributionNotFound
      2 import os.path
----> 3 from .core import mass  # noqa: F401
      4 from .stump import stump  # noqa: F401
      5 from .stumped import stumped  # noqa: F401

/usr/home/userman/venv/lib/python3.7/site-packages/stumpy/core.py in <module>
      8 
      9 import numpy as np
---> 10 from numba import njit, prange
     11 from scipy.signal import convolve
     12 from scipy.ndimage.filters import maximum_filter1d, minimum_filter1d

/usr/home/userman/venv/lib/python3.7/site-packages/numba/__init__.py in <module>
     17 
     18 
---> 19 from numba.core import config
     20 from numba.testing import _runtests as runtests
     21 from numba.core import types, errors

/usr/home/userman/venv/lib/python3.7/site-packages/numba/core/config.py in <module>
     14 
     15 
---> 16 import llvmlite.binding as ll
     17 
     18 IS_WIN32 = sys.platform.startswith('win32')

/usr/home/userman/venv/lib/python3.7/site-packages/llvmlite/binding/__init__.py in <module>
      8 from .module import *
      9 from .options import *
---> 10 from .passmanagers import *
     11 from .targets import *
     12 from .transforms import *

/usr/home/userman/venv/lib/python3.7/site-packages/llvmlite/binding/passmanagers.py in <module>
    281 
    282 ffi.lib.LLVMPY_AddRefPrunePass.argtypes = [ffi.LLVMPassManagerRef, c_int,
--> 283                                            c_size_t]

/usr/home/userman/venv/lib/python3.7/site-packages/llvmlite/binding/ffi.py in __getattr__(self, name)
     96         except KeyError:
     97             # Lazily wraps new functions as they are requested
---> 98             cfn = getattr(self._lib, name)
     99             wrapped = _lib_fn_wrapper(self._lock, cfn)
    100             self._fntab[name] = wrapped

/usr/local/lib/python3.7/ctypes/__init__.py in __getattr__(self, name)
    375         if name.startswith('__') and name.endswith('__'):
    376             raise AttributeError(name)
--> 377         func = self.__getitem__(name)
    378         setattr(self, name, func)
    379         return func

/usr/local/lib/python3.7/ctypes/__init__.py in __getitem__(self, name_or_ordinal)
    380 
    381     def __getitem__(self, name_or_ordinal):
--> 382         func = self._FuncPtr((name_or_ordinal, self))
    383         if not isinstance(name_or_ordinal, int):
    384             func.__name__ = name_or_ordinal

AttributeError: Undefined symbol "LLVMPY_AddRefPrunePass"
sklam commented 2 years ago

This looks like a build issue. On FreeBSD, the sharedlibrary is missing the LLVMPY_AddRefPrunePass symbol. I'm guessing it is caused by the lack of custom_passes.cpp in https://github.com/numba/llvmlite/blob/257f77f7417e5fbeea3aa3f7eaba176aec482fa9/ffi/Makefile.freebsd#L12-L14. For comparison, see the linux Makefile.

sklam commented 2 years ago

i thk the patch is just below, but i don't have a freebsd handy for testing.

diff --git a/ffi/Makefile.freebsd b/ffi/Makefile.freebsd
index ba727e3..7422e13 100644
--- a/ffi/Makefile.freebsd
+++ b/ffi/Makefile.freebsd
@@ -11,7 +11,7 @@ LIBS = $(LLVM_LIBS)
 INCLUDE = core.h
 SRC = assembly.cpp bitcode.cpp core.cpp initfini.cpp module.cpp value.cpp \
    executionengine.cpp transforms.cpp passmanagers.cpp targets.cpp dylib.cpp \
-   linker.cpp object_file.cpp
+   linker.cpp object_file.cpp custom_passes.cpp
 OUTPUT = libllvmlite.so

 all: $(OUTPUT)
ManPython commented 2 years ago

Soo.. I should uninstall and install again the llvmlite and numba? https://github.com/TDAmeritrade/stumpy/issues/468

ManPython commented 2 years ago

@sklam maybe it's related? https://github.com/matplotlib/matplotlib/issues/21202#issuecomment-932609678

esc commented 2 years ago

Soo.. I should uninstall and install again the llvmlite and numba? TDAmeritrade/stumpy#468

I think in this case you may have to compile llvmlite from scratch. Normally I would recommend to also compile LLVM itself, but people have been reporting good success with various distribution based LLVM packages recently, so I would recommend that. I.e. to use the patch @sklam suggested above and then to recompile llvmlite using a BSD provided LLVM package in version 11. Hope this helps and let us know if you need any additional pointers.

ManPython commented 2 years ago

No progress here coz the BSD is hosting and limiting administration, eg LLVM.