CUDA 内核操作中原子添加的一些问题 [英] Some issue with Atomic add in CUDA kernel operation

查看:37
本文介绍了CUDA 内核操作中原子添加的一些问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 kernel.cu 类有问题

I'm having a issue with my kernel.cu class

调用 nvcc -v kernel.cu -o kernel.o 我收到这个错误:

Calling nvcc -v kernel.cu -o kernel.o I'm getting this error:

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 不支持原子).试试:

You need to specify an architecture to nvcc which supports atomic memory operations (the default architecture is 1.0 which does not support atomics). Try:

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

看看会发生什么.

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

EDIT in 2015 to note that the default architecture in CUDA 7.0 is now 2.0, which supports atomic memory operations, so this should not be a problem in newer toolkit versions.

这篇关于CUDA 内核操作中原子添加的一些问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆