caffe icon indicating copy to clipboard operation
caffe copied to clipboard

Provide a Caffe package in Debian

Open cdluminate opened this issue 11 years ago • 83 comments

Status

Caffe packages are available for Debian/unstable.
Caffe packages are failing to build for Ubuntu-devel and need to be patched.

Last update: Dec.20 2016

Draft guide

Deploy Caffe with merely one command.

Brief Guide for Debian/unstable users

Only experienced linux users are recommended to try Debian/unstable (Sid). To install caffe, first make sure you have something like the follows in file /etc/apt/sources.list: (Uncomment the second line if you want to re-compile caffe locally.)

deb http://ftp.cn.debian.org/debian sid main contrib non-free
#deb-src http://ftp.cn.debian.org/debian sid main contrib non-free

Then update apt cache and install it. Note, you cannot install both the cpu version and the cuda version.

# apt update
# apt install [ caffe-cpu | caffe-cuda ]
# caffe

It should work out of box. I hope this work is helpful since there are many people struggling at the Caffe compiling process.

Here are some notes:

  • Please re-compile OpenBLAS locally with optimization flags for sake of performance. This is highly recommended if you are writing a paper. The way to re-compile OpenBLAS from Debian source is very similar with the next subsection.
  • If you are going to install caffe-cuda, it will automatically pull the CUDA package and the nvidia driver packages. The installation procress may fail if any part of the caffe dependency chain gets into trouble. That is to say, please take care if you have manually installed or significantly modified nvidia driver or CUDA toolkit or protobuf or any other related stuff.
  • if you encountered any problem when installing caffe-cuda on a clean Debian system, report bug to me (via Debian's bug tracking system) please.
  • If you encountered any problem when installing caffe-cpu, please report bug to me via Debian's bug tracking system.
  • Both of caffe-cpu and caffe-cuda contain a manpage (man caffe) and a bash complementation script (caffe <TAB><TAB>, caffe train <TAB><TAB>). Both of them are still not merged into caffe master.
  • The python interface is Python3 version: python3-caffe-{cpu,cuda}. No plan to support python2.

Compiling your custom caffe package on Debian/unstable

There is no promise for the content in this subsection. If you just want to compile again from the source without any change, the following should work as expected. If you want to compile it with e.g. CUDNN support, you should at least be able to read and hack the file debian/rules under the source tree (It's a Makefile).

First make sure you have a correct deb-src line in your apt source list file. Then we compile caffe with several simple commands.

# apt update
# apt install build-essential debhelper devscripts    # These are standard package building tools
# apt build-dep [ caffe-cpu | caffe-cuda ]    # the most elegant way to pull caffe build dependencies
# apt source [ caffe-cpu | caffe-cuda ]    # download the source tarball
# cd caffe-XXXX    # now we enter into the source tree
[ ... optional, make your custom changes at your own risk ... ]
# debuild -B -j4    # build caffe with 4 parallel jobs (similar to make -j4)
[ ... building ...]
# debc    # optional, if you want to check the package contents
# debi    # install the generated packages

FAQ

  1. where is caffe-cudnn?
    Due to legal reason the cudnn library cannot be redistributed. I'll be happy to make this package when CUDNN becomes re-distributable. The workaround is to install cudnn by yourself, and hack at least the debian/rules file if you really want the caffe *.deb packages with CUDNN support.

  2. how to report bug via Debian bug tracking system?
    See https://www.debian.org/Bugs/ .

  3. I installed the CPU version, what should I do if I want to switch to CUDA verison?
    sudo apt install caffe-cuda, apt's dependency resolver is smart enough for this.

  4. Where is the examples, the models and other documentation stuff?
    sudo apt install caffe-doc; dpkg -L caffe-doc

cdluminate avatar Jun 14 '15 10:06 cdluminate

Probably https://github.com/BVLC/caffe/pull/2523 could help you.

bhack avatar Jun 14 '15 10:06 bhack

@bhack Thank you for this info. I'm now struggling with caffe's Makefile and Debian packaging rules. Maybe I will have to look into compiler issues/etc someday in the future.

cdluminate avatar Jun 14 '15 10:06 cdluminate

Actually caffe maintain two build systems: Makefile and Cmake.

bhack avatar Jun 14 '15 10:06 bhack

Is there really a need to provide both Atlas and OpenBLAS versions? I don't think it makes a big difference performance-wise so I won't be upset if you were to settle on one BLAS library and only provide caffe-cpu and caffe-gpu. Of course that's only my personal opinion.

flx42 avatar Jun 14 '15 23:06 flx42

@bhack Yes, and I prefer to use Makefile :-)

cdluminate avatar Jun 16 '15 10:06 cdluminate

@flx42 Initially I don't want to force users to use one of the BLASes. However thank to your reminder I realized that, maybe it's really not necessary to provide both atlas version and openblas version, because those who really need extraordinary performance will build caffe by themselves, linking with some proprietary software/libraries (cuDNN, MKL).

These blogs are found in order to make a choice between atlas and openblas: this one , this one, this one, and this one

Well, seems that I should take openblas ?

cdluminate avatar Jun 16 '15 11:06 cdluminate

I completely agree with @flx42 's comment. Those who want a specific configuration will compile for themselves anyway, and for those who just want to try it out on a reasonable configuration it wouldn't matter.

Sometimes too much choice is not that good.

I think that OpenBLAS is a better choice

talda avatar Jun 16 '15 11:06 talda

@talda OK, thank you for feedback :-)

cdluminate avatar Jun 16 '15 11:06 cdluminate

See also https://wiki.debian.org/DebianScience/LinearAlgebraLibraries

bhack avatar Jun 16 '15 11:06 bhack

@bhack Gotcha. This is inspiring:

The optimal way of using these two packages is to recompile them locally on the machines on which they are to be used. 

and README.Debian of openblas says:

 34 Compile the package:
 35 
 36 $ cd openblas-<VERSION>
 37 $ fakeroot debian/rules custom
 38 
 39 It should produce a package that you can install with:
 40 
 41 $ sudo dpkg -i ../libopenblas-base_<DEBVERSION>.deb

Then IMHO

  • it seems to be of less and less need to provide many versions of compiled caffe
  • it could be better if I provide similar custom target like atlas/openblas does

cdluminate avatar Jun 16 '15 12:06 cdluminate

By the way, the alternative link libblas.so.3 will not work for caffe, because e.g. the reault of readelf -d against openblas libcaffe.so is

 0x0000000000000001 (NEEDED)             Shared library: [libopenblas.so.0]
[...]
 0x000000000000000e (SONAME)             Library soname: [libcaffe.so.0]

and the result of readelf -d caffe.bin is

 0x0000000000000001 (NEEDED)             Shared library: [libcaffe.so.0]
 0x0000000000000001 (NEEDED)             Shared library: [libglog.so.0]
 0x0000000000000001 (NEEDED)             Shared library: [libgflags.so.2]
 0x0000000000000001 (NEEDED)             Shared library: [libstdc++.so.6]
 0x0000000000000001 (NEEDED)             Shared library: [libgcc_s.so.1]
 0x0000000000000001 (NEEDED)             Shared library: [libc.so.6]

We see libcaffe.so is directly linked to openblas, so alternating libblas.so makes no difference.


Note that, I added SONAME and fixed RPATH issue for distro, so the result on your local caffe may differ from mine.

cdluminate avatar Jun 16 '15 12:06 cdluminate

The packaging work is available at the temp repo: http://anonscm.debian.org/cgit/users/cdluminate-guest/caffe.git it passes my local build and the core component works, but is still under heavy development.


These packages are provided:

Package: caffe
Package: libcaffe
Package: libcaffe-dev
Package: caffe-cuda
Package: libcaffe-cuda
Package: libcaffe-cuda-dev
Package: caffe-doc

And maybe python-caffe packages will be added in the future.

cdluminate avatar Jul 09 '15 03:07 cdluminate

The repo http://anonscm.debian.org/cgit/users/cdluminate-guest/caffe.git/ has trouble to be cloned.

So I just made a mirror for it: https://github.com/CDLuminate/caffe.git

cdluminate avatar Jul 09 '15 05:07 cdluminate

Packaging work was moved to Debian-Science:
http://anonscm.debian.org/cgit/debian-science/packages/caffe.git

cdluminate avatar Aug 07 '15 08:08 cdluminate

Current summary:
https://lists.debian.org/debian-science/2015/08/msg00030.html

cdluminate avatar Aug 07 '15 08:08 cdluminate

Thank you for working on packaging. This has been requested a lot. On Fri, Aug 7, 2015 at 01:52 Lumin Zhou [email protected] wrote:

Current summary:

https://lists.debian.org/debian-science/2015/08/msg00030.html

— Reply to this email directly or view it on GitHub https://github.com/BVLC/caffe/issues/2601#issuecomment-128644323.

shelhamer avatar Aug 07 '15 16:08 shelhamer

Good news, the Debian Packaging of Caffe is done.
http://anonscm.debian.org/cgit/debian-science/packages/caffe.git/

Current packaging scheme provided these Debian package:
Suite 1: caffe-cpu:

  • caffe-cpu
  • libcaffe-cpu0
  • libcaffe-cpu-dev
  • python3-caffe-cpu

Suite 2: caffe-cuda

  • caffe-cuda
  • libcaffe-cuda0
  • libcaffe-cuda-dev
  • python3-caffe-cuda

For pyhton2 caffe package please have a look at debian/README.Debian in the packaging repo.

Currently I'm running the last build test on my machine, and will soon find sponsorship to upload it to debian/experimental.

If you can't wait for Debian Official Archive to accept this package, you can build package by yourself. (you can do simply debuild or do custom build following instructions from debian/README.Debian)

I'll provide a new installation guide once the caffe was uploaded to debian/experimental, for Debian and possibly Ubuntu users. (well, installing Debian packages on Ubuntu is BAD IDEA but I hope it works when there is e.g. urgent need.)

P.S. Did you Caffe Devs plan any release date for caffe-1.0 ?
Please tell me if there is, so I can schedule my working time for importing caffe-1.0 into Debian Packaging repo.

cdluminate avatar Sep 02 '15 08:09 cdluminate

Do you plan to re-organize the modularization after https://github.com/BVLC/caffe/pull/2523?

bhack avatar Sep 02 '15 09:09 bhack

Well, I'm not going to change the modularization after that merger.
And I think providing all IO compatibility is a good choice for Debian package. :-) @bhack

cdluminate avatar Sep 02 '15 11:09 cdluminate

Oops, seems that there are some troubles with python3-* packages. By the way which version of python is recommended? 2 or 3?

cdluminate avatar Sep 02 '15 16:09 cdluminate