mmottl / gsl-ocaml

OCaml bindings to the GSL (GNU Scientific Library).
Other
36 stars 10 forks source link

Error building on Raspi #30

Closed haochenx closed 9 months ago

haochenx commented 3 years ago

I tried to install the gsl package via opam on Raspi 4b, and was getting the following error. do you think this could be easily fixed?

I have been successfully install and use the gsl package on other arm devices (including the Xilinx ZCU104, NVidia Jetson nano, and a few Android devices)

<><> Processing actions <><><><><><><><><><><><><><><><><><><><><><><><><><><><>
[ERROR] The compilation of gsl failed at "/home/pi/.opam/opam-init/hooks/sandbox.sh build dune
        build -p gsl -j 3".

#=== ERROR while compiling gsl.1.24.3 =========================================#
# context     2.0.8 | linux/arm32 | ocaml-base-compiler.4.09.1 | https://opam.ocaml.org#211fd895
# path        ~/.opam/4.09.1/.opam-switch/build/gsl.1.24.3
# command     ~/.opam/opam-init/hooks/sandbox.sh build dune build -p gsl -j 3
# exit-code   1
# env-file    ~/.opam/log/gsl-22056-a71bb4.env
# output-file ~/.opam/log/gsl-22056-a71bb4.out
### output ###
# In file included from mlgsl_vector_float.h:1,
# [...]
# wrappers.h:13:2: error: #error "Architectures with double-word alignment for doubles are not supported"
#  #error "Architectures with double-word alignment for doubles are not supported"
#   ^~~~~
#          gcc src/mlgsl_wavelet.o (exit 1)
# (cd _build/default/src && /usr/bin/gcc -O2 -fno-strict-aliasing -fwrapv -fPIC -D_FILE_OFFSET_BITS=64 -D_REENTRANT -O2 -fno-strict-aliasing -fwrapv -fPIC -fPIC -DPIC -Wno-unused-parameter -g -I /home/pi/.opam/4.09.1/lib/ocaml -o mlgsl_wavelet.o -c mlgsl_wavelet.c)
# In file included from mlgsl_matrix.h:9,
#                  from mlgsl_matrix_double.h:11,
#                  from mlgsl_wavelet.c:13:
# wrappers.h:13:2: error: #error "Architectures with double-word alignment for doubles are not supported"
#  #error "Architectures with double-word alignment for doubles are not supported"
#   ^~~~~

<><> Error report <><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
┌─ The following actions failed
│ λ build gsl 1.24.3
└─
╶─ No changes have been performed

System info:

# uname -a
Linux raspi 5.4.79-v7l+ #4 SMP Thu Dec 10 10:08:29 CST 2020 armv7l GNU/Linux

# cat /etc/os-release
PRETTY_NAME="Raspbian GNU/Linux 10 (buster)"
NAME="Raspbian GNU/Linux"
VERSION_ID="10"
VERSION="10 (buster)"
VERSION_CODENAME=buster
ID=raspbian
ID_LIKE=debian
HOME_URL="http://www.raspbian.org/"
SUPPORT_URL="http://www.raspbian.org/RaspbianForums"
BUG_REPORT_URL="http://www.raspbian.org/RaspbianBugs"

and ocaml version is 4.09.1

haochenx commented 3 years ago

one thing I just realized is that the arm hardware that worked with gsl were all running 64bit linux (where uname -a reports the CPU architecture being aarch64) but the raspbian that failed to install gsl is a 32bit linux (where uname -a reports armv7l)

mmottl commented 3 years ago

I assume your platform (processor) will signal alignment exceptions when trying to access doubles that are not aligned with double word boundaries. The initial author of the GSL-bindings may have made the assumption that e.g. OCaml float arrays are always properly aligned and may hence be passed directly to GSL. But this is not the case on your platform.

GSL is a fairly large library so I suspect that there are many instances in the bindings where such a problem can arise. The solution would be to copy the double array into an aligned memory region before passing it to GSL or other functions within the bindings. It might be even more future-proof to use the recently introduced OCaml floatarray type, but this would change the API and potentially break a lot of code.

I'm afraid, I don't have the time to work on that though it will likely have to happen eventually because of upcoming runtime changes required for OCaml multicore support. This is expected to end support for implicitly unboxed float arrays in the OCaml runtime.

haochenx commented 3 years ago

I see. So if I am understanding correctly it is fixable at the binding level but would require quite some work.

It seems that I could get around this by using a 64bit ubuntu installation on the raspi's for our current project. I may come back and attempt a fix if our project needs the 32bit Raspbian again.

Thanks for your time!

mmottl commented 3 years ago

Sounds good, please feel free to submit PRs for any changes. I'd recommend holding off for a while though, until multicore OCaml is at least in beta testing. It will be easier to see then what changes are required.

mmottl commented 9 months ago

Since OCaml 5.0.0 is out, this may be a good time to submit PRs if you have a fix for your problem!

haochenx commented 9 months ago

Thanks for the ping!

We decided to stick with 64bit os for our raspi project and didn't proceed to attempt a fix. (Also I think OCaml 5.0 has dropped tier 1 support for 32bit arm architectures..)

We may have future arm projects and will definitely give another try of this if we need to get it work on 32bit platforms.

mmottl commented 9 months ago

I'll close this issue, we can always open new one if necessary.