in Machine Learning

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

屏幕截图 2016-04-01 15.09.25

My Macbook pro

屏幕截图 2016-04-01 15.09.32

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.

Chinese version of this article.



Write a Comment

Comment

To create code blocks or other preformatted text, indent by four spaces:

    This will be displayed in a monospaced font. The first four 
    spaces will be stripped off, but all other whitespace
    will be preserved.
    
    Markdown is turned off in code blocks:
     [This is not a link](http://example.com)

To create not a block, but an inline code span, use backticks:

Here is some inline `code`.

For more help see http://daringfireball.net/projects/markdown/syntax

  1. 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 ..

    CUDA_TOOLKIT_ROOT_DIR not found or specified

    — 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’

    Tests disabled because Check was not found

    — Configuring done

    — Generating done

    — Build files have been written to: /Users/dfreire/Theano/libgpuarray/build

    I don’t know if have something to do with the problem….i don’t think I need CUDA on my laptop (Intel Iris 1536 MB) Can you give me a piece of advice? Thanks in advance.

    D.