# Problems with CUDA

**URL:** <https://forums.developer.nvidia.com/t/problems-with-cuda/27535>\
**Category:** CUDA Programming and Performance\
**Created:** [December 2, 2012, 1:35am UTC](https://forums.developer.nvidia.com/t/problems-with-cuda/27535 "2012-12-02T01:35:32Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![temporary](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@temporary](https://forums.developer.nvidia.com/u/temporary)\
**Post date:** [December 2, 2012, 1:35am UTC](https://forums.developer.nvidia.com/t/problems-with-cuda/27535/1 "2012-12-02T01:35:32Z")

</div>

Hello!

I’m having a little problems with CUDA on my Gentoo PC. I’m currently using CUDA SDK / toolkit 4.2 and gcc 4.6.3. Everything compiled without problems, and when I try deviceQuery or bandwidthTest both of them pass.  
Hovewer, when I try to use engine-cuda or libgpucrypto I’m getting some strange errors:

Gentoo engine-cuda-master # openssl  
OpenSSL\> engine -t dynamic -pre SO\_PATH:/usr/local/lib/engines/libcudamrg.so -pre ID:cudamrg -pre LIST\_ADD:1 -pre LOAD  
(dynamic) Dynamic engine loading support  
[Success]: SO\_PATH:/usr/local/lib/engines/libcudamrg.so  
[Success]: ID:cudamrg  
[Success]: LIST\_ADD:1  
[Success]: LOAD  
Loaded: (cudamrg) OpenSSL engine for AES, DES, IDEA, Blowfish, Camellia and CAST5 with CUDA acceleration  
Successfully found 1 CUDA devices (CUDART\_VERSION 4020).  
Cuda error 10 in file ‘cuda\_common.cu’ in line 123: invalid device ordinal.

* * *

## Gentoo bin # ./aes\_test -m ENC

## AES-128-CBC ENC, Size: 16KB

#msg latency(usec) thruput(Mbps)  
aes\_test: aes\_context.cc:87: void aes\_context::cbc\_encrypt(const void\*, long unsigned int, long unsigned int, long unsigned int, long unsigned int, long unsigned int, unsigned char\*, long unsigned int, long unsigned int, unsigned int, unsigned int): Assertion `cudaGetLastError() == cudaSuccess’ failed.  
Aborted

If anyone could tell me what causes them that’d be awesome :)  
Thank you in advance for your help.

temporary

---

<div class="post-metadata">

**Author:** ![njuffa](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@njuffa](https://forums.developer.nvidia.com/u/njuffa)\
**Post date:** [December 2, 2012, 5:34am UTC](https://forums.developer.nvidia.com/t/problems-with-cuda/27535/2 "2012-12-02T05:34:24Z")

</div>

Unfortunately, you are not showing any code, so I can only guess that the “invalid device ordinal” is reported by a cudaSetDevice() or similar API call. I tried finding a file cuda\_common.cu in the OpenSSL source browser, but no such file seems to esit. Presumably the code tries to talk to a GPU using a certain device index, but no GPU with that index is known to the driver. If so, you need to find the device id for the GPU(s) in the system, and compare the device id passed to cudaSetDevice()against that list.

(1) Is this a system with multiple GPUs ?  
(2) That is the ouput of `lspci | grep nVidia` ?  
(3) What is the output of `ls /dev/nvidia*` ?  
(4) What is the output of `nvidia-smi -q` ?  
(5) Are you using the display driver required for CUDA 4.2 ?  
(6) Did you change GPUs after installing NVIDIA drivers ? If so, try installing the drivers again.  
(7) Check that the GPU(s) are correctly seated in their slots  
(8) Check that the GPU(s) are connected to the required number of power connectors (6-pin, 8-pin)

I am not familiar with Gentoo. Is this Linux version on CUDA 4.2’s list of supported platforms ? Does this Linux version require the blacklisting of nouveau drivers to use NVIDIA drivers ?

---

<div class="post-metadata">

**Author:** ![temporary](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@temporary](https://forums.developer.nvidia.com/u/temporary)\
**Post date:** [December 2, 2012, 11:24am UTC](https://forums.developer.nvidia.com/t/problems-with-cuda/27535/3 "2012-12-02T11:24:05Z")

</div>

Hello, njuffa!

Both of the codes are publicly available:  
[http://code.google.com/p/engine-cuda/](http://code.google.com/p/engine-cuda/)  
[http://shader.kaist.edu/sslshader/libgpucrypto/](http://shader.kaist.edu/sslshader/libgpucrypto/)

If you’d like to take a look, cuda\_common.cu is [HERE](http://pastebin.com/zAXeGM4q), and you were right, line 123 is: \_CUDA(cudaSetDevice(6));. I tried setting it to 0 and 1, but it didn’t change anything. How do I find the correct device index? deviceQuery from samples wasn’t much help.

As for the libgpucrypto: [HERE](http://pastebin.com/RbRn52Hn)’s the aes\_context.cc . Unfortunately, I have no idea what’s wrong with this one, and I think it would be most useful to me :(

1. Nope, I’m using single GTX 580.
2. 01:00.0 VGA compatible controller: NVIDIA Corporation GF110 [GeForce GTX 580] (rev a1)  
01:00.1 Audio device: NVIDIA Corporation GF110 High Definition Audio Controller (rev a1)
3. /dev/nvidia0 /dev/nvidiactl
4. I don’t have nvidia-smi, only nvidia-settings
5. I’m using the latest version of nvidia-drivers. Do you think compiling older version might help?
6. I tried rebuilding nvidia-drivers several times, didn’t help.  
7 & 8 - Done.

CUDA 4.2 is supported by Gentoo:

[I] dev-util/nvidia-cuda-sdk  
Available versions: 2.02.0807.1535^b ~2.1.1215.2015^b ~2.2^b ~2.2-r1^b ~2.3^b ~3.0\_beta1^b ~3.0^b ~3.1^b ~3.2^b ~4.0^b ~4.1^b (~)4.2 {{+cuda debug +doc emulation +examples opencl}}  
Installed versions: 4.2(03:11:37 12/02/12)(cuda debug doc examples opencl)  
Homepage: [http://developer.nvidia.com/cuda](http://developer.nvidia.com/cuda)  
Description: NVIDIA CUDA Software Development Kit

[I] dev-util/nvidia-cuda-toolkit  
Available versions: ~3.2^b 4.0^b ~4.1^b (~)4.2 {{debugger doc profiler}}  
Installed versions: 4.2(03:07:17 12/02/12)(debugger profiler -doc)  
Homepage: [http://developer.nvidia.com/cuda](http://developer.nvidia.com/cuda)  
Description: NVIDIA CUDA Toolkit

As for blacklisting nouveau - I don’t know, because I don’t use it anyway.

---

<div class="post-metadata">

**Author:** ![eyalhir74](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@eyalhir74](https://forums.developer.nvidia.com/u/eyalhir74)\
**Post date:** [December 2, 2012, 12:10pm UTC](https://forums.developer.nvidia.com/t/problems-with-cuda/27535/4 "2012-12-02T12:10:29Z")

</div>

Hi,  
Try to put the assert(cudaGetLastError() == cudaSuccess); before the kernel calls,  
lets say at line 38 and 54 and 63 to make sure if the problem didnt occur before the kernel.  
If the code passes 38, 54 and 63 than its something in the kernels themselves.  
If so, try to remove code from the AES\_cbc\_128\_encrypt\_gpu kernel and see if now it passes,  
open/close code in the kernel carefully as not to cause the compiler to remove the kernel code  
as part of its dead-code optimizations.

Also, seems that both kernel calls uses streams even though the if statement in line  
65 indicates there should be two paths: one with streams and the other without. Are you sure  
you’re not using the streamless path with an un-initialized stream?

Eyal

---

<div class="post-metadata">

**Author:** ![temporary](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@temporary](https://forums.developer.nvidia.com/u/temporary)\
**Post date:** [December 2, 2012, 1:20pm UTC](https://forums.developer.nvidia.com/t/problems-with-cuda/27535/5 "2012-12-02T13:20:42Z")

</div>

Hello!

## I put the code in the lines you wanted, and i still get:

## AES-128-CBC ENC, Size: 16KB

#msg latency(usec) thruput(Mbps)  
aes\_test: aes\_context.cc:87: void aes\_context::cbc\_encrypt(const void\*, long unsigned int, long unsigned int, long unsigned int, long unsigned int, long unsigned int, unsigned char\*, long unsigned int, long unsigned int, unsigned int, unsigned int): Assertion `cudaGetLastError() == cudaSuccess’ failed.  
Aborted

I can’t find AES\_cbc\_128\_encrypt\_gpu anywhere. As for your second question: I really don’t know. I was just following manual on the developers site, but it’s pretty lame.

---

<div class="post-metadata">

**Author:** ![njuffa](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@njuffa](https://forums.developer.nvidia.com/u/njuffa)\
**Post date:** [December 2, 2012, 6:06pm UTC](https://forums.developer.nvidia.com/t/problems-with-cuda/27535/6 "2012-12-02T18:06:22Z")

</div>

Thanks for posting the data. I don’t see anything out of place. Running an older CUDA runtime with the latest drivers should just work (I use that all the time when I work with older versions of CUDA), the other way around is what doesn’t work (i.e. newer CUDA runtime on top of older driver). Nothing appears to point to a problem with CUDA and/or the GPU, and as you stated in your original post you can successfully run some example CUDA codes.

Looks like you will have to debug this from the code itself. As eyalhir74 says, make sure all CUDA API calls are checked to make sure the reported error isn’t just a followup error to an earlier one upstream. I am not familiar with these codes. Do they use configuration files maybe that could be misconfugured for your platform, e.g. set up for multi-GPU while your machine has a single GPU? Is there an online forum for this software? If so, you may want to ask there to see whether anybody has run into the same or a similar problem.

---

<div class="post-metadata">

**Author:** ![temporary](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@temporary](https://forums.developer.nvidia.com/u/temporary)\
**Post date:** [December 2, 2012, 6:21pm UTC](https://forums.developer.nvidia.com/t/problems-with-cuda/27535/7 "2012-12-02T18:21:21Z")

</div>

They do use config files. I already tried contacting developer, but he didn’t respond :( There’s also very little documentation, and so far I haven’t seen anyone with such problem.

---

<div class="post-metadata">

**Author:** ![temporary](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@temporary](https://forums.developer.nvidia.com/u/temporary)\
**Post date:** [December 2, 2012, 8:44pm UTC](https://forums.developer.nvidia.com/t/problems-with-cuda/27535/8 "2012-12-02T20:44:32Z")

</div>

Good news everyone: I managed (with some help) to run engine-cuda. Turns out I had to change \_CUDA(cudaSetDevice(6)); to 0, as I did before, and COMPILE AGAIN (I don’t know why didn’t do before - I’m such a noob). Anyway, if someone knows how to fix libgpucrypto I’d be most grateful.

---

<div class="post-metadata">

**Author:** ![njuffa](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@njuffa](https://forums.developer.nvidia.com/u/njuffa)\
**Post date:** [December 3, 2012, 5:42pm UTC](https://forums.developer.nvidia.com/t/problems-with-cuda/27535/9 "2012-12-03T17:42:04Z")

</div>

Hardcoding the device ID in a cudaSetDevice() call inside an application strikes me as a bad idea, even when coding the device ID as 0, which probably is always valid if there is at least one CUDA device, but I am not sure that this is guaranteed. A better strategy would be to construct a list of all CUDA devices at startup, then pick the most appropriate one for the app from the list, and / or allow the user to specify the device ID of the GPU to use.

As for the problem with libgpucrypto(), the first step should be to dump the exact CUDA status at the point of failure, as right now it is only known that it is not cudaSuccess. Then debug from there.
