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

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

问题描述

我有我的kernel.cu类的问题

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

调用 NVCC -v kernel.cu -o kernel.o 我得到这个错误:

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

我的code:

#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天全站免登陆