# How to install Theano on Mac OS X EI Capitan with OpenCL support

I have two Mac, a Mac pro and Macbook pro. They both use AMD display card, so I can’t use CUDA speed up machine learning, so I want to use OpenCL.

First install some requirements:

Then make install environment ( use virtualenv can make everything easy ):

Install Theano:

Then you can use this demo code ( test.py ) to test your Theano:

This test will show something like this:

It just do some math 1000 time, took 1.492254 seconds, and use cpu.

Then we must install libgpuarray to make Theano support OpenCL:

Then we can use THEANO_FLAGS to set use OpenCL device.

Use OpenCL & Cpu in my Mac pro:

Note: Code showed “Used the gnu”, but as you can see, this was using CPU.

Use OpenCL & GPU 1 in My Mac pro:

Finally, we can use OpenCL and GPU.

Performance:

My Mac pro

My Macbook pro

Note: Now we can use Theano and OpenCL. But I was very sad, when I found out Theano is using CUNN, so when you use Theano to do Neural Network, we still need CUDA support. Just for now I don’t know how to solve this problem.

1. Zizhao Zhang

Very nice post. Thanks very much

2. Dave

Nice post, but still having some difficulties on my macbook Pro. After following the procedure it says:

TESTING CPU:

iMe:Theano df$THEANO_FLAGS=device=opencl0:0 python3 main.py ERROR (theano.sandbox.gpuarray): pygpu was configured but could not be imported NoneType [Elemwise{exp,no_inplace}(<TensorType(float64, vector)>)] Looping 1000 times took 1.881757 seconds Result is [ 1.23178032 1.61879341 1.52278065 …, 2.20771815 2.29967753 1.62323285] Used the cpu TESTING GPU: iMe:Theano df$ THEANO_FLAGS=device=opencl0:1 python3 main.py

ERROR (theano.sandbox.gpuarray): pygpu was configured but could not be imported
NoneType
[Elemwise{exp,no_inplace}(<TensorType(float64, vector)>)]

Looping 1000 times took 1.630929 seconds

Result is [ 1.23178032 1.61879341 1.52278065 …, 2.20771815 2.29967753
1.62323285]

Used the cpu

I must say that when I do the cmake .. command, it says:
cmake ..

— Could NOT find CUDA (missing: CUDA_TOOLKIT_ROOT_DIR CUDA_NVCC_EXECUTABLE CUDA_INCLUDE_DIRS CUDA_CUDART_LIBRARY)

— Could NOT find CLBLAS (missing: CLBLAS_LIBRARIES CLBLAS_INCLUDE_DIRS)

— Checking for one of the modules ‘check’