C++ CUDA共享内存原子错误
我使用的是具有1.3计算能力和nvcc编译器驱动程序4.0的特斯拉C1060。我正在尝试对线程块进行一些局部计算。每个线程块都提供了一个共享数组,该数组首先初始化为零值。为了通过线程块的线程将并发更新(添加)同步到共享数据,我使用CUDA atomicAdd原语 一旦每个线程块在其共享数据数组中准备好结果,共享数据数组中的每个条目就会迭代地合并(使用atomicAdd)到全局数据数组中的相应条目 下面的代码与我基本上要做的非常相似C++ CUDA共享内存原子错误,c++,c,cuda,gpu,atomic,C++,C,Cuda,Gpu,Atomic,我使用的是具有1.3计算能力和nvcc编译器驱动程序4.0的特斯拉C1060。我正在尝试对线程块进行一些局部计算。每个线程块都提供了一个共享数组,该数组首先初始化为零值。为了通过线程块的线程将并发更新(添加)同步到共享数据,我使用CUDA atomicAdd原语 一旦每个线程块在其共享数据数组中准备好结果,共享数据数组中的每个条目就会迭代地合并(使用atomicAdd)到全局数据数组中的相应条目 下面的代码与我基本上要做的非常相似 #define DATA_SZ 16 typedef unsig
#define DATA_SZ 16
typedef unsigned long long int ULLInt;
__global__ void kernel( ULLInt* data, ULLInt ThreadCount )
{
ULLInt thid = threadIdx.x + blockIdx.x * blockDim.x;
__shared__ ULLInt sharedData[DATA_SZ];
// Initialize the shared data
if( threadIdx.x == 0 )
{
for( int i = 0; i < DATA_SZ; i++ ) { sharedData[i] = 0; }
}
__syncthreads();
//..some code here
if( thid < ThreadCount )
{
//..some code here
atomicAdd( &sharedData[getIndex(thid), thid );
//..some code here
for(..a loop...)
{
//..some code here
if(thid % 2 == 0)
{
// getIndex() returns a value in [0, DATA_SZ )
atomicAdd( &sharedData[getIndex(thid)], thid * thid );
}
}
}
__syncthreads();
if( threadIdx.x == 0 )
{
// ...
for( int i = 0; i < DATA_SZ; i++ ) { atomicAdd( &Data[i], sharedData[i] ); }
//...
}
}
如果我对以下两行进行注释,则-arch=sm_13不会出现任何错误:
atomicAdd( &sharedData[getIndex(thid), thid );
atomicAdd( &sharedData[getIndex(thid)], thid * thid );
有人能告诉我可能做错了什么吗 在CUDA C编程指南中找到了解决方案:在共享内存上运行的原子函数和在64位字上运行的原子函数仅适用于计算能力为1.2及以上的设备。在共享内存中64位字上运行的原子函数仅适用于计算能力为2.x及更高的设备
因此,基本上我不能在共享内存中使用ULLInt,我需要使用unsigned int在CUDA C编程指南中找到了解决方案:在共享内存上运行的原子函数和在64位字上运行的原子函数仅适用于计算能力为1.2及以上的设备。在共享内存中64位字上运行的原子函数仅适用于计算能力为2.x及更高的设备 所以基本上我不能在共享内存中使用ULLInt,我需要使用unsigned int
atomicAdd( &sharedData[getIndex(thid), thid );
atomicAdd( &sharedData[getIndex(thid)], thid * thid );