facebookarchive / caffe2

Caffe2 is a lightweight, modular, and scalable deep learning framework.
https://caffe2.ai
Apache License 2.0
8.42k stars 1.94k forks source link

ios binary extremely large - 170MB #695

Open ayyoitsp opened 7 years ago

ayyoitsp commented 7 years ago

Building caffe2 results in libCaffe2_CPU.a being 170MB. This is a show-stopper for delivering a build to the app store that is a reasonable size.

571 is a similar issue on Android, suggesting adding the -O3 flags to builds, which I have done with little success. I have also tried -Os, but builds are the same size.

285 suggests using CAFFE2_WHITELIST, but there are no examples of how to use this parameter.

ayyoitsp commented 7 years ago

-- **** Summary **** -- General: -- Git version : -- System : Darwin -- C++ compiler : /usr/bin/g++ -- C++ compiler version : 8.1.0.8020042 -- Protobuf compiler : /redacted/build_host_protoc/bin/protoc -- CXX flags : -fembed-bitcode -Wno-deprecated-declarations -Wno-deprecated -std=c++11 -Os -fPIC -Wno-narrowing -- Build type : Release -- Compile definitions : CAFFE2_USE_EIGEN_FOR_BLAS;EIGEN_MPL2_ONLY;CAFFE2_UNIQUE_LONG_TYPEMETA;CAFFE2_NO_BUILTIN_CPU_SUPPORTS

-- BUILD_SHARED_LIBS : OFF -- BUILD_PYTHON : OFF -- Python version : -- Python library : -- USE_CUDA : OFF -- USE_NERVANA_GPU : OFF -- USE_GLOG : OFF -- USE_GFLAGS : OFF -- USE_LMDB : OFF -- USE_LEVELDB : OFF -- USE_OPENCV : ON -- OpenCV version : 2.4.13 -- USE_FFMPEG : -- USE_ZMQ : OFF -- USE_ROCKSDB : OFF -- USE_MPI : OFF -- USE_NCCL : OFF -- USE_NNPACK : ON -- USE_OPENMP : OFF -- USE_REDIS : OFF -- USE_GLOO : OFF

futurely commented 7 years ago

CAFFE2_WHITELIST should be a text file in which each line is a needed source file or directory. https://github.com/caffe2/caffe2/blob/e80e8b28c31dd788a21aee9907de69b68ffa5073/cmake/Whitelist.cmake

ayyoitsp commented 7 years ago

How can I determine which files should be whitelisted?

futurely commented 7 years ago

All or most of the core and operators modules. https://github.com/caffe2/caffe2/tree/master/caffe2/core https://github.com/caffe2/caffe2/tree/master/caffe2/operators

I'm not sure. https://github.com/caffe2/caffe2/issues/663

lzx1413 commented 7 years ago

the format of whitelist can be something like this:

caffe2/core/asan.h
caffe2/core/blob.h
caffe2/core/blob_serialization.cc
caffe2/core/blob_serialization.h
caffe2/core/blob_serializer_base.h
caffe2/core/blob_stats.cc
caffe2/core/blob_stats.h
caffe2/core/blob_test.cc
caffe2/core/common.h
caffe2/core/db.cc
caffe2/core/common_cudnn.cc
caffe2/core/common_cudnn.h
caffe2/core/common_gpu.cc
caffe2/core/common_gpu.h
caffe2/core/common_omp.h
caffe2/core/context.cc
caffe2/core/context.h
christoph-conrads commented 7 years ago

Since you are compiling for iOS and since you set -fembed-bitcode on the compiler command line, I believe what you are seeing is XCode building a fat binary and not a Caffe2 problem. Try to disable bitcode.