4

I am running the following code. However, I am getting output as Got error with code 38 test = 0 deviceCount= 0 Got error with code 38 test2 = 0 I have an NVIDIA GTX 690 graphics card on Ubuntu. Does that mean the driver is not activated?

#include <iostream>

using namespace std;
__device__ __constant__ float* data;

template<class T> void allocOnly(T* deviceDest, size_t numElem)
{
    cudaError_t errCode = cudaMalloc((void**)&deviceDest, numElem*sizeof(T));
    if(errCode != cudaSuccess) 
        cout << "Got error with code " << errCode << endl;
}

int main()
{
    float* test(0);
    allocOnly<float>(test,10);
    cout << "test = " << test << endl;
    int deviceCount = 0;
    cudaGetDeviceCount(&deviceCount);
    cout << "deviceCount= " << deviceCount << endl;

    float* test2(0);    
    cudaError_t errCode = cudaMalloc((void**)&test2, 10*sizeof(float));
    if(errCode != cudaSuccess) 
        cout << "Got error with code " << errCode << endl;
    cout << "test2 = " << test2 << endl;

    return 0;
}
vkaul11
  • 4,098
  • 12
  • 47
  • 79
  • I don't know if that helps, but if you are running ubuntu on a recent laptop you may need Bumblebee because of Nvidia Optimus, in order to install drivers. – Brugere Jul 18 '13 at 16:34

2 Answers2

2

Yes, there is a problem with your system setup. Try running nvidia-smi -a from a terminal and see what it reports.

You should be doing proper cuda error checking on the call to cudaGetDeviceCount (and all cuda API calls and kernel calls). The error returned from that API call would also be instructive.

It would also make sense to me to perform the call to cudaGetDeviceCount before any other cuda API calls (such as the call to cudaMalloc in allocOnly).

Community
  • 1
  • 1
Robert Crovella
  • 143,785
  • 11
  • 213
  • 257
  • Thanks Robert I got the error jumioadmin@cudaGPU:~/cuda-convnet$ nvidia-smi -a NVIDIA: could not open the device file /dev/nvidiactl (No such file or directory). Nvidia-smi has failed because it couldn't communicate with NVIDIA driver. Make sure that latest NVIDIA driver is installed and running. I have the .run files from the NVIDIA website. What else do I need to do to get it to run each time? – vkaul11 Jul 17 '13 at 01:05
  • I'm not sure what you're asking. You may need to instantiate the necessary files by running something like `nvidia-smi` as a root user. Or maybe you just need to install the driver. Or maybe you are running into a conflict with a nouveau driver. I'm not really able to diagnose your system based on this information. Also, helping you get your system set up properly is off-topic for SO. You might want to read the linux [getting started guide](http://docs.nvidia.com/cuda/cuda-getting-started-guide-for-linux/index.html) as some of these topics are covered there. – Robert Crovella Jul 17 '13 at 01:10
  • The error returned from `cudaGetDeviceCount` would not be "instructive". That call is defined to always return `cudaSuccess`: See [the manual](https://www.cs.cmu.edu/afs/cs/academic/class/15668-s11/www/cuda-doc/html/group__CUDART__DEVICE_g665468e8cb33be42434f11bee2684ec9.html) – Chris Kitching Jul 30 '17 at 05:08
  • @ChrisKitching The manual you linked is quite old and is hosted by CMU, not NVIDIA. The current NVIDIA manual page is [here](http://docs.nvidia.com/cuda/cuda-runtime-api/group__CUDART__DEVICE.html#group__CUDART__DEVICE_1g18808e54893cfcaafefeab31a73cc55f) and it gives at least 2 situations where the "defined" return code may be different than `cudaSuccess`: 1. Note that this function may also return error codes from previous, asynchronous launches. 2. If no driver can be loaded to determine if any such devices exist then `cudaGetDeviceCount()` will return `cudaErrorInsufficientDriver`. – Robert Crovella Jul 30 '17 at 13:58
0

Execute the following command.. It should solve the problem..

sudo nvidia-xconfig --enable-all-gpus
Sagar Masuti
  • 1,271
  • 2
  • 11
  • 30