owl icon indicating copy to clipboard operation
owl copied to clipboard

Support Arm64 (and apple M1)

Open mseri opened this issue 2 years ago • 25 comments

Resubmitting as requested

to try this PR on mac use

opam pin -n git+https://github.com/mseri/owl.git#arm64 --with-version=1.1.0
PKG_CONFIG_PATH="/opt/homebrew/opt/openblas/lib/pkgconfig" opam install owl.1.1.0

mseri avatar Apr 14 '22 09:04 mseri

@jzstark can you test on both the mac and thinkpad. It seems I have some compilation issue on one of my thinkpads. I will also dig a bit deeper.

ryanrhymes avatar Apr 14 '22 13:04 ryanrhymes

I tried compiling the code with this PR on my Ubuntu 20.04 desktop, and there are indeed errors and warnings; the current master branch compile normally. Part of the log are pasted below.

File "src/owl/dune", line 56, characters 3-17:
56 |    owl_core_utils
        ^^^^^^^^^^^^^^
In file included from src/owl/core/owl_core.h:9,
                 from src/owl/core/owl_core_utils.c:6:
src/owl/core/owl_macros.h:90:6: error: #elif with no expression
src/owl/core/owl_core_utils.c:216:6: error: #elif with no expression
cc1: warning: unrecognized command line option ‘-Wno-logical-op-parentheses’
File "src/owl/dune", line 75, characters 3-22:
75 |    owl_fftpack_float32
        ^^^^^^^^^^^^^^^^^^^
In file included from src/owl/core/owl_core.h:9,
                 from src/owl/fftpack/owl_fftpack_float32.c:8:
src/owl/core/owl_macros.h:90:6: error: #elif with no expression
cc1: warning: unrecognized command line option ‘-Wno-logical-op-parentheses’
File "src/owl/dune", line 76, characters 3-22:
76 |    owl_fftpack_float64
        ^^^^^^^^^^^^^^^^^^^
In file included from src/owl/core/owl_core.h:9,
                 from src/owl/fftpack/owl_fftpack_float64.c:8:
src/owl/core/owl_macros.h:90:6: error: #elif with no expression
cc1: warning: unrecognized command line option ‘-Wno-logical-op-parentheses’
File "src/owl/dune", line 61, characters 3-28:
61 |    owl_ndarray_contract_stub
        ^^^^^^^^^^^^^^^^^^^^^^^^^
In file included from src/owl/core/owl_core.h:9,
                 from src/owl/core/owl_ndarray_contract_stub.c:6:
src/owl/core/owl_macros.h:90:6: error: #elif with no expression
cc1: warning: unrecognized command line option ‘-Wno-logical-op-parentheses’
File "src/owl/dune", line 59, characters 3-24:
59 |    owl_matrix_check_stub
        ^^^^^^^^^^^^^^^^^^^^^
In file included from src/owl/core/owl_core.h:9,
                 from src/owl/core/owl_matrix_check_stub.c:6:
src/owl/core/owl_macros.h:90:6: error: #elif with no expression
cc1: warning: unrecognized command line option ‘-Wno-logical-op-parentheses’
File "src/owl/dune", line 60, characters 3-23:
60 |    owl_matrix_swap_stub
        ^^^^^^^^^^^^^^^^^^^^
...

jzstark avatar Apr 14 '22 13:04 jzstark

I tried compiling the code with this PR on my Ubuntu 20.04 desktop, and there are indeed errors and warnings; the current master branch compile normally. Part of the log are pasted below.

File "src/owl/dune", line 56, characters 3-17:
56 |    owl_core_utils
        ^^^^^^^^^^^^^^
In file included from src/owl/core/owl_core.h:9,
                 from src/owl/core/owl_core_utils.c:6:
src/owl/core/owl_macros.h:90:6: error: #elif with no expression
src/owl/core/owl_core_utils.c:216:6: error: #elif with no expression
cc1: warning: unrecognized command line option ‘-Wno-logical-op-parentheses’
File "src/owl/dune", line 75, characters 3-22:
75 |    owl_fftpack_float32
        ^^^^^^^^^^^^^^^^^^^
In file included from src/owl/core/owl_core.h:9,
                 from src/owl/fftpack/owl_fftpack_float32.c:8:
src/owl/core/owl_macros.h:90:6: error: #elif with no expression
cc1: warning: unrecognized command line option ‘-Wno-logical-op-parentheses’
File "src/owl/dune", line 76, characters 3-22:
76 |    owl_fftpack_float64
        ^^^^^^^^^^^^^^^^^^^
In file included from src/owl/core/owl_core.h:9,
                 from src/owl/fftpack/owl_fftpack_float64.c:8:
src/owl/core/owl_macros.h:90:6: error: #elif with no expression
cc1: warning: unrecognized command line option ‘-Wno-logical-op-parentheses’
File "src/owl/dune", line 61, characters 3-28:
61 |    owl_ndarray_contract_stub
        ^^^^^^^^^^^^^^^^^^^^^^^^^
In file included from src/owl/core/owl_core.h:9,
                 from src/owl/core/owl_ndarray_contract_stub.c:6:
src/owl/core/owl_macros.h:90:6: error: #elif with no expression
cc1: warning: unrecognized command line option ‘-Wno-logical-op-parentheses’
File "src/owl/dune", line 59, characters 3-24:
59 |    owl_matrix_check_stub
        ^^^^^^^^^^^^^^^^^^^^^
In file included from src/owl/core/owl_core.h:9,
                 from src/owl/core/owl_matrix_check_stub.c:6:
src/owl/core/owl_macros.h:90:6: error: #elif with no expression
cc1: warning: unrecognized command line option ‘-Wno-logical-op-parentheses’
File "src/owl/dune", line 60, characters 3-23:
60 |    owl_matrix_swap_stub
        ^^^^^^^^^^^^^^^^^^^^
...

Thanks to confirm, I saw the same error. Removing that option fixed some errors but there are still some other errors. Probably the main issue is using different version of OCaml. I will try to switch to another version later.

ryanrhymes avatar Apr 14 '22 13:04 ryanrhymes

Super. I guess it depends on the compiler used. Does this new commit fix it?

mseri avatar Apr 14 '22 13:04 mseri

Where does -Wno-logical-op-parentheses come from? I did not add that anywhere

mseri avatar Apr 14 '22 13:04 mseri

This fixes a lot of warnings, but the error is still there. (I use OCaml 4.14 and dune 3.0.3.)

dune build @install
File "src/owl/dune", line 56, characters 3-17:
56 |    owl_core_utils
        ^^^^^^^^^^^^^^
src/owl/core/owl_core_utils.c:216:6: error: #elif with no expression
cc1: warning: unrecognized command line option ‘-Wno-logical-op-parentheses’
make: *** [Makefile:9: build] Error 1   

jzstark avatar Apr 14 '22 13:04 jzstark

-Wno-logical-op-parentheses

From here https://github.com/owlbarn/owl/blob/eead31f1920e63b876421e6a30e61c947f29827f/src/owl/config/configure.ml#L115

Actually, we can simply remove get_devmode_cflags, and move [ "-Wall"; "-pedantic"; "-Wextra"; "-Wunused" ] to https://github.com/owlbarn/owl/blob/eead31f1920e63b876421e6a30e61c947f29827f/src/owl/config/configure.ml#L253

ryanrhymes avatar Apr 14 '22 13:04 ryanrhymes

I'll make the change, but that line is there from before my PR. It is strange that it fails now and was not failing before. It would be interesting to understand why

mseri avatar Apr 14 '22 20:04 mseri

At some point we should probably get rid of (or rewrite) default_gcc_path (outdated in most systems) and openblas_default (can mix up x86_64 and arm64 libraries on mac for people using homebrew, which uses the old path for x86_64 and a new one, I think /opt/local, for arm64 libraries)

mseri avatar Apr 15 '22 07:04 mseri

I have created the parent PR on eigen, with these the build should work fine on both M1 and x86_64. I am still having some linking issues with eigen since the last macos update.

mseri avatar Apr 28 '22 20:04 mseri

I can no-longer test this, eigen fails to build for me with the lastest macos compiler upgrade

mseri avatar Apr 29 '22 07:04 mseri

Update: I have made a new PR to update the current eigen.0.3.0 build (not using recent dune features which seem to produce linking errors) and backported a fix from eigen to build on clang 3.9. The new PR is here: https://github.com/owlbarn/eigen/pull/36 With that one I seem to be able to use eigen and owl on both macos x86_64 and macos M1

mseri avatar May 02 '22 08:05 mseri

Any update regarding this PR? Now a number of users is using it without problems

mseri avatar May 11 '22 13:05 mseri

It should also fix the linking on debian system which was broken in 1.0.2 in some cases

mseri avatar May 11 '22 14:05 mseri

Any news on this? I have been using it fine on various different mac and linux intel and mac ARM cpus for weeks

mseri avatar Aug 17 '22 09:08 mseri

opam pin -n git+https://github.com/mseri/owl.git#arm64 --with-version=1.1.0 PKG_CONFIG_PATH="/opt/homebrew/opt/openblas/lib/pkgconfig" opam install owl.1.1.0

This worked for me on a new M1 mac

tachukao avatar Aug 18 '22 16:08 tachukao

I can confirm that this works perfectly well with my M1 Mac on macOS Monterey.

Zeta611 avatar Sep 06 '22 13:09 Zeta611

I've got:

# (cd _build/default && /Users/thomas/git/hdf5-ocaml/_opam/bin/ocamlmklib.opt -g -o src/owl/owl_stubs src/owl/SFMT.o src/owl/airy.o src/owl/airyf.o src/owl/bdtr.o src/owl/beta.o src/owl/btdtr.o src/owl/cbrt.o src/owl/chbevl.o src/owl/chbevlf.o src/owl/chdtr.o src/owl/const.o src/owl/constf.o src/owl/dawsn.o src/owl/dawsnf.o src/owl/ellie.o src/owl/ellik.o src/owl/ellpe.o src/owl/ellpj.o src/owl[...]
# ld: file not found: @rpath/libquadmath.0.dylib for architecture arm64

samoht avatar Oct 02 '22 14:10 samoht

Something is off with homebrew. For a similar issue with libgcc one needs to manually fix some paths or create special symlinks

mseri avatar Oct 02 '22 14:10 mseri

On my Intel mac the installation procedure in the top post is not working. macos 12.6.2. my homebrew installation of openblas says

For compilers to find openblas you may need to set:
  export LDFLAGS="-L/usr/local/opt/openblas/lib"
  export CPPFLAGS="-I/usr/local/opt/openblas/include"

For pkg-config to find openblas you may need to set:
  export PKG_CONFIG_PATH="/usr/local/opt/openblas/lib/pkgconfig"

so the path is a different one. also, my gfortran libquadmath is in /usr/local/gfortran/lib

nilsbecker avatar Jan 25 '23 09:01 nilsbecker

Needless to say, the current opam version of owl is also not building.

nilsbecker avatar Jan 25 '23 09:01 nilsbecker

This is still failing for me with:

   > clang-11: error: the clang compiler does not support '-mcpu=apple-m1'

anmonteiro avatar Oct 31 '23 21:10 anmonteiro

Try now: -march=native is supported on mac arm for recent enough macos, I modified the code to use that

mseri avatar Oct 31 '23 21:10 mseri

Thank you, it does work now.

anmonteiro avatar Oct 31 '23 22:10 anmonteiro

Running this on an M3 macOS Sonoma 14.2.1 I get this error:

File "_none_", line 1:             
Error: No implementations provided for the following modules:
         Unix referenced from /Users/tsmc/code/ocaml/par-matmul-profiling/_opam/lib/owl-base/owl_base.cmxa(Owl_utils),
           /Users/tsmc/code/ocaml/par-matmul-profiling/_opam/lib/owl-base/owl_base.cmxa(Owl_log),
           /Users/tsmc/code/ocaml/par-matmul-profiling/_opam/lib/owl-base/owl_base.cmxa(Owl_io)

Test case setting up https://github.com/ghennequin/par-matmul-profiling. If you rebase including commits from https://github.com/owlbarn/owl/pull/630 then it works well. To test try using:

opam pin -n git+https://github.com/tmcgilchrist/owl.git#arm64 --with-version=1.1.0
PKG_CONFIG_PATH="/opt/homebrew/opt/openblas/lib/pkgconfig" opam install owl.1.1.0

What is required to get this merged and a release of Owl for MacOS/ARM64 onto opam?

tmcgilchrist avatar Jan 15 '24 02:01 tmcgilchrist

I have merged main to fix the merge conflicts

mseri avatar Mar 05 '24 11:03 mseri

@jzstark any progress on getting ARM64 support merged?

tmcgilchrist avatar Apr 15 '24 07:04 tmcgilchrist

This would be a good sign that owl is indeed being actively maintained, now that the project conclusion was reverted.

nilsbecker avatar Apr 15 '24 09:04 nilsbecker