Ubuntu 12.04. Error: cudaGetDeviceCount returned 30

Hello.

I try to use CUDA 6.0.37 under LunaOS (based on Ubuntu 12.04.) with core i5 and 540M. I use nvidia-331 with bumblebee. I installed the Package Manager installation of CUDA on x64, using the .deb and with apt-get install cuda after installing and updating bumblebee.

Bumblebee works (e.g. with glxspheres), but not with cuda applications.

How can I fix that?

When I run ./deviceQuery I get this result (the output without sudo is the same):

$ sudo optirun ./deviceQuery 
./deviceQuery Starting...

 CUDA Device Query (Runtime API) version (CUDART static linking)

FATAL: Module nvidia_uvm not found.
cudaGetDeviceCount returned 30
-> unknown error
Result = FAIL

when I try ./clock I get thits:

$ sudo optirun ./clock 
CUDA Clock sample
FATAL: Module nvidia_uvm not found.
CUDA error at ../../common/inc/helper_cuda.h:905 code=30(cudaErrorUnknown) "cudaGetDeviceCount(&device_count)"

thanks for help - greetings
Vadammt

Could try to first see if you have the missing module by running:

sudo modinfo nvidia-uvm

and post the output. If this provides info on the module, please try to load the module by

sudo modprobe -v nvidia-uvm

And post the output of this command. If the device query does not work after the modprobe command

Update

331 is not specific enough. There was a bug in 331.67 with these properties, that have been fixed in 331.79. Please check your drivers minor version. You can also verify that this is the issue by running:

modprobe --force-modversion nvidia-uvm

Which should bring cuda back online, if an outdated driver is your issue. In that case, you should uopdate your driver!

For more info:

https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=747366

I noticed I dont have nvidia-uvm - but I have nvidia-331-uvm. nvidia-uvm has no install packet so I have no clue what to do now.
The link you posted doesnt seem to concern my issue, does it?

$ sudo modinfo nvidia-uvm
ERROR: modinfo: could not find module nvidia-uvm

Here’s my output of your mentioned commands with nvidia-uvm-331 (I assume you forgot sudo at the last command):

$ sudo modinfo nvidia-331-uvm 
filename:       /lib/modules/3.2.0-65-generic/extra/nvidia-331-uvm.ko
supported:      external
license:        MIT
srcversion:     C73F1022BA9FD9403D7EA16
depends:        nvidia
vermagic:       3.2.0-65-generic SMP mod_unload modversions 

$ sudo modprobe -v nvidia-331-uvm 
insmod /lib/modules/3.2.0-65-generic/extra/nvidia-331-uvm.ko 

$ sudo modprobe --force-modversion nvidia-331-uvm 
FATAL: Error inserting nvidia_331_uvm (/lib/modules/3.2.0-65-generic/extra/nvidia-331-uvm.ko): Invalid module format

Thank you very much for the help.

I fixed my problem :)

x86_64-linux-gnu_gl_conf was set to mesa. So I switched to auto mode but that crashed my XServer. Now I’m using nvidia-331-prime and it works!

$ sudo update-alternatives --config x86_64-linux-gnu_gl_conf
  Selection    Path                                       Priority   Status
------------------------------------------------------------
  0            /usr/lib/nvidia-331/ld.so.conf              8604      auto mode
* 1            /usr/lib/nvidia-331-prime/ld.so.conf        8603      manual mode
  2            /usr/lib/nvidia-331/ld.so.conf              8604      manual mode
  3            /usr/lib/x86_64-linux-gnu/mesa/ld.so.conf   500       manual mode

The result by using optirun with nvidia-331-prime:

$ opoptirun ./deviceQuery 
./deviceQuery Starting...

 CUDA Device Query (Runtime API) version (CUDART static linking)

Detected 1 CUDA Capable device(s)

Device 0: "GeForce GT 540M"
  [GPU stats ...]

deviceQuery, CUDA Driver = CUDART, CUDA Driver Version = 6.0, CUDA Runtime Version = 6.0, NumDevs = 1, Device0 = GeForce GT 540M
Result = PASS

Again: Thank you for the modinfo hint. Without this I could never get CUDA running.

Thanks vadammt, this worked for me as well (ASUS Zenbook with GeForce 840M).

Great thread!

I’m running ubuntu 15.04 wiith nvidia-346-updates driver together with bumblebee and fell into exactly the same problem. Finally @vadammt 's method really helps.

It’s worth noting that it is necessary to run any one of cuda program or ldconfig as root first time before everything is ok.

https://devtalk.nvidia.com/default/topic/699610/linux/334-21-driver-returns-999-on-cuinit-cuda-/post/4168702/#4168702
See post #7 and #8… the reason first run as root is needed is because the nodes are not created or created correctly.

I attached the modified script I made for my laptop running 14.04 and the corresponding udev rule. (remove the *.txt extension)
nvidia-uvm-probe.txt (132 Bytes)
01-nvidia-uvm.rules.txt (61 Bytes)

I have the same problem with you and your solution is really helpful. Could you explain how you figure out this solution? I always confused with these things:) Thank you.

excuse me, I also got the same problem.But i install cuda-8.0 on ubuntu14.04
when I want to try NVIDIA_CUDA-8.0_Samples/bin/x86_64/linux/release, got error.
run ./deviceQuery , I get this result.
How can I fix it?

./deviceQuery Starting...

CUDA Device Query (Runtime API) version (CUDART static linking)

cudaGetDeviceCount returned 30


-> unknown error
Result = FAIL

sudo modinfo nvidia-uvm

filename:       /lib/modules/4.4.0-31-generic/updates/dkms/nvidia-uvm.ko
supported:      external
license:        MIT
srcversion:     A818A16BB09EF4EBB6FA5C7
depends:        nvidia
vermagic:       4.4.0-31-generic SMP mod_unload modversions 
parm:           uvm_perf_prefetch_enable:uint
parm:           uvm_perf_prefetch_threshold:uint
parm:           uvm_perf_prefetch_min_faults:uint
parm:           uvm_perf_thrashing_enable:uint
parm:           uvm_perf_thrashing_threshold:uint
parm:           uvm_perf_thrashing_pin_threshold:uint
parm:           uvm_perf_thrashing_lapse_usec:uint
parm:           uvm_perf_thrashing_nap_usec:uint
parm:           uvm_perf_thrashing_epoch_msec:uint
parm:           uvm_perf_thrashing_max_resets:uint
parm:           uvm_hmm:Enable (1) or disable (0) HMM mode. Default: 0. Ignored if CONFIG_HMM is not set, or if NEXT settings conflict with HMM. (int)
parm:           uvm_global_oversubscription:Enable (1) or disable (0) global oversubscription support. (int)
parm:           uvm_leak_checker:Enable uvm memory leak checking. 0 = disabled, 1 = count total bytes allocated and freed, 2 = per-allocation origin tracking. (int)
parm:           uvm_force_prefetch_fault_support:uint
parm:           uvm_debug_enable_push_desc:Enable push description tracking (int)
parm:           uvm_page_table_location:Set the location for UVM-allocated page tables. Choices are: vid, sys. (charp)
parm:           uvm_perf_reenable_prefetch_faults_lapse_msec:uint
parm:           uvm_perf_fault_batch_count:uint
parm:           uvm_perf_fault_replay_policy:uint
parm:           uvm_perf_fault_max_batches_per_service:uint
parm:           uvm_perf_fault_max_throttle_per_service:uint
parm:           uvm_fault_force_sysmem:Force (1) using sysmem storage for pages that faulted. Default: 0. (int)
parm:           uvm_enable_debug_procfs:Enable debug procfs entries in /proc/driver/nvidia-uvm (int)
parm:           uvm_prefetch_stats:int
parm:           uvm_prefetch_threshold:int
parm:           uvm_prefetch_adaptive:int
parm:           uvm_prefetch_epoch:int
parm:           uvm_prefetch_sparsity_inc:int
parm:           uvm_prefetch_sparsity_dec:int
parm:           uvm_prefetch:int
parm:           uvm_driver_mode:Set the uvm kernel driver mode. Choices include: 8 (charp)
parm:           uvm_debug_prints:Enable uvm debug prints. (int)
parm:           uvm_enable_builtin_tests:Enable the UVM built-in tests. (This is a security risk) (int)

sudo modprobe -v nvidia-uvm

insmod /lib/modules/4.4.0-31-generic/updates/dkms/nvidia_340.ko 
insmod /lib/modules/4.4.0-31-generic/updates/dkms/nvidia_340_uvm.ko 
modprobe: ERROR: could not insert 'nvidia_340_uvm': Invalid argument

sorry, I am new to use ubuntu.
hope can help me,thanks
chun