Reputation: 3
I have Nvidia geforce 310M and when i write this code
int main()
{
int dev;
cudaDeviceProp prop;
cudaGetDevice(&dev);
cudaGetDeviceProperties(&prop,dev);
cout << "Device name " << prop.name << endl;
cout << "warp size = " << prop.warpSize << endl;
cout << "mutiprocesosrs = " << prop.multiProcessorCount << endl;
return 0;
}
it writes :
Device name ♀
warp size = -2144521342
mutiprocesosrs = 0
Press any key to continue . . .
and every time i run this program it produces different warp size. how can i fix that ?
(p.s. I'm using visual studio 2010)
Upvotes: 0
Views: 576
Reputation: 5492
With this code you can check if, something with your cuda setup is wrong. (Taken from the cuda deviceQuery sample)
if (cudaGetDeviceCount((int*)&_deviceCount) != cudaSuccess)
{
printf("ERROR: CUDA Driver and Runtime version may be mismatched.\n");
return false;
}
// This function call returns 0 if there are no CUDA capable devices.
if (_deviceCount == 0)
{
printf("ERROR: There is no device supporting CUDA!\n");
return false;
}
_deviceProperties = SAVE_ALLOCATE(cudaDeviceProp, _deviceCount * sizeof(cudaDeviceProp));
for (unsigned int dev = 0; dev < _deviceCount; ++dev)
{
cudaGetDeviceProperties(&_deviceProperties[dev], dev);
printf("\nDevice %d: \"%s\"\n", dev, _deviceProperties[dev].name);
#if CUDART_VERSION >= 2020
// Console log
cudaDriverGetVersion(&_driverVersion);
printf(" CUDA Driver Version: %d.%d\n", _driverVersion/1000, _driverVersion%100);
cudaRuntimeGetVersion(&_runtimeVersion);
printf(" CUDA Runtime Version: %d.%d\n", _runtimeVersion/1000, _runtimeVersion%100);
#endif
printf(" CUDA Capability revision number: %d.%d\n",
_deviceProperties[dev].major,_deviceProperties[dev].minor);
}
you sould see if something is wrong ;)
Upvotes: 1
Reputation: 477680
Check first of all whether the function calls succeed!
cudaDeviceProp prop;
int dev;
if (cudaGetDevice(&dev) != cudaSuccess)
{
/* error */
abort();
}
if (cudaGetDeviceProperties(&prop, dev) != cudaSuccess)
{
/* error */
abort();
}
I made a little macro I use for calling all CUDA functions which takes care of the checking and throws a custom exception:
#define CUDACALL(F, ARGS...) do { e = F(ARGS); if (e != cudaSuccess) throw cudaException(#F, e); } while (false)
With this, I just say,
try
{
int dev;
cudaDeviceProp prop;
CUDACALL(cudaGetDevice, &dev);
CUDACALL(cudaGetDeviceProperties, &prop, dev);
// ...
}
catch (cudeException const & e)
{
std::cerr << "Cuda error: " << e.what() << "\n";
}
The exception class is defined as follows:
struct cudaException : public std::exception
{
cudaException(const std::string & str, cudaError_t err) : s(str), e(err) { }
~cudaException() throw() { }
virtual const char * what() const throw()
{
const std::string r = s + ": \"" + cudaGetErrorString(e) + "\" (" + (char)(e + '0') + ')';
return r.c_str();
}
private:
std::string s;
cudaError_t e;
};
Upvotes: 3