Closed raoulalwani closed 2 years ago
Hey @raoulalwani, can you paste the output of g++ --version
and clang --version
?
@ankane thanks for the quick reply.
$ g++ --version
Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/include/c++/4.2.1
Apple clang version 12.0.0 (clang-1200.0.32.27)
Target: x86_64-apple-darwin19.6.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
$ clang --version
Apple clang version 12.0.0 (clang-1200.0.32.27)
Target: x86_64-apple-darwin19.6.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
I also checked my libtorch with brew info libtorch
:
libtorch: stable 1.5.0 (bottled)
Tensors and dynamic neural networks
https://pytorch.org/
/usr/local/Cellar/libtorch/1.5.0_1 (2,965 files, 102.2MB) *
Built from source on 2021-08-01 at 19:13:55
From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/libtorch.rb
It says 1.5.0 but in #22 there was a discussion about it being in version 1.8.1? I ran brew upgrade libtorch
but got this:
Warning: libtorch 1.5.0_1 already installed
Thanks @raoulalwani. Unfortunately, I'm not sure how to reproduce. Apple Clang should support OpenMP with the -Xclang
flag. https://github.com/ankane/torch.rb/blob/d851e888b2a4ffb9f0cd4a7b2da89a1941103084/ext/torch/extconf.rb#L11-L14
Repro commands - https://github.com/ankane/torch.rb/blob/5a8f8a33e77fbeb43990e5ab9263d071037281f6/.github/workflows/build.yml CI result - https://github.com/ankane/torch.rb/runs/3225038756?check_suite_focus=true
For LibTorch, you want to use the latest version (1.9.0 at the moment). Try running brew update
before brew upgrade libtorch
, or download it from https://pytorch.org/.
Thanks @ankane - no worries, will try on my Linux machine this weekend. Will reopen or recomment if I can figure it out for OSX.
Hi @ankane just re-opening this, finally had some time to try this out again.
Stil getting the same error:
$ gem install torch-rb
compiling backends.cpp
clang: error: unsupported option '-fopenmp'
I'm using libtorch 1.9.0, I have libomp
, I also installed llvm
, and so the outputs for g++ --version
and clang --version
are:
$ g++ --version
Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/include/c++/4.2.1
Apple clang version 12.0.0 (clang-1200.0.32.27)
Target: x86_64-apple-darwin19.6.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
$ clang --version
Homebrew clang version 12.0.1
Target: x86_64-apple-darwin19.6.0
Thread model: posix
InstalledDir: /usr/local/opt/llvm/bin
Inspecting the Makefile after the error stops the install:
Line 68: CXX = g++
Line 90: CXXFLAGS = $(CCDLFLAGS) $(cxxflags) -Wno-register -std=c++17 -std=c++17 $(optflags) -D_GLIBCXX_USE_CXX11_ABI=1 -fopenmp -Wno-noexcept-type -Wno-duplicated-cond -Wno-suggest-attribute=noreturn $(ARCH_FLAG)
So the -Xclang
flag is not getting added to the Makefile. Modifying the Makefile to either include the -Xclang
flag, or changing CXX = clang
to use the Homebrew llvm and running make
throws a lot of errors (eg: fft_functions.cpp:321:51: error: no viable conversion from 'optional<c10::string_view>' to 'optional<std::string>')
so that hasn't worked either.
I have Pytorch working fine with Python, so I can do import torch
in Python scripts and use it, but would much prefer exploring it in Ruby instead. Just sharing the above in case anyone has thoughts on how to get it working.
Hey @raoulalwani, with the latest version of the gem, you'll need LibTorch 1.10.0 or 1.10.1 (see compatibility table). Also, llvm
shouldn't be needed.
For the -Xclang
issue, what does the following command output?
ruby -v
gem -v
ruby -e 'puts RbConfig::CONFIG["CC_VERSION_MESSAGE"]'
Hi @ankane, thanks for the quick reply. Got it on the gem/libtorch versions. Re: the command outputs:
$ ruby -v
ruby 2.6.6p146 (2020-03-31 revision 67876) [x86_64-darwin15]
$ gem -v
3.0.8
$ ruby -e 'puts RbConfig::CONFIG["CC_VERSION_MESSAGE"]'
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 7.0.0 (clang-700.0.72)
Target: x86_64-apple-darwin15.3.0
Thread model: posix
Seems like it's pointing at a super old version of clang? I ran rvm get stable --auto-dotfiles
but that isn't updating the RBConfig.
Is there another way to build the gem from source? This issue def seems related to something in my machine, not in the gem itself.
It looks like your Ruby installation was compiled on darwin15
(El Capitan). I'd try creating a fresh installation of Ruby with rvm install 2.6.9
(alternatively, you could do rvm remove 2.6.6 && rvm install 2.6.6
).
@ankane thanks - it was indeed the Ruby issue on my machine (restoring an old laptop to a new one using Time Machine).
For anyone else potentially in the same spot: a fresh install of Ruby did the trick, so the output was as follows:
$ ruby -e 'puts RbConfig::CONFIG["CC_VERSION_MESSAGE"]'
Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/include/c++/4.2.1
Apple clang version 12.0.0 (clang-1200.0.32.27)
Target: x86_64-apple-darwin19.6.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
The errors I encountered above when running make
were because of the incompatible gem/libtorch versions, so since I am still on libtorch 1.9.0, I just did gem install torch-rb -v 0.8.3
(latest compatible gem version with my libtorch version) and everything is working nicely.
Thanks for the nice library!
Great, glad it's working.
Thanks for this nice library. When installing on OSX Catalina 10.15.6, I get the following error:
libtorch
was installed successfully via homebrew. Some quick googling showed this: https://stackoverflow.com/questions/43555410/enable-openmp-support-in-clang-in-mac-os-x-sierra-mojave but I'm hesitant tobrew install llvm
becausebrew info llvm
gives the following warning: "because macOS already provides this software and installing another version in parallel can cause all kinds of trouble."I already have
libomp
installed via brew earlier.