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

Darwin caffe #44616

Merged
merged 6 commits into from Aug 16, 2018
Merged

Darwin caffe #44616

merged 6 commits into from Aug 16, 2018

Conversation

zimbatm
Copy link
Member

@zimbatm zimbatm commented Aug 7, 2018

Motivation for this change

Compile caffe on macOS. In the process I added a postInstallCheck to improve the chances that the package is working properly and made some more features configurable.

I had to poke bigger holes in the Darwin sandbox in the process.

Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nox --run "nox-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Determined the impact on package closure size (by running nix path-info -S before and after)
  • Fits CONTRIBUTING.md.

the sub-frameworks are not reacheable without that extension
@zimbatm zimbatm requested a review from LnL7 August 7, 2018 14:40
@GrahamcOfBorg GrahamcOfBorg added the 6.topic: darwin Running or building packages on Darwin label Aug 7, 2018
propagatedBuildInputs = [ Accelerate ];
} ''
mkdir -p $out/lib
ln -s /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib $out/lib/libblas.dylib
Copy link
Member

Choose a reason for hiding this comment

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

This should link to the Accelerate derivation, not /System.

Copy link
Member Author

Choose a reason for hiding this comment

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

How do you solve an empty ${Accelerate}/Library/Frameworks/Accelerate.framework/Versions/A ?

Copy link
Member

Choose a reason for hiding this comment

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

Yes that's right there are no libraries in that derivation. But this will break when we reintroduce sandboxing.

Have you tried to just use Openblas here? It should work on darwin.

Copy link
Member Author

Choose a reason for hiding this comment

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

It was using openblas but cmake decided to use Accelerate even when it's not provided. Maybe the best option is to patch the build system.

@GrahamcOfBorg
Copy link

Failure on x86_64-darwin (full log)

Attempted: caffe

Partial log (click to expand)

In file included from /nix/store/z12257cijwyrffn3v2r25zf75xrgdq4r-apple-framework-Accelerate/Library/Frameworks/Accelerate.framework/Frameworks/vImage.framework/Headers/vImage.h:200:
/nix/store/z12257cijwyrffn3v2r25zf75xrgdq4r-apple-framework-Accelerate/Library/Frameworks/Accelerate.framework/Frameworks/vImage.framework/Headers/vImage_Utilities.h:14:10: fatal error: 'CoreGraphics/CoreGraphics.h' file not found
#include <CoreGraphics/CoreGraphics.h>  /* #define vImage_Utilities_h 1 before including Accelerate headers to turn this header off */
         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.
make[2]: *** [src/caffe/CMakeFiles/caffe.dir/build.make:63: src/caffe/CMakeFiles/caffe.dir/blob.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:236: src/caffe/CMakeFiles/caffe.dir/all] Error 2
make: *** [Makefile:130: all] Error 2
builder for '/nix/store/0jn0jci3m71kx10xc2wvk2k23i0yfpv9-caffe-1.0.drv' failed with exit code 2
error: build of '/nix/store/0jn0jci3m71kx10xc2wvk2k23i0yfpv9-caffe-1.0.drv' failed

@GrahamcOfBorg
Copy link

Failure on x86_64-linux (full log)

Attempted: caffe

Partial log (click to expand)

I0807 15:29:14.026806  3273 caffe.cpp:313] Batch 22, prob = 0.000999551
I0807 15:29:14.026811  3273 caffe.cpp:313] Batch 22, prob = 0.000926105
I0807 15:29:14.026816  3273 caffe.cpp:313] Batch 22, prob = 0.000925103
I0807 15:29:14.026821  3273 caffe.cpp:313] Batch 22, prob = 0.00115865
I0807 15:29:14.026826  3273 caffe.cpp:313] Batch 22, prob = 0.00104339
I0807 15:29:14.026832  3273 caffe.cpp:313] Batch 22, prob = 0.00101693
I0807 15:29:14.026837  3273 caffe.cpp:313] Batch 22, prob = 0.00106999
I0807 15:29:14.026842  3273 caffe.cpp:313] Batch 22, prob = 0.00115552
building of '/nix/store/4ch8xcknhbmvvqp3fyx4wlgwwayq5ckv-caffe-1.0.drv' timed out after 1800 seconds
error: build of '/nix/store/4ch8xcknhbmvvqp3fyx4wlgwwayq5ckv-caffe-1.0.drv' failed

@zimbatm
Copy link
Member Author

zimbatm commented Aug 7, 2018

@GrahamcOfBorg build caffe

@GrahamcOfBorg
Copy link

Success on aarch64-linux (full log)

Attempted: caffe

Partial log (click to expand)

stripping (with command strip and flags -S) in /nix/store/ksaqp5yvqp0ybabwza5lsriab0lkzzvq-caffe-1.0-bin/bin
patching script interpreter paths in /nix/store/ksaqp5yvqp0ybabwza5lsriab0lkzzvq-caffe-1.0-bin
checking for references to /build in /nix/store/ksaqp5yvqp0ybabwza5lsriab0lkzzvq-caffe-1.0-bin...
shrinking RPATHs of ELF executables and libraries in /nix/store/wqcv7n03dk15gzvqk5ghj7229ac283i1-caffe-1.0
shrinking /nix/store/wqcv7n03dk15gzvqk5ghj7229ac283i1-caffe-1.0/lib/libcaffe.so.1.0.0
strip is /nix/store/zrs21zqcchgyabjf4xfimncdq16njizc-binutils-2.30/bin/strip
stripping (with command strip and flags -S) in /nix/store/wqcv7n03dk15gzvqk5ghj7229ac283i1-caffe-1.0/lib
patching script interpreter paths in /nix/store/wqcv7n03dk15gzvqk5ghj7229ac283i1-caffe-1.0
checking for references to /build in /nix/store/wqcv7n03dk15gzvqk5ghj7229ac283i1-caffe-1.0...
/nix/store/ksaqp5yvqp0ybabwza5lsriab0lkzzvq-caffe-1.0-bin

@GrahamcOfBorg
Copy link

Success on x86_64-darwin (full log)

Attempted: caffe

Partial log (click to expand)

/nix/store/578j47qdx858xikv4iipi2ahwqw03a02-caffe-1.0/lib/libcaffe.1.0.0.dylib: fixing dylib
/nix/store/578j47qdx858xikv4iipi2ahwqw03a02-caffe-1.0/lib/libcaffe.1.0.0.dylib: fixing dylib
/nix/store/578j47qdx858xikv4iipi2ahwqw03a02-caffe-1.0/lib/libcaffe.1.0.0.dylib: fixing dylib
/nix/store/578j47qdx858xikv4iipi2ahwqw03a02-caffe-1.0/lib/libcaffe.1.0.0.dylib: fixing dylib
/nix/store/578j47qdx858xikv4iipi2ahwqw03a02-caffe-1.0/lib/libcaffe.1.0.0.dylib: fixing dylib
/nix/store/578j47qdx858xikv4iipi2ahwqw03a02-caffe-1.0/lib/libcaffe.1.0.0.dylib: fixing dylib
/nix/store/578j47qdx858xikv4iipi2ahwqw03a02-caffe-1.0/lib/libcaffe.1.0.0.dylib: fixing dylib
/nix/store/578j47qdx858xikv4iipi2ahwqw03a02-caffe-1.0/lib/libcaffe.1.0.0.dylib: fixing dylib
/nix/store/578j47qdx858xikv4iipi2ahwqw03a02-caffe-1.0/lib/libcaffe.1.0.0.dylib: fixing dylib
/nix/store/qgj5spaqi0mahw28h9fnj95cx39gfkmi-caffe-1.0-bin

@GrahamcOfBorg
Copy link

Success on x86_64-linux (full log)

Attempted: caffe

Partial log (click to expand)

strip is /nix/store/1hi76hr87bd1y1q1qjk0lv8nmcjip1c8-binutils-2.30/bin/strip
stripping (with command strip and flags -S) in /nix/store/r72a55iw7i9npmzkvhwff7n7kx833yg5-caffe-1.0-bin/bin
patching script interpreter paths in /nix/store/r72a55iw7i9npmzkvhwff7n7kx833yg5-caffe-1.0-bin
checking for references to /build in /nix/store/r72a55iw7i9npmzkvhwff7n7kx833yg5-caffe-1.0-bin...
shrinking RPATHs of ELF executables and libraries in /nix/store/rmyyd9pcbchbyd7wi2nwfgmxqmiy1b81-caffe-1.0
shrinking /nix/store/rmyyd9pcbchbyd7wi2nwfgmxqmiy1b81-caffe-1.0/lib/libcaffe.so.1.0.0
strip is /nix/store/1hi76hr87bd1y1q1qjk0lv8nmcjip1c8-binutils-2.30/bin/strip
stripping (with command strip and flags -S) in /nix/store/rmyyd9pcbchbyd7wi2nwfgmxqmiy1b81-caffe-1.0/lib
patching script interpreter paths in /nix/store/rmyyd9pcbchbyd7wi2nwfgmxqmiy1b81-caffe-1.0
checking for references to /build in /nix/store/rmyyd9pcbchbyd7wi2nwfgmxqmiy1b81-caffe-1.0...

@GrahamcOfBorg
Copy link

Success on aarch64-linux (full log)

Attempted: caffe

Partial log (click to expand)

/nix/store/ksaqp5yvqp0ybabwza5lsriab0lkzzvq-caffe-1.0-bin

@GrahamcOfBorg
Copy link

Success on x86_64-linux (full log)

Attempted: caffe

Partial log (click to expand)

strip is /nix/store/1hi76hr87bd1y1q1qjk0lv8nmcjip1c8-binutils-2.30/bin/strip
stripping (with command strip and flags -S) in /nix/store/r72a55iw7i9npmzkvhwff7n7kx833yg5-caffe-1.0-bin/bin
patching script interpreter paths in /nix/store/r72a55iw7i9npmzkvhwff7n7kx833yg5-caffe-1.0-bin
checking for references to /build in /nix/store/r72a55iw7i9npmzkvhwff7n7kx833yg5-caffe-1.0-bin...
shrinking RPATHs of ELF executables and libraries in /nix/store/rmyyd9pcbchbyd7wi2nwfgmxqmiy1b81-caffe-1.0
shrinking /nix/store/rmyyd9pcbchbyd7wi2nwfgmxqmiy1b81-caffe-1.0/lib/libcaffe.so.1.0.0
strip is /nix/store/1hi76hr87bd1y1q1qjk0lv8nmcjip1c8-binutils-2.30/bin/strip
stripping (with command strip and flags -S) in /nix/store/rmyyd9pcbchbyd7wi2nwfgmxqmiy1b81-caffe-1.0/lib
patching script interpreter paths in /nix/store/rmyyd9pcbchbyd7wi2nwfgmxqmiy1b81-caffe-1.0
checking for references to /build in /nix/store/rmyyd9pcbchbyd7wi2nwfgmxqmiy1b81-caffe-1.0...

@GrahamcOfBorg
Copy link

Failure on aarch64-linux (full log)

Attempted: caffe

Partial log (click to expand)

I0807 15:59:56.011777  3313 caffe.cpp:313] Batch 45, prob = 0.00106234
I0807 15:59:56.011808  3313 caffe.cpp:313] Batch 45, prob = 0.000977964
I0807 15:59:56.011827  3313 caffe.cpp:313] Batch 45, prob = 0.000912752
I0807 15:59:56.011842  3313 caffe.cpp:313] Batch 45, prob = 0.000863734
I0807 15:59:56.011857  3313 caffe.cpp:313] Batch 45, prob = 0.00103721
I0807 15:59:56.011873  3313 caffe.cpp:313] Batch 45, prob = 0.000941304
I0807 15:59:56.011888  3313 caffe.cpp:313] Batch 45, prob = 0.00121647
I0807 15:59:56.011901  3313 caffe.cpp:313] Batch 45, prob = 0.00111082
building of '/nix/store/ravx02bz7n26z2a75kzg7bk2r9vds9df-caffe-1.0.drv' timed out after 3600 seconds
error: build of '/nix/store/ravx02bz7n26z2a75kzg7bk2r9vds9df-caffe-1.0.drv' failed

@GrahamcOfBorg
Copy link

Failure on x86_64-darwin (full log)

Attempted: caffe

Partial log (click to expand)

I0807 16:19:30.977342 3001267072 caffe.cpp:313] Batch 20, prob = 0.000976626
I0807 16:19:30.977351 3001267072 caffe.cpp:313] Batch 20, prob = 0.000865289
I0807 16:19:30.977360 3001267072 caffe.cpp:313] Batch 20, prob = 0.00102131
I0807 16:19:30.977370 3001267072 caffe.cpp:313] Batch 20, prob = 0.00102944
I0807 16:19:30.977378 3001267072 caffe.cpp:313] Batch 20, prob = 0.000867973
I0807 16:19:30.977387 3001267072 caffe.cpp:313] Batch 20, prob = 0.000949143
I0807 16:19:30.977396 3001267072 caffe.cpp:313] Batch 20, prob = 0.000924369
I0807 16:19:30.977406 3001267072 caffe.cpp:313] Batch 20, prob = 0.000987476
building of '/nix/store/66w7i7xqs67x78g1ifwi6lr68j7kmfhh-caffe-1.0.drv' timed out after 1800 seconds
error: build of '/nix/store/66w7i7xqs67x78g1ifwi6lr68j7kmfhh-caffe-1.0.drv' failed

@GrahamcOfBorg
Copy link

Success on x86_64-darwin (full log)

Attempted: caffe

Partial log (click to expand)

/nix/store/qgj5spaqi0mahw28h9fnj95cx39gfkmi-caffe-1.0-bin

@GrahamcOfBorg
Copy link

Failure on x86_64-linux (full log)

Attempted: caffe

Partial log (click to expand)

[ 94%] Building CXX object modules/sfm/src/libmv/libmv/multiview/CMakeFiles/multiview.dir/twoviewtriangulation.cc.o
[ 94%] Linking CXX static library ../../../../../../lib/libmultiview.a
[ 94%] Built target multiview
Scanning dependencies of target correspondence
[ 94%] Building CXX object modules/sfm/src/libmv/libmv/correspondence/CMakeFiles/correspondence.dir/feature_matching.cc.o
[ 94%] Building CXX object modules/sfm/src/libmv/libmv/correspondence/CMakeFiles/correspondence.dir/matches.cc.o
[ 94%] Building CXX object modules/sfm/src/libmv/libmv/correspondence/CMakeFiles/correspondence.dir/nRobustViewMatching.cc.o
building of '/nix/store/dlcg8knb5g3lc9hsiwcnbjrld2wlmih6-opencv-3.4.2.drv' timed out after 3600 seconds
cannot build derivation '/nix/store/4ch8xcknhbmvvqp3fyx4wlgwwayq5ckv-caffe-1.0.drv': 1 dependencies couldn't be built
error: build of '/nix/store/4ch8xcknhbmvvqp3fyx4wlgwwayq5ckv-caffe-1.0.drv' failed

@@ -201,6 +201,13 @@ in rec {
};

overrides = super: {
Accelerate = stdenv.lib.overrideDerivation super.Accelerate (drv: {
__propagatedImpureHostDeps = drv.__propagatedImpureHostDeps ++ [
Copy link
Member

Choose a reason for hiding this comment

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

I don't think this is necessary since these paths are part of the Accelerate framework itself.

};

# work around /usr/lib having different lib names than the framework
macblas = runCommand "macblas" {
Copy link
Member

Choose a reason for hiding this comment

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

I'd move this to darwin-packages.nix instead of hiding it here.

Copy link
Member

Choose a reason for hiding this comment

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

I think we want everyone to be using openblas though - not Apple's version.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, ideally this wouldn't be necessary.

@GrahamcOfBorg
Copy link

Failure on aarch64-linux (full log)

Attempted: caffe

Partial log (click to expand)

I0807 17:00:01.170207  3314 caffe.cpp:313] Batch 44, prob = 0.000963745
I0807 17:00:01.170222  3314 caffe.cpp:313] Batch 44, prob = 0.000970502
I0807 17:00:01.170238  3314 caffe.cpp:313] Batch 44, prob = 0.00119094
I0807 17:00:01.170254  3314 caffe.cpp:313] Batch 44, prob = 0.000934112
I0807 17:00:01.170269  3314 caffe.cpp:313] Batch 44, prob = 0.00100334
I0807 17:00:01.170285  3314 caffe.cpp:313] Batch 44, prob = 0.0010535
I0807 17:00:01.170300  3314 caffe.cpp:313] Batch 44, prob = 0.00113937
I0807 17:00:01.170331  3314 caffe.cpp:313] Batch 44, prob = 0.000961296
building of '/nix/store/ravx02bz7n26z2a75kzg7bk2r9vds9df-caffe-1.0.drv' timed out after 3600 seconds
error: build of '/nix/store/ravx02bz7n26z2a75kzg7bk2r9vds9df-caffe-1.0.drv' failed

@zimbatm
Copy link
Member Author

zimbatm commented Aug 8, 2018

I don't have a lot of experience in the *blas sphere. Here is my understanding:

  • openblas is the cross-platform version.
  • The platform-native versions are usually better performance-wise.
  • Then there is atlas which I don't know what role is playing but is currently broken in master. It looks like it would be API-compatible with the Accelerate.framework.

Roads that I see could be tried:

  1. (a) The Accelerate.framework distributed with nixpkgs is not complete. drill down why it's missing the .so files. (b) Add a lib/ folder to the Accelerate derivation output for the renamed .dylib files.
  2. Try to fix the caffe CMake detection and always use openblas
  3. Fix the atlas compilation and use that instead of Accelerate.framework

What should I do next?

@LnL7
Copy link
Member

LnL7 commented Aug 8, 2018

I think it's generally best to avoid frameworks since they are impure, but while not ideal this is reasonable if the build system is too hard to configure.

@matthewbauer
Copy link
Member

@zimbatm I just pushed two commits that are working for me. This adds a patch to get rid of the special cases for macOS. Hope that works!

@GrahamcOfBorg
Copy link

Success on aarch64-linux (full log)

Attempted: caffe

Partial log (click to expand)

stripping (with command strip and flags -S) in /nix/store/52swmj4fc67xi598qlaimlrfq1b4k1y0-caffe-1.0-bin/bin
patching script interpreter paths in /nix/store/52swmj4fc67xi598qlaimlrfq1b4k1y0-caffe-1.0-bin
checking for references to /build in /nix/store/52swmj4fc67xi598qlaimlrfq1b4k1y0-caffe-1.0-bin...
shrinking RPATHs of ELF executables and libraries in /nix/store/z4jkzisnjv9lgi2rd5va9l6v38wmm7an-caffe-1.0
shrinking /nix/store/z4jkzisnjv9lgi2rd5va9l6v38wmm7an-caffe-1.0/lib/libcaffe.so.1.0.0
strip is /nix/store/ah0va6j4cnwj9nx4j6rwcfc8nh785jwm-binutils-2.30/bin/strip
stripping (with command strip and flags -S) in /nix/store/z4jkzisnjv9lgi2rd5va9l6v38wmm7an-caffe-1.0/lib
patching script interpreter paths in /nix/store/z4jkzisnjv9lgi2rd5va9l6v38wmm7an-caffe-1.0
checking for references to /build in /nix/store/z4jkzisnjv9lgi2rd5va9l6v38wmm7an-caffe-1.0...
/nix/store/52swmj4fc67xi598qlaimlrfq1b4k1y0-caffe-1.0-bin

@GrahamcOfBorg
Copy link

Success on x86_64-darwin (full log)

Attempted: caffe

Partial log (click to expand)

/nix/store/69mly11r0sjikx0imslvabqrfxx2lzqf-caffe-1.0/lib/libcaffe.1.0.0.dylib: fixing dylib
/nix/store/69mly11r0sjikx0imslvabqrfxx2lzqf-caffe-1.0/lib/libcaffe.1.0.0.dylib: fixing dylib
/nix/store/69mly11r0sjikx0imslvabqrfxx2lzqf-caffe-1.0/lib/libcaffe.1.0.0.dylib: fixing dylib
/nix/store/69mly11r0sjikx0imslvabqrfxx2lzqf-caffe-1.0/lib/libcaffe.1.0.0.dylib: fixing dylib
/nix/store/69mly11r0sjikx0imslvabqrfxx2lzqf-caffe-1.0/lib/libcaffe.1.0.0.dylib: fixing dylib
/nix/store/69mly11r0sjikx0imslvabqrfxx2lzqf-caffe-1.0/lib/libcaffe.1.0.0.dylib: fixing dylib
/nix/store/69mly11r0sjikx0imslvabqrfxx2lzqf-caffe-1.0/lib/libcaffe.1.0.0.dylib: fixing dylib
/nix/store/69mly11r0sjikx0imslvabqrfxx2lzqf-caffe-1.0/lib/libcaffe.1.0.0.dylib: fixing dylib
/nix/store/69mly11r0sjikx0imslvabqrfxx2lzqf-caffe-1.0/lib/libcaffe.1.0.0.dylib: fixing dylib
/nix/store/b3jvrkd8zj86a3yvqsf8qv1g69v854jk-caffe-1.0-bin

@GrahamcOfBorg
Copy link

Success on x86_64-linux (full log)

Attempted: caffe

Partial log (click to expand)

strip is /nix/store/gpc2wld1s0c6qzx9326cwn1wcx29xzsj-binutils-2.30/bin/strip
stripping (with command strip and flags -S) in /nix/store/bqhl4k80hn3jlijg6bikbfs3ffzmw3qq-caffe-1.0-bin/bin
patching script interpreter paths in /nix/store/bqhl4k80hn3jlijg6bikbfs3ffzmw3qq-caffe-1.0-bin
checking for references to /build in /nix/store/bqhl4k80hn3jlijg6bikbfs3ffzmw3qq-caffe-1.0-bin...
shrinking RPATHs of ELF executables and libraries in /nix/store/m82p68lvqmz81fpbdkrnyar7032ssvw5-caffe-1.0
shrinking /nix/store/m82p68lvqmz81fpbdkrnyar7032ssvw5-caffe-1.0/lib/libcaffe.so.1.0.0
strip is /nix/store/gpc2wld1s0c6qzx9326cwn1wcx29xzsj-binutils-2.30/bin/strip
stripping (with command strip and flags -S) in /nix/store/m82p68lvqmz81fpbdkrnyar7032ssvw5-caffe-1.0/lib
patching script interpreter paths in /nix/store/m82p68lvqmz81fpbdkrnyar7032ssvw5-caffe-1.0
checking for references to /build in /nix/store/m82p68lvqmz81fpbdkrnyar7032ssvw5-caffe-1.0...

@zimbatm
Copy link
Member Author

zimbatm commented Aug 16, 2018

hey, thanks @matthewbauer! Testing with the postInstallCheck phase enabled. If this passes I will merge the PR.

@zimbatm zimbatm merged commit b7e50d5 into NixOS:master Aug 16, 2018
@zimbatm zimbatm deleted the darwin-caffe branch August 16, 2018 11:46
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.

None yet

4 participants