Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

dyld: Library not loaded: @rpath/libcudart.8.0.dylib, while building tensorflow on Mac OSX

I am building tensorflow on my Mac(an hackintosh, so I have a GPU, and already installed CUDA8.0. It works fine with building caffe, so I am sure it works.) I have already set up the environment variables as following(I have put these in .zshrc,.bash_profile and .bashrc):

export CUDA_HOME=/usr/local/cuda
export DYLD_LIBRARY_PATH="$DYLD_LIBRARY_PATH:$CUDA_HOME/lib"
export PATH="$CUDA_HOME/bin:$PATH"
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$CUDA_HOME/lib:$CUDA_HOME/extras/CUPTI/lib"

./configure works fine. Then I start build using command bazel build -c opt --config=cuda //tensorflow/tools/pip_package:build_pip_package. Then I got this error:

    ERROR: /Development/tensorflow/tensorflow/python/BUILD:572:1: Executing genrule //tensorflow/python:array_ops_pygenrule failed: bash failed: error executing command /bin/bash -c ... (remaining 1 argument(s) skipped): com.google.devtools.build.lib.shell.AbnormalTerminationException: Process terminated by signal 5.
dyld: Library not loaded: @rpath/libcudart.8.0.dylib
  Referenced from: /private/var/tmp/_bazel_zarzen/bdf1cb43f3ff02468b610730bd03f348/execroot/tensorflow/bazel-out/host/bin/tensorflow/python/gen_array_ops_py_wrappers_cc
  Reason: image not found
/bin/bash: line 1: 92702 Trace/BPT trap: 5       bazel-out/host/bin/tensorflow/python/gen_array_ops_py_wrappers_cc @tensorflow/python/ops/hidden_ops.txt 1 > bazel-out/local_darwin-opt/genfiles/tensorflow/python/ops/gen_array_ops.py
Target //tensorflow/tools/pip_package:build_pip_package failed to build

I can make sure the missed library is there. And I also tried install pre-built binary(I know it only support CUDA7.5, so I set up the PATH to point to CUDA7.5, but it doesn't work. when I try to import tensorflow, similar error Library not loaded: @rpath/libcudart.7.5.dylib, only version number changed).

I don't know why it cannot find the lib. Anyone can help? or any suggestions?

like image 314
Zen Avatar asked Oct 05 '16 03:10

Zen


1 Answers

The following should fix the error.

Find the file "genrule-setup.sh". The file should be in

<tensorflow source dir>/bazel-tensorflow/external/bazel_tools/tools/genrule/

If the timestamp of this file changes then bazel build will fail saying the file is corrupted. So before modifying this file make a note of the timestamp

stat genrule-setup.sh

You should get an output like this:

16777220 25929227 -rwxr-xr-x 1 user wheel 0 242 "Oct 12 23:46:28 2016" "Oct 10 21:49:39 2026" "Oct 12 21:49:39 2016" "Oct 12 21:49:38 2016" 4096 8 0 genrule-setup.sh

Note down the second timestamp "Oct 10 21:49:39 2026" from the above output

edit the genrule-setup.sh file

nano genrule-setup.sh

and add the environment configuration to the end of the file

export DYLD_LIBRARY_PATH=/usr/local/cuda/lib

save and close the editor.

Then change the timestamp to the original timestamp

touch -t YYYYMMDDhhmm.SS genrule-setup.sh

for e.g.

touch -t 202610102149.39 genrule-setup.sh

Finally, create a symbolic link to avoid "Segmentation fault: 11" error

ln -sf /usr/local/cuda/lib/libcuda.dylib /usr/local/cuda/lib/libcuda.1.dylib

Now restart the build

bazel build -c opt --config=cuda //tensorflow/tools/pip_package:build_pip_package
like image 91
Vijay Avatar answered Sep 18 '22 14:09

Vijay