title: Theano with opencl GPU
body: <p>I have configured <code>theano</code> as follows:</p>
  
  <pre><code>[idf@localhost python]$ more ~idf/.theanorc 
  [global]
  device = opencl0:0
  floatX = float32
  
  [lib]
  cnmem=100
  [idf@localhost python]$
  </code></pre>
  
  <p>I also needed to</p>
  
  <pre><code>[idf@localhost python]$ export MKL_THREADING_LAYER=GNU
  </code></pre>
  
  <p>although interestingly enough, if I install <code>openblas</code> and add</p>
  
  <pre><code>[blas]
  ldflags = -lopenblas
  </code></pre>
  
  <p>to the <code>.theanorc file</code>, I no longer need to:</p>
  
  <pre><code>export MKL_THREADING_LAYER=GNU
  </code></pre>
  
  <p>Using a program I found on the internet which I modified slightly to use <code>gpuarray</code>, I am attempting to use <code>theano</code> with an <code>Intel</code> <code>GPU</code> through <code>opencl</code>:</p>
  
  <pre><code>import os
  import shutil
  
  
  from theano import function, config, shared, gpuarray
  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 xrange(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')
  </code></pre>
  
  <p>When I run the program, it seems as if it recognizes the <code>GPU</code>, but at the end the message "used the cpu" is printed.</p>
  
  <pre><code>[idf@localhost python]$ python theanoexam1.py 
  Mapped name None to device opencl0:0: Intel(R) HD Graphics 5500 BroadWell U-Processor GT2 
  [GpuElemwise{exp,no_inplace}(&lt;GpuArrayType&lt;None&gt;(float32, vector)&gt;), HostFromGpu(gpuarray)(GpuElemwise{exp,no_inplace}.0)]
  Looping 1000 times took 1.231896 seconds
  Result is [ 1.23178029  1.61879337  1.52278054 ...,  2.20771813  2.29967737
    1.62323284]
  Used the cpu
  [idf@localhost python]$ 
  </code></pre>
  
  <p>I am skeptical of the message "used the cpu": 1.231896 seconds seems fast for an <code>Intel i3</code> with four <code>cores</code>.</p>
  
  <p>Is there an extra configuration that is needed to use <code>opencl</code> with <code>theano</code>? Or did this program indeed show that <code>theano</code> is configured to use  the <code>GPU</code> through <code>opencl</code>?</p>