Saturday, September 17, 2016

failed to find on this system: Failed precondition: could not dlopen DSO: libcuda.1.dylib

I got that error on my Mac OS X after I tried to do import tensorflow as tf. The solution is a bit hacky, but it's based on the fact that even though the system was unable to find libcuda.1.dylib, if you look in /usr/local/cuda/lib you find that libcuda.dylib does exist. So I simply did:

cd /usr/local/cuda/lib
sudo ln -s libcuda.dylib libcuda.1.dylib

And after that, import tensorflow as tf did not give me an error and I was able to verify that the GPU was in use by following the instructions under "Logging Device Placement" here.

Happy tensorflowing.

ld: framework not found CUDA

On the tensorflow installations instruction page, the following commands are listed as a way to verify the CUDA installation:
$ cp -r /usr/local/cuda/samples ~/cuda-samples
$ pushd ~/cuda-samples
$ make
$ popd
$ ~/cuda-samples/bin/x86_64/darwin/release/deviceQuery

However, when running the make command on my Mac, I got the following error:
ld: framework not found CUDA

Based on the instructions here, I made the following changes to fix it. As stated on that site, for every Makefile in ~/cuda-samples that had
-L$(CUDA_PATH)/lib -framework CUDA
we replace it with
-L$(CUDA_PATH)/lib -F/Library/Frameworks -framework CUDA
as shown below (it seems to be on line 201):

I found the list of files to make the change on using grep:
avmac:cuda-samples$ grep -r "framework CUDA" .
./0_Simple/clock_nvrtc/Makefile: LDFLAGS += -L$(CUDA_PATH)/lib -framework CUDA
./0_Simple/inlinePTX_nvrtc/Makefile: LDFLAGS += -L$(CUDA_PATH)/lib -framework CUDA
./0_Simple/matrixMul_nvrtc/Makefile: LDFLAGS += -L$(CUDA_PATH)/lib -framework CUDA
./0_Simple/simpleAtomicIntrinsics_nvrtc/Makefile: LDFLAGS += -L$(CUDA_PATH)/lib -framework CUDA
./0_Simple/simpleTemplates_nvrtc/Makefile: LDFLAGS += -L$(CUDA_PATH)/lib -framework CUDA
./0_Simple/simpleVoteIntrinsics_nvrtc/Makefile: LDFLAGS += -L$(CUDA_PATH)/lib -framework CUDA
./0_Simple/vectorAdd_nvrtc/Makefile: LDFLAGS += -L$(CUDA_PATH)/lib -framework CUDA
./4_Finance/binomialOptions_nvrtc/Makefile: LDFLAGS += -L$(CUDA_PATH)/lib -framework CUDA
./4_Finance/BlackScholes_nvrtc/Makefile: LDFLAGS += -L$(CUDA_PATH)/lib -framework CUDA
./4_Finance/quasirandomGenerator_nvrtc/Makefile: LDFLAGS += -L$(CUDA_PATH)/lib -framework CUDA

However, that wasn't enough. I also had to make the following change on line 139, where I change
-rpath $(CUDA_PATH)/lib
-rpath $(CUDA_PATH)/lib -F/Library/Frameworks
as shown below:

I had to make that change on the following files:

After that, the compilations worked and I was able to run deviceQuery. Then I ran sudo pip install --upgrade $TF_BINARY_URL, but I got two errors when I tried to import tensorflow in a python session: one error was about libcuda and the other was about protobuf. The solution to the libcuda problem I have explained in this post. For the protobuf sollution, I had to do a brew install protobuf followed by the following solution from this thread:
pip uninstall protobuf
pip install --upgrade