Found an error while trying PyOpenCL and PyCuda at my workplace recently. Solved it after googling around, thinking wanna record it as a blog post to help peoples who face the same problem.

I’m using Ubuntu Gnome 15.04. PyOpenCL and PyCuda is installed from Ubuntu’s repo.

The problem is after you installed PyOpenCL and run the sample code:

import pyopencl as cl
cl.get_platforms()

You will get an error message:

Traceback (most recent call last):
  File "", line 1, in 
pyopencl.LogicError: clGetPlatformIDs failed: platform not found khr

If you try to run PyCuda’s sample code:

import pycuda.driver as cuda
import pycuda.autoinit

You will get another error message:

Traceback (most recent call last):
  File "", line 1, in 
  File "/usr/lib/python3/dist-packages/pycuda/autoinit.py", line 4, in 
    cuda.init()
pycuda._driver.Error: cuInit failed: unknown

This is due to a bug listed here. To fix the problem, just simply install nvidia-modprobe package

sudo apt-get install nvidia-modprobe

A kernel module nvidia_urm will be built and inserted into the kernel automatically.

Now try to run the PyOpenCL sample code again and you’ll something like this:

[pyopencl.Platform 'NVIDIA CUDA' at 0x2e42200]