【问题标题】:Some issue with Atomic add in CUDA kernel operation在 CUDA 内核操作中添加原子的一些问题
【发布时间】:2011-08-25 02:09:49
【问题描述】:

我的 kernel.cu 类有问题

致电nvcc -v kernel.cu -o kernel.o 我收到此错误:

kernel.cu(17): error: identifier "atomicAdd" is undefined

我的代码:

#include "dot.h"
#include <cuda.h>
#include "device_functions.h" //might call atomicAdd

__global__ void dot (int *a, int *b, int *c){
    __shared__ int temp[THREADS_PER_BLOCK];
    int index = threadIdx.x + blockIdx.x * blockDim.x;
    temp[threadIdx.x] = a[index] * b[index];

    __syncthreads();

    if( 0 == threadIdx.x ){
        int sum = 0;
        for( int i = 0; i<THREADS_PER_BLOCK; i++)
            sum += temp[i];
        atomicAdd(c, sum);
    }
}

有人建议?

【问题讨论】:

    标签: c atomic cuda


    【解决方案1】:

    您需要为nvcc 指定支持原子内存操作的架构(默认架构是1.0,不支持原子)。试试:

    nvcc -arch=sm_11 -v kernel.cu -o kernel.o
    

    看看会发生什么。


    在 2015 年编辑,注意 CUDA 7.0 中的默认架构现在是 2.0,它支持原子内存操作,因此在较新的工具包版本中这应该不是问题。

    【讨论】:

    • 另外,some atomic operations仅支持计算能力高于当前默认值的设备(例如仅cc 3.5支持,而当前默认值为2.0)。在这些情况下,仍然需要指定适当的 arch 选项,例如。 -arch=sm_35,此外,您不能指定多个 arch 选项,其中一些选项不符合使用中的原子所需的最低要求。
    【解决方案2】:

    今天使用最新的 cuda SDK 和工具包,此解决方案将无法正常工作。 人们还说添加:

    compute_11,sm_11; OR compute_12,sm_12; OR compute_13,sm_13;
    compute_20,sm_20;
    compute_30,sm_30;
    

    Visual Studio 2010 中项目属性中的 CUDA 将起作用。没有。

    您必须在其自己的属性(在 C++/CUDA->Device->Code Generation 下)选项卡中为 .cu 文件本身指定此项,例如:

    compute_13,sm_13;
    compute_20,sm_20;
    compute_30,sm_30;
    

    【讨论】:

    • 当您说此解决方案不适用于最新的工具包时,您究竟是什么意思?该解决方案显示带有-arch 选项的命令行nvcc 调用。对于 Windows 7、Linux 和 OS X 的 CUDA 4.2 工具包,这仍然完全有效。
    猜你喜欢
    • 2014-01-11
    • 2019-12-17
    • 2012-09-24
    • 2012-02-13
    • 1970-01-01
    • 2012-07-31
    • 2021-07-26
    • 1970-01-01
    相关资源
    最近更新 更多