Saturday, September 17, 2016

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
to
-rpath $(CUDA_PATH)/lib -F/Library/Frameworks
as shown below:


I had to make that change on the following files:
./0_Simple/matrixMulDrv/Makefile
./0_Simple/simpleTextureDrv/Makefile
./0_Simple/simpleVoteIntrinsics/Makefile
./0_Simple/vectorAddDrv/Makefile
./1_Utilities/deviceQueryDrv/Makefile
./6_Advanced/ptxjit/Makefile
./6_Advanced/threadMigration/Makefile

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 https://storage.googleapis.com/tensorflow/mac/tensorflow-0.7.1-cp27-none-any.whl

1 comment:

  1. You can just run "$xcode-select --install" to fix "framework not found CUDA" error

    ReplyDelete