Search code examples
pythonubuntuopenclgpgpupyopencl

Why doesn't run OpenCL on my GPU (Ubuntu)


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


Solution

  • 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