簡體   English   中英

CUDA 內核操作中原子添加的一些問題

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM