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

Scipy via ginstall fails due to fortran compiler errors #265

Closed
ashesfall opened this issue May 4, 2022 · 9 comments
Closed

Scipy via ginstall fails due to fortran compiler errors #265

ashesfall opened this issue May 4, 2022 · 9 comments
Assignees

Comments

@ashesfall
Copy link

After running graalpython -m ginstall install scipy an error about LAPACK is produced (included below).

Perhaps this is just a documentation issue. Is there a prerequisite for install scipy?

/home/michael/venv/lib/python3.8/site-packages/numpy-1.16.4-py3.8-linux-x86_64.egg/numpy/distutils/system_info.py:639: UserWarning: 
    Lapack (http://www.netlib.org/lapack/) sources not found.
    Directories to search for the sources can be specified in the
    numpy/distutils/site.cfg file (section [lapack_src]) or by setting
    the LAPACK_SRC environment variable.
  self.calc_info()
  NOT AVAILABLE

Traceback (most recent call last):
  File "/tmp/tmpg2uvn2_9/scipy-1.3.1/setup.py", line 505, in <module 'setup.py'>
    setup_package()
  File "/tmp/tmpg2uvn2_9/scipy-1.3.1/setup.py", line 501, in setup_package
    setup(**metadata)
  File "/home/michael/venv/lib/python3.8/site-packages/numpy-1.16.4-py3.8-linux-x86_64.egg/numpy/distutils/core.py", line 137, in setup
    config = configuration()
  File "/tmp/tmpg2uvn2_9/scipy-1.3.1/setup.py", line 403, in configuration
    raise NotFoundError(msg)
numpy.distutils.system_info.NotFoundError: No lapack/blas resources found.
@ashesfall
Copy link
Author

After installing openblas and lapack, a different error emerges.

/usr/bin/gfortran -Wall -g build/temp.linux-x86_64-3.8/scipy/cluster/_vq.o -L/usr/lib64 -L/usr/lib/gcc/x86_64-redhat-linux/7 -L/usr/lib/gcc/x86_64-redhat-linux/7 -Lbuild/temp.linux-x86_64-3.8 -llapack -llapack -lblas -lblas -lgfortran -o build/lib.linux-x86_64-3.8/scipy/cluster/_vq.graalpython-38-native-x86_64-linux.so
ld.lld: error: undefined symbol: main
>>> referenced by /usr/lib/gcc/x86_64-redhat-linux/7/../../../../lib64/crt1.o:(_start)

ld.lld: error: undefined symbol: PyModuleDef_Init
>>> referenced by _vq.c:8440 (/tmp/tmpaioal2ws/scipy-1.3.1/scipy/cluster/_vq.c:8440)
>>>               lto.tmp:(PyInit__vq)

ld.lld: error: undefined symbol: PyObject_GetAttrString
>>> referenced by _vq.c:8486 (/tmp/tmpaioal2ws/scipy-1.3.1/scipy/cluster/_vq.c:8486)
>>>               lto.tmp:(__pyx_pymod_create)
>>> referenced by __multiarray_api.h:1472 (/home/michael/venv/lib/python3.8/site-packages/numpy-1.16.4-py3.8-linux-x86_64.egg/numpy/core/include/numpy/__multiarray_api.h:1472)
>>>               lto.tmp:(_import_array)
>>> referenced by _vq.c:10204 (/tmp/tmpaioal2ws/scipy-1.3.1/scipy/cluster/_vq.c:10204)
>>>               lto.tmp:(__Pyx_ImportType)
>>> referenced 1 more times

ld.lld: error: undefined symbol: PyModule_NewObject
>>> referenced by _vq.c:8488 (/tmp/tmpaioal2ws/scipy-1.3.1/scipy/cluster/_vq.c:8488)
>>>               lto.tmp:(__pyx_pymod_create)

ld.lld: error: undefined symbol: PyModule_GetDict
>>> referenced by _vq.c:8491 (/tmp/tmpaioal2ws/scipy-1.3.1/scipy/cluster/_vq.c:8491)
>>>               lto.tmp:(__pyx_pymod_create)
>>> referenced by _vq.c:8574 (/tmp/tmpaioal2ws/scipy-1.3.1/scipy/cluster/_vq.c:8574)
>>>               lto.tmp:(__pyx_pymod_exec__vq)
>>> referenced by _vq.c:10274 (/tmp/tmpaioal2ws/scipy-1.3.1/scipy/cluster/_vq.c:10274)
>>>               lto.tmp:(__Pyx_Import)

ld.lld: error: undefined symbol: PyExc_RuntimeError
>>> referenced by _vq.c:8514 (/tmp/tmpaioal2ws/scipy-1.3.1/scipy/cluster/_vq.c:8514)
>>>               lto.tmp:(__pyx_pymod_exec__vq)
>>> referenced by __multiarray_api.h:1481 (/home/michael/venv/lib/python3.8/site-packages/numpy-1.16.4-py3.8-linux-x86_64.egg/numpy/core/include/numpy/__multiarray_api.h:1481)
>>>               lto.tmp:(_import_array)
>>> referenced by __multiarray_api.h:1508 (/home/michael/venv/lib/python3.8/site-packages/numpy-1.16.4-py3.8-linux-x86_64.egg/numpy/core/include/numpy/__multiarray_api.h:1508)
>>>               lto.tmp:(_import_array)
>>> referenced 4 more times

ld.lld: error: undefined symbol: PyErr_SetString
>>> referenced by _vq.c:8514 (/tmp/tmpaioal2ws/scipy-1.3.1/scipy/cluster/_vq.c:8514)
>>>               lto.tmp:(__pyx_pymod_exec__vq)
>>> referenced by _vq.c:8688 (/tmp/tmpaioal2ws/scipy-1.3.1/scipy/cluster/_vq.c:8688)
>>>               lto.tmp:(__pyx_pymod_exec__vq)
>>> referenced by _vq.c:11121 (/tmp/tmpaioal2ws/scipy-1.3.1/scipy/cluster/_vq.c:11121)
>>>               lto.tmp:(__Pyx_PyInt_As_int)
>>> referenced 13 more times

ld.lld: error: undefined symbol: PyTuple_New
>>> referenced by _vq.c:8534 (/tmp/tmpaioal2ws/scipy-1.3.1/scipy/cluster/_vq.c:8534)
>>>               lto.tmp:(__pyx_pymod_exec__vq)
>>> referenced by _vq.c:5365 (/tmp/tmpaioal2ws/scipy-1.3.1/scipy/cluster/_vq.c:5365)
>>>               lto.tmp:(__pyx_pf_5scipy_7cluster_3_vq_2update_cluster_means)
>>> referenced by _vq.c:5420 (/tmp/tmpaioal2ws/scipy-1.3.1/scipy/cluster/_vq.c:5420)
>>>               lto.tmp:(__pyx_pf_5scipy_7cluster_3_vq_2update_cluster_means)
>>> referenced 19 more times

ld.lld: error: undefined symbol: PyBytes_FromStringAndSize
>>> referenced by _vq.c:8535 (/tmp/tmpaioal2ws/scipy-1.3.1/scipy/cluster/_vq.c:8535)
>>>               lto.tmp:(__pyx_pymod_exec__vq)
>>> referenced by _vq.c:11676 (/tmp/tmpaioal2ws/scipy-1.3.1/scipy/cluster/_vq.c:11676)
>>>               lto.tmp:(__Pyx_InitStrings)

ld.lld: error: undefined symbol: PyUnicode_FromStringAndSize
>>> referenced by _vq.c:8536 (/tmp/tmpaioal2ws/scipy-1.3.1/scipy/cluster/_vq.c:8536)
>>>               lto.tmp:(__pyx_pymod_exec__vq)
>>> referenced by _vq.c:11673 (/tmp/tmpaioal2ws/scipy-1.3.1/scipy/cluster/_vq.c:11673)
>>>               lto.tmp:(__Pyx_InitStrings)

ld.lld: error: undefined symbol: PyImport_AddModule
>>> referenced by _vq.c:8576 (/tmp/tmpaioal2ws/scipy-1.3.1/scipy/cluster/_vq.c:8576)
>>>               lto.tmp:(__pyx_pymod_exec__vq)
>>> referenced by _vq.c:8578 (/tmp/tmpaioal2ws/scipy-1.3.1/scipy/cluster/_vq.c:8578)
>>>               lto.tmp:(__pyx_pymod_exec__vq)

ld.lld: error: undefined symbol: PyObject_SetAttrString
>>> referenced by _vq.c:8580 (/tmp/tmpaioal2ws/scipy-1.3.1/scipy/cluster/_vq.c:8580)
>>>               lto.tmp:(__pyx_pymod_exec__vq)

ld.lld: error: undefined symbol: PyObject_SetAttr
>>> referenced by _vq.c:8587 (/tmp/tmpaioal2ws/scipy-1.3.1/scipy/cluster/_vq.c:8587)
>>>               lto.tmp:(__pyx_pymod_exec__vq)
>>> referenced by _vq.c:10350 (/tmp/tmpaioal2ws/scipy-1.3.1/scipy/cluster/_vq.c:10350)
>>>               lto.tmp:(__Pyx_CLineForTraceback)

ld.lld: error: undefined symbol: PyImport_GetModuleDict
>>> referenced by _vq.c:8591 (/tmp/tmpaioal2ws/scipy-1.3.1/scipy/cluster/_vq.c:8591)
>>>               lto.tmp:(__pyx_pymod_exec__vq)

ld.lld: error: undefined symbol: PyDict_GetItemString
>>> referenced by _vq.c:8592 (/tmp/tmpaioal2ws/scipy-1.3.1/scipy/cluster/_vq.c:8592)
>>>               lto.tmp:(__pyx_pymod_exec__vq)

ld.lld: error: undefined symbol: PyDict_SetItemString
>>> referenced by _vq.c:8593 (/tmp/tmpaioal2ws/scipy-1.3.1/scipy/cluster/_vq.c:8593)
>>>               lto.tmp:(__pyx_pymod_exec__vq)
>>> referenced by _vq.c:8470 (/tmp/tmpaioal2ws/scipy-1.3.1/scipy/cluster/_vq.c:8470)
>>>               lto.tmp:(__Pyx_copy_spec_to_module)

ld.lld: error: undefined symbol: PyDict_SetItem
>>> referenced by _vq.c:8623 (/tmp/tmpaioal2ws/scipy-1.3.1/scipy/cluster/_vq.c:8623)
>>>               lto.tmp:(__pyx_pymod_exec__vq)
>>> referenced by _vq.c:8644 (/tmp/tmpaioal2ws/scipy-1.3.1/scipy/cluster/_vq.c:8644)
>>>               lto.tmp:(__pyx_pymod_exec__vq)
>>> referenced by _vq.c:8656 (/tmp/tmpaioal2ws/scipy-1.3.1/scipy/cluster/_vq.c:8656)
>>>               lto.tmp:(__pyx_pymod_exec__vq)
>>> referenced 5 more times

ld.lld: error: undefined symbol: PyCFunction_NewEx
>>> referenced by _vq.c:8642 (/tmp/tmpaioal2ws/scipy-1.3.1/scipy/cluster/_vq.c:8642)
>>>               lto.tmp:(__pyx_pymod_exec__vq)
>>> referenced by _vq.c:8654 (/tmp/tmpaioal2ws/scipy-1.3.1/scipy/cluster/_vq.c:8654)
>>>               lto.tmp:(__pyx_pymod_exec__vq)

ld.lld: error: undefined symbol: PyDict_New
>>> referenced by _vq.c:8664 (/tmp/tmpaioal2ws/scipy-1.3.1/scipy/cluster/_vq.c:8664)
>>>               lto.tmp:(__pyx_pymod_exec__vq)
>>> referenced by _vq.c:10277 (/tmp/tmpaioal2ws/scipy-1.3.1/scipy/cluster/_vq.c:10277)
>>>               lto.tmp:(__Pyx_Import)
>>> referenced by _vq.c:5370 (/tmp/tmpaioal2ws/scipy-1.3.1/scipy/cluster/_vq.c:5370)
>>>               lto.tmp:(__pyx_pf_5scipy_7cluster_3_vq_2update_cluster_means)
>>> referenced 3 more times

ld.lld: error: undefined symbol: PyErr_Occurred
>>> referenced by _vq.c:8687 (/tmp/tmpaioal2ws/scipy-1.3.1/scipy/cluster/_vq.c:8687)
>>>               lto.tmp:(__pyx_pymod_exec__vq)
>>> referenced by _vq.c:5073 (/tmp/tmpaioal2ws/scipy-1.3.1/scipy/cluster/_vq.c:5073)
>>>               lto.tmp:(__pyx_pw_5scipy_7cluster_3_vq_3update_cluster_means)
>>> referenced by _vq.c:9516 (/tmp/tmpaioal2ws/scipy-1.3.1/scipy/cluster/_vq.c:9516)
>>>               lto.tmp:(__Pyx_ParseOptionalKeywords)
>>> referenced 6 more times

ld.lld: error: too many errors emitted, stopping now (use -error-limit=0 to see all errors)
collect2: error: ld returned 1 exit status
error: Command "/usr/bin/gfortran -Wall -g build/temp.linux-x86_64-3.8/scipy/cluster/_vq.o -L/usr/lib64 -L/usr/lib/gcc/x86_64-redhat-linux/7 -L/usr/lib/gcc/x86_64-redhat-linux/7 -Lbuild/temp.linux-x86_64-3.8 -llapack -llapack -lblas -lblas -lgfortran -o build/lib.linux-x86_64-3.8/scipy/cluster/_vq.graalpython-38-native-x86_64-linux.so" failed with exit status 1
None

@ashesfall ashesfall changed the title Scipy via ginstall fails due to lapack Scipy via ginstall fails due to fortran compiler errors May 4, 2022
@msimacek
Copy link
Contributor

msimacek commented May 4, 2022

Which version did you try to install? We don't yet support newer versions of numpy and I think that extends to scipy as well. Please use python -m ginstall install scipy, that will pick the best version. Note that scipy is known to work only partially, some modules work, some don't.

To answer your first question - packages implemented in C typically have some system dependencies to build from source, they are usually described in the project's readme (something like "Building from source"). Many projects often also provide prebuilt binary wheels for few most common combinations of CPU + OS + libc + Python interpreter. So you probably didn't have to build from source on CPython because there is a prebuilt binary compatible with you system and CPython version. But nobody is yet building binary wheels for GraalPython, so we always end up building from source.

@ashesfall
Copy link
Author

All of the output I included in this ticket is the result of graalpython -m ginstall install scipy
This is using the latest graalpython for java 17, 22.1.0

@msimacek
Copy link
Contributor

I cannot build it either, although with a different error. @cosminbasca is working on fixing the build, we'll let you know when it's merged. But don't expect much, we still won't be able to run the fortran parts even if they build because there is no fortran-to-LLVM-bitcode compiler yet.

@ashesfall
Copy link
Author

What can I do to move this forward? I have experience with Intel HPC Fortran, have been working with the JVM since it was made available by Sun, and really need a solution to scipy on graal - if not now, then over the long term. What we're doing now is not going to scale over upcoming years. Is there something you can use me for?

@msimacek
Copy link
Contributor

The main issue for running scipy is that we cannot run the fortran code. GraalPython runs "native" languages like C using Sulong, an LLVM runtime on GraalVM. They get compiled to LLVM bitcode and Sulong then executes them. The problem with fortran is that last time we cehcked, there was still no working open-source compiler that could produce LLVM bitcode. So if you want to help, you could research the current state of fortran compilers targetting LLVM. There are many work-in-progress attempts at making a fortran LLVM compiler, maybe one of them progressed over the last few months to the point they can generate LLVM bitcode. If not, maybe you could contribute to one of the projects so that they can. Note it is necessary to generate LLVM bitcode, not just native executables (like gfortran).

@ashesfall
Copy link
Author

So, maybe I'm missing something here, but the LLVM intermediate language can be generated using the frontend flang:
https://github.com/llvm/llvm-project/tree/main/flang/

And the resulting IR (I would assume?) can be converted to bitcode.

Unless someone has already tried this and failed, I will go ahead and build flang and use it to try and build scipy from source.

@manticore-projects
Copy link

Greetings.

I ran into similar issues on ARCH Linux with GCC-13.
Although installing GCC-9 seems to work:

are@ryzen ~> source graalpy20/bin/activate.fish
(graalpy20) are@ryzen ~> CC="gcc-9" CF="gfortran-9" CFLAGS='-march=native' CXXFLAGS='-march=native' pip install --no-clean --no-binary :all: scipy

Runs for hours now, eating all my RAM but seem to do something.

@msimacek
Copy link
Contributor

The most recent version of graalpy doesn't use LLVM for C extension execution anymore by default, it would use your system toolchain, so the problem reported here shouldn't exist in graalpy 23.0. scipy would build with your system gfortran as it would for CPython. Please reopen the issue if you still observe problems.

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

No branches or pull requests

4 participants