Skip to content

Commit

Permalink
Packaging Caffe's dependencies as shared libraries.
Browse files Browse the repository at this point in the history
Allows an app using libcaffe to link its own C++ code and also use
Caffe's dependencies.
  • Loading branch information
cypof committed Oct 20, 2015
1 parent 1e345e0 commit 6e19b3b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 19 deletions.
26 changes: 15 additions & 11 deletions caffe/cppbuild.sh
Original file line number Diff line number Diff line change
Expand Up @@ -84,50 +84,50 @@ export CFLAGS="-fPIC"
export CXXFLAGS="-fPIC"

cd glog-$GLOG
./configure "--prefix=$INSTALL_PATH" --disable-shared
./configure "--prefix=$INSTALL_PATH"
make -j $MAKEJ
make install
cd ..

cd gflags-$GFLAGS
mkdir -p build
cd build
"$CMAKE" -DBUILD_SHARED_LIBS=OFF "-DCMAKE_INSTALL_PREFIX=$INSTALL_PATH" ..
"$CMAKE" -DBUILD_SHARED_LIBS=ON "-DCMAKE_INSTALL_PREFIX=$INSTALL_PATH" ..
make -j $MAKEJ
make install
cd ../..

cd protobuf-$PROTO
./configure "--prefix=$INSTALL_PATH" --disable-shared
./configure "--prefix=$INSTALL_PATH"
make -j $MAKEJ
make install
cd ..

cd leveldb-$LEVELDB
make -j $MAKEJ
cp -a libleveldb.a "$INSTALL_PATH/lib"
cp -a include/leveldb "$INSTALL_PATH/include/"
cp -a libleveldb.* "$INSTALL_PATH/lib"
cd ..

cd snappy-$SNAPPY
./configure "--prefix=$INSTALL_PATH" --disable-shared
./configure "--prefix=$INSTALL_PATH"
make -j $MAKEJ
make install
cd ..

cd lmdb-LMDB_$LMDB/libraries/liblmdb
make -j $MAKEJ "CC=$CC" "XCFLAGS=$CFLAGS" "CPPFLAGS=$CXXFLAGS"
cp -a lmdb.h ../../../include/
cp -a liblmdb.a ../../../lib/
cp -a lmdb.h "$INSTALL_PATH/include/"
cp -a liblmdb.so "$INSTALL_PATH/lib"
cd ../../..

cd boost_$BOOST
./bootstrap.sh --with-libraries=system,thread
./b2 install "--prefix=$INSTALL_PATH" "address-model=$BINARY" link=static "toolset=$TOOLSET" "cxxflags=$CXXFLAGS"
./b2 install "--prefix=$INSTALL_PATH" "address-model=$BINARY" "toolset=$TOOLSET" "cxxflags=$CXXFLAGS"
cd ..

cd hdf5-$HDF5
./configure "--prefix=$INSTALL_PATH" --disable-shared
./configure "--prefix=$INSTALL_PATH"
make -j $MAKEJ
make install
cd ..
Expand All @@ -136,11 +136,15 @@ cd ..
if [[ $PLATFORM != macosx-* ]]; then
# blas (requires fortran, e.g. sudo yum install gcc-gfortran)
cd OpenBLAS-$OPENBLAS
make -j $MAKEJ "CC=$CC" "FC=$FC" BINARY=$BINARY NO_SHARED=1
make install "PREFIX=$INSTALL_PATH" NO_SHARED=1
make -j $MAKEJ "CC=$CC" "FC=$FC" BINARY=$BINARY
make install "PREFIX=$INSTALL_PATH"
cd ..
fi

# Make sure only shared libs are used
rm "$INSTALL_PATH"/lib/*.a
rm "$INSTALL_PATH"/lib/*.la

# List Maven dependencies
pushd ../..
mvn org.bytedeco:javacpp:1.1-SNAPSHOT:build -DwriteIncludes=javacpp.incs.txt -DwriteLibs=javacpp.libs.txt
Expand Down
20 changes: 12 additions & 8 deletions caffe/src/main/java/org/bytedeco/javacpp/presets/caffe.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,18 @@
* @author Samuel Audet
*/
@Properties(inherit=opencv_highgui.class, target="org.bytedeco.javacpp.caffe", value={
@Platform(value={"linux", "macosx"}, define={"CPU_ONLY", "SHARED_PTR_NAMESPACE boost", "USE_LEVELDB", "USE_LMDB", "USE_OPENCV"}, include={"caffe/caffe.hpp", "caffe/util/device_alternate.hpp",
"caffe/common.hpp", "caffe/proto/caffe.pb.h", "caffe/util/blocking_queue.hpp", "caffe/data_reader.hpp", "caffe/util/math_functions.hpp", "caffe/syncedmem.hpp",
"caffe/blob.hpp", "caffe/data_transformer.hpp", "caffe/filler.hpp", "caffe/internal_thread.hpp", "caffe/util/hdf5.hpp", "caffe/data_layers.hpp", "caffe/layer_factory.hpp",
"caffe/layer.hpp", "caffe/loss_layers.hpp", "caffe/neuron_layers.hpp", "caffe/common_layers.hpp", "caffe/net.hpp", "caffe/parallel.hpp", "caffe/solver.hpp",
"caffe/vision_layers.hpp", "caffe/util/benchmark.hpp", "caffe/util/db.hpp", "caffe/util/db_leveldb.hpp", "caffe/util/db_lmdb.hpp",
"caffe/util/io.hpp", "caffe/util/rng.hpp", "caffe/util/im2col.hpp", "caffe/util/insert_splits.hpp", "caffe/util/mkl_alternate.hpp",
"caffe/util/upgrade_proto.hpp", /* "caffe/util/cudnn.hpp" */}, link="caffe", includepath={"/usr/local/cuda/include/",
"/System/Library/Frameworks/vecLib.framework/", "/System/Library/Frameworks/Accelerate.framework/"}, linkpath="/usr/local/cuda/lib/") })
@Platform(value={"linux", "macosx"},
define={"CPU_ONLY", "SHARED_PTR_NAMESPACE boost", "USE_LEVELDB", "USE_LMDB", "USE_OPENCV"},
include={"caffe/caffe.hpp", "caffe/util/device_alternate.hpp", "caffe/common.hpp", "caffe/proto/caffe.pb.h", "caffe/util/blocking_queue.hpp",
"caffe/data_reader.hpp", "caffe/util/math_functions.hpp", "caffe/syncedmem.hpp", "caffe/blob.hpp", "caffe/data_transformer.hpp",
"caffe/filler.hpp", "caffe/internal_thread.hpp", "caffe/util/hdf5.hpp", "caffe/data_layers.hpp", "caffe/layer_factory.hpp",
"caffe/layer.hpp", "caffe/loss_layers.hpp", "caffe/neuron_layers.hpp", "caffe/common_layers.hpp", "caffe/net.hpp", "caffe/parallel.hpp",
"caffe/solver.hpp", "caffe/vision_layers.hpp", "caffe/util/benchmark.hpp", "caffe/util/db.hpp", "caffe/util/db_leveldb.hpp",
"caffe/util/db_lmdb.hpp", "caffe/util/io.hpp", "caffe/util/rng.hpp", "caffe/util/im2col.hpp", "caffe/util/insert_splits.hpp",
"caffe/util/mkl_alternate.hpp", "caffe/util/upgrade_proto.hpp", /* "caffe/util/cudnn.hpp" */},
link={"glog", "gflags", "protobuf", "boost_system", "boost_thread", "hdf5_hl", "hdf5", "leveldb", "snappy", "lmdb", "openblas", "caffe"},
includepath={"/usr/local/cuda/include/", "/System/Library/Frameworks/vecLib.framework/", "/System/Library/Frameworks/Accelerate.framework/"},
linkpath="/usr/local/cuda/lib/") })
public class caffe implements InfoMapper {
public void map(InfoMap infoMap) {
infoMap.put(new Info("NOT_IMPLEMENTED", "NO_GPU", "CUDA_POST_KERNEL_CHECK").cppTypes().annotations())
Expand Down

0 comments on commit 6e19b3b

Please sign in to comment.