Code Yarns ‍👨‍💻
Tech BlogPersonal Blog

PyCUDA error: cuInit failed

📅 2015-Feb-24 ⬩ ✍️ Ashwin Nanjappa ⬩ 🏷️ cuda, error, pycuda ⬩ 📚 Archive


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

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


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

import pycuda.driver as cuda

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

© 2022 Ashwin Nanjappa • All writing under CC BY-SA license • 🐘📧