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

caffe2: init at 0.8.1 #34956

Merged
merged 5 commits into from Feb 16, 2018
Merged

caffe2: init at 0.8.1 #34956

merged 5 commits into from Feb 16, 2018

Conversation

yuriaisaka
Copy link
Contributor

Motivation for this change

Caffe2 is a lightweight, modular, and scalable deep learning framework developed at Facebook.
It is a successor to the widely used Caffe framework, and provides both C++ and Python APIs.

Requests for review:

(1) package location

I've tentatively put the package to pkgs/development/library/science/math,
although it might fit nicer to pkgs/development/library/science/machine-learning
if there's such a directory.

Notes:

  • There's a directory named pkgs/applications/science/machine-learning/
  • caffe resides in: pkgs/applications/science/math/
  • Other major deep learning frameworks (notably tensorflow & pytorch) are registered as python packages.

(2) CUDA issues

  • Caffe2 v0.8.1 (the version packaged in this PR) does not officially support Cuda Toolkit9
  • Cuda Toolkit8 does not officially support gcc6
  • Caffe2/CPU v0.8.1 compiles and seems to work fine both with gcc5 and gcc6.
  • I haven't been able to compile Caffe2/GPU v0.8.1 with Cuda Toolkit8 and gcc5.5 from 18.03pre (overrideCC stdenv pkgs.gcc5). It compiles (and seems to work fine) with Cuda Toolkit8 and gcc5.4 from release-17.09.
  • The errors from Caffe2/GPU v0.8.1 with Cuda Toolkit8 and gcc5.5 seems to be arising from AVX intrinsics, e.g.:
    Building NVCC (Device) object caffe2/CMakeFiles/Caffe2_GPU.dir/utils/Caffe2_GPU_generated_math_gpu.cu.o
    /nix/store/0l7rjsr59d7l8pr0gxvf37jx8gnva5fi-gcc-5.5.0/lib/gcc/x86_64-unknown-linux-gnu/5.5.0/include/avx512fintrin.h(9220): error: argument of type "const void *" is incompatible with parameter of type "const float *"
    
Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option build-use-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/)
  • Fits CONTRIBUTING.md.

stdenv.mkDerivation rec {
name = "caffe2-${version}";
version = "0.8.1";
src = fetchurl {
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider re-using version when fetching the source, for easier bumping. Also consider
using the fetchFromGitHub helper, it is a little bit more succinct & "safer" when using autogenerated archives.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Makes sense, thanks! Have updated the PR.

@joachifm
Copy link
Contributor

@GrahamcOfBorg build caffe2

@GrahamcOfBorg
Copy link

Failure on aarch64-linux (full log)

Partial log (click to expand)

error: while evaluating the attribute 'buildInputs' of the derivation 'caffe2-0.8.1' at /var/lib/gc-of-borg/nix-test-rs-3/repo/38dca4e3aa6bca43ea96d2fcc04e8229/builder/grahamc-aarch64-community-3/pkgs/stdenv/generic/make-derivation.nix:148:11:
while evaluating the attribute 'preConfigure' of the derivation 'opencv-3.4.0' at /var/lib/gc-of-borg/nix-test-rs-3/repo/38dca4e3aa6bca43ea96d2fcc04e8229/builder/grahamc-aarch64-community-3/pkgs/stdenv/generic/make-derivation.nix:148:11:
while evaluating 'installExtraFiles' at /var/lib/gc-of-borg/nix-test-rs-3/repo/38dca4e3aa6bca43ea96d2fcc04e8229/builder/grahamc-aarch64-community-3/pkgs/development/libraries/opencv/3.x.nix:128:23, called from /var/lib/gc-of-borg/nix-test-rs-3/repo/38dca4e3aa6bca43ea96d2fcc04e8229/builder/grahamc-aarch64-community-3/pkgs/development/libraries/opencv/3.x.nix:177:5:
while evaluating 'mapAttrsToList' at /var/lib/gc-of-borg/nix-test-rs-3/repo/38dca4e3aa6bca43ea96d2fcc04e8229/builder/grahamc-aarch64-community-3/lib/attrsets.nix:223:23, called from /var/lib/gc-of-borg/nix-test-rs-3/repo/38dca4e3aa6bca43ea96d2fcc04e8229/builder/grahamc-aarch64-community-3/pkgs/development/libraries/opencv/3.x.nix:130:23:
while evaluating the attribute 'files' at /var/lib/gc-of-borg/nix-test-rs-3/repo/38dca4e3aa6bca43ea96d2fcc04e8229/builder/grahamc-aarch64-community-3/pkgs/development/libraries/opencv/3.x.nix:64:5:
ICV is not available for this platform (or not yet supported by this package)

@GrahamcOfBorg
Copy link

Failure on x86_64-darwin (full log)

Partial log (click to expand)

^
/nix/store/gk21pv5a8wwrj6frd5m283qjdvd1yvkn-clang-4.0.1/bin/../lib/clang/4.0.1/include/f16cintrin.h:46:1: note: previous definition is here
_cvtsh_ss(unsigned short __a)
^
1 error generated.
make[2]: *** [caffe2/perfkernels/CMakeFiles/Caffe2_perfkernels_avx2.dir/build.make:111: caffe2/perfkernels/CMakeFiles/Caffe2_perfkernels_avx2.dir/typed_axpy_avx2.cc.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:729: caffe2/perfkernels/CMakeFiles/Caffe2_perfkernels_avx2.dir/all] Error 2
make: *** [Makefile:141: all] Error 2
builder for '/nix/store/yyxdcxndr78ink7pb459q8a1r3njkkf1-caffe2-0.8.1.drv' failed with exit code 2
error: build of '/nix/store/yyxdcxndr78ink7pb459q8a1r3njkkf1-caffe2-0.8.1.drv' failed

@GrahamcOfBorg
Copy link

Success on x86_64-linux (full log)

Partial log (click to expand)

stripping (with command strip and flags -S) in /nix/store/rx3s0kfjpk076pd96lnzdywi28qdz4a6-caffe2-0.8.1-bin/bin 
patching script interpreter paths in /nix/store/rx3s0kfjpk076pd96lnzdywi28qdz4a6-caffe2-0.8.1-bin
checking for references to /tmp/nix-build-caffe2-0.8.1.drv-0 in /nix/store/rx3s0kfjpk076pd96lnzdywi28qdz4a6-caffe2-0.8.1-bin...
shrinking RPATHs of ELF executables and libraries in /nix/store/2frqn70sig3n5v7dyicm70ng0z2ppfvn-caffe2-0.8.1
shrinking /nix/store/2frqn70sig3n5v7dyicm70ng0z2ppfvn-caffe2-0.8.1/caffe2/python/caffe2_pybind11_state.so
shrinking /nix/store/2frqn70sig3n5v7dyicm70ng0z2ppfvn-caffe2-0.8.1/lib/libCaffe2_CPU.so
strip is /nix/store/5qj61lcvzlap87rf6blvf8p577d482bv-binutils-2.28.1/bin/strip
stripping (with command strip and flags -S) in /nix/store/2frqn70sig3n5v7dyicm70ng0z2ppfvn-caffe2-0.8.1/lib 
patching script interpreter paths in /nix/store/2frqn70sig3n5v7dyicm70ng0z2ppfvn-caffe2-0.8.1
checking for references to /tmp/nix-build-caffe2-0.8.1.drv-0 in /nix/store/2frqn70sig3n5v7dyicm70ng0z2ppfvn-caffe2-0.8.1...

@yuriaisaka
Copy link
Contributor Author

yuriaisaka commented Feb 15, 2018

600b1d3 tries to fix the build failure on x86_64-darwin.
Since I don't have a working Darwin environment, shall remove darwin support for now if this attempt fails.

As for the build failure on aarch64-linux, probably pkgs/development/libraries/opencv/3.x.nix shall check if stdenv.system is one of (x86_64-linux, i686-linux, x86_64-darwin) before calling installExtraFiles ippicv at 3.x.nix:177? As far as I understand, opencv3 works without IntelCV.

@@ -0,0 +1,55 @@
diff --git a/caffe2/perfkernels/cvtsh_ss_bugfix.h b/caffe2/perfkernels/cvtsh_ss_bugfix.h
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there an external source for this patch? It is generally preferred to fetch patches (using e.g., fetchpatch).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the suggestion. As a single patch, I suspect not.

557f877 in https://github.com/caffe2/caffe2/commits/master/caffe2/perfkernels/cvtsh_ss_bugfix.h is in v0.8.1 and there're 4-5 patches upstream to cover various versions/flavors of clang.

But then, what the patch does is to replace cvtsh_ss_bugfix.h at v0.8.1 by that of the current master, so I could fetch a newer cvtsh_ss_bugfix.h and override by it in one of the build hooks.

;
propagatedBuildInputs = [ numpy future six python-protobuf pydot ];

patches = if stdenv.cc.isClang then [ ./update_clang_cvtsh_bugfix.patch ] else [ ];
Copy link
Contributor

Choose a reason for hiding this comment

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

The pattern if foo then [ x ] else [ ] can be reduced to optional foo x

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I should have noticed that, thanks.

@joachifm joachifm merged commit f8c4890 into NixOS:master Feb 16, 2018
@yuriaisaka yuriaisaka deleted the pr-caffe2-init branch February 19, 2018 08:26
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

3 participants