oracle / graalpython

A Python 3 implementation built on GraalVM
Other
1.2k stars 103 forks source link

ScyPi on GraalPy JDK 11 fails with Linker Error #352

Closed manticore-projects closed 1 year ago

manticore-projects commented 1 year ago

Issue 1: compiler flags need to be set for LLVM, or else an "Argument mismatch" error will stop the build

CFLAGS=-fallow-argument-mismatch FFLAGS=-fallow-argument-mismatch python -m ginstall install scipy

Issue 2: with flags set the build advances but fails linking

/usr/bin/gfortran -Wall -g build/temp.linux-x86_64-3.8/build/src.linux-x86_64-3.8/scipy/fftpack/_fftpackmodule.o build/temp.linux-x86_64-3.8/scipy/fftpack/src/zfft.o build/temp.linux-x86_64-3.8/scipy/fftpack/src/drfft.o build/temp.linux-x86_64-3.8/scipy/fftpack/src/zrfft.o build/temp.linux-x86_64-3.8/scipy/fftpack/src/zfftnd.o build/temp.linux-x86_64-3.8/build/src.linux-x86_64-3.8/scipy/fftpack/src/dct.o build/temp.linux-x86_64-3.8/build/src.linux-x86_64-3.8/scipy/fftpack/src/dst.o build/temp.linux-x86_64-3.8/build/src.linux-x86_64-3.8/build/src.linux-x86_64-3.8/scipy/fftpack/fortranobject.o -L/usr/lib/gcc/x86_64-pc-linux-gnu/13.2.1/../../../../lib -L/usr/lib/gcc/x86_64-pc-linux-gnu/13.2.1/../../../../lib -Lbuild/temp.linux-x86_64-3.8 -ldfftpack -lfftpack -lgfortran -o build/lib.linux-x86_64-3.8/scipy/fftpack/_fftpack.graalpy-38-native-x86_64-linux.so
ld.lld: error: undefined symbol: main
>>> referenced by /usr/lib/gcc/x86_64-pc-linux-gnu/13.2.1/../../../../lib/Scrt1.o:(_start)

ld.lld: error: undefined symbol: PyModule_Create2
>>> referenced by _fftpackmodule.c:4120 (/tmp/tmp05i77mjl/scipy-1.3.1/build/src.linux-x86_64-3.8/scipy/fftpack/_fftpackmodule.c:4120)
>>>               lto.tmp:(PyInit__fftpack)

ld.lld: error: undefined symbol: PyType_Type
>>> referenced by _fftpackmodule.c:4124 (/tmp/tmp05i77mjl/scipy-1.3.1/build/src.linux-x86_64-3.8/scipy/fftpack/_fftpackmodule.c:4124)
>>>               lto.tmp:(PyInit__fftpack)

ld.lld: error: undefined symbol: _Py_SET_TYPE
>>> referenced by _fftpackmodule.c:4124 (/tmp/tmp05i77mjl/scipy-1.3.1/build/src.linux-x86_64-3.8/scipy/fftpack/_fftpackmodule.c:4124)
>>>               lto.tmp:(PyInit__fftpack)

ld.lld: error: undefined symbol: PyImport_ImportModule
>>> referenced by __multiarray_api.h:1466 (/home/are/graalpy11/lib/python3.8/site-packages/numpy/core/include/numpy/__multiarray_api.h:1466)
>>>               lto.tmp:(PyInit__fftpack)

ld.lld: error: undefined symbol: PyObject_GetAttrString
>>> referenced by __multiarray_api.h:1472 (/home/are/graalpy11/lib/python3.8/site-packages/numpy/core/include/numpy/__multiarray_api.h:1472)
>>>               lto.tmp:(PyInit__fftpack)
>>> referenced by _fftpackmodule.c:152 (/tmp/tmp05i77mjl/scipy-1.3.1/build/src.linux-x86_64-3.8/scipy/fftpack/_fftpackmodule.c:152)
>>>               lto.tmp:(int_from_pyobj)
>>> referenced by fortranobject.c:415 (/tmp/tmp05i77mjl/scipy-1.3.1/build/src.linux-x86_64-3.8/build/src.linux-x86_64-3.8/scipy/fftpack/fortranobject.c:415)
>>>               lto.tmp:(fortran_repr)

ld.lld: error: undefined symbol: PyCapsule_TypeReference
>>> referenced by __multiarray_api.h:1480 (/home/are/graalpy11/lib/python3.8/site-packages/numpy/core/include/numpy/__multiarray_api.h:1480)
>>>               lto.tmp:(PyInit__fftpack)
>>> referenced by fortranobject.c:1060 (/tmp/tmp05i77mjl/scipy-1.3.1/build/src.linux-x86_64-3.8/build/src.linux-x86_64-3.8/scipy/fftpack/fortranobject.c:1060)
>>>               lto.tmp:(F2PyCapsule_Check)

ld.lld: error: undefined symbol: PyExc_RuntimeError
>>> referenced by __multiarray_api.h:1481 (/home/are/graalpy11/lib/python3.8/site-packages/numpy/core/include/numpy/__multiarray_api.h:1481)
>>>               lto.tmp:(PyInit__fftpack)
>>> referenced by __multiarray_api.h:1508 (/home/are/graalpy11/lib/python3.8/site-packages/numpy/core/include/numpy/__multiarray_api.h:1508)
>>>               lto.tmp:(PyInit__fftpack)
>>> referenced by __multiarray_api.h:1496 (/home/are/graalpy11/lib/python3.8/site-packages/numpy/core/include/numpy/__multiarray_api.h:1496)
>>>               lto.tmp:(PyInit__fftpack)
>>> referenced 4 more times

ld.lld: error: undefined symbol: PyErr_SetString
>>> referenced by __multiarray_api.h:1481 (/home/are/graalpy11/lib/python3.8/site-packages/numpy/core/include/numpy/__multiarray_api.h:1481)
>>>               lto.tmp:(PyInit__fftpack)
>>> referenced by __multiarray_api.h:1475 (/home/are/graalpy11/lib/python3.8/site-packages/numpy/core/include/numpy/__multiarray_api.h:1475)
>>>               lto.tmp:(PyInit__fftpack)
>>> referenced by __multiarray_api.h:1496 (/home/are/graalpy11/lib/python3.8/site-packages/numpy/core/include/numpy/__multiarray_api.h:1496)
>>>               lto.tmp:(PyInit__fftpack)
>>> referenced 38 more times

ld.lld: error: undefined symbol: _Py_Dealloc
>>> referenced by object.h:496 (/usr/lib/jvm/java-11-graalvm/languages/python/include/object.h:496)
>>>               lto.tmp:(PyInit__fftpack)
>>> referenced by object.h:496 (/usr/lib/jvm/java-11-graalvm/languages/python/include/object.h:496)
>>>               lto.tmp:(PyInit__fftpack)
>>> referenced by object.h:496 (/usr/lib/jvm/java-11-graalvm/languages/python/include/object.h:496)
>>>               lto.tmp:(PyInit__fftpack)
>>> referenced 18 more times

ld.lld: error: undefined symbol: PyExc_AttributeError
>>> referenced by __multiarray_api.h:1475 (/home/are/graalpy11/lib/python3.8/site-packages/numpy/core/include/numpy/__multiarray_api.h:1475)
>>>               lto.tmp:(PyInit__fftpack)
>>> referenced by fortranobject.c:382 (/tmp/tmp05i77mjl/scipy-1.3.1/build/src.linux-x86_64-3.8/build/src.linux-x86_64-3.8/scipy/fftpack/fortranobject.c:382)
>>>               lto.tmp:(fortran_setattr)
>>> referenced by fortranobject.c:333 (/tmp/tmp05i77mjl/scipy-1.3.1/build/src.linux-x86_64-3.8/build/src.linux-x86_64-3.8/scipy/fftpack/fortranobject.c:333)
>>>               lto.tmp:(fortran_setattr)

ld.lld: error: undefined symbol: PyCapsule_GetPointer
>>> referenced by __multiarray_api.h:1485 (/home/are/graalpy11/lib/python3.8/site-packages/numpy/core/include/numpy/__multiarray_api.h:1485)
>>>               lto.tmp:(PyInit__fftpack)
>>> referenced by fortranobject.c:1050 (/tmp/tmp05i77mjl/scipy-1.3.1/build/src.linux-x86_64-3.8/build/src.linux-x86_64-3.8/scipy/fftpack/fortranobject.c:1050)
>>>               lto.tmp:(F2PyCapsule_AsVoidPtr)

ld.lld: error: undefined symbol: PyErr_Format
>>> referenced by __multiarray_api.h:0 (/home/are/graalpy11/lib/python3.8/site-packages/numpy/core/include/numpy/__multiarray_api.h:0)
>>>               lto.tmp:(PyInit__fftpack)
>>> referenced by __multiarray_api.h:0 (/home/are/graalpy11/lib/python3.8/site-packages/numpy/core/include/numpy/__multiarray_api.h:0)
>>>               lto.tmp:(PyInit__fftpack)
>>> referenced by fortranobject.c:0 (/tmp/tmp05i77mjl/scipy-1.3.1/build/src.linux-x86_64-3.8/build/src.linux-x86_64-3.8/scipy/fftpack/fortranobject.c:0)
>>>               lto.tmp:(fortran_call)
>>> referenced 5 more times

ld.lld: error: undefined symbol: PyErr_Print
>>> referenced by _fftpackmodule.c:4125 (/tmp/tmp05i77mjl/scipy-1.3.1/build/src.linux-x86_64-3.8/scipy/fftpack/_fftpackmodule.c:4125)
>>>               lto.tmp:(PyInit__fftpack)
>>> referenced by fortranobject.c:25 (/tmp/tmp05i77mjl/scipy-1.3.1/build/src.linux-x86_64-3.8/build/src.linux-x86_64-3.8/scipy/fftpack/fortranobject.c:25)
>>>               lto.tmp:(F2PyDict_SetItemString)

ld.lld: error: undefined symbol: PyExc_ImportError
>>> referenced by _fftpackmodule.c:0 (/tmp/tmp05i77mjl/scipy-1.3.1/build/src.linux-x86_64-3.8/scipy/fftpack/_fftpackmodule.c:0)
>>>               lto.tmp:(PyInit__fftpack)

ld.lld: error: undefined symbol: PyErr_Occurred
>>> referenced by _fftpackmodule.c:4126 (/tmp/tmp05i77mjl/scipy-1.3.1/build/src.linux-x86_64-3.8/scipy/fftpack/_fftpackmodule.c:4126)
>>>               lto.tmp:(PyInit__fftpack)
>>> referenced by _fftpackmodule.c:319 (/tmp/tmp05i77mjl/scipy-1.3.1/build/src.linux-x86_64-3.8/scipy/fftpack/_fftpackmodule.c:319)
>>>               lto.tmp:(f2py_rout__fftpack_zfft)
>>> referenced by _fftpackmodule.c:346 (/tmp/tmp05i77mjl/scipy-1.3.1/build/src.linux-x86_64-3.8/scipy/fftpack/_fftpackmodule.c:346)
>>>               lto.tmp:(f2py_rout__fftpack_zfft)
>>> referenced 68 more times

ld.lld: error: undefined symbol: PyModule_GetDict
>>> referenced by _fftpackmodule.c:4128 (/tmp/tmp05i77mjl/scipy-1.3.1/build/src.linux-x86_64-3.8/scipy/fftpack/_fftpackmodule.c:4128)
>>>               lto.tmp:(PyInit__fftpack)

ld.lld: error: undefined symbol: PyBytes_FromString
>>> referenced by _fftpackmodule.c:4129 (/tmp/tmp05i77mjl/scipy-1.3.1/build/src.linux-x86_64-3.8/scipy/fftpack/_fftpackmodule.c:4129)
>>>               lto.tmp:(PyInit__fftpack)

ld.lld: error: undefined symbol: PyDict_SetItemString
>>> referenced by _fftpackmodule.c:4130 (/tmp/tmp05i77mjl/scipy-1.3.1/build/src.linux-x86_64-3.8/scipy/fftpack/_fftpackmodule.c:4130)
>>>               lto.tmp:(PyInit__fftpack)
>>> referenced by _fftpackmodule.c:4178 (/tmp/tmp05i77mjl/scipy-1.3.1/build/src.linux-x86_64-3.8/scipy/fftpack/_fftpackmodule.c:4178)
>>>               lto.tmp:(PyInit__fftpack)
>>> referenced by _fftpackmodule.c:4182 (/tmp/tmp05i77mjl/scipy-1.3.1/build/src.linux-x86_64-3.8/scipy/fftpack/_fftpackmodule.c:4182)
>>>               lto.tmp:(PyInit__fftpack)
>>> referenced 5 more times

ld.lld: error: undefined symbol: PyUnicode_FromString
>>> referenced by _fftpackmodule.c:4132 (/tmp/tmp05i77mjl/scipy-1.3.1/build/src.linux-x86_64-3.8/scipy/fftpack/_fftpackmodule.c:4132)
>>>               lto.tmp:(PyInit__fftpack)
>>> referenced by fortranobject.c:290 (/tmp/tmp05i77mjl/scipy-1.3.1/build/src.linux-x86_64-3.8/build/src.linux-x86_64-3.8/scipy/fftpack/fortranobject.c:290)
>>>               lto.tmp:(fortran_getattr)
>>> referenced by fortranobject.c:316 (/tmp/tmp05i77mjl/scipy-1.3.1/build/src.linux-x86_64-3.8/build/src.linux-x86_64-3.8/scipy/fftpack/fortranobject.c:316)
>>>               lto.tmp:(fortran_getattr)
>>> referenced 1 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/build/src.linux-x86_64-3.8/scipy/fftpack/_fftpackmodule.o build/temp.linux-x86_64-3.8/scipy/fftpack/src/zfft.o build/temp.linux-x86_64-3.8/scipy/fftpack/src/drfft.o build/temp.linux-x86_64-3.8/scipy/fftpack/src/zrfft.o build/temp.linux-x86_64-3.8/scipy/fftpack/src/zfftnd.o build/temp.linux-x86_64-3.8/build/src.linux-x86_64-3.8/scipy/fftpack/src/dct.o build/temp.linux-x86_64-3.8/build/src.linux-x86_64-3.8/scipy/fftpack/src/dst.o build/temp.linux-x86_64-3.8/build/src.linux-x86_64-3.8/build/src.linux-x86_64-3.8/scipy/fftpack/fortranobject.o -L/usr/lib/gcc/x86_64-pc-linux-gnu/13.2.1/../../../../lib -L/usr/lib/gcc/x86_64-pc-linux-gnu/13.2.1/../../../../lib -Lbuild/temp.linux-x86_64-3.8 -ldfftpack -lfftpack -lgfortran -o build/lib.linux-x86_64-3.8/scipy/fftpack/_fftpack.graalpy-38-native-x86_64-linux.so" failed with exit status 1
msimacek commented 1 year ago

Scipy is always problematic because of the fortran parts. We were able to build it on Centos 8 and LTS Ubuntu, but not on Fedora 37, it seems the fortran compiler there is too new. One would think that a language from the 50's would maintain backwards compatibility between recent versions by now, but apparently no. What is you gfortran version? Could you please try if it builds on CPython with pip install --no-binary :all: scipy==1.10.1?

msimacek commented 1 year ago

Oh, you didn't mention your GraalPy version. Please use at least 23.0. Older versions were using LLVM and that didn't play well with fortran at all. Newer versions use the system toolchain (gcc, gfortran).

manticore-projects commented 1 year ago

Greetings!

Thank you for responding, I do appreciate.

a) I can use any Fortran Compiler you'd like although the only relevant change between 9 and 13 is about the -fallow-argument-mismatch. Which version is preferred please?

Btw, documentation about the reference would be great. We do understand that this is highly experimental and fragile stuff, no problem. But a reference, what has been working exactly would help a lot.

b) I test JDK 11, JDK 17 and JDK 20 in parallel. I would have tested GraalPy 23 on JDK 17, when I was able to compile Numpy. But for whatever reason, I fail with Numpy on JDK17/20 and so there is no Scipy.

I will try to work though the rest of your recommendations. Thanks again!

msimacek commented 1 year ago

The fortran compiler that works for us in our testing infrastructure is:

$ gfortran --version
GNU Fortran (GCC) 8.5.0 20210514 (Red Hat 8.5.0-18.0.2)
manticore-projects commented 1 year ago

Thank you big time! I will try with that!

manticore-projects commented 1 year ago

There seems to be some progress:

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

keeps compiling for more than 1 hour now and using up to 12GB ram. Lets see if it will produce something eventually.

msimacek commented 1 year ago

Did it work after all?

manticore-projects commented 1 year ago

Greetings!

No, unfortunately not: The long compiling time was on Meson in combination with the --no-binary :all:. After it, PIP complains that Cython can't compile, but deletes immediately the error messages and log files (despite the --no-clean flag, the Python tool-chain is just hilarious from a Java programmer's point of view).

I guess we still can close this since the key requirement is to use a GCC suite before 13 (maybe 9 or 8). Rest seems to be a lot of experimenting and time.

Thanks for your help though.