Search code examples
python-2.7gputheanotheano-cuda

How to use theano with GPU on OSX?


OS: OSX 10.11.4

GPU: GeForce GT 750M, CUDA7.5

Language: Python Anaconda 2.7

I have followed theano's instructions to setup CUDA on my Mac:

  1. set PATH: export PATH=/Developer/NVIDIA/CUDA-7.5/bin:$PATH
  2. set LD_LIBRARY_PATH: export LD_LIBRARY_PATH=/Developer/NVIDIA/CUDA-7.5/lib:$LD_LIBRARY_PATH
  3. created a .theanorc file and add CUDA_ROOT=/Developer/NVIDIA/CUDA-7.5 in [cuda] section

I copied the code from theano website and pasted it into test.py file:

from theano import function, config, shared, sandbox
import theano.tensor as T
import numpy
import time

vlen = 10 * 30 * 768  # 10 x #cores x # threads per core
iters = 1000

rng = numpy.random.RandomState(22)
x = shared(numpy.asarray(rng.rand(vlen), config.floatX))
f = function([], T.exp(x))
print(f.maker.fgraph.toposort())
t0 = time.time()
for i in range(iters):
    r = f()
t1 = time.time()
print("Looping %d times took %f seconds" % (iters, t1 - t0))
print("Result is %s" % (r,))
if numpy.any([isinstance(x.op, T.Elemwise) for x in f.maker.fgraph.toposort()]):
    print('Used the cpu')
else:
    print('Used the gpu')

But when I run this line:

THEANO_FLAGS='floatX=float32,device=gpu0,nvcc.fastmath=True' python test.py

I got this error:

nvcc fatal: The version ('70300') of the host compiler ('Apple clang') is not supported

and a warning looks like this:

WARNING (theano.sandbox.cuda): CUDA is installed, but device gpu0 is not available (error: cuda unavailable)

Is it something because of my Xcode version(it is Version 7.3)? How to solve this problem?


Solution

  • I fixed this error: "nvcc fatal: The version ('70300').." installing the last version of the CUDA SDK 7.5.27, for OSX 10.11.4