“无效的配置参数”错误?
问题描述:
这里是我的代码:“无效的配置参数”错误?
int threadNum = BLOCKDIM/8;
dim3 dimBlock(threadNum,threadNum);
int blocks1 = nWidth/threadNum + (nWidth%threadNum == 0 ? 0 : 1);
int blocks2 = nHeight/threadNum + (nHeight%threadNum == 0 ? 0 : 1);
dim3 dimGrid;
dimGrid.x = blocks1;
dimGrid.y = blocks2;
// dim3 numThreads2(BLOCKDIM);
// dim3 numBlocks2(numPixels/BLOCKDIM + (numPixels%BLOCKDIM == 0 ? 0 : 1));
perform_scaling<<<dimGrid,dimBlock>>>(imageDevice,imageDevice_new,min,max,nWidth, nHeight);
cudaError_t err = cudaGetLastError();
cudasafe(err,"Kernel2");
这是我的第二个内核的执行,它是在数据的使用期限完全独立。 BLOCKDIM
是512,nWidth and nHeight
也是512并且cudasafe
只是简单地打印错误代码的相应字符串消息。代码的这一部分在内核调用之后发生配置错误。
什么可能会给这个错误,任何想法?
答
此类型的错误消息经常指的是启动配置参数(网格/在这种情况下threadblock尺寸,也可以共享存储器等在其他情况下)。当你看到这样的消息时,在启动内核之前打印出你的实际配置参数是一个好主意,看看你是否犯了什么错误。
你说BLOCKDIM
= 512你有threadNum = BLOCKDIM/8
所以threadNum
= 64你threadblock配置为:
dim3 dimBlock(threadNum,threadNum);
所以你要求推出的64×64个线程块,即每块4096个线程。这对任何一代CUDA设备都无效。
答
只需添加到以前的答案,你可以找到允许在你的代码也是最大线程数,因此它可以在其他设备没有硬编码您将使用的线程数运行:
struct cudaDeviceProp properties;
cudaGetDeviceProperties(&properties, device);
cout<<"using "<<properties.multiProcessorCount<<" multiprocessors"<<endl;
cout<<"max threads per processor: "<<properties.maxThreadsPerMultiProcessor<<endl;
我知道我的卡每块有1024个线程的配置。拥有32 * 32 2D配置和havin 1D 1024线程配置是否一样? – erogol 2013-04-20 21:47:48
1024个线程是以每个块为基础的限制。您可以拥有任何不超过此尺寸的一维,二维或三维尺寸。因此1024x1,512x2,256x4,128x8等都是可以接受的2D限制。类似地,对于3D,例如16x8x8,32x8x4,64x4x4等都是可以接受的3D限制。 'deviceQuery' cuda示例将提供关于总体和每维度限制的信息。但是,无论每个尺寸限制如何,实际的总产品数量都不能超过总限制1024或适用于您的设备的任何限制。 – 2013-04-20 21:52:16