【问题标题】:"invalid configuration argument " error for the call of CUDA kernel?调用 CUDA 内核时出现“无效的配置参数”错误?
【发布时间】:2013-04-20 21:31:00
【问题描述】:

这是我的代码:

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 只是打印错误代码的相应字符串消息。这部分代码在内核调用之后给出了配置错误。

什么可能导致这个错误,你知道吗?

【问题讨论】:

    标签: cuda


    【解决方案1】:

    这种类型的错误消息通常是指启动配置参数(在这种情况下是网格/线程块尺寸,在其他情况下也可能是共享内存等)。当您看到这样的消息时,最好在启动内核之前打印出您的实际配置参数,看看您是否犯了任何错误。

    你说BLOCKDIM = 512。你有threadNum = BLOCKDIM/8所以threadNum = 64。你的线程块配置是:

    dim3 dimBlock(threadNum,threadNum);
    

    所以您要求启动 64 x 64 线程的块,即每个块 4096 个线程。这不适用于任何一代的 CUDA 设备。当前所有 CUDA 设备都限制为每个块最多 1024 个线程,这是 3 个块维度的乘积。

    CUDA 编程指南的table 14 中列出了最大尺寸,也可通过deviceQuery CUDA 示例代码获得。

    【讨论】:

    • 我知道我的卡为每个块配置了 1024 个线程。 32*32 2D配置和1D 1024线程配置一样吗?
    • 1024 个线程是每个块的限制。您可以拥有不超过此值的任何 1D、2D 或 3D 尺寸集。所以 1024x1、512x2、256x4、128x8 等都是可接受的 2D 限制。对于 3D 也是如此,例如16x8x8、32x8x4、64x4x4 等都是可接受的 3D 限制。 deviceQuery cuda 样本将提供有关总和每个维度限制的信息。但无论每个维度的限制如何,实际总产品不能超过总限制 1024 或任何适合您设备的限制。
    【解决方案2】:

    除了前面的答案,您还可以找到代码中允许的最大线程数,因此它可以在其他设备上运行,而无需硬编码您将使用的线程数:

    struct cudaDeviceProp properties;
    cudaGetDeviceProperties(&properties, device);
    cout<<"using "<<properties.multiProcessorCount<<" multiprocessors"<<endl;
    cout<<"max threads per processor: "<<properties.maxThreadsPerMultiProcessor<<endl;
    

    【讨论】:

    • maxThreadsPerMultiProcessor 对于大多数 CUDA GPU 来说是 2048,并且没有表明任何关于线程块级别限制的信息,这就是这个问题中正在讨论的内容
    • device 来自哪里?
    • @BitTickler 我发现这是您设备的索引。如果您只有一个 GPU,则通常为 0。
    猜你喜欢
    • 1970-01-01
    • 2016-03-24
    • 1970-01-01
    • 1970-01-01
    • 2014-01-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多