[英]When should I use CUDA's built-in warpSize, as opposed to my own proper constant?
[英]Cuda (warpSize is negative)
我有Nvidia geforce 310M,當我編寫此代碼時
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;
}
它寫道:
Device name ♀
warp size = -2144521342
mutiprocesosrs = 0
Press any key to continue . . .
每次我運行此程序時,它都會產生不同的變形大小。 我該如何解決?
(ps我正在使用Visual Studio 2010)
首先檢查函數調用是否成功!
cudaDeviceProp prop;
int dev;
if (cudaGetDevice(&dev) != cudaSuccess)
{
/* error */
abort();
}
if (cudaGetDeviceProperties(&prop, dev) != cudaSuccess)
{
/* error */
abort();
}
我制作了一個小宏,用於調用所有CUDA函數,該宏負責檢查並引發自定義異常:
#define CUDACALL(F, ARGS...) do { e = F(ARGS); if (e != cudaSuccess) throw cudaException(#F, e); } while (false)
有了這個,我只是說,
try
{
int dev;
cudaDeviceProp prop;
CUDACALL(cudaGetDevice, &dev);
CUDACALL(cudaGetDeviceProperties, &prop, dev);
// ...
}
catch (cudeException const & e)
{
std::cerr << "Cuda error: " << e.what() << "\n";
}
異常類的定義如下:
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;
};
使用此代碼,您可以檢查您的cuda設置是否錯誤。 (來自cuda deviceQuery示例)
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);
}
您會發現是否有問題;)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.