2

I've set up pyopencl on my laptop by getting python-pyopencl from multiverse and installing the amd app sdk. To get the Nvidia ICDs I reinstalled the latest Nvidia driver from the driver manager.

My system is a Thinkpad t540p, i7 4700hq, Nvidia gt 730m, 64bit Ubuntu 14.04

To test the opencl installation I ran this pyopencl example: http://wiki.tiker.net/PyOpenCL/Examples/MatrixMultiply

Unfortunately the performance is very bad: Only 2 GFlop/s. Surely the laptop can do better. So I printed the vendor information. It's "GenuineIntel", apparently the kernel is not run on the GPU, but on the CPU. How can I change that ?

It seems like pyopencl doesn't find the GPU.

for dev in ctx.devices:
    print dev.vendor

this returns only "GenuineIntel"

The context is created with:

import pyopencl as cl
ctx=cl.create_some_context()

UPDATE:

This seems to be a duplicate of: ERROR: pyopencl: creating context for specific device

Community
  • 1
  • 1
lhk
  • 27,458
  • 30
  • 122
  • 201

1 Answers1

3

There are two issues here.

First, you should specify GPU as the device to execute the kernel on. Replace:

ctx = cl.create_some_context()

with:

platform = cl.get_platforms()
gpus = platform[0].get_devices(device_type=cl.device_type.GPU)
ctx = cl.Context(devices=gpus)

Second, you appear to have Optimus switchable graphics, so the NVIDIA card is actually left in standby and all the graphic tasks are handled by the CPU for powersaving. You will need to activate the discrete GPU for your program by launching it using Bumblebee:

optirun python yourscript.py
Stefano Sanfilippo
  • 32,265
  • 7
  • 79
  • 80
  • thanks, this works. Incredible, you solved the problem in barely 10mins – lhk Jul 26 '14 at 11:11
  • interestingly, my first platform is the cpu. I have to choose platform[1] or else this fails with the error message that no gpu was found – lhk Jul 26 '14 at 11:12
  • (removed the edit because the documentation is unclear about what happens in case no GPU is found on a platform and I cannot test the code right now). – Stefano Sanfilippo Jul 26 '14 at 11:22
  • If no device is found, the call creates a runtime error: pyopencl.RuntimeError: clGetDeviceIDs failed: device not found – lhk Jul 26 '14 at 11:26