caffe icon indicating copy to clipboard operation
caffe copied to clipboard

Make runtest failure

Open deepsamal opened this issue 11 years ago • 17 comments

Mac OS 10.9, CUDA 7.0 Make all and Make test ran without errors, except some warning about unused -pthread and 1 warning in test. But $make runtest gives segmentation fault. $make sudo runtest gives the error- .build_release/tools/caffe dyld: Library not loaded: @rpath/libcudart.7.0.dylib Referenced from: /Users/deepsamal/Desktop/Research/caffe/.build_release/tools/caffe Reason: image not found make: *** [runtest] Trace/BPT trap: 5

Seems a problem with dynamic loading of the cuda library path. checking the links of libcaffe.so, the paths to cuda libs are not resolved. But the libraries are present both in /usr/local/cuda/lib and in /Developer/NVIDIA.... folders.

Deep-Samals-MacBook-Pro:caffe deepsamal$ otool -L ~/Desktop/Research/caffe/build/lib/libcaffe.so /Users/deepsamal/Desktop/Research/caffe/build/lib/libcaffe.so: @rpath/libcaffe.so (compatibility version 0.0.0, current version 0.0.0) @rpath/libcudart.7.0.dylib (compatibility version 0.0.0, current version 7.0.29) @rpath/libcublas.7.0.dylib (compatibility version 0.0.0, current version 7.0.29) @rpath/libcurand.7.0.dylib (compatibility version 0.0.0, current version 7.0.29) /usr/local/lib/libglog.0.dylib (compatibility version 1.0.0, current version 1.0.0) /usr/local/lib/libprotobuf.9.dylib (compatibility version 10.0.0, current version 10.1.0) /usr/local/lib/libleveldb.1.dylib (compatibility version 0.0.0, current version 0.0.0) /usr/local/lib/libsnappy.1.dylib (compatibility version 4.0.0, current version 4.0.0) /usr/local/lib/liblmdb.dylib (compatibility version 0.0.0, current version 0.0.0) /usr/local/lib/libboost_system.dylib (compatibility version 0.0.0, current version 0.0.0) libhdf5_hl.9.dylib (compatibility version 10.0.0, current version 10.0.0) libhdf5.9.dylib (compatibility version 10.0.0, current version 10.0.0) /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1197.1.1) /usr/local/opt/opencv/lib/libopencv_core.2.4.dylib (compatibility version 2.4.0, current version 2.4.11) /usr/local/opt/opencv/lib/libopencv_highgui.2.4.dylib (compatibility version 2.4.0, current version 2.4.11) /usr/local/opt/opencv/lib/libopencv_imgproc.2.4.dylib (compatibility version 2.4.0, current version 2.4.11) /usr/local/lib/libboost_thread-mt.dylib (compatibility version 0.0.0, current version 0.0.0) @rpath/libcudnn.6.5.dylib (compatibility version 0.0.0, current version 6.5.48) /usr/local/lib/libboost_python.dylib (compatibility version 0.0.0, current version 0.0.0) libpython2.7.dylib (compatibility version 2.7.0, current version 2.7.0) libmkl_rt.dylib (compatibility version 0.0.0, current version 0.0.0) /usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 120.0.0)

Also I looked at links of the libcudart library-

$ otool -L /usr/local/cuda/lib/libcudart.7.0.dylib /usr/local/cuda/lib/libcudart.7.0.dylib: @rpath/libcudart.7.0.dylib (compatibility version 0.0.0, current version 7.0.29) /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation (compatibility version 150.0.0, current version 855.17.0) /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1197.1.1)

In both the outputs, library links seem to be broken. But make all and test are fine, this means dynamic linking is okay, loading is not?

May be the problem is environment variable related, my variables are- $ echo $DYLD_FALLBACK_LIBRARY_PATH /usr/local/cuda/lib:/Developer/NVIDIA/CUDA-7.0/lib:/Users/deepsamal/anaconda/lib:/usr/local/lib:/usr/lib:/opt/intel/composer_xe_2015.2.132/mkl/lib/:/opt/intel/composer_xe_2015.2.132/compiler/lib

$ echo $DYLD_LIBRARY_PATH /usr/local/cuda/lib

$ echo $LD_LIBRARY_PATH /usr/local/cuda/lib:/opt/intel/composer_xe_2015.2.132/mkl/lib/

$ ECHO $PATH /Developer/NVIDIA/CUDA-7.0/bin:/Users/deepsamal/anaconda/bin:/Applications/MATLAB_R2014a.app/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/git/bin

All advised paths are included, in fact, I even tried without setting LD_LIBRARY_PATH, same error. Any idea what might be the cause?

deepsamal avatar Apr 17 '15 01:04 deepsamal

I have exactly the same problem on my MacBookPro OS 10.10, CUDA 7.0. Any help will be much appreciated, thanks! =========== terminal output =========== sudo make runtest .build_release/tools/caffe dyld: Library not loaded: @rpath/libcudart.7.0.dylib Referenced from: /Developer/caffe/.build_release/tools/caffe Reason: image not found make: *** [runtest] Trace/BPT trap: 5

output from "env | grep LIB": DYLD_FALLBACK_LIBRARY_PATH=/usr/local/cuda/lib:/Applications/anaconda/lib:/usr/local/lib:/usr/lib LD_LIBRARY_PATH=/usr/local/lib DYLD_LIBRARY_PATH=/Developer/NVIDIA/CUDA-7.0/cudnn-6.5-osx-v2:/Developer/NVIDIA/CUDA-7.0/lib

iwen-kang avatar Apr 18 '15 01:04 iwen-kang

Follow the installation instructions and ask installation questions on the caffe-users group. You should not set DYLD_LIBRARY_PATH.

shelhamer avatar Apr 27 '15 07:04 shelhamer

This is bit old I guess. And I shouldn't be spamming with install advice but I just had the same problem. At the caffe user forum https://groups.google.com/forum/#!msg/caffe-users/BkMspfbYLIE/Pi6SUVANAKUJ someone said fix the DYLD_FALLBACK_LIBRARY_PATH variable for me it was just to add the /usr/local/cuda/lib as the first path

export DYLD_FALLBACK_LIBRARY_PATH=/usr/local/cuda/lib:/usr/local/lib:/usr/lib:/Developer/NVIDIA/CUDA-7.0/lib:

This worked for me.

MartinHjelm avatar Jun 02 '15 12:06 MartinHjelm

set DYLD_FALLBACK_LIBRARY_PATH solved my problem too

wlike avatar Aug 01 '15 04:08 wlike

I've set my DYLD_FALLBACK_LIBRARY_PATH as suggested and followed the advices from robertsdionne: echo $DYLD_FALLBACK_LIBRARY_PATH /usr/local/cuda/lib:/usr/local/lib:/Users/guigou/caffe/distribute/lib:/Developer/NVIDIA/CUDA-7.5/lib:

and I still get

ImportError                               Traceback (most recent call last)
<ipython-input-1-1cca3aa1f8c5> in <module>()
----> 1 import caffe

/Users/guigou/caffe/python/caffe/__init__.py in <module>()
----> 1 from .pycaffe import Net, SGDSolver, NesterovSolver, AdaGradSolver, RMSPropSolver, AdaDeltaSolver, AdamSolver
      2 from ._caffe import set_mode_cpu, set_mode_gpu, set_device, Layer, get_solver, layer_type_list
      3 from .proto.caffe_pb2 import TRAIN, TEST
      4 from .classifier import Classifier
      5 from .detector import Detector

/Users/guigou/caffe/python/caffe/pycaffe.py in <module>()
     11 import numpy as np
     12 
---> 13 from ._caffe import Net, SGDSolver, NesterovSolver, AdaGradSolver, \
     14         RMSPropSolver, AdaDeltaSolver, AdamSolver
     15 import caffe.io

ImportError: dlopen(/Users/guigou/caffe/python/caffe/_caffe.so, 2): Library not loaded: @rpath/libcudart.7.5.dylib
  Referenced from: /Users/guigou/caffe/python/caffe/_caffe.so
  Reason: image not found

gsabran avatar Oct 13 '15 05:10 gsabran

I have the exactly the same issue. I also already set

DYLD_LIBRARY_PATH DYLD_FALLBACK_LIBRARY_PATH

My version is also CUDA7.5. I think when I used CUDA7.0 before, everything is fine.

qiuwch avatar Oct 18 '15 00:10 qiuwch

Caffe seems to be linking in a pretty funny way ... If I run

otool -L .build_release/tools/caffe

I see something like this

.build_release/tools/caffe:
    @rpath/libcaffe.so (compatibility version 0.0.0, current version 0.0.0)
    /System/Library/Frameworks/Accelerate.framework/Versions/A/Accelerate (compatibility version 1.0.0, current version 4.0.0)
    @rpath/libcudart.7.5.dylib (compatibility version 0.0.0, current version 7.5.20)
    @rpath/libcublas.7.5.dylib (compatibility version 0.0.0, current version 7.5.20)
    @rpath/libcurand.7.5.dylib (compatibility version 0.0.0, current version 7.5.20)
    /usr/local/opt/glog/lib/libglog.0.dylib (compatibility version 1.0.0, current version 1.0.0)
    /usr/local/opt/gflags/lib/libgflags.2.dylib (compatibility version 2.0.0, current version 2.1.2)
    /usr/local/lib/libprotobuf.9.dylib (compatibility version 10.0.0, current version 10.1.0)
    /usr/local/lib/libboost_system.dylib (compatibility version 0.0.0, current version 0.0.0)
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1225.1.1)
    libhdf5_hl.10.dylib (compatibility version 11.0.0, current version 11.1.0)
    libhdf5.10.dylib (compatibility version 11.0.0, current version 11.1.0)
        ...

So some library paths are static, others are run-time paths and others are just assumed to be in the executable path (which they aren't). Unfortunately, in my case at least there are not rpath's set for either the executables or the libcaffe :( Just check `otool -l .build_release/tools/caffe | grep RPATH'

If you need a quick and dirty fix, you can add your CUDA path as an rpath

install_name_tool -add_rpath /usr/local/cuda/lib .build_release/tools/caffe
install_name_tool -add_rpath /usr/local/cuda/lib .build_release/test/test_all.testbin
install_name_tool -add_rpath /usr/local/cuda/lib .build_release/lib/libcaffe.so

With that I can run make runtest, but you should do the same for a few more files (mostly every caffe binary and also libcaffe.so) if you want to use them. And I also expect trouble with the HDF5 libraries at some point, but you can also use install_name_tool to fix those issues. Anyway, the most reasonable option is to fix the Makefile to do a proper job in OS X.

dg2 avatar Oct 20 '15 16:10 dg2

If you are installing on OS X El Capitan, DYLD_FALLBACK_LIBRARY_PATH is cleared by the new System Integrity Protection feature of El Capitan:

https://developer.apple.com/library/watchos/documentation/Security/Conceptual/System_Integrity_Protection_Guide/System_Integrity_Protection_Guide.pdf

make runtest completed successfully after I disabled System Integrity Protection.

cecilpang avatar Oct 29 '15 04:10 cecilpang

@cecilpang Thanks for your tips and it really helps. here is the steps to disable Integrity Protection:

  1. Boot to Recovery OS by restarting your machine and holding down the Command and R keys at startup.
  2. Launch Terminal from the Utilities menu.
  3. Enter the following command: $ csrutil disable 4.restart done

a7744hsc avatar Oct 30 '15 12:10 a7744hsc

@a7744hsc @cecilpang Your solutions resolved my problem. Thanks!

jiajunshen avatar Dec 16 '15 08:12 jiajunshen

@jiajunshen Very glad to hear that

a7744hsc avatar Dec 17 '15 10:12 a7744hsc

Worked... but so annoying! And now what about my system's integrity? Will I ever be able to trust it again?

cchriste avatar Dec 18 '15 00:12 cchriste

Before you run 'make runtest', do 'make clean' once.

shal233 avatar Mar 02 '16 00:03 shal233

@a7744hsc @cecilpang Your solutions resolved my problem too. Many thanks! BTW, Is there any other possible walk-around without disabling the Integrity Protection of Mac OS?

fanshiqing avatar May 18 '16 14:05 fanshiqing

Shouldn't this maybe be reopened, since there is no good fix for this? (I don't consider disabling the Mac OS X Integrity Protection a good fix...)

kmhofmann avatar Jun 04 '16 11:06 kmhofmann

Please refer https://github.com/BVLC/caffe/issues/3227 for a workaround without disabling Integrity protection on OSX 10.11.

mkmohangb avatar Jun 18 '16 21:06 mkmohangb

What should be the fix if there is no cuda gpu?

apuljain avatar Nov 21 '16 08:11 apuljain