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

Support Arm64 (and apple M1) #609

Merged
merged 24 commits into from
May 1, 2024
Merged

Support Arm64 (and apple M1) #609

merged 24 commits into from
May 1, 2024

Conversation

mseri
Copy link
Member

@mseri mseri commented Apr 14, 2022

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

@ryanrhymes
Copy link
Member

@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.

@jzstark
Copy link
Collaborator

jzstark commented Apr 14, 2022

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
        ^^^^^^^^^^^^^^^^^^^^
...

@ryanrhymes
Copy link
Member

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.

@mseri
Copy link
Member Author

mseri commented Apr 14, 2022

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

@mseri
Copy link
Member Author

mseri commented Apr 14, 2022

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

@jzstark
Copy link
Collaborator

jzstark commented Apr 14, 2022

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   

@ryanrhymes
Copy link
Member

-Wno-logical-op-parentheses

From here

then [ "-Wno-logical-op-parentheses" ]

Actually, we can simply remove get_devmode_cflags, and move [ "-Wall"; "-pedantic"; "-Wextra"; "-Wunused" ] to

@mseri
Copy link
Member Author

mseri commented Apr 14, 2022

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

They break the compilation with some c compilers. See owlbarn#609

Signed-off-by: Marcello Seri <[email protected]>
@mseri
Copy link
Member Author

mseri commented Apr 15, 2022

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)

Signed-off-by: Marcello Seri <[email protected]>
@mseri
Copy link
Member Author

mseri commented Apr 28, 2022

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.

Signed-off-by: Marcello Seri <[email protected]>
@mseri
Copy link
Member Author

mseri commented Apr 29, 2022

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

@mseri
Copy link
Member Author

mseri commented May 2, 2022

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: owlbarn/eigen#36
With that one I seem to be able to use eigen and owl on both macos x86_64 and macos M1

Debian now ships lapacke separately, requiring new set of flags for the linking to work.
This uses pkg-config to improve the detection of these flags.

Furthermore this commit adds a workaround to solve the issue with libgcc11_s not found,
which will not be addressed upstream in homebrew for the time being.

Signed-off-by: Marcello Seri <[email protected]>
@mseri
Copy link
Member Author

mseri commented Aug 17, 2022

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

@tachukao
Copy link
Member

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

@Zeta611
Copy link

Zeta611 commented Sep 6, 2022

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

@samoht
Copy link
Contributor

samoht commented Oct 2, 2022

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

@mseri
Copy link
Member Author

mseri commented Oct 2, 2022

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

]
in
(* homebrew M1 issue workaround, works only if users use the default homebrew path *)
let libs =
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@samoht something like this one here

src/owl/config/configure.ml Outdated Show resolved Hide resolved
Co-authored-by: Thomas Gazagnaire <[email protected]>
@nilsbecker
Copy link
Contributor

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
Copy link
Contributor

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

@anmonteiro
Copy link

This is still failing for me with:

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

src/aeos/config/configure.ml Outdated Show resolved Hide resolved
src/owl/config/configure.ml Outdated Show resolved Hide resolved
@mseri
Copy link
Member Author

mseri commented Oct 31, 2023

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

@anmonteiro
Copy link

Thank you, it does work now.

@tmcgilchrist
Copy link

tmcgilchrist commented Jan 15, 2024

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 #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?

@mseri
Copy link
Member Author

mseri commented Mar 5, 2024

I have merged main to fix the merge conflicts

@tmcgilchrist
Copy link

@jzstark any progress on getting ARM64 support merged?

@nilsbecker
Copy link
Contributor

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

@jzstark jzstark merged commit 5d2f6d1 into owlbarn:main May 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants