[英]Some issue with Atomic add in CUDA kernel operation
我的 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);
}
}
有人建议?
您需要为nvcc
指定一个支持原子内存操作的架构(默认架构是 1.0,不支持原子)。 尝试:
nvcc -arch=sm_11 -v kernel.cu -o kernel.o
看看会发生什么。
在 2015 年进行编辑以注意 CUDA 7.0 中的默认架构现在是 2.0,它支持原子内存操作,因此在较新的工具包版本中这应该不是问题。
今天使用最新的 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;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.