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

Build failed on MacBook Pro M1 #580

Closed
harisalam opened this issue Oct 14, 2022 · 21 comments
Closed

Build failed on MacBook Pro M1 #580

harisalam opened this issue Oct 14, 2022 · 21 comments
Labels
macos question Further information is requested

Comments

@harisalam
Copy link

harisalam commented Oct 14, 2022

Updated:
Please follow this to build k-NN in M1 for now to unblock yourself. Better process should be implemented still.

OpenSearch 3.0.0 distribution for mac does not exist in the public url. You can lower the version of k-NN to 2.3.0 which will use OpenSearch 2.3.0 release. Or, you can build your own OpenSearch distribution and use it as follow.

  1. Fork the OpenSearch Repo into your github account.
  2. Checkout the OpenSearch Repo in your laptop using right github commands.
  3. Run the below commands, as provided in the repo.
    $> cd OpenSearch && ./gradlew assemble && ./gradlew localDistro
  4. You should see a opensearch-min-3.0.0-SNAPSHOT-darwin-x64.tar.gz file present in distribution/archives/darwin-tar/build/distributions/
  5. Build k-NN by passing the OpenSearch distribution path in $> ./gradlew <integTest/run> -PcustomDistributionUrl="<Full path to .tar.gz file you noted above>"

With default setting of Make file I was getting the following error:
clang: error: the clang compiler does not support '-march=native'
Then someone from the community also experience an issue with this and solution was provided by changing -march=native to -mcpu=apple-a14, but that landed me on another issue which is omp.h not found. After researching for quite a long time I found out this error is caused of clang incompatibility on apple-m1.

Task :buildJniLib FAILED
Consolidate compiler generated dependencies of target NonMetricSpaceLib
[ 88%] Built target NonMetricSpaceLib
Consolidate compiler generated dependencies of target opensearchknn_common
[ 94%] Built target opensearchknn_common
Consolidate compiler generated dependencies of target opensearchknn_nmslib
[100%] Built target opensearchknn_nmslib
[ 2%] Building CXX object external/faiss/faiss/CMakeFiles/faiss.dir/AutoTune.cpp.o
In file included from /Users/harisalam/Documents/k-NN/jni/external/faiss/faiss/AutoTune.cpp:34:
In file included from /Users/harisalam/Documents/k-NN/jni/external/faiss/faiss/IndexHNSW.h:14:
/Users/harisalam/Documents/k-NN/jni/external/faiss/faiss/impl/HNSW.h:16:10: fatal error: 'omp.h' file not found
#include <omp.h>
^~~~~~~
1 error generated.
make[3]: *** [external/faiss/faiss/CMakeFiles/faiss.dir/AutoTune.cpp.o] Error 1
make[2]: *** [external/faiss/faiss/CMakeFiles/faiss.dir/all] Error 2
make[1]: *** [CMakeFiles/opensearchknn_faiss.dir/rule] Error 2
make: *** [opensearchknn_faiss] Error 2

FAILURE: Build failed with an exception.

  • What went wrong:
    Execution failed for task ':buildJniLib'.

Process 'command 'make'' finished with non-zero exit value 2

@nknize
Copy link

nknize commented Oct 17, 2022

I don't have a M1 or even a Mac to try this out so I'm largely probing here. You may have already tried this, but did you try the /opt/homebrew bundled clang which looks to support the M1 as of 3.0.0? The M1 discussion is in a few different repos (here's a good entry point) so maybe someone there can also help move this forward? @bbarani @dblock? Also /cc @jmazanec15 @martin-gaievski, has anyone on K-nn successfully built the native faiss library on the M1? Looks like apple's clang gives issues but bundled homebrew clang might work?

@nknize nknize added bug Something isn't working help wanted Extra attention is needed macos labels Oct 17, 2022
@martin-gaievski
Copy link
Member

martin-gaievski commented Oct 17, 2022

I think @heemin32 was facing issues with build on m1

@heemin32
Copy link
Collaborator

I think @heemin32 was facing issues with build on m1

I haven't tried to build k-NN. I was having issue with running bwc integTest of OpenSearch.

@jmazanec15
Copy link
Member

@harisalam I dont have M1 mac, but Ill see if I can get access to one.

Have you tried:

brew install gcc

you might be able to get passed omp failure this way, because gcc toolchain will ship an implementation of omp. This works for me on mac x86 - not sure if itll work on M1.

@heemin32
Copy link
Collaborator

After changing -march=native to -mcpu=apple-m1, I see following error.

/Users/heemin/workplace/OS/k-NN/jni/external/nmslib/similarity_search/src/distcomp_scalar.cc:85:9: error: pragma message requires parenthesized string
#pragma message WARN("ScalarProductSIMD<float>: SSE2 is not available, defaulting to pure C++ implementation!")

@harisalam
Copy link
Author

@harisalam I dont have M1 mac, but Ill see if I can get access to one.

Have you tried:

brew install gcc

you might be able to get passed omp failure this way, because gcc toolchain will ship an implementation of omp. This works for me on mac x86 - not sure if itll work on M1.

@jmazanec15 I have tried that but still its wasn't able to find omp.h library, then I figured that out by manually passing the location of omp.h library in libomp directory. After that I landed on another error which was related to clang "ld: symbol(s) not found for architecture arm64".

@harisalam
Copy link
Author

After changing -march=native to -mcpu=apple-m1, I see following error.

/Users/heemin/workplace/OS/k-NN/jni/external/nmslib/similarity_search/src/distcomp_scalar.cc:85:9: error: pragma message requires parenthesized string
#pragma message WARN("ScalarProductSIMD<float>: SSE2 is not available, defaulting to pure C++ implementation!")

@heemin32 the solution for that scenario was to comment out pragma errors in CMakeList file. But still it could build the project successfully

@harisalam
Copy link
Author

I don't have a M1 or even a Mac to try this out so I'm largely probing here. You may have already tried this, but did you try the /opt/homebrew bundled clang which looks to support the M1 as of 3.0.0? The M1 discussion is in a few different repos (here's a good entry point) so maybe someone there can also help move this forward? @bbarani @dblock? Also /cc @jmazanec15 @martin-gaievski, has anyone on K-nn successfully built the native faiss library on the M1? Looks like apple's clang gives issues but bundled homebrew clang might work?

@nknize I have also tried that by following the developer guide, but it wasn't successfully building for the following reasons:

  1. march=native error
  2. omp.h not found
  3. clang error "ld: symbol(s) not found for architecture arm64"

@harisalam
Copy link
Author

  1. March native error was addressed by making changes to the CMake file by simply changing -march=native to -mcpu=apple-a14
  2. omp.h was addressed by specifying the location to omp.h file on the local drive
  3. Have no idea how to deal with clang error; this error is most probably for one specific reason which is the system tries to execute .cpp file using clang however clang++ needs to used for execution or compilation.

@heemin32
Copy link
Collaborator

heemin32 commented Oct 20, 2022

I also got stuck with the clang error ld: symbol(s) not found for architecture arm64 but @jmazanec15 helped me out here. Thanks @jmazanec15

// Go to jni folder
cd k-NN/jni

// File changes required
sed -i -e 's/\/usr\/local\/opt\/libomp\//\/opt\/homebrew\/opt\/llvm\//g' CMakeLists.txt
sed -i -e 's/-march=native/-mcpu=apple-m1/g' external/nmslib/similarity_search/CMakeLists.txt
sed -i -e 's/pragma message WARN/pragma message /g' external/nmslib/similarity_search/src/distcomp_scalar.cc
sed -i -e 's/-mcpu=apple-a14/-mcpu=apple-m1/g' external/nmslib/python_bindings/setup.py
sed -i -e 's/__aarch64__/__undefine_aarch64__/g' external/faiss/faiss/utils/distances_simd.cpp

// Install llvm
brew install llvm
echo 'export PATH="/opt/homebrew/opt/llvm/bin:$PATH"' >> ~/.zshrc
source ~/.zshrc

// Set compiler path for CMAKE
export CC=/opt/homebrew/opt/llvm/bin/clang
export CXX=/opt/homebrew/opt/llvm/bin/clang++

// Build
cmake . --fresh
make

@harisalam
Copy link
Author

@heemin32 With above changes to the files I have been able to override clang errors, however, build is continuously failing because the mentioned snapshots aren't accessible for some reason.

Screen Shot 2022-10-30 at 5 03 49 PM

@harisalam
Copy link
Author

@heemin32 @jmazanec15 When I try to access (https://artifacts.opensearch.org/snapshots/core/opensearch/3.0.0-SNAPSHOT/opensearch-min-3.0.0-SNAPSHOT-darwin-arm64-latest.tar.gz) using https it throws me an error "Access Denied". Are there any bugs in the new release which is causing this issue?
Screen Shot 2022-10-30 at 6 30 48 PM

@heemin32
Copy link
Collaborator

heemin32 commented Oct 31, 2022

OpenSearch 3.0.0 distribution for mac does not exist in the public url. You can lower the version of k-NN to 2.3.0 which will use OpenSearch 2.3.0 release. Or, you can build your own OpenSearch distribution and use it as follow.

  1. Fork the OpenSearch Repo into your github account.
  2. Checkout the OpenSearch Repo in your laptop using right github commands.
  3. Run the below commands, as provided in the repo.
    $> cd OpenSearch && ./gradlew assemble && ./gradlew localDistro
  4. You should see a opensearch-min-3.0.0-SNAPSHOT-darwin-x64.tar.gz file present in distribution/archives/darwin-tar/build/distributions/
  5. Build k-NN by passing the OpenSearch distribution path in $> ./gradlew <integTest/run> -PcustomDistributionUrl="<Full path to .tar.gz file you noted above>"

@harisalam Please kindly share if you are able to build k-NN in M1 processor after following the steps.

@navneet1v navneet1v added question Further information is requested and removed bug Something isn't working help wanted Extra attention is needed labels Mar 15, 2023
@navneet1v
Copy link
Collaborator

@heemin32 can you check if darwin arm64 snapshot is present or not?

@austintlee
Copy link

austintlee commented Aug 17, 2023

The workaround mentioned above works for me on the 2023 M2 Pro and I also had the issue with the missing darwin-arm64 on 'integTest' which was resolved using the customDistributionUrl trick. Thanks!

@austintlee
Copy link

I can build k-nn, but I can't install in in my local repo. I get this error:

Execution failed for task ':publishNebulaPublicationToMavenLocal'.
> Failed to publish publication 'nebula' to repository 'mavenLocal'
   > Invalid publication 'nebula': supplied groupId (org.opensearch) does not match value from POM file (org.opensearch.plugin). Cannot edit groupId directly in the POM file.

@TrungBui59
Copy link

Hi everyone, how can you guys fix this issue? I followed the instructions by @heemin32 but found the issue of cannot find omp.h:

/Users/trungbui/k-NN/jni/external/faiss/faiss/impl/HNSW.h:16:10: fatal error: 'omp.h' file not found
#include <omp.h>

@navneet1v
Copy link
Collaborator

@ryanbogan can you help here.. you recently work on k-nn with M1 chip

@heemin32
Copy link
Collaborator

heemin32 commented Sep 27, 2023

@TrungBui59 Install clang using brew
Reference: https://stackoverflow.com/questions/71061894/how-to-install-openmp-on-mac-m1

/usr/bin/clang
$ brew install llvm
$ echo 'export PATH="/opt/homebrew/opt/llvm/bin:$PATH"' >> ~/.zshrc
$ source ~/.zshrc
$ which clang
opt/homebrew/opt/llvm/bin/clang
$ export CC=/opt/homebrew/opt/llvm/bin/clang
$ export CXX=/opt/homebrew/opt/llvm/bin/clang++
$ cmake . --fresh
$ make

@bbarani
Copy link
Member

bbarani commented Sep 29, 2023

You can download the Darwin snapshot 3.0.0 -min build of OpenSearch here @heemin32 @navneet1v

@heemin32
Copy link
Collaborator

Closing it in favor of #1302

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
macos question Further information is requested
Projects
None yet
Development

No branches or pull requests

9 participants