0

我在单独的编译模式下使用 Cuda 5.0。在

thrust/system/cuda/detail/detail/b40c/kernel_utils.h

有这个定义

__shared__ int vote_reduction[B40C_WARP_THREADS];

链接器抱怨vote_reduction.

解决方法是什么?

补充:重现问题的代码

推力版本:100600

迭代器.h

#pragma once
#include <thrust/transform_reduce.h>
#include <thrust/functional.h>

struct Unary_Op
{
    __host__ __device__ int operator()(const int index) const;
};

int iterates(int start, int end);

迭代器.cu

#include "iterator.h"

__host__ __device__ int Unary_Op::operator()(const int index) const
{
    return index;
}

int iterates(int start, int end)
{
    thrust::counting_iterator<int> first(start);
    thrust::counting_iterator<int> last = first + end;

    Unary_Op unary_op = Unary_Op();
    thrust::plus<int> binary_op;
    int init = 0;

    int sum = thrust::transform_reduce(first, last, unary_op, init, binary_op);

    return sum;
}

计算.h

#include "iterator.h"

int compute();

计算.cu

#include "calculation.h"

int compute()
{
    return iterates(0,10);
}

主文件

#include "calculation.h"

int main()
{
    compute();
    return 0;
}

编译命令(NSight)

Building file: ../calculation.cu
Invoking: NVCC Compiler
nvcc -G -g -O0 -gencode arch=compute_20,code=sm_20 -odir "" -M -o "calculation.d" "../calculation.cu"
nvcc --device-c -G -O0 -g -gencode arch=compute_20,code=sm_20  -x cu -o  "calculation.o" "../calculation.cu"

Building file: ../iterator.cu
Invoking: NVCC Compiler
nvcc -G -g -O0 -gencode arch=compute_20,code=sm_20 -odir "" -M -o "iterator.d" "../iterator.cu"
nvcc --device-c -G -O0 -g -gencode arch=compute_20,code=sm_20  -x cu -o  "iterator.o" "../iterator.cu"

Building file: ../main.cu
Invoking: NVCC Compiler
nvcc -G -g -O0 -gencode arch=compute_20,code=sm_20 -odir "" -M -o "main.d" "../main.cu"
nvcc --device-c -G -O0 -g -gencode arch=compute_20,code=sm_20  -x cu -o  "main.o" "../main.cu"

Invoking: NVCC Linker
nvcc --relocatable-device-code=true -gencode arch=compute_20,code=sm_20 -link -o  "testt"  ./calculation.o ./iterator.o ./main.o   
nvlink error   : Multiple definitions of '_ZN6thrust6system4cuda6detail6detail11b40c_thrust14vote_reductionE'
nvlink error   : Multiple definitions of '_ZN6thrust6system4cuda6detail6detail11b40c_thrust14vote_reductionE'
make: *** [tt] Error 255
4

1 回答 1

1

这似乎是针对 CUDA 5.x 工具包中提供的推力版本的单独编译的错误或问题。升级或降级到推力 1.5.3 或推力 1.7 似乎已经解决了问题

[此答案已从评论中收集并添加为社区 wiki 条目,以将问题从未回答的问题列表中删除]

于 2016-01-23T12:16:04.300 回答