PyCUDA error: cuInit failed

Problem

After installing PyCUDA, I tried to run a sample PyCUDA program and got this error:

$ python hello_cuda.py
Traceback (most recent call last):
  File "hello_cuda.py", line 1, in <module>
    import pycuda.autoinit
  File "/usr/local/lib/python2.7/dist-packages/pycuda/autoinit.py", line 4, in <module>
    cuda.init()
pycuda._driver.Error: cuInit failed: unknown

Solution

The error refers to line 4 in /usr/local/lib/python2.7/dist-packages/pycuda/autoinit.py. The lines relevant to that error in the file are:

import pycuda.driver as cuda
cuda.init()

So, CUDA initialization is failing for some reason. After a bit of Googling, I found that this means that the necessary (CUDA? NVIDIA?) modules were not being loaded into the kernel. NVIDIA provides a modprobe package that can auto-load modules into the kernel as needed.

I installed this package:

$ sudo apt-get install nvidia-modprobe

CUDA was able to initialized immediately after this package was installed, no reboot was needed.

Tried with: PyCUDA 2014.1, CUDA 5.5, NVIDIA 331 drivers, GTX Titan and Ubuntu 14.04

Advertisements

One thought on “PyCUDA error: cuInit failed”

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s